@remix-run/assets 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -47
- package/dist/lib/asset-server.d.ts +45 -43
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +142 -46
- package/dist/lib/compilation-error.d.ts +2 -2
- package/dist/lib/compilation-error.d.ts.map +1 -1
- package/dist/lib/compilation-error.js +1 -1
- package/dist/lib/file-matcher.d.ts.map +1 -1
- package/dist/lib/file-matcher.js +3 -2
- package/dist/lib/module-store.d.ts +41 -0
- package/dist/lib/module-store.d.ts.map +1 -0
- package/dist/lib/{scripts/store.js → module-store.js} +43 -41
- package/dist/lib/scripts/compiler.d.ts +15 -15
- package/dist/lib/scripts/compiler.d.ts.map +1 -1
- package/dist/lib/scripts/compiler.js +50 -46
- package/dist/lib/scripts/emit.js +2 -2
- package/dist/lib/scripts/resolve.d.ts +7 -17
- package/dist/lib/scripts/resolve.d.ts.map +1 -1
- package/dist/lib/scripts/resolve.js +15 -9
- package/dist/lib/scripts/transform.d.ts +11 -9
- package/dist/lib/scripts/transform.d.ts.map +1 -1
- package/dist/lib/scripts/transform.js +32 -21
- package/dist/lib/source-maps.d.ts +1 -1
- package/dist/lib/source-maps.d.ts.map +1 -1
- package/dist/lib/source-maps.js +7 -1
- package/dist/lib/styles/compiler.d.ts +52 -0
- package/dist/lib/styles/compiler.d.ts.map +1 -0
- package/dist/lib/styles/compiler.js +272 -0
- package/dist/lib/styles/emit.d.ts +25 -0
- package/dist/lib/styles/emit.d.ts.map +1 -0
- package/dist/lib/styles/emit.js +78 -0
- package/dist/lib/styles/resolve.d.ts +48 -0
- package/dist/lib/styles/resolve.d.ts.map +1 -0
- package/dist/lib/styles/resolve.js +188 -0
- package/dist/lib/styles/transform.d.ts +47 -0
- package/dist/lib/styles/transform.d.ts.map +1 -0
- package/dist/lib/styles/transform.js +131 -0
- package/dist/lib/target.d.ts +21 -0
- package/dist/lib/target.d.ts.map +1 -0
- package/dist/lib/target.js +127 -0
- package/package.json +7 -2
- package/src/lib/asset-server.ts +218 -96
- package/src/lib/compilation-error.ts +7 -7
- package/src/lib/file-matcher.ts +3 -2
- package/src/lib/{scripts/store.ts → module-store.ts} +100 -87
- package/src/lib/scripts/compiler.ts +88 -70
- package/src/lib/scripts/emit.ts +2 -2
- package/src/lib/scripts/resolve.ts +34 -23
- package/src/lib/scripts/transform.ts +49 -34
- package/src/lib/source-maps.ts +8 -1
- package/src/lib/styles/compiler.ts +400 -0
- package/src/lib/styles/emit.ts +137 -0
- package/src/lib/styles/resolve.ts +316 -0
- package/src/lib/styles/transform.ts +226 -0
- package/src/lib/target.ts +196 -0
- package/dist/lib/scripts/store.d.ts +0 -40
- package/dist/lib/scripts/store.d.ts.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ResolverFactory } from 'oxc-resolver';
|
|
2
2
|
import type { AssetServerCompilationError } from '../compilation-error.ts';
|
|
3
|
+
import type { ModuleRecord, ModuleTracking } from '../module-store.ts';
|
|
3
4
|
import type { CompiledRoutes } from '../routes.ts';
|
|
4
|
-
import type { ModuleRecord } from './store.ts';
|
|
5
5
|
import type { ResolveModuleResult, TransformedModule } from './transform.ts';
|
|
6
|
+
import type { EmittedModule } from './emit.ts';
|
|
7
|
+
type ScriptRecord = ModuleRecord<TransformedModule, ResolvedModule, EmittedModule>;
|
|
6
8
|
export declare const resolverExtensionAlias: {
|
|
7
9
|
'.js': string[];
|
|
8
10
|
'.jsx': string[];
|
|
@@ -16,38 +18,26 @@ type ResolvedImport = {
|
|
|
16
18
|
quote?: '"' | "'" | '`';
|
|
17
19
|
start: number;
|
|
18
20
|
};
|
|
19
|
-
type RelativeImportResolution = {
|
|
20
|
-
candidatePaths: readonly string[];
|
|
21
|
-
candidatePrefixes: readonly string[];
|
|
22
|
-
specifier: string;
|
|
23
|
-
};
|
|
24
|
-
export type TrackedResolution = RelativeImportResolution & {
|
|
25
|
-
resolvedIdentityPath: string | null;
|
|
26
|
-
};
|
|
27
21
|
export type ResolvedModule = {
|
|
28
22
|
deps: string[];
|
|
29
23
|
fingerprint: string | null;
|
|
30
24
|
identityPath: string;
|
|
31
25
|
imports: ResolvedImport[];
|
|
32
26
|
trackedFiles: string[];
|
|
33
|
-
trackedResolutions: TrackedResolution[];
|
|
34
27
|
rawCode: string;
|
|
35
28
|
resolvedPath: string;
|
|
36
29
|
sourceMap: string | null;
|
|
37
30
|
stableUrlPathname: string;
|
|
38
31
|
};
|
|
39
|
-
export type ResolutionFailureState = {
|
|
40
|
-
trackedFiles: readonly string[];
|
|
41
|
-
trackedResolutions: readonly TrackedResolution[];
|
|
42
|
-
};
|
|
43
32
|
type ResolveResult = {
|
|
33
|
+
tracking: ModuleTracking;
|
|
34
|
+
} & ({
|
|
44
35
|
ok: true;
|
|
45
36
|
value: ResolvedModule;
|
|
46
37
|
} | {
|
|
47
38
|
ok: false;
|
|
48
39
|
error: AssetServerCompilationError;
|
|
49
|
-
|
|
50
|
-
};
|
|
40
|
+
});
|
|
51
41
|
export type ResolveArgs = {
|
|
52
42
|
isAllowed(absolutePath: string): boolean;
|
|
53
43
|
isWatchIgnored(filePath: string): boolean;
|
|
@@ -55,6 +45,6 @@ export type ResolveArgs = {
|
|
|
55
45
|
resolverFactory: ResolverFactory;
|
|
56
46
|
routes: CompiledRoutes;
|
|
57
47
|
};
|
|
58
|
-
export declare function resolveModule(record:
|
|
48
|
+
export declare function resolveModule(record: ScriptRecord, transformed: TransformedModule, args: ResolveArgs): Promise<ResolveResult>;
|
|
59
49
|
export {};
|
|
60
50
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAMnD,OAAO,KAAK,EAAE,2B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AAA;AAED,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,cAAc,CAAA;CACzB,GAAG,CACA;IACE,EAAE,EAAE,IAAI,CAAA;IACR,KAAK,EAAE,cAAc,CAAA;CACtB,GACD;IACE,EAAE,EAAE,KAAK,CAAA;IACT,KAAK,EAAE,2BAA2B,CAAA;CACnC,CACJ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAA;IACxC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;IACzC,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAAA;IACnE,eAAe,EAAE,eAAe,CAAA;IAChC,MAAM,EAAE,cAAc,CAAA;CACvB,CAAA;AAQD,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,iBAAiB,EAC9B,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,aAAa,CAAC,CAyIxB"}
|
|
@@ -38,20 +38,20 @@ export async function resolveModule(record, transformed, args) {
|
|
|
38
38
|
}
|
|
39
39
|
let resolvedImport = args.resolveModulePath(resolvedSpec.absolutePath);
|
|
40
40
|
if (!resolvedImport) {
|
|
41
|
-
return failResolve(createAssetServerCompilationError(`
|
|
41
|
+
return failResolve(createAssetServerCompilationError(`Import "${unresolved.specifier}" in ${transformed.resolvedPath}, resolved to "${resolvedSpec.absolutePath}", is not a supported script file. ` +
|
|
42
42
|
`Supported extensions are ${supportedScriptExtensions.join(', ')}.`, {
|
|
43
43
|
code: 'IMPORT_NOT_SUPPORTED',
|
|
44
44
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
45
45
|
}
|
|
46
46
|
if (!args.isAllowed(resolvedImport.identityPath)) {
|
|
47
|
-
return failResolve(createAssetServerCompilationError(`
|
|
48
|
-
`Add a matching allow rule, remove a conflicting deny rule, or mark this import as external.`, {
|
|
47
|
+
return failResolve(createAssetServerCompilationError(`Import "${unresolved.specifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is not allowed by the asset server allow/deny configuration. ` +
|
|
48
|
+
`Add a matching allow rule for this file path, remove a conflicting deny rule for this file path, or mark this import as external.`, {
|
|
49
49
|
code: 'IMPORT_NOT_ALLOWED',
|
|
50
50
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
51
51
|
}
|
|
52
52
|
let stableUrlPathname = args.routes.toUrlPathname(resolvedImport.identityPath);
|
|
53
53
|
if (!stableUrlPathname) {
|
|
54
|
-
return failResolve(createAssetServerCompilationError(`
|
|
54
|
+
return failResolve(createAssetServerCompilationError(`Import "${unresolved.specifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured fileMap entries. ` +
|
|
55
55
|
`Add a matching fileMap entry for this file path, or mark this import as external.`, {
|
|
56
56
|
code: 'IMPORT_OUTSIDE_FILE_MAP',
|
|
57
57
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
@@ -78,13 +78,13 @@ export async function resolveModule(record, transformed, args) {
|
|
|
78
78
|
}
|
|
79
79
|
return {
|
|
80
80
|
ok: true,
|
|
81
|
+
tracking: toResolveTracking(trackedFiles, trackedResolutions),
|
|
81
82
|
value: {
|
|
82
83
|
deps: [...deps],
|
|
83
84
|
fingerprint: transformed.fingerprint,
|
|
84
85
|
identityPath: record.identityPath,
|
|
85
86
|
imports: importsWithPaths,
|
|
86
87
|
trackedFiles: [...trackedFiles],
|
|
87
|
-
trackedResolutions,
|
|
88
88
|
rawCode: transformed.rawCode,
|
|
89
89
|
resolvedPath: transformed.resolvedPath,
|
|
90
90
|
sourceMap: transformed.sourceMap,
|
|
@@ -203,10 +203,16 @@ function failResolve(error, trackedFiles, trackedResolutions, importerPath, opti
|
|
|
203
203
|
return {
|
|
204
204
|
ok: false,
|
|
205
205
|
error: toResolveError(error, importerPath),
|
|
206
|
-
tracking:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
tracking: toResolveTracking(trackedFiles, appendFailedTrackedResolution(trackedResolutions, options.trackedResolution)),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function toResolveTracking(trackedFiles, trackedResolutions) {
|
|
210
|
+
return {
|
|
211
|
+
trackedFiles: [
|
|
212
|
+
...trackedFiles,
|
|
213
|
+
...trackedResolutions.flatMap((trackedResolution) => trackedResolution.candidatePaths),
|
|
214
|
+
],
|
|
215
|
+
trackedDirectories: trackedResolutions.flatMap((trackedResolution) => trackedResolution.candidatePrefixes),
|
|
210
216
|
};
|
|
211
217
|
}
|
|
212
218
|
function appendFailedTrackedResolution(trackedResolutions, trackedResolution) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { TsConfigJsonResolved } from 'get-tsconfig';
|
|
2
2
|
import type { AssetServerCompilationError } from '../compilation-error.ts';
|
|
3
|
+
import type { ModuleRecord, ModuleTracking } from '../module-store.ts';
|
|
3
4
|
import type { CompiledRoutes } from '../routes.ts';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
5
|
+
import type { EmittedModule } from './emit.ts';
|
|
6
|
+
import type { ResolvedScriptTarget } from '../target.ts';
|
|
7
|
+
import type { ResolvedModule } from './resolve.ts';
|
|
8
|
+
type ScriptRecord = ModuleRecord<TransformedModule, ResolvedModule, EmittedModule>;
|
|
6
9
|
export type ResolveModuleResult = {
|
|
7
10
|
identityPath: string;
|
|
8
11
|
resolvedPath: string;
|
|
@@ -25,16 +28,15 @@ export type TransformedModule = {
|
|
|
25
28
|
trackedFiles: string[];
|
|
26
29
|
unresolvedImports: UnresolvedImport[];
|
|
27
30
|
};
|
|
28
|
-
export type TransformFailureState = {
|
|
29
|
-
trackedFiles: readonly string[];
|
|
30
|
-
};
|
|
31
31
|
type TransformResult = {
|
|
32
|
+
tracking: ModuleTracking;
|
|
33
|
+
} & ({
|
|
32
34
|
ok: true;
|
|
33
35
|
value: TransformedModule;
|
|
34
|
-
} |
|
|
36
|
+
} | {
|
|
35
37
|
ok: false;
|
|
36
38
|
error: AssetServerCompilationError;
|
|
37
|
-
}
|
|
39
|
+
});
|
|
38
40
|
type TsconfigTransformOptions = {
|
|
39
41
|
trackedFiles: string[];
|
|
40
42
|
tsconfigRaw?: TsConfigJsonResolved;
|
|
@@ -50,13 +52,13 @@ export type TransformArgs = {
|
|
|
50
52
|
routes: CompiledRoutes;
|
|
51
53
|
sourceMapSourcePaths: 'absolute' | 'url';
|
|
52
54
|
sourceMaps: 'external' | 'inline' | null;
|
|
53
|
-
target:
|
|
55
|
+
target: ResolvedScriptTarget | null;
|
|
54
56
|
tsconfigTransformOptionsResolver: TsconfigTransformOptionsResolver;
|
|
55
57
|
};
|
|
56
58
|
export declare function createTsconfigTransformOptionsResolver(): {
|
|
57
59
|
clear(): void;
|
|
58
60
|
getTransformOptions(filePath: string, isWatchIgnored: (filePath: string) => boolean): TsconfigTransformOptions;
|
|
59
61
|
};
|
|
60
|
-
export declare function transformModule(record:
|
|
62
|
+
export declare function transformModule(record: ScriptRecord, args: TransformArgs): Promise<TransformResult>;
|
|
61
63
|
export {};
|
|
62
64
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/transform.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAS,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAQ/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/transform.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAS,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAQ/D,OAAO,KAAK,EAAE,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B,GACD;IACE,EAAE,EAAE,KAAK,CAAA;IACT,KAAK,EAAE,2BAA2B,CAAA;CACnC,CACJ,CAAA;AAED,KAAK,wBAAwB,GAAG;IAC9B,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACnC,CAAA;AAED,KAAK,gCAAgC,GAAG,UAAU,CAAC,OAAO,sCAAsC,CAAC,CAAA;AAEjG,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IACrC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAChC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;IACzC,MAAM,EAAE,OAAO,CAAA;IACf,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACtD,MAAM,EAAE,cAAc,CAAA;IACtB,oBAAoB,EAAE,UAAU,GAAG,KAAK,CAAA;IACxC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAA;IACxC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAA;IACnC,gCAAgC,EAAE,gCAAgC,CAAA;CACnE,CAAA;AAED,wBAAgB,sCAAsC;;;EAkCrD;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,eAAe,CAAC,CA6H1B"}
|
|
@@ -63,10 +63,12 @@ export async function transformModule(record, args) {
|
|
|
63
63
|
if (!resolvedPath) {
|
|
64
64
|
return {
|
|
65
65
|
ok: false,
|
|
66
|
-
error: createAssetServerCompilationError(`
|
|
67
|
-
code: '
|
|
66
|
+
error: createAssetServerCompilationError(`File not found: ${record.identityPath}`, {
|
|
67
|
+
code: 'FILE_NOT_FOUND',
|
|
68
68
|
}),
|
|
69
|
-
|
|
69
|
+
tracking: {
|
|
70
|
+
trackedFiles: args.isWatchIgnored(record.identityPath) ? [] : [record.identityPath],
|
|
71
|
+
},
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
let transformOptions = args.tsconfigTransformOptionsResolver.getTransformOptions(resolvedPath, args.isWatchIgnored);
|
|
@@ -82,17 +84,21 @@ export async function transformModule(record, args) {
|
|
|
82
84
|
if (isNoEntityError(error)) {
|
|
83
85
|
return {
|
|
84
86
|
ok: false,
|
|
85
|
-
error: createAssetServerCompilationError(`
|
|
87
|
+
error: createAssetServerCompilationError(`File not found: ${resolvedPath}`, {
|
|
86
88
|
cause: error,
|
|
87
|
-
code: '
|
|
89
|
+
code: 'FILE_NOT_FOUND',
|
|
88
90
|
}),
|
|
89
|
-
|
|
91
|
+
tracking: {
|
|
92
|
+
trackedFiles,
|
|
93
|
+
},
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
return {
|
|
93
97
|
ok: false,
|
|
94
98
|
error: toTransformFailedError(error, resolvedPath),
|
|
95
|
-
|
|
99
|
+
tracking: {
|
|
100
|
+
trackedFiles,
|
|
101
|
+
},
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
104
|
try {
|
|
@@ -107,20 +113,23 @@ export async function transformModule(record, args) {
|
|
|
107
113
|
throw createAssetServerCompilationError(`CommonJS module detected: ${resolvedPath}. ` +
|
|
108
114
|
`This module uses CommonJS (require/module.exports) which is not supported. ` +
|
|
109
115
|
`Please use an ESM-compatible module.`, {
|
|
110
|
-
code: '
|
|
116
|
+
code: 'COMMONJS_NOT_SUPPORTED',
|
|
111
117
|
});
|
|
112
118
|
}
|
|
113
119
|
let stableUrlPathname = args.routes.toUrlPathname(record.identityPath);
|
|
114
120
|
if (!stableUrlPathname) {
|
|
115
|
-
throw createAssetServerCompilationError(`
|
|
116
|
-
code: '
|
|
121
|
+
throw createAssetServerCompilationError(`File ${record.identityPath} is outside all configured fileMap entries.`, {
|
|
122
|
+
code: 'FILE_OUTSIDE_FILE_MAP',
|
|
117
123
|
});
|
|
118
124
|
}
|
|
119
125
|
let sourceMap = analysis.sourceMap
|
|
120
|
-
? rewriteSourceMapSources(analysis.sourceMap, resolvedPath, stableUrlPathname, args.sourceMapSourcePaths)
|
|
126
|
+
? rewriteSourceMapSources(analysis.sourceMap, resolvedPath, stableUrlPathname, args.sourceMapSourcePaths, sourceText)
|
|
121
127
|
: null;
|
|
122
128
|
return {
|
|
123
129
|
ok: true,
|
|
130
|
+
tracking: {
|
|
131
|
+
trackedFiles,
|
|
132
|
+
},
|
|
124
133
|
value: {
|
|
125
134
|
fingerprint: args.buildId === null
|
|
126
135
|
? null
|
|
@@ -146,7 +155,9 @@ export async function transformModule(record, args) {
|
|
|
146
155
|
return {
|
|
147
156
|
ok: false,
|
|
148
157
|
error: toTransformFailedError(error, resolvedPath),
|
|
149
|
-
|
|
158
|
+
tracking: {
|
|
159
|
+
trackedFiles,
|
|
160
|
+
},
|
|
150
161
|
};
|
|
151
162
|
}
|
|
152
163
|
}
|
|
@@ -175,9 +186,9 @@ async function analyzeModuleSource(sourceText, resolvedPath, transformOptions, o
|
|
|
175
186
|
catch (error) {
|
|
176
187
|
if (isAssetServerCompilationError(error))
|
|
177
188
|
throw error;
|
|
178
|
-
throw createAssetServerCompilationError(`Failed to transform
|
|
189
|
+
throw createAssetServerCompilationError(`Failed to transform script ${resolvedPath}. ${formatUnknownError(error)}`, {
|
|
179
190
|
cause: error,
|
|
180
|
-
code: '
|
|
191
|
+
code: 'TRANSFORM_FAILED',
|
|
181
192
|
});
|
|
182
193
|
}
|
|
183
194
|
let rawCode = transformResult.code.trimEnd();
|
|
@@ -213,9 +224,9 @@ async function minifyModule(rawCode, resolvedPath, target, sourceMaps) {
|
|
|
213
224
|
catch (error) {
|
|
214
225
|
if (isAssetServerCompilationError(error))
|
|
215
226
|
throw error;
|
|
216
|
-
throw createAssetServerCompilationError(`Failed to minify
|
|
227
|
+
throw createAssetServerCompilationError(`Failed to minify script ${resolvedPath}. ${formatUnknownError(error)}`, {
|
|
217
228
|
cause: error,
|
|
218
|
-
code: '
|
|
229
|
+
code: 'TRANSFORM_FAILED',
|
|
219
230
|
});
|
|
220
231
|
}
|
|
221
232
|
}
|
|
@@ -256,7 +267,7 @@ function getJsxOptions(resolvedPath, compilerOptions) {
|
|
|
256
267
|
if (jsx === 'preserve' || jsx === 'react-native') {
|
|
257
268
|
throw createAssetServerCompilationError(`Unsupported tsconfig compilerOptions.jsx = "${jsx}" for ${resolvedPath}. ` +
|
|
258
269
|
`Asset server must compile JSX to browser-runnable JavaScript.`, {
|
|
259
|
-
code: '
|
|
270
|
+
code: 'TRANSFORM_FAILED',
|
|
260
271
|
});
|
|
261
272
|
}
|
|
262
273
|
if (jsx === 'react-jsx' || jsx === 'react-jsxdev') {
|
|
@@ -293,8 +304,8 @@ function getStringOption(compilerOptions, key) {
|
|
|
293
304
|
function assertNoCompilerErrors(errors, resolvedPath, operation) {
|
|
294
305
|
if (!errors || errors.length === 0)
|
|
295
306
|
return;
|
|
296
|
-
throw createAssetServerCompilationError(`Failed to ${operation}
|
|
297
|
-
code: '
|
|
307
|
+
throw createAssetServerCompilationError(`Failed to ${operation} script ${resolvedPath}. ${errors[0].message ?? 'Unknown error'}`, {
|
|
308
|
+
code: 'TRANSFORM_FAILED',
|
|
298
309
|
});
|
|
299
310
|
}
|
|
300
311
|
async function getUnresolvedImportsFromLexer(rawCode) {
|
|
@@ -352,9 +363,9 @@ function formatUnknownError(error) {
|
|
|
352
363
|
function toTransformFailedError(error, resolvedPath) {
|
|
353
364
|
if (isAssetServerCompilationError(error))
|
|
354
365
|
return error;
|
|
355
|
-
return createAssetServerCompilationError(`Failed to transform
|
|
366
|
+
return createAssetServerCompilationError(`Failed to transform script ${resolvedPath}. ${formatUnknownError(error)}`, {
|
|
356
367
|
cause: error,
|
|
357
|
-
code: '
|
|
368
|
+
code: 'TRANSFORM_FAILED',
|
|
358
369
|
});
|
|
359
370
|
}
|
|
360
371
|
function isNoEntityError(error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function composeSourceMaps(rewriteSourceMap: string, transformSourceMap: string): string;
|
|
2
|
-
export declare function rewriteSourceMapSources(sourceMap: string, resolvedPath: string, stableUrlPathname: string, sourceMapSourcePaths: 'absolute' | 'url'): string;
|
|
2
|
+
export declare function rewriteSourceMapSources(sourceMap: string, resolvedPath: string, stableUrlPathname: string, sourceMapSourcePaths: 'absolute' | 'url', sourceContent?: string): string;
|
|
3
3
|
export declare function stringifySourceMap(map: unknown): string | null;
|
|
4
4
|
//# sourceMappingURL=source-maps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-maps.d.ts","sourceRoot":"","sources":["../../src/lib/source-maps.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CA2C9F;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,EACzB,oBAAoB,EAAE,UAAU,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"source-maps.d.ts","sourceRoot":"","sources":["../../src/lib/source-maps.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CA2C9F;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,EACzB,oBAAoB,EAAE,UAAU,GAAG,KAAK,EACxC,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQ9D"}
|
package/dist/lib/source-maps.js
CHANGED
|
@@ -38,11 +38,14 @@ export function composeSourceMaps(rewriteSourceMap, transformSourceMap) {
|
|
|
38
38
|
}
|
|
39
39
|
return JSON.stringify(generator.toJSON());
|
|
40
40
|
}
|
|
41
|
-
export function rewriteSourceMapSources(sourceMap, resolvedPath, stableUrlPathname, sourceMapSourcePaths) {
|
|
41
|
+
export function rewriteSourceMapSources(sourceMap, resolvedPath, stableUrlPathname, sourceMapSourcePaths, sourceContent) {
|
|
42
42
|
let json = JSON.parse(sourceMap);
|
|
43
43
|
json.sources = [
|
|
44
44
|
sourceMapSourcePaths === 'absolute' ? normalizeFilePath(resolvedPath) : stableUrlPathname,
|
|
45
45
|
];
|
|
46
|
+
if (sourceContent !== undefined) {
|
|
47
|
+
json.sourcesContent = [sourceContent];
|
|
48
|
+
}
|
|
46
49
|
return JSON.stringify(json);
|
|
47
50
|
}
|
|
48
51
|
export function stringifySourceMap(map) {
|
|
@@ -50,6 +53,9 @@ export function stringifySourceMap(map) {
|
|
|
50
53
|
return null;
|
|
51
54
|
if (typeof map === 'string')
|
|
52
55
|
return map;
|
|
56
|
+
if (map instanceof Uint8Array) {
|
|
57
|
+
return Buffer.from(map).toString('utf8');
|
|
58
|
+
}
|
|
53
59
|
if (typeof map === 'object' && map !== null)
|
|
54
60
|
return JSON.stringify(map);
|
|
55
61
|
return String(map);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CompiledRoutes } from '../routes.ts';
|
|
2
|
+
import type { ResolvedStyleTarget } from '../target.ts';
|
|
3
|
+
import type { EmittedAsset } from './emit.ts';
|
|
4
|
+
type StyleCompileResult = {
|
|
5
|
+
code: EmittedAsset;
|
|
6
|
+
fingerprint: string | null;
|
|
7
|
+
sourceMap: EmittedAsset | null;
|
|
8
|
+
};
|
|
9
|
+
type StyleGetResult = {
|
|
10
|
+
style: StyleCompileResult;
|
|
11
|
+
type: 'style';
|
|
12
|
+
} | {
|
|
13
|
+
etag: string;
|
|
14
|
+
type: 'not-modified';
|
|
15
|
+
};
|
|
16
|
+
type StyleGetOptions = {
|
|
17
|
+
ifNoneMatch: string | null;
|
|
18
|
+
isSourceMapRequest: boolean;
|
|
19
|
+
requestedFingerprint: string | null;
|
|
20
|
+
};
|
|
21
|
+
type StyleCompilerOptions = {
|
|
22
|
+
buildId?: string;
|
|
23
|
+
fingerprintAssets: boolean;
|
|
24
|
+
isAllowed(absolutePath: string): boolean;
|
|
25
|
+
minify: boolean;
|
|
26
|
+
onWatchDirectoriesChange?: (delta: {
|
|
27
|
+
add: string[];
|
|
28
|
+
remove: string[];
|
|
29
|
+
}) => void;
|
|
30
|
+
rootDir: string;
|
|
31
|
+
routes: CompiledRoutes;
|
|
32
|
+
sourceMapSourcePaths: 'absolute' | 'url';
|
|
33
|
+
sourceMaps?: 'external' | 'inline';
|
|
34
|
+
targets?: ResolvedStyleTarget;
|
|
35
|
+
watchIgnore?: readonly string[];
|
|
36
|
+
};
|
|
37
|
+
type StyleCompiler = {
|
|
38
|
+
getHref(filePath: string): Promise<string>;
|
|
39
|
+
getPreloadLayers(filePath: string | readonly string[]): Promise<string[][]>;
|
|
40
|
+
getStyle(filePath: string, options: StyleGetOptions): Promise<StyleGetResult>;
|
|
41
|
+
handleFileEvent(filePath: string, event: 'add' | 'change' | 'unlink'): Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
export declare function createStyleCompiler(options: StyleCompilerOptions): StyleCompiler;
|
|
44
|
+
export declare function isStyleFilePath(filePath: string): boolean;
|
|
45
|
+
export declare function createResponseForStyle(result: StyleCompileResult, options: {
|
|
46
|
+
cacheControl: string;
|
|
47
|
+
ifNoneMatch: string | null;
|
|
48
|
+
isSourceMapRequest: boolean;
|
|
49
|
+
method: string;
|
|
50
|
+
}): Response;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/lib/styles/compiler.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MA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