@embroider/vite 0.2.1 → 0.2.2-unstable.aaeb674
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.d.ts +4 -1
- package/index.mjs +4 -1
- package/package.json +25 -11
- package/src/assets.d.ts +2 -0
- package/src/assets.js +87 -0
- package/src/assets.js.map +1 -0
- package/src/build.d.ts +3 -0
- package/src/build.js +60 -0
- package/src/build.js.map +1 -0
- package/src/content-for.d.ts +2 -0
- package/src/content-for.js +19 -0
- package/src/content-for.js.map +1 -0
- package/src/esbuild-request.d.ts +30 -0
- package/src/esbuild-request.js +162 -0
- package/src/esbuild-request.js.map +1 -0
- package/src/esbuild-resolver.d.ts +2 -0
- package/src/esbuild-resolver.js +150 -0
- package/src/esbuild-resolver.js.map +1 -0
- package/src/hbs.js +62 -89
- package/src/hbs.js.map +1 -1
- package/src/optimize-deps.js +6 -4
- package/src/optimize-deps.js.map +1 -1
- package/src/request.d.ts +14 -2
- package/src/request.js +74 -18
- package/src/request.js.map +1 -1
- package/src/resolver.js +145 -41
- package/src/resolver.js.map +1 -1
- package/src/scripts.js +17 -37
- package/src/scripts.js.map +1 -1
- package/src/template-tag.js +7 -37
- package/src/template-tag.js.map +1 -1
- package/src/addons.d.ts +0 -1
- package/src/addons.js +0 -23
- package/src/addons.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './src/resolver.js';
|
|
2
|
+
export * from './src/esbuild-resolver.js';
|
|
2
3
|
export * from './src/hbs.js';
|
|
3
4
|
export * from './src/scripts.js';
|
|
4
5
|
export * from './src/template-tag.js';
|
|
5
|
-
export * from './src/addons.js';
|
|
6
6
|
export * from './src/optimize-deps.js';
|
|
7
|
+
export * from './src/assets.js';
|
|
8
|
+
export * from './src/build.js';
|
|
9
|
+
export * from './src/content-for.js';
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './src/resolver.js';
|
|
2
|
+
export * from './src/esbuild-resolver.js';
|
|
2
3
|
export * from './src/hbs.js';
|
|
3
4
|
export * from './src/scripts.js';
|
|
4
5
|
export * from './src/template-tag.js';
|
|
5
|
-
export * from './src/addons.js';
|
|
6
6
|
export * from './src/optimize-deps.js';
|
|
7
|
+
export * from './src/build.js';
|
|
8
|
+
export * from './src/assets.js';
|
|
9
|
+
export * from './src/content-for.js';
|
package/package.json
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/vite",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.2.2-unstable.aaeb674",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"default": "./index.mjs",
|
|
8
|
+
"types": "./index.d.ts"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
5
11
|
"peerDependencies": {
|
|
6
|
-
"vite": "^
|
|
7
|
-
"@embroider/core": "^3.4.
|
|
12
|
+
"vite": "^5.2.0",
|
|
13
|
+
"@embroider/core": "^3.4.20-unstable.aaeb674"
|
|
8
14
|
},
|
|
9
15
|
"dependencies": {
|
|
10
|
-
"@
|
|
16
|
+
"@babel/core": "^7.22.9",
|
|
17
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
11
18
|
"assert-never": "^1.2.1",
|
|
12
|
-
"content-tag": "^2.0.
|
|
19
|
+
"content-tag": "^2.0.2",
|
|
13
20
|
"debug": "^4.3.2",
|
|
21
|
+
"esbuild": "^0.17.19",
|
|
22
|
+
"fast-glob": "^3.3.2",
|
|
14
23
|
"fs-extra": "^10.0.0",
|
|
15
24
|
"jsdom": "^25.0.0",
|
|
25
|
+
"send": "^0.18.0",
|
|
16
26
|
"source-map-url": "^0.4.1",
|
|
17
|
-
"terser": "^5.7.0"
|
|
27
|
+
"terser": "^5.7.0",
|
|
28
|
+
"@embroider/macros": "1.16.10-unstable.aaeb674",
|
|
29
|
+
"@embroider/reverse-exports": "0.1.1-unstable.aaeb674"
|
|
18
30
|
},
|
|
19
31
|
"devDependencies": {
|
|
32
|
+
"@types/babel__core": "^7.20.1",
|
|
20
33
|
"@types/debug": "^4.1.5",
|
|
21
|
-
"@types/jsdom": "^16.2.11",
|
|
22
34
|
"@types/fs-extra": "^9.0.12",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
35
|
+
"@types/jsdom": "^16.2.11",
|
|
36
|
+
"@types/send": "^0.17.4",
|
|
37
|
+
"rollup": "^4.18.0",
|
|
38
|
+
"vite": "^5.3.3",
|
|
39
|
+
"@embroider/core": "^3.4.20-unstable.aaeb674"
|
|
26
40
|
},
|
|
27
41
|
"files": [
|
|
28
42
|
"index.mjs",
|
package/src/assets.d.ts
ADDED
package/src/assets.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import core from '@embroider/core';
|
|
2
|
+
const { ResolverLoader } = core;
|
|
3
|
+
import * as process from 'process';
|
|
4
|
+
import { join, posix } from 'path';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
const { existsSync, readFileSync, lstatSync } = fs;
|
|
7
|
+
import send from 'send';
|
|
8
|
+
function findPublicAsset(relativePath, resolver) {
|
|
9
|
+
var _a;
|
|
10
|
+
const packageCache = resolver.packageCache;
|
|
11
|
+
let pkg = packageCache.ownerOfFile(relativePath);
|
|
12
|
+
for (const engine of resolver.options.engines) {
|
|
13
|
+
for (const addon of engine.activeAddons) {
|
|
14
|
+
pkg = packageCache.ownerOfFile(addon.root);
|
|
15
|
+
if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {
|
|
16
|
+
const asset = (_a = Object.entries(pkg.meta['public-assets']).find(([_key, a]) => posix.resolve('/', a) === relativePath)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17
|
+
let local = asset ? join(addon.root, asset) : null;
|
|
18
|
+
if (local && existsSync(local)) {
|
|
19
|
+
return local;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function assets() {
|
|
26
|
+
const cwd = process.cwd();
|
|
27
|
+
const resolverLoader = new ResolverLoader(cwd);
|
|
28
|
+
let mode = 'build';
|
|
29
|
+
let publicDir = 'public';
|
|
30
|
+
return {
|
|
31
|
+
name: 'assets',
|
|
32
|
+
enforce: 'post',
|
|
33
|
+
configResolved(options) {
|
|
34
|
+
mode = options.command;
|
|
35
|
+
publicDir = options.publicDir;
|
|
36
|
+
},
|
|
37
|
+
configureServer(server) {
|
|
38
|
+
return () => {
|
|
39
|
+
server.middlewares.use((req, res, next) => {
|
|
40
|
+
if (req.originalUrl && req.originalUrl.length > 1) {
|
|
41
|
+
const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);
|
|
42
|
+
if (assetUrl) {
|
|
43
|
+
return send(req, assetUrl).pipe(res);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return next();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
buildStart: {
|
|
51
|
+
// we need to wait for the compatBuild plugin's buildStart hook to finish
|
|
52
|
+
// so that the resolver config exists before we try to read it.
|
|
53
|
+
sequential: true,
|
|
54
|
+
order: 'post',
|
|
55
|
+
async handler() {
|
|
56
|
+
if (mode !== 'build')
|
|
57
|
+
return;
|
|
58
|
+
const engines = resolverLoader.resolver.options.engines;
|
|
59
|
+
for (const engine of engines) {
|
|
60
|
+
const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));
|
|
61
|
+
packages.forEach(pkg => {
|
|
62
|
+
if (!pkg || !pkg.isV2Addon())
|
|
63
|
+
return;
|
|
64
|
+
const assets = pkg.meta['public-assets'] || {};
|
|
65
|
+
Object.entries(assets).forEach(([path, dest]) => {
|
|
66
|
+
// do not override app public assets
|
|
67
|
+
if (existsSync(join(publicDir, dest))) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const filePath = join(pkg.root, path);
|
|
71
|
+
if (!lstatSync(filePath).isFile()) {
|
|
72
|
+
console.log(`Invalid package definition, ${pkg.name} has defined a file "${path}" that is not a file`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.emitFile({
|
|
76
|
+
type: 'asset',
|
|
77
|
+
source: readFileSync(filePath),
|
|
78
|
+
fileName: posix.resolve('/', dest).slice(1),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +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;AAGxB,SAAS,eAAe,CAAC,YAAoB,EAAE,QAAkB;;IAC/D,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;IAC3C,IAAI,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAEjD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxC,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,GAAG,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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';\nimport type { Readable } from 'stream';\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 as Readable, assetUrl).pipe(res);\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"]}
|
package/src/build.d.ts
ADDED
package/src/build.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fork } from 'child_process';
|
|
2
|
+
export function emberBuild(command, mode, resolvableExtensions) {
|
|
3
|
+
let env = {
|
|
4
|
+
...process.env,
|
|
5
|
+
EMBROIDER_PREBUILD: 'true',
|
|
6
|
+
};
|
|
7
|
+
if (resolvableExtensions) {
|
|
8
|
+
env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions === null || resolvableExtensions === void 0 ? void 0 : resolvableExtensions.join(',');
|
|
9
|
+
}
|
|
10
|
+
if (command === 'build') {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], { env });
|
|
13
|
+
child.on('exit', code => (code === 0 ? resolve() : reject()));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {
|
|
18
|
+
silent: true,
|
|
19
|
+
env,
|
|
20
|
+
});
|
|
21
|
+
child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));
|
|
22
|
+
child.on('spawn', () => {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', data => {
|
|
25
|
+
console.error(data.toString());
|
|
26
|
+
});
|
|
27
|
+
child.stdout.on('data', data => {
|
|
28
|
+
console.log(data.toString());
|
|
29
|
+
if (data.toString().includes('Build successful')) {
|
|
30
|
+
resolve();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function compatPrebuild() {
|
|
37
|
+
let viteCommand;
|
|
38
|
+
let viteMode;
|
|
39
|
+
let resolvableExtensions;
|
|
40
|
+
return {
|
|
41
|
+
name: 'embroider-builder',
|
|
42
|
+
enforce: 'pre',
|
|
43
|
+
config(config, { mode, command }) {
|
|
44
|
+
var _a;
|
|
45
|
+
viteCommand = command;
|
|
46
|
+
viteMode = mode;
|
|
47
|
+
resolvableExtensions = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.extensions;
|
|
48
|
+
},
|
|
49
|
+
async buildStart() {
|
|
50
|
+
if (!viteCommand) {
|
|
51
|
+
throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);
|
|
52
|
+
}
|
|
53
|
+
if (!viteMode) {
|
|
54
|
+
throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);
|
|
55
|
+
}
|
|
56
|
+
await emberBuild(viteCommand, viteMode, resolvableExtensions);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=build.js.map
|
package/src/build.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,IAAY,EAAE,oBAA0C;IAClG,IAAI,GAAG,GAA2B;QAChC,GAAG,OAAO,CAAC,GAAG;QACd,kBAAkB,EAAE,MAAM;KAC3B,CAAC;IAEF,IAAI,oBAAoB,EAAE,CAAC;QACzB,GAAG,CAAC,iCAAiC,CAAC,GAAG,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,oCAAoC,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YACpG,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,oCAAoC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,eAAe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AAC,UAAU;YACd,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;YACjF,CAAC;YACD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC9E,CAAC;YACD,MAAM,UAAU,CAAC,WAAW,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAChE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { fork } from 'child_process';\nimport type { Plugin } from 'vite';\n\nexport function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void> {\n let env: Record<string, string> = {\n ...process.env,\n EMBROIDER_PREBUILD: 'true',\n };\n\n if (resolvableExtensions) {\n env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions?.join(',');\n }\n\n if (command === 'build') {\n return new Promise((resolve, reject) => {\n const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], { env });\n child.on('exit', code => (code === 0 ? resolve() : reject()));\n });\n }\n return new Promise((resolve, reject) => {\n const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {\n silent: true,\n env,\n });\n child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));\n child.on('spawn', () => {\n child.stderr?.on('data', data => {\n console.error(data.toString());\n });\n child.stdout!.on('data', data => {\n console.log(data.toString());\n if (data.toString().includes('Build successful')) {\n resolve();\n }\n });\n });\n });\n}\n\nexport function compatPrebuild(): Plugin {\n let viteCommand: string | undefined;\n let viteMode: string | undefined;\n let resolvableExtensions: string[] | undefined;\n\n return {\n name: 'embroider-builder',\n enforce: 'pre',\n config(config, { mode, command }) {\n viteCommand = command;\n viteMode = mode;\n resolvableExtensions = config.resolve?.extensions;\n },\n async buildStart() {\n if (!viteCommand) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);\n }\n if (!viteMode) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);\n }\n await emberBuild(viteCommand, viteMode, resolvableExtensions);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
const { readJSONSync } = fs;
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import core from '@embroider/core';
|
|
5
|
+
const { locateEmbroiderWorkingDir } = core;
|
|
6
|
+
export function contentFor() {
|
|
7
|
+
return {
|
|
8
|
+
name: 'embroider-content-for',
|
|
9
|
+
transformIndexHtml(html, { path }) {
|
|
10
|
+
let config = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));
|
|
11
|
+
let contentsForConfig = config[path];
|
|
12
|
+
for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {
|
|
13
|
+
html = html.replace(`{{content-for "${contentType}"}}`, `${htmlContent}`);
|
|
14
|
+
}
|
|
15
|
+
return html;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=content-for.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-for.js","sourceRoot":"","sources":["content-for.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,yBAAyB,EAAE,GAAG,IAAI,CAAC;AAE3C,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAE7B,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE;YAC/B,IAAI,MAAM,GAAQ,YAAY,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;YACnG,IAAI,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACrC,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC3E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,WAAW,KAAK,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'vite';\nimport fs from 'fs-extra';\nconst { readJSONSync } = fs;\nimport { join } from 'path';\nimport core from '@embroider/core';\nconst { locateEmbroiderWorkingDir } = core;\n\nexport function contentFor(): Plugin {\n return {\n name: 'embroider-content-for',\n\n transformIndexHtml(html, { path }) {\n let config: any = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));\n let contentsForConfig = config[path];\n for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {\n html = html.replace(`{{content-for \"${contentType}\"}}`, `${htmlContent}`);\n }\n return html;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
|
|
2
|
+
import type { PackageCache as _PackageCache, Resolution, ModuleRequest } from '@embroider/core';
|
|
3
|
+
type PublicAPI<T> = {
|
|
4
|
+
[K in keyof T]: T[K];
|
|
5
|
+
};
|
|
6
|
+
type PackageCache = PublicAPI<_PackageCache>;
|
|
7
|
+
export declare class EsBuildModuleRequest implements ModuleRequest {
|
|
8
|
+
private packageCache;
|
|
9
|
+
private phase;
|
|
10
|
+
private context;
|
|
11
|
+
private kind;
|
|
12
|
+
readonly specifier: string;
|
|
13
|
+
readonly fromFile: string;
|
|
14
|
+
readonly meta: Record<string, any> | undefined;
|
|
15
|
+
readonly isVirtual: boolean;
|
|
16
|
+
readonly isNotFound: boolean;
|
|
17
|
+
readonly resolvedTo: Resolution<OnResolveResult, OnResolveResult> | undefined;
|
|
18
|
+
static from(packageCache: PackageCache, phase: 'bundling' | 'other', context: PluginBuild, kind: ImportKind, source: string, importer: string | undefined, pluginData: Record<string, any> | undefined): EsBuildModuleRequest | undefined;
|
|
19
|
+
private constructor();
|
|
20
|
+
get debugType(): string;
|
|
21
|
+
alias(newSpecifier: string): this;
|
|
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>>;
|
|
28
|
+
}
|
|
29
|
+
export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import core from '@embroider/core';
|
|
2
|
+
const { cleanUrl, packageName } = core;
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import { externalName } from '@embroider/reverse-exports';
|
|
5
|
+
export class EsBuildModuleRequest {
|
|
6
|
+
static from(packageCache, phase, context, kind, source, importer, pluginData) {
|
|
7
|
+
var _a, _b, _c;
|
|
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
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (source && importer && source[0] !== '\0' && !source.startsWith('virtual-module:')) {
|
|
12
|
+
let fromFile = cleanUrl(importer);
|
|
13
|
+
return new EsBuildModuleRequest(packageCache, phase, context, kind, source, fromFile, (_c = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _c === void 0 ? void 0 : _c.meta, false, false, undefined);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
constructor(packageCache, phase, context, kind, specifier, fromFile, meta, isVirtual, isNotFound, resolvedTo) {
|
|
17
|
+
this.packageCache = packageCache;
|
|
18
|
+
this.phase = phase;
|
|
19
|
+
this.context = context;
|
|
20
|
+
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
|
+
get debugType() {
|
|
29
|
+
return 'esbuild';
|
|
30
|
+
}
|
|
31
|
+
alias(newSpecifier) {
|
|
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;
|
|
56
|
+
if (request.isVirtual) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'found',
|
|
59
|
+
filename: request.specifier,
|
|
60
|
+
result: { path: request.specifier, namespace: 'embroider-virtual' },
|
|
61
|
+
isVirtual: this.isVirtual,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (request.isNotFound) {
|
|
65
|
+
// todo: make sure this looks correct to users
|
|
66
|
+
return {
|
|
67
|
+
type: 'not_found',
|
|
68
|
+
err: {
|
|
69
|
+
errors: [{ text: `module not found ${request.specifier}` }],
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
requestStatus(request.specifier);
|
|
74
|
+
let result = await this.context.resolve(request.specifier, {
|
|
75
|
+
importer: request.fromFile,
|
|
76
|
+
resolveDir: dirname(request.fromFile),
|
|
77
|
+
kind: this.kind,
|
|
78
|
+
pluginData: {
|
|
79
|
+
embroider: {
|
|
80
|
+
enableCustomResolver: false,
|
|
81
|
+
meta: request.meta,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
let status = readStatus(request.specifier);
|
|
86
|
+
if (result.errors.length > 0 || status === 'not_found') {
|
|
87
|
+
return { type: 'not_found', err: result };
|
|
88
|
+
}
|
|
89
|
+
else if (result.external) {
|
|
90
|
+
return { type: 'ignored', result };
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (this.phase === 'bundling') {
|
|
94
|
+
// we need to ensure that we don't traverse back into the app while
|
|
95
|
+
// doing dependency pre-bundling. There are multiple ways an addon can
|
|
96
|
+
// resolve things from the app, due to the existince of both app-js
|
|
97
|
+
// (modules in addons that are logically part of the app's namespace)
|
|
98
|
+
// and non-strict handlebars (which resolves
|
|
99
|
+
// components/helpers/modifiers against the app's global pool).
|
|
100
|
+
let pkg = this.packageCache.ownerOfFile(result.path);
|
|
101
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) === this.packageCache.appRoot) {
|
|
102
|
+
let externalizedName = request.specifier;
|
|
103
|
+
if (!packageName(externalizedName)) {
|
|
104
|
+
// the request was a relative path. This won't remain valid once
|
|
105
|
+
// it has been bundled into vite/deps. But we know it targets the
|
|
106
|
+
// app, so we can always convert it into a non-relative import
|
|
107
|
+
// from the app's namespace
|
|
108
|
+
//
|
|
109
|
+
// IMPORTANT: whenever an addon resolves a relative path to the
|
|
110
|
+
// app, it does so because our code in the core resolver has
|
|
111
|
+
// rewritten the request to be relative to the app's root. So here
|
|
112
|
+
// we will only ever encounter relative paths that are already
|
|
113
|
+
// relative to the app's root directory.
|
|
114
|
+
externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
type: 'ignored',
|
|
118
|
+
result: {
|
|
119
|
+
path: externalizedName,
|
|
120
|
+
external: true,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/*
|
|
130
|
+
This is an unfortunate necessity. During depscan, vite deliberately hides
|
|
131
|
+
information from esbuild. Specifically, it treats "not found" and "this is an
|
|
132
|
+
external dependency" as both "external: true". But we really care about the
|
|
133
|
+
difference, since we have fallback behaviors for the "not found" case. Using
|
|
134
|
+
this global state, our rollup resolver plugin can observe what vite is
|
|
135
|
+
actually doing and communicate that knowledge outward to our esbuild resolver
|
|
136
|
+
plugin.
|
|
137
|
+
*/
|
|
138
|
+
function sharedGlobalState() {
|
|
139
|
+
let channel = globalThis.__embroider_vite_resolver_channel__;
|
|
140
|
+
if (!channel) {
|
|
141
|
+
channel = new Map();
|
|
142
|
+
globalThis.__embroider_vite_resolver_channel__ = channel;
|
|
143
|
+
}
|
|
144
|
+
return channel;
|
|
145
|
+
}
|
|
146
|
+
function requestStatus(id) {
|
|
147
|
+
sharedGlobalState().set(id, 'pending');
|
|
148
|
+
}
|
|
149
|
+
export function writeStatus(id, status) {
|
|
150
|
+
let channel = sharedGlobalState();
|
|
151
|
+
if (channel.get(id) === 'pending') {
|
|
152
|
+
channel.set(id, status);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function readStatus(id) {
|
|
156
|
+
var _a;
|
|
157
|
+
let channel = sharedGlobalState();
|
|
158
|
+
let result = (_a = channel.get(id)) !== null && _a !== void 0 ? _a : 'pending';
|
|
159
|
+
channel.delete(id);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=esbuild-request.js.map
|
|
@@ -0,0 +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,MAAM,OAAO,oBAAoB;IAC/B,MAAM,CAAC,IAAI,CACT,YAA0B,EAC1B,KAA2B,EAC3B,OAAoB,EACpB,IAAgB,EAChB,MAAc,EACd,QAA4B,EAC5B,UAA2C;;QAE3C,IAAI,CAAC,CAAC,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,0CAAE,oBAAoB,mCAAI,IAAI,CAAC,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACtF,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,C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QG;AACH,SAAS,iBAAiB;IACxB,IAAI,OAAO,GAAI,UAAkB,CAAC,mCAEgB,CAAC;IACnD,IAAI,CAAC,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 } 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"]}
|