@embroider/core 2.1.1 → 2.1.2-unstable.16dc72c
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 +10 -8
- package/src/app-differ.d.ts +1 -1
- package/src/app-differ.js +21 -22
- package/src/app-differ.js.map +1 -1
- package/src/app-files.d.ts +1 -2
- package/src/app-files.js +0 -7
- package/src/app-files.js.map +1 -1
- package/src/app.d.ts +10 -8
- package/src/app.js +37 -47
- package/src/app.js.map +1 -1
- package/src/asset.d.ts +1 -1
- package/src/describe-exports.d.ts +0 -1
- package/src/describe-exports.js +8 -9
- package/src/describe-exports.js.map +1 -1
- package/src/index.d.ts +3 -0
- package/src/index.js +10 -2
- package/src/index.js.map +1 -1
- package/src/measure-concat.js +2 -5
- package/src/measure-concat.js.map +1 -1
- package/src/messages.d.ts +0 -1
- package/src/module-resolver.d.ts +66 -25
- package/src/module-resolver.js +703 -131
- package/src/module-resolver.js.map +1 -1
- package/src/multi-tree-diff.d.ts +1 -1
- package/src/options.d.ts +0 -1
- package/src/options.js.map +1 -1
- package/src/portable-babel-config.d.ts +1 -1
- package/src/virtual-content.d.ts +9 -0
- package/src/virtual-content.js +131 -0
- package/src/virtual-content.js.map +1 -0
- package/src/wait-for-trees.d.ts +1 -1
- package/src/wait-for-trees.js.map +1 -1
- package/src/babel-plugin-adjust-imports.d.ts +0 -31
- package/src/babel-plugin-adjust-imports.js +0 -224
- package/src/babel-plugin-adjust-imports.js.map +0 -1
- package/src/babel-plugin-inline-hbs-deps-node.d.ts +0 -14
- package/src/babel-plugin-inline-hbs-deps-node.js +0 -27
- package/src/babel-plugin-inline-hbs-deps-node.js.map +0 -1
- package/src/babel-plugin-inline-hbs-deps.d.ts +0 -10
- package/src/babel-plugin-inline-hbs-deps.js +0 -134
- package/src/babel-plugin-inline-hbs-deps.js.map +0 -1
- package/src/babel-plugin-inline-hbs-node.d.ts +0 -7
- package/src/babel-plugin-inline-hbs-node.js +0 -15
- package/src/babel-plugin-inline-hbs-node.js.map +0 -1
- package/src/babel-plugin-inline-hbs.d.ts +0 -24
- package/src/babel-plugin-inline-hbs.js +0 -142
- package/src/babel-plugin-inline-hbs.js.map +0 -1
- package/src/babel-plugin-stage1-inline-hbs-node.d.ts +0 -12
- package/src/babel-plugin-stage1-inline-hbs-node.js +0 -9
- package/src/babel-plugin-stage1-inline-hbs-node.js.map +0 -1
- package/src/babel-plugin-stage1-inline-hbs.d.ts +0 -9
- package/src/babel-plugin-stage1-inline-hbs.js +0 -96
- package/src/babel-plugin-stage1-inline-hbs.js.map +0 -1
- package/src/browser-index.d.ts +0 -1
- package/src/browser-index.js +0 -6
- package/src/browser-index.js.map +0 -1
- package/src/ember-template-compiler-types.d.ts +0 -41
- package/src/ember-template-compiler-types.js +0 -3
- package/src/ember-template-compiler-types.js.map +0 -1
- package/src/load-ember-template-compiler.d.ts +0 -6
- package/src/load-ember-template-compiler.js +0 -57
- package/src/load-ember-template-compiler.js.map +0 -1
- package/src/mini-modules-polyfill.d.ts +0 -12
- package/src/mini-modules-polyfill.js +0 -80
- package/src/mini-modules-polyfill.js.map +0 -1
- package/src/patch-template-compiler.d.ts +0 -1
- package/src/patch-template-compiler.js +0 -176
- package/src/patch-template-compiler.js.map +0 -1
- package/src/resolver-plugin.d.ts +0 -3
- package/src/resolver-plugin.js +0 -53
- package/src/resolver-plugin.js.map +0 -1
- package/src/resolver.d.ts +0 -14
- package/src/resolver.js +0 -3
- package/src/resolver.js.map +0 -1
- package/src/template-compiler-common.d.ts +0 -70
- package/src/template-compiler-common.js +0 -176
- package/src/template-compiler-common.js.map +0 -1
- package/src/template-compiler-node.d.ts +0 -17
- package/src/template-compiler-node.js +0 -32
- package/src/template-compiler-node.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2-unstable.16dc72c",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A build system for EmberJS applications.",
|
|
6
6
|
"repository": {
|
|
@@ -26,10 +26,9 @@
|
|
|
26
26
|
"@babel/plugin-transform-runtime": "^7.14.5",
|
|
27
27
|
"@babel/runtime": "^7.14.5",
|
|
28
28
|
"@babel/traverse": "^7.14.5",
|
|
29
|
-
"@embroider/macros": "1.10.
|
|
30
|
-
"@embroider/shared-internals": "2.0.
|
|
29
|
+
"@embroider/macros": "1.10.1-unstable.16dc72c",
|
|
30
|
+
"@embroider/shared-internals": "2.0.1-unstable.16dc72c",
|
|
31
31
|
"assert-never": "^1.2.1",
|
|
32
|
-
"babel-import-util": "^1.1.0",
|
|
33
32
|
"babel-plugin-ember-template-compilation": "^2.0.0",
|
|
34
33
|
"broccoli-node-api": "^1.7.0",
|
|
35
34
|
"broccoli-persistent-filter": "^3.1.2",
|
|
@@ -51,20 +50,23 @@
|
|
|
51
50
|
"walk-sync": "^3.0.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
|
-
"@embroider/sample-transforms": "
|
|
55
|
-
"@embroider/test-support": "
|
|
53
|
+
"@embroider/sample-transforms": "workspace:*",
|
|
54
|
+
"@embroider/test-support": "workspace:*",
|
|
56
55
|
"@glimmer/syntax": "^0.84.2",
|
|
56
|
+
"@glint/template": "^1.0.0",
|
|
57
57
|
"@types/babel__core": "^7.1.14",
|
|
58
|
+
"@types/babel__traverse": "^7.18.5",
|
|
58
59
|
"@types/debug": "^4.1.5",
|
|
59
|
-
"@types/
|
|
60
|
+
"@types/fs-extra": "^9.0.12",
|
|
60
61
|
"@types/jsdom": "^16.2.11",
|
|
62
|
+
"@types/js-string-escape": "^1.0.0",
|
|
61
63
|
"@types/lodash": "^4.14.170",
|
|
62
64
|
"@types/node": "^15.12.2",
|
|
63
65
|
"@types/resolve": "^1.20.0",
|
|
64
66
|
"@types/tmp": "^0.1.0",
|
|
65
67
|
"fixturify": "^2.1.1",
|
|
66
68
|
"tmp": "^0.1.0",
|
|
67
|
-
"typescript": "
|
|
69
|
+
"typescript": "^4.9.0"
|
|
68
70
|
},
|
|
69
71
|
"engines": {
|
|
70
72
|
"node": "12.* || 14.* || >= 16"
|
package/src/app-differ.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export default class AppDiffer {
|
|
|
6
6
|
private differ;
|
|
7
7
|
private sources;
|
|
8
8
|
private firstFastbootTree;
|
|
9
|
-
readonly files:
|
|
9
|
+
readonly files: Set<string>;
|
|
10
10
|
isFastbootOnly: Map<string, boolean>;
|
|
11
11
|
constructor(outputPath: string, ownAppJSDir: string, activeAddonDescendants: AddonPackage[], fastbootEnabled?: boolean, ownFastbootJSDir?: string | undefined, babelParserConfig?: TransformOptions | undefined);
|
|
12
12
|
update(): void;
|
package/src/app-differ.js
CHANGED
|
@@ -21,13 +21,8 @@ class AppDiffer {
|
|
|
21
21
|
this.outputPath = outputPath;
|
|
22
22
|
this.babelParserConfig = babelParserConfig;
|
|
23
23
|
this.firstFastbootTree = Infinity;
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
// resolution semantics so that each of the app files can still resolve
|
|
27
|
-
// relative to where it was authored.
|
|
28
|
-
//
|
|
29
|
-
// files authored within the app map to null
|
|
30
|
-
this.files = new Map();
|
|
24
|
+
// set of filenames logically located in the app
|
|
25
|
+
this.files = new Set();
|
|
31
26
|
// true for files that are fastboot-only.
|
|
32
27
|
this.isFastbootOnly = new Map();
|
|
33
28
|
this.sources = activeAddonDescendants.map(addon => maybeSource(addon, 'app-js')).filter(Boolean);
|
|
@@ -96,8 +91,10 @@ class AppDiffer {
|
|
|
96
91
|
this.isFastbootOnly.set(relativePath, sourceIndices[0] >= this.firstFastbootTree);
|
|
97
92
|
let source = this.sources[sourceIndices[0]];
|
|
98
93
|
let sourceFile = source.locate(relativePath);
|
|
99
|
-
(
|
|
100
|
-
|
|
94
|
+
if (!source.isRelocated) {
|
|
95
|
+
(0, fs_extra_1.copySync)(sourceFile, outputPath, { dereference: true });
|
|
96
|
+
}
|
|
97
|
+
this.updateFiles(relativePath);
|
|
101
98
|
}
|
|
102
99
|
else {
|
|
103
100
|
// we have both fastboot and non-fastboot files for this path.
|
|
@@ -110,10 +107,12 @@ class AppDiffer {
|
|
|
110
107
|
let base = (0, path_1.basename)(relativePath);
|
|
111
108
|
let browserDest = `_browser_${base}`;
|
|
112
109
|
let fastbootDest = `_fastboot_${base}`;
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
if (!browserSrc.isRelocated && !fastbootSrc.isRelocated) {
|
|
111
|
+
(0, fs_extra_1.copySync)(browserSourceFile, (0, path_1.join)(this.outputPath, dir, browserDest), { dereference: true });
|
|
112
|
+
(0, fs_extra_1.copySync)(fastbootSourceFile, (0, path_1.join)(this.outputPath, dir, fastbootDest), { dereference: true });
|
|
113
|
+
(0, fs_extra_1.writeFileSync)(outputPath, switcher(browserDest, fastbootDest, this.babelParserConfig, (0, fs_extra_1.readFileSync)(browserSourceFile, 'utf8')));
|
|
114
|
+
}
|
|
115
|
+
this.updateFiles(relativePath);
|
|
117
116
|
}
|
|
118
117
|
break;
|
|
119
118
|
default:
|
|
@@ -121,13 +120,8 @@ class AppDiffer {
|
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
|
-
updateFiles(relativePath
|
|
125
|
-
|
|
126
|
-
this.files.set(relativePath, sourceFile);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
this.files.set(relativePath, null);
|
|
130
|
-
}
|
|
123
|
+
updateFiles(relativePath) {
|
|
124
|
+
this.files.add(relativePath);
|
|
131
125
|
}
|
|
132
126
|
}
|
|
133
127
|
exports.default = AppDiffer;
|
|
@@ -175,8 +169,13 @@ export const {{name}} = mod.{{name}};
|
|
|
175
169
|
{{/each}}
|
|
176
170
|
`);
|
|
177
171
|
function switcher(browserDest, fastbootDest, babelParserConfig, browserSource) {
|
|
178
|
-
let { names
|
|
179
|
-
return switcherTemplate({
|
|
172
|
+
let { names } = (0, describe_exports_1.describeExports)(browserSource, babelParserConfig);
|
|
173
|
+
return switcherTemplate({
|
|
174
|
+
fastbootDest,
|
|
175
|
+
browserDest,
|
|
176
|
+
names: [...names].filter(name => name !== 'default'),
|
|
177
|
+
hasDefaultExport: names.has('default'),
|
|
178
|
+
});
|
|
180
179
|
}
|
|
181
180
|
function maybeSource(addon, key) {
|
|
182
181
|
let maybeFiles = addon.meta[key];
|
package/src/app-differ.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-differ.js","sourceRoot":"","sources":["app-differ.ts"],"names":[],"mappings":";;;;;AACA,wEAA6D;AAC7D,0DAAiC;AACjC,+BAAwD;AACxD,uCAAgH;AAChH,yCAAmC;AACnC,gEAAuC;AACvC,yDAAqD;AACrD,mDAA0C;AAE1C,2BAA8B;AAC9B,+BAA8B;AAE9B,MAAqB,SAAS;IAgB5B,YACU,UAAkB,EAC1B,WAAmB,EACnB,sBAAsC;IACtC,wEAAwE;IACxE,4EAA4E;IAC5E,eAAe,GAAG,KAAK,EACvB,gBAAqC,EAC7B,iBAAgD;QAPhD,eAAU,GAAV,UAAU,CAAQ;QAOlB,sBAAiB,GAAjB,iBAAiB,CAA+B;QArBlD,sBAAiB,GAAG,QAAQ,CAAC;QAErC,8EAA8E;QAC9E,oEAAoE;QACpE,uEAAuE;QACvE,qCAAqC;QACrC,EAAE;QACF,4CAA4C;QACnC,UAAK,GAA+B,IAAI,GAAG,EAAE,CAAC;QAEvD,yCAAyC;QACzC,mBAAc,GAAyB,IAAI,GAAG,EAAE,CAAC;QAY/C,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAa,CAAC;QAE7G,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,SAAS,EAAE,IAAI;YACf,IAAI;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AAG,CAAC;qBACX;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YACD,WAAW,EAAE,IAAI;YACjB,MAAM,CAAC,YAAoB;gBACzB,IAAI,QAAQ,GAAG,KAAK,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC;gBAC1C,IAAI,CAAC,QAAQ,EAAE;oBACb,MAAM,IAAI,KAAK,CAAC,sBAAsB,YAAY,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;iBACnF;gBACD,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACvC,CAAC;SACF,CAAC;KACH;AACH,CAAC;AAED,SAAS,wBAAwB,CAAC,QAAgB,EAAE,SAAgB;IAClE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAA,aAAM,EAAC,SAAS,CAAC,KAAK,QAAQ,iCAAiC,CAAC,CAAC;KACrF;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { AddonPackage } from '@embroider/shared-internals';\nimport MultiTreeDiff, { InputTree } from './multi-tree-diff';\nimport walkSync from 'walk-sync';\nimport { join, basename, dirname, resolve } from 'path';\nimport { mkdirpSync, unlinkSync, rmdirSync, removeSync, copySync, writeFileSync, readFileSync } from 'fs-extra';\nimport { debug } from './messages';\nimport assertNever from 'assert-never';\nimport { describeExports } from './describe-exports';\nimport { compile } from './js-handlebars';\nimport { TransformOptions } from '@babel/core';\nimport { statSync } from 'fs';\nimport { format } from 'util';\n\nexport default class AppDiffer {\n private differ: MultiTreeDiff;\n private sources: Source[];\n private firstFastbootTree = Infinity;\n\n // maps from each filename in the app to the original directory from whence it\n // came, if it came from an addon. The mapping allows us to preserve\n // resolution semantics so that each of the app files can still resolve\n // relative to where it was authored.\n //\n // files authored within the app map to null\n readonly files: Map<string, string | null> = new Map();\n\n // true for files that are fastboot-only.\n isFastbootOnly: Map<string, boolean> = new Map();\n\n constructor(\n private outputPath: string,\n ownAppJSDir: string,\n activeAddonDescendants: AddonPackage[],\n // arguments below this point are only needed in fastboot mode. Fastboot\n // makes this pretty messy because fastboot trees all merge into the app 🤮.\n fastbootEnabled = false,\n ownFastbootJSDir?: string | undefined,\n private babelParserConfig?: TransformOptions | undefined\n ) {\n this.sources = activeAddonDescendants.map(addon => maybeSource(addon, 'app-js')).filter(Boolean) as Source[];\n\n this.sources.push({\n mayChange: true,\n walk() {\n return walkSync.entries(ownAppJSDir);\n },\n isRelocated: false,\n locate(relativePath: string) {\n return resolve(ownAppJSDir, relativePath);\n },\n });\n\n if (!fastbootEnabled) {\n this.differ = new MultiTreeDiff(this.sources, lastOneWins);\n return;\n }\n\n this.firstFastbootTree = this.sources.length;\n for (let addon of activeAddonDescendants) {\n let source = maybeSource(addon, 'fastboot-js');\n if (source) {\n this.sources.push(source);\n }\n }\n if (ownFastbootJSDir) {\n this.sources.push({\n mayChange: true,\n walk() {\n return walkSync.entries(ownFastbootJSDir);\n },\n isRelocated: false,\n locate(relativePath) {\n return resolve(ownFastbootJSDir, relativePath);\n },\n });\n }\n this.differ = new MultiTreeDiff(this.sources, fastbootMerge(this.firstFastbootTree));\n }\n\n update() {\n let { ops, sources } = this.differ.update();\n debug(`app-differ operations count: %s`, ops.length);\n for (let [operation, relativePath] of ops) {\n let outputPath = join(this.outputPath, relativePath);\n switch (operation) {\n case 'unlink':\n unlinkSync(outputPath);\n this.files.delete(relativePath);\n break;\n case 'rmdir':\n rmdirSync(outputPath);\n break;\n case 'mkdir':\n mkdirpSync(outputPath);\n break;\n case 'change':\n removeSync(outputPath);\n // deliberate fallthrough\n case 'create':\n let sourceIndices = sources.get(relativePath)!;\n if (sourceIndices.length === 1) {\n // a single file won. whether it's fastboot or non-fastboot doesn't\n // actually change what we do here. It gets emitted in the app's\n // namespace (if it's fastboot-only, non-fastboot code shouldn't be\n // trying to import it anyway, because that would have already been\n // an error pre-embroider).\n this.isFastbootOnly.set(relativePath, sourceIndices[0] >= this.firstFastbootTree);\n let source = this.sources[sourceIndices[0]];\n let sourceFile = source.locate(relativePath);\n copySync(sourceFile, outputPath, { dereference: true });\n this.updateFiles(relativePath, source, sourceFile);\n } else {\n // we have both fastboot and non-fastboot files for this path.\n // Because of the way fastbootMerge is written, the first one is the\n // non-fastboot.\n this.isFastbootOnly.set(relativePath, false);\n let [browserSrc, fastbootSrc] = sourceIndices.map(i => this.sources[i]);\n let [browserSourceFile, fastbootSourceFile] = [browserSrc, fastbootSrc].map(src =>\n src.locate(relativePath)\n );\n let dir = dirname(relativePath);\n let base = basename(relativePath);\n let browserDest = `_browser_${base}`;\n let fastbootDest = `_fastboot_${base}`;\n copySync(browserSourceFile, join(this.outputPath, dir, browserDest), { dereference: true });\n copySync(fastbootSourceFile, join(this.outputPath, dir, fastbootDest), { dereference: true });\n writeFileSync(\n outputPath,\n switcher(browserDest, fastbootDest, this.babelParserConfig!, readFileSync(browserSourceFile, 'utf8'))\n );\n this.updateFiles(relativePath, browserSrc, browserSourceFile);\n }\n break;\n default:\n assertNever(operation);\n }\n }\n }\n\n private updateFiles(relativePath: string, source: Source, sourceFile: string) {\n if (source.isRelocated) {\n this.files.set(relativePath, sourceFile);\n } else {\n this.files.set(relativePath, null);\n }\n }\n}\n\nfunction lastOneWins(treeIds: number[]) {\n return treeIds.slice(-1);\n}\n\nfunction fastbootMerge(firstFastbootTree: number) {\n return function _fastbootMerge(treeIds: number[]): number[] {\n let mainWinner, fastbootWinner;\n for (let id of treeIds) {\n if (id < firstFastbootTree) {\n mainWinner = id;\n } else {\n fastbootWinner = id;\n }\n }\n if (mainWinner != null && fastbootWinner != null) {\n return [mainWinner, fastbootWinner];\n } else if (mainWinner != null) {\n return [mainWinner];\n } else if (fastbootWinner != null) {\n return [fastbootWinner];\n } else {\n throw new Error(`bug: should always have at least one winner in fastbootMerge`);\n }\n };\n}\n\nconst switcherTemplate = compile(`\nimport { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';\nlet mod;\nif (macroCondition(getGlobalConfig().fastboot?.isRunning)){\n mod = importSync(\"./{{js-string-escape fastbootDest}}\");\n} else {\n mod = importSync(\"./{{js-string-escape browserDest}}\");\n}\n{{#if hasDefaultExport}}\nexport default mod.default;\n{{/if}}\n{{#each names as |name|}}\nexport const {{name}} = mod.{{name}};\n{{/each}}\n`) as (params: { fastbootDest: string; browserDest: string; names: string[]; hasDefaultExport: boolean }) => string;\n\nfunction switcher(\n browserDest: string,\n fastbootDest: string,\n babelParserConfig: TransformOptions,\n browserSource: string\n): string {\n let { names, hasDefaultExport } = describeExports(browserSource, babelParserConfig);\n return switcherTemplate({ fastbootDest, browserDest, names: [...names], hasDefaultExport });\n}\n\ninterface Source extends InputTree {\n // find the real on disk location of the file that is presented externally as\n // `relativePath`\n locate(relativePath: string): string;\n\n // true if this source relocates its file out of their original package,\n // meaning we will need to track them in order to adjust package resolution\n isRelocated: boolean;\n}\n\nfunction maybeSource(addon: AddonPackage, key: 'app-js' | 'fastboot-js'): Source | undefined {\n let maybeFiles = addon.meta[key];\n if (maybeFiles) {\n let files = maybeFiles;\n return {\n mayChange: addon.mayRebuild,\n walk() {\n return Object.entries(files).map(([externalName, internalName]) => {\n try {\n let stat = statSync(resolve(addon.root, internalName));\n return {\n relativePath: withoutMandatoryDotSlash(externalName, [\n 'in package.json at %s in key ember-addon.%s',\n addon.root,\n key,\n ]),\n mode: stat.mode,\n size: stat.size,\n mtime: stat.mtime,\n isDirectory() {\n return false;\n },\n };\n } catch (err) {\n if (err.code === 'ENOENT') {\n throw new Error(\n `${addon.name}/package.json lists ${internalName} in ember-addon.${key}, but that file does not exist`\n );\n }\n throw err;\n }\n });\n },\n isRelocated: true,\n locate(relativePath: string) {\n let internal = files['./' + relativePath];\n if (!internal) {\n throw new Error(`bug: couldn't find ${relativePath} in ${JSON.stringify(files)}`);\n }\n return resolve(addon.root, internal);\n },\n };\n }\n}\n\nfunction withoutMandatoryDotSlash(filename: string, debugInfo: any[]): string {\n if (!filename.startsWith('./')) {\n throw new Error(`${format(debugInfo)}: ${filename} is required to start with \"./\"`);\n }\n return filename.slice(2);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"app-differ.js","sourceRoot":"","sources":["app-differ.ts"],"names":[],"mappings":";;;;;AACA,wEAA6D;AAC7D,0DAAiC;AACjC,+BAAwD;AACxD,uCAAgH;AAChH,yCAAmC;AACnC,gEAAuC;AACvC,yDAAqD;AACrD,mDAA0C;AAE1C,2BAA8B;AAC9B,+BAA8B;AAE9B,MAAqB,SAAS;IAW5B,YACU,UAAkB,EAC1B,WAAmB,EACnB,sBAAsC;IACtC,wEAAwE;IACxE,4EAA4E;IAC5E,eAAe,GAAG,KAAK,EACvB,gBAAqC,EAC7B,iBAAgD;QAPhD,eAAU,GAAV,UAAU,CAAQ;QAOlB,sBAAiB,GAAjB,iBAAiB,CAA+B;QAhBlD,sBAAiB,GAAG,QAAQ,CAAC;QAErC,gDAAgD;QACvC,UAAK,GAAgB,IAAI,GAAG,EAAE,CAAC;QAExC,yCAAyC;QACzC,mBAAc,GAAyB,IAAI,GAAG,EAAE,CAAC;QAY/C,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAa,CAAC;QAE7G,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,SAAS,EAAE,IAAI;YACf,IAAI;gBACF,OAAO,mBAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACvC,CAAC;YACD,WAAW,EAAE,KAAK;YAClB,MAAM,CAAC,YAAoB;gBACzB,OAAO,IAAA,cAAO,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YAC5C,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,EAAE;YACpB,IAAI,C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,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;iBACnF;gBACD,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACvC,CAAC;SACF,CAAC;KACH;AACH,CAAC;AAED,SAAS,wBAAwB,CAAC,QAAgB,EAAE,SAAgB;IAClE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAA,aAAM,EAAC,SAAS,CAAC,KAAK,QAAQ,iCAAiC,CAAC,CAAC;KACrF;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { AddonPackage } from '@embroider/shared-internals';\nimport MultiTreeDiff, { InputTree } from './multi-tree-diff';\nimport walkSync from 'walk-sync';\nimport { join, basename, dirname, resolve } from 'path';\nimport { mkdirpSync, unlinkSync, rmdirSync, removeSync, copySync, writeFileSync, readFileSync } from 'fs-extra';\nimport { debug } from './messages';\nimport assertNever from 'assert-never';\nimport { describeExports } from './describe-exports';\nimport { compile } from './js-handlebars';\nimport { TransformOptions } from '@babel/core';\nimport { statSync } from 'fs';\nimport { format } from 'util';\n\nexport default class AppDiffer {\n private differ: MultiTreeDiff;\n private sources: Source[];\n private firstFastbootTree = Infinity;\n\n // set of filenames logically located in the app\n readonly files: Set<string> = new Set();\n\n // true for files that are fastboot-only.\n isFastbootOnly: Map<string, boolean> = new Map();\n\n constructor(\n private outputPath: string,\n ownAppJSDir: string,\n activeAddonDescendants: AddonPackage[],\n // arguments below this point are only needed in fastboot mode. Fastboot\n // makes this pretty messy because fastboot trees all merge into the app 🤮.\n fastbootEnabled = false,\n ownFastbootJSDir?: string | undefined,\n private babelParserConfig?: TransformOptions | undefined\n ) {\n this.sources = activeAddonDescendants.map(addon => maybeSource(addon, 'app-js')).filter(Boolean) as Source[];\n\n this.sources.push({\n mayChange: true,\n walk() {\n return walkSync.entries(ownAppJSDir);\n },\n isRelocated: false,\n locate(relativePath: string) {\n return resolve(ownAppJSDir, relativePath);\n },\n });\n\n if (!fastbootEnabled) {\n this.differ = new MultiTreeDiff(this.sources, lastOneWins);\n return;\n }\n\n this.firstFastbootTree = this.sources.length;\n for (let addon of activeAddonDescendants) {\n let source = maybeSource(addon, 'fastboot-js');\n if (source) {\n this.sources.push(source);\n }\n }\n if (ownFastbootJSDir) {\n this.sources.push({\n mayChange: true,\n walk() {\n return walkSync.entries(ownFastbootJSDir);\n },\n isRelocated: false,\n locate(relativePath) {\n return resolve(ownFastbootJSDir, relativePath);\n },\n });\n }\n this.differ = new MultiTreeDiff(this.sources, fastbootMerge(this.firstFastbootTree));\n }\n\n update() {\n let { ops, sources } = this.differ.update();\n debug(`app-differ operations count: %s`, ops.length);\n for (let [operation, relativePath] of ops) {\n let outputPath = join(this.outputPath, relativePath);\n switch (operation) {\n case 'unlink':\n unlinkSync(outputPath);\n this.files.delete(relativePath);\n break;\n case 'rmdir':\n rmdirSync(outputPath);\n break;\n case 'mkdir':\n mkdirpSync(outputPath);\n break;\n case 'change':\n removeSync(outputPath);\n // deliberate fallthrough\n case 'create':\n let sourceIndices = sources.get(relativePath)!;\n if (sourceIndices.length === 1) {\n // a single file won. whether it's fastboot or non-fastboot doesn't\n // actually change what we do here. It gets emitted in the app's\n // namespace (if it's fastboot-only, non-fastboot code shouldn't be\n // trying to import it anyway, because that would have already been\n // an error pre-embroider).\n this.isFastbootOnly.set(relativePath, sourceIndices[0] >= this.firstFastbootTree);\n let source = this.sources[sourceIndices[0]];\n let sourceFile = source.locate(relativePath);\n if (!source.isRelocated) {\n copySync(sourceFile, outputPath, { dereference: true });\n }\n this.updateFiles(relativePath);\n } else {\n // we have both fastboot and non-fastboot files for this path.\n // Because of the way fastbootMerge is written, the first one is the\n // non-fastboot.\n this.isFastbootOnly.set(relativePath, false);\n let [browserSrc, fastbootSrc] = sourceIndices.map(i => this.sources[i]);\n let [browserSourceFile, fastbootSourceFile] = [browserSrc, fastbootSrc].map(src =>\n src.locate(relativePath)\n );\n let dir = dirname(relativePath);\n let base = basename(relativePath);\n let browserDest = `_browser_${base}`;\n let fastbootDest = `_fastboot_${base}`;\n if (!browserSrc.isRelocated && !fastbootSrc.isRelocated) {\n copySync(browserSourceFile, join(this.outputPath, dir, browserDest), { dereference: true });\n copySync(fastbootSourceFile, join(this.outputPath, dir, fastbootDest), { dereference: true });\n writeFileSync(\n outputPath,\n switcher(browserDest, fastbootDest, this.babelParserConfig!, readFileSync(browserSourceFile, 'utf8'))\n );\n }\n this.updateFiles(relativePath);\n }\n break;\n default:\n assertNever(operation);\n }\n }\n }\n\n private updateFiles(relativePath: string) {\n this.files.add(relativePath);\n }\n}\n\nfunction lastOneWins(treeIds: number[]) {\n return treeIds.slice(-1);\n}\n\nfunction fastbootMerge(firstFastbootTree: number) {\n return function _fastbootMerge(treeIds: number[]): number[] {\n let mainWinner, fastbootWinner;\n for (let id of treeIds) {\n if (id < firstFastbootTree) {\n mainWinner = id;\n } else {\n fastbootWinner = id;\n }\n }\n if (mainWinner != null && fastbootWinner != null) {\n return [mainWinner, fastbootWinner];\n } else if (mainWinner != null) {\n return [mainWinner];\n } else if (fastbootWinner != null) {\n return [fastbootWinner];\n } else {\n throw new Error(`bug: should always have at least one winner in fastbootMerge`);\n }\n };\n}\n\nconst switcherTemplate = compile(`\nimport { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';\nlet mod;\nif (macroCondition(getGlobalConfig().fastboot?.isRunning)){\n mod = importSync(\"./{{js-string-escape fastbootDest}}\");\n} else {\n mod = importSync(\"./{{js-string-escape browserDest}}\");\n}\n{{#if hasDefaultExport}}\nexport default mod.default;\n{{/if}}\n{{#each names as |name|}}\nexport const {{name}} = mod.{{name}};\n{{/each}}\n`) as (params: { fastbootDest: string; browserDest: string; names: string[]; hasDefaultExport: boolean }) => string;\n\nfunction switcher(\n browserDest: string,\n fastbootDest: string,\n babelParserConfig: TransformOptions,\n browserSource: string\n): string {\n let { names } = describeExports(browserSource, babelParserConfig);\n return switcherTemplate({\n fastbootDest,\n browserDest,\n names: [...names].filter(name => name !== 'default'),\n hasDefaultExport: names.has('default'),\n });\n}\n\ninterface Source extends InputTree {\n // find the real on disk location of the file that is presented externally as\n // `relativePath`\n locate(relativePath: string): string;\n\n // true if this source relocates its file out of their original package,\n // meaning we will need to track them in order to adjust package resolution\n isRelocated: boolean;\n}\n\nfunction maybeSource(addon: AddonPackage, key: 'app-js' | 'fastboot-js'): Source | undefined {\n let maybeFiles = addon.meta[key];\n if (maybeFiles) {\n let files = maybeFiles;\n return {\n mayChange: addon.mayRebuild,\n walk() {\n return Object.entries(files).map(([externalName, internalName]) => {\n try {\n let stat = statSync(resolve(addon.root, internalName));\n return {\n relativePath: withoutMandatoryDotSlash(externalName, [\n 'in package.json at %s in key ember-addon.%s',\n addon.root,\n key,\n ]),\n mode: stat.mode,\n size: stat.size,\n mtime: stat.mtime,\n isDirectory() {\n return false;\n },\n };\n } catch (err) {\n if (err.code === 'ENOENT') {\n throw new Error(\n `${addon.name}/package.json lists ${internalName} in ember-addon.${key}, but that file does not exist`\n );\n }\n throw err;\n }\n });\n },\n isRelocated: true,\n locate(relativePath: string) {\n let internal = files['./' + relativePath];\n if (!internal) {\n throw new Error(`bug: couldn't find ${relativePath} in ${JSON.stringify(files)}`);\n }\n return resolve(addon.root, internal);\n },\n };\n }\n}\n\nfunction withoutMandatoryDotSlash(filename: string, debugInfo: any[]): string {\n if (!filename.startsWith('./')) {\n throw new Error(`${format(debugInfo)}: ${filename} is required to start with \"./\"`);\n }\n return filename.slice(2);\n}\n"]}
|
package/src/app-files.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Package, AddonPackage } from '@embroider/shared-internals';
|
|
2
|
-
import AppDiffer from './app-differ';
|
|
2
|
+
import type AppDiffer from './app-differ';
|
|
3
3
|
export interface RouteFiles {
|
|
4
4
|
route?: string;
|
|
5
5
|
template?: string;
|
|
@@ -13,7 +13,6 @@ export declare class AppFiles {
|
|
|
13
13
|
readonly modifiers: ReadonlyArray<string>;
|
|
14
14
|
private perRoute;
|
|
15
15
|
readonly otherAppFiles: ReadonlyArray<string>;
|
|
16
|
-
readonly relocatedFiles: Map<string, string>;
|
|
17
16
|
readonly isFastbootOnly: Map<string, boolean>;
|
|
18
17
|
constructor(appDiffer: AppDiffer, resolvableExtensions: RegExp, podModulePrefix?: string);
|
|
19
18
|
private handleClassicRouteFile;
|
package/src/app-files.js
CHANGED
|
@@ -57,13 +57,6 @@ class AppFiles {
|
|
|
57
57
|
this.helpers = helpers;
|
|
58
58
|
this.modifiers = modifiers;
|
|
59
59
|
this.otherAppFiles = otherAppFiles;
|
|
60
|
-
let relocatedFiles = new Map();
|
|
61
|
-
for (let [relativePath, owningPath] of appDiffer.files) {
|
|
62
|
-
if (owningPath) {
|
|
63
|
-
relocatedFiles.set(relativePath, owningPath);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.relocatedFiles = relocatedFiles;
|
|
67
60
|
this.isFastbootOnly = appDiffer.isFastbootOnly;
|
|
68
61
|
}
|
|
69
62
|
handleClassicRouteFile(relativePath) {
|
package/src/app-files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-files.js","sourceRoot":"","sources":["app-files.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAW3B,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"app-files.js","sourceRoot":"","sources":["app-files.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAW3B,MAAa,QAAQ;IASnB,YAAY,SAAoB,EAAE,oBAA4B,EAAE,eAAwB;QACtF,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,IAAI,UAAU,GAAa,EAAE,CAAC;QAC9B,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,IAAI,SAAS,GAAa,EAAE,CAAC;QAC7B,IAAI,aAAa,GAAa,EAAE,CA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AC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAnID,4BAmIC","sourcesContent":["import { sep } from 'path';\nimport { Package, AddonPackage } from '@embroider/shared-internals';\nimport type AppDiffer from './app-differ';\n\nexport interface RouteFiles {\n route?: string;\n template?: string;\n controller?: string;\n children: Map<string, RouteFiles>;\n}\n\nexport class AppFiles {\n readonly tests: ReadonlyArray<string>;\n readonly components: ReadonlyArray<string>;\n readonly helpers: ReadonlyArray<string>;\n readonly modifiers: ReadonlyArray<string>;\n private perRoute: RouteFiles;\n readonly otherAppFiles: ReadonlyArray<string>;\n readonly isFastbootOnly: Map<string, boolean>;\n\n constructor(appDiffer: AppDiffer, resolvableExtensions: RegExp, podModulePrefix?: string) {\n let tests: string[] = [];\n let components: string[] = [];\n let helpers: string[] = [];\n let modifiers: string[] = [];\n let otherAppFiles: string[] = [];\n this.perRoute = { children: new Map() };\n for (let relativePath of appDiffer.files.keys()) {\n relativePath = relativePath.split(sep).join('/');\n if (!resolvableExtensions.test(relativePath)) {\n continue;\n }\n\n if (/\\.d\\.ts$/.test(relativePath)) {\n // .d.ts files are technically \"*.ts\" files but aren't really and we\n // don't want to include them when we crawl through the app.\n continue;\n }\n\n if (relativePath.startsWith('tests/')) {\n tests.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('components/')) {\n // hbs files are resolvable, but not when they're used via co-location.\n // An hbs file is used via colocation when it's inside the components\n // directory, and also not named \"template.hbs\" (because that is an\n // older pattern used with pods-like layouts).\n if (!relativePath.endsWith('.hbs') || relativePath.endsWith('/template.hbs')) {\n components.push(relativePath);\n }\n continue;\n }\n\n if (relativePath.startsWith('templates/components/')) {\n components.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('helpers/')) {\n helpers.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('modifiers/')) {\n modifiers.push(relativePath);\n continue;\n }\n\n if (\n this.handleClassicRouteFile(relativePath) ||\n (podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix))\n ) {\n continue;\n }\n\n otherAppFiles.push(relativePath);\n }\n this.tests = tests;\n this.components = components;\n this.helpers = helpers;\n this.modifiers = modifiers;\n this.otherAppFiles = otherAppFiles;\n this.isFastbootOnly = appDiffer.isFastbootOnly;\n }\n\n private handleClassicRouteFile(relativePath: string): boolean {\n let [prefix, ...rest] = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n if (!['controllers', 'templates', 'routes'].includes(prefix)) {\n return false;\n }\n let type = prefix.slice(0, -1) as 'controller' | 'template' | 'route';\n let cursor = this.perRoute;\n for (let part of rest) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type] = relativePath;\n return true;\n }\n\n private handlePodsRouteFile(relativePath: string, podModulePrefix: string): boolean {\n let parts = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n let type = parts.pop();\n if (!type || !['controller', 'template', 'route'].includes(type)) {\n return false;\n }\n let podParts = podModulePrefix.split('/');\n // The first part of podModulePrefix is the app's package name\n podParts.shift();\n\n for (let podPart of podParts) {\n if (parts.shift() !== podPart) {\n return false;\n }\n }\n\n let cursor = this.perRoute;\n for (let part of parts) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type as 'controller' | 'template' | 'route'] = relativePath;\n return true;\n }\n\n get routeFiles(): Readonly<RouteFiles> {\n return this.perRoute;\n }\n}\n\nexport interface EngineSummary {\n // the engine's own package\n package: Package;\n // the set of active addons in the engine\n addons: Set<AddonPackage>;\n // the parent engine, if any\n parent: EngineSummary | undefined;\n // where the engine's own V2 code comes from\n sourcePath: string;\n // where the engine gets built into, combining its own code with all its\n // addons\n destPath: string;\n // runtime name for the engine's own module namespace\n modulePrefix: string;\n // this is destPath but relative to the app itself\n appRelativePath: string;\n}\n\nexport interface Engine extends EngineSummary {\n appFiles: AppFiles;\n}\n"]}
|
package/src/app.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ import { OutputPaths } from './wait-for-trees';
|
|
|
3
3
|
import { Asset } from './asset';
|
|
4
4
|
import Options from './options';
|
|
5
5
|
import { MacrosConfig } from '@embroider/macros/src/node';
|
|
6
|
-
import { TransformOptions } from '@babel/core';
|
|
7
|
-
import { Options as
|
|
6
|
+
import { PluginItem, TransformOptions } from '@babel/core';
|
|
7
|
+
import { Options as ResolverConfig } from './module-resolver';
|
|
8
|
+
import { Engine } from './app-files';
|
|
8
9
|
import type { Transform } from 'babel-plugin-ember-template-compilation';
|
|
9
|
-
export
|
|
10
|
-
export interface AppAdapter<TreeNames> {
|
|
10
|
+
export type EmberENV = unknown;
|
|
11
|
+
export interface AppAdapter<TreeNames, SpecificResolverConfig extends ResolverConfig = ResolverConfig> {
|
|
11
12
|
readonly allActiveAddons: AddonPackage[];
|
|
12
13
|
activeAddonChildren(pkg: Package): AddonPackage[];
|
|
13
14
|
appJSSrcDir(treePaths: OutputPaths<TreeNames>): string;
|
|
@@ -21,9 +22,10 @@ export interface AppAdapter<TreeNames> {
|
|
|
21
22
|
podModulePrefix(): string | undefined;
|
|
22
23
|
rootURL(): string;
|
|
23
24
|
templateCompilerPath(): string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
hbsTransforms(resolverConfig: SpecificResolverConfig): Transform[];
|
|
26
|
+
jsPlugins(resolverConfig: SpecificResolverConfig): PluginItem[];
|
|
27
|
+
resolverConfig(engines: Engine[]): SpecificResolverConfig;
|
|
28
|
+
resolvableExtensions(): string[];
|
|
27
29
|
htmlbarsPlugins(): Transform[];
|
|
28
30
|
babelConfig(): TransformOptions;
|
|
29
31
|
babelMajorVersion(): 7;
|
|
@@ -52,7 +54,6 @@ export declare class AppBuilder<TreeNames> {
|
|
|
52
54
|
private impliedAddonAssets;
|
|
53
55
|
private babelParserConfig;
|
|
54
56
|
private babelConfig;
|
|
55
|
-
private adjustImportsPlugin;
|
|
56
57
|
private insertEmberApp;
|
|
57
58
|
private implicitScriptsAsset;
|
|
58
59
|
private implicitStylesAsset;
|
|
@@ -78,6 +79,7 @@ export declare class AppBuilder<TreeNames> {
|
|
|
78
79
|
private etcOptions;
|
|
79
80
|
private get portableHints();
|
|
80
81
|
private addBabelConfig;
|
|
82
|
+
private addResolverConfig;
|
|
81
83
|
private shouldSplitRoute;
|
|
82
84
|
private splitRoute;
|
|
83
85
|
private topAppJSAsset;
|
package/src/app.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -145,7 +149,7 @@ class AppBuilder {
|
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
get resolvableExtensionsPattern() {
|
|
148
|
-
return (0, shared_internals_1.extensionsPattern)(this.adapter.
|
|
152
|
+
return (0, shared_internals_1.extensionsPattern)(this.adapter.resolvableExtensions());
|
|
149
153
|
}
|
|
150
154
|
impliedAssets(type, engine, emberENV) {
|
|
151
155
|
let result = this.impliedAddonAssets(type, engine).map((sourcePath) => {
|
|
@@ -238,7 +242,7 @@ class AppBuilder {
|
|
|
238
242
|
babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
|
|
239
243
|
return babel;
|
|
240
244
|
}
|
|
241
|
-
babelConfig(
|
|
245
|
+
babelConfig(resolverConfig) {
|
|
242
246
|
let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
|
|
243
247
|
if (!babel.plugins) {
|
|
244
248
|
babel.plugins = [];
|
|
@@ -248,7 +252,7 @@ class AppBuilder {
|
|
|
248
252
|
babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
|
|
249
253
|
// https://github.com/webpack/webpack/issues/12154
|
|
250
254
|
babel.plugins.push(require.resolve('./rename-require-plugin'));
|
|
251
|
-
babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions()]);
|
|
255
|
+
babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
|
|
252
256
|
// this is @embroider/macros configured for full stage3 resolution
|
|
253
257
|
babel.plugins.push(...this.macrosConfig.babelPluginConfig());
|
|
254
258
|
let colocationOptions = {
|
|
@@ -285,7 +289,9 @@ class AppBuilder {
|
|
|
285
289
|
require.resolve('@embroider/shared-internals/src/template-colocation-plugin'),
|
|
286
290
|
colocationOptions,
|
|
287
291
|
]);
|
|
288
|
-
|
|
292
|
+
for (let p of this.adapter.jsPlugins(resolverConfig)) {
|
|
293
|
+
babel.plugins.push(p);
|
|
294
|
+
}
|
|
289
295
|
// we can use globally shared babel runtime by default
|
|
290
296
|
babel.plugins.push([
|
|
291
297
|
require.resolve('@babel/plugin-transform-runtime'),
|
|
@@ -295,23 +301,6 @@ class AppBuilder {
|
|
|
295
301
|
addCachablePlugin(portable.config);
|
|
296
302
|
return portable;
|
|
297
303
|
}
|
|
298
|
-
adjustImportsPlugin(engines) {
|
|
299
|
-
let relocatedFiles = {};
|
|
300
|
-
for (let { destPath, appFiles } of engines) {
|
|
301
|
-
for (let [relativePath, originalPath] of appFiles.relocatedFiles) {
|
|
302
|
-
relocatedFiles[(0, path_1.join)(destPath, relativePath)] = originalPath;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
let relocatedFilesPath = (0, path_1.join)(this.root, '_relocated_files.json');
|
|
306
|
-
(0, fs_extra_1.writeFileSync)(relocatedFilesPath, JSON.stringify({ relocatedFiles }));
|
|
307
|
-
return [
|
|
308
|
-
require.resolve('./babel-plugin-adjust-imports'),
|
|
309
|
-
{
|
|
310
|
-
adjustImportsOptionsPath: this.adapter.adjustImportsOptionsPath(),
|
|
311
|
-
relocatedFilesPath,
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
}
|
|
315
304
|
insertEmberApp(asset, appFiles, prepared, emberENV) {
|
|
316
305
|
let html = asset.html;
|
|
317
306
|
if (this.fastbootConfig) {
|
|
@@ -508,9 +497,10 @@ class AppBuilder {
|
|
|
508
497
|
.reverse()
|
|
509
498
|
.forEach(a => a.differ.update());
|
|
510
499
|
return this.appDiffers.map(a => {
|
|
511
|
-
return
|
|
500
|
+
return {
|
|
501
|
+
...a.engine,
|
|
512
502
|
appFiles: new app_files_1.AppFiles(a.differ, this.resolvableExtensionsPattern, this.adapter.podModulePrefix()),
|
|
513
|
-
}
|
|
503
|
+
};
|
|
514
504
|
});
|
|
515
505
|
}
|
|
516
506
|
prepareAsset(asset, appFiles, prepared, emberENV) {
|
|
@@ -684,8 +674,6 @@ class AppBuilder {
|
|
|
684
674
|
let emberENV = this.adapter.emberENV();
|
|
685
675
|
let assets = this.gatherAssets(inputPaths);
|
|
686
676
|
let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
|
|
687
|
-
let babelConfig = this.babelConfig(appFiles);
|
|
688
|
-
this.addBabelConfig(babelConfig);
|
|
689
677
|
let assetPaths = assets.map(asset => asset.relativePath);
|
|
690
678
|
if (this.activeFastboot) {
|
|
691
679
|
// when using fastboot, our own package.json needs to be in the output so fastboot can read it.
|
|
@@ -705,11 +693,10 @@ class AppBuilder {
|
|
|
705
693
|
assets: assetPaths,
|
|
706
694
|
babel: {
|
|
707
695
|
filename: '_babel_config_.js',
|
|
708
|
-
isParallelSafe:
|
|
696
|
+
isParallelSafe: true,
|
|
709
697
|
majorVersion: this.adapter.babelMajorVersion(),
|
|
710
698
|
fileFilter: '_babel_filter_.js',
|
|
711
699
|
},
|
|
712
|
-
'resolvable-extensions': this.adapter.adjustImportsOptions().resolvableExtensions,
|
|
713
700
|
'root-url': this.adapter.rootURL(),
|
|
714
701
|
};
|
|
715
702
|
if (!this.adapter.strictV2Format()) {
|
|
@@ -717,6 +704,10 @@ class AppBuilder {
|
|
|
717
704
|
}
|
|
718
705
|
let pkg = this.combinePackageJSON(meta);
|
|
719
706
|
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
|
|
707
|
+
let resolverConfig = this.adapter.resolverConfig(appFiles);
|
|
708
|
+
this.addResolverConfig(resolverConfig);
|
|
709
|
+
let babelConfig = this.babelConfig(resolverConfig);
|
|
710
|
+
this.addBabelConfig(babelConfig);
|
|
720
711
|
}
|
|
721
712
|
combinePackageJSON(meta) {
|
|
722
713
|
let pkgLayers = [this.app.packageJSON];
|
|
@@ -729,16 +720,15 @@ class AppBuilder {
|
|
|
729
720
|
pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
|
|
730
721
|
return combinePackageJSON(...pkgLayers);
|
|
731
722
|
}
|
|
732
|
-
etcOptions() {
|
|
723
|
+
etcOptions(resolverConfig) {
|
|
733
724
|
let transforms = this.adapter.htmlbarsPlugins();
|
|
734
725
|
let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
|
|
735
726
|
setConfig(this.macrosConfig);
|
|
736
727
|
for (let macroPlugin of macroPlugins) {
|
|
737
728
|
transforms.push(macroPlugin);
|
|
738
729
|
}
|
|
739
|
-
let
|
|
740
|
-
|
|
741
|
-
transforms.push(transform);
|
|
730
|
+
for (let t of this.adapter.hbsTransforms(resolverConfig)) {
|
|
731
|
+
transforms.push(t);
|
|
742
732
|
}
|
|
743
733
|
return {
|
|
744
734
|
transforms,
|
|
@@ -770,6 +760,9 @@ class AppBuilder {
|
|
|
770
760
|
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, '_babel_config_.js'), `module.exports = ${JSON.stringify(pconfig.config, null, 2)}`, 'utf8');
|
|
771
761
|
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, '_babel_filter_.js'), babelFilterTemplate({ skipBabel: this.options.skipBabel, appRoot: this.root }), 'utf8');
|
|
772
762
|
}
|
|
763
|
+
addResolverConfig(config) {
|
|
764
|
+
(0, fs_extra_1.outputJSONSync)((0, path_1.join)(this.root, '.embroider', 'resolver.json'), config);
|
|
765
|
+
}
|
|
773
766
|
shouldSplitRoute(routeName) {
|
|
774
767
|
return (!this.options.splitAtRoutes ||
|
|
775
768
|
this.options.splitAtRoutes.find(pattern => {
|
|
@@ -916,16 +909,16 @@ class AppBuilder {
|
|
|
916
909
|
}
|
|
917
910
|
lazyRoutes.push({
|
|
918
911
|
names: routeNames,
|
|
919
|
-
path: this.importPaths(engine, routeEntrypoint
|
|
912
|
+
path: this.importPaths(engine, routeEntrypoint).buildtime,
|
|
920
913
|
});
|
|
921
914
|
});
|
|
922
915
|
}
|
|
923
916
|
let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
|
|
924
|
-
let amdModules = nonFastboot.map(file => this.importPaths(engine, file
|
|
925
|
-
let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(engine, file
|
|
917
|
+
let amdModules = nonFastboot.map(file => this.importPaths(engine, file));
|
|
918
|
+
let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(engine, file));
|
|
926
919
|
// this is a backward-compatibility feature: addons can force inclusion of
|
|
927
920
|
// modules.
|
|
928
|
-
this.gatherImplicitModules('implicit-modules',
|
|
921
|
+
this.gatherImplicitModules('implicit-modules', engine, amdModules);
|
|
929
922
|
let params = { amdModules, fastbootOnlyAmdModules, lazyRoutes, lazyEngines, eagerModules, styles };
|
|
930
923
|
if (entryParams) {
|
|
931
924
|
Object.assign(params, entryParams);
|
|
@@ -942,12 +935,11 @@ class AppBuilder {
|
|
|
942
935
|
get modulePrefix() {
|
|
943
936
|
return this.adapter.modulePrefix();
|
|
944
937
|
}
|
|
945
|
-
importPaths(engine, engineRelativePath
|
|
946
|
-
let appRelativePath = (0, path_1.join)(engine.appRelativePath, engineRelativePath);
|
|
938
|
+
importPaths(engine, engineRelativePath) {
|
|
947
939
|
let noHBS = engineRelativePath.replace(this.resolvableExtensionsPattern, '').replace(/\.hbs$/, '');
|
|
948
940
|
return {
|
|
949
941
|
runtime: `${engine.modulePrefix}/${noHBS}`,
|
|
950
|
-
buildtime:
|
|
942
|
+
buildtime: path_1.posix.join(engine.package.name, engineRelativePath),
|
|
951
943
|
};
|
|
952
944
|
}
|
|
953
945
|
routeEntrypoint(engine, relativePath, files) {
|
|
@@ -955,8 +947,8 @@ class AppBuilder {
|
|
|
955
947
|
let asset = {
|
|
956
948
|
kind: 'in-memory',
|
|
957
949
|
source: routeEntryTemplate({
|
|
958
|
-
files: nonFastboot.map(f => this.importPaths(engine, f
|
|
959
|
-
fastbootOnlyFiles: fastboot.map(f => this.importPaths(engine, f
|
|
950
|
+
files: nonFastboot.map(f => this.importPaths(engine, f)),
|
|
951
|
+
fastbootOnlyFiles: fastboot.map(f => this.importPaths(engine, f)),
|
|
960
952
|
}),
|
|
961
953
|
relativePath,
|
|
962
954
|
};
|
|
@@ -983,10 +975,10 @@ class AppBuilder {
|
|
|
983
975
|
let amdModules = [];
|
|
984
976
|
// this is a backward-compatibility feature: addons can force inclusion of
|
|
985
977
|
// test support modules.
|
|
986
|
-
this.gatherImplicitModules('implicit-test-modules',
|
|
978
|
+
this.gatherImplicitModules('implicit-test-modules', engine, amdModules);
|
|
987
979
|
let { appFiles } = engine;
|
|
988
980
|
for (let relativePath of appFiles.tests) {
|
|
989
|
-
amdModules.push(this.importPaths(engine, relativePath
|
|
981
|
+
amdModules.push(this.importPaths(engine, relativePath));
|
|
990
982
|
}
|
|
991
983
|
let source = entryTemplate({
|
|
992
984
|
amdModules,
|
|
@@ -1001,7 +993,7 @@ class AppBuilder {
|
|
|
1001
993
|
prepared.set(asset.relativePath, asset);
|
|
1002
994
|
return asset;
|
|
1003
995
|
}
|
|
1004
|
-
gatherImplicitModules(section,
|
|
996
|
+
gatherImplicitModules(section, engine, lazyModules) {
|
|
1005
997
|
for (let addon of engine.addons) {
|
|
1006
998
|
let implicitModules = addon.meta[section];
|
|
1007
999
|
if (implicitModules) {
|
|
@@ -1026,9 +1018,7 @@ class AppBuilder {
|
|
|
1026
1018
|
runtime = runtime.split(path_1.sep).join('/');
|
|
1027
1019
|
lazyModules.push({
|
|
1028
1020
|
runtime,
|
|
1029
|
-
buildtime:
|
|
1030
|
-
? (0, path_1.join)(packageName, name)
|
|
1031
|
-
: (0, shared_internals_1.explicitRelative)((0, path_1.dirname)((0, path_1.join)(this.root, relativeTo)), (0, path_1.join)(addon.root, name)),
|
|
1021
|
+
buildtime: path_1.posix.join(packageName, name),
|
|
1032
1022
|
});
|
|
1033
1023
|
}
|
|
1034
1024
|
}
|