@embroider/webpack 4.0.9 → 4.0.10-unstable.f779011
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/package.json +8 -8
- package/src/ember-webpack.js +25 -41
- package/src/ember-webpack.js.map +1 -1
- package/src/virtual-loader.d.ts +1 -1
- package/src/virtual-loader.js +3 -1
- package/src/virtual-loader.js.map +1 -1
- package/src/webpack-resolver-plugin.js +112 -73
- package/src/webpack-resolver-plugin.js.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@embroider/webpack",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.10-unstable.f779011",
|
4
4
|
"private": false,
|
5
5
|
"description": "Builds EmberJS apps with Webpack",
|
6
6
|
"repository": {
|
@@ -36,9 +36,9 @@
|
|
36
36
|
"supports-color": "^8.1.0",
|
37
37
|
"terser": "^5.7.0",
|
38
38
|
"thread-loader": "^3.0.4",
|
39
|
-
"@embroider/babel-loader-9": "3.1.
|
40
|
-
"@embroider/
|
41
|
-
"@embroider/
|
39
|
+
"@embroider/babel-loader-9": "3.1.2-unstable.f779011",
|
40
|
+
"@embroider/shared-internals": "2.8.2-unstable.f779011",
|
41
|
+
"@embroider/hbs-loader": "3.0.4-unstable.f779011"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
44
|
"@types/csso": "^3.5.1",
|
@@ -46,15 +46,15 @@
|
|
46
46
|
"@types/fs-extra": "^9.0.12",
|
47
47
|
"@types/lodash": "^4.14.170",
|
48
48
|
"@types/mini-css-extract-plugin": "^1.4.3",
|
49
|
-
"@types/node": "^
|
49
|
+
"@types/node": "^22.9.3",
|
50
50
|
"@types/semver": "^7.3.6",
|
51
|
-
"typescript": "^5.
|
51
|
+
"typescript": "^5.4.5",
|
52
52
|
"webpack": "^5.38.1",
|
53
|
-
"@embroider/core": "^3.
|
53
|
+
"@embroider/core": "^3.5.1-unstable.f779011"
|
54
54
|
},
|
55
55
|
"peerDependencies": {
|
56
56
|
"webpack": "^5.0.0",
|
57
|
-
"@embroider/core": "^3.
|
57
|
+
"@embroider/core": "^3.5.1-unstable.f779011"
|
58
58
|
},
|
59
59
|
"engines": {
|
60
60
|
"node": "12.* || 14.* || >= 16"
|
package/src/ember-webpack.js
CHANGED
@@ -9,29 +9,6 @@
|
|
9
9
|
multiple HTML entrypoints and apply correct HTML semantics (for example,
|
10
10
|
getting script vs module context correct).
|
11
11
|
*/
|
12
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
13
|
-
if (k2 === undefined) k2 = k;
|
14
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
15
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
16
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
17
|
-
}
|
18
|
-
Object.defineProperty(o, k2, desc);
|
19
|
-
}) : (function(o, m, k, k2) {
|
20
|
-
if (k2 === undefined) k2 = k;
|
21
|
-
o[k2] = m[k];
|
22
|
-
}));
|
23
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
24
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
25
|
-
}) : function(o, v) {
|
26
|
-
o["default"] = v;
|
27
|
-
});
|
28
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
29
|
-
if (mod && mod.__esModule) return mod;
|
30
|
-
var result = {};
|
31
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
32
|
-
__setModuleDefault(result, mod);
|
33
|
-
return result;
|
34
|
-
};
|
35
12
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
14
|
};
|
@@ -55,10 +32,15 @@ const satisfies_1 = __importDefault(require("semver/functions/satisfies"));
|
|
55
32
|
const supports_color_1 = __importDefault(require("supports-color"));
|
56
33
|
const webpack_resolver_plugin_1 = require("./webpack-resolver-plugin");
|
57
34
|
const debug = (0, debug_1.default)('embroider:debug');
|
35
|
+
// this function is never called. It exists to workaround typescript being
|
36
|
+
// obtuse. https://github.com/microsoft/TypeScript/pull/53426
|
37
|
+
async function loadTerser() {
|
38
|
+
let Terser = await import('terser');
|
39
|
+
return Terser.minify;
|
40
|
+
}
|
58
41
|
// AppInfos are equal if they result in the same webpack config.
|
59
42
|
function equalAppInfo(left, right) {
|
60
|
-
return (
|
61
|
-
left.entrypoints.length === right.entrypoints.length &&
|
43
|
+
return (left.entrypoints.length === right.entrypoints.length &&
|
62
44
|
left.entrypoints.every((e, index) => (0, isEqual_1.default)(e.modules, right.entrypoints[index].modules)));
|
63
45
|
}
|
64
46
|
function createBarrier() {
|
@@ -140,9 +122,9 @@ const Webpack = (_a = class Webpack {
|
|
140
122
|
await this.runWebpack(webpack);
|
141
123
|
}
|
142
124
|
examineApp() {
|
143
|
-
|
125
|
+
// @ts-expect-error webpack is not updated to work on @embroider/core 4.x
|
126
|
+
let meta = getAppMeta(this.pathToVanillaApp);
|
144
127
|
let rootURL = meta['ember-addon']['root-url'];
|
145
|
-
let babel = meta['ember-addon']['babel'];
|
146
128
|
let entrypoints = [];
|
147
129
|
let otherAssets = [];
|
148
130
|
let publicAssetURL = this.publicAssetURL || rootURL;
|
@@ -155,10 +137,10 @@ const Webpack = (_a = class Webpack {
|
|
155
137
|
}
|
156
138
|
}
|
157
139
|
let resolverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)((0, shared_internals_1.locateEmbroiderWorkingDir)(this.appRoot), 'resolver.json'));
|
158
|
-
return { entrypoints, otherAssets,
|
140
|
+
return { entrypoints, otherAssets, rootURL, resolverConfig, publicAssetURL, packageName: meta.name };
|
159
141
|
}
|
160
142
|
configureWebpack(appInfo, variant, variantIndex) {
|
161
|
-
const { entrypoints,
|
143
|
+
const { entrypoints, publicAssetURL, packageName, resolverConfig } = appInfo;
|
162
144
|
let entry = {};
|
163
145
|
for (let entrypoint of entrypoints) {
|
164
146
|
for (let moduleName of entrypoint.modules) {
|
@@ -166,7 +148,7 @@ const Webpack = (_a = class Webpack {
|
|
166
148
|
}
|
167
149
|
}
|
168
150
|
let { plugins: stylePlugins, loaders: styleLoaders } = this.setupStyleConfig(variant);
|
169
|
-
let babelLoaderOptions = makeBabelLoaderOptions(
|
151
|
+
let babelLoaderOptions = makeBabelLoaderOptions(variant, (0, path_1.join)(this.appRoot, 'babel.config.cjs'), this.extraBabelLoaderOptions);
|
170
152
|
let babelLoaderPrefix = `babel-loader-9?${JSON.stringify(babelLoaderOptions.options)}!`;
|
171
153
|
return {
|
172
154
|
mode: variant.optimizeForProduction ? 'production' : 'development',
|
@@ -191,7 +173,7 @@ const Webpack = (_a = class Webpack {
|
|
191
173
|
{
|
192
174
|
test: /\.hbs$/,
|
193
175
|
use: nonNullArray([
|
194
|
-
maybeThreadLoader(
|
176
|
+
maybeThreadLoader(this.extraThreadLoaderOptions),
|
195
177
|
babelLoaderOptions,
|
196
178
|
{
|
197
179
|
loader: require.resolve('@embroider/hbs-loader'),
|
@@ -208,11 +190,9 @@ const Webpack = (_a = class Webpack {
|
|
208
190
|
]),
|
209
191
|
},
|
210
192
|
{
|
211
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
212
|
-
test: require((0, path_1.join)(this.pathToVanillaApp, babel.fileFilter)),
|
213
193
|
use: nonNullArray([
|
214
|
-
maybeThreadLoader(
|
215
|
-
makeBabelLoaderOptions(
|
194
|
+
maybeThreadLoader(this.extraThreadLoaderOptions),
|
195
|
+
makeBabelLoaderOptions(variant, (0, path_1.join)(this.appRoot, 'babel.config.cjs'), this.extraBabelLoaderOptions),
|
216
196
|
]),
|
217
197
|
},
|
218
198
|
{
|
@@ -246,6 +226,10 @@ const Webpack = (_a = class Webpack {
|
|
246
226
|
'style-loader': require.resolve('style-loader'),
|
247
227
|
},
|
248
228
|
},
|
229
|
+
experiments: {
|
230
|
+
// this is needed because fasboot-only modules need to use await import()
|
231
|
+
topLevelAwait: true,
|
232
|
+
},
|
249
233
|
};
|
250
234
|
}
|
251
235
|
getWebpack(appInfo) {
|
@@ -271,7 +255,7 @@ const Webpack = (_a = class Webpack {
|
|
271
255
|
}
|
272
256
|
// loading these lazily here so they never load in non-production builds.
|
273
257
|
// The node cache will ensures we only load them once.
|
274
|
-
const [Terser, srcURL] = await Promise.all([
|
258
|
+
const [Terser, srcURL] = await Promise.all([import('terser'), import('source-map-url')]);
|
275
259
|
let inCode = (0, fs_extra_1.readFileSync)((0, path_1.join)(this.pathToVanillaApp, script), 'utf8');
|
276
260
|
let terserOpts = {};
|
277
261
|
let fileRelativeSourceMapURL;
|
@@ -291,7 +275,7 @@ const Webpack = (_a = class Webpack {
|
|
291
275
|
terserOpts.sourceMap = { content, url: fileRelativeSourceMapURL };
|
292
276
|
}
|
293
277
|
}
|
294
|
-
let { code: outCode, map: outMap } = await Terser.
|
278
|
+
let { code: outCode, map: outMap } = await Terser.minify(inCode, terserOpts);
|
295
279
|
let finalFilename = this.getFingerprintedFilename(script, outCode);
|
296
280
|
(0, fs_extra_1.outputFileSync)((0, path_1.join)(this.outputPath, finalFilename), outCode);
|
297
281
|
written.add(script);
|
@@ -307,7 +291,7 @@ const Webpack = (_a = class Webpack {
|
|
307
291
|
written.add(style);
|
308
292
|
return style;
|
309
293
|
}
|
310
|
-
const csso = await
|
294
|
+
const csso = await import('csso');
|
311
295
|
const cssContent = (0, fs_extra_1.readFileSync)((0, path_1.join)(this.pathToVanillaApp, style), 'utf8');
|
312
296
|
const minifiedCss = csso.minify(cssContent).css;
|
313
297
|
let finalFilename = this.getFingerprintedFilename(style, minifiedCss);
|
@@ -590,8 +574,8 @@ function warmUp(extraOptions) {
|
|
590
574
|
require.resolve('@embroider/babel-loader-9'),
|
591
575
|
]);
|
592
576
|
}
|
593
|
-
function maybeThreadLoader(
|
594
|
-
if (!canUseThreadLoader(extraOptions)
|
577
|
+
function maybeThreadLoader(extraOptions) {
|
578
|
+
if (!canUseThreadLoader(extraOptions)) {
|
595
579
|
return null;
|
596
580
|
}
|
597
581
|
return {
|
@@ -612,7 +596,7 @@ function isCSS(filename) {
|
|
612
596
|
function nonNullArray(array) {
|
613
597
|
return array.filter(Boolean);
|
614
598
|
}
|
615
|
-
function makeBabelLoaderOptions(
|
599
|
+
function makeBabelLoaderOptions(variant, appBabelConfigPath, extraOptions) {
|
616
600
|
const cacheDirectory = (0, core_1.getPackagerCacheDir)('webpack-babel-loader');
|
617
601
|
const options = {
|
618
602
|
variant,
|
package/src/ember-webpack.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ember-webpack.js","sourceRoot":"","sources":["ember-webpack.ts"],"names":[],"mappings":";AAAA;;;;;;;;;EASE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGF,0CAA+F;AAC/F,kEAAuG;AAEvG,sDAA8B;AAE9B,uCAA0F;AAC1F,+BAAoD;AACpD,6DAAqC;AACrC,iEAAyC;AACzC,6DAAqC;AACrC,sFAA2D;AAC3D,kDAA8B;AAC9B,+BAA8B;AAC9B,iDAA6D;AAE7D,oDAA4B;AAC5B,2EAAyD;AACzD,oEAA2C;AAG3C,uEAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,eAAS,EAAC,iBAAiB,CAAC,CAAC;AAiB3C,gEAAgE;AAChE,SAAS,YAAY,CAAC,IAAa,EAAE,KAAc;IACjD,OAAO,CACL,IAAA,iBAAO,EAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAChC,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,KAAK,CAAC,WAAW,CAAC,MAAM;QACpD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAA,iBAAO,EAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,OAAO,C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AAQ,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,QAAgB;IAC7B,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,+EAA+E;AAC/E,QAAQ;AACR,SAAS,YAAY,CAAI,KAAU;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAqB,CAAC;AACnD,CAAC;AAED,SAAS,sBAAsB,CAC7B,aAAgB,EAChB,OAAgB,EAChB,kBAA0B,EAC1B,YAA4C;IAE5C,MAAM,cAAc,GAAG,IAAA,0BAAmB,EAAC,sBAAsB,CAAC,CAAC;IACnE,MAAM,OAAO,GAA0E;QACrF,OAAO;QACP,kBAAkB;QAClB,cAAc;QACd,GAAG,YAAY;KAChB,CAAC;IACF,OAAO;QACL,MAAM,EAAE,gBAAgB;QACxB,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["/*\n Most of the work this module does is putting an HTML-oriented facade around\n Webpack. That is, we want both the input and output to be primarily HTML files\n with proper spec semantics, and we use webpack to optimize the assets referred\n to by those files.\n\n While there are webpack plugins for handling HTML, none of them handle\n multiple HTML entrypoints and apply correct HTML semantics (for example,\n getting script vs module context correct).\n*/\n\nimport type { AppMeta, BundleSummary, Packager, PackagerConstructor, Variant, ResolverOptions } from '@embroider/core';\nimport { HTMLEntrypoint, getAppMeta, getPackagerCacheDir, getOrCreate } from '@embroider/core';\nimport { locateEmbroiderWorkingDir, RewrittenPackageCache, tmpdir } from '@embroider/shared-internals';\nimport type { Configuration, RuleSetUseItem, WebpackPluginInstance } from 'webpack';\nimport webpack from 'webpack';\nimport type { Stats } from 'fs-extra';\nimport { readFileSync, outputFileSync, copySync, statSync, readJSONSync } from 'fs-extra';\nimport { join, dirname, relative, sep } from 'path';\nimport isEqual from 'lodash/isEqual';\nimport mergeWith from 'lodash/mergeWith';\nimport flatMap from 'lodash/flatMap';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport makeDebug from 'debug';\nimport { format } from 'util';\nimport { warmup as threadLoaderWarmup } from 'thread-loader';\nimport type { Options, BabelLoaderOptions } from './options';\nimport crypto from 'crypto';\nimport semverSatisfies from 'semver/functions/satisfies';\nimport supportsColor from 'supports-color';\nimport type { Options as HbsLoaderOptions } from '@embroider/hbs-loader';\nimport type { Options as EmbroiderPluginOptions } from './webpack-resolver-plugin';\nimport { EmbroiderPlugin } from './webpack-resolver-plugin';\n\nconst debug = makeDebug('embroider:debug');\n\n// This is a type-only import, so it gets compiled away. At runtime, we load\n// terser lazily so it's only loaded for production builds that use it. Don't\n// add any non-type-only imports here.\nimport type { MinifyOptions } from 'terser';\n\ninterface AppInfo {\n entrypoints: HTMLEntrypoint[];\n otherAssets: string[];\n babel: AppMeta['babel'];\n rootURL: AppMeta['root-url'];\n publicAssetURL: string;\n resolverConfig: ResolverOptions;\n packageName: string;\n}\n\n// AppInfos are equal if they result in the same webpack config.\nfunction equalAppInfo(left: AppInfo, right: AppInfo): boolean {\n return (\n isEqual(left.babel, right.babel) &&\n left.entrypoints.length === right.entrypoints.length &&\n left.entrypoints.every((e, index) => isEqual(e.modules, right.entrypoints[index].modules))\n );\n}\n\ntype BeginFn = (total: number) => void;\ntype IncrementFn = () => Promise<void>;\n\nfunction createBarrier(): [BeginFn, IncrementFn] {\n const barriers: Array<[() => void, (e: unknown) => void]> = [];\n let done = true;\n let limit = 0;\n return [begin, increment];\n\n function begin(newLimit: number) {\n if (!done) flush(new Error('begin called before limit reached'));\n done = false;\n limit = newLimit;\n }\n\n async function increment() {\n if (done) {\n throw new Error('increment after limit reach');\n }\n const promise = new Promise<void>((resolve, reject) => {\n barriers.push([resolve, reject]);\n });\n if (barriers.length === limit) {\n flush();\n }\n await promise;\n }\n\n function flush(err?: Error) {\n for (const [resolve, reject] of barriers) {\n if (err) reject(err);\n else resolve();\n }\n barriers.length = 0;\n done = true;\n }\n}\n\n// we want to ensure that not only does our instance conform to\n// PackagerInstance, but our constructor conforms to Packager. So instead of\n// just exporting our class directly, we export a const constructor of the\n// correct type.\nconst Webpack: PackagerConstructor<Options> = class Webpack implements Packager {\n static annotation = '@embroider/webpack';\n\n private pathToVanillaApp: string;\n private extraConfig: Configuration | undefined;\n private passthroughCache: Map<string, Stats> = new Map();\n private publicAssetURL: string | undefined;\n private extraThreadLoaderOptions: object | false | undefined;\n private extraBabelLoaderOptions: BabelLoaderOptions | undefined;\n private extraCssLoaderOptions: object | undefined;\n private extraStyleLoaderOptions: object | undefined;\n private _bundleSummary: BundleSummary | undefined;\n private beginBarrier: BeginFn;\n private incrementBarrier: IncrementFn;\n\n constructor(\n private appRoot: string,\n private outputPath: string,\n private variants: Variant[],\n private consoleWrite: (msg: string) => void,\n options?: Options\n ) {\n if (!semverSatisfies(webpack.version, '^5.0.0')) {\n throw new Error(`@embroider/webpack requires webpack@^5.0.0, but found version ${webpack.version}`);\n }\n\n let packageCache = RewrittenPackageCache.shared('embroider', appRoot);\n this.pathToVanillaApp = packageCache.maybeMoved(packageCache.get(appRoot)).root;\n this.extraConfig = options?.webpackConfig;\n this.publicAssetURL = options?.publicAssetURL;\n this.extraThreadLoaderOptions = options?.threadLoaderOptions;\n this.extraBabelLoaderOptions = options?.babelLoaderOptions;\n this.extraCssLoaderOptions = options?.cssLoaderOptions;\n this.extraStyleLoaderOptions = options?.styleLoaderOptions;\n [this.beginBarrier, this.incrementBarrier] = createBarrier();\n warmUp(this.extraThreadLoaderOptions);\n }\n\n get bundleSummary(): BundleSummary {\n let bundleSummary = this._bundleSummary;\n if (bundleSummary === undefined) {\n this._bundleSummary = bundleSummary = {\n entrypoints: new Map(),\n lazyBundles: new Map(),\n variants: this.variants,\n };\n }\n return bundleSummary;\n }\n\n async build(): Promise<void> {\n this._bundleSummary = undefined;\n this.beginBarrier(this.variants.length);\n let appInfo = this.examineApp();\n let webpack = this.getWebpack(appInfo);\n await this.runWebpack(webpack);\n }\n\n private examineApp(): AppInfo {\n let meta = getAppMeta(this.pathToVanillaApp);\n let rootURL = meta['ember-addon']['root-url'];\n let babel = meta['ember-addon']['babel'];\n let entrypoints = [];\n let otherAssets = [];\n let publicAssetURL = this.publicAssetURL || rootURL;\n\n for (let relativePath of meta['ember-addon'].assets) {\n if (/\\.html/i.test(relativePath)) {\n entrypoints.push(new HTMLEntrypoint(this.pathToVanillaApp, rootURL, publicAssetURL, relativePath));\n } else {\n otherAssets.push(relativePath);\n }\n }\n\n let resolverConfig: EmbroiderPluginOptions = readJSONSync(\n join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json')\n );\n\n return { entrypoints, otherAssets, babel, rootURL, resolverConfig, publicAssetURL, packageName: meta.name };\n }\n\n private configureWebpack(appInfo: AppInfo, variant: Variant, variantIndex: number): Configuration {\n const { entrypoints, babel, publicAssetURL, packageName, resolverConfig } = appInfo;\n\n let entry: { [name: string]: string } = {};\n for (let entrypoint of entrypoints) {\n for (let moduleName of entrypoint.modules) {\n entry[moduleName] = './' + moduleName;\n }\n }\n\n let { plugins: stylePlugins, loaders: styleLoaders } = this.setupStyleConfig(variant);\n\n let babelLoaderOptions = makeBabelLoaderOptions(\n babel.majorVersion,\n variant,\n join(this.pathToVanillaApp, babel.filename),\n this.extraBabelLoaderOptions\n );\n\n let babelLoaderPrefix = `babel-loader-9?${JSON.stringify(babelLoaderOptions.options)}!`;\n\n return {\n mode: variant.optimizeForProduction ? 'production' : 'development',\n context: this.pathToVanillaApp,\n entry,\n performance: {\n hints: false,\n },\n plugins: [\n ...stylePlugins,\n new EmbroiderPlugin(resolverConfig, babelLoaderPrefix),\n compiler => {\n compiler.hooks.done.tapPromise('EmbroiderPlugin', async stats => {\n this.summarizeStats(stats, variant, variantIndex);\n await this.writeFiles(this.bundleSummary, this.lastAppInfo!, variantIndex);\n });\n },\n ],\n node: false,\n module: {\n rules: [\n {\n test: /\\.hbs$/,\n use: nonNullArray([\n maybeThreadLoader(babel.isParallelSafe, this.extraThreadLoaderOptions),\n babelLoaderOptions,\n {\n loader: require.resolve('@embroider/hbs-loader'),\n options: (() => {\n let options: HbsLoaderOptions = {\n compatModuleNaming: {\n rootDir: this.pathToVanillaApp,\n modulePrefix: packageName,\n },\n };\n return options;\n })(),\n },\n ]),\n },\n {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n test: require(join(this.pathToVanillaApp, babel.fileFilter)),\n use: nonNullArray([\n maybeThreadLoader(babel.isParallelSafe, this.extraThreadLoaderOptions),\n makeBabelLoaderOptions(\n babel.majorVersion,\n variant,\n join(this.pathToVanillaApp, babel.filename),\n this.extraBabelLoaderOptions\n ),\n ]),\n },\n {\n test: isCSS,\n use: styleLoaders,\n },\n ],\n },\n output: {\n path: join(this.outputPath),\n filename: `assets/chunk.[chunkhash].js`,\n chunkFilename: `assets/chunk.[chunkhash].js`,\n publicPath: publicAssetURL,\n },\n optimization: {\n splitChunks: {\n chunks: 'all',\n },\n },\n resolve: {\n extensions: resolverConfig.resolvableExtensions,\n },\n resolveLoader: {\n alias: {\n // these loaders are our dependencies, not the app's dependencies. I'm\n // not overriding the default loader resolution rules in case the app also\n // wants to control those.\n 'thread-loader': require.resolve('thread-loader'),\n 'babel-loader-9': require.resolve('@embroider/babel-loader-9'),\n 'css-loader': require.resolve('css-loader'),\n 'style-loader': require.resolve('style-loader'),\n },\n },\n };\n }\n\n private lastAppInfo: AppInfo | undefined;\n private lastWebpack: webpack.MultiCompiler | undefined;\n\n private getWebpack(appInfo: AppInfo) {\n if (this.lastWebpack && this.lastAppInfo && equalAppInfo(appInfo, this.lastAppInfo)) {\n debug(`reusing webpack config`);\n // the appInfos result in equal webpack configs so we don't need to\n // reconfigure webpack. But they may contain other changes (like HTML\n // content changes that don't alter the webpack config) so we still want\n // lastAppInfo to update so that the latest one will be seen in the\n // webpack post-build.\n this.lastAppInfo = appInfo;\n return this.lastWebpack;\n }\n debug(`configuring webpack`);\n let config = this.variants.map((variant, variantIndex) =>\n mergeWith({}, this.configureWebpack(appInfo, variant, variantIndex), this.extraConfig, appendArrays)\n );\n this.lastAppInfo = appInfo;\n return (this.lastWebpack = webpack(config));\n }\n\n private async writeScript(script: string, written: Set<string>, variant: Variant) {\n if (!variant.optimizeForProduction) {\n this.copyThrough(script);\n return script;\n }\n\n // loading these lazily here so they never load in non-production builds.\n // The node cache will ensures we only load them once.\n const [Terser, srcURL] = await Promise.all([import('terser'), import('source-map-url')]);\n\n let inCode = readFileSync(join(this.pathToVanillaApp, script), 'utf8');\n let terserOpts: MinifyOptions = {};\n let fileRelativeSourceMapURL;\n let appRelativeSourceMapURL;\n if (srcURL.default.existsIn(inCode)) {\n fileRelativeSourceMapURL = srcURL.default.getFrom(inCode)!;\n appRelativeSourceMapURL = join(dirname(script), fileRelativeSourceMapURL);\n let content;\n try {\n content = readJSONSync(join(this.pathToVanillaApp, appRelativeSourceMapURL));\n } catch (err) {\n // the script refers to a sourcemap that doesn't exist, so we just leave\n // the map out.\n }\n if (content) {\n terserOpts.sourceMap = { content, url: fileRelativeSourceMapURL };\n }\n }\n let { code: outCode, map: outMap } = await Terser.default.minify(inCode, terserOpts);\n let finalFilename = this.getFingerprintedFilename(script, outCode!);\n outputFileSync(join(this.outputPath, finalFilename), outCode!);\n written.add(script);\n if (appRelativeSourceMapURL && outMap) {\n outputFileSync(join(this.outputPath, appRelativeSourceMapURL), outMap);\n written.add(appRelativeSourceMapURL);\n }\n return finalFilename;\n }\n\n private async writeStyle(style: string, written: Set<string>, variant: Variant) {\n if (!variant.optimizeForProduction) {\n this.copyThrough(style);\n written.add(style);\n return style;\n }\n\n const csso = await import('csso');\n const cssContent = readFileSync(join(this.pathToVanillaApp, style), 'utf8');\n const minifiedCss = csso.minify(cssContent).css;\n\n let finalFilename = this.getFingerprintedFilename(style, minifiedCss);\n outputFileSync(join(this.outputPath, finalFilename), minifiedCss);\n written.add(style);\n return finalFilename;\n }\n\n private async provideErrorContext(message: string, messageParams: any[], fn: () => Promise<void>) {\n try {\n return await fn();\n } catch (err) {\n let context = format(message, ...messageParams);\n err.message = context + ': ' + err.message;\n throw err;\n }\n }\n\n private async writeFiles(stats: BundleSummary, { entrypoints, otherAssets }: AppInfo, variantIndex: number) {\n // we're doing this ourselves because I haven't seen a webpack 4 HTML plugin\n // that handles multiple HTML entrypoints correctly.\n\n let written: Set<string> = new Set();\n // scripts (as opposed to modules) and stylesheets (as opposed to CSS\n // modules that are imported from JS modules) get passed through without\n // going through webpack.\n for (let entrypoint of entrypoints) {\n await this.provideErrorContext('needed by %s', [entrypoint.filename], async () => {\n for (let script of entrypoint.scripts) {\n if (!stats.entrypoints.has(script)) {\n const mapping = [] as string[];\n try {\n // zero here means we always attribute passthrough scripts to the\n // first build variant\n stats.entrypoints.set(script, new Map([[0, mapping]]));\n mapping.push(await this.writeScript(script, written, this.variants[0]));\n } catch (err) {\n if (err.code === 'ENOENT' && err.path === join(this.pathToVanillaApp, script)) {\n this.consoleWrite(\n `warning: in ${entrypoint.filename} <script src=\"${script\n .split(sep)\n .join(\n '/'\n )}\"> does not exist on disk. If this is intentional, use a data-embroider-ignore attribute.`\n );\n } else {\n throw err;\n }\n }\n }\n }\n for (let style of entrypoint.styles) {\n if (!stats.entrypoints.has(style)) {\n const mapping = [] as string[];\n try {\n // zero here means we always attribute passthrough styles to the\n // first build variant\n stats.entrypoints.set(style, new Map([[0, mapping]]));\n mapping.push(await this.writeStyle(style, written, this.variants[0]));\n } catch (err) {\n if (err.code === 'ENOENT' && err.path === join(this.pathToVanillaApp, style)) {\n this.consoleWrite(\n `warning: in ${entrypoint.filename} <link rel=\"stylesheet\" href=\"${style\n .split(sep)\n .join(\n '/'\n )}\"> does not exist on disk. If this is intentional, use a data-embroider-ignore attribute.`\n );\n } else {\n throw err;\n }\n }\n }\n }\n });\n }\n // we need to wait for both compilers before writing html entrypoint\n await this.incrementBarrier();\n // only the first variant should write it.\n if (variantIndex === 0) {\n for (let entrypoint of entrypoints) {\n this.writeIfChanged(join(this.outputPath, entrypoint.filename), entrypoint.render(stats));\n written.add(entrypoint.filename);\n }\n }\n\n for (let relativePath of otherAssets) {\n if (!written.has(relativePath)) {\n written.add(relativePath);\n await this.provideErrorContext(`while copying app's assets`, [], async () => {\n this.copyThrough(relativePath);\n });\n }\n }\n }\n\n private lastContents = new Map<string, string>();\n\n // The point of this caching isn't really performance (we generate the\n // contents either way, and the actual write is unlikely to be expensive).\n // It's helping ember-cli's traditional livereload system to avoid triggering\n // a full page reload when that wasn't really necessary.\n private writeIfChanged(filename: string, content: string) {\n if (this.lastContents.get(filename) !== content) {\n outputFileSync(filename, content, 'utf8');\n this.lastContents.set(filename, content);\n }\n }\n\n private copyThrough(relativePath: string) {\n let sourcePath = join(this.pathToVanillaApp, relativePath);\n let newStats = statSync(sourcePath);\n let oldStats = this.passthroughCache.get(sourcePath);\n if (!oldStats || oldStats.mtimeMs !== newStats.mtimeMs || oldStats.size !== newStats.size) {\n debug(`emitting ${relativePath}`);\n copySync(sourcePath, join(this.outputPath, relativePath));\n this.passthroughCache.set(sourcePath, newStats);\n }\n }\n\n private getFingerprintedFilename(filename: string, content: string): string {\n let md5 = crypto.createHash('md5');\n md5.update(content);\n let hash = md5.digest('hex');\n\n let fileParts = filename.split('.');\n fileParts.splice(fileParts.length - 1, 0, hash);\n return fileParts.join('.');\n }\n\n private summarizeStats(stats: webpack.Stats, variant: Variant, variantIndex: number): void {\n let output = this.bundleSummary;\n let { entrypoints, chunks } = stats.toJson({\n all: false,\n entrypoints: true,\n chunks: true,\n });\n\n // webpack's types are written rather loosely, implying that these two\n // properties may not be present. They really always are, as far as I can\n // tell, but we need to check here anyway to satisfy the type checker.\n if (!entrypoints) {\n throw new Error(`unexpected webpack output: no entrypoints`);\n }\n if (!chunks) {\n throw new Error(`unexpected webpack output: no chunks`);\n }\n\n for (let id of Object.keys(entrypoints)) {\n let { assets: entrypointAssets } = entrypoints[id];\n if (!entrypointAssets) {\n throw new Error(`unexpected webpack output: no entrypoint.assets`);\n }\n\n getOrCreate(output.entrypoints, id, () => new Map()).set(\n variantIndex,\n entrypointAssets.map(asset => asset.name)\n );\n if (variant.runtime !== 'browser') {\n // in the browser we don't need to worry about lazy assets (they will be\n // handled automatically by webpack as needed), but in any other runtime\n // we need the ability to preload them\n output.lazyBundles.set(\n id,\n flatMap(\n chunks.filter(chunk => chunk.runtime?.includes(id)),\n chunk => chunk.files\n ).filter(file => !entrypointAssets?.find(a => a.name === file)) as string[]\n );\n }\n }\n }\n\n private runWebpack(webpack: webpack.MultiCompiler): Promise<webpack.MultiStats> {\n return new Promise((resolve, reject) => {\n webpack.run((err, stats) => {\n try {\n if (err) {\n if (stats) {\n this.consoleWrite(stats.toString());\n }\n throw err;\n }\n if (!stats) {\n // this doesn't really happen, but webpack's types imply that it\n // could, so we just satisfy typescript here\n throw new Error('bug: no stats and no err');\n }\n if (stats.hasErrors()) {\n // write all the stats output to the console\n this.consoleWrite(\n stats.toString({\n colors: Boolean(supportsColor.stdout),\n })\n );\n\n // the typing for MultiCompiler are all foobared.\n throw this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors));\n }\n if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) {\n this.consoleWrite(\n stats.toString({\n colors: Boolean(supportsColor.stdout),\n })\n );\n }\n resolve(stats);\n } catch (e) {\n reject(e);\n }\n });\n });\n }\n\n private setupStyleConfig(variant: Variant): {\n loaders: RuleSetUseItem[];\n plugins: WebpackPluginInstance[];\n } {\n let cssLoader = {\n loader: 'css-loader',\n options: {\n url: true,\n import: true,\n modules: 'global',\n ...this.extraCssLoaderOptions,\n },\n };\n\n if (!variant.optimizeForProduction && variant.runtime === 'browser') {\n // in development builds that only need to work in the browser (not\n // fastboot), we can use style-loader because it's fast\n return {\n loaders: [\n { loader: 'style-loader', options: { injectType: 'styleTag', ...this.extraStyleLoaderOptions } },\n cssLoader,\n ],\n plugins: [],\n };\n } else {\n // in any other build, we separate the CSS into its own bundles\n return {\n loaders: [MiniCssExtractPlugin.loader, cssLoader],\n plugins: [\n new MiniCssExtractPlugin({\n filename: `assets/chunk.[chunkhash].css`,\n chunkFilename: `assets/chunk.[chunkhash].css`,\n // in the browser, MiniCssExtractPlugin can manage it's own runtime\n // lazy loading of stylesheets.\n //\n // but in fastboot, we need to disable that in favor of doing our\n // own insertion of `<link>` tags in the HTML\n runtime: variant.runtime === 'browser',\n // It's not reasonable to make assumptions about order when doing CSS via modules\n ignoreOrder: true,\n }),\n ],\n };\n }\n }\n\n private findBestError(errors: any[]) {\n let error = errors[0];\n let file;\n if (error.module?.userRequest) {\n file = relative(this.pathToVanillaApp, error.module.userRequest);\n }\n\n if (!error.file) {\n error.file = file || (error.loc ? error.loc.file : null) || (error.location ? error.location.file : null);\n }\n if (error.line == null) {\n error.line = (error.loc ? error.loc.line : null) || (error.location ? error.location.line : null);\n }\n if (typeof error.message === 'string') {\n if (error.module?.context) {\n error.message = error.message.replace(error.module.context, error.module.userRequest);\n }\n\n // the tmpdir on OSX is horribly long and makes error messages hard to\n // read. This is doing the same as String.prototype.replaceAll, which node\n // doesn't have yet.\n error.message = error.message.split(tmpdir).join('$TMPDIR');\n }\n return error;\n }\n};\n\nconst threadLoaderOptions = {\n workers: 'JOBS' in process.env && Number(process.env.JOBS),\n // poolTimeout shuts down idle workers. The problem is, for\n // interactive rebuilds that means your startup cost for the\n // next rebuild is at least 600ms worse. So we insist on\n // keeping workers alive always.\n poolTimeout: Infinity,\n};\n\nfunction canUseThreadLoader(extraOptions: object | false | undefined) {\n // If the environment sets JOBS to 0, or if our extraOptions are set to false,\n // we have been explicitly configured not to use thread-loader\n if (process.env.JOBS === '0' || extraOptions === false) {\n return false;\n } else {\n return true;\n }\n}\n\nfunction warmUp(extraOptions: object | false | undefined) {\n // We don't know if we'll be parallel-safe or not, but if we've been\n // configured to not use thread-loader, then there is no need to consume extra\n // resources warming the worker pool\n if (!canUseThreadLoader(extraOptions)) {\n return null;\n }\n\n threadLoaderWarmup(Object.assign({}, threadLoaderOptions, extraOptions), [\n require.resolve('@embroider/hbs-loader'),\n require.resolve('@embroider/babel-loader-9'),\n ]);\n}\n\nfunction maybeThreadLoader(isParallelSafe: boolean, extraOptions: object | false | undefined) {\n if (!canUseThreadLoader(extraOptions) || !isParallelSafe) {\n return null;\n }\n\n return {\n loader: 'thread-loader',\n options: Object.assign({}, threadLoaderOptions, extraOptions),\n };\n}\n\nfunction appendArrays(objValue: any, srcValue: any) {\n if (Array.isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n}\n\nfunction isCSS(filename: string) {\n return /\\.css$/i.test(filename);\n}\n\n// typescript doesn't understand that regular use of array.filter(Boolean) does\n// this.\nfunction nonNullArray<T>(array: T[]): NonNullable<T>[] {\n return array.filter(Boolean) as NonNullable<T>[];\n}\n\nfunction makeBabelLoaderOptions(\n _majorVersion: 7,\n variant: Variant,\n appBabelConfigPath: string,\n extraOptions: BabelLoaderOptions | undefined\n) {\n const cacheDirectory = getPackagerCacheDir('webpack-babel-loader');\n const options: BabelLoaderOptions & { variant: Variant; appBabelConfigPath: string } = {\n variant,\n appBabelConfigPath,\n cacheDirectory,\n ...extraOptions,\n };\n return {\n loader: 'babel-loader-9',\n options,\n };\n}\n\nexport { Webpack };\n"]}
|
1
|
+
{"version":3,"file":"ember-webpack.js","sourceRoot":"","sources":["ember-webpack.ts"],"names":[],"mappings":";AAAA;;;;;;;;;EASE;;;;;;;AAGF,0CAAmF;AACnF,kEAAuG;AAEvG,sDAA8B;AAE9B,uCAA0F;AAC1F,+BAAoD;AACpD,6DAAqC;AACrC,iEAAyC;AACzC,6DAAqC;AACrC,sFAA2D;AAC3D,kDAA8B;AAC9B,+BAA8B;AAC9B,iDAA6D;AAE7D,oDAA4B;AAC5B,2EAAyD;AACzD,oEAA2C;AAG3C,uEAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,eAAS,EAAC,iBAAiB,CAAC,CAAC;AAE3C,0EAA0E;AAC1E,6DAA6D;AAC7D,KAAK,UAAU,UAAU;IACvB,IAAI,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC;AACv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,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,QAAgB;IAC7B,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,+EAA+E;AAC/E,QAAQ;AACR,SAAS,YAAY,CAAI,KAAU;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAqB,CAAC;AACnD,CAAC;AAED,SAAS,sBAAsB,CAC7B,OAAgB,EAChB,kBAA0B,EAC1B,YAA4C;IAE5C,MAAM,cAAc,GAAG,IAAA,0BAAmB,EAAC,sBAAsB,CAAC,CAAC;IACnE,MAAM,OAAO,GAA0E;QACrF,OAAO;QACP,kBAAkB;QAClB,cAAc;QACd,GAAG,YAAY;KAChB,CAAC;IACF,OAAO;QACL,MAAM,EAAE,gBAAgB;QACxB,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["/*\n Most of the work this module does is putting an HTML-oriented facade around\n Webpack. That is, we want both the input and output to be primarily HTML files\n with proper spec semantics, and we use webpack to optimize the assets referred\n to by those files.\n\n While there are webpack plugins for handling HTML, none of them handle\n multiple HTML entrypoints and apply correct HTML semantics (for example,\n getting script vs module context correct).\n*/\n\nimport type { BundleSummary, Packager, PackagerConstructor, Variant, ResolverOptions } from '@embroider/core';\nimport { HTMLEntrypoint, getPackagerCacheDir, getOrCreate } from '@embroider/core';\nimport { locateEmbroiderWorkingDir, RewrittenPackageCache, tmpdir } from '@embroider/shared-internals';\nimport type { Configuration, RuleSetUseItem, WebpackPluginInstance } from 'webpack';\nimport webpack from 'webpack';\nimport type { Stats } from 'fs-extra';\nimport { readFileSync, outputFileSync, copySync, statSync, readJSONSync } from 'fs-extra';\nimport { join, dirname, relative, sep } from 'path';\nimport isEqual from 'lodash/isEqual';\nimport mergeWith from 'lodash/mergeWith';\nimport flatMap from 'lodash/flatMap';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport makeDebug from 'debug';\nimport { format } from 'util';\nimport { warmup as threadLoaderWarmup } from 'thread-loader';\nimport type { Options, BabelLoaderOptions } from './options';\nimport crypto from 'crypto';\nimport semverSatisfies from 'semver/functions/satisfies';\nimport supportsColor from 'supports-color';\nimport type { Options as HbsLoaderOptions } from '@embroider/hbs-loader';\nimport type { Options as EmbroiderPluginOptions } from './webpack-resolver-plugin';\nimport { EmbroiderPlugin } from './webpack-resolver-plugin';\n\nconst debug = makeDebug('embroider:debug');\n\n// this function is never called. It exists to workaround typescript being\n// obtuse. https://github.com/microsoft/TypeScript/pull/53426\nasync function loadTerser() {\n let Terser = await import('terser');\n return Terser.minify;\n}\ntype MinifyOptions = NonNullable<Parameters<Awaited<ReturnType<typeof loadTerser>>>[1]>;\n\ninterface AppInfo {\n entrypoints: HTMLEntrypoint[];\n otherAssets: string[];\n rootURL: string;\n publicAssetURL: string;\n resolverConfig: ResolverOptions;\n packageName: string;\n}\n\n// AppInfos are equal if they result in the same webpack config.\nfunction equalAppInfo(left: AppInfo, right: AppInfo): boolean {\n return (\n left.entrypoints.length === right.entrypoints.length &&\n left.entrypoints.every((e, index) => isEqual(e.modules, right.entrypoints[index].modules))\n );\n}\n\ntype BeginFn = (total: number) => void;\ntype IncrementFn = () => Promise<void>;\n\nfunction createBarrier(): [BeginFn, IncrementFn] {\n const barriers: Array<[() => void, (e: unknown) => void]> = [];\n let done = true;\n let limit = 0;\n return [begin, increment];\n\n function begin(newLimit: number) {\n if (!done) flush(new Error('begin called before limit reached'));\n done = false;\n limit = newLimit;\n }\n\n async function increment() {\n if (done) {\n throw new Error('increment after limit reach');\n }\n const promise = new Promise<void>((resolve, reject) => {\n barriers.push([resolve, reject]);\n });\n if (barriers.length === limit) {\n flush();\n }\n await promise;\n }\n\n function flush(err?: Error) {\n for (const [resolve, reject] of barriers) {\n if (err) reject(err);\n else resolve();\n }\n barriers.length = 0;\n done = true;\n }\n}\n\n// we want to ensure that not only does our instance conform to\n// PackagerInstance, but our constructor conforms to Packager. So instead of\n// just exporting our class directly, we export a const constructor of the\n// correct type.\nconst Webpack: PackagerConstructor<Options> = class Webpack implements Packager {\n static annotation = '@embroider/webpack';\n\n private pathToVanillaApp: string;\n private extraConfig: Configuration | undefined;\n private passthroughCache: Map<string, Stats> = new Map();\n private publicAssetURL: string | undefined;\n private extraThreadLoaderOptions: object | false | undefined;\n private extraBabelLoaderOptions: BabelLoaderOptions | undefined;\n private extraCssLoaderOptions: object | undefined;\n private extraStyleLoaderOptions: object | undefined;\n private _bundleSummary: BundleSummary | undefined;\n private beginBarrier: BeginFn;\n private incrementBarrier: IncrementFn;\n\n constructor(\n private appRoot: string,\n private outputPath: string,\n private variants: Variant[],\n private consoleWrite: (msg: string) => void,\n options?: Options\n ) {\n if (!semverSatisfies(webpack.version, '^5.0.0')) {\n throw new Error(`@embroider/webpack requires webpack@^5.0.0, but found version ${webpack.version}`);\n }\n\n let packageCache = RewrittenPackageCache.shared('embroider', appRoot);\n this.pathToVanillaApp = packageCache.maybeMoved(packageCache.get(appRoot)).root;\n this.extraConfig = options?.webpackConfig;\n this.publicAssetURL = options?.publicAssetURL;\n this.extraThreadLoaderOptions = options?.threadLoaderOptions;\n this.extraBabelLoaderOptions = options?.babelLoaderOptions;\n this.extraCssLoaderOptions = options?.cssLoaderOptions;\n this.extraStyleLoaderOptions = options?.styleLoaderOptions;\n [this.beginBarrier, this.incrementBarrier] = createBarrier();\n warmUp(this.extraThreadLoaderOptions);\n }\n\n get bundleSummary(): BundleSummary {\n let bundleSummary = this._bundleSummary;\n if (bundleSummary === undefined) {\n this._bundleSummary = bundleSummary = {\n entrypoints: new Map(),\n lazyBundles: new Map(),\n variants: this.variants,\n };\n }\n return bundleSummary;\n }\n\n async build(): Promise<void> {\n this._bundleSummary = undefined;\n this.beginBarrier(this.variants.length);\n let appInfo = this.examineApp();\n let webpack = this.getWebpack(appInfo);\n await this.runWebpack(webpack);\n }\n\n private examineApp(): AppInfo {\n // @ts-expect-error webpack is not updated to work on @embroider/core 4.x\n let meta = getAppMeta(this.pathToVanillaApp);\n let rootURL = meta['ember-addon']['root-url'];\n let entrypoints = [];\n let otherAssets = [];\n let publicAssetURL = this.publicAssetURL || rootURL;\n\n for (let relativePath of meta['ember-addon'].assets) {\n if (/\\.html/i.test(relativePath)) {\n entrypoints.push(new HTMLEntrypoint(this.pathToVanillaApp, rootURL, publicAssetURL, relativePath));\n } else {\n otherAssets.push(relativePath);\n }\n }\n\n let resolverConfig: EmbroiderPluginOptions = readJSONSync(\n join(locateEmbroiderWorkingDir(this.appRoot), 'resolver.json')\n );\n\n return { entrypoints, otherAssets, rootURL, resolverConfig, publicAssetURL, packageName: meta.name };\n }\n\n private configureWebpack(appInfo: AppInfo, variant: Variant, variantIndex: number): Configuration {\n const { entrypoints, publicAssetURL, packageName, resolverConfig } = appInfo;\n\n let entry: { [name: string]: string } = {};\n for (let entrypoint of entrypoints) {\n for (let moduleName of entrypoint.modules) {\n entry[moduleName] = './' + moduleName;\n }\n }\n\n let { plugins: stylePlugins, loaders: styleLoaders } = this.setupStyleConfig(variant);\n\n let babelLoaderOptions = makeBabelLoaderOptions(\n variant,\n join(this.appRoot, 'babel.config.cjs'),\n this.extraBabelLoaderOptions\n );\n\n let babelLoaderPrefix = `babel-loader-9?${JSON.stringify(babelLoaderOptions.options)}!`;\n\n return {\n mode: variant.optimizeForProduction ? 'production' : 'development',\n context: this.pathToVanillaApp,\n entry,\n performance: {\n hints: false,\n },\n plugins: [\n ...stylePlugins,\n new EmbroiderPlugin(resolverConfig, babelLoaderPrefix),\n compiler => {\n compiler.hooks.done.tapPromise('EmbroiderPlugin', async stats => {\n this.summarizeStats(stats, variant, variantIndex);\n await this.writeFiles(this.bundleSummary, this.lastAppInfo!, variantIndex);\n });\n },\n ],\n node: false,\n module: {\n rules: [\n {\n test: /\\.hbs$/,\n use: nonNullArray([\n maybeThreadLoader(this.extraThreadLoaderOptions),\n babelLoaderOptions,\n {\n loader: require.resolve('@embroider/hbs-loader'),\n options: (() => {\n let options: HbsLoaderOptions = {\n compatModuleNaming: {\n rootDir: this.pathToVanillaApp,\n modulePrefix: packageName,\n },\n };\n return options;\n })(),\n },\n ]),\n },\n {\n use: nonNullArray([\n maybeThreadLoader(this.extraThreadLoaderOptions),\n makeBabelLoaderOptions(variant, join(this.appRoot, 'babel.config.cjs'), this.extraBabelLoaderOptions),\n ]),\n },\n {\n test: isCSS,\n use: styleLoaders,\n },\n ],\n },\n output: {\n path: join(this.outputPath),\n filename: `assets/chunk.[chunkhash].js`,\n chunkFilename: `assets/chunk.[chunkhash].js`,\n publicPath: publicAssetURL,\n },\n optimization: {\n splitChunks: {\n chunks: 'all',\n },\n },\n resolve: {\n extensions: resolverConfig.resolvableExtensions,\n },\n resolveLoader: {\n alias: {\n // these loaders are our dependencies, not the app's dependencies. I'm\n // not overriding the default loader resolution rules in case the app also\n // wants to control those.\n 'thread-loader': require.resolve('thread-loader'),\n 'babel-loader-9': require.resolve('@embroider/babel-loader-9'),\n 'css-loader': require.resolve('css-loader'),\n 'style-loader': require.resolve('style-loader'),\n },\n },\n experiments: {\n // this is needed because fasboot-only modules need to use await import()\n topLevelAwait: true,\n },\n };\n }\n\n private lastAppInfo: AppInfo | undefined;\n private lastWebpack: webpack.MultiCompiler | undefined;\n\n private getWebpack(appInfo: AppInfo) {\n if (this.lastWebpack && this.lastAppInfo && equalAppInfo(appInfo, this.lastAppInfo)) {\n debug(`reusing webpack config`);\n // the appInfos result in equal webpack configs so we don't need to\n // reconfigure webpack. But they may contain other changes (like HTML\n // content changes that don't alter the webpack config) so we still want\n // lastAppInfo to update so that the latest one will be seen in the\n // webpack post-build.\n this.lastAppInfo = appInfo;\n return this.lastWebpack;\n }\n debug(`configuring webpack`);\n let config = this.variants.map((variant, variantIndex) =>\n mergeWith({}, this.configureWebpack(appInfo, variant, variantIndex), this.extraConfig, appendArrays)\n );\n this.lastAppInfo = appInfo;\n return (this.lastWebpack = webpack(config));\n }\n\n private async writeScript(script: string, written: Set<string>, variant: Variant) {\n if (!variant.optimizeForProduction) {\n this.copyThrough(script);\n return script;\n }\n\n // loading these lazily here so they never load in non-production builds.\n // The node cache will ensures we only load them once.\n const [Terser, srcURL] = await Promise.all([import('terser'), import('source-map-url')]);\n\n let inCode = readFileSync(join(this.pathToVanillaApp, script), 'utf8');\n let terserOpts: MinifyOptions = {};\n let fileRelativeSourceMapURL;\n let appRelativeSourceMapURL;\n if (srcURL.default.existsIn(inCode)) {\n fileRelativeSourceMapURL = srcURL.default.getFrom(inCode)!;\n appRelativeSourceMapURL = join(dirname(script), fileRelativeSourceMapURL);\n let content;\n try {\n content = readJSONSync(join(this.pathToVanillaApp, appRelativeSourceMapURL));\n } catch (err) {\n // the script refers to a sourcemap that doesn't exist, so we just leave\n // the map out.\n }\n if (content) {\n terserOpts.sourceMap = { content, url: fileRelativeSourceMapURL };\n }\n }\n let { code: outCode, map: outMap } = await Terser.minify(inCode, terserOpts);\n let finalFilename = this.getFingerprintedFilename(script, outCode!);\n outputFileSync(join(this.outputPath, finalFilename), outCode!);\n written.add(script);\n if (appRelativeSourceMapURL && outMap) {\n outputFileSync(join(this.outputPath, appRelativeSourceMapURL), outMap);\n written.add(appRelativeSourceMapURL);\n }\n return finalFilename;\n }\n\n private async writeStyle(style: string, written: Set<string>, variant: Variant) {\n if (!variant.optimizeForProduction) {\n this.copyThrough(style);\n written.add(style);\n return style;\n }\n\n const csso = await import('csso');\n const cssContent = readFileSync(join(this.pathToVanillaApp, style), 'utf8');\n const minifiedCss = csso.minify(cssContent).css;\n\n let finalFilename = this.getFingerprintedFilename(style, minifiedCss);\n outputFileSync(join(this.outputPath, finalFilename), minifiedCss);\n written.add(style);\n return finalFilename;\n }\n\n private async provideErrorContext(message: string, messageParams: any[], fn: () => Promise<void>) {\n try {\n return await fn();\n } catch (err) {\n let context = format(message, ...messageParams);\n err.message = context + ': ' + err.message;\n throw err;\n }\n }\n\n private async writeFiles(stats: BundleSummary, { entrypoints, otherAssets }: AppInfo, variantIndex: number) {\n // we're doing this ourselves because I haven't seen a webpack 4 HTML plugin\n // that handles multiple HTML entrypoints correctly.\n\n let written: Set<string> = new Set();\n // scripts (as opposed to modules) and stylesheets (as opposed to CSS\n // modules that are imported from JS modules) get passed through without\n // going through webpack.\n for (let entrypoint of entrypoints) {\n await this.provideErrorContext('needed by %s', [entrypoint.filename], async () => {\n for (let script of entrypoint.scripts) {\n if (!stats.entrypoints.has(script)) {\n const mapping = [] as string[];\n try {\n // zero here means we always attribute passthrough scripts to the\n // first build variant\n stats.entrypoints.set(script, new Map([[0, mapping]]));\n mapping.push(await this.writeScript(script, written, this.variants[0]));\n } catch (err) {\n if (err.code === 'ENOENT' && err.path === join(this.pathToVanillaApp, script)) {\n this.consoleWrite(\n `warning: in ${entrypoint.filename} <script src=\"${script\n .split(sep)\n .join(\n '/'\n )}\"> does not exist on disk. If this is intentional, use a data-embroider-ignore attribute.`\n );\n } else {\n throw err;\n }\n }\n }\n }\n for (let style of entrypoint.styles) {\n if (!stats.entrypoints.has(style)) {\n const mapping = [] as string[];\n try {\n // zero here means we always attribute passthrough styles to the\n // first build variant\n stats.entrypoints.set(style, new Map([[0, mapping]]));\n mapping.push(await this.writeStyle(style, written, this.variants[0]));\n } catch (err) {\n if (err.code === 'ENOENT' && err.path === join(this.pathToVanillaApp, style)) {\n this.consoleWrite(\n `warning: in ${entrypoint.filename} <link rel=\"stylesheet\" href=\"${style\n .split(sep)\n .join(\n '/'\n )}\"> does not exist on disk. If this is intentional, use a data-embroider-ignore attribute.`\n );\n } else {\n throw err;\n }\n }\n }\n }\n });\n }\n // we need to wait for both compilers before writing html entrypoint\n await this.incrementBarrier();\n // only the first variant should write it.\n if (variantIndex === 0) {\n for (let entrypoint of entrypoints) {\n this.writeIfChanged(join(this.outputPath, entrypoint.filename), entrypoint.render(stats));\n written.add(entrypoint.filename);\n }\n }\n\n for (let relativePath of otherAssets) {\n if (!written.has(relativePath)) {\n written.add(relativePath);\n await this.provideErrorContext(`while copying app's assets`, [], async () => {\n this.copyThrough(relativePath);\n });\n }\n }\n }\n\n private lastContents = new Map<string, string>();\n\n // The point of this caching isn't really performance (we generate the\n // contents either way, and the actual write is unlikely to be expensive).\n // It's helping ember-cli's traditional livereload system to avoid triggering\n // a full page reload when that wasn't really necessary.\n private writeIfChanged(filename: string, content: string) {\n if (this.lastContents.get(filename) !== content) {\n outputFileSync(filename, content, 'utf8');\n this.lastContents.set(filename, content);\n }\n }\n\n private copyThrough(relativePath: string) {\n let sourcePath = join(this.pathToVanillaApp, relativePath);\n let newStats = statSync(sourcePath);\n let oldStats = this.passthroughCache.get(sourcePath);\n if (!oldStats || oldStats.mtimeMs !== newStats.mtimeMs || oldStats.size !== newStats.size) {\n debug(`emitting ${relativePath}`);\n copySync(sourcePath, join(this.outputPath, relativePath));\n this.passthroughCache.set(sourcePath, newStats);\n }\n }\n\n private getFingerprintedFilename(filename: string, content: string): string {\n let md5 = crypto.createHash('md5');\n md5.update(content);\n let hash = md5.digest('hex');\n\n let fileParts = filename.split('.');\n fileParts.splice(fileParts.length - 1, 0, hash);\n return fileParts.join('.');\n }\n\n private summarizeStats(stats: webpack.Stats, variant: Variant, variantIndex: number): void {\n let output = this.bundleSummary;\n let { entrypoints, chunks } = stats.toJson({\n all: false,\n entrypoints: true,\n chunks: true,\n });\n\n // webpack's types are written rather loosely, implying that these two\n // properties may not be present. They really always are, as far as I can\n // tell, but we need to check here anyway to satisfy the type checker.\n if (!entrypoints) {\n throw new Error(`unexpected webpack output: no entrypoints`);\n }\n if (!chunks) {\n throw new Error(`unexpected webpack output: no chunks`);\n }\n\n for (let id of Object.keys(entrypoints)) {\n let { assets: entrypointAssets } = entrypoints[id];\n if (!entrypointAssets) {\n throw new Error(`unexpected webpack output: no entrypoint.assets`);\n }\n\n getOrCreate(output.entrypoints, id, () => new Map()).set(\n variantIndex,\n entrypointAssets.map(asset => asset.name)\n );\n if (variant.runtime !== 'browser') {\n // in the browser we don't need to worry about lazy assets (they will be\n // handled automatically by webpack as needed), but in any other runtime\n // we need the ability to preload them\n output.lazyBundles.set(\n id,\n flatMap(\n chunks.filter(chunk => chunk.runtime?.includes(id)),\n chunk => chunk.files\n ).filter(file => !entrypointAssets?.find(a => a.name === file)) as string[]\n );\n }\n }\n }\n\n private runWebpack(webpack: webpack.MultiCompiler): Promise<webpack.MultiStats> {\n return new Promise((resolve, reject) => {\n webpack.run((err, stats) => {\n try {\n if (err) {\n if (stats) {\n this.consoleWrite(stats.toString());\n }\n throw err;\n }\n if (!stats) {\n // this doesn't really happen, but webpack's types imply that it\n // could, so we just satisfy typescript here\n throw new Error('bug: no stats and no err');\n }\n if (stats.hasErrors()) {\n // write all the stats output to the console\n this.consoleWrite(\n stats.toString({\n colors: Boolean(supportsColor.stdout),\n })\n );\n\n // the typing for MultiCompiler are all foobared.\n throw this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors));\n }\n if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) {\n this.consoleWrite(\n stats.toString({\n colors: Boolean(supportsColor.stdout),\n })\n );\n }\n resolve(stats);\n } catch (e) {\n reject(e);\n }\n });\n });\n }\n\n private setupStyleConfig(variant: Variant): {\n loaders: RuleSetUseItem[];\n plugins: WebpackPluginInstance[];\n } {\n let cssLoader = {\n loader: 'css-loader',\n options: {\n url: true,\n import: true,\n modules: 'global',\n ...this.extraCssLoaderOptions,\n },\n };\n\n if (!variant.optimizeForProduction && variant.runtime === 'browser') {\n // in development builds that only need to work in the browser (not\n // fastboot), we can use style-loader because it's fast\n return {\n loaders: [\n { loader: 'style-loader', options: { injectType: 'styleTag', ...this.extraStyleLoaderOptions } },\n cssLoader,\n ],\n plugins: [],\n };\n } else {\n // in any other build, we separate the CSS into its own bundles\n return {\n loaders: [MiniCssExtractPlugin.loader, cssLoader],\n plugins: [\n new MiniCssExtractPlugin({\n filename: `assets/chunk.[chunkhash].css`,\n chunkFilename: `assets/chunk.[chunkhash].css`,\n // in the browser, MiniCssExtractPlugin can manage it's own runtime\n // lazy loading of stylesheets.\n //\n // but in fastboot, we need to disable that in favor of doing our\n // own insertion of `<link>` tags in the HTML\n runtime: variant.runtime === 'browser',\n // It's not reasonable to make assumptions about order when doing CSS via modules\n ignoreOrder: true,\n }),\n ],\n };\n }\n }\n\n private findBestError(errors: any[]) {\n let error = errors[0];\n let file;\n if (error.module?.userRequest) {\n file = relative(this.pathToVanillaApp, error.module.userRequest);\n }\n\n if (!error.file) {\n error.file = file || (error.loc ? error.loc.file : null) || (error.location ? error.location.file : null);\n }\n if (error.line == null) {\n error.line = (error.loc ? error.loc.line : null) || (error.location ? error.location.line : null);\n }\n if (typeof error.message === 'string') {\n if (error.module?.context) {\n error.message = error.message.replace(error.module.context, error.module.userRequest);\n }\n\n // the tmpdir on OSX is horribly long and makes error messages hard to\n // read. This is doing the same as String.prototype.replaceAll, which node\n // doesn't have yet.\n error.message = error.message.split(tmpdir).join('$TMPDIR');\n }\n return error;\n }\n};\n\nconst threadLoaderOptions = {\n workers: 'JOBS' in process.env && Number(process.env.JOBS),\n // poolTimeout shuts down idle workers. The problem is, for\n // interactive rebuilds that means your startup cost for the\n // next rebuild is at least 600ms worse. So we insist on\n // keeping workers alive always.\n poolTimeout: Infinity,\n};\n\nfunction canUseThreadLoader(extraOptions: object | false | undefined) {\n // If the environment sets JOBS to 0, or if our extraOptions are set to false,\n // we have been explicitly configured not to use thread-loader\n if (process.env.JOBS === '0' || extraOptions === false) {\n return false;\n } else {\n return true;\n }\n}\n\nfunction warmUp(extraOptions: object | false | undefined) {\n // We don't know if we'll be parallel-safe or not, but if we've been\n // configured to not use thread-loader, then there is no need to consume extra\n // resources warming the worker pool\n if (!canUseThreadLoader(extraOptions)) {\n return null;\n }\n\n threadLoaderWarmup(Object.assign({}, threadLoaderOptions, extraOptions), [\n require.resolve('@embroider/hbs-loader'),\n require.resolve('@embroider/babel-loader-9'),\n ]);\n}\n\nfunction maybeThreadLoader(extraOptions: object | false | undefined) {\n if (!canUseThreadLoader(extraOptions)) {\n return null;\n }\n\n return {\n loader: 'thread-loader',\n options: Object.assign({}, threadLoaderOptions, extraOptions),\n };\n}\n\nfunction appendArrays(objValue: any, srcValue: any) {\n if (Array.isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n}\n\nfunction isCSS(filename: string) {\n return /\\.css$/i.test(filename);\n}\n\n// typescript doesn't understand that regular use of array.filter(Boolean) does\n// this.\nfunction nonNullArray<T>(array: T[]): NonNullable<T>[] {\n return array.filter(Boolean) as NonNullable<T>[];\n}\n\nfunction makeBabelLoaderOptions(\n variant: Variant,\n appBabelConfigPath: string,\n extraOptions: BabelLoaderOptions | undefined\n) {\n const cacheDirectory = getPackagerCacheDir('webpack-babel-loader');\n const options: BabelLoaderOptions & { variant: Variant; appBabelConfigPath: string } = {\n variant,\n appBabelConfigPath,\n cacheDirectory,\n ...extraOptions,\n };\n return {\n loader: 'babel-loader-9',\n options,\n };\n}\n\nexport { Webpack };\n"]}
|
package/src/virtual-loader.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import type { LoaderContext } from 'webpack';
|
2
|
-
export default function virtualLoader(this: LoaderContext<unknown>): string;
|
2
|
+
export default function virtualLoader(this: LoaderContext<unknown>): string | undefined;
|
package/src/virtual-loader.js
CHANGED
@@ -19,7 +19,9 @@ function virtualLoader() {
|
|
19
19
|
}
|
20
20
|
let { resolver } = setup(appRoot);
|
21
21
|
this.resourcePath = filename;
|
22
|
-
|
22
|
+
// @ts-expect-error unimplemented
|
23
|
+
let virtual = fixmeImplementVirtualResponse();
|
24
|
+
return (0, core_1.virtualContent)(virtual, resolver).src;
|
23
25
|
}
|
24
26
|
throw new Error(`@embroider/webpack/src/virtual-loader received unexpected request: ${this.query}`);
|
25
27
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"virtual-loader.js","sourceRoot":"","sources":["virtual-loader.ts"],"names":[],"mappings":";;AAYA,
|
1
|
+
{"version":3,"file":"virtual-loader.js","sourceRoot":"","sources":["virtual-loader.ts"],"names":[],"mappings":";;AAYA,gCAeC;AA3BD,0CAAuF;AAGvF,IAAI,cAA0C,CAAC;AAE/C,SAAS,KAAK,CAAC,OAAe;IAC5B,IAAI,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,OAAO,MAAK,OAAO,EAAE,CAAC;QACxC,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAwB,aAAa;IACnC,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QAC5D,IAAI,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,qEAAqE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACrG,CAAC;QACD,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,iCAAiC;QACjC,IAAI,OAAO,GAAoB,6BAA6B,EAAE,CAAC;QAC/D,OAAO,IAAA,qBAAc,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC;IAC/C,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sEAAsE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AACtG,CAAC","sourcesContent":["import { ResolverLoader, virtualContent, type VirtualResponse } from '@embroider/core';\nimport type { LoaderContext } from 'webpack';\n\nlet resolverLoader: ResolverLoader | undefined;\n\nfunction setup(appRoot: string): ResolverLoader {\n if (resolverLoader?.appRoot !== appRoot) {\n resolverLoader = new ResolverLoader(appRoot);\n }\n return resolverLoader;\n}\n\nexport default function virtualLoader(this: LoaderContext<unknown>): string | undefined {\n if (typeof this.query === 'string' && this.query[0] === '?') {\n let params = new URLSearchParams(this.query);\n let filename = params.get('f');\n let appRoot = params.get('a');\n if (!filename || !appRoot) {\n throw new Error(`bug in @embroider/webpack virtual loader, cannot locate params in ${this.query}`);\n }\n let { resolver } = setup(appRoot);\n this.resourcePath = filename;\n // @ts-expect-error unimplemented\n let virtual: VirtualResponse = fixmeImplementVirtualResponse();\n return virtualContent(virtual, resolver).src;\n }\n throw new Error(`@embroider/webpack/src/virtual-loader received unexpected request: ${this.query}`);\n}\n"]}
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.EmbroiderPlugin = void 0;
|
19
19
|
const path_1 = require("path");
|
20
20
|
const core_1 = require("@embroider/core");
|
21
|
+
const core_2 = require("@embroider/core");
|
21
22
|
const assert_never_1 = __importDefault(require("assert-never"));
|
22
23
|
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
23
24
|
const virtualLoaderName = '@embroider/webpack/src/virtual-loader';
|
@@ -29,7 +30,7 @@ class EmbroiderPlugin {
|
|
29
30
|
_EmbroiderPlugin_resolver.set(this, void 0);
|
30
31
|
_EmbroiderPlugin_babelLoaderPrefix.set(this, void 0);
|
31
32
|
_EmbroiderPlugin_appRoot.set(this, void 0);
|
32
|
-
__classPrivateFieldSet(this, _EmbroiderPlugin_resolver, new
|
33
|
+
__classPrivateFieldSet(this, _EmbroiderPlugin_resolver, new core_2.Resolver(opts), "f");
|
33
34
|
__classPrivateFieldSet(this, _EmbroiderPlugin_babelLoaderPrefix, babelLoaderPrefix, "f");
|
34
35
|
__classPrivateFieldSet(this, _EmbroiderPlugin_appRoot, opts.appRoot, "f");
|
35
36
|
}
|
@@ -37,20 +38,24 @@ class EmbroiderPlugin {
|
|
37
38
|
__classPrivateFieldGet(this, _EmbroiderPlugin_instances, "m", _EmbroiderPlugin_addLoaderAlias).call(this, compiler, virtualLoaderName, virtualLoaderPath);
|
38
39
|
compiler.hooks.normalModuleFactory.tap('@embroider/webpack', nmf => {
|
39
40
|
let defaultResolve = getDefaultResolveHook(nmf.hooks.resolve.taps);
|
40
|
-
let adaptedResolve = getAdaptedResolve(defaultResolve);
|
41
41
|
nmf.hooks.resolve.tapAsync({ name: '@embroider/webpack', stage: 50 }, (state, callback) => {
|
42
|
-
let request =
|
42
|
+
let request = core_1.ModuleRequest.create(WebpackRequestAdapter.create, {
|
43
|
+
resolveFunction: defaultResolve,
|
44
|
+
state,
|
45
|
+
babelLoaderPrefix: __classPrivateFieldGet(this, _EmbroiderPlugin_babelLoaderPrefix, "f"),
|
46
|
+
appRoot: __classPrivateFieldGet(this, _EmbroiderPlugin_appRoot, "f"),
|
47
|
+
});
|
43
48
|
if (!request) {
|
44
49
|
defaultResolve(state, callback);
|
45
50
|
return;
|
46
51
|
}
|
47
|
-
__classPrivateFieldGet(this, _EmbroiderPlugin_resolver, "f").resolve(request
|
52
|
+
__classPrivateFieldGet(this, _EmbroiderPlugin_resolver, "f").resolve(request).then(resolution => {
|
48
53
|
switch (resolution.type) {
|
49
54
|
case 'not_found':
|
50
55
|
callback(resolution.err);
|
51
56
|
break;
|
52
57
|
case 'found':
|
53
|
-
callback(null,
|
58
|
+
callback(null, undefined);
|
54
59
|
break;
|
55
60
|
default:
|
56
61
|
throw (0, assert_never_1.default)(resolution);
|
@@ -84,89 +89,123 @@ function getDefaultResolveHook(taps) {
|
|
84
89
|
let { fn } = taps.find(t => t.name === 'NormalModuleFactory');
|
85
90
|
return fn;
|
86
91
|
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
class WebpackModuleRequest {
|
106
|
-
static from(state, babelLoaderPrefix, appRoot) {
|
107
|
-
var _a, _b, _c;
|
108
|
-
// when the files emitted from our virtual-loader try to import things,
|
109
|
-
// those requests show in webpack as having no issuer. But we can see here
|
110
|
-
// which requests they are and adjust the issuer so they resolve things from
|
111
|
-
// the correct logical place.
|
112
|
-
if (!((_a = state.contextInfo) === null || _a === void 0 ? void 0 : _a.issuer) && Array.isArray(state.dependencies)) {
|
92
|
+
class WebpackRequestAdapter {
|
93
|
+
static create({ resolveFunction, state, babelLoaderPrefix, appRoot, }) {
|
94
|
+
var _a;
|
95
|
+
let specifier = state.request;
|
96
|
+
if (specifier.includes(virtualLoaderName) || // prevents recursion on requests we have already sent to our virtual loader
|
97
|
+
specifier.startsWith('!') // ignores internal webpack resolvers
|
98
|
+
) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
let fromFile;
|
102
|
+
if (state.contextInfo.issuer) {
|
103
|
+
fromFile = state.contextInfo.issuer;
|
104
|
+
}
|
105
|
+
else {
|
106
|
+
// when the files emitted from our virtual-loader try to import things,
|
107
|
+
// those requests show in webpack as having no issuer. But we can see here
|
108
|
+
// which requests they are and adjust the issuer so they resolve things from
|
109
|
+
// the correct logical place.
|
113
110
|
for (let dep of state.dependencies) {
|
114
|
-
let match = virtualRequestPattern.exec((
|
111
|
+
let match = virtualRequestPattern.exec((_a = dep._parentModule) === null || _a === void 0 ? void 0 : _a.userRequest);
|
115
112
|
if (match) {
|
116
|
-
|
117
|
-
|
113
|
+
fromFile = new URLSearchParams(match.groups.query).get('f');
|
114
|
+
break;
|
118
115
|
}
|
119
116
|
}
|
120
117
|
}
|
121
|
-
if (
|
122
|
-
|
123
|
-
typeof ((_c = state.contextInfo) === null || _c === void 0 ? void 0 : _c.issuer) === 'string' &&
|
124
|
-
state.contextInfo.issuer !== '' &&
|
125
|
-
!state.request.includes(virtualLoaderName) && // prevents recursion on requests we have already sent to our virtual loader
|
126
|
-
!state.request.startsWith('!') // ignores internal webpack resolvers
|
127
|
-
) {
|
128
|
-
return new WebpackModuleRequest(babelLoaderPrefix, appRoot, state);
|
118
|
+
if (!fromFile) {
|
119
|
+
return;
|
129
120
|
}
|
121
|
+
return {
|
122
|
+
initialState: {
|
123
|
+
specifier,
|
124
|
+
fromFile,
|
125
|
+
meta: state.contextInfo._embroiderMeta,
|
126
|
+
},
|
127
|
+
adapter: new WebpackRequestAdapter(resolveFunction, babelLoaderPrefix, appRoot, state),
|
128
|
+
};
|
130
129
|
}
|
131
|
-
constructor(babelLoaderPrefix, appRoot,
|
130
|
+
constructor(resolveFunction, babelLoaderPrefix, appRoot, originalState) {
|
131
|
+
this.resolveFunction = resolveFunction;
|
132
132
|
this.babelLoaderPrefix = babelLoaderPrefix;
|
133
133
|
this.appRoot = appRoot;
|
134
|
-
this.
|
135
|
-
this.isVirtual = isVirtual;
|
136
|
-
// these get copied here because we mutate the underlying state as we
|
137
|
-
// convert one request into the next, and it seems better for debuggability
|
138
|
-
// if the fields on the previous request don't change when you make a new
|
139
|
-
// one (although it is true that only the newest one has a a valid `state`
|
140
|
-
// that can actually be handed back to webpack)
|
141
|
-
this.specifier = state.request;
|
142
|
-
this.fromFile = state.contextInfo.issuer;
|
143
|
-
this.meta = state.contextInfo._embroiderMeta ? { ...state.contextInfo._embroiderMeta } : undefined;
|
134
|
+
this.originalState = originalState;
|
144
135
|
}
|
145
|
-
|
146
|
-
|
147
|
-
return new WebpackModuleRequest(this.babelLoaderPrefix, this.appRoot, this.state);
|
136
|
+
get debugType() {
|
137
|
+
return 'webpack';
|
148
138
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
139
|
+
// Webpack mostly relies on mutation to adjust requests. We could create a
|
140
|
+
// whole new ResolveData instead, and that would allow defaultResolving to
|
141
|
+
// happen, but for the output of that process to actually affect the
|
142
|
+
// downstream code in Webpack we would still need to mutate the original
|
143
|
+
// ResolveData with the results (primarily the `createData`). So since we
|
144
|
+
// cannot avoid the mutation anyway, it seems best to do it earlier rather
|
145
|
+
// than later, so that everything from here forward is "normal".
|
146
|
+
//
|
147
|
+
// Technically a NormalModuleLoader `resolve` hook *can* directly return a
|
148
|
+
// Module, but that is not how the stock one works, and it would force us to
|
149
|
+
// copy more of Webpack's default behaviors into the inside of our hook. Like,
|
150
|
+
// we would need to invoke afterResolve, createModule, createModuleClass, etc,
|
151
|
+
// just like webpack does if we wanted to produce a Module directly.
|
152
|
+
//
|
153
|
+
// So the mutation strategy is much less intrusive, even though it means there
|
154
|
+
// is the risk of state leakage all over the place.
|
155
|
+
//
|
156
|
+
// We mitigate that risk by waiting until the last possible moment to apply
|
157
|
+
// our desired ModuleRequest fields to the ResolveData. This means that as
|
158
|
+
// requests evolve through the module-resolver they aren't actually all
|
159
|
+
// mutating the shared state. Only when a request is allowed to bubble back
|
160
|
+
// out to webpack does that happen.
|
161
|
+
toWebpackResolveData(request, virtualFileName) {
|
162
|
+
let specifier = request.specifier;
|
163
|
+
if (virtualFileName) {
|
164
|
+
let params = new URLSearchParams();
|
165
|
+
params.set('f', virtualFileName);
|
166
|
+
params.set('a', this.appRoot);
|
167
|
+
specifier = `${this.babelLoaderPrefix}${virtualLoaderName}?${params.toString()}!`;
|
152
168
|
}
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
169
|
+
this.originalState.request = specifier;
|
170
|
+
this.originalState.context = (0, path_1.dirname)(request.fromFile);
|
171
|
+
this.originalState.contextInfo.issuer = request.fromFile;
|
172
|
+
this.originalState.contextInfo._embroiderMeta = request.meta;
|
173
|
+
if (request.resolvedTo && typeof request.resolvedTo !== 'function') {
|
174
|
+
if (request.resolvedTo.type === 'found') {
|
175
|
+
this.originalState.createData = request.resolvedTo.result;
|
176
|
+
}
|
157
177
|
}
|
178
|
+
return this.originalState;
|
158
179
|
}
|
159
|
-
|
160
|
-
let
|
161
|
-
|
162
|
-
|
163
|
-
let next = this.alias(`${this.babelLoaderPrefix}${virtualLoaderName}?${params.toString()}!`);
|
164
|
-
next.isVirtual = true;
|
165
|
-
return next;
|
180
|
+
notFoundResponse(request) {
|
181
|
+
let err = new Error(`module not found ${request.specifier}`);
|
182
|
+
err.code = 'MODULE_NOT_FOUND';
|
183
|
+
return { type: 'not_found', err };
|
166
184
|
}
|
167
|
-
|
168
|
-
|
169
|
-
|
185
|
+
virtualResponse(request, virtual) {
|
186
|
+
return () => {
|
187
|
+
return this._resolve(request, virtual);
|
188
|
+
};
|
189
|
+
}
|
190
|
+
async resolve(request) {
|
191
|
+
return this._resolve(request, false);
|
192
|
+
}
|
193
|
+
async _resolve(request, virtualResponse) {
|
194
|
+
return await new Promise(resolve => this.resolveFunction(this.toWebpackResolveData(request, virtualResponse ? virtualResponse.specifier : request.specifier), err => {
|
195
|
+
if (err) {
|
196
|
+
// unfortunately webpack doesn't let us distinguish between Not Found
|
197
|
+
// and other unexpected exceptions here.
|
198
|
+
resolve({ type: 'not_found', err });
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
resolve({
|
202
|
+
type: 'found',
|
203
|
+
result: this.originalState.createData,
|
204
|
+
virtual: virtualResponse,
|
205
|
+
filename: this.originalState.createData.resource,
|
206
|
+
});
|
207
|
+
}
|
208
|
+
}));
|
170
209
|
}
|
171
210
|
}
|
172
211
|
//# sourceMappingURL=webpack-resolver-plugin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"webpack-resolver-plugin.js","sourceRoot":"","sources":["webpack-resolver-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAwC;AAExC,0CAA6G;AAE7G,gEAAuC;AACvC,gFAAgD;AAIhD,MAAM,iBAAiB,GAAG,uCAAuC,CAAC;AAClE,MAAM,iBAAiB,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACpE,MAAM,qBAAqB,GAAG,IAAI,MAAM,CAAC,GAAG,IAAA,8BAAY,EAAC,iBAAiB,CAAC,kBAAkB,CA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B,IAAI,IAAI,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC;YAC5C,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAA,cAAO,EAAC,WAAW,CAAC,CAAC;YAC1C,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAS,CAAC;QAC5F,CAAC;IACH,CAAC;IACD,UAAU,CAAC,QAAgB;QACzB,IAAI,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC7F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,QAAQ,CAAC,IAAqC;QAC5C,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7C,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAS,CAAC;IAC5F,CAAC;CACF","sourcesContent":["import { dirname, resolve } from 'path';\nimport type { ModuleRequest, ResolverFunction, Resolution } from '@embroider/core';\nimport { Resolver as EmbroiderResolver, ResolverOptions as EmbroiderResolverOptions } from '@embroider/core';\nimport type { Compiler, Module } from 'webpack';\nimport assertNever from 'assert-never';\nimport escapeRegExp from 'escape-string-regexp';\n\nexport { EmbroiderResolverOptions as Options };\n\nconst virtualLoaderName = '@embroider/webpack/src/virtual-loader';\nconst virtualLoaderPath = resolve(__dirname, './virtual-loader.js');\nconst virtualRequestPattern = new RegExp(`${escapeRegExp(virtualLoaderPath)}\\\\?(?<query>.+)!`);\n\nexport class EmbroiderPlugin {\n #resolver: EmbroiderResolver;\n #babelLoaderPrefix: string;\n #appRoot: string;\n\n constructor(opts: EmbroiderResolverOptions, babelLoaderPrefix: string) {\n this.#resolver = new EmbroiderResolver(opts);\n this.#babelLoaderPrefix = babelLoaderPrefix;\n this.#appRoot = opts.appRoot;\n }\n\n #addLoaderAlias(compiler: Compiler, name: string, alias: string) {\n let { resolveLoader } = compiler.options;\n if (Array.isArray(resolveLoader.alias)) {\n resolveLoader.alias.push({ name, alias });\n } else if (resolveLoader.alias) {\n resolveLoader.alias[name] = alias;\n } else {\n resolveLoader.alias = {\n [name]: alias,\n };\n }\n }\n\n apply(compiler: Compiler) {\n this.#addLoaderAlias(compiler, virtualLoaderName, virtualLoaderPath);\n\n compiler.hooks.normalModuleFactory.tap('@embroider/webpack', nmf => {\n let defaultResolve = getDefaultResolveHook(nmf.hooks.resolve.taps);\n let adaptedResolve = getAdaptedResolve(defaultResolve);\n\n nmf.hooks.resolve.tapAsync({ name: '@embroider/webpack', stage: 50 }, (state: unknown, callback: CB) => {\n let request = WebpackModuleRequest.from(state, this.#babelLoaderPrefix, this.#appRoot);\n if (!request) {\n defaultResolve(state, callback);\n return;\n }\n\n this.#resolver.resolve(request, adaptedResolve).then(\n resolution => {\n switch (resolution.type) {\n case 'not_found':\n callback(resolution.err);\n break;\n case 'found':\n callback(null, resolution.result);\n break;\n default:\n throw assertNever(resolution);\n }\n },\n err => callback(err)\n );\n });\n });\n }\n}\n\ntype CB = (err: null | Error, result?: Module | undefined) => void;\ntype DefaultResolve = (state: unknown, callback: CB) => void;\n\n// Despite being absolutely riddled with way-too-powerful tap points,\n// webpack still doesn't succeed in making it possible to provide a\n// fallback to the default resolve hook in the NormalModuleFactory. So\n// instead we will find the default behavior and call it from our own tap,\n// giving us a chance to handle its failures.\nfunction getDefaultResolveHook(taps: { name: string; fn: Function }[]): DefaultResolve {\n let { fn } = taps.find(t => t.name === 'NormalModuleFactory')!;\n return fn as DefaultResolve;\n}\n\n// This converts the raw function we got out of webpack into the right interface\n// for use by @embroider/core's resolver.\nfunction getAdaptedResolve(\n defaultResolve: DefaultResolve\n): ResolverFunction<WebpackModuleRequest, Resolution<Module, null | Error>> {\n return function (request: WebpackModuleRequest): Promise<Resolution<Module, null | Error>> {\n return new Promise(resolve => {\n defaultResolve(request.state, (err, value) => {\n if (err) {\n // unfortunately webpack doesn't let us distinguish between Not Found\n // and other unexpected exceptions here.\n resolve({ type: 'not_found', err });\n } else {\n resolve({ type: 'found', result: value! });\n }\n });\n });\n };\n}\n\nclass WebpackModuleRequest implements ModuleRequest {\n readonly specifier: string;\n readonly fromFile: string;\n readonly meta: Record<string, any> | undefined;\n\n static from(state: any, babelLoaderPrefix: string, appRoot: string): WebpackModuleRequest | undefined {\n // when the files emitted from our virtual-loader try to import things,\n // those requests show in webpack as having no issuer. But we can see here\n // which requests they are and adjust the issuer so they resolve things from\n // the correct logical place.\n if (!state.contextInfo?.issuer && Array.isArray(state.dependencies)) {\n for (let dep of state.dependencies) {\n let match = virtualRequestPattern.exec(dep._parentModule?.userRequest);\n if (match) {\n state.contextInfo.issuer = new URLSearchParams(match.groups!.query).get('f');\n state.context = dirname(state.contextInfo.issuer);\n }\n }\n }\n\n if (\n typeof state.request === 'string' &&\n typeof state.context === 'string' &&\n typeof state.contextInfo?.issuer === 'string' &&\n state.contextInfo.issuer !== '' &&\n !state.request.includes(virtualLoaderName) && // prevents recursion on requests we have already sent to our virtual loader\n !state.request.startsWith('!') // ignores internal webpack resolvers\n ) {\n return new WebpackModuleRequest(babelLoaderPrefix, appRoot, state);\n }\n }\n\n constructor(\n private babelLoaderPrefix: string,\n private appRoot: string,\n public state: {\n request: string;\n context: string;\n contextInfo: {\n issuer: string;\n _embroiderMeta?: Record<string, any> | undefined;\n };\n },\n public isVirtual = false\n ) {\n // these get copied here because we mutate the underlying state as we\n // convert one request into the next, and it seems better for debuggability\n // if the fields on the previous request don't change when you make a new\n // one (although it is true that only the newest one has a a valid `state`\n // that can actually be handed back to webpack)\n this.specifier = state.request;\n this.fromFile = state.contextInfo.issuer;\n this.meta = state.contextInfo._embroiderMeta ? { ...state.contextInfo._embroiderMeta } : undefined;\n }\n\n alias(newSpecifier: string) {\n this.state.request = newSpecifier;\n return new WebpackModuleRequest(this.babelLoaderPrefix, this.appRoot, this.state) as this;\n }\n rehome(newFromFile: string) {\n if (this.fromFile === newFromFile) {\n return this;\n } else {\n this.state.contextInfo.issuer = newFromFile;\n this.state.context = dirname(newFromFile);\n return new WebpackModuleRequest(this.babelLoaderPrefix, this.appRoot, this.state) as this;\n }\n }\n virtualize(filename: string) {\n let params = new URLSearchParams();\n params.set('f', filename);\n params.set('a', this.appRoot);\n let next = this.alias(`${this.babelLoaderPrefix}${virtualLoaderName}?${params.toString()}!`);\n next.isVirtual = true;\n return next;\n }\n withMeta(meta: Record<string, any> | undefined): this {\n this.state.contextInfo._embroiderMeta = meta;\n return new WebpackModuleRequest(this.babelLoaderPrefix, this.appRoot, this.state) as this;\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"webpack-resolver-plugin.js","sourceRoot":"","sources":["webpack-resolver-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAwC;AACxC,0CAA4G;AAC5G,0CAA6G;AAE7G,gEAAuC;AACvC,gFAAgD;AAIhD,MAAM,iBAAiB,GAAG,uCAAuC,CAAC;AAClE,MAAM,iBAAiB,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACpE,MAAM,qBAAqB,GAAG,IAAI,MAAM,CAAC,GAAG,IAAA,8BAAY,EAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAE/F,MAAa,e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BACrC,OAAO,EAAE,eAAe;oBACxB,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAS;iBAClD,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CACF,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { dirname, resolve } from 'path';\nimport { ModuleRequest, type VirtualResponse, type RequestAdapter, type Resolution } from '@embroider/core';\nimport { Resolver as EmbroiderResolver, ResolverOptions as EmbroiderResolverOptions } from '@embroider/core';\nimport type { Compiler, Module, ResolveData } from 'webpack';\nimport assertNever from 'assert-never';\nimport escapeRegExp from 'escape-string-regexp';\n\nexport { EmbroiderResolverOptions as Options };\n\nconst virtualLoaderName = '@embroider/webpack/src/virtual-loader';\nconst virtualLoaderPath = resolve(__dirname, './virtual-loader.js');\nconst virtualRequestPattern = new RegExp(`${escapeRegExp(virtualLoaderPath)}\\\\?(?<query>.+)!`);\n\nexport class EmbroiderPlugin {\n #resolver: EmbroiderResolver;\n #babelLoaderPrefix: string;\n #appRoot: string;\n\n constructor(opts: EmbroiderResolverOptions, babelLoaderPrefix: string) {\n this.#resolver = new EmbroiderResolver(opts);\n this.#babelLoaderPrefix = babelLoaderPrefix;\n this.#appRoot = opts.appRoot;\n }\n\n #addLoaderAlias(compiler: Compiler, name: string, alias: string) {\n let { resolveLoader } = compiler.options;\n if (Array.isArray(resolveLoader.alias)) {\n resolveLoader.alias.push({ name, alias });\n } else if (resolveLoader.alias) {\n resolveLoader.alias[name] = alias;\n } else {\n resolveLoader.alias = {\n [name]: alias,\n };\n }\n }\n\n apply(compiler: Compiler) {\n this.#addLoaderAlias(compiler, virtualLoaderName, virtualLoaderPath);\n\n compiler.hooks.normalModuleFactory.tap('@embroider/webpack', nmf => {\n let defaultResolve = getDefaultResolveHook(nmf.hooks.resolve.taps);\n\n nmf.hooks.resolve.tapAsync(\n { name: '@embroider/webpack', stage: 50 },\n (state: ExtendedResolveData, callback: CB) => {\n let request = ModuleRequest.create(WebpackRequestAdapter.create, {\n resolveFunction: defaultResolve,\n state,\n babelLoaderPrefix: this.#babelLoaderPrefix,\n appRoot: this.#appRoot,\n });\n if (!request) {\n defaultResolve(state, callback);\n return;\n }\n\n this.#resolver.resolve(request).then(\n resolution => {\n switch (resolution.type) {\n case 'not_found':\n callback(resolution.err);\n break;\n case 'found':\n callback(null, undefined);\n break;\n default:\n throw assertNever(resolution);\n }\n },\n err => callback(err)\n );\n }\n );\n });\n }\n}\n\ninterface CB {\n (err: null, result: Module | undefined): void;\n (err: Error | null): void;\n}\ntype DefaultResolve = (state: ResolveData, callback: CB) => void;\n\n// Despite being absolutely riddled with way-too-powerful tap points,\n// webpack still doesn't succeed in making it possible to provide a\n// fallback to the default resolve hook in the NormalModuleFactory. So\n// instead we will find the default behavior and call it from our own tap,\n// giving us a chance to handle its failures.\nfunction getDefaultResolveHook(taps: { name: string; fn: Function }[]): DefaultResolve {\n let { fn } = taps.find(t => t.name === 'NormalModuleFactory')!;\n return fn as DefaultResolve;\n}\n\ntype ExtendedResolveData = ResolveData & {\n contextInfo: ResolveData['contextInfo'] & { _embroiderMeta?: Record<string, any> };\n};\n\ntype WebpackResolution = Resolution<ResolveData['createData'], null | Error>;\n\nclass WebpackRequestAdapter implements RequestAdapter<WebpackResolution> {\n static create({\n resolveFunction,\n state,\n babelLoaderPrefix,\n appRoot,\n }: {\n resolveFunction: DefaultResolve;\n state: ExtendedResolveData;\n babelLoaderPrefix: string;\n appRoot: string;\n }) {\n let specifier = state.request;\n if (\n specifier.includes(virtualLoaderName) || // prevents recursion on requests we have already sent to our virtual loader\n specifier.startsWith('!') // ignores internal webpack resolvers\n ) {\n return;\n }\n\n let fromFile: string | undefined;\n if (state.contextInfo.issuer) {\n fromFile = state.contextInfo.issuer;\n } else {\n // when the files emitted from our virtual-loader try to import things,\n // those requests show in webpack as having no issuer. But we can see here\n // which requests they are and adjust the issuer so they resolve things from\n // the correct logical place.\n for (let dep of state.dependencies) {\n let match = virtualRequestPattern.exec((dep as any)._parentModule?.userRequest);\n if (match) {\n fromFile = new URLSearchParams(match.groups!.query).get('f')!;\n break;\n }\n }\n }\n if (!fromFile) {\n return;\n }\n\n return {\n initialState: {\n specifier,\n fromFile,\n meta: state.contextInfo._embroiderMeta,\n },\n adapter: new WebpackRequestAdapter(resolveFunction, babelLoaderPrefix, appRoot, state),\n };\n }\n\n private constructor(\n private resolveFunction: DefaultResolve,\n private babelLoaderPrefix: string,\n private appRoot: string,\n private originalState: ExtendedResolveData\n ) {}\n\n get debugType() {\n return 'webpack';\n }\n\n // Webpack mostly relies on mutation to adjust requests. We could create a\n // whole new ResolveData instead, and that would allow defaultResolving to\n // happen, but for the output of that process to actually affect the\n // downstream code in Webpack we would still need to mutate the original\n // ResolveData with the results (primarily the `createData`). So since we\n // cannot avoid the mutation anyway, it seems best to do it earlier rather\n // than later, so that everything from here forward is \"normal\".\n //\n // Technically a NormalModuleLoader `resolve` hook *can* directly return a\n // Module, but that is not how the stock one works, and it would force us to\n // copy more of Webpack's default behaviors into the inside of our hook. Like,\n // we would need to invoke afterResolve, createModule, createModuleClass, etc,\n // just like webpack does if we wanted to produce a Module directly.\n //\n // So the mutation strategy is much less intrusive, even though it means there\n // is the risk of state leakage all over the place.\n //\n // We mitigate that risk by waiting until the last possible moment to apply\n // our desired ModuleRequest fields to the ResolveData. This means that as\n // requests evolve through the module-resolver they aren't actually all\n // mutating the shared state. Only when a request is allowed to bubble back\n // out to webpack does that happen.\n toWebpackResolveData(\n request: ModuleRequest<WebpackResolution>,\n virtualFileName: string | undefined\n ): ExtendedResolveData {\n let specifier = request.specifier;\n if (virtualFileName) {\n let params = new URLSearchParams();\n params.set('f', virtualFileName);\n params.set('a', this.appRoot);\n specifier = `${this.babelLoaderPrefix}${virtualLoaderName}?${params.toString()}!`;\n }\n\n this.originalState.request = specifier;\n this.originalState.context = dirname(request.fromFile);\n this.originalState.contextInfo.issuer = request.fromFile;\n this.originalState.contextInfo._embroiderMeta = request.meta;\n if (request.resolvedTo && typeof request.resolvedTo !== 'function') {\n if (request.resolvedTo.type === 'found') {\n this.originalState.createData = request.resolvedTo.result;\n }\n }\n return this.originalState;\n }\n\n notFoundResponse(request: ModuleRequest<WebpackResolution>): WebpackResolution {\n let err = new Error(`module not found ${request.specifier}`);\n (err as any).code = 'MODULE_NOT_FOUND';\n return { type: 'not_found', err };\n }\n\n virtualResponse(\n request: ModuleRequest<WebpackResolution>,\n virtual: VirtualResponse\n ): () => Promise<WebpackResolution> {\n return () => {\n return this._resolve(request, virtual);\n };\n }\n\n async resolve(request: ModuleRequest<WebpackResolution>): Promise<WebpackResolution> {\n return this._resolve(request, false);\n }\n\n async _resolve(\n request: ModuleRequest<WebpackResolution>,\n virtualResponse: VirtualResponse | false\n ): Promise<WebpackResolution> {\n return await new Promise(resolve =>\n this.resolveFunction(\n this.toWebpackResolveData(request, virtualResponse ? virtualResponse.specifier : request.specifier),\n err => {\n if (err) {\n // unfortunately webpack doesn't let us distinguish between Not Found\n // and other unexpected exceptions here.\n resolve({ type: 'not_found', err });\n } else {\n resolve({\n type: 'found',\n result: this.originalState.createData,\n virtual: virtualResponse,\n filename: this.originalState.createData.resource!,\n });\n }\n }\n )\n );\n }\n}\n"]}
|