@remix-run/assets 0.2.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 +35 -20
- package/dist/lib/access.d.ts.map +1 -1
- package/dist/lib/access.js +3 -0
- package/dist/lib/asset-server.d.ts +5 -2
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +19 -6
- 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/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/resolve.d.ts.map +1 -1
- package/dist/lib/scripts/resolve.js +35 -8
- package/dist/lib/scripts/transform.d.ts.map +1 -1
- package/dist/lib/scripts/transform.js +78 -2
- package/package.json +7 -3
- package/src/lib/access.ts +2 -0
- package/src/lib/asset-server.ts +25 -7
- package/src/lib/injected-packages.ts +117 -0
- package/src/lib/paths.ts +28 -0
- package/src/lib/routes.ts +31 -22
- package/src/lib/scripts/resolve.ts +54 -8
- package/src/lib/scripts/transform.ts +104 -2
package/README.md
CHANGED
|
@@ -27,9 +27,10 @@ import { createRouter } from 'remix/fetch-router'
|
|
|
27
27
|
import { createAssetServer } from 'remix/assets'
|
|
28
28
|
|
|
29
29
|
let assetServer = createAssetServer({
|
|
30
|
+
basePath: '/assets',
|
|
30
31
|
fileMap: {
|
|
31
|
-
'/
|
|
32
|
-
'/
|
|
32
|
+
'/app/*path': 'app/*path',
|
|
33
|
+
'/npm/*path': 'node_modules/*path',
|
|
33
34
|
},
|
|
34
35
|
allow: ['app/assets/**', 'node_modules/**'],
|
|
35
36
|
})
|
|
@@ -53,9 +54,10 @@ import { createAssetServer } from 'remix/assets'
|
|
|
53
54
|
|
|
54
55
|
let assetServer = createAssetServer({
|
|
55
56
|
rootDir: path.resolve(import.meta.dirname, '..'),
|
|
57
|
+
basePath: '/assets',
|
|
56
58
|
fileMap: {
|
|
57
|
-
'/
|
|
58
|
-
'/
|
|
59
|
+
'/app/*path': 'app/*path',
|
|
60
|
+
'/npm/*path': 'node_modules/*path',
|
|
59
61
|
},
|
|
60
62
|
allow: ['app/assets/**', 'node_modules/**'],
|
|
61
63
|
})
|
|
@@ -69,7 +71,8 @@ You must provide an `allow` list to specify which files are allowed to be served
|
|
|
69
71
|
import { createAssetServer } from 'remix/assets'
|
|
70
72
|
|
|
71
73
|
let assetServer = createAssetServer({
|
|
72
|
-
|
|
74
|
+
basePath: '/assets',
|
|
75
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
73
76
|
allow: ['app/assets/**'],
|
|
74
77
|
deny: ['app/**/*.server.*'],
|
|
75
78
|
})
|
|
@@ -79,21 +82,22 @@ Rules for `allow` and `deny` are file paths or globs. Relative values are resolv
|
|
|
79
82
|
|
|
80
83
|
## File Map
|
|
81
84
|
|
|
82
|
-
Use `fileMap` to map public URLs to file paths on disk.
|
|
85
|
+
Use `fileMap` to map public URLs to file paths on disk. `basePath` defines the shared public mount point, and the `fileMap` keys are URL patterns relative to that base path. The values are root-relative file path patterns.
|
|
83
86
|
|
|
84
87
|
```ts
|
|
85
88
|
import { createAssetServer } from 'remix/assets'
|
|
86
89
|
|
|
87
90
|
let assetServer = createAssetServer({
|
|
91
|
+
basePath: '/assets',
|
|
88
92
|
fileMap: {
|
|
89
|
-
'/
|
|
90
|
-
'/
|
|
93
|
+
'/app/*path': 'app/*path',
|
|
94
|
+
'/packages/*path': '../packages/*path',
|
|
91
95
|
},
|
|
92
96
|
allow: ['app/assets/**', '../packages/**'],
|
|
93
97
|
})
|
|
94
98
|
```
|
|
95
99
|
|
|
96
|
-
`fileMap` entries use [`route-pattern`](https://github.com/remix-run/remix/tree/main/packages/route-pattern) syntax for both URL and file patterns. Wildcards must be named, and the same params must appear in both patterns so imports can be rewritten back to public URLs.
|
|
100
|
+
`fileMap` entries use [`route-pattern`](https://github.com/remix-run/remix/tree/main/packages/route-pattern) syntax for both URL and file patterns. Wildcards must be named, and the same params must appear in both patterns so imports can be rewritten back to public URLs. For example, with `basePath: '/assets'`, a `fileMap` key of `'/app/*path'` is served at `/assets/app/*path`.
|
|
97
101
|
|
|
98
102
|
### File watching
|
|
99
103
|
|
|
@@ -103,7 +107,8 @@ The file system is watched by default so source changes are picked up without re
|
|
|
103
107
|
import { createAssetServer } from 'remix/assets'
|
|
104
108
|
|
|
105
109
|
let assetServer = createAssetServer({
|
|
106
|
-
|
|
110
|
+
basePath: '/assets',
|
|
111
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
107
112
|
allow: ['app/assets/**', 'app/node_modules/**'],
|
|
108
113
|
})
|
|
109
114
|
```
|
|
@@ -120,7 +125,8 @@ You can disable file watching if the files on disk won't change, or if watching
|
|
|
120
125
|
import { createAssetServer } from 'remix/assets'
|
|
121
126
|
|
|
122
127
|
let assetServer = createAssetServer({
|
|
123
|
-
|
|
128
|
+
basePath: '/assets',
|
|
129
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
124
130
|
allow: ['app/assets/**', 'app/node_modules/**'],
|
|
125
131
|
watch: false,
|
|
126
132
|
})
|
|
@@ -132,7 +138,8 @@ You can optionally provide an array of glob patterns to the `watch.ignore` optio
|
|
|
132
138
|
import { createAssetServer } from 'remix/assets'
|
|
133
139
|
|
|
134
140
|
let assetServer = createAssetServer({
|
|
135
|
-
|
|
141
|
+
basePath: '/assets',
|
|
142
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
136
143
|
allow: ['app/assets/**', 'app/node_modules/**'],
|
|
137
144
|
watch: {
|
|
138
145
|
ignore: ['**/node_modules/**'],
|
|
@@ -174,7 +181,8 @@ If you want clients to cache assets aggressively without revalidation, you can o
|
|
|
174
181
|
import { createAssetServer } from 'remix/assets'
|
|
175
182
|
|
|
176
183
|
let assetServer = createAssetServer({
|
|
177
|
-
|
|
184
|
+
basePath: '/assets',
|
|
185
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
178
186
|
allow: ['app/assets/**'],
|
|
179
187
|
watch: false,
|
|
180
188
|
fingerprint: {
|
|
@@ -195,7 +203,8 @@ Use `target` to lower emitted syntax to a specific browser support policy and/or
|
|
|
195
203
|
import { createAssetServer } from 'remix/assets'
|
|
196
204
|
|
|
197
205
|
let assetServer = createAssetServer({
|
|
198
|
-
|
|
206
|
+
basePath: '/assets',
|
|
207
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
199
208
|
allow: ['app/assets/**'],
|
|
200
209
|
target: {
|
|
201
210
|
chrome: '109',
|
|
@@ -215,7 +224,8 @@ Enable sourcemaps with either `'external'` or `'inline'` using `sourceMaps`:
|
|
|
215
224
|
import { createAssetServer } from 'remix/assets'
|
|
216
225
|
|
|
217
226
|
let assetServer = createAssetServer({
|
|
218
|
-
|
|
227
|
+
basePath: '/assets',
|
|
228
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
219
229
|
allow: ['app/assets/**'],
|
|
220
230
|
sourceMaps: 'external',
|
|
221
231
|
})
|
|
@@ -227,7 +237,8 @@ By default, sourcemap `sources` use URLs so they're presented alongside the comp
|
|
|
227
237
|
import { createAssetServer } from 'remix/assets'
|
|
228
238
|
|
|
229
239
|
let assetServer = createAssetServer({
|
|
230
|
-
|
|
240
|
+
basePath: '/assets',
|
|
241
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
231
242
|
allow: ['app/assets/**'],
|
|
232
243
|
sourceMaps: 'inline',
|
|
233
244
|
sourceMapSourcePaths: 'absolute',
|
|
@@ -242,7 +253,8 @@ Enable minification with `minify`:
|
|
|
242
253
|
import { createAssetServer } from 'remix/assets'
|
|
243
254
|
|
|
244
255
|
let assetServer = createAssetServer({
|
|
245
|
-
|
|
256
|
+
basePath: '/assets',
|
|
257
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
246
258
|
allow: ['app/assets/**'],
|
|
247
259
|
minify: true,
|
|
248
260
|
})
|
|
@@ -258,7 +270,8 @@ Use `scripts.define` to replace global identifiers with constant expressions.
|
|
|
258
270
|
import { createAssetServer } from 'remix/assets'
|
|
259
271
|
|
|
260
272
|
let assetServer = createAssetServer({
|
|
261
|
-
|
|
273
|
+
basePath: '/assets',
|
|
274
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
262
275
|
allow: ['app/assets/**', 'app/node_modules/**'],
|
|
263
276
|
scripts: {
|
|
264
277
|
define: {
|
|
@@ -278,7 +291,8 @@ Use `scripts.external` to leave specific import specifiers unchanged by providin
|
|
|
278
291
|
import { createAssetServer } from 'remix/assets'
|
|
279
292
|
|
|
280
293
|
let assetServer = createAssetServer({
|
|
281
|
-
|
|
294
|
+
basePath: '/assets',
|
|
295
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
282
296
|
allow: ['app/assets/**'],
|
|
283
297
|
scripts: {
|
|
284
298
|
external: ['my-external-import'],
|
|
@@ -305,7 +319,8 @@ Use `onError` to report unexpected compilation failures and/or return a custom r
|
|
|
305
319
|
import { createAssetServer } from 'remix/assets'
|
|
306
320
|
|
|
307
321
|
let assetServer = createAssetServer({
|
|
308
|
-
|
|
322
|
+
basePath: '/assets',
|
|
323
|
+
fileMap: { '/app/*path': 'app/*path' },
|
|
309
324
|
allow: ['app/assets/**'],
|
|
310
325
|
onError(error) {
|
|
311
326
|
console.error('Failed to build client assets', error)
|
package/dist/lib/access.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/lib/access.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/lib/access.ts"],"names":[],"mappings":"AAGA,KAAK,YAAY,GAAG;IAClB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CACrC,CAAA;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAcf"}
|
package/dist/lib/access.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createFileMatcher } from "./file-matcher.js";
|
|
2
|
+
import { isInjectedPackageFilePath } from "./injected-packages.js";
|
|
2
3
|
export function createAccessPolicy(options) {
|
|
3
4
|
let allowMatchers = options.allow.map((pattern) => createFileMatcher(pattern, options.rootDir));
|
|
4
5
|
let denyMatchers = (options.deny ?? []).map((pattern) => createFileMatcher(pattern, options.rootDir));
|
|
5
6
|
return {
|
|
6
7
|
isAllowed(filePath) {
|
|
8
|
+
if (isInjectedPackageFilePath(filePath))
|
|
9
|
+
return true;
|
|
7
10
|
if (!allowMatchers.some((matcher) => matcher(filePath)))
|
|
8
11
|
return false;
|
|
9
12
|
if (denyMatchers.length > 0 && denyMatchers.some((matcher) => matcher(filePath)))
|
|
@@ -34,7 +34,9 @@ interface AssetServerScriptOptions {
|
|
|
34
34
|
external?: string[];
|
|
35
35
|
}
|
|
36
36
|
export interface AssetServerOptions {
|
|
37
|
-
/**
|
|
37
|
+
/** Public mount path for this asset server, e.g. `'/assets'`. */
|
|
38
|
+
basePath: string;
|
|
39
|
+
/** File patterns keyed by public URL patterns relative to `basePath`. */
|
|
38
40
|
fileMap: Readonly<Record<string, string>>;
|
|
39
41
|
/**
|
|
40
42
|
* Root directory used to resolve relative file paths. Defaults to `process.cwd()`.
|
|
@@ -125,8 +127,9 @@ export declare function getInternalWatchTargets(assetServer: AssetServer): reado
|
|
|
125
127
|
* @example
|
|
126
128
|
* ```ts
|
|
127
129
|
* let assetServer = createAssetServer({
|
|
130
|
+
* basePath: '/assets',
|
|
128
131
|
* fileMap: {
|
|
129
|
-
* '/
|
|
132
|
+
* '/app/*path': 'app/*path',
|
|
130
133
|
* },
|
|
131
134
|
* allow: ['app/**'],
|
|
132
135
|
* })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-server.d.ts","sourceRoot":"","sources":["../../src/lib/asset-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asset-server.d.ts","sourceRoot":"","sources":["../../src/lib/asset-server.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAA6C,MAAM,aAAa,CAAA;AAEzF,OAAO,KAAK,EAAsB,eAAe,EAAE,MAAM,YAAY,CAAA;AAErE,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,UAAU,kBAAkB;IAC1B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,KAAK,eAAe,GAAG,QAAQ,GAAG,UAAU,CAAA;AAC5C,KAAK,yBAAyB,GAAG,KAAK,GAAG,UAAU,CAAA;AAEnD,UAAU,wBAAwB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAID,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAA;IAChB,yEAAyE;IACzE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACzC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB;;;;;OAKG;IACH,WAAW,CAAC,EAA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.js";
|
|
4
4
|
import { isAssetServerCompilationError } from "./compilation-error.js";
|
|
5
5
|
import { getFingerprintRequestCacheControl, parseFingerprintSuffix } from "./fingerprint.js";
|
|
6
|
-
import {
|
|
6
|
+
import { getInjectedPackageRouteConfigs } from "./injected-packages.js";
|
|
7
|
+
import { normalizeFilePath, normalizePathname } from "./paths.js";
|
|
7
8
|
import { compileRoutes } from "./routes.js";
|
|
8
9
|
import { createResponseForScript, createScriptCompiler } from "./scripts/compiler.js";
|
|
9
10
|
import { supportedScriptExtensions } from "./scripts/resolve.js";
|
|
@@ -31,8 +32,9 @@ export function getInternalWatchTargets(assetServer) {
|
|
|
31
32
|
* @example
|
|
32
33
|
* ```ts
|
|
33
34
|
* let assetServer = createAssetServer({
|
|
35
|
+
* basePath: '/assets',
|
|
34
36
|
* fileMap: {
|
|
35
|
-
* '/
|
|
37
|
+
* '/app/*path': 'app/*path',
|
|
36
38
|
* },
|
|
37
39
|
* allow: ['app/**'],
|
|
38
40
|
* })
|
|
@@ -264,6 +266,7 @@ function defaultErrorHandler(error) {
|
|
|
264
266
|
}
|
|
265
267
|
function resolveAssetServerOptions(options) {
|
|
266
268
|
let rootDir = normalizeFilePath(fs.realpathSync(path.resolve(options.rootDir ?? process.cwd())));
|
|
269
|
+
let basePath = normalizeBasePath(options.basePath);
|
|
267
270
|
let scriptOptions = options.scripts ?? {};
|
|
268
271
|
let fingerprintOptions = normalizeFingerprintOptions({
|
|
269
272
|
fingerprint: options.fingerprint,
|
|
@@ -271,6 +274,7 @@ function resolveAssetServerOptions(options) {
|
|
|
271
274
|
});
|
|
272
275
|
return {
|
|
273
276
|
allow: options.allow,
|
|
277
|
+
basePath,
|
|
274
278
|
buildId: fingerprintOptions.buildId,
|
|
275
279
|
define: scriptOptions.define,
|
|
276
280
|
deny: options.deny,
|
|
@@ -279,10 +283,13 @@ function resolveAssetServerOptions(options) {
|
|
|
279
283
|
minify: options.minify ?? false,
|
|
280
284
|
onError: options.onError ?? defaultErrorHandler,
|
|
281
285
|
rootDir,
|
|
282
|
-
routes: compileRoutes(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
routes: compileRoutes(basePath, [
|
|
287
|
+
{
|
|
288
|
+
fileMap: options.fileMap,
|
|
289
|
+
rootDir,
|
|
290
|
+
},
|
|
291
|
+
...getInjectedPackageRouteConfigs(),
|
|
292
|
+
]),
|
|
286
293
|
sourceMapSourcePaths: options.sourceMapSourcePaths ?? 'url',
|
|
287
294
|
sourceMaps: options.sourceMaps,
|
|
288
295
|
scriptsTarget: resolveScriptTarget(options.target),
|
|
@@ -290,6 +297,12 @@ function resolveAssetServerOptions(options) {
|
|
|
290
297
|
watchOptions: normalizeWatchOptions(options.watch),
|
|
291
298
|
};
|
|
292
299
|
}
|
|
300
|
+
function normalizeBasePath(basePath) {
|
|
301
|
+
if (typeof basePath !== 'string') {
|
|
302
|
+
throw new TypeError('basePath must be a string');
|
|
303
|
+
}
|
|
304
|
+
return normalizePathname(basePath || '/').replace(/\/+$/, '') || '/';
|
|
305
|
+
}
|
|
293
306
|
function normalizeFingerprintOptions(options) {
|
|
294
307
|
if (!options.fingerprint) {
|
|
295
308
|
return {
|
|
@@ -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
|
+
}
|
package/dist/lib/paths.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export declare function isAbsoluteFilePath(filePath: string): boolean;
|
|
|
4
4
|
export declare function normalizeFilePath(filePath: string): string;
|
|
5
5
|
export declare function resolveFilePath(rootDir: string, filePath: string): string;
|
|
6
6
|
export declare function getFilePathDirectory(filePath: string): string;
|
|
7
|
+
export declare function getRelativeFilePath(fromPath: string, toPath: string): string;
|
|
7
8
|
export declare function getFilePathBaseName(filePath: string): string;
|
|
8
9
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/lib/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
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|
package/dist/lib/paths.js
CHANGED
|
@@ -42,6 +42,18 @@ export function resolveFilePath(rootDir, filePath) {
|
|
|
42
42
|
export function getFilePathDirectory(filePath) {
|
|
43
43
|
return path.posix.dirname(normalizeWindowsPath(filePath));
|
|
44
44
|
}
|
|
45
|
+
export function getRelativeFilePath(fromPath, toPath) {
|
|
46
|
+
let normalizedFromPath = normalizeFilePath(fromPath);
|
|
47
|
+
let normalizedToPath = normalizeFilePath(toPath);
|
|
48
|
+
if (normalizedFromPath.startsWith('//') || normalizedToPath.startsWith('//')) {
|
|
49
|
+
return normalizeWindowsPath(path.win32.relative(normalizedFromPath.replace(/\//g, '\\'), normalizedToPath.replace(/\//g, '\\')));
|
|
50
|
+
}
|
|
51
|
+
if (windowsDriveLetterRE.test(normalizedFromPath) ||
|
|
52
|
+
windowsDriveLetterRE.test(normalizedToPath)) {
|
|
53
|
+
return normalizeWindowsPath(path.win32.relative(normalizedFromPath.replace(/\//g, '\\'), normalizedToPath.replace(/\//g, '\\')));
|
|
54
|
+
}
|
|
55
|
+
return path.posix.relative(normalizedFromPath, normalizedToPath);
|
|
56
|
+
}
|
|
45
57
|
export function getFilePathBaseName(filePath) {
|
|
46
58
|
return path.posix.basename(normalizeWindowsPath(filePath));
|
|
47
59
|
}
|
package/dist/lib/routes.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface RouteConfig {
|
|
2
|
+
fileMap: Readonly<Record<string, string>>;
|
|
3
|
+
rootDir: string;
|
|
4
4
|
}
|
|
5
5
|
export interface CompiledRoutes {
|
|
6
6
|
resolveUrlPathname(pathname: string): string | null;
|
|
7
7
|
toUrlPathname(filePath: string): string | null;
|
|
8
8
|
}
|
|
9
|
-
export declare function compileRoutes(
|
|
10
|
-
|
|
11
|
-
rootDir: string;
|
|
12
|
-
}): CompiledRoutes;
|
|
9
|
+
export declare function compileRoutes(basePath: string, routeConfigs: readonly RouteConfig[]): CompiledRoutes;
|
|
10
|
+
export {};
|
|
13
11
|
//# sourceMappingURL=routes.d.ts.map
|
package/dist/lib/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/lib/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/lib/routes.ts"],"names":[],"mappings":"AAeA,UAAU,WAAW;IACnB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;CAChB;AAQD,MAAM,WAAW,cAAc;IAC7B,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACnD,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAC/C;AAYD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,SAAS,WAAW,EAAE,GACnC,cAAc,CA8ChB"}
|
package/dist/lib/routes.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
1
|
import { RoutePattern } from '@remix-run/route-pattern';
|
|
3
|
-
import { isAbsoluteFilePath, normalizeFilePath, normalizePathname, resolveFilePath, } from "./paths.js";
|
|
2
|
+
import { getRelativeFilePath, isAbsoluteFilePath, normalizeFilePath, normalizePathname, resolveFilePath, } from "./paths.js";
|
|
4
3
|
function normalizeFilePattern(pattern) {
|
|
5
4
|
if (isAbsoluteFilePath(pattern)) {
|
|
6
5
|
throw new Error(`File route patterns must be relative to the asset server root.\nPattern: ${pattern}`);
|
|
7
6
|
}
|
|
8
7
|
return normalizePathname(pattern);
|
|
9
8
|
}
|
|
10
|
-
export function compileRoutes(
|
|
11
|
-
if (Object.keys(
|
|
9
|
+
export function compileRoutes(basePath, routeConfigs) {
|
|
10
|
+
if (routeConfigs.every((routeConfig) => Object.keys(routeConfig.fileMap).length === 0)) {
|
|
12
11
|
throw new Error('createAssetServer() requires at least one configured fileMap entry.');
|
|
13
12
|
}
|
|
14
|
-
let compiledRoutes = Object.entries(
|
|
15
|
-
urlPattern,
|
|
13
|
+
let compiledRoutes = routeConfigs.flatMap((routeConfig) => Object.entries(routeConfig.fileMap).map(([urlPattern, filePattern]) => compileRoute({
|
|
16
14
|
filePattern,
|
|
17
|
-
|
|
15
|
+
urlPattern,
|
|
16
|
+
}, {
|
|
17
|
+
basePath,
|
|
18
|
+
rootDir: routeConfig.rootDir,
|
|
19
|
+
})));
|
|
18
20
|
return {
|
|
19
21
|
resolveUrlPathname(pathname) {
|
|
20
22
|
let normalizedPathname = normalizePathname(pathname);
|
|
@@ -30,9 +32,7 @@ export function compileRoutes(options) {
|
|
|
30
32
|
toUrlPathname(filePath) {
|
|
31
33
|
let normalizedFilePath = normalizeFilePath(filePath);
|
|
32
34
|
for (let route of compiledRoutes) {
|
|
33
|
-
let relativeFilePath = getRelativeFilePath(
|
|
34
|
-
if (relativeFilePath === null)
|
|
35
|
-
continue;
|
|
35
|
+
let relativeFilePath = getRelativeFilePath(route.rootDir, normalizedFilePath);
|
|
36
36
|
let match = route.filePattern.ast.pathname.match(relativeFilePath);
|
|
37
37
|
if (!match)
|
|
38
38
|
continue;
|
|
@@ -43,7 +43,9 @@ export function compileRoutes(options) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
function compileRoute(route, options) {
|
|
46
|
-
let
|
|
46
|
+
let basePath = normalizePathname(options.basePath).replace(/\/+$/, '') || '/';
|
|
47
|
+
let relativeUrlPattern = normalizePathname(route.urlPattern);
|
|
48
|
+
let urlPatternSource = normalizePathname(`${basePath.replace(/\/+$/, '')}/${relativeUrlPattern.replace(/^\/+/, '')}`);
|
|
47
49
|
let filePatternSource = normalizeFilePattern(route.filePattern);
|
|
48
50
|
let urlPattern = new RoutePattern(urlPatternSource);
|
|
49
51
|
let filePattern = new RoutePattern(filePatternSource);
|
|
@@ -56,11 +58,6 @@ function compileRoute(route, options) {
|
|
|
56
58
|
filePattern,
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
|
-
function getRelativeFilePath(filePath, rootDir) {
|
|
60
|
-
if (filePath[1] === ':' && rootDir[1] === ':' && filePath[0] !== rootDir[0])
|
|
61
|
-
return null;
|
|
62
|
-
return path.posix.relative(rootDir, filePath);
|
|
63
|
-
}
|
|
64
61
|
function getPathnameParams(pattern, match) {
|
|
65
62
|
let params = {};
|
|
66
63
|
for (let param of pattern.ast.pathname.params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAMnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAMnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAM1E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,KAAK,YAAY,GAAG,YAAY,CAAC,iBAAiB,EAAE,cAAc,EAAE,aAAa,CAAC,CAAA;AAElF,eAAO,MAAM,sBAAsB;;;;CAIC,CAAA;AAEpC,eAAO,MAAM,kBAAkB,UAAiD,CAAA;AAChF,eAAO,M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|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { createAssetServerCompilationError, isAssetServerCompilationError, } from "../compilation-error.js";
|
|
4
|
+
import { getInjectedPackageNameForSpecifier, getInjectedPackageImporterPath, restoreAuthoredInjectedPackageSpecifier, } from "../injected-packages.js";
|
|
4
5
|
import { normalizeFilePath } from "../paths.js";
|
|
5
6
|
export const resolverExtensionAlias = {
|
|
6
7
|
'.js': ['.js', '.ts', '.tsx', '.jsx'],
|
|
@@ -28,30 +29,31 @@ export async function resolveModule(record, transformed, args) {
|
|
|
28
29
|
let importsWithPaths = [];
|
|
29
30
|
let deps = new Set();
|
|
30
31
|
for (let unresolved of transformed.unresolvedImports) {
|
|
31
|
-
let
|
|
32
|
+
let displaySpecifier = getDisplayImportSpecifier(unresolved.specifier);
|
|
33
|
+
let trackedResolution = getTrackedRelativeImportResolution(transformed.importerDir, displaySpecifier, args.isWatchIgnored);
|
|
32
34
|
let resolvedSpec = resolvedImports.get(unresolved.specifier);
|
|
33
35
|
if (!resolvedSpec?.absolutePath) {
|
|
34
|
-
return failResolve(createAssetServerCompilationError(`Failed to resolve import "${
|
|
36
|
+
return failResolve(createAssetServerCompilationError(`Failed to resolve import "${displaySpecifier}" in ${transformed.resolvedPath}. ` +
|
|
35
37
|
`Ensure it resolves to a file within the configured asset server fileMap, or mark it as external.`, {
|
|
36
38
|
code: 'IMPORT_RESOLUTION_FAILED',
|
|
37
39
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
38
40
|
}
|
|
39
41
|
let resolvedImport = args.resolveModulePath(resolvedSpec.absolutePath);
|
|
40
42
|
if (!resolvedImport) {
|
|
41
|
-
return failResolve(createAssetServerCompilationError(`Import "${
|
|
43
|
+
return failResolve(createAssetServerCompilationError(`Import "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedSpec.absolutePath}", is not a supported script file. ` +
|
|
42
44
|
`Supported extensions are ${supportedScriptExtensions.join(', ')}.`, {
|
|
43
45
|
code: 'IMPORT_NOT_SUPPORTED',
|
|
44
46
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
45
47
|
}
|
|
46
48
|
if (!args.isAllowed(resolvedImport.identityPath)) {
|
|
47
|
-
return failResolve(createAssetServerCompilationError(`Import "${
|
|
49
|
+
return failResolve(createAssetServerCompilationError(`Import "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is not allowed by the asset server allow/deny configuration. ` +
|
|
48
50
|
`Add a matching allow rule for this file path, remove a conflicting deny rule for this file path, or mark this import as external.`, {
|
|
49
51
|
code: 'IMPORT_NOT_ALLOWED',
|
|
50
52
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
51
53
|
}
|
|
52
54
|
let stableUrlPathname = args.routes.toUrlPathname(resolvedImport.identityPath);
|
|
53
55
|
if (!stableUrlPathname) {
|
|
54
|
-
return failResolve(createAssetServerCompilationError(`Import "${
|
|
56
|
+
return failResolve(createAssetServerCompilationError(`Import "${displaySpecifier}" in ${transformed.resolvedPath}, resolved to "${resolvedImport.identityPath}", is outside all configured fileMap entries. ` +
|
|
55
57
|
`Add a matching fileMap entry for this file path, or mark this import as external.`, {
|
|
56
58
|
code: 'IMPORT_OUTSIDE_FILE_MAP',
|
|
57
59
|
}), trackedFiles, trackedResolutions, transformed.resolvedPath, { isWatchIgnored: args.isWatchIgnored, trackedResolution });
|
|
@@ -164,10 +166,13 @@ async function batchResolveSpecifiers(specifiers, importerPath, resolverFactory)
|
|
|
164
166
|
return resolvedBySpecifier;
|
|
165
167
|
try {
|
|
166
168
|
for (let specifier of specifiers) {
|
|
167
|
-
let
|
|
169
|
+
let normalizedResolution = normalizeSpecifierResolution(specifier, importerPath);
|
|
170
|
+
let resolutionResult = await resolverFactory.resolveFileAsync(normalizedResolution.importerPath, normalizedResolution.specifier);
|
|
168
171
|
if (resolutionResult.error) {
|
|
169
|
-
throw createAssetServerCompilationError(
|
|
170
|
-
`
|
|
172
|
+
throw createAssetServerCompilationError(normalizedResolution.importerPath === getInjectedPackageImporterPath()
|
|
173
|
+
? `Failed to resolve injected import "${specifier}" from asset server.`
|
|
174
|
+
: `Failed to resolve import "${normalizedResolution.specifier}" in ${normalizedResolution.importerPath}. ` +
|
|
175
|
+
`Ensure it resolves to a file within the configured asset server fileMap, or mark it as external.`, {
|
|
171
176
|
code: 'IMPORT_RESOLUTION_FAILED',
|
|
172
177
|
});
|
|
173
178
|
}
|
|
@@ -199,6 +204,28 @@ function getUniqueSpecifiers(unresolvedImports) {
|
|
|
199
204
|
function formatUnknownError(error) {
|
|
200
205
|
return error instanceof Error ? error.message : String(error);
|
|
201
206
|
}
|
|
207
|
+
function normalizeSpecifierResolution(specifier, importerPath) {
|
|
208
|
+
let authoredInjectedPackageSpecifier = restoreAuthoredInjectedPackageSpecifier(specifier);
|
|
209
|
+
if (authoredInjectedPackageSpecifier) {
|
|
210
|
+
return {
|
|
211
|
+
importerPath,
|
|
212
|
+
specifier: authoredInjectedPackageSpecifier,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (getInjectedPackageNameForSpecifier(specifier)) {
|
|
216
|
+
return {
|
|
217
|
+
importerPath: getInjectedPackageImporterPath(),
|
|
218
|
+
specifier,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
importerPath,
|
|
223
|
+
specifier,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function getDisplayImportSpecifier(specifier) {
|
|
227
|
+
return restoreAuthoredInjectedPackageSpecifier(specifier) ?? specifier;
|
|
228
|
+
}
|
|
202
229
|
function failResolve(error, trackedFiles, trackedResolutions, importerPath, options = {}) {
|
|
203
230
|
return {
|
|
204
231
|
ok: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/transform.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAS,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAS/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAO1E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,KAAK,YAAY,GAAG,YAAY,CAAC,iBAAiB,EAAE,cAAc,EAAE,aAAa,CAAC,CAAA;AA4BlF,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,iBAAiB,EAAE,MA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