@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.
- package/README.md +331 -72
- package/dist/assets.d.ts +4 -1
- package/dist/assets.d.ts.map +1 -1
- package/dist/assets.js +2 -2
- package/dist/lib/access.d.ts +35 -4
- package/dist/lib/access.d.ts.map +1 -1
- package/dist/lib/access.js +332 -11
- package/dist/lib/asset-server.d.ts +138 -11
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +281 -30
- package/dist/lib/compilation-error.d.ts +1 -1
- package/dist/lib/compilation-error.d.ts.map +1 -1
- package/dist/lib/file-matcher.js +1 -1
- package/dist/lib/files/compiler.d.ts.map +1 -1
- package/dist/lib/files/compiler.js +9 -8
- package/dist/lib/files/config.js +1 -1
- package/dist/lib/hmr.d.ts +37 -0
- package/dist/lib/hmr.d.ts.map +1 -0
- package/dist/lib/hmr.js +357 -0
- 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 +43 -17
- 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/loaders.d.ts +57 -0
- package/dist/lib/loaders.d.ts.map +1 -0
- package/dist/lib/loaders.js +1 -0
- package/dist/lib/module-store.d.ts +24 -0
- package/dist/lib/module-store.d.ts.map +1 -1
- package/dist/lib/module-store.js +136 -11
- package/dist/lib/routes.d.ts +11 -3
- package/dist/lib/routes.d.ts.map +1 -1
- package/dist/lib/routes.js +124 -80
- package/dist/lib/scripts/compiler.d.ts +24 -1
- package/dist/lib/scripts/compiler.d.ts.map +1 -1
- package/dist/lib/scripts/compiler.js +183 -29
- package/dist/lib/scripts/conditions.d.ts +2 -0
- package/dist/lib/scripts/conditions.d.ts.map +1 -0
- package/dist/lib/scripts/conditions.js +1 -0
- package/dist/lib/scripts/emit.d.ts +3 -0
- package/dist/lib/scripts/emit.d.ts.map +1 -1
- package/dist/lib/scripts/emit.js +24 -5
- package/dist/lib/scripts/resolve.d.ts +4 -0
- package/dist/lib/scripts/resolve.d.ts.map +1 -1
- package/dist/lib/scripts/resolve.js +75 -10
- package/dist/lib/scripts/transform.d.ts +9 -0
- package/dist/lib/scripts/transform.d.ts.map +1 -1
- package/dist/lib/scripts/transform.js +222 -18
- package/dist/lib/source-maps.js +1 -1
- package/dist/lib/styles/compiler.d.ts +14 -1
- package/dist/lib/styles/compiler.d.ts.map +1 -1
- package/dist/lib/styles/compiler.js +78 -14
- package/dist/lib/styles/emit.js +4 -4
- package/dist/lib/styles/resolve.d.ts.map +1 -1
- package/dist/lib/styles/resolve.js +16 -15
- package/dist/lib/styles/transform.js +5 -5
- package/dist/lib/target.d.ts +1 -1
- package/dist/lib/target.d.ts.map +1 -1
- package/dist/lib/watch.js +1 -1
- package/dist/types/hmr.d.ts +36 -0
- package/package.json +16 -11
- package/src/assets.ts +4 -1
- package/src/lib/access.ts +445 -11
- package/src/lib/asset-server.ts +466 -27
- package/src/lib/compilation-error.ts +4 -3
- package/src/lib/files/compiler.ts +9 -5
- package/src/lib/hmr.ts +397 -0
- package/src/lib/injected-packages.ts +52 -16
- package/src/lib/inspection.ts +229 -0
- package/src/lib/loaders.ts +80 -0
- package/src/lib/module-store.ts +190 -9
- package/src/lib/routes.ts +158 -126
- package/src/lib/scripts/compiler.ts +248 -24
- package/src/lib/scripts/conditions.ts +1 -0
- package/src/lib/scripts/emit.ts +50 -5
- package/src/lib/scripts/resolve.ts +129 -7
- package/src/lib/scripts/transform.ts +290 -19
- package/src/lib/styles/compiler.ts +108 -8
- package/src/lib/styles/emit.ts +1 -1
- package/src/lib/styles/resolve.ts +19 -15
- package/src/lib/styles/transform.ts +2 -2
- package/src/types/hmr.d.ts +36 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import { createAssetServerCompilationError, isAssetServerCompilationError, } from
|
|
5
|
-
import { normalizeFilePath } from
|
|
4
|
+
import { createAssetServerCompilationError, isAssetServerCompilationError, } from '../compilation-error.js';
|
|
5
|
+
import { normalizeFilePath } from '../paths.js';
|
|
6
6
|
export async function resolveStyle(record, transformed, args) {
|
|
7
7
|
let trackedFiles = new Set(transformed.trackedFiles);
|
|
8
8
|
let dependencies = [];
|
|
@@ -63,14 +63,15 @@ export function resolveServedStyleOrThrow(filePath, args) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
if (!args.isAllowed(identityPath)) {
|
|
66
|
-
throw createAssetServerCompilationError(`File is not allowed
|
|
66
|
+
throw createAssetServerCompilationError(`File "${identityPath}" is not allowed by the asset server access configuration. ` +
|
|
67
|
+
`Add a matching allowFiles or allowPackages rule, or remove a conflicting denyFiles rule.`, {
|
|
67
68
|
code: 'FILE_NOT_ALLOWED',
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
let stableUrlPathname = args.routes.toUrlPathname(identityPath);
|
|
71
72
|
if (!stableUrlPathname) {
|
|
72
|
-
throw createAssetServerCompilationError(`File ${identityPath} is outside all configured
|
|
73
|
-
code: '
|
|
73
|
+
throw createAssetServerCompilationError(`File ${identityPath} is outside all configured mounts.`, {
|
|
74
|
+
code: 'FILE_OUTSIDE_MOUNTS',
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
return { identityPath, stableUrlPathname };
|
|
@@ -100,15 +101,15 @@ function resolveImportDependency(url, importerPath, placeholder, args) {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
if (!args.isAllowed(identityPath)) {
|
|
103
|
-
throw createAssetServerCompilationError(`Import "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server
|
|
104
|
-
`Add a matching
|
|
104
|
+
throw createAssetServerCompilationError(`Import "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server access configuration. ` +
|
|
105
|
+
`Add a matching allowFiles or allowPackages rule, remove a conflicting denyFiles rule, or mark this import as external.`, {
|
|
105
106
|
code: 'IMPORT_NOT_ALLOWED',
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
if (!args.routes.toUrlPathname(identityPath)) {
|
|
109
|
-
throw createAssetServerCompilationError(`Import "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured
|
|
110
|
-
`Add a matching
|
|
111
|
-
code: '
|
|
110
|
+
throw createAssetServerCompilationError(`Import "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured mounts. ` +
|
|
111
|
+
`Add a matching mount for this file path, or mark this import as external.`, {
|
|
112
|
+
code: 'IMPORT_OUTSIDE_MOUNTS',
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
return {
|
|
@@ -149,15 +150,15 @@ function resolveUrlDependency(url, importerPath, placeholder, args) {
|
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
if (!args.isAllowed(identityPath)) {
|
|
152
|
-
throw createAssetServerCompilationError(`URL "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server
|
|
153
|
-
`Add a matching
|
|
153
|
+
throw createAssetServerCompilationError(`URL "${url}" in ${importerPath}, resolved to "${identityPath}", is not allowed by the asset server access configuration. ` +
|
|
154
|
+
`Add a matching allowFiles or allowPackages rule, or remove a conflicting denyFiles rule.`, {
|
|
154
155
|
code: 'URL_NOT_ALLOWED',
|
|
155
156
|
});
|
|
156
157
|
}
|
|
157
158
|
if (!args.routes.toUrlPathname(identityPath)) {
|
|
158
|
-
throw createAssetServerCompilationError(`URL "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured
|
|
159
|
-
`Add a matching
|
|
160
|
-
code: '
|
|
159
|
+
throw createAssetServerCompilationError(`URL "${url}" in ${importerPath}, resolved to "${identityPath}", is outside all configured mounts. ` +
|
|
160
|
+
`Add a matching mount for this file path.`, {
|
|
161
|
+
code: 'URL_OUTSIDE_MOUNTS',
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
let parsedRequest = parseResolvedFileRequest({ hash, search });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import { transform } from 'lightningcss';
|
|
3
|
-
import { createAssetServerCompilationError, isAssetServerCompilationError, } from
|
|
4
|
-
import { generateFingerprint } from
|
|
5
|
-
import { rewriteSourceMapSources, stringifySourceMap } from
|
|
3
|
+
import { createAssetServerCompilationError, isAssetServerCompilationError, } from '../compilation-error.js';
|
|
4
|
+
import { generateFingerprint } from '../fingerprint.js';
|
|
5
|
+
import { rewriteSourceMapSources, stringifySourceMap } from '../source-maps.js';
|
|
6
6
|
export async function transformStyle(record, args) {
|
|
7
7
|
let resolvedPath = record.identityPath;
|
|
8
8
|
let trackedFiles = args.isWatchIgnored(resolvedPath) ? [] : [resolvedPath];
|
|
@@ -34,8 +34,8 @@ export async function transformStyle(record, args) {
|
|
|
34
34
|
try {
|
|
35
35
|
let stableUrlPathname = args.routes.toUrlPathname(record.identityPath);
|
|
36
36
|
if (!stableUrlPathname) {
|
|
37
|
-
throw createAssetServerCompilationError(`File ${record.identityPath} is outside all configured
|
|
38
|
-
code: '
|
|
37
|
+
throw createAssetServerCompilationError(`File ${record.identityPath} is outside all configured mounts.`, {
|
|
38
|
+
code: 'FILE_OUTSIDE_MOUNTS',
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
let transformResult = runLightningTransform(resolvedPath, rawBytes, {
|
package/dist/lib/target.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Targets as LightningCssTargets } from 'lightningcss';
|
|
2
|
-
declare const browserTargetNames: readonly [
|
|
2
|
+
declare const browserTargetNames: readonly ['chrome', 'edge', 'firefox', 'ie', 'ios', 'opera', 'safari', 'samsung'];
|
|
3
3
|
export type AssetTargetVersion = `${number}` | `${number}.${number}` | `${number}.${number}.${number}`;
|
|
4
4
|
export type BrowserTargetName = (typeof browserTargetNames)[number];
|
|
5
5
|
export type ResolvedScriptTarget = string[];
|
package/dist/lib/target.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/lib/target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElE,QAAA,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/lib/target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElE,QAAA,MAAM,kBAAkB,YACtB,QAAQ,EACR,MAAM,EACN,SAAS,EACT,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,SAAS,CACD,CAAA;AAeV,MAAM,MAAM,kBAAkB,GAC1B,GAAG,MAAM,EAAE,GACX,GAAG,MAAM,IAAI,MAAM,EAAE,GACrB,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAA;AACnC,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AACnE,MAAM,MAAM,oBAAoB,GAAG,MAAM,EAAE,CAAA;AAC3C,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAA;AAErD,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,EAAE,CAAC,EAAE,kBAAkB,CAAA;IACvB,GAAG,CAAC,EAAE,kBAAkB,CAAA;IACxB,KAAK,CAAC,EAAE,kBAAkB,CAAA;IAC1B,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAMD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,oBAAoB,GAAG,SAAS,CAgBlC;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,mBAAmB,GAAG,SAAS,CAajC"}
|
package/dist/lib/watch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
|
-
import { getFilePathDirectory, normalizeFilePath } from
|
|
2
|
+
import { getFilePathDirectory, normalizeFilePath } from './paths.js';
|
|
3
3
|
export function createAssetServerWatcher(options) {
|
|
4
4
|
let watcher = chokidar.watch([], {
|
|
5
5
|
ignoreInitial: true,
|
|
@@ -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 {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/assets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Fetch-based server for compiling browser JS/TS and CSS assets on demand",
|
|
5
5
|
"author": "Michael Jackson <mjijackson@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"types": "./dist/assets.d.ts",
|
|
24
24
|
"default": "./dist/assets.js"
|
|
25
25
|
},
|
|
26
|
+
"./types/hmr": {
|
|
27
|
+
"types": "./dist/types/hmr.d.ts"
|
|
28
|
+
},
|
|
26
29
|
"./package.json": "./package.json"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
@@ -38,17 +41,19 @@
|
|
|
38
41
|
"oxc-transform": "^0.121.0",
|
|
39
42
|
"picomatch": "^4.0.4",
|
|
40
43
|
"source-map-js": "^1.2.1",
|
|
41
|
-
"@remix-run/
|
|
42
|
-
"@remix-run/
|
|
43
|
-
"@remix-run/
|
|
44
|
-
"@remix-run/mime": "0.4.2"
|
|
44
|
+
"@remix-run/file-storage": "^0.13.7",
|
|
45
|
+
"@remix-run/mime": "^0.4.2",
|
|
46
|
+
"@remix-run/headers": "^0.21.1"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/node": "^24.6.0",
|
|
48
50
|
"@types/picomatch": "^4.0.3",
|
|
49
|
-
"
|
|
51
|
+
"typescript": "^7.0.2",
|
|
52
|
+
"@remix-run/node-tsx": "^0.1.1",
|
|
53
|
+
"@remix-run/node-hmr": "^0.1.0",
|
|
50
54
|
"@remix-run/assert": "0.3.0",
|
|
51
|
-
"@remix-run/test": "0.
|
|
55
|
+
"@remix-run/test": "0.6.0",
|
|
56
|
+
"@remix-run/ui": "0.8.0"
|
|
52
57
|
},
|
|
53
58
|
"keywords": [
|
|
54
59
|
"remix",
|
|
@@ -61,10 +66,10 @@
|
|
|
61
66
|
],
|
|
62
67
|
"scripts": {
|
|
63
68
|
"bench": "pnpm --dir ./bench run bench",
|
|
64
|
-
"build": "
|
|
69
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-package-type-only-exports.ts .",
|
|
65
70
|
"clean": "git clean -fdX",
|
|
66
|
-
"test": "remix
|
|
67
|
-
"test:bun": "bun x --bun remix
|
|
68
|
-
"typecheck": "
|
|
71
|
+
"test": "remix test",
|
|
72
|
+
"test:bun": "bun x --bun remix test --type server",
|
|
73
|
+
"typecheck": "tsc --noEmit"
|
|
69
74
|
}
|
|
70
75
|
}
|
package/src/assets.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { createAssetServer } from './lib/asset-server.ts'
|
|
2
2
|
export { defineFileTransform } from './lib/files/config.ts'
|
|
3
|
-
export type {
|
|
3
|
+
export type { AssetAccessDetails, AssetAccessRule } from './lib/access.ts'
|
|
4
|
+
export type { AssetServer, AssetServerOptions, BrowserHmrChannel } from './lib/asset-server.ts'
|
|
5
|
+
export type { AssetDetails, AssetKind, AssetStatus } from './lib/inspection.ts'
|
|
6
|
+
export type { ModuleLoader } from './lib/loaders.ts'
|