(uri: string)
| 121 | } |
| 122 | |
| 123 | public static fromURI(uri: string): CSSSource { |
| 124 | // webpack modules require all file paths to be relative to /app folder |
| 125 | const appRelativeUri = CSSSource.pathRelativeToApp(uri); |
| 126 | const sanitizedModuleName = sanitizeModuleName(appRelativeUri); |
| 127 | const resolvedModuleName = resolveModuleName(sanitizedModuleName, 'css'); |
| 128 | |
| 129 | try { |
| 130 | const cssOrAst = global.loadModule(resolvedModuleName, true); |
| 131 | if (cssOrAst) { |
| 132 | return CSSSource.fromDetect(cssOrAst, resolvedModuleName); |
| 133 | } |
| 134 | } catch (e) { |
| 135 | if (Trace.isEnabled()) { |
| 136 | Trace.write(`Could not load CSS from ${uri}: ${e}`, Trace.categories.Error, Trace.messageType.warn); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return CSSSource.fromFile(appRelativeUri); |
| 141 | } |
| 142 | |
| 143 | private static pathRelativeToApp(uri: string): string { |
| 144 | if (!uri.startsWith('/')) { |
no test coverage detected