@embroider/vite 0.2.1-unstable.fad2387 → 0.2.2-unstable.3e8dbe3
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/LICENSE +21 -0
- package/index.d.ts +1 -0
- package/package.json +27 -20
- package/src/assets.js +18 -46
- package/src/assets.js.map +1 -1
- package/src/build.d.ts +1 -1
- package/src/build.js +18 -21
- package/src/build.js.map +1 -1
- package/src/content-for.js +7 -9
- package/src/content-for.js.map +1 -1
- package/src/esbuild-request.d.ts +10 -3
- package/src/esbuild-request.js +88 -21
- package/src/esbuild-request.js.map +1 -1
- package/src/esbuild-resolver.d.ts +1 -1
- package/src/esbuild-resolver.js +124 -95
- package/src/esbuild-resolver.js.map +1 -1
- package/src/hbs.js +60 -106
- package/src/hbs.js.map +1 -1
- package/src/optimize-deps.js +3 -7
- package/src/optimize-deps.js.map +1 -1
- package/src/request.js +12 -18
- package/src/request.js.map +1 -1
- package/src/resolver.js +118 -22
- package/src/resolver.js.map +1 -1
- package/src/scripts.js +14 -40
- package/src/scripts.js.map +1 -1
- package/src/template-tag.js +5 -40
- package/src/template-tag.js.map +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Edward Faulkner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/vite",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.2.2-unstable.3e8dbe3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"default": "./index.mjs",
|
|
8
|
+
"types": "./index.d.ts"
|
|
9
|
+
}
|
|
8
10
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"vite": "^5.2.0",
|
|
13
|
+
"@embroider/core": "^3.4.20-unstable.3e8dbe3"
|
|
11
14
|
},
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"@babel/core": "^7.22.9",
|
|
14
|
-
"@
|
|
15
|
-
"@rollup/pluginutils": "^4.1.1",
|
|
17
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
16
18
|
"assert-never": "^1.2.1",
|
|
17
|
-
"content-tag": "^2.0.
|
|
19
|
+
"content-tag": "^2.0.2",
|
|
18
20
|
"debug": "^4.3.2",
|
|
19
21
|
"esbuild": "^0.17.19",
|
|
22
|
+
"fast-glob": "^3.3.2",
|
|
20
23
|
"fs-extra": "^10.0.0",
|
|
21
|
-
"jsdom": "^
|
|
24
|
+
"jsdom": "^25.0.0",
|
|
25
|
+
"send": "^0.18.0",
|
|
22
26
|
"source-map-url": "^0.4.1",
|
|
23
27
|
"terser": "^5.7.0",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
28
|
+
"@embroider/macros": "1.16.10-unstable.3e8dbe3",
|
|
29
|
+
"@embroider/reverse-exports": "0.1.1-unstable.3e8dbe3"
|
|
26
30
|
},
|
|
27
31
|
"devDependencies": {
|
|
28
|
-
"@embroider/core": "3.4.8-unstable.fad2387",
|
|
29
32
|
"@types/babel__core": "^7.20.1",
|
|
30
|
-
"@types/send": "^0.17.4",
|
|
31
33
|
"@types/debug": "^4.1.5",
|
|
32
|
-
"@types/jsdom": "^16.2.11",
|
|
33
34
|
"@types/fs-extra": "^9.0.12",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
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.3e8dbe3"
|
|
36
40
|
},
|
|
37
41
|
"files": [
|
|
38
42
|
"index.mjs",
|
|
@@ -40,5 +44,8 @@
|
|
|
40
44
|
"src/**/*.js",
|
|
41
45
|
"src/**/*.d.ts",
|
|
42
46
|
"src/**/*.js.map"
|
|
43
|
-
]
|
|
44
|
-
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "jest"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/assets.js
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 = void 0;
|
|
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"));
|
|
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';
|
|
35
8
|
function findPublicAsset(relativePath, resolver) {
|
|
36
9
|
var _a;
|
|
37
10
|
const packageCache = resolver.packageCache;
|
|
@@ -40,18 +13,18 @@ function findPublicAsset(relativePath, resolver) {
|
|
|
40
13
|
for (const addon of engine.activeAddons) {
|
|
41
14
|
pkg = packageCache.ownerOfFile(addon.root);
|
|
42
15
|
if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {
|
|
43
|
-
const asset = (_a = Object.entries(pkg.meta['public-assets']).find(([_key, a]) =>
|
|
44
|
-
let local = asset ?
|
|
45
|
-
if (local &&
|
|
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)) {
|
|
46
19
|
return local;
|
|
47
20
|
}
|
|
48
21
|
}
|
|
49
22
|
}
|
|
50
23
|
}
|
|
51
24
|
}
|
|
52
|
-
function assets() {
|
|
25
|
+
export function assets() {
|
|
53
26
|
const cwd = process.cwd();
|
|
54
|
-
const resolverLoader = new
|
|
27
|
+
const resolverLoader = new ResolverLoader(cwd);
|
|
55
28
|
let mode = 'build';
|
|
56
29
|
let publicDir = 'public';
|
|
57
30
|
return {
|
|
@@ -67,7 +40,7 @@ function assets() {
|
|
|
67
40
|
if (req.originalUrl && req.originalUrl.length > 1) {
|
|
68
41
|
const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);
|
|
69
42
|
if (assetUrl) {
|
|
70
|
-
return (
|
|
43
|
+
return send(req, assetUrl).pipe(res);
|
|
71
44
|
}
|
|
72
45
|
}
|
|
73
46
|
return next();
|
|
@@ -91,18 +64,18 @@ function assets() {
|
|
|
91
64
|
const assets = pkg.meta['public-assets'] || {};
|
|
92
65
|
Object.entries(assets).forEach(([path, dest]) => {
|
|
93
66
|
// do not override app public assets
|
|
94
|
-
if (
|
|
67
|
+
if (existsSync(join(publicDir, dest))) {
|
|
95
68
|
return;
|
|
96
69
|
}
|
|
97
|
-
const filePath =
|
|
98
|
-
if (!
|
|
70
|
+
const filePath = join(pkg.root, path);
|
|
71
|
+
if (!lstatSync(filePath).isFile()) {
|
|
99
72
|
console.log(`Invalid package definition, ${pkg.name} has defined a file "${path}" that is not a file`);
|
|
100
73
|
return;
|
|
101
74
|
}
|
|
102
75
|
this.emitFile({
|
|
103
76
|
type: 'asset',
|
|
104
|
-
source:
|
|
105
|
-
fileName:
|
|
77
|
+
source: readFileSync(filePath),
|
|
78
|
+
fileName: posix.resolve('/', dest).slice(1),
|
|
106
79
|
});
|
|
107
80
|
});
|
|
108
81
|
});
|
|
@@ -111,5 +84,4 @@ function assets() {
|
|
|
111
84
|
},
|
|
112
85
|
};
|
|
113
86
|
}
|
|
114
|
-
exports.assets = assets;
|
|
115
87
|
//# sourceMappingURL=assets.js.map
|
package/src/assets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","sourceRoot":"","sources":["assets.ts"],"names":[],"mappings":"
|
|
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,IAAI,GAAG,CAAC,IAAI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,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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
export declare function emberBuild(command: string, mode: string): Promise<void>;
|
|
2
|
+
export declare function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void>;
|
|
3
3
|
export declare function compatPrebuild(): Plugin;
|
package/src/build.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
}
|
|
6
10
|
if (command === 'build') {
|
|
7
11
|
return new Promise((resolve, reject) => {
|
|
8
|
-
const child =
|
|
9
|
-
env: {
|
|
10
|
-
...process.env,
|
|
11
|
-
EMBROIDER_PREBUILD: 'true',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
12
|
+
const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode], { env });
|
|
14
13
|
child.on('exit', code => (code === 0 ? resolve() : reject()));
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
16
|
return new Promise((resolve, reject) => {
|
|
18
|
-
const child =
|
|
17
|
+
const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode], {
|
|
19
18
|
silent: true,
|
|
20
|
-
env
|
|
21
|
-
...process.env,
|
|
22
|
-
EMBROIDER_PREBUILD: 'true',
|
|
23
|
-
},
|
|
19
|
+
env,
|
|
24
20
|
});
|
|
25
21
|
child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));
|
|
26
22
|
child.on('spawn', () => {
|
|
@@ -37,16 +33,18 @@ function emberBuild(command, mode) {
|
|
|
37
33
|
});
|
|
38
34
|
});
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
function compatPrebuild() {
|
|
36
|
+
export function compatPrebuild() {
|
|
42
37
|
let viteCommand;
|
|
43
38
|
let viteMode;
|
|
39
|
+
let resolvableExtensions;
|
|
44
40
|
return {
|
|
45
41
|
name: 'embroider-builder',
|
|
46
42
|
enforce: 'pre',
|
|
47
|
-
config(
|
|
43
|
+
config(config, { mode, command }) {
|
|
44
|
+
var _a;
|
|
48
45
|
viteCommand = command;
|
|
49
46
|
viteMode = mode;
|
|
47
|
+
resolvableExtensions = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.extensions;
|
|
50
48
|
},
|
|
51
49
|
async buildStart() {
|
|
52
50
|
if (!viteCommand) {
|
|
@@ -55,9 +53,8 @@ function compatPrebuild() {
|
|
|
55
53
|
if (!viteMode) {
|
|
56
54
|
throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);
|
|
57
55
|
}
|
|
58
|
-
await emberBuild(viteCommand, viteMode);
|
|
56
|
+
await emberBuild(viteCommand, viteMode, resolvableExtensions);
|
|
59
57
|
},
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
|
-
exports.compatPrebuild = compatPrebuild;
|
|
63
60
|
//# sourceMappingURL=build.js.map
|
package/src/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":"
|
|
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,E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AAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,IAAI,WAA+B,CAAC;IACpC,IAAI,QAA4B,CAAC;IACjC,IAAI,oBAA0C,CAAC;IAE/C,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;;YAC9B,WAAW,GAAG,OAAO,CAAC;YACtB,QAAQ,GAAG,IAAI,CAAC;YAChB,oBAAoB,GAAG,MAAA,MAAM,CAAC,OAAO,0CAAE,UAAU,CAAC;QACpD,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,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"]}
|
package/src/content-for.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
function contentFor() {
|
|
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() {
|
|
8
7
|
return {
|
|
9
8
|
name: 'embroider-content-for',
|
|
10
9
|
transformIndexHtml(html, { path }) {
|
|
11
|
-
let config =
|
|
10
|
+
let config = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));
|
|
12
11
|
let contentsForConfig = config[path];
|
|
13
12
|
for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {
|
|
14
13
|
html = html.replace(`{{content-for "${contentType}"}}`, `${htmlContent}`);
|
|
@@ -17,5 +16,4 @@ function contentFor() {
|
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
|
-
exports.contentFor = contentFor;
|
|
21
19
|
//# sourceMappingURL=content-for.js.map
|
package/src/content-for.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-for.js","sourceRoot":"","sources":["content-for.ts"],"names":[],"mappings":"
|
|
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"]}
|
package/src/esbuild-request.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { type ModuleRequest } from '@embroider/core';
|
|
2
1
|
import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
|
|
3
|
-
import type { Resolution } from '@embroider/core';
|
|
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>;
|
|
4
7
|
export declare class EsBuildModuleRequest implements ModuleRequest {
|
|
8
|
+
private packageCache;
|
|
9
|
+
private phase;
|
|
5
10
|
private context;
|
|
6
11
|
private kind;
|
|
7
12
|
readonly specifier: string;
|
|
@@ -10,7 +15,7 @@ export declare class EsBuildModuleRequest implements ModuleRequest {
|
|
|
10
15
|
readonly isVirtual: boolean;
|
|
11
16
|
readonly isNotFound: boolean;
|
|
12
17
|
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;
|
|
18
|
+
static from(packageCache: PackageCache, phase: 'bundling' | 'other', context: PluginBuild, kind: ImportKind, source: string, importer: string | undefined, pluginData: Record<string, any> | undefined): EsBuildModuleRequest | undefined;
|
|
14
19
|
private constructor();
|
|
15
20
|
get debugType(): string;
|
|
16
21
|
alias(newSpecifier: string): this;
|
|
@@ -21,3 +26,5 @@ export declare class EsBuildModuleRequest implements ModuleRequest {
|
|
|
21
26
|
resolveTo(resolution: Resolution<OnResolveResult, OnResolveResult>): this;
|
|
22
27
|
defaultResolve(): Promise<Resolution<OnResolveResult, OnResolveResult>>;
|
|
23
28
|
}
|
|
29
|
+
export declare function writeStatus(id: string, status: 'found' | 'not_found'): void;
|
|
30
|
+
export {};
|
package/src/esbuild-request.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
static from(context, kind, source, importer, pluginData) {
|
|
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) {
|
|
8
7
|
var _a, _b, _c;
|
|
9
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)) {
|
|
10
9
|
return;
|
|
11
10
|
}
|
|
12
|
-
if (source && importer && source[0] !== '\0') {
|
|
13
|
-
let fromFile =
|
|
14
|
-
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);
|
|
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);
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
constructor(context, kind, specifier, fromFile, meta, isVirtual, isNotFound, resolvedTo) {
|
|
16
|
+
constructor(packageCache, phase, context, kind, specifier, fromFile, meta, isVirtual, isNotFound, resolvedTo) {
|
|
17
|
+
this.packageCache = packageCache;
|
|
18
|
+
this.phase = phase;
|
|
18
19
|
this.context = context;
|
|
19
20
|
this.kind = kind;
|
|
20
21
|
this.specifier = specifier;
|
|
@@ -28,27 +29,27 @@ class EsBuildModuleRequest {
|
|
|
28
29
|
return 'esbuild';
|
|
29
30
|
}
|
|
30
31
|
alias(newSpecifier) {
|
|
31
|
-
return new EsBuildModuleRequest(this.context, this.kind, newSpecifier, this.fromFile, this.meta, this.isVirtual, false, undefined);
|
|
32
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, newSpecifier, this.fromFile, this.meta, this.isVirtual, false, undefined);
|
|
32
33
|
}
|
|
33
34
|
rehome(newFromFile) {
|
|
34
35
|
if (this.fromFile === newFromFile) {
|
|
35
36
|
return this;
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
|
-
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, newFromFile, this.meta, this.isVirtual, false, undefined);
|
|
39
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, newFromFile, this.meta, this.isVirtual, false, undefined);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
virtualize(filename) {
|
|
42
|
-
return new EsBuildModuleRequest(this.context, this.kind, filename, this.fromFile, this.meta, true, false, undefined);
|
|
43
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, filename, this.fromFile, this.meta, true, false, undefined);
|
|
43
44
|
}
|
|
44
45
|
withMeta(meta) {
|
|
45
|
-
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, this.fromFile, meta, this.isVirtual, this.isNotFound, this.resolvedTo);
|
|
46
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, meta, this.isVirtual, this.isNotFound, this.resolvedTo);
|
|
46
47
|
}
|
|
47
48
|
notFound() {
|
|
48
|
-
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, true, undefined);
|
|
49
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, true, undefined);
|
|
49
50
|
}
|
|
50
51
|
resolveTo(resolution) {
|
|
51
|
-
return new EsBuildModuleRequest(this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, this.isNotFound, resolution);
|
|
52
|
+
return new EsBuildModuleRequest(this.packageCache, this.phase, this.context, this.kind, this.specifier, this.fromFile, this.meta, this.isVirtual, this.isNotFound, resolution);
|
|
52
53
|
}
|
|
53
54
|
async defaultResolve() {
|
|
54
55
|
const request = this;
|
|
@@ -56,7 +57,7 @@ class EsBuildModuleRequest {
|
|
|
56
57
|
return {
|
|
57
58
|
type: 'found',
|
|
58
59
|
filename: request.specifier,
|
|
59
|
-
result: { path: request.specifier, namespace: 'embroider' },
|
|
60
|
+
result: { path: request.specifier, namespace: 'embroider-virtual' },
|
|
60
61
|
isVirtual: this.isVirtual,
|
|
61
62
|
};
|
|
62
63
|
}
|
|
@@ -69,9 +70,10 @@ class EsBuildModuleRequest {
|
|
|
69
70
|
},
|
|
70
71
|
};
|
|
71
72
|
}
|
|
73
|
+
requestStatus(request.specifier);
|
|
72
74
|
let result = await this.context.resolve(request.specifier, {
|
|
73
75
|
importer: request.fromFile,
|
|
74
|
-
resolveDir:
|
|
76
|
+
resolveDir: dirname(request.fromFile),
|
|
75
77
|
kind: this.kind,
|
|
76
78
|
pluginData: {
|
|
77
79
|
embroider: {
|
|
@@ -80,16 +82,81 @@ class EsBuildModuleRequest {
|
|
|
80
82
|
},
|
|
81
83
|
},
|
|
82
84
|
});
|
|
83
|
-
|
|
85
|
+
let status = readStatus(request.specifier);
|
|
86
|
+
if (result.errors.length > 0 || status === 'not_found') {
|
|
84
87
|
return { type: 'not_found', err: result };
|
|
85
88
|
}
|
|
86
89
|
else if (result.external) {
|
|
87
90
|
return { type: 'ignored', result };
|
|
88
91
|
}
|
|
89
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
|
+
}
|
|
90
125
|
return { type: 'found', filename: result.path, result, isVirtual: this.isVirtual };
|
|
91
126
|
}
|
|
92
127
|
}
|
|
93
128
|
}
|
|
94
|
-
|
|
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
|
+
}
|
|
95
162
|
//# sourceMappingURL=esbuild-request.js.map
|