@remix-run/assets 0.6.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 +101 -13
- package/dist/assets.d.ts +2 -1
- package/dist/assets.d.ts.map +1 -1
- package/dist/lib/asset-server.d.ts +41 -19
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +98 -41
- 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 +26 -29
- 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/routes.d.ts +1 -0
- package/dist/lib/routes.d.ts.map +1 -1
- package/dist/lib/routes.js +1 -1
- 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 +186 -36
- 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 +110 -3
- 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 +2 -16
- 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 +0 -1
- 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 +0 -7
- 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 -5
- package/src/assets.ts +7 -1
- package/src/lib/asset-server.ts +175 -73
- package/src/lib/compilation-error.ts +1 -0
- package/src/lib/files/compiler.ts +30 -40
- 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/routes.ts +1 -1
- package/src/lib/scripts/compiler.ts +238 -52
- package/src/lib/scripts/emit.ts +34 -19
- package/src/lib/scripts/resolve.ts +166 -4
- package/src/lib/scripts/specifiers.ts +11 -0
- package/src/lib/scripts/transform.ts +4 -23
- package/src/lib/styles/compiler.ts +137 -39
- package/src/lib/styles/emit.ts +18 -13
- package/src/lib/styles/resolve.ts +0 -2
- package/src/lib/styles/transform.ts +0 -10
- package/src/lib/virtual-store.ts +124 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import { transform } from 'lightningcss';
|
|
3
3
|
import { createAssetServerCompilationError, isAssetServerCompilationError, } from '../compilation-error.js';
|
|
4
|
-
import { generateFingerprint } from '../fingerprint.js';
|
|
5
4
|
import { rewriteSourceMapSources, stringifySourceMap } from '../source-maps.js';
|
|
6
5
|
export async function transformStyle(record, args) {
|
|
7
6
|
let resolvedPath = record.identityPath;
|
|
@@ -72,12 +71,6 @@ export async function transformStyle(record, args) {
|
|
|
72
71
|
trackedFiles,
|
|
73
72
|
},
|
|
74
73
|
value: {
|
|
75
|
-
fingerprint: args.buildId === null
|
|
76
|
-
? null
|
|
77
|
-
: await generateFingerprint({
|
|
78
|
-
buildId: args.buildId,
|
|
79
|
-
content: sourceText,
|
|
80
|
-
}),
|
|
81
74
|
identityPath: record.identityPath,
|
|
82
75
|
rawCode: Buffer.from(transformResult.code).toString('utf8'),
|
|
83
76
|
resolvedPath,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-store.d.ts","sourceRoot":"","sources":["../../src/lib/virtual-store.ts"],"names":[],"mappings":"AAkBA,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IACnD,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACxC,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG;IACF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB,EAAE,CAcF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { getFilePathBaseName, getFilePathDirectory, normalizeFilePath, resolveFilePath, } from './paths.js';
|
|
4
|
+
import { resolveMountFileRoot } from './routes.js';
|
|
5
|
+
const modulesStateFileName = '.modules.yaml';
|
|
6
|
+
const virtualStoreBasePath = '/__@remix/virtual-store';
|
|
7
|
+
const virtualStoreDirLineRE = /^virtualStoreDir:[ \t]*(.+)$/m;
|
|
8
|
+
// pnpm's global virtual store links packages from a machine-wide directory, so package realpaths
|
|
9
|
+
// land outside `rootDir` and would otherwise have no public URL. The store location comes from
|
|
10
|
+
// `node_modules/.modules.yaml`, which pnpm rewrites on every install.
|
|
11
|
+
export function getVirtualStoreMountConfigs(options) {
|
|
12
|
+
let virtualStoreDir = findVirtualStoreDir(options.rootDir);
|
|
13
|
+
if (virtualStoreDir === null)
|
|
14
|
+
return [];
|
|
15
|
+
// A store inside a mount, such as pnpm's default `node_modules/.pnpm`, already has URLs.
|
|
16
|
+
if (isWithinMounts(virtualStoreDir, options))
|
|
17
|
+
return [];
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
mounts: {
|
|
21
|
+
[virtualStoreBasePath]: getFilePathBaseName(virtualStoreDir),
|
|
22
|
+
},
|
|
23
|
+
rootDir: getFilePathDirectory(virtualStoreDir),
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function findVirtualStoreDir(rootDir) {
|
|
28
|
+
let directory = normalizeFilePath(rootDir);
|
|
29
|
+
// Workspace members share the workspace root's file, so walk up to the nearest one.
|
|
30
|
+
while (true) {
|
|
31
|
+
let modulesDir = `${directory}/node_modules`;
|
|
32
|
+
let modulesState = readModulesState(`${modulesDir}/${modulesStateFileName}`);
|
|
33
|
+
if (modulesState !== null) {
|
|
34
|
+
let virtualStoreDir = readVirtualStoreDir(modulesState);
|
|
35
|
+
if (virtualStoreDir === null)
|
|
36
|
+
return null;
|
|
37
|
+
return realpathDirectory(resolveFilePath(modulesDir, virtualStoreDir));
|
|
38
|
+
}
|
|
39
|
+
let parentDirectory = normalizeFilePath(path.dirname(directory));
|
|
40
|
+
if (parentDirectory === directory)
|
|
41
|
+
return null;
|
|
42
|
+
directory = parentDirectory;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function readVirtualStoreDir(modulesState) {
|
|
46
|
+
// pnpm 10.34 and later write JSON, earlier versions write YAML, and package managers that
|
|
47
|
+
// mirror the global virtual store write either one. Reading the one scalar this needs keeps
|
|
48
|
+
// both formats working without a YAML parser.
|
|
49
|
+
try {
|
|
50
|
+
let parsedState = JSON.parse(modulesState);
|
|
51
|
+
if (parsedState === null || typeof parsedState !== 'object')
|
|
52
|
+
return null;
|
|
53
|
+
let virtualStoreDir = parsedState.virtualStoreDir;
|
|
54
|
+
return typeof virtualStoreDir === 'string' ? virtualStoreDir : null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
let match = virtualStoreDirLineRE.exec(modulesState);
|
|
58
|
+
return match === null ? null : unquoteScalar(match[1].trim());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function unquoteScalar(value) {
|
|
62
|
+
let quote = value[0];
|
|
63
|
+
if (value.length > 1 && (quote === "'" || quote === '"') && value.endsWith(quote)) {
|
|
64
|
+
return value.slice(1, -1);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
function isWithinMounts(directory, options) {
|
|
69
|
+
return Object.values(options.mounts).some((fileRoot) => {
|
|
70
|
+
let mountRoot = resolveMountFileRoot(options.rootDir, fileRoot);
|
|
71
|
+
return directory === mountRoot || directory.startsWith(`${mountRoot}/`);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function readModulesState(filePath) {
|
|
75
|
+
try {
|
|
76
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (isPathNotFoundError(error))
|
|
80
|
+
return null;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function realpathDirectory(filePath) {
|
|
85
|
+
try {
|
|
86
|
+
let realPath = fs.realpathSync(filePath);
|
|
87
|
+
return fs.statSync(realPath).isDirectory() ? normalizeFilePath(realPath) : null;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (isPathNotFoundError(error))
|
|
91
|
+
return null;
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isPathNotFoundError(error) {
|
|
96
|
+
return (error instanceof Error &&
|
|
97
|
+
'code' in error &&
|
|
98
|
+
(error.code === 'ENOENT' ||
|
|
99
|
+
error.code === 'ENOTDIR'));
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/assets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
|
@@ -41,19 +41,20 @@
|
|
|
41
41
|
"oxc-transform": "^0.121.0",
|
|
42
42
|
"picomatch": "^4.0.4",
|
|
43
43
|
"source-map-js": "^1.2.1",
|
|
44
|
-
"@remix-run/file-storage": "^0.13.7",
|
|
45
44
|
"@remix-run/mime": "^0.4.2",
|
|
45
|
+
"@remix-run/file-storage": "^0.13.7",
|
|
46
46
|
"@remix-run/headers": "^0.21.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^24.6.0",
|
|
50
50
|
"@types/picomatch": "^4.0.3",
|
|
51
|
+
"playwright": "^1.60.0",
|
|
51
52
|
"typescript": "^7.0.2",
|
|
52
|
-
"@remix-run/node-tsx": "^0.1.1",
|
|
53
|
-
"@remix-run/node-hmr": "^0.1.0",
|
|
54
53
|
"@remix-run/assert": "0.3.0",
|
|
54
|
+
"@remix-run/node-tsx": "^0.1.1",
|
|
55
|
+
"@remix-run/node-hmr": "^0.2.0",
|
|
55
56
|
"@remix-run/test": "0.6.0",
|
|
56
|
-
"@remix-run/ui": "0.
|
|
57
|
+
"@remix-run/ui": "0.9.0"
|
|
57
58
|
},
|
|
58
59
|
"keywords": [
|
|
59
60
|
"remix",
|
package/src/assets.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { createAssetServer } from './lib/asset-server.ts'
|
|
2
2
|
export { defineFileTransform } from './lib/files/config.ts'
|
|
3
3
|
export type { AssetAccessDetails, AssetAccessRule } from './lib/access.ts'
|
|
4
|
-
export type {
|
|
4
|
+
export type {
|
|
5
|
+
AssetServer,
|
|
6
|
+
AssetServerOptions,
|
|
7
|
+
BrowserHmrChannel,
|
|
8
|
+
ScriptEntry,
|
|
9
|
+
} from './lib/asset-server.ts'
|
|
5
10
|
export type { AssetDetails, AssetKind, AssetStatus } from './lib/inspection.ts'
|
|
11
|
+
export type { ScriptImportMap } from './lib/scripts/compiler.ts'
|
|
6
12
|
export type { ModuleLoader } from './lib/loaders.ts'
|