@remix-run/assets 0.4.4 → 0.6.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.
Files changed (83) hide show
  1. package/README.md +331 -72
  2. package/dist/assets.d.ts +4 -1
  3. package/dist/assets.d.ts.map +1 -1
  4. package/dist/assets.js +2 -2
  5. package/dist/lib/access.d.ts +35 -4
  6. package/dist/lib/access.d.ts.map +1 -1
  7. package/dist/lib/access.js +332 -11
  8. package/dist/lib/asset-server.d.ts +138 -11
  9. package/dist/lib/asset-server.d.ts.map +1 -1
  10. package/dist/lib/asset-server.js +281 -30
  11. package/dist/lib/compilation-error.d.ts +1 -1
  12. package/dist/lib/compilation-error.d.ts.map +1 -1
  13. package/dist/lib/file-matcher.js +1 -1
  14. package/dist/lib/files/compiler.d.ts.map +1 -1
  15. package/dist/lib/files/compiler.js +9 -8
  16. package/dist/lib/files/config.js +1 -1
  17. package/dist/lib/hmr.d.ts +37 -0
  18. package/dist/lib/hmr.d.ts.map +1 -0
  19. package/dist/lib/hmr.js +357 -0
  20. package/dist/lib/injected-packages.d.ts +3 -2
  21. package/dist/lib/injected-packages.d.ts.map +1 -1
  22. package/dist/lib/injected-packages.js +43 -17
  23. package/dist/lib/inspection.d.ts +39 -0
  24. package/dist/lib/inspection.d.ts.map +1 -0
  25. package/dist/lib/inspection.js +160 -0
  26. package/dist/lib/loaders.d.ts +57 -0
  27. package/dist/lib/loaders.d.ts.map +1 -0
  28. package/dist/lib/loaders.js +1 -0
  29. package/dist/lib/module-store.d.ts +24 -0
  30. package/dist/lib/module-store.d.ts.map +1 -1
  31. package/dist/lib/module-store.js +136 -11
  32. package/dist/lib/routes.d.ts +11 -3
  33. package/dist/lib/routes.d.ts.map +1 -1
  34. package/dist/lib/routes.js +124 -80
  35. package/dist/lib/scripts/compiler.d.ts +24 -1
  36. package/dist/lib/scripts/compiler.d.ts.map +1 -1
  37. package/dist/lib/scripts/compiler.js +183 -29
  38. package/dist/lib/scripts/conditions.d.ts +2 -0
  39. package/dist/lib/scripts/conditions.d.ts.map +1 -0
  40. package/dist/lib/scripts/conditions.js +1 -0
  41. package/dist/lib/scripts/emit.d.ts +3 -0
  42. package/dist/lib/scripts/emit.d.ts.map +1 -1
  43. package/dist/lib/scripts/emit.js +24 -5
  44. package/dist/lib/scripts/resolve.d.ts +4 -0
  45. package/dist/lib/scripts/resolve.d.ts.map +1 -1
  46. package/dist/lib/scripts/resolve.js +75 -10
  47. package/dist/lib/scripts/transform.d.ts +9 -0
  48. package/dist/lib/scripts/transform.d.ts.map +1 -1
  49. package/dist/lib/scripts/transform.js +222 -18
  50. package/dist/lib/source-maps.js +1 -1
  51. package/dist/lib/styles/compiler.d.ts +14 -1
  52. package/dist/lib/styles/compiler.d.ts.map +1 -1
  53. package/dist/lib/styles/compiler.js +78 -14
  54. package/dist/lib/styles/emit.js +4 -4
  55. package/dist/lib/styles/resolve.d.ts.map +1 -1
  56. package/dist/lib/styles/resolve.js +16 -15
  57. package/dist/lib/styles/transform.js +5 -5
  58. package/dist/lib/target.d.ts +1 -1
  59. package/dist/lib/target.d.ts.map +1 -1
  60. package/dist/lib/watch.js +1 -1
  61. package/dist/types/hmr.d.ts +36 -0
  62. package/package.json +16 -11
  63. package/src/assets.ts +4 -1
  64. package/src/lib/access.ts +445 -11
  65. package/src/lib/asset-server.ts +466 -27
  66. package/src/lib/compilation-error.ts +4 -3
  67. package/src/lib/files/compiler.ts +9 -5
  68. package/src/lib/hmr.ts +397 -0
  69. package/src/lib/injected-packages.ts +52 -16
  70. package/src/lib/inspection.ts +229 -0
  71. package/src/lib/loaders.ts +80 -0
  72. package/src/lib/module-store.ts +190 -9
  73. package/src/lib/routes.ts +158 -126
  74. package/src/lib/scripts/compiler.ts +248 -24
  75. package/src/lib/scripts/conditions.ts +1 -0
  76. package/src/lib/scripts/emit.ts +50 -5
  77. package/src/lib/scripts/resolve.ts +129 -7
  78. package/src/lib/scripts/transform.ts +290 -19
  79. package/src/lib/styles/compiler.ts +108 -8
  80. package/src/lib/styles/emit.ts +1 -1
  81. package/src/lib/styles/resolve.ts +19 -15
  82. package/src/lib/styles/transform.ts +2 -2
  83. package/src/types/hmr.d.ts +36 -0
@@ -163,17 +163,21 @@ export function resolveServedStyleOrThrow(
163
163
  }
164
164
 
165
165
  if (!args.isAllowed(identityPath)) {
166
- throw createAssetServerCompilationError(`File is not allowed: ${identityPath}`, {
167
- code: 'FILE_NOT_ALLOWED',
168
- })
166
+ throw createAssetServerCompilationError(
167
+ `File "${identityPath}" is not allowed by the asset server access configuration. ` +
168
+ `Add a matching allowFiles or allowPackages rule, or remove a conflicting denyFiles rule.`,
169
+ {
170
+ code: 'FILE_NOT_ALLOWED',
171
+ },
172
+ )
169
173
  }
170
174
 
171
175
  let stableUrlPathname = args.routes.toUrlPathname(identityPath)
172
176
  if (!stableUrlPathname) {
173
177
  throw createAssetServerCompilationError(
174
- `File ${identityPath} is outside all configured fileMap entries.`,
178
+ `File ${identityPath} is outside all configured mounts.`,
175
179
  {
176
- code: 'FILE_OUTSIDE_FILE_MAP',
180
+ code: 'FILE_OUTSIDE_MOUNTS',
177
181
  },
178
182
  )
179
183
  }
@@ -218,8 +222,8 @@ function resolveImportDependency(
218
222
 
219
223
  if (!args.isAllowed(identityPath)) {
220
224
  throw createAssetServerCompilationError(
221
- `Import "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server allow/deny configuration. ` +
222
- `Add a matching allow rule for this file path, remove a conflicting deny rule for this file path, or mark this import as external.`,
225
+ `Import "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server access configuration. ` +
226
+ `Add a matching allowFiles or allowPackages rule, remove a conflicting denyFiles rule, or mark this import as external.`,
223
227
  {
224
228
  code: 'IMPORT_NOT_ALLOWED',
225
229
  },
@@ -228,10 +232,10 @@ function resolveImportDependency(
228
232
 
229
233
  if (!args.routes.toUrlPathname(identityPath)) {
230
234
  throw createAssetServerCompilationError(
231
- `Import "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured fileMap entries. ` +
232
- `Add a matching fileMap entry for this file path, or mark this import as external.`,
235
+ `Import "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured mounts. ` +
236
+ `Add a matching mount for this file path, or mark this import as external.`,
233
237
  {
234
- code: 'IMPORT_OUTSIDE_FILE_MAP',
238
+ code: 'IMPORT_OUTSIDE_MOUNTS',
235
239
  },
236
240
  )
237
241
  }
@@ -288,8 +292,8 @@ function resolveUrlDependency(
288
292
 
289
293
  if (!args.isAllowed(identityPath)) {
290
294
  throw createAssetServerCompilationError(
291
- `URL "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server allow/deny configuration. ` +
292
- `Add a matching allow rule for this file path or remove a conflicting deny rule for this file path.`,
295
+ `URL "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server access configuration. ` +
296
+ `Add a matching allowFiles or allowPackages rule, or remove a conflicting denyFiles rule.`,
293
297
  {
294
298
  code: 'URL_NOT_ALLOWED',
295
299
  },
@@ -298,10 +302,10 @@ function resolveUrlDependency(
298
302
 
299
303
  if (!args.routes.toUrlPathname(identityPath)) {
300
304
  throw createAssetServerCompilationError(
301
- `URL "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured fileMap entries. ` +
302
- `Add a matching fileMap entry for this file path.`,
305
+ `URL "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured mounts. ` +
306
+ `Add a matching mount for this file path.`,
303
307
  {
304
- code: 'URL_OUTSIDE_FILE_MAP',
308
+ code: 'URL_OUTSIDE_MOUNTS',
305
309
  },
306
310
  )
307
311
  }
@@ -99,9 +99,9 @@ export async function transformStyle(
99
99
  let stableUrlPathname = args.routes.toUrlPathname(record.identityPath)
100
100
  if (!stableUrlPathname) {
101
101
  throw createAssetServerCompilationError(
102
- `File ${record.identityPath} is outside all configured fileMap entries.`,
102
+ `File ${record.identityPath} is outside all configured mounts.`,
103
103
  {
104
- code: 'FILE_OUTSIDE_FILE_MAP',
104
+ code: 'FILE_OUTSIDE_MOUNTS',
105
105
  },
106
106
  )
107
107
  }
@@ -0,0 +1,36 @@
1
+ interface ImportMetaHot {
2
+ /** Mutable state preserved for this module across accepted updates and passed to dispose handlers. */
3
+ readonly data: Record<string, unknown>
4
+ /** Accepts updates to this module, optionally receiving its newly evaluated namespace. */
5
+ accept(callback?: (module: HotModule) => HotCallbackResult): void
6
+ /** Accepts updates from one dependency, optionally receiving its newly evaluated namespace. */
7
+ accept(dep: string, callback?: (module: HotModule) => HotCallbackResult): void
8
+ /**
9
+ * Accepts updates from multiple dependencies. The callback array preserves `deps` order and
10
+ * contains the updated namespace only at the position of the dependency that changed.
11
+ */
12
+ accept(
13
+ deps: readonly string[],
14
+ callback?: (modules: Array<HotModule | undefined>) => HotCallbackResult,
15
+ ): void
16
+ /** Registers cleanup that runs before this module is re-evaluated or the runtime is disposed. */
17
+ dispose(callback: (data: Record<string, unknown>) => HotCallbackResult): void
18
+ /** Declines the current update and reloads the page if no importing boundary accepts it. */
19
+ invalidate(message?: string): void
20
+ /** Registers a listener for custom events from the browser HMR channel. */
21
+ on(event: string, callback: (data: unknown) => void | Promise<void>): void
22
+ }
23
+
24
+ type HotModule = Readonly<Record<string, unknown>> & {
25
+ readonly [Symbol.toStringTag]: 'Module'
26
+ }
27
+
28
+ type HotCallbackResult = void | Promise<void>
29
+
30
+ declare global {
31
+ interface ImportMeta {
32
+ readonly hot?: ImportMetaHot
33
+ }
34
+ }
35
+
36
+ export {}