@embroider/vite 0.2.0 → 0.2.1-unstable.024270b
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 +16 -9
- package/src/assets.d.ts +2 -0
- package/src/assets.js +114 -0
- package/src/assets.js.map +1 -0
- package/src/build.d.ts +3 -0
- package/src/build.js +62 -0
- package/src/build.js.map +1 -0
- package/src/content-for.d.ts +2 -0
- package/src/content-for.js +20 -0
- package/src/content-for.js.map +1 -0
- package/src/esbuild-request.d.ts +24 -0
- package/src/esbuild-request.js +131 -0
- package/src/esbuild-request.js.map +1 -0
- package/src/esbuild-resolver.d.ts +2 -0
- package/src/esbuild-resolver.js +100 -0
- package/src/esbuild-resolver.js.map +1 -0
- package/src/hbs.js +56 -85
- package/src/hbs.js.map +1 -1
- package/src/optimize-deps.js +6 -2
- package/src/optimize-deps.js.map +1 -1
- package/src/request.d.ts +14 -2
- package/src/request.js +66 -7
- package/src/request.js.map +1 -1
- package/src/resolver.js +68 -32
- package/src/resolver.js.map +1 -1
- package/src/scripts.js +7 -3
- package/src/scripts.js.map +1 -1
- package/src/template-tag.d.ts +3 -1
- package/src/template-tag.js +8 -33
- package/src/template-tag.js.map +1 -1
- package/src/addons.d.ts +0 -1
- package/src/addons.js +0 -24
- 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,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/vite",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-unstable.024270b",
|
|
4
4
|
"main": "index.mjs",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"vite": "^
|
|
7
|
-
"@embroider/core": "^3.4.
|
|
6
|
+
"vite": "^5.2.0",
|
|
7
|
+
"@embroider/core": "^3.4.15-unstable.024270b"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@babel/core": "^7.22.9",
|
|
10
11
|
"@rollup/pluginutils": "^4.1.1",
|
|
11
12
|
"assert-never": "^1.2.1",
|
|
12
|
-
"content-tag": "^
|
|
13
|
+
"content-tag": "^2.0.1",
|
|
13
14
|
"debug": "^4.3.2",
|
|
15
|
+
"esbuild": "^0.17.19",
|
|
16
|
+
"fast-glob": "^3.3.2",
|
|
14
17
|
"fs-extra": "^10.0.0",
|
|
15
18
|
"jsdom": "^16.6.0",
|
|
19
|
+
"send": "^0.18.0",
|
|
16
20
|
"source-map-url": "^0.4.1",
|
|
17
|
-
"terser": "^5.7.0"
|
|
21
|
+
"terser": "^5.7.0",
|
|
22
|
+
"@embroider/macros": "1.16.6-unstable.024270b"
|
|
18
23
|
},
|
|
19
24
|
"devDependencies": {
|
|
25
|
+
"@types/babel__core": "^7.20.1",
|
|
20
26
|
"@types/debug": "^4.1.5",
|
|
21
|
-
"@types/jsdom": "^16.2.11",
|
|
22
27
|
"@types/fs-extra": "^9.0.12",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
28
|
+
"@types/jsdom": "^16.2.11",
|
|
29
|
+
"@types/send": "^0.17.4",
|
|
30
|
+
"rollup": "^4.18.0",
|
|
31
|
+
"vite": "^5.3.3",
|
|
32
|
+
"@embroider/core": "^3.4.15-unstable.024270b"
|
|
26
33
|
},
|
|
27
34
|
"files": [
|
|
28
35
|
"index.mjs",
|
package/src/assets.d.ts
ADDED
package/src/assets.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.assets = assets;
|
|
30
|
+
const core_1 = require("@embroider/core");
|
|
31
|
+
const process = __importStar(require("process"));
|
|
32
|
+
const path_1 = require("path");
|
|
33
|
+
const fs_extra_1 = require("fs-extra");
|
|
34
|
+
const send_1 = __importDefault(require("send"));
|
|
35
|
+
function findPublicAsset(relativePath, resolver) {
|
|
36
|
+
var _a;
|
|
37
|
+
const packageCache = resolver.packageCache;
|
|
38
|
+
let pkg = packageCache.ownerOfFile(relativePath);
|
|
39
|
+
for (const engine of resolver.options.engines) {
|
|
40
|
+
for (const addon of engine.activeAddons) {
|
|
41
|
+
pkg = packageCache.ownerOfFile(addon.root);
|
|
42
|
+
if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {
|
|
43
|
+
const asset = (_a = Object.entries(pkg.meta['public-assets']).find(([_key, a]) => path_1.posix.resolve('/', a) === relativePath)) === null || _a === void 0 ? void 0 : _a[0];
|
|
44
|
+
let local = asset ? (0, path_1.join)(addon.root, asset) : null;
|
|
45
|
+
if (local && (0, fs_extra_1.existsSync)(local)) {
|
|
46
|
+
return local;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function assets() {
|
|
53
|
+
const cwd = process.cwd();
|
|
54
|
+
const resolverLoader = new core_1.ResolverLoader(cwd);
|
|
55
|
+
let mode = 'build';
|
|
56
|
+
let publicDir = 'public';
|
|
57
|
+
return {
|
|
58
|
+
name: 'assets',
|
|
59
|
+
enforce: 'post',
|
|
60
|
+
configResolved(options) {
|
|
61
|
+
mode = options.command;
|
|
62
|
+
publicDir = options.publicDir;
|
|
63
|
+
},
|
|
64
|
+
configureServer(server) {
|
|
65
|
+
return () => {
|
|
66
|
+
server.middlewares.use((req, res, next) => {
|
|
67
|
+
if (req.originalUrl && req.originalUrl.length > 1) {
|
|
68
|
+
const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);
|
|
69
|
+
if (assetUrl) {
|
|
70
|
+
return (0, send_1.default)(req, assetUrl).pipe(res);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return next();
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
buildStart: {
|
|
78
|
+
// we need to wait for the compatBuild plugin's buildStart hook to finish
|
|
79
|
+
// so that the resolver config exists before we try to read it.
|
|
80
|
+
sequential: true,
|
|
81
|
+
order: 'post',
|
|
82
|
+
async handler() {
|
|
83
|
+
if (mode !== 'build')
|
|
84
|
+
return;
|
|
85
|
+
const engines = resolverLoader.resolver.options.engines;
|
|
86
|
+
for (const engine of engines) {
|
|
87
|
+
const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));
|
|
88
|
+
packages.forEach(pkg => {
|
|
89
|
+
if (!pkg || !pkg.isV2Addon())
|
|
90
|
+
return;
|
|
91
|
+
const assets = pkg.meta['public-assets'] || {};
|
|
92
|
+
Object.entries(assets).forEach(([path, dest]) => {
|
|
93
|
+
// do not override app public assets
|
|
94
|
+
if ((0, fs_extra_1.existsSync)((0, path_1.join)(publicDir, dest))) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const filePath = (0, path_1.join)(pkg.root, path);
|
|
98
|
+
if (!(0, fs_extra_1.lstatSync)(filePath).isFile()) {
|
|
99
|
+
console.log(`Invalid package definition, ${pkg.name} has defined a file "${path}" that is not a file`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.emitFile({
|
|
103
|
+
type: 'asset',
|
|
104
|
+
source: (0, fs_extra_1.readFileSync)(filePath),
|
|
105
|
+
fileName: path_1.posix.resolve('/', dest).slice(1),
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|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AAC;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 { ResolverLoader } from '@embroider/core';\nimport type { Plugin } from 'vite';\nimport * as process from 'process';\nimport { join, posix } from 'path';\nimport { existsSync, readFileSync, lstatSync } from 'fs-extra';\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,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emberBuild = emberBuild;
|
|
4
|
+
exports.compatPrebuild = compatPrebuild;
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
function emberBuild(command, mode) {
|
|
7
|
+
if (command === 'build') {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const child = (0, child_process_1.fork)('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], {
|
|
10
|
+
env: {
|
|
11
|
+
...process.env,
|
|
12
|
+
EMBROIDER_PREBUILD: 'true',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
child.on('exit', code => (code === 0 ? resolve() : reject()));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const child = (0, child_process_1.fork)('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {
|
|
20
|
+
silent: true,
|
|
21
|
+
env: {
|
|
22
|
+
...process.env,
|
|
23
|
+
EMBROIDER_PREBUILD: 'true',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));
|
|
27
|
+
child.on('spawn', () => {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', data => {
|
|
30
|
+
console.error(data.toString());
|
|
31
|
+
});
|
|
32
|
+
child.stdout.on('data', data => {
|
|
33
|
+
console.log(data.toString());
|
|
34
|
+
if (data.toString().includes('Build successful')) {
|
|
35
|
+
resolve();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function compatPrebuild() {
|
|
42
|
+
let viteCommand;
|
|
43
|
+
let viteMode;
|
|
44
|
+
return {
|
|
45
|
+
name: 'embroider-builder',
|
|
46
|
+
enforce: 'pre',
|
|
47
|
+
config(_config, { mode, command }) {
|
|
48
|
+
viteCommand = command;
|
|
49
|
+
viteMode = mode;
|
|
50
|
+
},
|
|
51
|
+
async buildStart() {
|
|
52
|
+
if (!viteCommand) {
|
|
53
|
+
throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);
|
|
54
|
+
}
|
|
55
|
+
if (!viteMode) {
|
|
56
|
+
throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);
|
|
57
|
+
}
|
|
58
|
+
await emberBuild(viteCommand, viteMode);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# 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":";;AAGA,gCAiCC;AAED,wCAqBC;AA3DD,iDAAqC;AAGrC,SAAgB,UAAU,CAAC,OAAe,EAAE,IAAY;IACtD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,KAAK,GAAG,IAAA,oBAAI,EAAC,oCAAoC,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE;gBACzF,G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C,kBAAkB,CAAC,EAAE,CAAC;oBACjD,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,cAAc;IAC5B,IAAI,WAA+B,CAAC;IACpC,IAAI,QAA4B,CAAC;IAEjC,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;YAC/B,WAAW,GAAG,OAAO,CAAC;YACtB,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,KAAK,CAAC,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,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { fork } from 'child_process';\nimport type { Plugin } from 'vite';\n\nexport function emberBuild(command: string, mode: string): Promise<void> {\n if (command === 'build') {\n return new Promise((resolve, reject) => {\n const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], {\n env: {\n ...process.env,\n EMBROIDER_PREBUILD: 'true',\n },\n });\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 ...process.env,\n EMBROIDER_PREBUILD: 'true',\n },\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\n return {\n name: 'embroider-builder',\n enforce: 'pre',\n config(_config, { mode, command }) {\n viteCommand = command;\n viteMode = mode;\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);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentFor = contentFor;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const core_1 = require("@embroider/core");
|
|
7
|
+
function contentFor() {
|
|
8
|
+
return {
|
|
9
|
+
name: 'embroider-content-for',
|
|
10
|
+
transformIndexHtml(html, { path }) {
|
|
11
|
+
let config = (0, fs_extra_1.readJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(process.cwd()), 'content-for.json'));
|
|
12
|
+
let contentsForConfig = config[path];
|
|
13
|
+
for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {
|
|
14
|
+
html = html.replace(`{{content-for "${contentType}"}}`, `${htmlContent}`);
|
|
15
|
+
}
|
|
16
|
+
return html;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=content-for.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-for.js","sourceRoot":"","sources":["content-for.ts"],"names":[],"mappings":";;AAKA,gCAaC;AAjBD,uCAAwC;AACxC,+BAA4B;AAC5B,0CAA4D;AAE5D,SAAgB,UAAU;IACxB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAE7B,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE;YAC/B,IAAI,MAAM,GAAQ,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAAA,gCAAyB,EAAC,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 { readJSONSync } from 'fs-extra';\nimport { join } from 'path';\nimport { locateEmbroiderWorkingDir } from '@embroider/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,24 @@
|
|
|
1
|
+
import { type ModuleRequest } from '@embroider/core';
|
|
2
|
+
import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
|
|
3
|
+
import type { Resolution } from '@embroider/core';
|
|
4
|
+
export declare class EsBuildModuleRequest implements ModuleRequest {
|
|
5
|
+
private context;
|
|
6
|
+
private kind;
|
|
7
|
+
readonly specifier: string;
|
|
8
|
+
readonly fromFile: string;
|
|
9
|
+
readonly meta: Record<string, any> | undefined;
|
|
10
|
+
readonly isVirtual: boolean;
|
|
11
|
+
readonly isNotFound: boolean;
|
|
12
|
+
readonly resolvedTo: Resolution<OnResolveResult, OnResolveResult> | undefined;
|
|
13
|
+
static from(context: PluginBuild, kind: ImportKind, source: string, importer: string | undefined, pluginData: Record<string, any> | undefined): EsBuildModuleRequest | undefined;
|
|
14
|
+
private constructor();
|
|
15
|
+
get debugType(): string;
|
|
16
|
+
alias(newSpecifier: string): this;
|
|
17
|
+
rehome(newFromFile: string): this;
|
|
18
|
+
virtualize(filename: string): this;
|
|
19
|
+
withMeta(meta: Record<string, any> | undefined): this;
|
|
20
|
+
notFound(): this;
|
|
21
|
+
resolveTo(resolution: Resolution<OnResolveResult, OnResolveResult>): this;
|
|
22
|
+
defaultResolve(): Promise<Resolution<OnResolveResult, OnResolveResult>>;
|
|
23
|
+
}
|
|
24
|
+
export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EsBuildModuleRequest = void 0;
|
|
4
|
+
exports.writeStatus = writeStatus;
|
|
5
|
+
const core_1 = require("@embroider/core");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
class EsBuildModuleRequest {
|
|
8
|
+
static from(context, kind, source, importer, pluginData) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
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)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (source && importer && source[0] !== '\0' && !source.startsWith('virtual-module:')) {
|
|
14
|
+
let fromFile = (0, core_1.cleanUrl)(importer);
|
|
15
|
+
return new EsBuildModuleRequest(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);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
constructor(context, kind, specifier, fromFile, meta, isVirtual, isNotFound, resolvedTo) {
|
|
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.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.context, this.kind, this.specifier, newFromFile, this.meta, this.isVirtual, false, undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
virtualize(filename) {
|
|
43
|
+
return new EsBuildModuleRequest(this.context, this.kind, filename, this.fromFile, this.meta, true, false, undefined);
|
|
44
|
+
}
|
|
45
|
+
withMeta(meta) {
|
|
46
|
+
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, this.fromFile, meta, this.isVirtual, this.isNotFound, this.resolvedTo);
|
|
47
|
+
}
|
|
48
|
+
notFound() {
|
|
49
|
+
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, true, undefined);
|
|
50
|
+
}
|
|
51
|
+
resolveTo(resolution) {
|
|
52
|
+
return new EsBuildModuleRequest(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: (0, path_1.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
|
+
return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.EsBuildModuleRequest = EsBuildModuleRequest;
|
|
98
|
+
/*
|
|
99
|
+
This is an unfortunate necessity. During depscan, vite deliberately hides
|
|
100
|
+
information from esbuild. Specifically, it treats "not found" and "this is an
|
|
101
|
+
external dependency" as both "external: true". But we really care about the
|
|
102
|
+
difference, since we have fallback behaviors for the "not found" case. Using
|
|
103
|
+
this global state, our rollup resolver plugin can observe what vite is
|
|
104
|
+
actually doing and communicate that knowledge outward to our esbuild resolver
|
|
105
|
+
plugin.
|
|
106
|
+
*/
|
|
107
|
+
function sharedGlobalState() {
|
|
108
|
+
let channel = globalThis.__embroider_vite_resolver_channel__;
|
|
109
|
+
if (!channel) {
|
|
110
|
+
channel = new Map();
|
|
111
|
+
globalThis.__embroider_vite_resolver_channel__ = channel;
|
|
112
|
+
}
|
|
113
|
+
return channel;
|
|
114
|
+
}
|
|
115
|
+
function requestStatus(id) {
|
|
116
|
+
sharedGlobalState().set(id, 'pending');
|
|
117
|
+
}
|
|
118
|
+
function writeStatus(id, status) {
|
|
119
|
+
let channel = sharedGlobalState();
|
|
120
|
+
if (channel.get(id) === 'pending') {
|
|
121
|
+
channel.set(id, status);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function readStatus(id) {
|
|
125
|
+
var _a;
|
|
126
|
+
let channel = sharedGlobalState();
|
|
127
|
+
let result = (_a = channel.get(id)) !== null && _a !== void 0 ? _a : 'pending';
|
|
128
|
+
channel.delete(id);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=esbuild-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-request.js","sourceRoot":"","sources":["esbuild-request.ts"],"names":[],"mappings":";;;AAoMA,kCAKC;AAzMD,0CAA+D;AAE/D,+BAA+B;AAI/B,MAAa,oBAAoB;IAC/B,MAAM,CAAC,IAAI,CACT,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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,oDAoKC;AAED;;;;;;;;GAQG;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,SAAgB,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 { type ModuleRequest, cleanUrl } from '@embroider/core';\nimport type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';\nimport { dirname } from 'path';\n\nimport type { Resolution } from '@embroider/core';\n\nexport class EsBuildModuleRequest implements ModuleRequest {\n static from(\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 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 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.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.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.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.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.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.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 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"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.esBuildResolver = esBuildResolver;
|
|
7
|
+
const core_1 = require("@babel/core");
|
|
8
|
+
const core_2 = require("@embroider/core");
|
|
9
|
+
const fs_extra_1 = require("fs-extra");
|
|
10
|
+
const esbuild_request_1 = require("./esbuild-request");
|
|
11
|
+
const assert_never_1 = __importDefault(require("assert-never"));
|
|
12
|
+
const core_3 = require("@embroider/core");
|
|
13
|
+
const content_tag_1 = require("content-tag");
|
|
14
|
+
const templateOnlyComponent = `import templateOnly from '@ember/component/template-only';\n` + `export default templateOnly();\n`;
|
|
15
|
+
function esBuildResolver() {
|
|
16
|
+
let resolverLoader = new core_2.ResolverLoader(process.cwd());
|
|
17
|
+
let preprocessor = new content_tag_1.Preprocessor();
|
|
18
|
+
function transformAndAssert(src, filename) {
|
|
19
|
+
const result = (0, core_1.transform)(src, { filename });
|
|
20
|
+
if (!result || result.code == null) {
|
|
21
|
+
throw new Error(`Failed to load file ${filename} in esbuild-hbs-loader`);
|
|
22
|
+
}
|
|
23
|
+
return result.code;
|
|
24
|
+
}
|
|
25
|
+
function onLoad({ path, namespace }) {
|
|
26
|
+
let src;
|
|
27
|
+
if (namespace === 'embroider-template-only-component') {
|
|
28
|
+
src = templateOnlyComponent;
|
|
29
|
+
}
|
|
30
|
+
else if (namespace === 'embroider-virtual') {
|
|
31
|
+
src = (0, core_2.virtualContent)(path, resolverLoader.resolver).src;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
src = (0, fs_extra_1.readFileSync)(path, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
if (path.endsWith('.hbs')) {
|
|
37
|
+
src = (0, core_3.hbsToJS)(src);
|
|
38
|
+
}
|
|
39
|
+
else if (['.gjs', '.gts'].some(ext => path.endsWith(ext))) {
|
|
40
|
+
src = preprocessor.process(src, { filename: path });
|
|
41
|
+
}
|
|
42
|
+
if (['.hbs', '.gjs', '.gts', '.js', '.ts'].some(ext => path.endsWith(ext))) {
|
|
43
|
+
src = transformAndAssert(src, path);
|
|
44
|
+
}
|
|
45
|
+
return { contents: src };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
name: 'embroider-esbuild-resolver',
|
|
49
|
+
setup(build) {
|
|
50
|
+
// Embroider Resolver
|
|
51
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {
|
|
52
|
+
let request = esbuild_request_1.EsBuildModuleRequest.from(build, kind, path, importer, pluginData);
|
|
53
|
+
if (!request) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let resolution = await resolverLoader.resolver.resolve(request);
|
|
57
|
+
switch (resolution.type) {
|
|
58
|
+
case 'found':
|
|
59
|
+
case 'ignored':
|
|
60
|
+
return resolution.result;
|
|
61
|
+
case 'not_found':
|
|
62
|
+
return resolution.err;
|
|
63
|
+
default:
|
|
64
|
+
throw (0, assert_never_1.default)(resolution);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// template-only-component synthesis
|
|
68
|
+
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
|
|
69
|
+
if (pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroiderExtensionResolving) {
|
|
70
|
+
// reentrance
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
let result = await build.resolve(path, {
|
|
74
|
+
namespace,
|
|
75
|
+
resolveDir,
|
|
76
|
+
importer,
|
|
77
|
+
kind,
|
|
78
|
+
// avoid reentrance
|
|
79
|
+
pluginData: { ...pluginData, embroiderExtensionResolving: true },
|
|
80
|
+
});
|
|
81
|
+
if (result.errors.length === 0 && !result.external) {
|
|
82
|
+
let syntheticPath = (0, core_2.needsSyntheticComponentJS)(path, result.path, resolverLoader.resolver.packageCache);
|
|
83
|
+
if (syntheticPath) {
|
|
84
|
+
return { path: syntheticPath, namespace: 'embroider-template-only-component' };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
});
|
|
89
|
+
// we need to handle everything from one of our three special namespaces:
|
|
90
|
+
build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);
|
|
91
|
+
build.onLoad({ namespace: 'embroider-virtual', filter: /./ }, onLoad);
|
|
92
|
+
build.onLoad({ namespace: 'embroider-template-tag', filter: /./ }, onLoad);
|
|
93
|
+
// we need to handle all hbs
|
|
94
|
+
build.onLoad({ filter: /\.hbs$/ }, onLoad);
|
|
95
|
+
// we need to handle all GJS (to preprocess) and JS (to run macros)
|
|
96
|
+
build.onLoad({ filter: /\.g?[jt]s$/ }, onLoad);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=esbuild-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-resolver.js","sourceRoot":"","sources":["esbuild-resolver.ts"],"names":[],"mappings":";;;;;AAYA,0CA2FC;AAtGD,sCAAwC;AACxC,0CAA4F;AAC5F,uCAAwC;AACxC,uDAAyD;AACzD,gEAAuC;AACvC,0CAA0C;AAC1C,6CAA2C;AAE3C,MAAM,qBAAqB,GACzB,8DAA8D,GAAG,kCAAkC,CAAC;AAEtG,SAAgB,eAAe;IAC7B,IAAI,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACvD,IAAI,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAC;IAEtC,SAAS,kBAAkB,CAAC,GAAW,EAAE,QAAgB;QACvD,MAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,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,CAAC;QAC3E,CAAC;QACD,OAAO,MAAM,CAAC,IAAK,CAAC;IACtB,CAAC;IAED,SAAS,M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C,QAAQ,EAAE,CAAC;oBACnD,IAAI,aAAa,GAAG,IAAA,gCAAyB,EAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;oBACvG,IAAI,aAAa,EAAE,CAAC;wBAClB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,mCAAmC,EAAE,CAAC;oBACjF,CAAC;gBACH,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC,CAAC;YAEH,yEAAyE;YACzE,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,mCAAmC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;YACtF,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;YACtE,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,EAAE,GAAG,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","sourcesContent":["import type { Plugin as EsBuildPlugin, OnLoadResult } from 'esbuild';\nimport { transform } from '@babel/core';\nimport { ResolverLoader, virtualContent, needsSyntheticComponentJS } from '@embroider/core';\nimport { readFileSync } from 'fs-extra';\nimport { EsBuildModuleRequest } from './esbuild-request';\nimport assertNever from 'assert-never';\nimport { hbsToJS } from '@embroider/core';\nimport { Preprocessor } from 'content-tag';\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 // Embroider Resolver\n build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {\n let request = EsBuildModuleRequest.from(build, kind, path, importer, pluginData);\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?.embroiderExtensionResolving) {\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, embroiderExtensionResolving: true },\n });\n\n if (result.errors.length === 0 && !result.external) {\n let syntheticPath = needsSyntheticComponentJS(path, result.path, resolverLoader.resolver.packageCache);\n if (syntheticPath) {\n return { path: syntheticPath, namespace: 'embroider-template-only-component' };\n }\n }\n\n return result;\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"]}
|