@remix-run/assets 0.5.0 → 0.7.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 +185 -104
- package/dist/assets.d.ts +4 -1
- package/dist/assets.d.ts.map +1 -1
- package/dist/lib/access.d.ts +29 -2
- package/dist/lib/access.d.ts.map +1 -1
- package/dist/lib/access.js +52 -26
- package/dist/lib/asset-server.d.ts +61 -25
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +127 -55
- package/dist/lib/compilation-error.d.ts +1 -1
- package/dist/lib/compilation-error.d.ts.map +1 -1
- package/dist/lib/files/compiler.d.ts +1 -1
- package/dist/lib/files/compiler.d.ts.map +1 -1
- package/dist/lib/files/compiler.js +28 -31
- package/dist/lib/files/config.d.ts +6 -0
- package/dist/lib/files/config.d.ts.map +1 -1
- package/dist/lib/files/config.js +9 -0
- package/dist/lib/fingerprint.d.ts +0 -4
- package/dist/lib/fingerprint.d.ts.map +1 -1
- package/dist/lib/fingerprint.js +0 -4
- package/dist/lib/hmr.d.ts +7 -0
- package/dist/lib/hmr.d.ts.map +1 -1
- package/dist/lib/hmr.js +198 -25
- package/dist/lib/injected-packages.d.ts +3 -2
- package/dist/lib/injected-packages.d.ts.map +1 -1
- package/dist/lib/injected-packages.js +11 -8
- package/dist/lib/inspection.d.ts +39 -0
- package/dist/lib/inspection.d.ts.map +1 -0
- package/dist/lib/inspection.js +160 -0
- package/dist/lib/routes.d.ts +12 -3
- package/dist/lib/routes.d.ts.map +1 -1
- package/dist/lib/routes.js +124 -80
- package/dist/lib/scripts/compiler.d.ts +8 -2
- package/dist/lib/scripts/compiler.d.ts.map +1 -1
- package/dist/lib/scripts/compiler.js +188 -38
- package/dist/lib/scripts/emit.d.ts +2 -1
- package/dist/lib/scripts/emit.d.ts.map +1 -1
- package/dist/lib/scripts/emit.js +25 -16
- package/dist/lib/scripts/resolve.d.ts +7 -1
- package/dist/lib/scripts/resolve.d.ts.map +1 -1
- package/dist/lib/scripts/resolve.js +119 -12
- package/dist/lib/scripts/specifiers.d.ts +2 -0
- package/dist/lib/scripts/specifiers.d.ts.map +1 -0
- package/dist/lib/scripts/specifiers.js +9 -0
- package/dist/lib/scripts/transform.d.ts +2 -3
- package/dist/lib/scripts/transform.d.ts.map +1 -1
- package/dist/lib/scripts/transform.js +4 -18
- package/dist/lib/styles/compiler.d.ts +0 -1
- package/dist/lib/styles/compiler.d.ts.map +1 -1
- package/dist/lib/styles/compiler.js +105 -25
- package/dist/lib/styles/emit.d.ts +2 -1
- package/dist/lib/styles/emit.d.ts.map +1 -1
- package/dist/lib/styles/emit.js +12 -10
- package/dist/lib/styles/resolve.d.ts +0 -1
- package/dist/lib/styles/resolve.d.ts.map +1 -1
- package/dist/lib/styles/resolve.js +8 -9
- package/dist/lib/styles/transform.d.ts +0 -2
- package/dist/lib/styles/transform.d.ts.map +1 -1
- package/dist/lib/styles/transform.js +2 -9
- package/dist/lib/virtual-store.d.ts +8 -0
- package/dist/lib/virtual-store.d.ts.map +1 -0
- package/dist/lib/virtual-store.js +100 -0
- package/package.json +6 -6
- package/src/assets.ts +9 -1
- package/src/lib/access.ts +83 -30
- package/src/lib/asset-server.ts +224 -94
- package/src/lib/compilation-error.ts +4 -3
- package/src/lib/files/compiler.ts +32 -42
- package/src/lib/files/config.ts +17 -0
- package/src/lib/fingerprint.ts +0 -9
- package/src/lib/hmr.ts +210 -26
- package/src/lib/injected-packages.ts +16 -10
- package/src/lib/inspection.ts +229 -0
- package/src/lib/routes.ts +158 -126
- package/src/lib/scripts/compiler.ts +240 -54
- package/src/lib/scripts/emit.ts +34 -19
- package/src/lib/scripts/resolve.ts +175 -13
- package/src/lib/scripts/specifiers.ts +11 -0
- package/src/lib/scripts/transform.ts +6 -25
- package/src/lib/styles/compiler.ts +137 -39
- package/src/lib/styles/emit.ts +18 -13
- package/src/lib/styles/resolve.ts +8 -10
- package/src/lib/styles/transform.ts +2 -12
- package/src/lib/virtual-store.ts +124 -0
|
@@ -17,6 +17,7 @@ import { normalizeFilePath } from '../paths.ts'
|
|
|
17
17
|
import type { CompiledRoutes } from '../routes.ts'
|
|
18
18
|
import type { ResolveModuleResult, TransformedModule } from './transform.ts'
|
|
19
19
|
import type { EmittedModule } from './emit.ts'
|
|
20
|
+
import { isBareImportSpecifier } from './specifiers.ts'
|
|
20
21
|
|
|
21
22
|
type ScriptRecord = ModuleRecord<TransformedModule, ResolvedModule, EmittedModule>
|
|
22
23
|
|
|
@@ -31,14 +32,24 @@ export const supportedScriptExtensions = ['.ts', '.tsx', '.js', '.jsx', '.mts',
|
|
|
31
32
|
const supportedScriptExtensionSet = new Set<string>(supportedScriptExtensions)
|
|
32
33
|
|
|
33
34
|
type ResolvedImport = {
|
|
35
|
+
compiledSpecifier: string
|
|
34
36
|
depPath: string
|
|
35
37
|
end: number
|
|
36
38
|
quote?: '"' | "'" | '`'
|
|
39
|
+
scopePathname?: string
|
|
40
|
+
specifier: string
|
|
37
41
|
start: number
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
type ResolvedHmrAcceptedDependency = ResolvedImport
|
|
41
45
|
|
|
46
|
+
type PendingBareImportScope = {
|
|
47
|
+
imported: ResolvedImport
|
|
48
|
+
resolvedIdentityPath: string
|
|
49
|
+
specifier: string
|
|
50
|
+
trackedResolution: RelativeImportResolution | null
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
type RelativeImportResolution = {
|
|
43
54
|
candidatePaths: readonly string[]
|
|
44
55
|
candidatePrefixes: readonly string[]
|
|
@@ -51,7 +62,6 @@ type TrackedResolution = RelativeImportResolution & {
|
|
|
51
62
|
|
|
52
63
|
export type ResolvedModule = {
|
|
53
64
|
deps: string[]
|
|
54
|
-
fingerprint: string | null
|
|
55
65
|
hmr: Omit<TransformedModule['hmr'], 'acceptedDeps'> & {
|
|
56
66
|
acceptedDeps: ResolvedHmrAcceptedDependency[]
|
|
57
67
|
}
|
|
@@ -61,6 +71,7 @@ export type ResolvedModule = {
|
|
|
61
71
|
rawCode: string
|
|
62
72
|
resolvedPath: string
|
|
63
73
|
sourceMap: string | null
|
|
74
|
+
staticDeps: string[]
|
|
64
75
|
stableUrlPathname: string
|
|
65
76
|
}
|
|
66
77
|
|
|
@@ -78,10 +89,13 @@ type ResolveResult = {
|
|
|
78
89
|
)
|
|
79
90
|
|
|
80
91
|
export type ResolveArgs = {
|
|
92
|
+
concurrency: number
|
|
93
|
+
isDirectoryResolutionFileIndependent(directory: string): boolean
|
|
81
94
|
isAllowed(absolutePath: string): boolean
|
|
82
95
|
isWatchIgnored(filePath: string): boolean
|
|
83
96
|
resolveModulePath(absolutePath: string): ResolveModuleResult | null
|
|
84
97
|
resolverFactory: ResolverFactory
|
|
98
|
+
resolveDirectorySpecifierIdentity(directory: string, specifier: string): Promise<string | null>
|
|
85
99
|
routes: CompiledRoutes
|
|
86
100
|
}
|
|
87
101
|
|
|
@@ -121,8 +135,10 @@ export async function resolveModule(
|
|
|
121
135
|
}
|
|
122
136
|
|
|
123
137
|
let importsWithPaths: ResolvedImport[] = []
|
|
138
|
+
let pendingBareImportScopes: PendingBareImportScope[] = []
|
|
124
139
|
let acceptedDepsWithPaths: ResolvedHmrAcceptedDependency[] = []
|
|
125
140
|
let deps = new Set<string>()
|
|
141
|
+
let staticDeps = new Set<string>()
|
|
126
142
|
|
|
127
143
|
for (let unresolved of transformed.unresolvedImports) {
|
|
128
144
|
let displaySpecifier = getDisplayImportSpecifier(unresolved.specifier)
|
|
@@ -137,7 +153,7 @@ export async function resolveModule(
|
|
|
137
153
|
return failResolve(
|
|
138
154
|
createAssetServerCompilationError(
|
|
139
155
|
`Failed to resolve import "${displaySpecifier}" in ${transformed.resolvedPath}. ` +
|
|
140
|
-
`Ensure it resolves to a file within
|
|
156
|
+
`Ensure it resolves to a file within a configured asset server mount, or mark it as external.`,
|
|
141
157
|
{
|
|
142
158
|
code: 'IMPORT_RESOLUTION_FAILED',
|
|
143
159
|
},
|
|
@@ -186,10 +202,10 @@ export async function resolveModule(
|
|
|
186
202
|
if (!stableUrlPathname) {
|
|
187
203
|
return failResolve(
|
|
188
204
|
createAssetServerCompilationError(
|
|
189
|
-
`Import "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured
|
|
190
|
-
`Add a matching
|
|
205
|
+
`Import "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured mounts. ` +
|
|
206
|
+
`Add a matching mount for this file path, or mark this import as external.`,
|
|
191
207
|
{
|
|
192
|
-
code: '
|
|
208
|
+
code: 'IMPORT_OUTSIDE_MOUNTS',
|
|
193
209
|
},
|
|
194
210
|
),
|
|
195
211
|
trackedFiles,
|
|
@@ -200,6 +216,7 @@ export async function resolveModule(
|
|
|
200
216
|
}
|
|
201
217
|
|
|
202
218
|
deps.add(resolvedImport.identityPath)
|
|
219
|
+
if (!unresolved.dynamic) staticDeps.add(resolvedImport.identityPath)
|
|
203
220
|
|
|
204
221
|
if (transformed.packageSpecifiers.includes(unresolved.specifier)) {
|
|
205
222
|
let packageJsonPath =
|
|
@@ -216,12 +233,50 @@ export async function resolveModule(
|
|
|
216
233
|
})
|
|
217
234
|
}
|
|
218
235
|
|
|
219
|
-
|
|
236
|
+
let imported: ResolvedImport = {
|
|
237
|
+
compiledSpecifier: unresolved.specifier,
|
|
220
238
|
depPath: resolvedImport.identityPath,
|
|
221
239
|
end: unresolved.end,
|
|
222
240
|
quote: unresolved.quote,
|
|
241
|
+
specifier: displaySpecifier,
|
|
223
242
|
start: unresolved.start,
|
|
224
|
-
}
|
|
243
|
+
}
|
|
244
|
+
importsWithPaths.push(imported)
|
|
245
|
+
|
|
246
|
+
if (isBareImportSpecifier(displaySpecifier)) {
|
|
247
|
+
pendingBareImportScopes.push({
|
|
248
|
+
imported,
|
|
249
|
+
resolvedIdentityPath: resolvedImport.identityPath,
|
|
250
|
+
specifier: normalizeSpecifierResolution(unresolved.specifier, transformed.resolvedPath)
|
|
251
|
+
.specifier,
|
|
252
|
+
trackedResolution,
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (pendingBareImportScopes.length > 0) {
|
|
258
|
+
let scopeResults = await resolveBareImportScopes(
|
|
259
|
+
pendingBareImportScopes,
|
|
260
|
+
transformed.resolvedPath,
|
|
261
|
+
args,
|
|
262
|
+
)
|
|
263
|
+
for (let index = 0; index < scopeResults.length; index++) {
|
|
264
|
+
let result = scopeResults[index]
|
|
265
|
+
let pending = pendingBareImportScopes[index]
|
|
266
|
+
if (!result.ok) {
|
|
267
|
+
return failResolve(
|
|
268
|
+
result.error,
|
|
269
|
+
trackedFiles,
|
|
270
|
+
trackedResolutions,
|
|
271
|
+
transformed.resolvedPath,
|
|
272
|
+
{
|
|
273
|
+
isWatchIgnored: args.isWatchIgnored,
|
|
274
|
+
trackedResolution: pending.trackedResolution,
|
|
275
|
+
},
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
pending.imported.scopePathname = result.scopePathname
|
|
279
|
+
}
|
|
225
280
|
}
|
|
226
281
|
|
|
227
282
|
for (let unresolved of transformed.hmr.acceptedDeps) {
|
|
@@ -254,7 +309,7 @@ export async function resolveModule(
|
|
|
254
309
|
return failResolve(
|
|
255
310
|
createAssetServerCompilationError(
|
|
256
311
|
`Failed to resolve accepted HMR dependency "${displaySpecifier}" in ${transformed.resolvedPath}. ` +
|
|
257
|
-
`Ensure it resolves to a file within
|
|
312
|
+
`Ensure it resolves to a file within a configured asset server mount, or mark it as external.`,
|
|
258
313
|
{
|
|
259
314
|
code: 'IMPORT_RESOLUTION_FAILED',
|
|
260
315
|
},
|
|
@@ -303,10 +358,10 @@ export async function resolveModule(
|
|
|
303
358
|
if (!stableUrlPathname) {
|
|
304
359
|
return failResolve(
|
|
305
360
|
createAssetServerCompilationError(
|
|
306
|
-
`Accepted HMR dependency "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured
|
|
307
|
-
`Add a matching
|
|
361
|
+
`Accepted HMR dependency "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured mounts. ` +
|
|
362
|
+
`Add a matching mount for this file path, or mark this import as external.`,
|
|
308
363
|
{
|
|
309
|
-
code: '
|
|
364
|
+
code: 'IMPORT_OUTSIDE_MOUNTS',
|
|
310
365
|
},
|
|
311
366
|
),
|
|
312
367
|
trackedFiles,
|
|
@@ -324,9 +379,11 @@ export async function resolveModule(
|
|
|
324
379
|
}
|
|
325
380
|
|
|
326
381
|
acceptedDepsWithPaths.push({
|
|
382
|
+
compiledSpecifier: unresolved.specifier,
|
|
327
383
|
depPath: resolvedImport.identityPath,
|
|
328
384
|
end: unresolved.end,
|
|
329
385
|
quote: unresolved.quote,
|
|
386
|
+
specifier: displaySpecifier,
|
|
330
387
|
start: unresolved.start,
|
|
331
388
|
})
|
|
332
389
|
}
|
|
@@ -336,7 +393,6 @@ export async function resolveModule(
|
|
|
336
393
|
tracking: toResolveTracking(trackedFiles, trackedResolutions),
|
|
337
394
|
value: {
|
|
338
395
|
deps: [...deps],
|
|
339
|
-
fingerprint: transformed.fingerprint,
|
|
340
396
|
hmr: {
|
|
341
397
|
acceptedDeps: acceptedDepsWithPaths,
|
|
342
398
|
selfAccepting: transformed.hmr.selfAccepting,
|
|
@@ -348,11 +404,117 @@ export async function resolveModule(
|
|
|
348
404
|
rawCode: transformed.rawCode,
|
|
349
405
|
resolvedPath: transformed.resolvedPath,
|
|
350
406
|
sourceMap: transformed.sourceMap,
|
|
407
|
+
staticDeps: [...staticDeps],
|
|
351
408
|
stableUrlPathname: transformed.stableUrlPathname,
|
|
352
409
|
},
|
|
353
410
|
}
|
|
354
411
|
}
|
|
355
412
|
|
|
413
|
+
async function resolveBareImportScopes(
|
|
414
|
+
pendingScopes: PendingBareImportScope[],
|
|
415
|
+
importerPath: string,
|
|
416
|
+
args: ResolveArgs,
|
|
417
|
+
): Promise<
|
|
418
|
+
({ ok: true; scopePathname: string } | { ok: false; error: AssetServerCompilationError })[]
|
|
419
|
+
> {
|
|
420
|
+
let results = new Array<
|
|
421
|
+
{ ok: true; scopePathname: string } | { ok: false; error: AssetServerCompilationError }
|
|
422
|
+
>(pendingScopes.length)
|
|
423
|
+
let nextIndex = 0
|
|
424
|
+
|
|
425
|
+
async function worker(): Promise<void> {
|
|
426
|
+
while (nextIndex < pendingScopes.length) {
|
|
427
|
+
let index = nextIndex++
|
|
428
|
+
let pending = pendingScopes[index]
|
|
429
|
+
try {
|
|
430
|
+
results[index] = {
|
|
431
|
+
ok: true,
|
|
432
|
+
scopePathname: await getBareImportScopePathname({
|
|
433
|
+
importerPath,
|
|
434
|
+
resolvedIdentityPath: pending.resolvedIdentityPath,
|
|
435
|
+
specifier: pending.specifier,
|
|
436
|
+
...args,
|
|
437
|
+
}),
|
|
438
|
+
}
|
|
439
|
+
} catch (error) {
|
|
440
|
+
results[index] = {
|
|
441
|
+
ok: false,
|
|
442
|
+
error: isAssetServerCompilationError(error)
|
|
443
|
+
? error
|
|
444
|
+
: createAssetServerCompilationError(
|
|
445
|
+
`Failed to determine an import map scope for "${pending.imported.specifier}" in ${importerPath}. ${formatUnknownError(error)}`,
|
|
446
|
+
{ cause: error, code: 'IMPORT_RESOLUTION_FAILED' },
|
|
447
|
+
),
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (pendingScopes.length === 1) {
|
|
454
|
+
await worker()
|
|
455
|
+
} else {
|
|
456
|
+
await Promise.all(
|
|
457
|
+
Array.from({ length: Math.min(args.concurrency, pendingScopes.length) }, () => worker()),
|
|
458
|
+
)
|
|
459
|
+
}
|
|
460
|
+
return results
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async function getBareImportScopePathname(args: {
|
|
464
|
+
importerPath: string
|
|
465
|
+
isDirectoryResolutionFileIndependent(directory: string): boolean
|
|
466
|
+
resolvedIdentityPath: string
|
|
467
|
+
resolveDirectorySpecifierIdentity(directory: string, specifier: string): Promise<string | null>
|
|
468
|
+
routes: CompiledRoutes
|
|
469
|
+
specifier: string
|
|
470
|
+
}): Promise<string> {
|
|
471
|
+
let importerDirectory = normalizeFilePath(path.dirname(args.importerPath))
|
|
472
|
+
let importerScopePathname = args.routes.toUrlPathname(importerDirectory)
|
|
473
|
+
if (!importerScopePathname) {
|
|
474
|
+
throw new Error(`Expected a URL pathname for ${importerDirectory}`)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
let importerDirectoryResolution: string | null = args.resolvedIdentityPath
|
|
478
|
+
if (!args.isDirectoryResolutionFileIndependent(importerDirectory)) {
|
|
479
|
+
importerDirectoryResolution = await args.resolveDirectorySpecifierIdentity(
|
|
480
|
+
importerDirectory,
|
|
481
|
+
args.specifier,
|
|
482
|
+
)
|
|
483
|
+
if (importerDirectoryResolution !== args.resolvedIdentityPath) {
|
|
484
|
+
throw createAssetServerCompilationError(
|
|
485
|
+
`Bare import "${args.specifier}" in ${args.importerPath} resolves differently based on the importer file. ` +
|
|
486
|
+
`Browser module resolution must be uniform for all files in the same directory.`,
|
|
487
|
+
{ code: 'IMPORT_RESOLUTION_NOT_DIRECTORY_UNIFORM' },
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
let directory = importerDirectory
|
|
493
|
+
let scopePathname = importerScopePathname
|
|
494
|
+
let broadestScopePathname = importerScopePathname
|
|
495
|
+
while (true) {
|
|
496
|
+
let resolvedIdentityPath =
|
|
497
|
+
directory === importerDirectory
|
|
498
|
+
? importerDirectoryResolution
|
|
499
|
+
: await args.resolveDirectorySpecifierIdentity(directory, args.specifier)
|
|
500
|
+
if (resolvedIdentityPath !== args.resolvedIdentityPath) break
|
|
501
|
+
|
|
502
|
+
broadestScopePathname = scopePathname
|
|
503
|
+
let parentDirectory = normalizeFilePath(path.dirname(directory))
|
|
504
|
+
if (parentDirectory === directory) break
|
|
505
|
+
let parentScopePathname = args.routes.toUrlPathname(parentDirectory)
|
|
506
|
+
if (!parentScopePathname) break
|
|
507
|
+
directory = parentDirectory
|
|
508
|
+
scopePathname = parentScopePathname
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return ensureTrailingSlash(broadestScopePathname)
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function ensureTrailingSlash(value: string): string {
|
|
515
|
+
return value.endsWith('/') ? value : `${value}/`
|
|
516
|
+
}
|
|
517
|
+
|
|
356
518
|
function findNearestPackageJsonPath(filePath: string): string | null {
|
|
357
519
|
let directory = path.dirname(filePath)
|
|
358
520
|
|
|
@@ -462,7 +624,7 @@ async function batchResolveSpecifiers(
|
|
|
462
624
|
normalizedResolution.importerPath === getInjectedPackageImporterPath()
|
|
463
625
|
? `Failed to resolve injected import "${specifier}" from asset server.`
|
|
464
626
|
: `Failed to resolve import "${normalizedResolution.specifier}" in ${normalizedResolution.importerPath}. ` +
|
|
465
|
-
`Ensure it resolves to a file within
|
|
627
|
+
`Ensure it resolves to a file within a configured asset server mount, or mark it as external.`,
|
|
466
628
|
{
|
|
467
629
|
code: 'IMPORT_RESOLUTION_FAILED',
|
|
468
630
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function isBareImportSpecifier(specifier: string): boolean {
|
|
2
|
+
return (
|
|
3
|
+
!specifier.startsWith('./') &&
|
|
4
|
+
!specifier.startsWith('../') &&
|
|
5
|
+
!specifier.startsWith('/') &&
|
|
6
|
+
!specifier.startsWith('file:') &&
|
|
7
|
+
!specifier.startsWith('data:') &&
|
|
8
|
+
!specifier.startsWith('http://') &&
|
|
9
|
+
!specifier.startsWith('https://')
|
|
10
|
+
)
|
|
11
|
+
}
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
isAssetServerCompilationError,
|
|
19
19
|
} from '../compilation-error.ts'
|
|
20
20
|
import type { AssetServerCompilationError } from '../compilation-error.ts'
|
|
21
|
-
import { generateFingerprint } from '../fingerprint.ts'
|
|
22
21
|
import {
|
|
23
22
|
maskAuthoredInjectedPackageSpecifier,
|
|
24
23
|
mayContainInjectedPackageSpecifier,
|
|
@@ -38,6 +37,7 @@ import type { EmittedModule } from './emit.ts'
|
|
|
38
37
|
import type { ResolvedScriptTarget } from '../target.ts'
|
|
39
38
|
import type { ResolvedModule } from './resolve.ts'
|
|
40
39
|
import { scriptLoaderConditions } from './conditions.ts'
|
|
40
|
+
import { isBareImportSpecifier } from './specifiers.ts'
|
|
41
41
|
|
|
42
42
|
type ScriptRecord = ModuleRecord<TransformedModule, ResolvedModule, EmittedModule>
|
|
43
43
|
|
|
@@ -74,16 +74,16 @@ export type ResolveModuleResult = {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
type UnresolvedImport = {
|
|
77
|
+
dynamic: boolean
|
|
77
78
|
end: number
|
|
78
79
|
quote?: '"' | "'" | '`'
|
|
79
80
|
specifier: string
|
|
80
81
|
start: number
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
type HmrAcceptedDependency = UnresolvedImport
|
|
84
|
+
type HmrAcceptedDependency = Omit<UnresolvedImport, 'dynamic'>
|
|
84
85
|
|
|
85
86
|
export type TransformedModule = {
|
|
86
|
-
fingerprint: string | null
|
|
87
87
|
hmr: {
|
|
88
88
|
acceptedDeps: HmrAcceptedDependency[]
|
|
89
89
|
selfAccepting: boolean
|
|
@@ -121,7 +121,6 @@ type TsconfigTransformOptions = {
|
|
|
121
121
|
type TsconfigTransformOptionsResolver = ReturnType<typeof createTsconfigTransformOptionsResolver>
|
|
122
122
|
|
|
123
123
|
export type TransformArgs = {
|
|
124
|
-
buildId: string | null
|
|
125
124
|
define: Record<string, string> | null
|
|
126
125
|
externalSet: ReadonlySet<string>
|
|
127
126
|
isWatchIgnored(filePath: string): boolean
|
|
@@ -225,9 +224,9 @@ export async function transformModule(
|
|
|
225
224
|
let stableUrlPathname = args.routes.toUrlPathname(record.identityPath)
|
|
226
225
|
if (!stableUrlPathname) {
|
|
227
226
|
throw createAssetServerCompilationError(
|
|
228
|
-
`File ${record.identityPath} is outside all configured
|
|
227
|
+
`File ${record.identityPath} is outside all configured mounts.`,
|
|
229
228
|
{
|
|
230
|
-
code: '
|
|
229
|
+
code: 'FILE_OUTSIDE_MOUNTS',
|
|
231
230
|
},
|
|
232
231
|
)
|
|
233
232
|
}
|
|
@@ -272,13 +271,6 @@ export async function transformModule(
|
|
|
272
271
|
trackedFiles,
|
|
273
272
|
},
|
|
274
273
|
value: {
|
|
275
|
-
fingerprint:
|
|
276
|
-
args.buildId === null
|
|
277
|
-
? null
|
|
278
|
-
: await generateFingerprint({
|
|
279
|
-
buildId: args.buildId,
|
|
280
|
-
content: sourceText,
|
|
281
|
-
}),
|
|
282
274
|
hmr: getHmrAnalysis(analysis.rawCode),
|
|
283
275
|
identityPath: record.identityPath,
|
|
284
276
|
importerDir: path.dirname(resolvedPath),
|
|
@@ -434,18 +426,6 @@ function findNearestTsconfigPath(directory: string): string | null {
|
|
|
434
426
|
}
|
|
435
427
|
}
|
|
436
428
|
|
|
437
|
-
function isBareImportSpecifier(specifier: string): boolean {
|
|
438
|
-
return (
|
|
439
|
-
!specifier.startsWith('./') &&
|
|
440
|
-
!specifier.startsWith('../') &&
|
|
441
|
-
!specifier.startsWith('/') &&
|
|
442
|
-
!specifier.startsWith('file:') &&
|
|
443
|
-
!specifier.startsWith('data:') &&
|
|
444
|
-
!specifier.startsWith('http://') &&
|
|
445
|
-
!specifier.startsWith('https://')
|
|
446
|
-
)
|
|
447
|
-
}
|
|
448
|
-
|
|
449
429
|
async function analyzeModuleSource(
|
|
450
430
|
sourceText: string,
|
|
451
431
|
resolvedPath: string,
|
|
@@ -823,6 +803,7 @@ async function getUnresolvedImportsFromLexer(rawCode: string): Promise<Unresolve
|
|
|
823
803
|
let specifier = getStaticImportSpecifier(rawCode, imported)
|
|
824
804
|
if (specifier == null || isBrowserExternalModuleUrl(specifier)) continue
|
|
825
805
|
unresolvedImports.push({
|
|
806
|
+
dynamic: imported.d !== -1,
|
|
826
807
|
specifier,
|
|
827
808
|
start: imported.s,
|
|
828
809
|
end: imported.e,
|