@remix-run/assets 0.1.0 → 0.3.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 +88 -67
- package/dist/lib/access.d.ts.map +1 -1
- package/dist/lib/access.js +3 -0
- package/dist/lib/asset-server.d.ts +50 -45
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +159 -50
- 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/injected-packages.d.ts +11 -0
- package/dist/lib/injected-packages.d.ts.map +1 -0
- package/dist/lib/injected-packages.js +86 -0
- 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/paths.d.ts +1 -0
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +12 -0
- package/dist/lib/routes.d.ts +5 -7
- package/dist/lib/routes.d.ts.map +1 -1
- package/dist/lib/routes.js +13 -16
- 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 +47 -14
- 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 +110 -23
- 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 +13 -4
- package/src/lib/access.ts +2 -0
- package/src/lib/asset-server.ts +239 -99
- package/src/lib/compilation-error.ts +7 -7
- package/src/lib/file-matcher.ts +3 -2
- package/src/lib/injected-packages.ts +117 -0
- package/src/lib/{scripts/store.ts → module-store.ts} +100 -87
- package/src/lib/paths.ts +28 -0
- package/src/lib/routes.ts +31 -22
- package/src/lib/scripts/compiler.ts +88 -70
- package/src/lib/scripts/emit.ts +2 -2
- package/src/lib/scripts/resolve.ts +85 -28
- package/src/lib/scripts/transform.ts +153 -36
- 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
package/dist/lib/asset-server.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
-
import { isAssetServerCompilationError } from "./compilation-error.js";
|
|
4
3
|
import { createAccessPolicy } from "./access.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { isAssetServerCompilationError } from "./compilation-error.js";
|
|
5
|
+
import { getFingerprintRequestCacheControl, parseFingerprintSuffix } from "./fingerprint.js";
|
|
6
|
+
import { getInjectedPackageRouteConfigs } from "./injected-packages.js";
|
|
7
|
+
import { normalizeFilePath, normalizePathname } from "./paths.js";
|
|
7
8
|
import { compileRoutes } from "./routes.js";
|
|
9
|
+
import { createResponseForScript, createScriptCompiler } from "./scripts/compiler.js";
|
|
10
|
+
import { supportedScriptExtensions } from "./scripts/resolve.js";
|
|
11
|
+
import { createResponseForStyle, createStyleCompiler, isStyleFilePath } from "./styles/compiler.js";
|
|
12
|
+
import { resolveScriptTarget, resolveStyleTarget } from "./target.js";
|
|
8
13
|
import { createAssetServerWatcher } from "./watch.js";
|
|
9
|
-
const
|
|
10
|
-
'es2015',
|
|
11
|
-
'es2016',
|
|
12
|
-
'es2017',
|
|
13
|
-
'es2018',
|
|
14
|
-
'es2019',
|
|
15
|
-
'es2020',
|
|
16
|
-
'es2021',
|
|
17
|
-
'es2022',
|
|
18
|
-
'es2023',
|
|
19
|
-
'es2024',
|
|
20
|
-
'es2025',
|
|
21
|
-
'es2026',
|
|
22
|
-
'esnext',
|
|
23
|
-
];
|
|
24
|
-
const scriptTargetSet = new Set(scriptTargets);
|
|
14
|
+
const scriptExtensionSet = new Set(supportedScriptExtensions);
|
|
25
15
|
const chokidarWatcherByAssetServer = new WeakMap();
|
|
26
16
|
const watcherByAssetServer = new WeakMap();
|
|
27
17
|
export function getInternalChokidarWatcher(assetServer) {
|
|
@@ -33,8 +23,8 @@ export function getInternalWatchTargets(assetServer) {
|
|
|
33
23
|
/**
|
|
34
24
|
* Create an asset server instance
|
|
35
25
|
*
|
|
36
|
-
* Compiles TypeScript/JavaScript
|
|
37
|
-
* fingerprinting, caching, and configurable file mapping.
|
|
26
|
+
* Compiles TypeScript/JavaScript scripts and CSS styles on demand with optional
|
|
27
|
+
* source-based URL fingerprinting, caching, and configurable file mapping.
|
|
38
28
|
*
|
|
39
29
|
* @param options Server configuration
|
|
40
30
|
* @returns A {@link AssetServer} with `fetch()`, `getHref()`, and `getPreloads()` methods
|
|
@@ -42,8 +32,9 @@ export function getInternalWatchTargets(assetServer) {
|
|
|
42
32
|
* @example
|
|
43
33
|
* ```ts
|
|
44
34
|
* let assetServer = createAssetServer({
|
|
35
|
+
* basePath: '/assets',
|
|
45
36
|
* fileMap: {
|
|
46
|
-
* '/
|
|
37
|
+
* '/app/*path': 'app/*path',
|
|
47
38
|
* },
|
|
48
39
|
* allow: ['app/**'],
|
|
49
40
|
* })
|
|
@@ -60,11 +51,11 @@ export function createAssetServer(options) {
|
|
|
60
51
|
});
|
|
61
52
|
let watcher = null;
|
|
62
53
|
let chokidarWatcher = null;
|
|
63
|
-
let
|
|
54
|
+
let scriptCompiler = createScriptCompiler({
|
|
64
55
|
buildId: resolvedOptions.buildId,
|
|
65
56
|
define: resolvedOptions.define,
|
|
66
57
|
external: resolvedOptions.external,
|
|
67
|
-
|
|
58
|
+
fingerprintAssets: resolvedOptions.fingerprintAssets,
|
|
68
59
|
isAllowed: accessPolicy.isAllowed,
|
|
69
60
|
minify: resolvedOptions.minify,
|
|
70
61
|
onWatchDirectoriesChange: (delta) => {
|
|
@@ -80,6 +71,23 @@ export function createAssetServer(options) {
|
|
|
80
71
|
watchIgnore: resolvedOptions.watchOptions?.ignore,
|
|
81
72
|
watchMode: resolvedOptions.watchOptions !== null,
|
|
82
73
|
});
|
|
74
|
+
let styleCompiler = createStyleCompiler({
|
|
75
|
+
buildId: resolvedOptions.buildId,
|
|
76
|
+
fingerprintAssets: resolvedOptions.fingerprintAssets,
|
|
77
|
+
isAllowed: accessPolicy.isAllowed,
|
|
78
|
+
minify: resolvedOptions.minify,
|
|
79
|
+
onWatchDirectoriesChange: (delta) => {
|
|
80
|
+
if (!watcher)
|
|
81
|
+
return;
|
|
82
|
+
watcher.updateWatchedDirectories(delta);
|
|
83
|
+
},
|
|
84
|
+
rootDir: resolvedOptions.rootDir,
|
|
85
|
+
routes: resolvedOptions.routes,
|
|
86
|
+
sourceMapSourcePaths: resolvedOptions.sourceMapSourcePaths,
|
|
87
|
+
sourceMaps: resolvedOptions.sourceMaps,
|
|
88
|
+
targets: resolvedOptions.stylesTarget,
|
|
89
|
+
watchIgnore: resolvedOptions.watchOptions?.ignore,
|
|
90
|
+
});
|
|
83
91
|
if (resolvedOptions.watchOptions) {
|
|
84
92
|
watcher = createAssetServerWatcher({
|
|
85
93
|
...resolvedOptions.watchOptions,
|
|
@@ -102,7 +110,8 @@ export function createAssetServer(options) {
|
|
|
102
110
|
async function handleWatchEvent(filePath, event) {
|
|
103
111
|
try {
|
|
104
112
|
let normalizedFilePath = normalizeFilePath(filePath);
|
|
105
|
-
await
|
|
113
|
+
await scriptCompiler.handleFileEvent(normalizedFilePath, event);
|
|
114
|
+
await styleCompiler.handleFileEvent(normalizedFilePath, event);
|
|
106
115
|
}
|
|
107
116
|
catch (error) {
|
|
108
117
|
console.error(`There was an error invalidating the asset server cache: ${error}`);
|
|
@@ -112,28 +121,58 @@ export function createAssetServer(options) {
|
|
|
112
121
|
async fetch(request) {
|
|
113
122
|
if (request.method !== 'GET' && request.method !== 'HEAD')
|
|
114
123
|
return null;
|
|
115
|
-
let parsedRequestPathname =
|
|
124
|
+
let parsedRequestPathname = parseAssetRequestPathname(new URL(request.url).pathname, {
|
|
125
|
+
fingerprintAssets: resolvedOptions.fingerprintAssets,
|
|
126
|
+
routes: resolvedOptions.routes,
|
|
127
|
+
});
|
|
116
128
|
if (!parsedRequestPathname)
|
|
117
129
|
return null;
|
|
118
130
|
try {
|
|
119
131
|
let ifNoneMatch = request.headers.get('If-None-Match');
|
|
120
|
-
|
|
132
|
+
if (isStyleFilePath(parsedRequestPathname.filePath)) {
|
|
133
|
+
let styleResult = await styleCompiler.getStyle(parsedRequestPathname.filePath, {
|
|
134
|
+
ifNoneMatch,
|
|
135
|
+
isSourceMapRequest: parsedRequestPathname.isSourceMapRequest,
|
|
136
|
+
requestedFingerprint: parsedRequestPathname.requestedFingerprint,
|
|
137
|
+
});
|
|
138
|
+
if (styleResult.type === 'not-modified') {
|
|
139
|
+
return new Response(null, {
|
|
140
|
+
status: 304,
|
|
141
|
+
headers: { ETag: styleResult.etag },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
let compiledStyle = styleResult.style;
|
|
145
|
+
if (parsedRequestPathname.requestedFingerprint !== null) {
|
|
146
|
+
if (compiledStyle.fingerprint !== parsedRequestPathname.requestedFingerprint)
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return createResponseForStyle(compiledStyle, {
|
|
150
|
+
cacheControl: parsedRequestPathname.cacheControl,
|
|
151
|
+
ifNoneMatch,
|
|
152
|
+
isSourceMapRequest: parsedRequestPathname.isSourceMapRequest,
|
|
153
|
+
method: request.method,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (!isScriptFilePath(parsedRequestPathname.filePath)) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
let scriptResult = await scriptCompiler.getScript(parsedRequestPathname.filePath, {
|
|
121
160
|
ifNoneMatch,
|
|
122
161
|
isSourceMapRequest: parsedRequestPathname.isSourceMapRequest,
|
|
123
162
|
requestedFingerprint: parsedRequestPathname.requestedFingerprint,
|
|
124
163
|
});
|
|
125
|
-
if (
|
|
164
|
+
if (scriptResult.type === 'not-modified') {
|
|
126
165
|
return new Response(null, {
|
|
127
166
|
status: 304,
|
|
128
|
-
headers: { ETag:
|
|
167
|
+
headers: { ETag: scriptResult.etag },
|
|
129
168
|
});
|
|
130
169
|
}
|
|
131
|
-
let
|
|
170
|
+
let compiledScript = scriptResult.script;
|
|
132
171
|
if (parsedRequestPathname.requestedFingerprint !== null) {
|
|
133
|
-
if (
|
|
172
|
+
if (compiledScript.fingerprint !== parsedRequestPathname.requestedFingerprint)
|
|
134
173
|
return null;
|
|
135
174
|
}
|
|
136
|
-
return
|
|
175
|
+
return createResponseForScript(compiledScript, {
|
|
137
176
|
cacheControl: parsedRequestPathname.cacheControl,
|
|
138
177
|
ifNoneMatch,
|
|
139
178
|
isSourceMapRequest: parsedRequestPathname.isSourceMapRequest,
|
|
@@ -145,17 +184,45 @@ export function createAssetServer(options) {
|
|
|
145
184
|
// compiling imports. In this fetch context, both cases should fall through as "not
|
|
146
185
|
// handled here" so the outer router can continue to its own 404 behavior.
|
|
147
186
|
if (isAssetServerCompilationError(error) &&
|
|
148
|
-
(error.code === '
|
|
187
|
+
(error.code === 'FILE_NOT_FOUND' || error.code === 'FILE_NOT_ALLOWED')) {
|
|
149
188
|
return null;
|
|
150
189
|
}
|
|
151
190
|
return responseForError(error);
|
|
152
191
|
}
|
|
153
192
|
},
|
|
154
193
|
async getHref(filePath) {
|
|
155
|
-
|
|
194
|
+
if (isStyleFilePath(filePath)) {
|
|
195
|
+
return styleCompiler.getHref(filePath);
|
|
196
|
+
}
|
|
197
|
+
return scriptCompiler.getHref(filePath);
|
|
156
198
|
},
|
|
157
199
|
async getPreloads(filePath) {
|
|
158
|
-
|
|
200
|
+
let filePaths = Array.isArray(filePath) ? filePath : [filePath];
|
|
201
|
+
let styleFiles = [];
|
|
202
|
+
let scriptFiles = [];
|
|
203
|
+
for (let nextFilePath of filePaths) {
|
|
204
|
+
if (isStyleFilePath(nextFilePath)) {
|
|
205
|
+
styleFiles.push(nextFilePath);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
scriptFiles.push(nextFilePath);
|
|
209
|
+
}
|
|
210
|
+
if (styleFiles.length === 0 && scriptFiles.length === 0) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
if (styleFiles.length === 0) {
|
|
214
|
+
return flattenPreloadLayers(await scriptCompiler.getPreloadLayers(filePath));
|
|
215
|
+
}
|
|
216
|
+
if (scriptFiles.length === 0) {
|
|
217
|
+
return flattenPreloadLayers(await styleCompiler.getPreloadLayers(filePath));
|
|
218
|
+
}
|
|
219
|
+
// Mixed asset type preloads need to be merged, so we merge in order of first asset type seen
|
|
220
|
+
let scriptPreloadLayersPromise = scriptCompiler.getPreloadLayers(scriptFiles);
|
|
221
|
+
let stylePreloadLayersPromise = styleCompiler.getPreloadLayers(styleFiles);
|
|
222
|
+
let preloadLayerGroups = isStyleFilePath(filePaths[0])
|
|
223
|
+
? [stylePreloadLayersPromise, scriptPreloadLayersPromise]
|
|
224
|
+
: [scriptPreloadLayersPromise, stylePreloadLayersPromise];
|
|
225
|
+
return mergePreloadLayers(await Promise.all(preloadLayerGroups));
|
|
159
226
|
},
|
|
160
227
|
async close() {
|
|
161
228
|
await watcher?.close();
|
|
@@ -175,11 +242,31 @@ function internalServerError() {
|
|
|
175
242
|
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
176
243
|
});
|
|
177
244
|
}
|
|
245
|
+
function mergePreloadLayers(preloadLayersByRoot) {
|
|
246
|
+
let urls = [];
|
|
247
|
+
let seen = new Set();
|
|
248
|
+
let maxDepth = Math.max(0, ...preloadLayersByRoot.map((layers) => layers.length));
|
|
249
|
+
for (let depth = 0; depth < maxDepth; depth++) {
|
|
250
|
+
for (let preloadLayers of preloadLayersByRoot) {
|
|
251
|
+
for (let url of preloadLayers[depth] ?? []) {
|
|
252
|
+
if (seen.has(url))
|
|
253
|
+
continue;
|
|
254
|
+
seen.add(url);
|
|
255
|
+
urls.push(url);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return urls;
|
|
260
|
+
}
|
|
261
|
+
function flattenPreloadLayers(preloadLayers) {
|
|
262
|
+
return preloadLayers.flatMap((layer) => layer);
|
|
263
|
+
}
|
|
178
264
|
function defaultErrorHandler(error) {
|
|
179
265
|
console.error(error);
|
|
180
266
|
}
|
|
181
267
|
function resolveAssetServerOptions(options) {
|
|
182
268
|
let rootDir = normalizeFilePath(fs.realpathSync(path.resolve(options.rootDir ?? process.cwd())));
|
|
269
|
+
let basePath = normalizeBasePath(options.basePath);
|
|
183
270
|
let scriptOptions = options.scripts ?? {};
|
|
184
271
|
let fingerprintOptions = normalizeFingerprintOptions({
|
|
185
272
|
fingerprint: options.fingerprint,
|
|
@@ -187,31 +274,34 @@ function resolveAssetServerOptions(options) {
|
|
|
187
274
|
});
|
|
188
275
|
return {
|
|
189
276
|
allow: options.allow,
|
|
277
|
+
basePath,
|
|
190
278
|
buildId: fingerprintOptions.buildId,
|
|
191
279
|
define: scriptOptions.define,
|
|
192
280
|
deny: options.deny,
|
|
193
281
|
external: scriptOptions.external ?? [],
|
|
194
|
-
|
|
195
|
-
minify:
|
|
282
|
+
fingerprintAssets: fingerprintOptions.enabled,
|
|
283
|
+
minify: options.minify ?? false,
|
|
196
284
|
onError: options.onError ?? defaultErrorHandler,
|
|
197
285
|
rootDir,
|
|
198
|
-
routes: compileRoutes(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
286
|
+
routes: compileRoutes(basePath, [
|
|
287
|
+
{
|
|
288
|
+
fileMap: options.fileMap,
|
|
289
|
+
rootDir,
|
|
290
|
+
},
|
|
291
|
+
...getInjectedPackageRouteConfigs(),
|
|
292
|
+
]),
|
|
293
|
+
sourceMapSourcePaths: options.sourceMapSourcePaths ?? 'url',
|
|
294
|
+
sourceMaps: options.sourceMaps,
|
|
295
|
+
scriptsTarget: resolveScriptTarget(options.target),
|
|
296
|
+
stylesTarget: resolveStyleTarget(options.target),
|
|
205
297
|
watchOptions: normalizeWatchOptions(options.watch),
|
|
206
298
|
};
|
|
207
299
|
}
|
|
208
|
-
function
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
if (typeof target !== 'string' || !scriptTargetSet.has(target)) {
|
|
212
|
-
throw new TypeError(`Expected target to be one of ${scriptTargets.map((value) => `"${value}"`).join(', ')}. Received "${target}".`);
|
|
300
|
+
function normalizeBasePath(basePath) {
|
|
301
|
+
if (typeof basePath !== 'string') {
|
|
302
|
+
throw new TypeError('basePath must be a string');
|
|
213
303
|
}
|
|
214
|
-
return
|
|
304
|
+
return normalizePathname(basePath || '/').replace(/\/+$/, '') || '/';
|
|
215
305
|
}
|
|
216
306
|
function normalizeFingerprintOptions(options) {
|
|
217
307
|
if (!options.fingerprint) {
|
|
@@ -240,3 +330,22 @@ function normalizeWatchOptions(options) {
|
|
|
240
330
|
return {};
|
|
241
331
|
return options;
|
|
242
332
|
}
|
|
333
|
+
function parseAssetRequestPathname(pathname, options) {
|
|
334
|
+
let isSourceMapRequest = pathname.endsWith('.map');
|
|
335
|
+
let pathWithoutMap = isSourceMapRequest ? pathname.slice(0, -4) : pathname;
|
|
336
|
+
let fingerprint = parseFingerprintSuffix(pathWithoutMap);
|
|
337
|
+
let filePath = options.routes.resolveUrlPathname(fingerprint.pathname);
|
|
338
|
+
if (!filePath)
|
|
339
|
+
return null;
|
|
340
|
+
if (options.fingerprintAssets && fingerprint.requestedFingerprint === null)
|
|
341
|
+
return null;
|
|
342
|
+
return {
|
|
343
|
+
cacheControl: getFingerprintRequestCacheControl(fingerprint.requestedFingerprint),
|
|
344
|
+
filePath,
|
|
345
|
+
isSourceMapRequest,
|
|
346
|
+
requestedFingerprint: fingerprint.requestedFingerprint,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function isScriptFilePath(filePath) {
|
|
350
|
+
return scriptExtensionSet.has(path.extname(filePath).toLowerCase());
|
|
351
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
type AssetServerCompilationErrorCode = '
|
|
1
|
+
type AssetServerCompilationErrorCode = 'FILE_NOT_FOUND' | 'FILE_NOT_ALLOWED' | 'FILE_OUTSIDE_FILE_MAP' | 'COMMONJS_NOT_SUPPORTED' | 'TRANSFORM_FAILED' | 'EMIT_FAILED' | 'IMPORT_RESOLUTION_FAILED' | 'IMPORT_NOT_SUPPORTED' | 'IMPORT_NOT_ALLOWED' | 'IMPORT_OUTSIDE_FILE_MAP';
|
|
2
2
|
/**
|
|
3
|
-
* Internal error used by the request-time
|
|
3
|
+
* Internal error used by the request-time asset compilation pipeline.
|
|
4
4
|
*/
|
|
5
5
|
export declare class AssetServerCompilationError extends Error {
|
|
6
6
|
code: AssetServerCompilationErrorCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilation-error.d.ts","sourceRoot":"","sources":["../../src/lib/compilation-error.ts"],"names":[],"mappings":"AAAA,KAAK,+BAA+B,GAChC,kBAAkB,GAClB,
|
|
1
|
+
{"version":3,"file":"compilation-error.d.ts","sourceRoot":"","sources":["../../src/lib/compilation-error.ts"],"names":[],"mappings":"AAAA,KAAK,+BAA+B,GAChC,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,wBAAwB,GACxB,kBAAkB,GAClB,aAAa,GACb,0BAA0B,GAC1B,sBAAsB,GACtB,oBAAoB,GACpB,yBAAyB,CAAA;AAE7B;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,IAAI,EAAE,+BAA+B,CAAA;IAErC,YACE,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,IAAI,EAAE,+BAA+B,CAAA;KACtC,EAKF;CACF;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,2BAA2B,CAEtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IACP,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,+BAA+B,CAAA;CACtC,GACA,2BAA2B,CAE7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-matcher.d.ts","sourceRoot":"","sources":["../../src/lib/file-matcher.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;AAEvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GACL,WAAW,
|
|
1
|
+
{"version":3,"file":"file-matcher.d.ts","sourceRoot":"","sources":["../../src/lib/file-matcher.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;AAEvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GACL,WAAW,CA2Bb"}
|
package/dist/lib/file-matcher.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
-
import
|
|
2
|
+
import picomatch from 'picomatch';
|
|
3
3
|
import { normalizeFilePath, resolveFilePath } from "./paths.js";
|
|
4
4
|
export function createFileMatcher(pattern, rootDir, options = {}) {
|
|
5
5
|
let resolvedPatternPath = resolveFilePath(rootDir, pattern);
|
|
@@ -26,7 +26,8 @@ export function createFileMatcher(pattern, rootDir, options = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
return (filePath) => filePath === resolvedPatternPath;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
let globMatcher = picomatch(resolvedPatternPath, { dot: true });
|
|
30
|
+
return (filePath) => globMatcher(filePath);
|
|
30
31
|
}
|
|
31
32
|
function isSameOrDescendantPath(filePath, directoryPath) {
|
|
32
33
|
let normalizedDirectoryPath = directoryPath.replace(/\/+$/, '');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function isInjectedPackageFilePath(filePath: string): boolean;
|
|
2
|
+
export declare function getInjectedPackageRouteConfigs(): {
|
|
3
|
+
fileMap: Record<string, string>;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function getInjectedPackageNameForSpecifier(specifier: string): string | null;
|
|
7
|
+
export declare function mayContainInjectedPackageSpecifier(sourceText: string): boolean;
|
|
8
|
+
export declare function maskAuthoredInjectedPackageSpecifier(specifier: string): string | null;
|
|
9
|
+
export declare function restoreAuthoredInjectedPackageSpecifier(specifier: string): string | null;
|
|
10
|
+
export declare function getInjectedPackageImporterPath(): string;
|
|
11
|
+
//# sourceMappingURL=injected-packages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injected-packages.d.ts","sourceRoot":"","sources":["../../src/lib/injected-packages.ts"],"names":[],"mappings":"AAeA,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWnE;AAED,wBAAgB,8BAA8B,IAAI;IAChD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAA;CAChB,EAAE,CAWF;AAED,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQnF;AAED,wBAAgB,kCAAkC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE9E;AAED,wBAAgB,oCAAoC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMrF;AAED,wBAAgB,uCAAuC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYxF;AAMD,wBAAgB,8BAA8B,IAAI,MAAM,CAEvD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { getFilePathDirectory, normalizeFilePath } from "./paths.js";
|
|
4
|
+
const injectedPackageNames = ['@oxc-project/runtime'];
|
|
5
|
+
const injectedPackagesBasePath = '/__@remix/injected';
|
|
6
|
+
const resolvedInjectedPackages = new Map();
|
|
7
|
+
export function isInjectedPackageFilePath(filePath) {
|
|
8
|
+
let normalizedFilePath = normalizeFilePath(filePath);
|
|
9
|
+
for (let packageName of injectedPackageNames) {
|
|
10
|
+
let packageRoot = getResolvedInjectedPackage(packageName).packageRoot;
|
|
11
|
+
if (normalizedFilePath === packageRoot || normalizedFilePath.startsWith(`${packageRoot}/`)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
export function getInjectedPackageRouteConfigs() {
|
|
18
|
+
return injectedPackageNames.map((packageName) => {
|
|
19
|
+
let { packageRoot } = getResolvedInjectedPackage(packageName);
|
|
20
|
+
return {
|
|
21
|
+
fileMap: {
|
|
22
|
+
[getInjectedPackageRoutePattern(packageName)]: `${packageName}/*path`,
|
|
23
|
+
},
|
|
24
|
+
rootDir: getInjectedPackageRouteRoot(packageRoot, packageName),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function getInjectedPackageNameForSpecifier(specifier) {
|
|
29
|
+
for (let packageName of injectedPackageNames) {
|
|
30
|
+
if (specifier === packageName || specifier.startsWith(`${packageName}/`)) {
|
|
31
|
+
return packageName;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
export function mayContainInjectedPackageSpecifier(sourceText) {
|
|
37
|
+
return injectedPackageNames.some((packageName) => sourceText.includes(packageName));
|
|
38
|
+
}
|
|
39
|
+
export function maskAuthoredInjectedPackageSpecifier(specifier) {
|
|
40
|
+
let packageName = getInjectedPackageNameForSpecifier(specifier);
|
|
41
|
+
if (!packageName)
|
|
42
|
+
return null;
|
|
43
|
+
let maskedPackageName = getMaskedInjectedPackageName(packageName);
|
|
44
|
+
return `${maskedPackageName}${specifier.slice(packageName.length)}`;
|
|
45
|
+
}
|
|
46
|
+
export function restoreAuthoredInjectedPackageSpecifier(specifier) {
|
|
47
|
+
for (let packageName of injectedPackageNames) {
|
|
48
|
+
let maskedPackageName = getMaskedInjectedPackageName(packageName);
|
|
49
|
+
if (specifier === maskedPackageName) {
|
|
50
|
+
return packageName;
|
|
51
|
+
}
|
|
52
|
+
if (specifier.startsWith(`${maskedPackageName}/`)) {
|
|
53
|
+
return `${packageName}${specifier.slice(maskedPackageName.length)}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function getMaskedInjectedPackageName(packageName) {
|
|
59
|
+
return `~${packageName.slice(1)}`;
|
|
60
|
+
}
|
|
61
|
+
export function getInjectedPackageImporterPath() {
|
|
62
|
+
return normalizeFilePath(fileURLToPath(import.meta.url));
|
|
63
|
+
}
|
|
64
|
+
function getResolvedInjectedPackage(packageName) {
|
|
65
|
+
let existing = resolvedInjectedPackages.get(packageName);
|
|
66
|
+
if (existing)
|
|
67
|
+
return existing;
|
|
68
|
+
let packageJsonUrl = import.meta.resolve(`${packageName}/package.json`);
|
|
69
|
+
let packageJsonPath = normalizeFilePath(fs.realpathSync(fileURLToPath(packageJsonUrl)));
|
|
70
|
+
let resolvedInjectedPackage = {
|
|
71
|
+
packageJsonPath,
|
|
72
|
+
packageRoot: normalizeFilePath(fs.realpathSync(getFilePathDirectory(packageJsonPath))),
|
|
73
|
+
};
|
|
74
|
+
resolvedInjectedPackages.set(packageName, resolvedInjectedPackage);
|
|
75
|
+
return resolvedInjectedPackage;
|
|
76
|
+
}
|
|
77
|
+
function getInjectedPackageRoutePattern(packageName) {
|
|
78
|
+
return `${injectedPackagesBasePath}/${packageName}/*path`;
|
|
79
|
+
}
|
|
80
|
+
function getInjectedPackageRouteRoot(packageRoot, packageName) {
|
|
81
|
+
let routeRoot = packageRoot;
|
|
82
|
+
for (let _segment of packageName.split('/')) {
|
|
83
|
+
routeRoot = getFilePathDirectory(routeRoot);
|
|
84
|
+
}
|
|
85
|
+
return routeRoot;
|
|
86
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ModuleTracking = {
|
|
2
|
+
trackedFiles: readonly string[];
|
|
3
|
+
trackedDirectories?: readonly string[];
|
|
4
|
+
};
|
|
5
|
+
export type ModuleWatchEvent = 'change' | 'add' | 'unlink';
|
|
6
|
+
export type FileSnapshot = {
|
|
7
|
+
mtimeNs: bigint;
|
|
8
|
+
size: bigint;
|
|
9
|
+
};
|
|
10
|
+
export type ModuleSnapshot = ReadonlyMap<string, FileSnapshot>;
|
|
11
|
+
type ModuleRecordState<transformed, resolved, emitted> = {
|
|
12
|
+
identityPath: string;
|
|
13
|
+
invalidationVersion: number;
|
|
14
|
+
transformed?: transformed;
|
|
15
|
+
resolved?: resolved;
|
|
16
|
+
emitted?: emitted;
|
|
17
|
+
emittedSnapshot?: ModuleSnapshot;
|
|
18
|
+
staleEmitted?: emitted;
|
|
19
|
+
staleEmittedSnapshot?: ModuleSnapshot;
|
|
20
|
+
trackedFiles: ReadonlySet<string>;
|
|
21
|
+
trackedDirectories: ReadonlySet<string>;
|
|
22
|
+
};
|
|
23
|
+
export type ModuleRecord<transformed, resolved, emitted> = Readonly<ModuleRecordState<transformed, resolved, emitted>>;
|
|
24
|
+
export type ModuleStore<transformed, resolved, emitted> = {
|
|
25
|
+
get(identityPath: string): ModuleRecord<transformed, resolved, emitted>;
|
|
26
|
+
clearTransformed(identityPath: string, tracking: readonly ModuleTracking[]): void;
|
|
27
|
+
setTransformed(identityPath: string, transformed: transformed, tracking: readonly ModuleTracking[]): void;
|
|
28
|
+
setResolved(identityPath: string, resolved: resolved, tracking: readonly ModuleTracking[]): void;
|
|
29
|
+
clearResolved(identityPath: string, tracking: readonly ModuleTracking[]): void;
|
|
30
|
+
setEmitted(identityPath: string, emitted: emitted, snapshot: ModuleSnapshot | null): void;
|
|
31
|
+
invalidateForFileEvent(filePath: string, event: ModuleWatchEvent): void;
|
|
32
|
+
invalidateAll(): void;
|
|
33
|
+
};
|
|
34
|
+
export declare function createModuleStore<transformed, resolved, emitted>(options?: {
|
|
35
|
+
onWatchDirectoriesChange?: (delta: {
|
|
36
|
+
add: string[];
|
|
37
|
+
remove: string[];
|
|
38
|
+
}) => void;
|
|
39
|
+
}): ModuleStore<transformed, resolved, emitted>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=module-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-store.d.ts","sourceRoot":"","sources":["../../src/lib/module-store.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAA;IAC/B,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAE9D,KAAK,iBAAiB,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,IAAI;IACvD,YAAY,EAAE,MAAM,CAAA;IACpB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,cAAc,CAAA;IAChC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,oBAAoB,CAAC,EAAE,cAAc,CAAA;IACrC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IACjC,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,YAAY,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,IAAI,QAAQ,CACjE,iBAAiB,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAClD,CAAA;AAeD,MAAM,MAAM,WAAW,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,IAAI;IACxD,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;IACvE,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI,CAAA;IACjF,cAAc,CACZ,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,IAAI,CAAA;IACP,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI,CAAA;IAChG,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI,CAAA;IAC9E,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAAA;IACzF,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACvE,aAAa,IAAI,IAAI,CAAA;CACtB,CAAA;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,EAC9D,OAAO,GAAE;IACP,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,CAAA;CAC3E,GACL,WAAW,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CA4M7C"}
|