@embroider/vite 0.2.2-unstable.449a68c → 0.2.2-unstable.57e628d
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/index.mjs +2 -0
- package/package.json +5 -5
- package/src/assets.js.map +1 -1
- package/src/classic-ember-support.d.ts +1 -0
- package/src/classic-ember-support.js +9 -0
- package/src/classic-ember-support.js.map +1 -0
- package/src/ember.d.ts +6 -0
- package/src/ember.js +43 -0
- package/src/ember.js.map +1 -0
- package/src/esbuild-request.d.ts +19 -16
- package/src/esbuild-request.js +15 -38
- package/src/esbuild-request.js.map +1 -1
- package/src/esbuild-resolver.js +16 -8
- package/src/esbuild-resolver.js.map +1 -1
- package/src/request.d.ts +13 -18
- package/src/request.js +46 -70
- package/src/request.js.map +1 -1
- package/src/resolver.js +8 -3
- package/src/resolver.js.map +1 -1
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/vite",
|
|
3
|
-
"version": "0.2.2-unstable.
|
|
3
|
+
"version": "0.2.2-unstable.57e628d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
12
|
"vite": "^5.2.0",
|
|
13
|
-
"@embroider/core": "^3.4.20-unstable.
|
|
13
|
+
"@embroider/core": "^3.4.20-unstable.57e628d"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/core": "^7.22.9",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"send": "^0.18.0",
|
|
26
26
|
"source-map-url": "^0.4.1",
|
|
27
27
|
"terser": "^5.7.0",
|
|
28
|
-
"@embroider/macros": "1.16.10-unstable.
|
|
29
|
-
"@embroider/reverse-exports": "0.1.1-unstable.
|
|
28
|
+
"@embroider/macros": "1.16.10-unstable.57e628d",
|
|
29
|
+
"@embroider/reverse-exports": "0.1.1-unstable.57e628d"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/babel__core": "^7.20.1",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/send": "^0.17.4",
|
|
37
37
|
"rollup": "^4.18.0",
|
|
38
38
|
"vite": "^5.3.3",
|
|
39
|
-
"@embroider/core": "^3.4.20-unstable.
|
|
39
|
+
"@embroider/core": "^3.4.20-unstable.57e628d"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"index.mjs",
|
package/src/assets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","sourceRoot":"","sources":["assets.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;AAEhC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["assets.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;AAEhC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,SAA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C,CAAC;oBACxG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;wBACrB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;4BAAE,OAAO;wBACrC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;wBAC/C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;4BAC9C,oCAAoC;4BACpC,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;gCACtC,OAAO;4BACT,CAAC;4BAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;4BACtC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;gCAClC,OAAO,CAAC,GAAG,CAAC,+BAA+B,GAAG,CAAC,IAAI,wBAAwB,IAAI,sBAAsB,CAAC,CAAC;gCACvG,OAAO;4BACT,CAAC;4BAED,IAAI,CAAC,QAAQ,CAAC;gCACZ,IAAI,EAAE,OAAO;gCACb,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC;gCAC9B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;6BAC5C,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Resolver } from '@embroider/core';\nimport core from '@embroider/core';\nconst { ResolverLoader } = core;\nimport type { Plugin } from 'vite';\nimport * as process from 'process';\nimport { join, posix } from 'path';\nimport fs from 'fs-extra';\nconst { existsSync, readFileSync, lstatSync } = fs;\nimport send from 'send';\n\nfunction findPublicAsset(relativePath: string, resolver: Resolver) {\n const packageCache = resolver.packageCache;\n let pkg = packageCache.ownerOfFile(relativePath);\n\n for (const engine of resolver.options.engines) {\n for (const addon of engine.activeAddons) {\n pkg = packageCache.ownerOfFile(addon.root);\n if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {\n const asset = Object.entries(pkg.meta['public-assets']).find(\n ([_key, a]) => posix.resolve('/', a) === relativePath\n )?.[0];\n let local = asset ? join(addon.root, asset) : null;\n if (local && existsSync(local)) {\n return local;\n }\n }\n }\n }\n}\n\nexport function assets(): Plugin {\n const cwd = process.cwd();\n const resolverLoader = new ResolverLoader(cwd);\n let mode: 'build' | 'serve' = 'build';\n let publicDir = 'public';\n return {\n name: 'assets',\n enforce: 'post',\n configResolved(options) {\n mode = options.command;\n publicDir = options.publicDir;\n },\n configureServer(server) {\n return () => {\n server.middlewares.use((req, res, next) => {\n if (req.originalUrl && req.originalUrl.length > 1) {\n const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);\n if (assetUrl) {\n return send(req, assetUrl).pipe(res as unknown as NodeJS.WritableStream);\n }\n }\n return next();\n });\n };\n },\n buildStart: {\n // we need to wait for the compatBuild plugin's buildStart hook to finish\n // so that the resolver config exists before we try to read it.\n sequential: true,\n order: 'post',\n async handler() {\n if (mode !== 'build') return;\n const engines = resolverLoader.resolver.options.engines;\n for (const engine of engines) {\n const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));\n packages.forEach(pkg => {\n if (!pkg || !pkg.isV2Addon()) return;\n const assets = pkg.meta['public-assets'] || {};\n Object.entries(assets).forEach(([path, dest]) => {\n // do not override app public assets\n if (existsSync(join(publicDir, dest))) {\n return;\n }\n\n const filePath = join(pkg.root, path);\n if (!lstatSync(filePath).isFile()) {\n console.log(`Invalid package definition, ${pkg.name} has defined a file \"${path}\" that is not a file`);\n return;\n }\n\n this.emitFile({\n type: 'asset',\n source: readFileSync(filePath),\n fileName: posix.resolve('/', dest).slice(1),\n });\n });\n });\n }\n },\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function classicEmberSupport(): import("vite").Plugin<any>[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { hbs } from './hbs.js';
|
|
2
|
+
import { scripts } from './scripts.js';
|
|
3
|
+
import { compatPrebuild } from './build.js';
|
|
4
|
+
import { assets } from './assets.js';
|
|
5
|
+
import { contentFor } from './content-for.js';
|
|
6
|
+
export function classicEmberSupport() {
|
|
7
|
+
return [hbs(), scripts(), compatPrebuild(), assets(), contentFor()];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=classic-ember-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classic-ember-support.js","sourceRoot":"","sources":["classic-ember-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { hbs } from './hbs.js';\nimport { scripts } from './scripts.js';\nimport { compatPrebuild } from './build.js';\nimport { assets } from './assets.js';\nimport { contentFor } from './content-for.js';\n\nexport function classicEmberSupport() {\n return [hbs(), scripts(), compatPrebuild(), assets(), contentFor()];\n}\n"]}
|
package/src/ember.d.ts
ADDED
package/src/ember.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { templateTag } from './template-tag.js';
|
|
2
|
+
import { resolver } from './resolver.js';
|
|
3
|
+
import { mergeConfig } from 'vite';
|
|
4
|
+
import { esBuildResolver } from './esbuild-resolver.js';
|
|
5
|
+
export let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json'];
|
|
6
|
+
export function ember() {
|
|
7
|
+
return [
|
|
8
|
+
templateTag(),
|
|
9
|
+
resolver(),
|
|
10
|
+
{
|
|
11
|
+
name: 'vite-plugin-ember-config',
|
|
12
|
+
async config(config, env) {
|
|
13
|
+
return mergeConfig({
|
|
14
|
+
resolve: {
|
|
15
|
+
extensions,
|
|
16
|
+
},
|
|
17
|
+
optimizeDeps: {
|
|
18
|
+
exclude: ['@embroider/macros'],
|
|
19
|
+
extensions: ['.hbs', '.gjs', '.gts'],
|
|
20
|
+
esbuildOptions: {
|
|
21
|
+
plugins: [esBuildResolver()],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
build: {
|
|
25
|
+
rollupOptions: {
|
|
26
|
+
input: {
|
|
27
|
+
main: 'index.html',
|
|
28
|
+
...(shouldBuildTests(env.mode) ? { tests: 'tests/index.html' } : undefined),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
server: {
|
|
33
|
+
port: 4200,
|
|
34
|
+
},
|
|
35
|
+
}, config);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
function shouldBuildTests(mode) {
|
|
41
|
+
return mode !== 'production' || process.env.FORCE_BUILD_TESTS;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ember.js.map
|
package/src/ember.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ember.js","sourceRoot":"","sources":["ember.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAmC,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,IAAI,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAEnG,MAAM,UAAU,KAAK;IACnB,OAAO;QACL,WAAW,EAAE;QACb,QAAQ,EAAE;QACV;YACE,IAAI,EAAE,0BAA0B;YAChC,KAAK,CAAC,MAAM,CAAC,MAAkB,EAAE,GAAc;gBAC7C,OAAO,WAAW,CAChB;oBACE,OAAO,EAAE;wBACP,UAAU;qBACX;oBAED,YAAY,EAAE;wBACZ,OAAO,EAAE,CAAC,mBAAmB,CAAC;wBAC9B,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;wBACpC,cAAc,EAAE;4BACd,OAAO,EAAE,CAAC,eAAe,EAAE,CAAC;yBAC7B;qBACF;oBAED,KAAK,EAAE;wBACL,aAAa,EAAE;4BACb,KAAK,EAAE;gCACL,IAAI,EAAE,YAAY;gCAClB,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;6BAC5E;yBACF;qBACF;oBACD,MAAM,EAAE;wBACN,IAAI,EAAE,IAAI;qBACX;iBACF,EACD,MAAM,CACP,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAChE,CAAC","sourcesContent":["import { templateTag } from './template-tag.js';\nimport { resolver } from './resolver.js';\nimport { mergeConfig, type UserConfig, type ConfigEnv } from 'vite';\nimport { esBuildResolver } from './esbuild-resolver.js';\n\nexport let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json'];\n\nexport function ember() {\n return [\n templateTag(),\n resolver(),\n {\n name: 'vite-plugin-ember-config',\n async config(config: UserConfig, env: ConfigEnv) {\n return mergeConfig(\n {\n resolve: {\n extensions,\n },\n\n optimizeDeps: {\n exclude: ['@embroider/macros'],\n extensions: ['.hbs', '.gjs', '.gts'],\n esbuildOptions: {\n plugins: [esBuildResolver()],\n },\n },\n\n build: {\n rollupOptions: {\n input: {\n main: 'index.html',\n ...(shouldBuildTests(env.mode) ? { tests: 'tests/index.html' } : undefined),\n },\n },\n },\n server: {\n port: 4200,\n },\n },\n config\n );\n },\n },\n ];\n}\n\nfunction shouldBuildTests(mode: string) {\n return mode !== 'production' || process.env.FORCE_BUILD_TESTS;\n}\n"]}
|
package/src/esbuild-request.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
|
|
2
|
-
import type { PackageCache as _PackageCache, Resolution, ModuleRequest } from '@embroider/core';
|
|
2
|
+
import type { PackageCache as _PackageCache, Resolution, ModuleRequest, RequestAdapter } from '@embroider/core';
|
|
3
3
|
type PublicAPI<T> = {
|
|
4
4
|
[K in keyof T]: T[K];
|
|
5
5
|
};
|
|
6
6
|
type PackageCache = PublicAPI<_PackageCache>;
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolveResult, OnResolveResult>> {
|
|
8
8
|
private packageCache;
|
|
9
9
|
private phase;
|
|
10
10
|
private context;
|
|
11
11
|
private kind;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
static create({ packageCache, phase, build, kind, path, importer, pluginData, }: {
|
|
13
|
+
packageCache: PackageCache;
|
|
14
|
+
phase: 'bundling' | 'other';
|
|
15
|
+
build: PluginBuild;
|
|
16
|
+
kind: ImportKind;
|
|
17
|
+
path: string;
|
|
18
|
+
importer: string | undefined;
|
|
19
|
+
pluginData: Record<string, any> | undefined;
|
|
20
|
+
}): {
|
|
21
|
+
initialState: {
|
|
22
|
+
specifier: string;
|
|
23
|
+
fromFile: string;
|
|
24
|
+
meta: any;
|
|
25
|
+
};
|
|
26
|
+
adapter: EsBuildRequestAdapter;
|
|
27
|
+
} | undefined;
|
|
19
28
|
private constructor();
|
|
20
29
|
get debugType(): string;
|
|
21
|
-
|
|
22
|
-
rehome(newFromFile: string): this;
|
|
23
|
-
virtualize(filename: string): this;
|
|
24
|
-
withMeta(meta: Record<string, any> | undefined): this;
|
|
25
|
-
notFound(): this;
|
|
26
|
-
resolveTo(resolution: Resolution<OnResolveResult, OnResolveResult>): this;
|
|
27
|
-
defaultResolve(): Promise<Resolution<OnResolveResult, OnResolveResult>>;
|
|
30
|
+
resolve(request: ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>): Promise<Resolution<OnResolveResult, OnResolveResult>>;
|
|
28
31
|
}
|
|
29
32
|
export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
|
|
30
33
|
export {};
|
package/src/esbuild-request.js
CHANGED
|
@@ -2,63 +2,40 @@ import core from '@embroider/core';
|
|
|
2
2
|
const { cleanUrl, packageName } = core;
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
import { externalName } from '@embroider/reverse-exports';
|
|
5
|
-
export class
|
|
6
|
-
static
|
|
5
|
+
export class EsBuildRequestAdapter {
|
|
6
|
+
static create({ packageCache, phase, build, kind, path, importer, pluginData, }) {
|
|
7
7
|
var _a, _b, _c;
|
|
8
8
|
if (!((_b = (_a = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
if (
|
|
11
|
+
if (path && importer && path[0] !== '\0' && !path.startsWith('virtual-module:')) {
|
|
12
12
|
let fromFile = cleanUrl(importer);
|
|
13
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
initialState: {
|
|
15
|
+
specifier: path,
|
|
16
|
+
fromFile,
|
|
17
|
+
meta: (_c = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _c === void 0 ? void 0 : _c.meta,
|
|
18
|
+
},
|
|
19
|
+
adapter: new EsBuildRequestAdapter(packageCache, phase, build, kind),
|
|
20
|
+
};
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
|
-
constructor(packageCache, phase, context, kind
|
|
23
|
+
constructor(packageCache, phase, context, kind) {
|
|
17
24
|
this.packageCache = packageCache;
|
|
18
25
|
this.phase = phase;
|
|
19
26
|
this.context = context;
|
|
20
27
|
this.kind = kind;
|
|
21
|
-
this.specifier = specifier;
|
|
22
|
-
this.fromFile = fromFile;
|
|
23
|
-
this.meta = meta;
|
|
24
|
-
this.isVirtual = isVirtual;
|
|
25
|
-
this.isNotFound = isNotFound;
|
|
26
|
-
this.resolvedTo = resolvedTo;
|
|
27
28
|
}
|
|
28
29
|
get debugType() {
|
|
29
30
|
return 'esbuild';
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, newSpecifier, this.fromFile, this.meta, this.isVirtual, false, undefined);
|
|
33
|
-
}
|
|
34
|
-
rehome(newFromFile) {
|
|
35
|
-
if (this.fromFile === newFromFile) {
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, newFromFile, this.meta, this.isVirtual, false, undefined);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
virtualize(filename) {
|
|
43
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, filename, this.fromFile, this.meta, true, false, undefined);
|
|
44
|
-
}
|
|
45
|
-
withMeta(meta) {
|
|
46
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, meta, this.isVirtual, this.isNotFound, this.resolvedTo);
|
|
47
|
-
}
|
|
48
|
-
notFound() {
|
|
49
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, true, undefined);
|
|
50
|
-
}
|
|
51
|
-
resolveTo(resolution) {
|
|
52
|
-
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, this.isNotFound, resolution);
|
|
53
|
-
}
|
|
54
|
-
async defaultResolve() {
|
|
55
|
-
const request = this;
|
|
32
|
+
async resolve(request) {
|
|
56
33
|
if (request.isVirtual) {
|
|
57
34
|
return {
|
|
58
35
|
type: 'found',
|
|
59
36
|
filename: request.specifier,
|
|
60
37
|
result: { path: request.specifier, namespace: 'embroider-virtual' },
|
|
61
|
-
isVirtual:
|
|
38
|
+
isVirtual: request.isVirtual,
|
|
62
39
|
};
|
|
63
40
|
}
|
|
64
41
|
if (request.isNotFound) {
|
|
@@ -122,7 +99,7 @@ export class EsBuildModuleRequest {
|
|
|
122
99
|
};
|
|
123
100
|
}
|
|
124
101
|
}
|
|
125
|
-
return { type: 'found', filename: result.path, result, isVirtual:
|
|
102
|
+
return { type: 'found', filename: result.path, result, isVirtual: request.isVirtual };
|
|
126
103
|
}
|
|
127
104
|
}
|
|
128
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-request.js","sourceRoot":"","sources":["esbuild-request.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK1D,MA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AC;IAC1C,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import core from '@embroider/core';\nconst { cleanUrl, packageName } = core;\nimport type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';\nimport { dirname } from 'path';\n\nimport type { PackageCache as _PackageCache, Resolution, ModuleRequest } from '@embroider/core';\nimport { externalName } from '@embroider/reverse-exports';\n\ntype PublicAPI<T> = { [K in keyof T]: T[K] };\ntype PackageCache = PublicAPI<_PackageCache>;\n\nexport class EsBuildModuleRequest implements ModuleRequest {\n static from(\n packageCache: PackageCache,\n phase: 'bundling' | 'other',\n context: PluginBuild,\n kind: ImportKind,\n source: string,\n importer: string | undefined,\n pluginData: Record<string, any> | undefined\n ): EsBuildModuleRequest | undefined {\n if (!(pluginData?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n\n if (source && importer && source[0] !== '\\0' && !source.startsWith('virtual-module:')) {\n let fromFile = cleanUrl(importer);\n return new EsBuildModuleRequest(\n packageCache,\n phase,\n context,\n kind,\n source,\n fromFile,\n pluginData?.embroider?.meta,\n false,\n false,\n undefined\n );\n }\n }\n\n private constructor(\n private packageCache: PackageCache,\n private phase: 'bundling' | 'other',\n private context: PluginBuild,\n private kind: ImportKind,\n readonly specifier: string,\n readonly fromFile: string,\n readonly meta: Record<string, any> | undefined,\n readonly isVirtual: boolean,\n readonly isNotFound: boolean,\n readonly resolvedTo: Resolution<OnResolveResult, OnResolveResult> | undefined\n ) {}\n\n get debugType() {\n return 'esbuild';\n }\n\n alias(newSpecifier: string) {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n newSpecifier,\n this.fromFile,\n this.meta,\n this.isVirtual,\n false,\n undefined\n ) as this;\n }\n rehome(newFromFile: string) {\n if (this.fromFile === newFromFile) {\n return this;\n } else {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n this.specifier,\n newFromFile,\n this.meta,\n this.isVirtual,\n false,\n undefined\n ) as this;\n }\n }\n virtualize(filename: string) {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n filename,\n this.fromFile,\n this.meta,\n true,\n false,\n undefined\n ) as this;\n }\n withMeta(meta: Record<string, any> | undefined): this {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n this.specifier,\n this.fromFile,\n meta,\n this.isVirtual,\n this.isNotFound,\n this.resolvedTo\n ) as this;\n }\n notFound(): this {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n this.specifier,\n this.fromFile,\n this.meta,\n this.isVirtual,\n true,\n undefined\n ) as this;\n }\n\n resolveTo(resolution: Resolution<OnResolveResult, OnResolveResult>): this {\n return new EsBuildModuleRequest(\n this.packageCache,\n this.phase,\n this.context,\n this.kind,\n this.specifier,\n this.fromFile,\n this.meta,\n this.isVirtual,\n this.isNotFound,\n resolution\n ) as this;\n }\n\n async defaultResolve(): Promise<Resolution<OnResolveResult, OnResolveResult>> {\n const request = this;\n if (request.isVirtual) {\n return {\n type: 'found',\n filename: request.specifier,\n result: { path: request.specifier, namespace: 'embroider-virtual' },\n isVirtual: this.isVirtual,\n };\n }\n if (request.isNotFound) {\n // todo: make sure this looks correct to users\n return {\n type: 'not_found',\n err: {\n errors: [{ text: `module not found ${request.specifier}` }],\n },\n };\n }\n\n requestStatus(request.specifier);\n\n let result = await this.context.resolve(request.specifier, {\n importer: request.fromFile,\n resolveDir: dirname(request.fromFile),\n kind: this.kind,\n pluginData: {\n embroider: {\n enableCustomResolver: false,\n meta: request.meta,\n },\n },\n });\n\n let status = readStatus(request.specifier);\n\n if (result.errors.length > 0 || status === 'not_found') {\n return { type: 'not_found', err: result };\n } else if (result.external) {\n return { type: 'ignored', result };\n } else {\n if (this.phase === 'bundling') {\n // we need to ensure that we don't traverse back into the app while\n // doing dependency pre-bundling. There are multiple ways an addon can\n // resolve things from the app, due to the existince of both app-js\n // (modules in addons that are logically part of the app's namespace)\n // and non-strict handlebars (which resolves\n // components/helpers/modifiers against the app's global pool).\n let pkg = this.packageCache.ownerOfFile(result.path);\n if (pkg?.root === this.packageCache.appRoot) {\n let externalizedName = request.specifier;\n if (!packageName(externalizedName)) {\n // the request was a relative path. This won't remain valid once\n // it has been bundled into vite/deps. But we know it targets the\n // app, so we can always convert it into a non-relative import\n // from the app's namespace\n //\n // IMPORTANT: whenever an addon resolves a relative path to the\n // app, it does so because our code in the core resolver has\n // rewritten the request to be relative to the app's root. So here\n // we will only ever encounter relative paths that are already\n // relative to the app's root directory.\n externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;\n }\n return {\n type: 'ignored',\n result: {\n path: externalizedName,\n external: true,\n },\n };\n }\n }\n return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual };\n }\n }\n}\n\n/*\n This is an unfortunate necessity. During depscan, vite deliberately hides\n information from esbuild. Specifically, it treats \"not found\" and \"this is an\n external dependency\" as both \"external: true\". But we really care about the\n difference, since we have fallback behaviors for the \"not found\" case. Using\n this global state, our rollup resolver plugin can observe what vite is\n actually doing and communicate that knowledge outward to our esbuild resolver\n plugin.\n */\nfunction sharedGlobalState() {\n let channel = (globalThis as any).__embroider_vite_resolver_channel__ as\n | undefined\n | Map<string, 'pending' | 'found' | 'not_found'>;\n if (!channel) {\n channel = new Map();\n (globalThis as any).__embroider_vite_resolver_channel__ = channel;\n }\n return channel;\n}\n\nfunction requestStatus(id: string): void {\n sharedGlobalState().set(id, 'pending');\n}\n\nexport function writeStatus(id: string, status: 'found' | 'not_found'): void {\n let channel = sharedGlobalState();\n if (channel.get(id) === 'pending') {\n channel.set(id, status);\n }\n}\n\nfunction readStatus(id: string): 'pending' | 'not_found' | 'found' {\n let channel = sharedGlobalState();\n let result = channel.get(id) ?? 'pending';\n channel.delete(id);\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"esbuild-request.js","sourceRoot":"","sources":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OAAO,EAAE,CAAC;QACb,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACnB,UAAkB,CAAC,mCAAmC,GAAG,OAAO,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,EAAU;IAC/B,iBAAiB,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAU,EAAE,MAA6B;IACnE,IAAI,OAAO,GAAG,iBAAiB,EAAE,CAAC;IAClC,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,EAAU;;IAC5B,IAAI,OAAO,GAAG,iBAAiB,EAAE,CAAC;IAClC,IAAI,MAAM,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,mCAAI,SAAS,CAAC;IAC1C,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import core from '@embroider/core';\nconst { cleanUrl, packageName } = core;\nimport type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';\nimport { dirname } from 'path';\n\nimport type { PackageCache as _PackageCache, Resolution, ModuleRequest, RequestAdapter } from '@embroider/core';\nimport { externalName } from '@embroider/reverse-exports';\n\ntype PublicAPI<T> = { [K in keyof T]: T[K] };\ntype PackageCache = PublicAPI<_PackageCache>;\n\nexport class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolveResult, OnResolveResult>> {\n static create({\n packageCache,\n phase,\n build,\n kind,\n path,\n importer,\n pluginData,\n }: {\n packageCache: PackageCache;\n phase: 'bundling' | 'other';\n build: PluginBuild;\n kind: ImportKind;\n path: string;\n importer: string | undefined;\n pluginData: Record<string, any> | undefined;\n }) {\n if (!(pluginData?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n\n if (path && importer && path[0] !== '\\0' && !path.startsWith('virtual-module:')) {\n let fromFile = cleanUrl(importer);\n return {\n initialState: {\n specifier: path,\n fromFile,\n meta: pluginData?.embroider?.meta,\n },\n adapter: new EsBuildRequestAdapter(packageCache, phase, build, kind),\n };\n }\n }\n\n private constructor(\n private packageCache: PackageCache,\n private phase: 'bundling' | 'other',\n private context: PluginBuild,\n private kind: ImportKind\n ) {}\n\n get debugType() {\n return 'esbuild';\n }\n\n async resolve(\n request: ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>\n ): Promise<Resolution<OnResolveResult, OnResolveResult>> {\n if (request.isVirtual) {\n return {\n type: 'found',\n filename: request.specifier,\n result: { path: request.specifier, namespace: 'embroider-virtual' },\n isVirtual: request.isVirtual,\n };\n }\n if (request.isNotFound) {\n // todo: make sure this looks correct to users\n return {\n type: 'not_found',\n err: {\n errors: [{ text: `module not found ${request.specifier}` }],\n },\n };\n }\n\n requestStatus(request.specifier);\n\n let result = await this.context.resolve(request.specifier, {\n importer: request.fromFile,\n resolveDir: dirname(request.fromFile),\n kind: this.kind,\n pluginData: {\n embroider: {\n enableCustomResolver: false,\n meta: request.meta,\n },\n },\n });\n\n let status = readStatus(request.specifier);\n\n if (result.errors.length > 0 || status === 'not_found') {\n return { type: 'not_found', err: result };\n } else if (result.external) {\n return { type: 'ignored', result };\n } else {\n if (this.phase === 'bundling') {\n // we need to ensure that we don't traverse back into the app while\n // doing dependency pre-bundling. There are multiple ways an addon can\n // resolve things from the app, due to the existince of both app-js\n // (modules in addons that are logically part of the app's namespace)\n // and non-strict handlebars (which resolves\n // components/helpers/modifiers against the app's global pool).\n let pkg = this.packageCache.ownerOfFile(result.path);\n if (pkg?.root === this.packageCache.appRoot) {\n let externalizedName = request.specifier;\n if (!packageName(externalizedName)) {\n // the request was a relative path. This won't remain valid once\n // it has been bundled into vite/deps. But we know it targets the\n // app, so we can always convert it into a non-relative import\n // from the app's namespace\n //\n // IMPORTANT: whenever an addon resolves a relative path to the\n // app, it does so because our code in the core resolver has\n // rewritten the request to be relative to the app's root. So here\n // we will only ever encounter relative paths that are already\n // relative to the app's root directory.\n externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;\n }\n return {\n type: 'ignored',\n result: {\n path: externalizedName,\n external: true,\n },\n };\n }\n }\n return { type: 'found', filename: result.path, result, isVirtual: request.isVirtual };\n }\n }\n}\n\n/*\n This is an unfortunate necessity. During depscan, vite deliberately hides\n information from esbuild. Specifically, it treats \"not found\" and \"this is an\n external dependency\" as both \"external: true\". But we really care about the\n difference, since we have fallback behaviors for the \"not found\" case. Using\n this global state, our rollup resolver plugin can observe what vite is\n actually doing and communicate that knowledge outward to our esbuild resolver\n plugin.\n */\nfunction sharedGlobalState() {\n let channel = (globalThis as any).__embroider_vite_resolver_channel__ as\n | undefined\n | Map<string, 'pending' | 'found' | 'not_found'>;\n if (!channel) {\n channel = new Map();\n (globalThis as any).__embroider_vite_resolver_channel__ = channel;\n }\n return channel;\n}\n\nfunction requestStatus(id: string): void {\n sharedGlobalState().set(id, 'pending');\n}\n\nexport function writeStatus(id: string, status: 'found' | 'not_found'): void {\n let channel = sharedGlobalState();\n if (channel.get(id) === 'pending') {\n channel.set(id, status);\n }\n}\n\nfunction readStatus(id: string): 'pending' | 'not_found' | 'found' {\n let channel = sharedGlobalState();\n let result = channel.get(id) ?? 'pending';\n channel.delete(id);\n return result;\n}\n"]}
|
package/src/esbuild-resolver.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import core from '@embroider/core';
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
import core, { ModuleRequest } from '@embroider/core';
|
|
3
3
|
const { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
const { readFileSync } = fs;
|
|
6
|
-
import {
|
|
6
|
+
import { EsBuildRequestAdapter } from './esbuild-request.js';
|
|
7
7
|
import { assertNever } from 'assert-never';
|
|
8
8
|
import { hbsToJS } from '@embroider/core';
|
|
9
9
|
import { Preprocessor } from 'content-tag';
|
|
@@ -12,14 +12,14 @@ const templateOnlyComponent = `import templateOnly from '@ember/component/templa
|
|
|
12
12
|
export function esBuildResolver() {
|
|
13
13
|
let resolverLoader = new ResolverLoader(process.cwd());
|
|
14
14
|
let preprocessor = new Preprocessor();
|
|
15
|
-
function transformAndAssert(src, filename) {
|
|
16
|
-
const result =
|
|
15
|
+
async function transformAndAssert(src, filename) {
|
|
16
|
+
const result = await transformAsync(src, { filename });
|
|
17
17
|
if (!result || result.code == null) {
|
|
18
18
|
throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);
|
|
19
19
|
}
|
|
20
20
|
return result.code;
|
|
21
21
|
}
|
|
22
|
-
function onLoad({ path, namespace }) {
|
|
22
|
+
async function onLoad({ path, namespace }) {
|
|
23
23
|
let src;
|
|
24
24
|
if (namespace === 'embroider-template-only-component') {
|
|
25
25
|
src = templateOnlyComponent;
|
|
@@ -37,7 +37,7 @@ export function esBuildResolver() {
|
|
|
37
37
|
src = preprocessor.process(src, { filename: path });
|
|
38
38
|
}
|
|
39
39
|
if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {
|
|
40
|
-
src = transformAndAssert(src, path);
|
|
40
|
+
src = await transformAndAssert(src, path);
|
|
41
41
|
}
|
|
42
42
|
return { contents: src };
|
|
43
43
|
}
|
|
@@ -47,7 +47,15 @@ export function esBuildResolver() {
|
|
|
47
47
|
const phase = detectPhase(build);
|
|
48
48
|
// Embroider Resolver
|
|
49
49
|
build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {
|
|
50
|
-
let request =
|
|
50
|
+
let request = ModuleRequest.create(EsBuildRequestAdapter.create, {
|
|
51
|
+
packageCache: resolverLoader.resolver.packageCache,
|
|
52
|
+
phase,
|
|
53
|
+
build,
|
|
54
|
+
kind,
|
|
55
|
+
path,
|
|
56
|
+
importer,
|
|
57
|
+
pluginData,
|
|
58
|
+
});
|
|
51
59
|
if (!request) {
|
|
52
60
|
return null;
|
|
53
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-resolver.js","sourceRoot":"","sources":["esbuild-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;AAC3F,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,qBAAqB,GACzB,8DAA8D,GAAG,kCAAkC,CAAC;AAEtG,MAAM,UAAU,eAAe;IAC7B,IAAI,cAAc,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvD,IAAI,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IAEtC,SAAS,kBAAkB,CAAC,GAAW,EAAE,QAAgB;QACvD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,wBAAwB,CAAC,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AC;IACjB,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,CAAC,eAAe,CAAC,SAAiB,EAAE,UAAoB;IAC/D,MAAM,SAAS,CAAC;IAChB,iEAAiE;IACjE,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,KAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,GAAG,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin as EsBuildPlugin, OnLoadResult, PluginBuild, ResolveResult } from 'esbuild';\nimport { transform } from '@babel/core';\nimport core from '@embroider/core';\nconst { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;\nimport fs from 'fs-extra';\nconst { readFileSync } = fs;\nimport { EsBuildModuleRequest } from './esbuild-request.js';\nimport { assertNever } from 'assert-never';\nimport { hbsToJS } from '@embroider/core';\nimport { Preprocessor } from 'content-tag';\nimport { extname } from 'path';\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` + `export default templateOnly();\\n`;\n\nexport function esBuildResolver(): EsBuildPlugin {\n let resolverLoader = new ResolverLoader(process.cwd());\n let preprocessor = new Preprocessor();\n\n function transformAndAssert(src: string, filename: string): string {\n const result = transform(src, { filename });\n if (!result || result.code == null) {\n throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);\n }\n return result.code!;\n }\n\n function onLoad({ path, namespace }: { path: string; namespace: string }): OnLoadResult {\n let src: string;\n if (namespace === 'embroider-template-only-component') {\n src = templateOnlyComponent;\n } else if (namespace === 'embroider-virtual') {\n src = virtualContent(path, resolverLoader.resolver).src;\n } else {\n src = readFileSync(path, 'utf8');\n }\n if (path.endsWith('.hbs')) {\n src = hbsToJS(src);\n } else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {\n src = preprocessor.process(src, { filename: path });\n }\n if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {\n src = transformAndAssert(src, path);\n }\n return { contents: src };\n }\n\n return {\n name: 'embroider-esbuild-resolver',\n setup(build) {\n const phase = detectPhase(build);\n\n // Embroider Resolver\n build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {\n let request = EsBuildModuleRequest.from(\n resolverLoader.resolver.packageCache,\n phase,\n build,\n kind,\n path,\n importer,\n pluginData\n );\n if (!request) {\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return resolution.err;\n default:\n throw assertNever(resolution);\n }\n });\n\n // template-only-component synthesis\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderHBSResolving) {\n // reentrance\n return null;\n }\n\n let result = await build.resolve(path, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderHBSResolving: true },\n });\n\n if (result.errors.length === 0 && !result.external) {\n let syntheticPath = needsSyntheticComponentJS(path, result.path);\n if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {\n return { path: syntheticPath, namespace: 'embroider-template-only-component' };\n }\n }\n\n return result;\n });\n\n if (phase === 'bundling') {\n // during bundling phase, we need to provide our own extension\n // searching. We do it here in its own resolve plugin so that it's\n // sitting beneath both embroider resolver and template-only-component\n // synthesizer, since both expect the ambient system to have extension\n // search.\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderExtensionResolving) {\n // reentrance\n return null;\n }\n\n let firstResult: ResolveResult | undefined;\n\n for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {\n let result = await build.resolve(requestName, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderExtensionResolving: true },\n });\n\n if (result.errors.length > 0) {\n // if extension search fails, we want to let the first failure be the\n // one that propagates, so that the error message makes sense.\n firstResult = result;\n } else {\n return result;\n }\n }\n\n return firstResult;\n });\n }\n\n // we need to handle everything from one of our three special namespaces:\n build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);\n\n // we need to handle all hbs\n build.onLoad({ filter: /\\.hbs$/ }, onLoad);\n\n // we need to handle all GJS (to preprocess) and JS (to run macros)\n build.onLoad({ filter: /\\.g?[jt]s$/ }, onLoad);\n },\n };\n}\n\nfunction detectPhase(build: PluginBuild): 'bundling' | 'other' {\n let plugins = (build.initialOptions.plugins ?? []).map(p => p.name);\n if (plugins.includes('vite:dep-pre-bundle')) {\n return 'bundling';\n } else {\n return 'other';\n }\n}\n\nfunction* extensionSearch(specifier: string, extensions: string[]): Generator<string> {\n yield specifier;\n // when there's no explicit extension, we may do extension search\n if (extname(specifier) === '') {\n for (let ext of extensions) {\n yield specifier + ext;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"esbuild-resolver.js","sourceRoot":"","sources":["esbuild-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,IAAI,EAAE,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtD,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;AAC3F,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EA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EAAE,EAAE,MAAM,CAAC,CAAC;YAE3E,4BAA4B;YAC5B,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;YAE3C,mEAAmE;YACnE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAkB;;IACrC,IAAI,OAAO,GAAG,CAAC,MAAA,KAAK,CAAC,cAAc,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpE,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAC5C,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,CAAC,eAAe,CAAC,SAAiB,EAAE,UAAoB;IAC/D,MAAM,SAAS,CAAC;IAChB,iEAAiE;IACjE,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,KAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,GAAG,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin as EsBuildPlugin, OnLoadResult, PluginBuild, ResolveResult } from 'esbuild';\nimport { transformAsync } from '@babel/core';\nimport core, { ModuleRequest } from '@embroider/core';\nconst { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;\nimport fs from 'fs-extra';\nconst { readFileSync } = fs;\nimport { EsBuildRequestAdapter } from './esbuild-request.js';\nimport { assertNever } from 'assert-never';\nimport { hbsToJS } from '@embroider/core';\nimport { Preprocessor } from 'content-tag';\nimport { extname } from 'path';\n\nconst templateOnlyComponent =\n `import templateOnly from '@ember/component/template-only';\\n` + `export default templateOnly();\\n`;\n\nexport function esBuildResolver(): EsBuildPlugin {\n let resolverLoader = new ResolverLoader(process.cwd());\n let preprocessor = new Preprocessor();\n\n async function transformAndAssert(src: string, filename: string): Promise<string> {\n const result = await transformAsync(src, { filename });\n if (!result || result.code == null) {\n throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);\n }\n return result.code!;\n }\n\n async function onLoad({ path, namespace }: { path: string; namespace: string }): Promise<OnLoadResult> {\n let src: string;\n if (namespace === 'embroider-template-only-component') {\n src = templateOnlyComponent;\n } else if (namespace === 'embroider-virtual') {\n src = virtualContent(path, resolverLoader.resolver).src;\n } else {\n src = readFileSync(path, 'utf8');\n }\n if (path.endsWith('.hbs')) {\n src = hbsToJS(src);\n } else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {\n src = preprocessor.process(src, { filename: path });\n }\n if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {\n src = await transformAndAssert(src, path);\n }\n return { contents: src };\n }\n\n return {\n name: 'embroider-esbuild-resolver',\n setup(build) {\n const phase = detectPhase(build);\n\n // Embroider Resolver\n build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {\n let request = ModuleRequest.create(EsBuildRequestAdapter.create, {\n packageCache: resolverLoader.resolver.packageCache,\n phase,\n build,\n kind,\n path,\n importer,\n pluginData,\n });\n if (!request) {\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return resolution.err;\n default:\n throw assertNever(resolution);\n }\n });\n\n // template-only-component synthesis\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderHBSResolving) {\n // reentrance\n return null;\n }\n\n let result = await build.resolve(path, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderHBSResolving: true },\n });\n\n if (result.errors.length === 0 && !result.external) {\n let syntheticPath = needsSyntheticComponentJS(path, result.path);\n if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {\n return { path: syntheticPath, namespace: 'embroider-template-only-component' };\n }\n }\n\n return result;\n });\n\n if (phase === 'bundling') {\n // during bundling phase, we need to provide our own extension\n // searching. We do it here in its own resolve plugin so that it's\n // sitting beneath both embroider resolver and template-only-component\n // synthesizer, since both expect the ambient system to have extension\n // search.\n build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {\n if (pluginData?.embroiderExtensionResolving) {\n // reentrance\n return null;\n }\n\n let firstResult: ResolveResult | undefined;\n\n for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {\n let result = await build.resolve(requestName, {\n namespace,\n resolveDir,\n importer,\n kind,\n // avoid reentrance\n pluginData: { ...pluginData, embroiderExtensionResolving: true },\n });\n\n if (result.errors.length > 0) {\n // if extension search fails, we want to let the first failure be the\n // one that propagates, so that the error message makes sense.\n firstResult = result;\n } else {\n return result;\n }\n }\n\n return firstResult;\n });\n }\n\n // we need to handle everything from one of our three special namespaces:\n build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);\n build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);\n\n // we need to handle all hbs\n build.onLoad({ filter: /\\.hbs$/ }, onLoad);\n\n // we need to handle all GJS (to preprocess) and JS (to run macros)\n build.onLoad({ filter: /\\.g?[jt]s$/ }, onLoad);\n },\n };\n}\n\nfunction detectPhase(build: PluginBuild): 'bundling' | 'other' {\n let plugins = (build.initialOptions.plugins ?? []).map(p => p.name);\n if (plugins.includes('vite:dep-pre-bundle')) {\n return 'bundling';\n } else {\n return 'other';\n }\n}\n\nfunction* extensionSearch(specifier: string, extensions: string[]): Generator<string> {\n yield specifier;\n // when there's no explicit extension, we may do extension search\n if (extname(specifier) === '') {\n for (let ext of extensions) {\n yield specifier + ext;\n }\n }\n}\n"]}
|
package/src/request.d.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import type { ModuleRequest, Resolution } from '@embroider/core';
|
|
1
|
+
import type { ModuleRequest, RequestAdapter, RequestAdapterCreate, Resolution } from '@embroider/core';
|
|
2
2
|
import type { PluginContext, ResolveIdResult } from 'rollup';
|
|
3
3
|
export declare const virtualPrefix = "embroider_virtual:";
|
|
4
|
-
|
|
4
|
+
interface Init {
|
|
5
|
+
context: PluginContext;
|
|
6
|
+
source: string;
|
|
7
|
+
importer: string | undefined;
|
|
8
|
+
custom: Record<string, any> | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare class RollupRequestAdapter implements RequestAdapter<Resolution<ResolveIdResult>> {
|
|
5
11
|
private context;
|
|
6
|
-
readonly specifier: string;
|
|
7
|
-
readonly fromFile: string;
|
|
8
|
-
readonly meta: Record<string, any> | undefined;
|
|
9
|
-
readonly isNotFound: boolean;
|
|
10
|
-
readonly resolvedTo: Resolution<ResolveIdResult> | undefined;
|
|
11
12
|
private queryParams;
|
|
12
13
|
private importerQueryParams;
|
|
13
|
-
static
|
|
14
|
+
static create: RequestAdapterCreate<Init, Resolution<ResolveIdResult>>;
|
|
14
15
|
private constructor();
|
|
15
16
|
get debugType(): string;
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
alias(newSpecifier: string): this;
|
|
20
|
-
rehome(newFromFile: string): this;
|
|
21
|
-
virtualize(filename: string): this;
|
|
22
|
-
withMeta(meta: Record<string, any> | undefined): this;
|
|
23
|
-
notFound(): this;
|
|
24
|
-
defaultResolve(): Promise<Resolution<ResolveIdResult>>;
|
|
25
|
-
resolveTo(resolution: Resolution<ResolveIdResult>): this;
|
|
17
|
+
private specifierWithQueryParams;
|
|
18
|
+
private fromFileWithQueryParams;
|
|
19
|
+
resolve(request: ModuleRequest<Resolution<ResolveIdResult>>): Promise<Resolution<ResolveIdResult>>;
|
|
26
20
|
}
|
|
21
|
+
export {};
|
package/src/request.js
CHANGED
|
@@ -1,108 +1,84 @@
|
|
|
1
1
|
import core from '@embroider/core';
|
|
2
2
|
const { cleanUrl, getUrlQueryParams } = core;
|
|
3
3
|
export const virtualPrefix = 'embroider_virtual:';
|
|
4
|
-
export class
|
|
5
|
-
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
if (!((_b = (_a = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (source && importer && source[0] !== '\0') {
|
|
11
|
-
let nonVirtual;
|
|
12
|
-
if (importer.startsWith(virtualPrefix)) {
|
|
13
|
-
nonVirtual = importer.slice(virtualPrefix.length);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
nonVirtual = importer;
|
|
17
|
-
}
|
|
18
|
-
// strip query params off the importer
|
|
19
|
-
let fromFile = cleanUrl(nonVirtual);
|
|
20
|
-
let importerQueryParams = getUrlQueryParams(nonVirtual);
|
|
21
|
-
// strip query params off the source but keep track of them
|
|
22
|
-
// we use regexp-based methods over a URL object because the
|
|
23
|
-
// source can be a relative path.
|
|
24
|
-
let cleanSource = cleanUrl(source);
|
|
25
|
-
let queryParams = getUrlQueryParams(source);
|
|
26
|
-
return new RollupModuleRequest(context, cleanSource, fromFile, (_c = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _c === void 0 ? void 0 : _c.meta, false, undefined, queryParams, importerQueryParams);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
constructor(context, specifier, fromFile, meta, isNotFound, resolvedTo, queryParams, importerQueryParams) {
|
|
4
|
+
export class RollupRequestAdapter {
|
|
5
|
+
constructor(context, queryParams, importerQueryParams) {
|
|
30
6
|
this.context = context;
|
|
31
|
-
this.specifier = specifier;
|
|
32
|
-
this.fromFile = fromFile;
|
|
33
|
-
this.meta = meta;
|
|
34
|
-
this.isNotFound = isNotFound;
|
|
35
|
-
this.resolvedTo = resolvedTo;
|
|
36
7
|
this.queryParams = queryParams;
|
|
37
8
|
this.importerQueryParams = importerQueryParams;
|
|
38
9
|
}
|
|
39
10
|
get debugType() {
|
|
40
11
|
return 'rollup';
|
|
41
12
|
}
|
|
42
|
-
|
|
43
|
-
return this.
|
|
44
|
-
}
|
|
45
|
-
get specifierWithQueryParams() {
|
|
46
|
-
return `${this.specifier}${this.queryParams}`;
|
|
47
|
-
}
|
|
48
|
-
get fromFileWithQueryParams() {
|
|
49
|
-
return `${this.fromFile}${this.importerQueryParams}`;
|
|
50
|
-
}
|
|
51
|
-
alias(newSpecifier) {
|
|
52
|
-
return new RollupModuleRequest(this.context, newSpecifier, this.fromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
|
|
53
|
-
}
|
|
54
|
-
rehome(newFromFile) {
|
|
55
|
-
if (this.fromFile === newFromFile) {
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return new RollupModuleRequest(this.context, this.specifier, newFromFile, this.meta, false, undefined, this.queryParams, this.importerQueryParams);
|
|
60
|
-
}
|
|
13
|
+
specifierWithQueryParams(specifier) {
|
|
14
|
+
return `${specifier}${this.queryParams}`;
|
|
61
15
|
}
|
|
62
|
-
|
|
63
|
-
return
|
|
16
|
+
fromFileWithQueryParams(fromFile) {
|
|
17
|
+
return `${fromFile}${this.importerQueryParams}`;
|
|
64
18
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
notFound() {
|
|
69
|
-
return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, true, undefined, this.queryParams, this.importerQueryParams);
|
|
70
|
-
}
|
|
71
|
-
async defaultResolve() {
|
|
72
|
-
if (this.isVirtual) {
|
|
19
|
+
async resolve(request) {
|
|
20
|
+
if (request.isVirtual) {
|
|
21
|
+
let specifier = virtualPrefix + request.specifier;
|
|
73
22
|
return {
|
|
74
23
|
type: 'found',
|
|
75
|
-
filename:
|
|
76
|
-
result: {
|
|
77
|
-
|
|
24
|
+
filename: specifier,
|
|
25
|
+
result: {
|
|
26
|
+
id: this.specifierWithQueryParams(specifier),
|
|
27
|
+
resolvedBy: this.fromFileWithQueryParams(request.fromFile),
|
|
28
|
+
},
|
|
29
|
+
isVirtual: request.isVirtual,
|
|
78
30
|
};
|
|
79
31
|
}
|
|
80
|
-
if (
|
|
32
|
+
if (request.isNotFound) {
|
|
81
33
|
// TODO: we can make sure this looks correct in rollup & vite output when a
|
|
82
34
|
// user encounters it
|
|
83
35
|
let err = new Error(`module not found ${this.specifierWithQueryParams}`);
|
|
84
36
|
err.code = 'MODULE_NOT_FOUND';
|
|
85
37
|
return { type: 'not_found', err };
|
|
86
38
|
}
|
|
87
|
-
let result = await this.context.resolve(this.specifierWithQueryParams, this.fromFileWithQueryParams, {
|
|
39
|
+
let result = await this.context.resolve(this.specifierWithQueryParams(request.specifier), this.fromFileWithQueryParams(request.fromFile), {
|
|
88
40
|
skipSelf: true,
|
|
89
41
|
custom: {
|
|
90
42
|
embroider: {
|
|
91
43
|
enableCustomResolver: false,
|
|
92
|
-
meta:
|
|
44
|
+
meta: request.meta,
|
|
93
45
|
},
|
|
94
46
|
},
|
|
95
47
|
});
|
|
96
48
|
if (result) {
|
|
97
49
|
let { pathname } = new URL(result.id, 'http://example.com');
|
|
98
|
-
return { type: 'found', filename: pathname, result, isVirtual:
|
|
50
|
+
return { type: 'found', filename: pathname, result, isVirtual: request.isVirtual };
|
|
99
51
|
}
|
|
100
52
|
else {
|
|
101
53
|
return { type: 'not_found', err: undefined };
|
|
102
54
|
}
|
|
103
55
|
}
|
|
104
|
-
resolveTo(resolution) {
|
|
105
|
-
return new RollupModuleRequest(this.context, this.specifier, this.fromFile, this.meta, this.isNotFound, resolution, this.queryParams, this.importerQueryParams);
|
|
106
|
-
}
|
|
107
56
|
}
|
|
57
|
+
RollupRequestAdapter.create = ({ context, source, importer, custom, }) => {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
if (!((_b = (_a = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (source && importer && source[0] !== '\0') {
|
|
63
|
+
let nonVirtual;
|
|
64
|
+
if (importer.startsWith(virtualPrefix)) {
|
|
65
|
+
nonVirtual = importer.slice(virtualPrefix.length);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
nonVirtual = importer;
|
|
69
|
+
}
|
|
70
|
+
// strip query params off the importer
|
|
71
|
+
let fromFile = cleanUrl(nonVirtual);
|
|
72
|
+
let importerQueryParams = getUrlQueryParams(nonVirtual);
|
|
73
|
+
// strip query params off the source but keep track of them
|
|
74
|
+
// we use regexp-based methods over a URL object because the
|
|
75
|
+
// source can be a relative path.
|
|
76
|
+
let cleanSource = cleanUrl(source);
|
|
77
|
+
let queryParams = getUrlQueryParams(source);
|
|
78
|
+
return {
|
|
79
|
+
initialState: { specifier: cleanSource, fromFile, meta: (_c = custom === null || custom === void 0 ? void 0 : custom.embroider) === null || _c === void 0 ? void 0 : _c.meta },
|
|
80
|
+
adapter: new RollupRequestAdapter(context, queryParams, importerQueryParams),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
108
84
|
//# sourceMappingURL=request.js.map
|
package/src/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["request.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;AAG7C,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["request.ts"],"names":[],"mappings":"A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C,MAAM,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,UAAU,GAAG,QAAQ,CAAC;QACxB,CAAC;QAED,sCAAsC;QACtC,IAAI,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,mBAAmB,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAExD,2DAA2D;QAC3D,4DAA4D;QAC5D,iCAAiC;QACjC,IAAI,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAE5C,OAAO;YACL,YAAY,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,0CAAE,IAAI,EAAE;YACjF,OAAO,EAAE,IAAI,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,mBAAmB,CAAC;SAC7E,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { ModuleRequest, RequestAdapter, RequestAdapterCreate, Resolution } from '@embroider/core';\nimport core from '@embroider/core';\nconst { cleanUrl, getUrlQueryParams } = core;\nimport type { PluginContext, ResolveIdResult } from 'rollup';\n\nexport const virtualPrefix = 'embroider_virtual:';\n\ninterface Init {\n context: PluginContext;\n source: string;\n importer: string | undefined;\n custom: Record<string, any> | undefined;\n}\n\nexport class RollupRequestAdapter implements RequestAdapter<Resolution<ResolveIdResult>> {\n static create: RequestAdapterCreate<Init, Resolution<ResolveIdResult>> = ({\n context,\n source,\n importer,\n custom,\n }: Init) => {\n if (!(custom?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n if (source && importer && source[0] !== '\\0') {\n let nonVirtual: string;\n if (importer.startsWith(virtualPrefix)) {\n nonVirtual = importer.slice(virtualPrefix.length);\n } else {\n nonVirtual = importer;\n }\n\n // strip query params off the importer\n let fromFile = cleanUrl(nonVirtual);\n let importerQueryParams = getUrlQueryParams(nonVirtual);\n\n // strip query params off the source but keep track of them\n // we use regexp-based methods over a URL object because the\n // source can be a relative path.\n let cleanSource = cleanUrl(source);\n let queryParams = getUrlQueryParams(source);\n\n return {\n initialState: { specifier: cleanSource, fromFile, meta: custom?.embroider?.meta },\n adapter: new RollupRequestAdapter(context, queryParams, importerQueryParams),\n };\n }\n };\n\n private constructor(\n private context: PluginContext,\n private queryParams: string,\n private importerQueryParams: string\n ) {}\n\n get debugType() {\n return 'rollup';\n }\n\n private specifierWithQueryParams(specifier: string): string {\n return `${specifier}${this.queryParams}`;\n }\n\n private fromFileWithQueryParams(fromFile: string): string {\n return `${fromFile}${this.importerQueryParams}`;\n }\n\n async resolve(request: ModuleRequest<Resolution<ResolveIdResult>>): Promise<Resolution<ResolveIdResult>> {\n if (request.isVirtual) {\n let specifier = virtualPrefix + request.specifier;\n return {\n type: 'found',\n filename: specifier,\n result: {\n id: this.specifierWithQueryParams(specifier),\n resolvedBy: this.fromFileWithQueryParams(request.fromFile),\n },\n isVirtual: request.isVirtual,\n };\n }\n if (request.isNotFound) {\n // TODO: we can make sure this looks correct in rollup & vite output when a\n // user encounters it\n let err = new Error(`module not found ${this.specifierWithQueryParams}`);\n (err as any).code = 'MODULE_NOT_FOUND';\n return { type: 'not_found', err };\n }\n let result = await this.context.resolve(\n this.specifierWithQueryParams(request.specifier),\n this.fromFileWithQueryParams(request.fromFile),\n {\n skipSelf: true,\n custom: {\n embroider: {\n enableCustomResolver: false,\n meta: request.meta,\n },\n },\n }\n );\n if (result) {\n let { pathname } = new URL(result.id, 'http://example.com');\n return { type: 'found', filename: pathname, result, isVirtual: request.isVirtual };\n } else {\n return { type: 'not_found', err: undefined };\n }\n }\n}\n"]}
|
package/src/resolver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import core from '@embroider/core';
|
|
1
|
+
import core, { ModuleRequest } from '@embroider/core';
|
|
2
2
|
const { virtualContent, ResolverLoader, explicitRelative, cleanUrl, tmpdir } = core;
|
|
3
|
-
import {
|
|
3
|
+
import { RollupRequestAdapter, virtualPrefix } from './request.js';
|
|
4
4
|
import { assertNever } from 'assert-never';
|
|
5
5
|
import makeDebug from 'debug';
|
|
6
6
|
import { resolve, join } from 'path';
|
|
@@ -40,7 +40,12 @@ export function resolver() {
|
|
|
40
40
|
if ((_a = options.custom) === null || _a === void 0 ? void 0 : _a.depScan) {
|
|
41
41
|
return await observeDepScan(this, source, importer, options);
|
|
42
42
|
}
|
|
43
|
-
let request =
|
|
43
|
+
let request = ModuleRequest.create(RollupRequestAdapter.create, {
|
|
44
|
+
context: this,
|
|
45
|
+
source,
|
|
46
|
+
importer,
|
|
47
|
+
custom: options.custom,
|
|
48
|
+
});
|
|
44
49
|
if (!request) {
|
|
45
50
|
// fallthrough to other rollup plugins
|
|
46
51
|
return null;
|
package/src/resolver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":"AACA,OAAO,IAAuB,MAAM,iBAAiB,CAAC;AACtD,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,SAAS,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,EAAE,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teDevServer } from 'vite';\nimport core, { type Resolver } from '@embroider/core';\nconst { virtualContent, ResolverLoader, explicitRelative, cleanUrl, tmpdir } = core;\nimport { RollupModuleRequest, virtualPrefix } from './request.js';\nimport { assertNever } from 'assert-never';\nimport makeDebug from 'debug';\nimport { resolve, join } from 'path';\nimport { writeStatus } from './esbuild-request.js';\nimport type { PluginContext, ResolveIdResult } from 'rollup';\nimport { externalName } from '@embroider/reverse-exports';\nimport fs from 'fs-extra';\nimport { createHash } from 'crypto';\n\nconst { ensureSymlinkSync, outputJSONSync } = fs;\n\nconst debug = makeDebug('embroider:vite');\n\nexport function resolver(): Plugin {\n const resolverLoader = new ResolverLoader(process.cwd());\n let server: ViteDevServer;\n const virtualDeps: Map<string, string[]> = new Map();\n const notViteDeps = new Set<string>();\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n\n configureServer(s) {\n server = s;\n server.watcher.on('all', (_eventName, path) => {\n for (let [id, watches] of virtualDeps) {\n for (let watch of watches) {\n if (path.startsWith(watch)) {\n debug('Invalidate %s because %s', id, path);\n server.moduleGraph.onFileChange(id);\n let m = server.moduleGraph.getModuleById(id);\n if (m) {\n server.reloadModule(m);\n }\n }\n }\n }\n });\n },\n\n async resolveId(source, importer, options) {\n if (options.custom?.depScan) {\n return await observeDepScan(this, source, importer, options);\n }\n\n let request = RollupModuleRequest.from(this, source, importer, options.custom);\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n if (resolution.isVirtual) {\n return resolution.result;\n } else {\n return await maybeCaptureNewOptimizedDep(this, resolverLoader.resolver, resolution.result, notViteDeps);\n }\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n let { pathname } = new URL(id, 'http://example.com');\n let { src, watches } = virtualContent(pathname.slice(virtualPrefix.length + 1), resolverLoader.resolver);\n virtualDeps.set(id, watches);\n server?.watcher.add(watches);\n return src;\n }\n },\n buildEnd() {\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/virtual/vendor.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'),\n resolverLoader.resolver\n ).src,\n });\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/virtual/test-support.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),\n resolverLoader.resolver\n ).src,\n });\n },\n };\n}\n\n// During depscan, we have a wildly different job than during normal\n// usage. Embroider's esbuild resolver plugin replaces this rollup\n// resolver plugin for actually doing resolving, so we don't do any of\n// that. But we are still well-positioned to observe what vite's rollup\n// resolver plugin is doing, and that is important because vite's\n// esbuild depscan plugin will always obscure the results before\n// embroider's esbuild resolver plugin can see them. It obscures the\n// results by marking *both* \"not found\" and \"this is a third-party\n// package\" as \"external: true\". We really care about the difference\n// between the two, since we have fallback behaviors that should apply\n// to \"not found\" that should not apply to successfully discovered\n// third-party packages.\nasync function observeDepScan(context: PluginContext, source: string, importer: string | undefined, options: any) {\n let result = await context.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n writeStatus(source, result ? 'found' : 'not_found');\n return result;\n}\n\nfunction idFromResult(result: ResolveIdResult): string | undefined {\n if (!result) {\n return undefined;\n }\n if (typeof result === 'string') {\n return cleanUrl(result);\n }\n return cleanUrl(result.id);\n}\n\nfunction hashed(path: string): string {\n let h = createHash('sha1');\n return h.update(path).digest('hex').slice(0, 8);\n}\n\nasync function maybeCaptureNewOptimizedDep(\n context: PluginContext,\n resolver: Resolver,\n result: ResolveIdResult,\n notViteDeps: Set<string>\n): Promise<ResolveIdResult> {\n let foundFile = idFromResult(result);\n if (!foundFile) {\n return result;\n }\n if (foundFile.startsWith(join(resolver.packageCache.appRoot, 'node_modules', '.vite'))) {\n debug('maybeCaptureNewOptimizedDep: %s already in vite deps', foundFile);\n return result;\n }\n let pkg = resolver.packageCache.ownerOfFile(foundFile);\n if (!pkg?.isV2Addon()) {\n debug('maybeCaptureNewOptimizedDep: %s not in v2 addon', foundFile);\n return result;\n }\n let target = externalName(pkg.packageJSON, explicitRelative(pkg.root, foundFile));\n if (!target) {\n debug('maybeCaptureNewOptimizedDep: %s is not exported', foundFile);\n return result;\n }\n\n if (notViteDeps.has(foundFile)) {\n debug('maybeCaptureNewOptimizedDep: already attmpted %s', foundFile);\n return result;\n }\n\n debug('maybeCaptureNewOptimizedDep: doing re-resolve for %s ', foundFile);\n\n let jumpRoot = join(tmpdir, 'embroider-vite-jump', hashed(pkg.root));\n let fromFile = join(jumpRoot, 'package.json');\n outputJSONSync(fromFile, {\n name: 'jump-root',\n });\n ensureSymlinkSync(pkg.root, join(jumpRoot, 'node_modules', pkg.name));\n let newResult = await context.resolve(target, fromFile);\n if (newResult) {\n if (idFromResult(newResult) === foundFile) {\n // This case is normal. For example, people could be using\n // `optimizeDeps.exclude` or they might be working in a monorepo where an\n // addon is not in node_modules. In both cases vite will decide not to\n // optimize the file, even though we gave it a chance to.\n //\n // We cache that result so we don't keep trying.\n debug('maybeCaptureNewOptimizedDep: %s did not become an optimized dep', foundFile);\n notViteDeps.add(foundFile);\n }\n\n return newResult;\n } else {\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,EAAE,EAAE,aAAa,EAAiB,MAAM,iBAAiB,CAAC;AACrE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,SAAS,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC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,0DAA0D;YAC1D,yEAAyE;YACzE,sEAAsE;YACtE,yDAAyD;YACzD,EAAE;YACF,gDAAgD;YAChD,KAAK,CAAC,iEAAiE,EAAE,SAAS,CAAC,CAAC;YACpF,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin, ViteDevServer } from 'vite';\nimport core, { ModuleRequest, type Resolver } from '@embroider/core';\nconst { virtualContent, ResolverLoader, explicitRelative, cleanUrl, tmpdir } = core;\nimport { RollupRequestAdapter, virtualPrefix } from './request.js';\nimport { assertNever } from 'assert-never';\nimport makeDebug from 'debug';\nimport { resolve, join } from 'path';\nimport { writeStatus } from './esbuild-request.js';\nimport type { PluginContext, ResolveIdResult } from 'rollup';\nimport { externalName } from '@embroider/reverse-exports';\nimport fs from 'fs-extra';\nimport { createHash } from 'crypto';\n\nconst { ensureSymlinkSync, outputJSONSync } = fs;\n\nconst debug = makeDebug('embroider:vite');\n\nexport function resolver(): Plugin {\n const resolverLoader = new ResolverLoader(process.cwd());\n let server: ViteDevServer;\n const virtualDeps: Map<string, string[]> = new Map();\n const notViteDeps = new Set<string>();\n\n return {\n name: 'embroider-resolver',\n enforce: 'pre',\n\n configureServer(s) {\n server = s;\n server.watcher.on('all', (_eventName, path) => {\n for (let [id, watches] of virtualDeps) {\n for (let watch of watches) {\n if (path.startsWith(watch)) {\n debug('Invalidate %s because %s', id, path);\n server.moduleGraph.onFileChange(id);\n let m = server.moduleGraph.getModuleById(id);\n if (m) {\n server.reloadModule(m);\n }\n }\n }\n }\n });\n },\n\n async resolveId(source, importer, options) {\n if (options.custom?.depScan) {\n return await observeDepScan(this, source, importer, options);\n }\n\n let request = ModuleRequest.create(RollupRequestAdapter.create, {\n context: this,\n source,\n importer,\n custom: options.custom,\n });\n if (!request) {\n // fallthrough to other rollup plugins\n return null;\n }\n let resolution = await resolverLoader.resolver.resolve(request);\n switch (resolution.type) {\n case 'found':\n if (resolution.isVirtual) {\n return resolution.result;\n } else {\n return await maybeCaptureNewOptimizedDep(this, resolverLoader.resolver, resolution.result, notViteDeps);\n }\n case 'ignored':\n return resolution.result;\n case 'not_found':\n return null;\n default:\n throw assertNever(resolution);\n }\n },\n load(id) {\n if (id.startsWith(virtualPrefix)) {\n let { pathname } = new URL(id, 'http://example.com');\n let { src, watches } = virtualContent(pathname.slice(virtualPrefix.length + 1), resolverLoader.resolver);\n virtualDeps.set(id, watches);\n server?.watcher.add(watches);\n return src;\n }\n },\n buildEnd() {\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/virtual/vendor.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-vendor.js'),\n resolverLoader.resolver\n ).src,\n });\n this.emitFile({\n type: 'asset',\n fileName: '@embroider/virtual/test-support.js',\n source: virtualContent(\n resolve(resolverLoader.resolver.options.engines[0].root, '-embroider-test-support.js'),\n resolverLoader.resolver\n ).src,\n });\n },\n };\n}\n\n// During depscan, we have a wildly different job than during normal\n// usage. Embroider's esbuild resolver plugin replaces this rollup\n// resolver plugin for actually doing resolving, so we don't do any of\n// that. But we are still well-positioned to observe what vite's rollup\n// resolver plugin is doing, and that is important because vite's\n// esbuild depscan plugin will always obscure the results before\n// embroider's esbuild resolver plugin can see them. It obscures the\n// results by marking *both* \"not found\" and \"this is a third-party\n// package\" as \"external: true\". We really care about the difference\n// between the two, since we have fallback behaviors that should apply\n// to \"not found\" that should not apply to successfully discovered\n// third-party packages.\nasync function observeDepScan(context: PluginContext, source: string, importer: string | undefined, options: any) {\n let result = await context.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n writeStatus(source, result ? 'found' : 'not_found');\n return result;\n}\n\nfunction idFromResult(result: ResolveIdResult): string | undefined {\n if (!result) {\n return undefined;\n }\n if (typeof result === 'string') {\n return cleanUrl(result);\n }\n return cleanUrl(result.id);\n}\n\nfunction hashed(path: string): string {\n let h = createHash('sha1');\n return h.update(path).digest('hex').slice(0, 8);\n}\n\nasync function maybeCaptureNewOptimizedDep(\n context: PluginContext,\n resolver: Resolver,\n result: ResolveIdResult,\n notViteDeps: Set<string>\n): Promise<ResolveIdResult> {\n let foundFile = idFromResult(result);\n if (!foundFile) {\n return result;\n }\n if (foundFile.startsWith(join(resolver.packageCache.appRoot, 'node_modules', '.vite'))) {\n debug('maybeCaptureNewOptimizedDep: %s already in vite deps', foundFile);\n return result;\n }\n let pkg = resolver.packageCache.ownerOfFile(foundFile);\n if (!pkg?.isV2Addon()) {\n debug('maybeCaptureNewOptimizedDep: %s not in v2 addon', foundFile);\n return result;\n }\n let target = externalName(pkg.packageJSON, explicitRelative(pkg.root, foundFile));\n if (!target) {\n debug('maybeCaptureNewOptimizedDep: %s is not exported', foundFile);\n return result;\n }\n\n if (notViteDeps.has(foundFile)) {\n debug('maybeCaptureNewOptimizedDep: already attmpted %s', foundFile);\n return result;\n }\n\n debug('maybeCaptureNewOptimizedDep: doing re-resolve for %s ', foundFile);\n\n let jumpRoot = join(tmpdir, 'embroider-vite-jump', hashed(pkg.root));\n let fromFile = join(jumpRoot, 'package.json');\n outputJSONSync(fromFile, {\n name: 'jump-root',\n });\n ensureSymlinkSync(pkg.root, join(jumpRoot, 'node_modules', pkg.name));\n let newResult = await context.resolve(target, fromFile);\n if (newResult) {\n if (idFromResult(newResult) === foundFile) {\n // This case is normal. For example, people could be using\n // `optimizeDeps.exclude` or they might be working in a monorepo where an\n // addon is not in node_modules. In both cases vite will decide not to\n // optimize the file, even though we gave it a chance to.\n //\n // We cache that result so we don't keep trying.\n debug('maybeCaptureNewOptimizedDep: %s did not become an optimized dep', foundFile);\n notViteDeps.add(foundFile);\n }\n\n return newResult;\n } else {\n return result;\n }\n}\n"]}
|