@embroider/core 3.1.3-unstable.ef70747 → 3.1.4-unstable.0c7aa66
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 +6 -6
- package/src/app-files.js +2 -2
- package/src/app-files.js.map +1 -1
- package/src/html-entrypoint.js +1 -1
- package/src/html-entrypoint.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/module-resolver.d.ts +9 -7
- package/src/module-resolver.js +77 -71
- package/src/module-resolver.js.map +1 -1
- package/src/portable.js +1 -1
- package/src/portable.js.map +1 -1
- package/src/resolver-loader.d.ts +8 -0
- package/src/resolver-loader.js +48 -0
- package/src/resolver-loader.js.map +1 -0
- package/src/virtual-content.d.ts +6 -1
- package/src/virtual-content.js +107 -3
- package/src/virtual-content.js.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@embroider/core",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.4-unstable.0c7aa66",
|
4
4
|
"private": false,
|
5
5
|
"description": "A build system for EmberJS applications.",
|
6
6
|
"repository": {
|
@@ -23,17 +23,17 @@
|
|
23
23
|
"@babel/core": "^7.14.5",
|
24
24
|
"@babel/parser": "^7.14.5",
|
25
25
|
"@babel/traverse": "^7.14.5",
|
26
|
-
"@embroider/macros": "1.12.
|
27
|
-
"@embroider/shared-internals": "2.2.
|
26
|
+
"@embroider/macros": "1.12.4-unstable.0c7aa66",
|
27
|
+
"@embroider/shared-internals": "2.2.4-unstable.0c7aa66",
|
28
28
|
"assert-never": "^1.2.1",
|
29
|
-
"babel-plugin-ember-template-compilation": "^2.
|
29
|
+
"babel-plugin-ember-template-compilation": "^2.1.1",
|
30
30
|
"broccoli-node-api": "^1.7.0",
|
31
31
|
"broccoli-persistent-filter": "^3.1.2",
|
32
32
|
"broccoli-plugin": "^4.0.7",
|
33
33
|
"broccoli-source": "^3.0.1",
|
34
34
|
"debug": "^4.3.2",
|
35
35
|
"fast-sourcemap-concat": "^1.4.0",
|
36
|
-
"filesize": "^
|
36
|
+
"filesize": "^10.0.7",
|
37
37
|
"fs-extra": "^9.1.0",
|
38
38
|
"fs-tree-diff": "^2.0.1",
|
39
39
|
"handlebars": "^4.7.7",
|
@@ -62,7 +62,7 @@
|
|
62
62
|
"@types/tmp": "^0.1.0",
|
63
63
|
"fixturify": "^2.1.1",
|
64
64
|
"tmp": "^0.1.0",
|
65
|
-
"typescript": "^
|
65
|
+
"typescript": "^5.1.6"
|
66
66
|
},
|
67
67
|
"engines": {
|
68
68
|
"node": "12.* || 14.* || >= 16"
|
package/src/app-files.js
CHANGED
@@ -75,8 +75,8 @@ class AppFiles {
|
|
75
75
|
modifiers.push(relativePath);
|
76
76
|
continue;
|
77
77
|
}
|
78
|
-
if (this.
|
79
|
-
|
78
|
+
if ((podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix)) ||
|
79
|
+
this.handleClassicRouteFile(relativePath)) {
|
80
80
|
continue;
|
81
81
|
}
|
82
82
|
otherAppFiles.push(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;AAU3B,MAAa,QAAQ;IAUnB,YACW,MAAc,EACvB,QAAqB,EACrB,aAA0B,EAC1B,oBAA4B,EAC5B,eAAwB;QAJf,WAAM,GAAN,MAAM,CAAQ;QAMvB,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,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAExC,I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C,IAAI,KAAK,EAAE;gBACT,MAAM,GAAG,KAAK,CAAC;aAChB;iBAAM;gBACL,IAAI,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;gBACvC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACpC,MAAM,GAAG,QAAQ,CAAC;aACnB;SACF;QACD,MAAM,CAAC,IAA2C,CAAC,GAAG,YAAY,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA7LD,4BA6LC","sourcesContent":["import { sep } from 'path';\nimport { Package, AddonPackage } from '@embroider/shared-internals';\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 readonly fastbootFiles: { [appName: string]: { localFilename: string; shadowedFilename: string | undefined } };\n\n constructor(\n readonly engine: Engine,\n appFiles: Set<string>,\n fastbootFiles: Set<string>,\n resolvableExtensions: RegExp,\n podModulePrefix?: string\n ) {\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\n let combinedFiles = new Set<string>();\n let combinedNonFastbootFiles = new Set<string>();\n let isFastbootOnly = new Map<string, boolean>();\n\n for (let f of appFiles) {\n combinedFiles.add(f);\n combinedNonFastbootFiles.add(f);\n }\n for (let f of fastbootFiles) {\n combinedFiles.add(f);\n }\n\n for (let addon of engine.addons) {\n let appJS = addon.meta['app-js'];\n if (appJS) {\n for (let filename of Object.keys(appJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n combinedNonFastbootFiles.add(filename);\n }\n }\n\n let fastbootJS = addon.meta['fastboot-js'];\n if (fastbootJS) {\n for (let filename of Object.keys(fastbootJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n }\n }\n }\n\n for (let relativePath of combinedFiles) {\n isFastbootOnly.set(relativePath, !combinedNonFastbootFiles.has(relativePath));\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 = isFastbootOnly;\n\n // this deliberately only describes the app's fastboot files. Not the full\n // merge from all the addons. This is because they need different handling\n // in the module resolver -- addon fastboot files can always be a\n // fallbackResolve, because if the app happens to define the same name\n // (whether fastboot-specific or just browser) that wins over the addon.\n // Whereas if the app itself defines a fastbot-specific version of a file,\n // that must take precedence over the *normal* resolution, and must be\n // implemented in beforeResolve.\n this.fastbootFiles = Object.fromEntries(\n [...fastbootFiles].map(name => [\n `./${name}`,\n {\n localFilename: `./_fastboot_/${name}`,\n shadowedFilename: appFiles.has(name) ? `./${name}` : undefined,\n },\n ])\n );\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 Engine {\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: Engine | undefined;\n // where the engine's own V2 code comes from\n sourcePath: 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"]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,CAAC,IAAI,CAAC,EAAE;YAChE,OAAO,KAAK,CAAC;SACd;QACD,IAAI,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,8DAA8D;QAC9D,QAAQ,CAAC,KAAK,EAAE,CAAC;QAEjB,KAAK,IAAI,OAAO,IAAI,QAAQ,EAAE;YAC5B,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,OAAO,EAAE;gBAC7B,OAAO,KAAK,CAAC;aACd;SACF;QAED,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC3B,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YACtB,IAAI,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,KAAK,EAAE;gBACT,MAAM,GAAG,KAAK,CAAC;aAChB;iBAAM;gBACL,IAAI,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;gBACvC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACpC,MAAM,GAAG,QAAQ,CAAC;aACnB;SACF;QACD,MAAM,CAAC,IAA2C,CAAC,GAAG,YAAY,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA7LD,4BA6LC","sourcesContent":["import { sep } from 'path';\nimport { Package, AddonPackage } from '@embroider/shared-internals';\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 readonly fastbootFiles: { [appName: string]: { localFilename: string; shadowedFilename: string | undefined } };\n\n constructor(\n readonly engine: Engine,\n appFiles: Set<string>,\n fastbootFiles: Set<string>,\n resolvableExtensions: RegExp,\n podModulePrefix?: string\n ) {\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\n let combinedFiles = new Set<string>();\n let combinedNonFastbootFiles = new Set<string>();\n let isFastbootOnly = new Map<string, boolean>();\n\n for (let f of appFiles) {\n combinedFiles.add(f);\n combinedNonFastbootFiles.add(f);\n }\n for (let f of fastbootFiles) {\n combinedFiles.add(f);\n }\n\n for (let addon of engine.addons) {\n let appJS = addon.meta['app-js'];\n if (appJS) {\n for (let filename of Object.keys(appJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n combinedNonFastbootFiles.add(filename);\n }\n }\n\n let fastbootJS = addon.meta['fastboot-js'];\n if (fastbootJS) {\n for (let filename of Object.keys(fastbootJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n }\n }\n }\n\n for (let relativePath of combinedFiles) {\n isFastbootOnly.set(relativePath, !combinedNonFastbootFiles.has(relativePath));\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 (podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix)) ||\n this.handleClassicRouteFile(relativePath)\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 = isFastbootOnly;\n\n // this deliberately only describes the app's fastboot files. Not the full\n // merge from all the addons. This is because they need different handling\n // in the module resolver -- addon fastboot files can always be a\n // fallbackResolve, because if the app happens to define the same name\n // (whether fastboot-specific or just browser) that wins over the addon.\n // Whereas if the app itself defines a fastbot-specific version of a file,\n // that must take precedence over the *normal* resolution, and must be\n // implemented in beforeResolve.\n this.fastbootFiles = Object.fromEntries(\n [...fastbootFiles].map(name => [\n `./${name}`,\n {\n localFilename: `./_fastboot_/${name}`,\n shadowedFilename: appFiles.has(name) ? `./${name}` : undefined,\n },\n ])\n );\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 Engine {\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: Engine | undefined;\n // where the engine's own V2 code comes from\n sourcePath: 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"]}
|
package/src/html-entrypoint.js
CHANGED
@@ -100,7 +100,7 @@ class HTMLEntrypoint {
|
|
100
100
|
// fastboot always loads scripts from. If there's no
|
101
101
|
// fastboot-specific variant, fastboot loads the base variant, but
|
102
102
|
// still from rootURL rather than publicAssetURL.
|
103
|
-
fastboot = this.rootURL + (fastboot
|
103
|
+
fastboot = this.rootURL + (fastboot !== null && fastboot !== void 0 ? fastboot : base);
|
104
104
|
}
|
105
105
|
if (base) {
|
106
106
|
// the browser version gets prefixed with the publicAssetURL
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"html-entrypoint.js","sourceRoot":"","sources":["html-entrypoint.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0D;AAC1D,uCAAwC;AACxC,+BAA4B;AAC5B,iCAA8B;AAC9B,iEAAyC;AACzC,qDAA6B;AAC7B,0EAA6C;AAG7C,MAAa,cAAc;IAOzB,YACU,gBAAwB,EACxB,OAAe,EACf,cAAsB,EACvB,QAAgB;QAHf,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QATj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EAAE,CAAC;SAC7B;KACF;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,WAAqB,EAAE,WAAwB,EAAE,cAAsB;IAC/F,KAAK,IAAI,MAAM,IAAI,WAAW,EAAE;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC3B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACpE,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC1C,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;SAC7B;KACF;AACH,CAAC","sourcesContent":["import { getOrCreate } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { join } from 'path';\nimport { JSDOM } from 'jsdom';\nimport partition from 'lodash/partition';\nimport zip from 'lodash/zip';\nimport Placeholder from './html-placeholder';\nimport { Variant } from './packager';\n\nexport class HTMLEntrypoint {\n private dom: JSDOM;\n private placeholders: Map<string, Placeholder[]> = new Map();\n modules: string[] = [];\n scripts: string[] = [];\n styles: string[] = [];\n\n constructor(\n private pathToVanillaApp: string,\n private rootURL: string,\n private publicAssetURL: string,\n public filename: string\n ) {\n this.dom = new JSDOM(readFileSync(join(this.pathToVanillaApp, this.filename), 'utf8'));\n\n for (let tag of this.handledStyles()) {\n let styleTag = tag as HTMLLinkElement;\n let href = styleTag.href;\n if (!isAbsoluteURL(href)) {\n let url = this.relativeToApp(href);\n this.styles.push(url);\n let placeholder = new Placeholder(styleTag);\n let list = getOrCreate(this.placeholders, url, () => []);\n list.push(placeholder);\n }\n }\n\n for (let scriptTag of this.handledScripts()) {\n // scriptTag.src include rootURL. Convert it to be relative to the app.\n let src = this.relativeToApp(scriptTag.src);\n\n if (scriptTag.type === 'module') {\n this.modules.push(src);\n } else {\n this.scripts.push(src);\n }\n\n let placeholder = new Placeholder(scriptTag);\n let list = getOrCreate(this.placeholders, src, () => []);\n list.push(placeholder);\n }\n }\n\n private relativeToApp(rootRelativeURL: string) {\n return rootRelativeURL.replace(this.rootURL, '');\n }\n\n private handledScripts() {\n let scriptTags = [...this.dom.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n let [ignoredScriptTags, handledScriptTags] = partition(scriptTags, scriptTag => {\n return !scriptTag.src || scriptTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(scriptTag.src);\n });\n for (let scriptTag of ignoredScriptTags) {\n scriptTag.removeAttribute('data-embroider-ignore');\n }\n return handledScriptTags;\n }\n\n private handledStyles() {\n let styleTags = [...this.dom.window.document.querySelectorAll('link[rel=\"stylesheet\"]')] as HTMLLinkElement[];\n let [ignoredStyleTags, handledStyleTags] = partition(styleTags, styleTag => {\n return !styleTag.href || styleTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(styleTag.href);\n });\n for (let styleTag of ignoredStyleTags) {\n styleTag.removeAttribute('data-embroider-ignore');\n }\n return handledStyleTags;\n }\n\n // bundles maps from input asset to a per-variant map of output assets\n render(stats: BundleSummary): string {\n let insertedLazy = new Set<string>();\n let fastbootVariant = stats.variants.findIndex(v => Boolean(v.runtime === 'fastboot'));\n let supportsFastboot = stats.variants.some(v => v.runtime === 'fastboot' || v.runtime === 'all');\n\n for (let [src, placeholders] of this.placeholders) {\n let match = stats.entrypoints.get(src);\n if (match) {\n let firstVariant = stats.variants.findIndex((_, index) => Boolean(match!.get(index)));\n let matchingBundles = match.get(firstVariant)!;\n let matchingFastbootBundles = fastbootVariant >= 0 ? match.get(fastbootVariant) || [] : [];\n\n for (let placeholder of placeholders) {\n placeholder.clear();\n if (supportsFastboot && placeholder.isScript()) {\n // if there is any fastboot involved, we will emit the lazy bundles\n // right before our first script.\n\n let lazyMatch = stats.lazyBundles.get(src);\n if (lazyMatch && !insertedLazy.has(src)) {\n insertLazyJavascript(lazyMatch, placeholder, this.rootURL);\n insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);\n insertedLazy.add(src);\n }\n }\n for (let [base, fastboot] of zip(matchingBundles, matchingFastbootBundles)) {\n if (supportsFastboot) {\n // the fastboot version gets prefixed with the rootURL, which\n // points to our local build directory, because that's where\n // fastboot always loads scripts from. If there's no\n // fastboot-specific variant, fastboot loads the base variant, but\n // still from rootURL rather than publicAssetURL.\n fastboot = this.rootURL + (fastboot ?? base);\n }\n\n if (base) {\n // the browser version gets prefixed with the publicAssetURL\n // because that's where browsers will load it from\n base = this.publicAssetURL + base;\n }\n\n if (!base) {\n // this bundle only exists in the fastboot variant\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', fastboot!);\n placeholder.insert(element);\n placeholder.insertNewline();\n } else if (!fastboot) {\n // no fastboot variant\n placeholder.insertURL(base);\n } else if (fastboot === base) {\n // fastboot variant happens to be exactly the same bundle as base\n // (and publicAssetURL===rootURL), so a plain script tag covers\n // both\n placeholder.insertURL(base);\n } else {\n // we have both and they differ\n let element = placeholder.insertURL(base);\n if (element) {\n element.setAttribute('data-fastboot-src', fastboot);\n }\n }\n }\n }\n } else {\n // no match means keep the original HTML content for this placeholder.\n // (If we really wanted it empty instead, there would be matchingBundles\n // and it would be an empty list.)\n for (let placeholder of placeholders) {\n placeholder.reset();\n }\n }\n }\n return this.dom.serialize();\n }\n}\n\nexport interface BundleSummary {\n // entrypoints.get(inputAsset).get(variantIndex) === outputAssets\n //\n // these are the output assets that are needed eagerly to boot the given input\n // asset\n entrypoints: Map<string, Map<number, string[]>>;\n\n // lazyBundles.get(inputAsset) === lazyOutputAssets\n //\n // these are the output assets that might be loaded lazyily at runtime by the\n // given input asset.\n //\n // These are tracked specifically for the fastboot variant, because that's\n // where we need to be responsble for them.\n lazyBundles: Map<string, string[]>;\n\n variants: Variant[];\n}\n\nfunction isAbsoluteURL(url: string) {\n return /^(?:[a-z]+:)?\\/\\//i.test(url);\n}\n\n// we (somewhat arbitrarily) decide to put the lazy javascript bundles before\n// the very first <script> that we have rewritten\nfunction insertLazyJavascript(lazyBundles: string[], placeholder: Placeholder, rootURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.js')) {\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n // we're using rootURL instead of publicAssetURL here because\n // <fastboot-script> is executed by fastboot, which always loads them from\n // the local build directory. NOT from the publicAssetURL that browsers\n // will use, which could be a CDN.\n element.setAttribute('src', rootURL + bundle);\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n\nfunction insertLazyStyles(lazyBundles: string[], placeholder: Placeholder, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.css')) {\n let element = placeholder.start.ownerDocument.createElement('link');\n element.setAttribute('href', publicAssetURL + bundle);\n element.setAttribute('rel', 'stylesheet');\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"html-entrypoint.js","sourceRoot":"","sources":["html-entrypoint.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0D;AAC1D,uCAAwC;AACxC,+BAA4B;AAC5B,iCAA8B;AAC9B,iEAAyC;AACzC,qDAA6B;AAC7B,0EAA6C;AAG7C,MAAa,cAAc;IAOzB,YACU,gBAAwB,EACxB,OAAe,EACf,cAAsB,EACvB,QAAgB;QAHf,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QATjB,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAC7D,YAAO,GAAa,EAAE,CAAC;QACvB,YAAO,GAAa,EAAE,CAAC;QACvB,WAAM,GAAa,EAAE,CAAC;QAQpB,IAAI,CAAC,GAAG,GAAG,IAAI,aAAK,CAAC,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAA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C3B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACpE,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC1C,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;SAC7B;KACF;AACH,CAAC","sourcesContent":["import { getOrCreate } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { join } from 'path';\nimport { JSDOM } from 'jsdom';\nimport partition from 'lodash/partition';\nimport zip from 'lodash/zip';\nimport Placeholder from './html-placeholder';\nimport { Variant } from './packager';\n\nexport class HTMLEntrypoint {\n private dom: JSDOM;\n private placeholders: Map<string, Placeholder[]> = new Map();\n modules: string[] = [];\n scripts: string[] = [];\n styles: string[] = [];\n\n constructor(\n private pathToVanillaApp: string,\n private rootURL: string,\n private publicAssetURL: string,\n public filename: string\n ) {\n this.dom = new JSDOM(readFileSync(join(this.pathToVanillaApp, this.filename), 'utf8'));\n\n for (let tag of this.handledStyles()) {\n let styleTag = tag as HTMLLinkElement;\n let href = styleTag.href;\n if (!isAbsoluteURL(href)) {\n let url = this.relativeToApp(href);\n this.styles.push(url);\n let placeholder = new Placeholder(styleTag);\n let list = getOrCreate(this.placeholders, url, () => []);\n list.push(placeholder);\n }\n }\n\n for (let scriptTag of this.handledScripts()) {\n // scriptTag.src include rootURL. Convert it to be relative to the app.\n let src = this.relativeToApp(scriptTag.src);\n\n if (scriptTag.type === 'module') {\n this.modules.push(src);\n } else {\n this.scripts.push(src);\n }\n\n let placeholder = new Placeholder(scriptTag);\n let list = getOrCreate(this.placeholders, src, () => []);\n list.push(placeholder);\n }\n }\n\n private relativeToApp(rootRelativeURL: string) {\n return rootRelativeURL.replace(this.rootURL, '');\n }\n\n private handledScripts() {\n let scriptTags = [...this.dom.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n let [ignoredScriptTags, handledScriptTags] = partition(scriptTags, scriptTag => {\n return !scriptTag.src || scriptTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(scriptTag.src);\n });\n for (let scriptTag of ignoredScriptTags) {\n scriptTag.removeAttribute('data-embroider-ignore');\n }\n return handledScriptTags;\n }\n\n private handledStyles() {\n let styleTags = [...this.dom.window.document.querySelectorAll('link[rel=\"stylesheet\"]')] as HTMLLinkElement[];\n let [ignoredStyleTags, handledStyleTags] = partition(styleTags, styleTag => {\n return !styleTag.href || styleTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(styleTag.href);\n });\n for (let styleTag of ignoredStyleTags) {\n styleTag.removeAttribute('data-embroider-ignore');\n }\n return handledStyleTags;\n }\n\n // bundles maps from input asset to a per-variant map of output assets\n render(stats: BundleSummary): string {\n let insertedLazy = new Set<string>();\n let fastbootVariant = stats.variants.findIndex(v => Boolean(v.runtime === 'fastboot'));\n let supportsFastboot = stats.variants.some(v => v.runtime === 'fastboot' || v.runtime === 'all');\n\n for (let [src, placeholders] of this.placeholders) {\n let match = stats.entrypoints.get(src);\n if (match) {\n let firstVariant = stats.variants.findIndex((_, index) => Boolean(match!.get(index)));\n let matchingBundles = match.get(firstVariant)!;\n let matchingFastbootBundles = fastbootVariant >= 0 ? match.get(fastbootVariant) || [] : [];\n\n for (let placeholder of placeholders) {\n placeholder.clear();\n if (supportsFastboot && placeholder.isScript()) {\n // if there is any fastboot involved, we will emit the lazy bundles\n // right before our first script.\n\n let lazyMatch = stats.lazyBundles.get(src);\n if (lazyMatch && !insertedLazy.has(src)) {\n insertLazyJavascript(lazyMatch, placeholder, this.rootURL);\n insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);\n insertedLazy.add(src);\n }\n }\n for (let [base, fastboot] of zip(matchingBundles, matchingFastbootBundles)) {\n if (supportsFastboot) {\n // the fastboot version gets prefixed with the rootURL, which\n // points to our local build directory, because that's where\n // fastboot always loads scripts from. If there's no\n // fastboot-specific variant, fastboot loads the base variant, but\n // still from rootURL rather than publicAssetURL.\n fastboot = this.rootURL + (fastboot ?? base);\n }\n\n if (base) {\n // the browser version gets prefixed with the publicAssetURL\n // because that's where browsers will load it from\n base = this.publicAssetURL + base;\n }\n\n if (!base) {\n // this bundle only exists in the fastboot variant\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', fastboot!);\n placeholder.insert(element);\n placeholder.insertNewline();\n } else if (!fastboot) {\n // no fastboot variant\n placeholder.insertURL(base);\n } else if (fastboot === base) {\n // fastboot variant happens to be exactly the same bundle as base\n // (and publicAssetURL===rootURL), so a plain script tag covers\n // both\n placeholder.insertURL(base);\n } else {\n // we have both and they differ\n let element = placeholder.insertURL(base);\n if (element) {\n element.setAttribute('data-fastboot-src', fastboot);\n }\n }\n }\n }\n } else {\n // no match means keep the original HTML content for this placeholder.\n // (If we really wanted it empty instead, there would be matchingBundles\n // and it would be an empty list.)\n for (let placeholder of placeholders) {\n placeholder.reset();\n }\n }\n }\n return this.dom.serialize();\n }\n}\n\nexport interface BundleSummary {\n // entrypoints.get(inputAsset).get(variantIndex) === outputAssets\n //\n // these are the output assets that are needed eagerly to boot the given input\n // asset\n entrypoints: Map<string, Map<number, string[]>>;\n\n // lazyBundles.get(inputAsset) === lazyOutputAssets\n //\n // these are the output assets that might be loaded lazyily at runtime by the\n // given input asset.\n //\n // These are tracked specifically for the fastboot variant, because that's\n // where we need to be responsble for them.\n lazyBundles: Map<string, string[]>;\n\n variants: Variant[];\n}\n\nfunction isAbsoluteURL(url: string) {\n return /^(?:[a-z]+:)?\\/\\//i.test(url);\n}\n\n// we (somewhat arbitrarily) decide to put the lazy javascript bundles before\n// the very first <script> that we have rewritten\nfunction insertLazyJavascript(lazyBundles: string[], placeholder: Placeholder, rootURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.js')) {\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n // we're using rootURL instead of publicAssetURL here because\n // <fastboot-script> is executed by fastboot, which always loads them from\n // the local build directory. NOT from the publicAssetURL that browsers\n // will use, which could be a CDN.\n element.setAttribute('src', rootURL + bundle);\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n\nfunction insertLazyStyles(lazyBundles: string[], placeholder: Placeholder, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.css')) {\n let element = placeholder.start.ownerDocument.createElement('link');\n element.setAttribute('href', publicAssetURL + bundle);\n element.setAttribute('rel', 'stylesheet');\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
@@ -8,6 +8,7 @@ export { default as WaitForTrees, OutputPaths } from './wait-for-trees';
|
|
8
8
|
export { compile as jsHandlebarsCompile } from './js-handlebars';
|
9
9
|
export { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';
|
10
10
|
export { Resolver, Options as ResolverOptions, ModuleRequest, Resolution, ResolverFunction, SyncResolverFunction, } from './module-resolver';
|
11
|
+
export { ResolverLoader } from './resolver-loader';
|
11
12
|
export { virtualContent } from './virtual-content';
|
12
13
|
export type { Engine } from './app-files';
|
13
14
|
export * from '@embroider/shared-internals';
|
package/src/index.js
CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
18
|
};
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
-
exports.virtualContent = exports.Resolver = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.jsHandlebarsCompile = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.HTMLEntrypoint = exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
20
|
+
exports.virtualContent = exports.ResolverLoader = exports.Resolver = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.jsHandlebarsCompile = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.HTMLEntrypoint = exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
21
21
|
var packager_1 = require("./packager");
|
22
22
|
Object.defineProperty(exports, "applyVariantToBabelConfig", { enumerable: true, get: function () { return packager_1.applyVariantToBabelConfig; } });
|
23
23
|
Object.defineProperty(exports, "getAppMeta", { enumerable: true, get: function () { return packager_1.getAppMeta; } });
|
@@ -41,6 +41,8 @@ Object.defineProperty(exports, "expectWarning", { enumerable: true, get: functio
|
|
41
41
|
Object.defineProperty(exports, "throwOnWarnings", { enumerable: true, get: function () { return messages_1.throwOnWarnings; } });
|
42
42
|
var module_resolver_1 = require("./module-resolver");
|
43
43
|
Object.defineProperty(exports, "Resolver", { enumerable: true, get: function () { return module_resolver_1.Resolver; } });
|
44
|
+
var resolver_loader_1 = require("./resolver-loader");
|
45
|
+
Object.defineProperty(exports, "ResolverLoader", { enumerable: true, get: function () { return resolver_loader_1.ResolverLoader; } });
|
44
46
|
var virtual_content_1 = require("./virtual-content");
|
45
47
|
Object.defineProperty(exports, "virtualContent", { enumerable: true, get: function () { return virtual_content_1.virtualContent; } });
|
46
48
|
// this is reexported because we already make users manage a peerDep from some
|
package/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAOoB;AAHlB,qHAAA,yBAAyB,OAAA;AACzB,sGAAA,UAAU,OAAA;AACV,+GAAA,mBAAmB,OAAA;AAErB,qDAAkE;AAAzD,iHAAA,cAAc,OAAA;AAGvB,qCAAoE;AAAvC,8GAAA,mBAAmB,OAAA;AAChD,2DAAmE;AAA1D,uIAAA,OAAO,OAAoB;AACpC,mDAAwE;AAA/D,+HAAA,OAAO,OAAgB;AAChC,iDAAiE;AAAxD,oHAAA,OAAO,OAAuB;AACvC,uCAA4F;AAAnF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,gGAAA,IAAI,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,2GAAA,eAAe,OAAA;AACvE,qDAO2B;AANzB,2GAAA,QAAQ,OAAA;AAOV,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,8EAA8E;AAC9E,+DAA+D;AAC/D,8DAA4C","sourcesContent":["export {\n Packager,\n PackagerConstructor,\n Variant,\n applyVariantToBabelConfig,\n getAppMeta,\n getPackagerCacheDir,\n} from './packager';\nexport { HTMLEntrypoint, BundleSummary } from './html-entrypoint';\nexport { default as Stage } from './stage';\nexport { Asset, EmberAsset, ImplicitAssetPaths } from './asset';\nexport { default as Options, optionsWithDefaults } from './options';\nexport { default as toBroccoliPlugin } from './to-broccoli-plugin';\nexport { default as WaitForTrees, OutputPaths } from './wait-for-trees';\nexport { compile as jsHandlebarsCompile } from './js-handlebars';\nexport { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';\nexport {\n Resolver,\n Options as ResolverOptions,\n ModuleRequest,\n Resolution,\n ResolverFunction,\n SyncResolverFunction,\n} from './module-resolver';\nexport { virtualContent } from './virtual-content';\nexport type { Engine } from './app-files';\n\n// this is reexported because we already make users manage a peerDep from some\n// other packages (like embroider/webpack and @embroider/compat\nexport * from '@embroider/shared-internals';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAOoB;AAHlB,qHAAA,yBAAyB,OAAA;AACzB,sGAAA,UAAU,OAAA;AACV,+GAAA,mBAAmB,OAAA;AAErB,qDAAkE;AAAzD,iHAAA,cAAc,OAAA;AAGvB,qCAAoE;AAAvC,8GAAA,mBAAmB,OAAA;AAChD,2DAAmE;AAA1D,uIAAA,OAAO,OAAoB;AACpC,mDAAwE;AAA/D,+HAAA,OAAO,OAAgB;AAChC,iDAAiE;AAAxD,oHAAA,OAAO,OAAuB;AACvC,uCAA4F;AAAnF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,gGAAA,IAAI,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,2GAAA,eAAe,OAAA;AACvE,qDAO2B;AANzB,2GAAA,QAAQ,OAAA;AAOV,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,8EAA8E;AAC9E,+DAA+D;AAC/D,8DAA4C","sourcesContent":["export {\n Packager,\n PackagerConstructor,\n Variant,\n applyVariantToBabelConfig,\n getAppMeta,\n getPackagerCacheDir,\n} from './packager';\nexport { HTMLEntrypoint, BundleSummary } from './html-entrypoint';\nexport { default as Stage } from './stage';\nexport { Asset, EmberAsset, ImplicitAssetPaths } from './asset';\nexport { default as Options, optionsWithDefaults } from './options';\nexport { default as toBroccoliPlugin } from './to-broccoli-plugin';\nexport { default as WaitForTrees, OutputPaths } from './wait-for-trees';\nexport { compile as jsHandlebarsCompile } from './js-handlebars';\nexport { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';\nexport {\n Resolver,\n Options as ResolverOptions,\n ModuleRequest,\n Resolution,\n ResolverFunction,\n SyncResolverFunction,\n} from './module-resolver';\nexport { ResolverLoader } from './resolver-loader';\nexport { virtualContent } from './virtual-content';\nexport type { Engine } from './app-files';\n\n// this is reexported because we already make users manage a peerDep from some\n// other packages (like embroider/webpack and @embroider/compat\nexport * from '@embroider/shared-internals';\n"]}
|
package/src/module-resolver.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Package } from '@embroider/shared-internals';
|
1
|
+
import { Package, RewrittenPackageCache } from '@embroider/shared-internals';
|
2
2
|
export interface Options {
|
3
3
|
renamePackages: {
|
4
4
|
[fromName: string]: string;
|
@@ -30,12 +30,14 @@ interface EngineConfig {
|
|
30
30
|
root: string;
|
31
31
|
}
|
32
32
|
export interface ModuleRequest {
|
33
|
-
specifier: string;
|
34
|
-
fromFile: string;
|
35
|
-
isVirtual: boolean;
|
33
|
+
readonly specifier: string;
|
34
|
+
readonly fromFile: string;
|
35
|
+
readonly isVirtual: boolean;
|
36
|
+
readonly meta: Record<string, unknown> | undefined;
|
36
37
|
alias(newSpecifier: string): this;
|
37
38
|
rehome(newFromFile: string): this;
|
38
39
|
virtualize(virtualFilename: string): this;
|
40
|
+
withMeta(meta: Record<string, any> | undefined): this;
|
39
41
|
}
|
40
42
|
export type Resolution<T = unknown, E = unknown> = {
|
41
43
|
type: 'found';
|
@@ -47,7 +49,7 @@ export type Resolution<T = unknown, E = unknown> = {
|
|
47
49
|
export type ResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Promise<Res>;
|
48
50
|
export type SyncResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Res;
|
49
51
|
export declare class Resolver {
|
50
|
-
|
52
|
+
readonly options: Options;
|
51
53
|
constructor(options: Options);
|
52
54
|
beforeResolve<R extends ModuleRequest>(request: R): R;
|
53
55
|
resolve<Req extends ModuleRequest, Res extends Resolution>(request: Req, defaultResolve: ResolverFunction<Req, Res>): Promise<Res>;
|
@@ -64,11 +66,11 @@ export declare class Resolver {
|
|
64
66
|
type: 'not_found';
|
65
67
|
err: Error;
|
66
68
|
};
|
67
|
-
|
68
|
-
owningPackage(fromFile: string): Package | undefined;
|
69
|
+
get packageCache(): RewrittenPackageCache;
|
69
70
|
private logicalPackage;
|
70
71
|
private generateFastbootSwitch;
|
71
72
|
private handleFastbootSwitch;
|
73
|
+
private handleImplicitModules;
|
72
74
|
private handleGlobalsCompat;
|
73
75
|
private resolveHelper;
|
74
76
|
private resolveComponent;
|
package/src/module-resolver.js
CHANGED
@@ -43,24 +43,28 @@ function logTransition(reason, before, after = before) {
|
|
43
43
|
}
|
44
44
|
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
45
45
|
class NodeModuleRequest {
|
46
|
-
constructor(specifier, fromFile, isVirtual
|
46
|
+
constructor(specifier, fromFile, isVirtual, meta) {
|
47
47
|
this.specifier = specifier;
|
48
48
|
this.fromFile = fromFile;
|
49
49
|
this.isVirtual = isVirtual;
|
50
|
+
this.meta = meta;
|
50
51
|
}
|
51
52
|
alias(specifier) {
|
52
|
-
return new NodeModuleRequest(specifier, this.fromFile);
|
53
|
+
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
|
53
54
|
}
|
54
55
|
rehome(fromFile) {
|
55
56
|
if (this.fromFile === fromFile) {
|
56
57
|
return this;
|
57
58
|
}
|
58
59
|
else {
|
59
|
-
return new NodeModuleRequest(this.specifier, fromFile);
|
60
|
+
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
|
60
61
|
}
|
61
62
|
}
|
62
63
|
virtualize(filename) {
|
63
|
-
return new NodeModuleRequest(filename, this.fromFile, true);
|
64
|
+
return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
|
65
|
+
}
|
66
|
+
withMeta(meta) {
|
67
|
+
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
|
64
68
|
}
|
65
69
|
}
|
66
70
|
class Resolver {
|
@@ -77,6 +81,7 @@ class Resolver {
|
|
77
81
|
}
|
78
82
|
request = this.handleFastbootSwitch(request);
|
79
83
|
request = this.handleGlobalsCompat(request);
|
84
|
+
request = this.handleImplicitModules(request);
|
80
85
|
request = this.handleRenaming(request);
|
81
86
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
82
87
|
request = this.generateFastbootSwitch(request);
|
@@ -144,13 +149,13 @@ class Resolver {
|
|
144
149
|
// top. This is a convenience method for calling resolveSync with the
|
145
150
|
// defaultResolve already configured to be "do the normal node thing".
|
146
151
|
nodeResolve(specifier, fromFile) {
|
147
|
-
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile), request => {
|
152
|
+
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
|
148
153
|
if (request.isVirtual) {
|
149
154
|
return {
|
150
155
|
type: 'found',
|
151
156
|
result: {
|
152
157
|
type: 'virtual',
|
153
|
-
content: (0, virtual_content_1.virtualContent)(request.specifier),
|
158
|
+
content: (0, virtual_content_1.virtualContent)(request.specifier, this),
|
154
159
|
filename: request.specifier,
|
155
160
|
},
|
156
161
|
};
|
@@ -181,9 +186,6 @@ class Resolver {
|
|
181
186
|
get packageCache() {
|
182
187
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
183
188
|
}
|
184
|
-
owningPackage(fromFile) {
|
185
|
-
return this.packageCache.ownerOfFile(fromFile);
|
186
|
-
}
|
187
189
|
logicalPackage(owningPackage, file) {
|
188
190
|
let logicalLocation = this.reverseSearchAppTree(owningPackage, file);
|
189
191
|
if (logicalLocation) {
|
@@ -196,7 +198,7 @@ class Resolver {
|
|
196
198
|
return owningPackage;
|
197
199
|
}
|
198
200
|
generateFastbootSwitch(request) {
|
199
|
-
let pkg = this.
|
201
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
200
202
|
if (!pkg) {
|
201
203
|
return request;
|
202
204
|
}
|
@@ -231,6 +233,7 @@ class Resolver {
|
|
231
233
|
return request;
|
232
234
|
}
|
233
235
|
handleFastbootSwitch(request) {
|
236
|
+
var _a;
|
234
237
|
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile);
|
235
238
|
if (!match) {
|
236
239
|
return request;
|
@@ -245,7 +248,7 @@ class Resolver {
|
|
245
248
|
if (!section) {
|
246
249
|
return logTransition('non-special import in fastboot switch', request);
|
247
250
|
}
|
248
|
-
let pkg = this.
|
251
|
+
let pkg = this.packageCache.ownerOfFile(match.filename);
|
249
252
|
if (pkg) {
|
250
253
|
let rel = (0, shared_internals_2.explicitRelative)(pkg.root, match.filename);
|
251
254
|
let engineConfig = this.engineConfig(pkg.name);
|
@@ -267,21 +270,39 @@ class Resolver {
|
|
267
270
|
request.alias((0, shared_internals_2.explicitRelative)((0, path_1.dirname)(request.fromFile), (0, path_1.resolve)(pkg.root, targetFile))));
|
268
271
|
}
|
269
272
|
}
|
270
|
-
let entry = this.getEntryFromMergeMap(rel, pkg.root)
|
271
|
-
if (entry
|
273
|
+
let entry = (_a = this.getEntryFromMergeMap(rel, pkg.root)) === null || _a === void 0 ? void 0 : _a.entry;
|
274
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') {
|
272
275
|
return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json')));
|
273
276
|
}
|
274
277
|
}
|
275
278
|
return logTransition('failed to match in fastboot switch', request);
|
276
279
|
}
|
280
|
+
handleImplicitModules(request) {
|
281
|
+
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
282
|
+
if (!im) {
|
283
|
+
return request;
|
284
|
+
}
|
285
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
286
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
287
|
+
throw new Error(`bug: found implicit modules import in non-ember package at ${request.fromFile}`);
|
288
|
+
}
|
289
|
+
let packageName = (0, shared_internals_1.packageName)(im.fromFile);
|
290
|
+
if (packageName) {
|
291
|
+
let dep = this.packageCache.resolve(packageName, pkg);
|
292
|
+
return logTransition(`dep's implicit modules`, request, request.virtualize((0, path_1.resolve)(dep.root, `#embroider-${im.type}`)));
|
293
|
+
}
|
294
|
+
else {
|
295
|
+
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `#embroider-${im.type}`)));
|
296
|
+
}
|
297
|
+
}
|
277
298
|
handleGlobalsCompat(request) {
|
278
299
|
let match = compatPattern.exec(request.specifier);
|
279
300
|
if (!match) {
|
280
301
|
return request;
|
281
302
|
}
|
282
303
|
let { type, rest } = match.groups;
|
283
|
-
let fromPkg = this.
|
284
|
-
if (!fromPkg
|
304
|
+
let fromPkg = this.packageCache.ownerOfFile(request.fromFile);
|
305
|
+
if (!(fromPkg === null || fromPkg === void 0 ? void 0 : fromPkg.isV2Ember())) {
|
285
306
|
return request;
|
286
307
|
}
|
287
308
|
let engine = this.owningEngine(fromPkg);
|
@@ -420,7 +441,7 @@ class Resolver {
|
|
420
441
|
throw new Error(`addon ${addon.name} declares app-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
421
442
|
}
|
422
443
|
let prevEntry = engineModules.get(inEngineName);
|
423
|
-
switch (prevEntry
|
444
|
+
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
424
445
|
case undefined:
|
425
446
|
engineModules.set(inEngineName, {
|
426
447
|
type: 'app-only',
|
@@ -459,7 +480,7 @@ class Resolver {
|
|
459
480
|
throw new Error(`addon ${addon.name} declares fastboot-js in its package.json with the illegal name "${inAddonName}". It must start with "./" to make it clear that it's relative to the addon`);
|
460
481
|
}
|
461
482
|
let prevEntry = engineModules.get(inEngineName);
|
462
|
-
switch (prevEntry
|
483
|
+
switch (prevEntry === null || prevEntry === void 0 ? void 0 : prevEntry.type) {
|
463
484
|
case undefined:
|
464
485
|
engineModules.set(inEngineName, {
|
465
486
|
type: 'fastboot-only',
|
@@ -501,7 +522,7 @@ class Resolver {
|
|
501
522
|
return owningEngine;
|
502
523
|
}
|
503
524
|
handleRewrittenPackages(request) {
|
504
|
-
let requestingPkg = this.
|
525
|
+
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
505
526
|
if (!requestingPkg) {
|
506
527
|
return request;
|
507
528
|
}
|
@@ -538,7 +559,7 @@ class Resolver {
|
|
538
559
|
else if (originalRequestingPkg) {
|
539
560
|
// in this case, the requesting package is moved but its destination is
|
540
561
|
// not, so we need to rehome the request back to the original location.
|
541
|
-
return logTransition('outbound request from moved package', request, request.rehome((0, path_1.resolve)(originalRequestingPkg.root,
|
562
|
+
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
542
563
|
}
|
543
564
|
return request;
|
544
565
|
}
|
@@ -550,25 +571,31 @@ class Resolver {
|
|
550
571
|
if (!packageName) {
|
551
572
|
return request;
|
552
573
|
}
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
574
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
575
|
+
if (!pkg || !pkg.isV2Ember()) {
|
576
|
+
return request;
|
577
|
+
}
|
578
|
+
// real deps take precedence over renaming rules. That is, a package like
|
579
|
+
// ember-source might provide backburner via module renaming, but if you
|
580
|
+
// have an explicit dependency on backburner you should still get that real
|
581
|
+
// copy.
|
582
|
+
if (!pkg.hasDependency(packageName)) {
|
583
|
+
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) {
|
584
|
+
if (candidate === request.specifier) {
|
559
585
|
return logTransition(`renameModules`, request, request.alias(replacement));
|
560
586
|
}
|
561
|
-
|
562
|
-
|
587
|
+
for (let extension of this.options.resolvableExtensions) {
|
588
|
+
if (candidate === request.specifier + '/index' + extension) {
|
589
|
+
return logTransition(`renameModules`, request, request.alias(replacement));
|
590
|
+
}
|
591
|
+
if (candidate === request.specifier + extension) {
|
592
|
+
return logTransition(`renameModules`, request, request.alias(replacement));
|
593
|
+
}
|
563
594
|
}
|
564
595
|
}
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
}
|
569
|
-
let pkg = this.owningPackage(request.fromFile);
|
570
|
-
if (!pkg || !pkg.isV2Ember()) {
|
571
|
-
return request;
|
596
|
+
if (this.options.renamePackages[packageName]) {
|
597
|
+
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
598
|
+
}
|
572
599
|
}
|
573
600
|
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {
|
574
601
|
// we found a self-import, resolve it for them. Only auto-upgraded
|
@@ -596,7 +623,7 @@ class Resolver {
|
|
596
623
|
return request;
|
597
624
|
}
|
598
625
|
let { specifier, fromFile } = request;
|
599
|
-
let pkg = this.
|
626
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
600
627
|
if (!pkg || !pkg.isV2Ember()) {
|
601
628
|
return request;
|
602
629
|
}
|
@@ -637,19 +664,9 @@ class Resolver {
|
|
637
664
|
if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
|
638
665
|
return external('beforeResolve emberVirtualPackages', request, specifier);
|
639
666
|
}
|
640
|
-
if (
|
641
|
-
//
|
642
|
-
//
|
643
|
-
// see those dependencies after those dependencies have been converted to
|
644
|
-
// v2.
|
645
|
-
//
|
646
|
-
// But unlike auto-upgraded addons, native v2 addons are not necessarily
|
647
|
-
// copied out of their original place in node_modules. And from that
|
648
|
-
// original place they might accidentally resolve the emberVirtualPeerDeps
|
649
|
-
// that are present there in v1 format.
|
650
|
-
//
|
651
|
-
// So before we let normal resolving happen, we adjust these imports to
|
652
|
-
// point at the app's copies instead.
|
667
|
+
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
668
|
+
// addons (whether auto-upgraded or not) may use the app's
|
669
|
+
// emberVirtualPeerDeps, like "@glimmer/component" etc.
|
653
670
|
if (!this.options.activeAddons[packageName]) {
|
654
671
|
throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);
|
655
672
|
}
|
@@ -686,6 +703,7 @@ class Resolver {
|
|
686
703
|
return request;
|
687
704
|
}
|
688
705
|
fallbackResolve(request) {
|
706
|
+
var _a;
|
689
707
|
let { specifier, fromFile } = request;
|
690
708
|
if (compatPattern.test(specifier)) {
|
691
709
|
// Some kinds of compat requests get rewritten into other things
|
@@ -703,7 +721,7 @@ class Resolver {
|
|
703
721
|
// here.
|
704
722
|
return request;
|
705
723
|
}
|
706
|
-
let pkg = this.
|
724
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
707
725
|
if (!pkg) {
|
708
726
|
return logTransition('no identifiable owningPackage', request);
|
709
727
|
}
|
@@ -713,7 +731,10 @@ class Resolver {
|
|
713
731
|
// isV2Ember()
|
714
732
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
715
733
|
if (movedPkg !== pkg) {
|
716
|
-
|
734
|
+
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.wasMovedTo)) {
|
735
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
736
|
+
}
|
737
|
+
fromFile = request.meta.wasMovedTo;
|
717
738
|
pkg = movedPkg;
|
718
739
|
}
|
719
740
|
if (!pkg.isV2Ember()) {
|
@@ -735,22 +756,6 @@ class Resolver {
|
|
735
756
|
}
|
736
757
|
}
|
737
758
|
else {
|
738
|
-
if (pkg.meta['auto-upgraded'] && (0, path_1.dirname)(request.fromFile) === pkg.root) {
|
739
|
-
let otherRoot = this.options.activeAddons[pkg.name];
|
740
|
-
if (otherRoot && otherRoot !== pkg.root) {
|
741
|
-
// This provides some backward-compatibility with the way things
|
742
|
-
// would have resolved in earlier embroider versions, where the
|
743
|
-
// final fallback was always the activeAddons. These requests now
|
744
|
-
// end up getting converted to relative requests inside a particular
|
745
|
-
// moved package, which is why we need to handle them here.
|
746
|
-
//
|
747
|
-
// TODO: We shouldn't need this if we generate notional per-package
|
748
|
-
// entrypoints that pull in all the implicit-modules, so that the
|
749
|
-
// imports for implicit-modules happen in places with normal
|
750
|
-
// dependency resolvability.
|
751
|
-
return logTransition('fallbackResolve: relative path falling through to activeAddons', request, request.rehome((0, path_1.resolve)(otherRoot, 'package.json')));
|
752
|
-
}
|
753
|
-
}
|
754
759
|
// nothing else to do for relative imports
|
755
760
|
return logTransition('fallbackResolve: relative failure', request);
|
756
761
|
}
|
@@ -797,9 +802,10 @@ class Resolver {
|
|
797
802
|
return logTransition('fallbackResolve final exit', request);
|
798
803
|
}
|
799
804
|
getEntryFromMergeMap(inEngineSpecifier, root) {
|
805
|
+
var _a;
|
800
806
|
let entry;
|
801
807
|
for (let candidate of this.withResolvableExtensions(inEngineSpecifier)) {
|
802
|
-
entry = this.mergeMap.get(root)
|
808
|
+
entry = (_a = this.mergeMap.get(root)) === null || _a === void 0 ? void 0 : _a.get(candidate);
|
803
809
|
if (entry) {
|
804
810
|
return { entry, matched: candidate };
|
805
811
|
}
|
@@ -817,7 +823,7 @@ class Resolver {
|
|
817
823
|
}
|
818
824
|
searchAppTree(request, engine, inEngineSpecifier) {
|
819
825
|
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root);
|
820
|
-
switch (matched
|
826
|
+
switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) {
|
821
827
|
case undefined:
|
822
828
|
return undefined;
|
823
829
|
case 'app-only':
|
@@ -860,8 +866,8 @@ class Resolver {
|
|
860
866
|
// check if this file is resolvable as a global component, and if so return
|
861
867
|
// its dasherized name
|
862
868
|
reverseComponentLookup(filename) {
|
863
|
-
const owningPackage = this.
|
864
|
-
if (!owningPackage
|
869
|
+
const owningPackage = this.packageCache.ownerOfFile(filename);
|
870
|
+
if (!(owningPackage === null || owningPackage === void 0 ? void 0 : owningPackage.isV2Ember())) {
|
865
871
|
return;
|
866
872
|
}
|
867
873
|
let engineConfig = this.options.engines.find(e => e.root === owningPackage.root);
|
@@ -895,10 +901,10 @@ class Resolver {
|
|
895
901
|
return undefined;
|
896
902
|
}
|
897
903
|
}
|
904
|
+
exports.Resolver = Resolver;
|
898
905
|
__decorate([
|
899
906
|
(0, typescript_memoize_1.Memoize)()
|
900
907
|
], Resolver.prototype, "mergeMap", null);
|
901
|
-
exports.Resolver = Resolver;
|
902
908
|
function isExplicitlyExternal(specifier, fromPkg) {
|
903
909
|
return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));
|
904
910
|
}
|