@embroider/vite 0.2.1 → 0.2.2-unstable.35f48d4
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 +33 -0
- package/src/esbuild-request.js +139 -0
- package/src/esbuild-request.js.map +1 -0
- package/src/esbuild-resolver.d.ts +2 -0
- package/src/esbuild-resolver.js +158 -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 +18 -11
- package/src/request.js +73 -41
- package/src/request.js.map +1 -1
- package/src/resolver.js +150 -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.35f48d4",
|
|
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.35f48d4"
|
|
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.35f48d4",
|
|
29
|
+
"@embroider/reverse-exports": "0.1.1-unstable.35f48d4"
|
|
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.35f48d4"
|
|
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;AAExB,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,I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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';\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"]}
|
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,EA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,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,33 @@
|
|
|
1
|
+
import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
|
|
2
|
+
import type { PackageCache as _PackageCache, Resolution, ModuleRequest, RequestAdapter } from '@embroider/core';
|
|
3
|
+
type PublicAPI<T> = {
|
|
4
|
+
[K in keyof T]: T[K];
|
|
5
|
+
};
|
|
6
|
+
type PackageCache = PublicAPI<_PackageCache>;
|
|
7
|
+
export declare class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolveResult, OnResolveResult>> {
|
|
8
|
+
private packageCache;
|
|
9
|
+
private phase;
|
|
10
|
+
private context;
|
|
11
|
+
private kind;
|
|
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;
|
|
28
|
+
private constructor();
|
|
29
|
+
get debugType(): string;
|
|
30
|
+
resolve(request: ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>): Promise<Resolution<OnResolveResult, OnResolveResult>>;
|
|
31
|
+
}
|
|
32
|
+
export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
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 EsBuildRequestAdapter {
|
|
6
|
+
static create({ packageCache, phase, build, kind, path, 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 (path && importer && path[0] !== '\0' && !path.startsWith('virtual-module:')) {
|
|
12
|
+
let fromFile = cleanUrl(importer);
|
|
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
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
constructor(packageCache, phase, context, kind) {
|
|
24
|
+
this.packageCache = packageCache;
|
|
25
|
+
this.phase = phase;
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.kind = kind;
|
|
28
|
+
}
|
|
29
|
+
get debugType() {
|
|
30
|
+
return 'esbuild';
|
|
31
|
+
}
|
|
32
|
+
async resolve(request) {
|
|
33
|
+
if (request.isVirtual) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'found',
|
|
36
|
+
filename: request.specifier,
|
|
37
|
+
result: { path: request.specifier, namespace: 'embroider-virtual' },
|
|
38
|
+
isVirtual: request.isVirtual,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (request.isNotFound) {
|
|
42
|
+
// todo: make sure this looks correct to users
|
|
43
|
+
return {
|
|
44
|
+
type: 'not_found',
|
|
45
|
+
err: {
|
|
46
|
+
errors: [{ text: `module not found ${request.specifier}` }],
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
requestStatus(request.specifier);
|
|
51
|
+
let result = await this.context.resolve(request.specifier, {
|
|
52
|
+
importer: request.fromFile,
|
|
53
|
+
resolveDir: dirname(request.fromFile),
|
|
54
|
+
kind: this.kind,
|
|
55
|
+
pluginData: {
|
|
56
|
+
embroider: {
|
|
57
|
+
enableCustomResolver: false,
|
|
58
|
+
meta: request.meta,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
let status = readStatus(request.specifier);
|
|
63
|
+
if (result.errors.length > 0 || status === 'not_found') {
|
|
64
|
+
return { type: 'not_found', err: result };
|
|
65
|
+
}
|
|
66
|
+
else if (result.external) {
|
|
67
|
+
return { type: 'ignored', result };
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (this.phase === 'bundling') {
|
|
71
|
+
// we need to ensure that we don't traverse back into the app while
|
|
72
|
+
// doing dependency pre-bundling. There are multiple ways an addon can
|
|
73
|
+
// resolve things from the app, due to the existince of both app-js
|
|
74
|
+
// (modules in addons that are logically part of the app's namespace)
|
|
75
|
+
// and non-strict handlebars (which resolves
|
|
76
|
+
// components/helpers/modifiers against the app's global pool).
|
|
77
|
+
let pkg = this.packageCache.ownerOfFile(result.path);
|
|
78
|
+
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) === this.packageCache.appRoot) {
|
|
79
|
+
let externalizedName = request.specifier;
|
|
80
|
+
if (!packageName(externalizedName)) {
|
|
81
|
+
// the request was a relative path. This won't remain valid once
|
|
82
|
+
// it has been bundled into vite/deps. But we know it targets the
|
|
83
|
+
// app, so we can always convert it into a non-relative import
|
|
84
|
+
// from the app's namespace
|
|
85
|
+
//
|
|
86
|
+
// IMPORTANT: whenever an addon resolves a relative path to the
|
|
87
|
+
// app, it does so because our code in the core resolver has
|
|
88
|
+
// rewritten the request to be relative to the app's root. So here
|
|
89
|
+
// we will only ever encounter relative paths that are already
|
|
90
|
+
// relative to the app's root directory.
|
|
91
|
+
externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
type: 'ignored',
|
|
95
|
+
result: {
|
|
96
|
+
path: externalizedName,
|
|
97
|
+
external: true,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { type: 'found', filename: result.path, result, isVirtual: request.isVirtual };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/*
|
|
107
|
+
This is an unfortunate necessity. During depscan, vite deliberately hides
|
|
108
|
+
information from esbuild. Specifically, it treats "not found" and "this is an
|
|
109
|
+
external dependency" as both "external: true". But we really care about the
|
|
110
|
+
difference, since we have fallback behaviors for the "not found" case. Using
|
|
111
|
+
this global state, our rollup resolver plugin can observe what vite is
|
|
112
|
+
actually doing and communicate that knowledge outward to our esbuild resolver
|
|
113
|
+
plugin.
|
|
114
|
+
*/
|
|
115
|
+
function sharedGlobalState() {
|
|
116
|
+
let channel = globalThis.__embroider_vite_resolver_channel__;
|
|
117
|
+
if (!channel) {
|
|
118
|
+
channel = new Map();
|
|
119
|
+
globalThis.__embroider_vite_resolver_channel__ = channel;
|
|
120
|
+
}
|
|
121
|
+
return channel;
|
|
122
|
+
}
|
|
123
|
+
function requestStatus(id) {
|
|
124
|
+
sharedGlobalState().set(id, 'pending');
|
|
125
|
+
}
|
|
126
|
+
export function writeStatus(id, status) {
|
|
127
|
+
let channel = sharedGlobalState();
|
|
128
|
+
if (channel.get(id) === 'pending') {
|
|
129
|
+
channel.set(id, status);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function readStatus(id) {
|
|
133
|
+
var _a;
|
|
134
|
+
let channel = sharedGlobalState();
|
|
135
|
+
let result = (_a = channel.get(id)) !== null && _a !== void 0 ? _a : 'pending';
|
|
136
|
+
channel.delete(id);
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
//# 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,qBAAqB;IAChC,MAAM,CAAC,MAAM,CAAC,EACZ,YAAY,EACZ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,GASX;;QACC,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,IAAI,IAAI,QA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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"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
import core, { ModuleRequest } from '@embroider/core';
|
|
3
|
+
const { ResolverLoader, virtualContent, needsSyntheticComponentJS, isInComponents } = core;
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
const { readFileSync } = fs;
|
|
6
|
+
import { EsBuildRequestAdapter } from './esbuild-request.js';
|
|
7
|
+
import { assertNever } from 'assert-never';
|
|
8
|
+
import { hbsToJS } from '@embroider/core';
|
|
9
|
+
import { Preprocessor } from 'content-tag';
|
|
10
|
+
import { extname } from 'path';
|
|
11
|
+
const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` + `export default templateOnly();\n`;
|
|
12
|
+
export function esBuildResolver() {
|
|
13
|
+
let resolverLoader = new ResolverLoader(process.cwd());
|
|
14
|
+
let preprocessor = new Preprocessor();
|
|
15
|
+
async function transformAndAssert(src, filename) {
|
|
16
|
+
const result = await transformAsync(src, { filename });
|
|
17
|
+
if (!result || result.code == null) {
|
|
18
|
+
throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);
|
|
19
|
+
}
|
|
20
|
+
return result.code;
|
|
21
|
+
}
|
|
22
|
+
async function onLoad({ path, namespace }) {
|
|
23
|
+
let src;
|
|
24
|
+
if (namespace === 'embroider-template-only-component') {
|
|
25
|
+
src = templateOnlyComponent;
|
|
26
|
+
}
|
|
27
|
+
else if (namespace === 'embroider-virtual') {
|
|
28
|
+
src = virtualContent(path, resolverLoader.resolver).src;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
src = readFileSync(path, 'utf8');
|
|
32
|
+
}
|
|
33
|
+
if (path.endsWith('.hbs')) {
|
|
34
|
+
src = hbsToJS(src);
|
|
35
|
+
}
|
|
36
|
+
else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {
|
|
37
|
+
src = preprocessor.process(src, { filename: path });
|
|
38
|
+
}
|
|
39
|
+
if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {
|
|
40
|
+
src = await transformAndAssert(src, path);
|
|
41
|
+
}
|
|
42
|
+
return { contents: src };
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name: 'embroider-esbuild-resolver',
|
|
46
|
+
setup(build) {
|
|
47
|
+
const phase = detectPhase(build);
|
|
48
|
+
// Embroider Resolver
|
|
49
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {
|
|
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
|
+
});
|
|
59
|
+
if (!request) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
let resolution = await resolverLoader.resolver.resolve(request);
|
|
63
|
+
switch (resolution.type) {
|
|
64
|
+
case 'found':
|
|
65
|
+
case 'ignored':
|
|
66
|
+
return resolution.result;
|
|
67
|
+
case 'not_found':
|
|
68
|
+
return resolution.err;
|
|
69
|
+
default:
|
|
70
|
+
throw assertNever(resolution);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// template-only-component synthesis
|
|
74
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
|
|
75
|
+
if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderHBSResolving) {
|
|
76
|
+
// reentrance
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let result = await build.resolve(path, {
|
|
80
|
+
namespace,
|
|
81
|
+
resolveDir,
|
|
82
|
+
importer,
|
|
83
|
+
kind,
|
|
84
|
+
// avoid reentrance
|
|
85
|
+
pluginData: { ...pluginData, embroiderHBSResolving: true },
|
|
86
|
+
});
|
|
87
|
+
if (result.errors.length === 0 && !result.external) {
|
|
88
|
+
let syntheticPath = needsSyntheticComponentJS(path, result.path);
|
|
89
|
+
if (syntheticPath && isInComponents(result.path, resolverLoader.resolver.packageCache)) {
|
|
90
|
+
return { path: syntheticPath, namespace: 'embroider-template-only-component' };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
if (phase === 'bundling') {
|
|
96
|
+
// during bundling phase, we need to provide our own extension
|
|
97
|
+
// searching. We do it here in its own resolve plugin so that it's
|
|
98
|
+
// sitting beneath both embroider resolver and template-only-component
|
|
99
|
+
// synthesizer, since both expect the ambient system to have extension
|
|
100
|
+
// search.
|
|
101
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
|
|
102
|
+
if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderExtensionResolving) {
|
|
103
|
+
// reentrance
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
let firstResult;
|
|
107
|
+
for (let requestName of extensionSearch(path, resolverLoader.resolver.options.resolvableExtensions)) {
|
|
108
|
+
let result = await build.resolve(requestName, {
|
|
109
|
+
namespace,
|
|
110
|
+
resolveDir,
|
|
111
|
+
importer,
|
|
112
|
+
kind,
|
|
113
|
+
// avoid reentrance
|
|
114
|
+
pluginData: { ...pluginData, embroiderExtensionResolving: true },
|
|
115
|
+
});
|
|
116
|
+
if (result.errors.length > 0) {
|
|
117
|
+
// if extension search fails, we want to let the first failure be the
|
|
118
|
+
// one that propagates, so that the error message makes sense.
|
|
119
|
+
firstResult = result;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return firstResult;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// we need to handle everything from one of our three special namespaces:
|
|
129
|
+
build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);
|
|
130
|
+
build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);
|
|
131
|
+
build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);
|
|
132
|
+
// we need to handle all hbs
|
|
133
|
+
build.onLoad({ filter: /\.hbs$/ }, onLoad);
|
|
134
|
+
// we need to handle all GJS (to preprocess) and JS (to run macros)
|
|
135
|
+
build.onLoad({ filter: /\.g?[jt]s$/ }, onLoad);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function detectPhase(build) {
|
|
140
|
+
var _a;
|
|
141
|
+
let plugins = ((_a = build.initialOptions.plugins) !== null && _a !== void 0 ? _a : []).map(p => p.name);
|
|
142
|
+
if (plugins.includes('vite:dep-pre-bundle')) {
|
|
143
|
+
return 'bundling';
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return 'other';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function* extensionSearch(specifier, extensions) {
|
|
150
|
+
yield specifier;
|
|
151
|
+
// when there's no explicit extension, we may do extension search
|
|
152
|
+
if (extname(specifier) === '') {
|
|
153
|
+
for (let ext of extensions) {
|
|
154
|
+
yield specifier + ext;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=esbuild-resolver.js.map
|