@embroider/core 1.5.0 → 1.7.1
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 +3 -3
- package/src/app.d.ts +0 -1
- package/src/app.js +6 -13
- package/src/app.js.map +1 -1
- package/src/babel-plugin-adjust-imports.js +1 -1
- package/src/babel-plugin-adjust-imports.js.map +1 -1
- package/src/babel-plugin-inline-hbs-deps-node.js +5 -1
- package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -1
- package/src/babel-plugin-inline-hbs-deps.d.ts +1 -1
- package/src/babel-plugin-inline-hbs-deps.js +23 -8
- package/src/babel-plugin-inline-hbs-deps.js.map +1 -1
- package/src/babel-plugin-inline-hbs-node.js +6 -0
- package/src/babel-plugin-inline-hbs-node.js.map +1 -1
- package/src/babel-plugin-inline-hbs.d.ts +1 -1
- package/src/babel-plugin-inline-hbs.js +1 -1
- package/src/babel-plugin-inline-hbs.js.map +1 -1
- package/src/babel-plugin-stage1-inline-hbs.d.ts +1 -1
- package/src/babel-plugin-stage1-inline-hbs.js.map +1 -1
- package/src/html-entrypoint.js +32 -11
- package/src/html-entrypoint.js.map +1 -1
- package/src/index.d.ts +1 -2
- package/src/index.js +6 -5
- package/src/index.js.map +1 -1
- package/src/options.js +0 -3
- package/src/options.js.map +1 -1
- package/src/packager.d.ts +0 -1
- package/src/packager.js +1 -7
- package/src/packager.js.map +1 -1
- package/src/resolver.d.ts +1 -1
- package/src/resolver.js.map +1 -1
- package/src/template-compiler-common.d.ts +0 -4
- package/src/template-compiler-common.js +12 -55
- package/src/template-compiler-common.js.map +1 -1
- package/src/template-compiler-node.d.ts +0 -2
- package/src/template-compiler-node.js +0 -43
- package/src/template-compiler-node.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-entrypoint.js","sourceRoot":"","sources":["html-entrypoint.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0D;AAC1D,uCAAwC;AACxC,+BAA4B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AAE,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 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.publicAssetURL);\n insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);\n insertedLazy.add(src);\n }\n }\n for (let [base, fastboot] of zip(matchingBundles, matchingFastbootBundles)) {\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', this.publicAssetURL + fastboot);\n placeholder.insert(element);\n placeholder.insertNewline();\n } else if (!fastboot || base === fastboot) {\n // no specialized fastboot variant\n let src = this.publicAssetURL + base;\n placeholder.insertURL(src);\n } else {\n // we have both and they differ\n let src = this.publicAssetURL + base;\n let element = placeholder.insertURL(src);\n if (element) {\n element.setAttribute('data-fastboot-src', this.publicAssetURL + 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, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.js')) {\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', publicAssetURL + 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,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAEvF,KAAK,IAAI,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACpC,IAAI,QAAQ,GAAG,GAAsB,CAAC;YACtC,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;YACzB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBACnC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACtB,IAAI,WAAW,GAAG,IAAI,0BAAW,CAAC,QAAQ,CA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B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAED,6EAA6E;AAC7E,iDAAiD;AACjD,SAAS,oBAAoB,CAAC,WAAqB,EAAE,WAAwB,EAAE,OAAe;IAC5F,KAAK,IAAI,MAAM,IAAI,WAAW,EAAE;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC1B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;YAC/E,6DAA6D;YAC7D,0EAA0E;YAC1E,uEAAuE;YACvE,kCAAkC;YAClC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;YAC9C,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,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 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
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export { Packager, PackagerConstructor, Variant, applyVariantToBabelConfig,
|
|
1
|
+
export { Packager, PackagerConstructor, Variant, applyVariantToBabelConfig, getAppMeta, getPackagerCacheDir, } from './packager';
|
|
2
2
|
export { HTMLEntrypoint, BundleSummary } from './html-entrypoint';
|
|
3
3
|
export { Resolver } from './resolver';
|
|
4
4
|
export { default as Stage } from './stage';
|
|
5
5
|
export { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';
|
|
6
6
|
export { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';
|
|
7
|
-
export { templateCompilerModule } from './write-template-compiler';
|
|
8
7
|
export { Plugins as TemplateCompilerPlugins } from './ember-template-compiler-types';
|
|
9
8
|
export { Asset, EmberAsset, ImplicitAssetPaths } from './asset';
|
|
10
9
|
export { default as Options, optionsWithDefaults } from './options';
|
package/src/index.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];
|
|
@@ -13,10 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
18
|
};
|
|
15
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.mangledEngineRoot = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.AppBuilder = exports.jsHandlebarsCompile = exports.BuildStage = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.
|
|
20
|
+
exports.mangledEngineRoot = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.AppBuilder = exports.jsHandlebarsCompile = exports.BuildStage = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.TemplateCompiler = exports.NodeTemplateCompiler = exports.HTMLEntrypoint = exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
|
17
21
|
var packager_1 = require("./packager");
|
|
18
22
|
Object.defineProperty(exports, "applyVariantToBabelConfig", { enumerable: true, get: function () { return packager_1.applyVariantToBabelConfig; } });
|
|
19
|
-
Object.defineProperty(exports, "applyVariantToTemplateCompiler", { enumerable: true, get: function () { return packager_1.applyVariantToTemplateCompiler; } });
|
|
20
23
|
Object.defineProperty(exports, "getAppMeta", { enumerable: true, get: function () { return packager_1.getAppMeta; } });
|
|
21
24
|
Object.defineProperty(exports, "getPackagerCacheDir", { enumerable: true, get: function () { return packager_1.getPackagerCacheDir; } });
|
|
22
25
|
var html_entrypoint_1 = require("./html-entrypoint");
|
|
@@ -25,8 +28,6 @@ var template_compiler_node_1 = require("./template-compiler-node");
|
|
|
25
28
|
Object.defineProperty(exports, "NodeTemplateCompiler", { enumerable: true, get: function () { return template_compiler_node_1.NodeTemplateCompiler; } });
|
|
26
29
|
var template_compiler_common_1 = require("./template-compiler-common");
|
|
27
30
|
Object.defineProperty(exports, "TemplateCompiler", { enumerable: true, get: function () { return template_compiler_common_1.TemplateCompiler; } });
|
|
28
|
-
var write_template_compiler_1 = require("./write-template-compiler");
|
|
29
|
-
Object.defineProperty(exports, "templateCompilerModule", { enumerable: true, get: function () { return write_template_compiler_1.templateCompilerModule; } });
|
|
30
31
|
var options_1 = require("./options");
|
|
31
32
|
Object.defineProperty(exports, "optionsWithDefaults", { enumerable: true, get: function () { return options_1.optionsWithDefaults; } });
|
|
32
33
|
var to_broccoli_plugin_1 = require("./to-broccoli-plugin");
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
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,mEAA4F;AAAnF,8HAAA,oBAAoB,OAAA;AAC7B,uEAAsF;AAA7E,4HAAA,gBAAgB,OAAA;AAGzB,qCAAoE;AAAvC,8GAAA,mBAAmB,OAAA;AAChD,2DAAmE;AAA1D,uIAAA,OAAO,OAAoB;AACpC,mDAAwE;AAA/D,+HAAA,OAAO,OAAgB;AAChC,6CAAsD;AAA7C,0HAAA,OAAO,OAAc;AAC9B,iDAAiE;AAAxD,oHAAA,OAAO,OAAuB;AACvC,6BAAyD;AAApC,iGAAA,UAAU,OAAA;AAC/B,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,mDAAqD;AAA5C,mHAAA,iBAAiB,OAAA;AAE1B,8EAA8E;AAC9E,yDAAyD;AACzD,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 { Resolver } from './resolver';\nexport { default as Stage } from './stage';\nexport { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nexport { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';\nexport { Plugins as TemplateCompilerPlugins } from './ember-template-compiler-types';\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 { default as BuildStage } from './build-stage';\nexport { compile as jsHandlebarsCompile } from './js-handlebars';\nexport { AppAdapter, AppBuilder, EmberENV } from './app';\nexport { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';\nexport { mangledEngineRoot } from './engine-mangler';\n\n// this is reexported because we already make users manage a peerDep from some\n// other packages (like embroider/webpack and @embroider/\nexport * from '@embroider/shared-internals';\n"]}
|
package/src/options.js
CHANGED
|
@@ -6,10 +6,7 @@ function optionsWithDefaults(options) {
|
|
|
6
6
|
staticHelpers: false,
|
|
7
7
|
staticModifiers: false,
|
|
8
8
|
staticComponents: false,
|
|
9
|
-
packageRules: [],
|
|
10
9
|
splitAtRoutes: [],
|
|
11
|
-
splitControllers: false,
|
|
12
|
-
splitRouteClasses: false,
|
|
13
10
|
staticAppPaths: [],
|
|
14
11
|
skipBabel: [],
|
|
15
12
|
pluginHints: [],
|
package/src/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AA6GA,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,gBAAgB,EAAE,KAAK;QACvB,
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AA6GA,SAAgB,mBAAmB,CAAC,OAAiB;IACnD,IAAI,QAAQ,GAAG;QACb,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,gBAAgB,EAAE,KAAK;QACvB,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,uBAAuB,EAAE,eAAkC;KAC5D,CAAC;IACF,IAAI,OAAO,EAAE;QACX,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KACzC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAfD,kDAeC","sourcesContent":["export default interface Options {\n // When true, we statically resolve all template helpers at build time. This\n // causes unused helpers to be left out of the build (\"tree shaking\" of\n // helpers).\n //\n // Defaults to false, which gives you greater compatibility with classic Ember\n // apps at the cost of bigger builds.\n //\n // Enabling this is a prerequisite for route splitting.\n staticHelpers?: boolean;\n\n // When true, we statically resolve all modifiers at build time. This\n // causes unused modifiers to be left out of the build (\"tree shaking\" of\n // modifiers).\n //\n // Defaults to false, which gives you greater compatibility with classic Ember\n // apps at the cost of bigger builds.\n //\n // Enabling this is a prerequisite for route splitting.\n staticModifiers?: boolean;\n\n // When true, we statically resolve all components at build time. This causes\n // unused components to be left out of the build (\"tree shaking\" of\n // components).\n //\n // Defaults to false, which gives you greater compatibility with classic Ember\n // apps at the cost of bigger builds.\n //\n // Enabling this is a prerequisite for route splitting.\n staticComponents?: boolean;\n\n // Enables per-route code splitting. Any route names that match these patterns\n // will be split out of the initial app payload. If you use this, you must\n // also add @embroider/router to your app. See [@embroider/router's\n // README](https://github.com/embroider-build/embroider/blob/main/packages/router/README.md)\n splitAtRoutes?: (RegExp | string)[];\n\n // Every file within your application's `app` directory is categorized as a\n // component, helper, modifier, route, route template, controller, or \"other\".\n //\n // This option lets you decide which \"other\" files should be loaded\n // statically. By default, all \"other\" files will be included in the build and\n // registered with Ember's runtime loader, because we can't know if somebody\n // is going to try to access them dynamically via Ember's resolver or AMD\n // runtime `require`.\n //\n // If you know that your files are only ever imported, you can list them here\n // and then they will only be included exactly where they're needed.\n //\n // Provide a list of directories or files relative to `/app`. For example\n //\n // staticAppPaths: ['lib']\n //\n // means that everything under your-project/app/lib will be loaded statically.\n //\n // This option has no effect on components (which are governed by\n // staticComponents), helpers (which are governed by staticHelpers), modifiers\n // (which are governed by staticModifiers) or the route-specific files (routes,\n // route templates, and controllers which are governed by splitAtRoutes).\n staticAppPaths?: string[];\n\n // By default, all modules that get imported into the app go through Babel, so\n // that all code will conform with your Babel targets. This option allows you\n // to turn Babel off for a particular package. You might need this to work\n // around a transpiler bug or you might use this as a build-performance\n // optimization if you've manually verified that a particular package doesn't\n // need transpilation to be safe in your target browsers.\n skipBabel?: { package: string; semverRange?: string }[];\n\n // This is a performance optimization that can help you avoid the \"Your build\n // is slower because some babel plugins are non-serializable\" penalty. If you\n // provide the locations of known non-serializable objects, we can discover\n // them and make them serializable.\n //\n // resolve is a list of paths to resolve, in a chain. This lets you resolve\n // your dependencies' dependencies, like: resolve: ['your-dependency',\n // 'inner-dependency/lib/transform']\n //\n // useMethod optionally lets you pick which property within the module to use.\n // If not provided, we use the module.exports itself.\n pluginHints?: { resolve: string[]; useMethod?: string }[];\n\n // Our addons' implicit-modules and implicit-test-modules are not necessarily\n // resolvable directly from the app, but the meaning of those\n // backward-compatibility features is \"the app should import this module\". So\n // we need some strategy for making them importable by the app. We can either\n // turn those imports into complete relative paths, or leave them as package\n // names:\n //\n // relativePaths:\n //\n // import('./node_modules/intermediate/node_modules/some-addon/thing.js')\n //\n // packageNames:\n //\n // import('some-addon/thing.js')\n //\n // When building under a tool like webpack, the relativePaths are safe and\n // always work, although they can be uglier to look at when debugging in\n // development.\n //\n // When building under a tool like snowpack, the package names can be easier\n // to work with because you already have web-bundles per package, and can't\n // necessarily address arbitrary places on the filesystem.\n //\n // Defaults to \"relativePaths\".\n implicitModulesStrategy?: 'packageNames' | 'relativePaths';\n}\n\nexport function optionsWithDefaults(options?: Options): Required<Options> {\n let defaults = {\n staticHelpers: false,\n staticModifiers: false,\n staticComponents: false,\n splitAtRoutes: [],\n staticAppPaths: [],\n skipBabel: [],\n pluginHints: [],\n implicitModulesStrategy: 'relativePaths' as 'relativePaths',\n };\n if (options) {\n return Object.assign(defaults, options);\n }\n return defaults;\n}\n"]}
|
package/src/packager.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export interface Packager {
|
|
|
12
12
|
build(): Promise<void>;
|
|
13
13
|
}
|
|
14
14
|
export declare function applyVariantToBabelConfig(variant: Variant, babelConfig: any): any;
|
|
15
|
-
export declare function applyVariantToTemplateCompiler(_variant: Variant, templateCompiler: any): any;
|
|
16
15
|
/**
|
|
17
16
|
* Get the app meta-data for a package
|
|
18
17
|
*/
|
package/src/packager.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPackagerCacheDir = exports.getAppMeta = exports.
|
|
3
|
+
exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
|
4
4
|
const shared_internals_1 = require("@embroider/shared-internals");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
@@ -24,12 +24,6 @@ function applyVariantToBabelConfig(variant, babelConfig) {
|
|
|
24
24
|
return babelConfig;
|
|
25
25
|
}
|
|
26
26
|
exports.applyVariantToBabelConfig = applyVariantToBabelConfig;
|
|
27
|
-
function applyVariantToTemplateCompiler(_variant, templateCompiler) {
|
|
28
|
-
// TODO: we don't actually consume the variant in the template macros yet, but
|
|
29
|
-
// Packagers must call this function anyway because we will.
|
|
30
|
-
return templateCompiler;
|
|
31
|
-
}
|
|
32
|
-
exports.applyVariantToTemplateCompiler = applyVariantToTemplateCompiler;
|
|
33
27
|
/**
|
|
34
28
|
* Get the app meta-data for a package
|
|
35
29
|
*/
|
package/src/packager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packager.js","sourceRoot":"","sources":["packager.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAC9D,uCAAwC;AACxC,mCAAmC;AACnC,+BAA4B;AAoE5B,SAAgB,yB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AAW,CAAC,OAAO,EAAE;YACvB,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;SACnD;aAAM;YACL,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;SAC1B;QACD,IAAI,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CACxC,CAAC,CAAM,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B,CACzE,CAAC;QACF,IAAI,WAAW,EAAE;YACf,IAAI,mBAAmB,GAAG,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC;YACjD,mBAAmB,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YACnE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;SAC9F;KACF;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAlBD,8DAkBC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,gBAAwB;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,gBAAgB,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,aAAa,CAAY,CAAC;AAC5G,CAAC;AAFD,gCAEC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAA,WAAI,EAAC,yBAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAFD,kDAEC","sourcesContent":["import { AppMeta, tmpdir } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { cloneDeep } from 'lodash';\nimport { join } from 'path';\n\n// This is a collection of flags that convey what kind of build you want. They\n// are intended to be generic across Packagers, and it's up to Packager authors\n// to support each option (or not).\nexport interface Variant {\n // descriptive name that can be used by the packager to label which output\n // goes with which variant.\n name: string;\n\n // Which runtime should this build work in? Dev builds will typically be \"all\"\n // because we produce a single build that works in browser and fastboot. But\n // production builds can be divided into a browser-only variant and a\n // fastboot-only variant so that each can be separately optimized.\n //\n // Note that if you build *only* a fastboot variant, you're unlikely to end up\n // with any assets that can boot and run in the browser too, so the typical\n // thing to do is to have to two variants and for the packager to use the\n // assets from the browser build to generate browser-facing <script> tags in\n // the output of the fastboot build.\n runtime: 'all' | 'browser' | 'fastboot';\n\n // true if this build should be optimized for production, at the cost of\n // slower builds and/or worse debuggability\n optimizeForProduction: boolean;\n}\n\nexport interface PackagerConstructor<Options> {\n new (\n // where on disk the packager will find the app it's supposed to build. The\n // app and its addons will necessarily already be in v2 format, which is\n // what makes a Packager a cleanly separable stage that needs only a small\n // amount of ember-specific knowledge.\n inputPath: string,\n // where the packager should write the packaged app.\n outputPath: string,\n // list of active build variants. There is always at least one variant, but\n // there can be many.\n //\n // The main requirement for correctness is that the Packager is required to\n // apply each variant to the babel and template-compiler configs that it\n // finds in the app in order to build that variant.\n //\n // It is up to each Packager to decide how to combine the output from the\n // multiple variants. It might choose to just put them in separate\n // subdirectories of `outputPath`, or it might know how to combine them\n // correctly into one build that will run each variant under the appropriate\n // conditions.\n //\n // Not all packagers will support all arbitrary combinations of variants.\n variants: Variant[],\n // if possible, the packager should direct its console output through this\n // hook.\n consoleWrite: (message: string) => void,\n // A packager can have whatever custom options type it wants here. If the\n // packager is based on a third-party tool, this is where that tool's\n // configuration can go.\n options?: Options\n ): Packager;\n\n // a description for this packager that aids debugging & profiling\n annotation: string;\n}\n\nexport interface Packager {\n build(): Promise<void>;\n}\n\nexport function applyVariantToBabelConfig(variant: Variant, babelConfig: any) {\n if (variant.runtime === 'fastboot') {\n babelConfig = Object.assign({}, babelConfig);\n if (babelConfig.plugins) {\n babelConfig.plugins = babelConfig.plugins.slice();\n } else {\n babelConfig.plugins = [];\n }\n let macroPlugin = babelConfig.plugins.find(\n (p: any) => Array.isArray(p) && p[1] && p[1].embroiderMacrosConfigMarker\n );\n if (macroPlugin) {\n let modifiedMacroPlugin = cloneDeep(macroPlugin);\n modifiedMacroPlugin[1].globalConfig.fastboot = { isRunning: true };\n babelConfig.plugins.splice(babelConfig.plugins.indexOf(macroPlugin), 1, modifiedMacroPlugin);\n }\n }\n return babelConfig;\n}\n\n/**\n * Get the app meta-data for a package\n */\nexport function getAppMeta(pathToVanillaApp: string): AppMeta {\n return JSON.parse(readFileSync(join(pathToVanillaApp, 'package.json'), 'utf8'))['ember-addon'] as AppMeta;\n}\n\n/**\n * Get the path to a cache directory in the recommended location\n *\n * This ensures they have exactly the same lifetime as some of embroider's own caches.\n */\nexport function getPackagerCacheDir(name: string): string {\n return join(tmpdir, 'embroider', name);\n}\n"]}
|
package/src/resolver.d.ts
CHANGED
package/src/resolver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":"","sourcesContent":["import { TemplateCompiler } from './template-compiler-common';\nimport { Options } from './babel-plugin-adjust-imports';\n\nexport interface ResolvedDep {\n runtimeName: string;\n path: string;\n absPath: string;\n}\n\nexport interface Resolver {\n astTransformer(templateCompiler: TemplateCompiler): unknown;\n dependenciesOf(moduleName: string): ResolvedDep[];\n\n // this takes an absolute path to a file and gives back a path like\n // \"the-package-name/path/to/the-file.js\", while taking into account any\n // backward-compatible runtime name of the package. It's used by the template\n // compiler, because this is the kind of path AST plugins expect to see.\n absPathToRuntimePath(absPath: string): string;\n\n // this takes an absolute path to a file and gives back the runtime name of\n // that module, as it would tradtionally be named within loader.js.\n absPathToRuntimeName(absPath: string): string;\n\n adjustImportsOptions: Options;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":"","sourcesContent":["import type { TemplateCompiler } from './template-compiler-common';\nimport { Options } from './babel-plugin-adjust-imports';\n\nexport interface ResolvedDep {\n runtimeName: string;\n path: string;\n absPath: string;\n}\n\nexport interface Resolver {\n astTransformer(templateCompiler: TemplateCompiler): unknown;\n dependenciesOf(moduleName: string): ResolvedDep[];\n\n // this takes an absolute path to a file and gives back a path like\n // \"the-package-name/path/to/the-file.js\", while taking into account any\n // backward-compatible runtime name of the package. It's used by the template\n // compiler, because this is the kind of path AST plugins expect to see.\n absPathToRuntimePath(absPath: string): string;\n\n // this takes an absolute path to a file and gives back the runtime name of\n // that module, as it would tradtionally be named within loader.js.\n absPathToRuntimeName(absPath: string): string;\n\n adjustImportsOptions: Options;\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Resolver, ResolvedDep } from './resolver';
|
|
2
|
-
import type { PluginItem } from '@babel/core';
|
|
3
2
|
export interface Plugins {
|
|
4
3
|
ast?: unknown[];
|
|
5
4
|
}
|
|
@@ -65,10 +64,7 @@ export declare class TemplateCompiler {
|
|
|
65
64
|
compiled: string;
|
|
66
65
|
dependencies: ResolvedDep[];
|
|
67
66
|
};
|
|
68
|
-
compile(moduleName: string, contents: string): string;
|
|
69
67
|
applyTransforms(moduleName: string, contents: string): string;
|
|
70
68
|
parse(moduleName: string, contents: string): AST;
|
|
71
69
|
baseDir(): string;
|
|
72
|
-
static isInlinePrecompilePlugin(item: PluginItem): boolean;
|
|
73
70
|
}
|
|
74
|
-
export declare function matchesSourceFile(filename: string): boolean;
|
|
@@ -9,30 +9,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.TemplateCompiler = void 0;
|
|
13
13
|
const strip_bom_1 = __importDefault(require("strip-bom"));
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const typescript_memoize_1 = require("typescript-memoize");
|
|
16
16
|
const wrap_legacy_hbs_plugin_if_needed_1 = __importDefault(require("wrap-legacy-hbs-plugin-if-needed"));
|
|
17
|
-
const htmlbarPathMatches = [
|
|
18
|
-
['htmlbars-inline-precompile', 'index.js'].join(path_1.sep),
|
|
19
|
-
['htmlbars-inline-precompile', 'lib', 'require-from-worker.js'].join(path_1.sep),
|
|
20
|
-
['htmlbars-inline-precompile', 'index'].join(path_1.sep),
|
|
21
|
-
['htmlbars-inline-precompile', 'lib', 'require-from-worker'].join(path_1.sep),
|
|
22
|
-
['ember-cli-htmlbars', 'index.js'].join(path_1.sep),
|
|
23
|
-
['ember-cli-htmlbars', 'lib', 'require-from-worker.js'].join(path_1.sep),
|
|
24
|
-
['ember-cli-htmlbars', 'index'].join(path_1.sep),
|
|
25
|
-
['ember-cli-htmlbars', 'lib', 'require-from-worker'].join(path_1.sep),
|
|
26
|
-
];
|
|
27
17
|
class TemplateCompiler {
|
|
28
18
|
constructor(params) {
|
|
29
19
|
this.loadEmberTemplateCompiler = params.loadEmberTemplateCompiler;
|
|
30
20
|
this.resolver = params.resolver;
|
|
31
21
|
this.EmberENV = params.EmberENV;
|
|
32
22
|
this.plugins = params.plugins;
|
|
33
|
-
// stage3 packagers don't need to know about our instance, they can just
|
|
34
|
-
// grab the compile function and use it.
|
|
35
|
-
this.compile = this.compile.bind(this);
|
|
36
23
|
}
|
|
37
24
|
get syntax() {
|
|
38
25
|
return this.setup().syntax;
|
|
@@ -63,13 +50,21 @@ class TemplateCompiler {
|
|
|
63
50
|
runtimeName = filename;
|
|
64
51
|
}
|
|
65
52
|
let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });
|
|
66
|
-
let plugins =
|
|
53
|
+
let plugins = {
|
|
54
|
+
...opts === null || opts === void 0 ? void 0 : opts.plugins,
|
|
55
|
+
ast: [
|
|
67
56
|
...this.getReversedASTPlugins(this.plugins.ast),
|
|
68
57
|
this.resolver && this.resolver.astTransformer(this),
|
|
69
58
|
// Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result
|
|
70
59
|
...((_b = (_a = opts === null || opts === void 0 ? void 0 : opts.plugins) === null || _a === void 0 ? void 0 : _a.ast) !== null && _b !== void 0 ? _b : []),
|
|
71
|
-
].filter(Boolean)
|
|
72
|
-
|
|
60
|
+
].filter(Boolean),
|
|
61
|
+
};
|
|
62
|
+
let compiled = this.syntax.precompile((0, strip_bom_1.default)(templateSource), {
|
|
63
|
+
contents: templateSource,
|
|
64
|
+
moduleName: runtimeName,
|
|
65
|
+
plugins,
|
|
66
|
+
...options,
|
|
67
|
+
});
|
|
73
68
|
if (this.resolver) {
|
|
74
69
|
dependencies = this.resolver.dependenciesOf(filename);
|
|
75
70
|
}
|
|
@@ -78,19 +73,6 @@ class TemplateCompiler {
|
|
|
78
73
|
}
|
|
79
74
|
return { compiled, dependencies };
|
|
80
75
|
}
|
|
81
|
-
// Compiles all the way from a template string to a javascript module string.
|
|
82
|
-
compile(moduleName, contents) {
|
|
83
|
-
let { compiled, dependencies } = this.precompile(contents, { filename: moduleName });
|
|
84
|
-
let lines = [];
|
|
85
|
-
let counter = 0;
|
|
86
|
-
for (let { runtimeName, path } of dependencies) {
|
|
87
|
-
lines.push(`import a${counter} from "${path.split(path_1.sep).join('/')}";`);
|
|
88
|
-
lines.push(`window.define('${runtimeName}', function(){ return a${counter++}});`);
|
|
89
|
-
}
|
|
90
|
-
lines.push(`import { createTemplateFactory } from '@ember/template-factory';`);
|
|
91
|
-
lines.push(`export default createTemplateFactory(${compiled});`);
|
|
92
|
-
return lines.join('\n');
|
|
93
|
-
}
|
|
94
76
|
// Applies all custom AST transforms and emits the results still as
|
|
95
77
|
// handlebars.
|
|
96
78
|
applyTransforms(moduleName, contents) {
|
|
@@ -124,24 +106,6 @@ class TemplateCompiler {
|
|
|
124
106
|
baseDir() {
|
|
125
107
|
return (0, path_1.join)(__dirname, '..');
|
|
126
108
|
}
|
|
127
|
-
// tests for the classic ember-cli-htmlbars-inline-precompile babel plugin
|
|
128
|
-
static isInlinePrecompilePlugin(item) {
|
|
129
|
-
if (typeof item === 'string') {
|
|
130
|
-
return matchesSourceFile(item);
|
|
131
|
-
}
|
|
132
|
-
if (hasProperties(item) && item._parallelBabel) {
|
|
133
|
-
return matchesSourceFile(item._parallelBabel.requireFile);
|
|
134
|
-
}
|
|
135
|
-
if (Array.isArray(item) && item.length > 0) {
|
|
136
|
-
if (typeof item[0] === 'string') {
|
|
137
|
-
return matchesSourceFile(item[0]);
|
|
138
|
-
}
|
|
139
|
-
if (hasProperties(item[0]) && item[0]._parallelBabel) {
|
|
140
|
-
return matchesSourceFile(item[0]._parallelBabel.requireFile);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
109
|
}
|
|
146
110
|
__decorate([
|
|
147
111
|
(0, typescript_memoize_1.Memoize)()
|
|
@@ -150,13 +114,6 @@ __decorate([
|
|
|
150
114
|
(0, typescript_memoize_1.Memoize)()
|
|
151
115
|
], TemplateCompiler.prototype, "getReversedASTPlugins", null);
|
|
152
116
|
exports.TemplateCompiler = TemplateCompiler;
|
|
153
|
-
function matchesSourceFile(filename) {
|
|
154
|
-
return Boolean(htmlbarPathMatches.find(match => filename.endsWith(match)));
|
|
155
|
-
}
|
|
156
|
-
exports.matchesSourceFile = matchesSourceFile;
|
|
157
|
-
function hasProperties(item) {
|
|
158
|
-
return item && (typeof item === 'object' || typeof item === 'function');
|
|
159
|
-
}
|
|
160
117
|
// this matches the setup done by ember-cli-htmlbars: https://git.io/JtbN6
|
|
161
118
|
function initializeEmberENV(syntax, EmberENV) {
|
|
162
119
|
if (!EmberENV) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler-common.js","sourceRoot":"","sources":["template-compiler-common.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAiC;AAEjC,+BAAiC;AAEjC,2DAA6C;AAC7C,wGAA2E;AAuD3E,MA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gC;QAChC,2BAA2B;QAC3B,wEAAwE;QACxE,IAAI,MAAM,GAAG,CAAC,MAAA,4BAA4B,CAAC,KAAK,mCAAI,4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CACvG,iBAAiB,CAClB,CAAC;QACF,IAAI,eAAe,GAAG,CAAC,MAAA,4BAA4B,CAAC,KAAK,mCAAI,4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAChH,oDAAoD,CACrD,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,cAAc,EAAE,eAAe,CAAC,OAAO;YACvC,UAAU,EAAE,4BAA4B,CAAC,UAAU;YACnD,MAAM,EAAE,4BAA4B,CAAC,MAAM;SAC5C,CAAC;KACH;AACH,CAAC","sourcesContent":["import stripBom from 'strip-bom';\nimport { Resolver, ResolvedDep } from './resolver';\nimport { join, sep } from 'path';\nimport type { PluginItem } from '@babel/core';\nimport { Memoize } from 'typescript-memoize';\nimport wrapLegacyHbsPluginIfNeeded from 'wrap-legacy-hbs-plugin-if-needed';\n\nexport interface Plugins {\n ast?: unknown[];\n}\n\nexport interface AST {\n _deliberatelyOpaque: 'AST';\n}\n\nexport interface PreprocessOptions {\n contents: string;\n moduleName: string;\n plugins?: Plugins;\n filename?: string;\n\n parseOptions?: {\n srcName?: string;\n ignoreStandalone?: boolean;\n };\n\n // added in Ember 3.17 (@glimmer/syntax@0.40.2)\n mode?: 'codemod' | 'precompile';\n\n // added in Ember 3.25\n strictMode?: boolean;\n locals?: string[];\n}\n\nexport interface PrinterOptions {\n entityEncoding?: 'transformed' | 'raw';\n}\n\n// This just reflects the API we're extracting from ember-template-compiler.js,\n// plus a cache key that lets us know when the underlying source has remained\n// stable.\nexport interface GlimmerSyntax {\n preprocess(html: string, options?: PreprocessOptions): AST;\n print(ast: AST, options?: PrinterOptions): string;\n defaultOptions(options: PreprocessOptions): PreprocessOptions;\n precompile(\n templateContents: string,\n options: {\n contents: string;\n moduleName: string;\n filename: string;\n plugins?: any;\n parseOptions?: {\n srcName?: string;\n };\n }\n ): string;\n _Ember: { FEATURES: any; ENV: any };\n}\n\nconst htmlbarPathMatches = [\n ['htmlbars-inline-precompile', 'index.js'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker.js'].join(sep),\n ['htmlbars-inline-precompile', 'index'].join(sep),\n ['htmlbars-inline-precompile', 'lib', 'require-from-worker'].join(sep),\n ['ember-cli-htmlbars', 'index.js'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker.js'].join(sep),\n ['ember-cli-htmlbars', 'index'].join(sep),\n ['ember-cli-htmlbars', 'lib', 'require-from-worker'].join(sep),\n];\n\nexport interface TemplateCompilerParams {\n // this should be the exports object from ember-template-compiler.js. It's\n // \"unknown\" here because it changes shape in different ember versions, we\n // will do our best to consume it.\n loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n resolver?: Resolver;\n EmberENV: unknown;\n plugins: Plugins;\n}\n\nexport class TemplateCompiler {\n private loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n private resolver?: Resolver;\n private EmberENV: unknown;\n private plugins: Plugins;\n\n constructor(params: TemplateCompilerParams) {\n this.loadEmberTemplateCompiler = params.loadEmberTemplateCompiler;\n this.resolver = params.resolver;\n this.EmberENV = params.EmberENV;\n this.plugins = params.plugins;\n\n // stage3 packagers don't need to know about our instance, they can just\n // grab the compile function and use it.\n this.compile = this.compile.bind(this);\n }\n\n private get syntax(): GlimmerSyntax {\n return this.setup().syntax;\n }\n\n get cacheKey(): string {\n return this.setup().cacheKey;\n }\n\n @Memoize()\n private setup() {\n let { theExports, cacheKey } = this.loadEmberTemplateCompiler();\n let syntax = loadGlimmerSyntax(theExports);\n initializeEmberENV(syntax, this.EmberENV);\n // todo: get resolver reflected in cacheKey\n return { syntax, cacheKey };\n }\n\n @Memoize()\n private getReversedASTPlugins(ast: unknown[]): unknown[] {\n return ast.slice().reverse();\n }\n\n // Compiles to the wire format plus dependency list.\n precompile(\n templateSource: string,\n options: Record<string, unknown> & { filename: string }\n ): { compiled: string; dependencies: ResolvedDep[] } {\n let dependencies: ResolvedDep[];\n let runtimeName: string;\n let filename: string = options.filename;\n\n if (this.resolver) {\n runtimeName = this.resolver.absPathToRuntimePath(filename);\n } else {\n runtimeName = filename;\n }\n\n let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });\n let plugins: Plugins = {\n ...opts?.plugins,\n\n ast: [\n ...this.getReversedASTPlugins(this.plugins.ast!),\n this.resolver && this.resolver.astTransformer(this),\n\n // Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result\n ...(opts?.plugins?.ast ?? []),\n ].filter(Boolean),\n };\n\n let compiled = this.syntax.precompile(stripBom(templateSource), {\n contents: templateSource,\n moduleName: runtimeName,\n plugins,\n ...options,\n });\n\n if (this.resolver) {\n dependencies = this.resolver.dependenciesOf(filename);\n } else {\n dependencies = [];\n }\n\n return { compiled, dependencies };\n }\n\n // Compiles all the way from a template string to a javascript module string.\n compile(moduleName: string, contents: string) {\n let { compiled, dependencies } = this.precompile(contents, { filename: moduleName });\n let lines = [];\n let counter = 0;\n for (let { runtimeName, path } of dependencies) {\n lines.push(`import a${counter} from \"${path.split(sep).join('/')}\";`);\n lines.push(`window.define('${runtimeName}', function(){ return a${counter++}});`);\n }\n\n lines.push(`import { createTemplateFactory } from '@ember/template-factory';`);\n lines.push(`export default createTemplateFactory(${compiled});`);\n\n return lines.join('\\n');\n }\n\n // Applies all custom AST transforms and emits the results still as\n // handlebars.\n applyTransforms(moduleName: string, contents: string): string {\n let opts = this.syntax.defaultOptions({ contents, moduleName });\n\n // the user-provided plugins come first in the list, and those are the\n // only ones we want to run. The built-in plugins don't need to run here\n // in stage1, it's better that they run in stage3 when the appropriate\n // ember version is in charge.\n //\n // rather than slicing them off, we could choose instead to not call\n // syntax.defaultOptions, but then we lose some of the compatibility\n // normalization that it does on the user-provided plugins.\n opts.plugins = opts.plugins || {}; // Ember 3.27+ won't add opts.plugins\n opts.plugins.ast = this.getReversedASTPlugins(this.plugins.ast!).map(plugin => {\n // Although the precompile API does, this direct glimmer syntax api\n // does not support these legacy plugins, so we must wrap them.\n return wrapLegacyHbsPluginIfNeeded(plugin as any);\n });\n\n // instructs glimmer-vm to preserve entity encodings (e.g. don't parse -> ' ')\n opts.mode = 'codemod';\n\n opts.filename = moduleName;\n opts.moduleName = this.resolver ? this.resolver.absPathToRuntimePath(moduleName) || moduleName : moduleName;\n let ast = this.syntax.preprocess(contents, opts);\n\n return this.syntax.print(ast, { entityEncoding: 'raw' });\n }\n\n parse(moduleName: string, contents: string): AST {\n // this is just a parse, so we deliberately don't run any plugins.\n let opts = { contents, moduleName, plugins: {} };\n return this.syntax.preprocess(contents, opts);\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n\n // tests for the classic ember-cli-htmlbars-inline-precompile babel plugin\n static isInlinePrecompilePlugin(item: PluginItem) {\n if (typeof item === 'string') {\n return matchesSourceFile(item);\n }\n if (hasProperties(item) && (item as any)._parallelBabel) {\n return matchesSourceFile((item as any)._parallelBabel.requireFile);\n }\n if (Array.isArray(item) && item.length > 0) {\n if (typeof item[0] === 'string') {\n return matchesSourceFile(item[0]);\n }\n if (hasProperties(item[0]) && (item[0] as any)._parallelBabel) {\n return matchesSourceFile((item[0] as any)._parallelBabel.requireFile);\n }\n }\n return false;\n }\n}\n\nexport function matchesSourceFile(filename: string) {\n return Boolean(htmlbarPathMatches.find(match => filename.endsWith(match)));\n}\n\nfunction hasProperties(item: any) {\n return item && (typeof item === 'object' || typeof item === 'function');\n}\n\n// this matches the setup done by ember-cli-htmlbars: https://git.io/JtbN6\nfunction initializeEmberENV(syntax: GlimmerSyntax, EmberENV: any) {\n if (!EmberENV) {\n return;\n }\n\n let props;\n\n if (EmberENV.FEATURES) {\n props = Object.keys(EmberENV.FEATURES);\n props.forEach(prop => {\n syntax._Ember.FEATURES[prop] = EmberENV.FEATURES[prop];\n });\n }\n\n if (EmberENV) {\n props = Object.keys(EmberENV);\n props.forEach(prop => {\n if (prop === 'FEATURES') {\n return;\n }\n syntax._Ember.ENV[prop] = EmberENV[prop];\n });\n }\n}\n\n// we could directly depend on @glimmer/syntax and have nice types and\n// everything. But the problem is, we really want to use the exact version that\n// the app itself is using, and its copy is bundled away inside\n// ember-template-compiler.js.\nfunction loadGlimmerSyntax(emberTemplateCompilerExports: any): GlimmerSyntax {\n // detect if we are using an Ember version with the exports we need\n // (from https://github.com/emberjs/ember.js/pull/19426)\n if (emberTemplateCompilerExports._preprocess !== undefined) {\n return {\n print: emberTemplateCompilerExports._print,\n preprocess: emberTemplateCompilerExports._preprocess,\n defaultOptions: emberTemplateCompilerExports._buildCompileOptions,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n } else {\n // Older Ember versions (prior to 3.27) do not expose a public way to to source 2 source compilation of templates.\n // because of this, we must resort to some hackery.\n //\n // We use the following API's (that we grab from Ember.__loader):\n //\n // * glimmer/syntax's preprocess\n // * glimmer/syntax's print\n // * ember-template-compiler/lib/system/compile-options's defaultOptions\n let syntax = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n '@glimmer/syntax'\n );\n let compilerOptions = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n 'ember-template-compiler/lib/system/compile-options'\n );\n\n return {\n print: syntax.print,\n preprocess: syntax.preprocess,\n defaultOptions: compilerOptions.default,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"template-compiler-common.js","sourceRoot":"","sources":["template-compiler-common.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAiC;AAEjC,+BAA4B;AAC5B,2DAA6C;AAC7C,wGAA2E;AAiE3E,MAAa,gBAAgB;IAM3B,YAA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4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CACvG,iBAAiB,CAClB,CAAC;QACF,IAAI,eAAe,GAAG,CAAC,MAAA,4BAA4B,CAAC,KAAK,mCAAI,4BAA4B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAChH,oDAAoD,CACrD,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,cAAc,EAAE,eAAe,CAAC,OAAO;YACvC,UAAU,EAAE,4BAA4B,CAAC,UAAU;YACnD,MAAM,EAAE,4BAA4B,CAAC,MAAM;SAC5C,CAAC;KACH;AACH,CAAC","sourcesContent":["import stripBom from 'strip-bom';\nimport { Resolver, ResolvedDep } from './resolver';\nimport { join } from 'path';\nimport { Memoize } from 'typescript-memoize';\nimport wrapLegacyHbsPluginIfNeeded from 'wrap-legacy-hbs-plugin-if-needed';\n\nexport interface Plugins {\n ast?: unknown[];\n}\n\nexport interface AST {\n _deliberatelyOpaque: 'AST';\n}\n\nexport interface PreprocessOptions {\n contents: string;\n moduleName: string;\n plugins?: Plugins;\n filename?: string;\n\n parseOptions?: {\n srcName?: string;\n ignoreStandalone?: boolean;\n };\n\n // added in Ember 3.17 (@glimmer/syntax@0.40.2)\n mode?: 'codemod' | 'precompile';\n\n // added in Ember 3.25\n strictMode?: boolean;\n locals?: string[];\n}\n\nexport interface PrinterOptions {\n entityEncoding?: 'transformed' | 'raw';\n}\n\n// This just reflects the API we're extracting from ember-template-compiler.js,\n// plus a cache key that lets us know when the underlying source has remained\n// stable.\nexport interface GlimmerSyntax {\n preprocess(html: string, options?: PreprocessOptions): AST;\n print(ast: AST, options?: PrinterOptions): string;\n defaultOptions(options: PreprocessOptions): PreprocessOptions;\n precompile(\n templateContents: string,\n options: {\n contents: string;\n moduleName: string;\n filename: string;\n plugins?: any;\n parseOptions?: {\n srcName?: string;\n };\n }\n ): string;\n _Ember: { FEATURES: any; ENV: any };\n}\n\nexport interface TemplateCompilerParams {\n // this should be the exports object from ember-template-compiler.js. It's\n // \"unknown\" here because it changes shape in different ember versions, we\n // will do our best to consume it.\n loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n resolver?: Resolver;\n EmberENV: unknown;\n plugins: Plugins;\n}\n\nexport class TemplateCompiler {\n private loadEmberTemplateCompiler: () => { theExports: unknown; cacheKey: string };\n private resolver?: Resolver;\n private EmberENV: unknown;\n private plugins: Plugins;\n\n constructor(params: TemplateCompilerParams) {\n this.loadEmberTemplateCompiler = params.loadEmberTemplateCompiler;\n this.resolver = params.resolver;\n this.EmberENV = params.EmberENV;\n this.plugins = params.plugins;\n }\n\n private get syntax(): GlimmerSyntax {\n return this.setup().syntax;\n }\n\n get cacheKey(): string {\n return this.setup().cacheKey;\n }\n\n @Memoize()\n private setup() {\n let { theExports, cacheKey } = this.loadEmberTemplateCompiler();\n let syntax = loadGlimmerSyntax(theExports);\n initializeEmberENV(syntax, this.EmberENV);\n // todo: get resolver reflected in cacheKey\n return { syntax, cacheKey };\n }\n\n @Memoize()\n private getReversedASTPlugins(ast: unknown[]): unknown[] {\n return ast.slice().reverse();\n }\n\n // Compiles to the wire format plus dependency list.\n precompile(\n templateSource: string,\n options: Record<string, unknown> & { filename: string }\n ): { compiled: string; dependencies: ResolvedDep[] } {\n let dependencies: ResolvedDep[];\n let runtimeName: string;\n let filename: string = options.filename;\n\n if (this.resolver) {\n runtimeName = this.resolver.absPathToRuntimePath(filename);\n } else {\n runtimeName = filename;\n }\n\n let opts = this.syntax.defaultOptions({ contents: templateSource, moduleName: filename });\n let plugins: Plugins = {\n ...opts?.plugins,\n\n ast: [\n ...this.getReversedASTPlugins(this.plugins.ast!),\n this.resolver && this.resolver.astTransformer(this),\n\n // Ember 3.27+ uses _buildCompileOptions will not add AST plugins to its result\n ...(opts?.plugins?.ast ?? []),\n ].filter(Boolean),\n };\n\n let compiled = this.syntax.precompile(stripBom(templateSource), {\n contents: templateSource,\n moduleName: runtimeName,\n plugins,\n ...options,\n });\n\n if (this.resolver) {\n dependencies = this.resolver.dependenciesOf(filename);\n } else {\n dependencies = [];\n }\n\n return { compiled, dependencies };\n }\n\n // Applies all custom AST transforms and emits the results still as\n // handlebars.\n applyTransforms(moduleName: string, contents: string): string {\n let opts = this.syntax.defaultOptions({ contents, moduleName });\n\n // the user-provided plugins come first in the list, and those are the\n // only ones we want to run. The built-in plugins don't need to run here\n // in stage1, it's better that they run in stage3 when the appropriate\n // ember version is in charge.\n //\n // rather than slicing them off, we could choose instead to not call\n // syntax.defaultOptions, but then we lose some of the compatibility\n // normalization that it does on the user-provided plugins.\n opts.plugins = opts.plugins || {}; // Ember 3.27+ won't add opts.plugins\n opts.plugins.ast = this.getReversedASTPlugins(this.plugins.ast!).map(plugin => {\n // Although the precompile API does, this direct glimmer syntax api\n // does not support these legacy plugins, so we must wrap them.\n return wrapLegacyHbsPluginIfNeeded(plugin as any);\n });\n\n // instructs glimmer-vm to preserve entity encodings (e.g. don't parse -> ' ')\n opts.mode = 'codemod';\n\n opts.filename = moduleName;\n opts.moduleName = this.resolver ? this.resolver.absPathToRuntimePath(moduleName) || moduleName : moduleName;\n let ast = this.syntax.preprocess(contents, opts);\n\n return this.syntax.print(ast, { entityEncoding: 'raw' });\n }\n\n parse(moduleName: string, contents: string): AST {\n // this is just a parse, so we deliberately don't run any plugins.\n let opts = { contents, moduleName, plugins: {} };\n return this.syntax.preprocess(contents, opts);\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n}\n\n// this matches the setup done by ember-cli-htmlbars: https://git.io/JtbN6\nfunction initializeEmberENV(syntax: GlimmerSyntax, EmberENV: any) {\n if (!EmberENV) {\n return;\n }\n\n let props;\n\n if (EmberENV.FEATURES) {\n props = Object.keys(EmberENV.FEATURES);\n props.forEach(prop => {\n syntax._Ember.FEATURES[prop] = EmberENV.FEATURES[prop];\n });\n }\n\n if (EmberENV) {\n props = Object.keys(EmberENV);\n props.forEach(prop => {\n if (prop === 'FEATURES') {\n return;\n }\n syntax._Ember.ENV[prop] = EmberENV[prop];\n });\n }\n}\n\n// we could directly depend on @glimmer/syntax and have nice types and\n// everything. But the problem is, we really want to use the exact version that\n// the app itself is using, and its copy is bundled away inside\n// ember-template-compiler.js.\nfunction loadGlimmerSyntax(emberTemplateCompilerExports: any): GlimmerSyntax {\n // detect if we are using an Ember version with the exports we need\n // (from https://github.com/emberjs/ember.js/pull/19426)\n if (emberTemplateCompilerExports._preprocess !== undefined) {\n return {\n print: emberTemplateCompilerExports._print,\n preprocess: emberTemplateCompilerExports._preprocess,\n defaultOptions: emberTemplateCompilerExports._buildCompileOptions,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n } else {\n // Older Ember versions (prior to 3.27) do not expose a public way to to source 2 source compilation of templates.\n // because of this, we must resort to some hackery.\n //\n // We use the following API's (that we grab from Ember.__loader):\n //\n // * glimmer/syntax's preprocess\n // * glimmer/syntax's print\n // * ember-template-compiler/lib/system/compile-options's defaultOptions\n let syntax = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n '@glimmer/syntax'\n );\n let compilerOptions = (emberTemplateCompilerExports.Ember ?? emberTemplateCompilerExports._Ember).__loader.require(\n 'ember-template-compiler/lib/system/compile-options'\n );\n\n return {\n print: syntax.print,\n preprocess: syntax.preprocess,\n defaultOptions: compilerOptions.default,\n precompile: emberTemplateCompilerExports.precompile,\n _Ember: emberTemplateCompilerExports._Ember,\n };\n }\n}\n"]}
|
|
@@ -12,8 +12,6 @@ export interface NodeTemplateCompilerParams {
|
|
|
12
12
|
export declare class NodeTemplateCompiler extends TemplateCompiler {
|
|
13
13
|
params: NodeTemplateCompilerParams;
|
|
14
14
|
constructor(params: NodeTemplateCompilerParams);
|
|
15
|
-
compile(moduleName: string, contents: string): string;
|
|
16
15
|
inlineTransformsBabelPlugin(): PluginItem;
|
|
17
16
|
baseDir(): string;
|
|
18
|
-
static isInlinePrecompilePlugin(item: PluginItem): boolean;
|
|
19
17
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.NodeTemplateCompiler = void 0;
|
|
7
4
|
const path_1 = require("path");
|
|
8
|
-
const core_1 = require("@babel/core");
|
|
9
5
|
const load_ember_template_compiler_1 = require("./load-ember-template-compiler");
|
|
10
6
|
const template_compiler_common_1 = require("./template-compiler-common");
|
|
11
|
-
const babel_plugin_adjust_imports_1 = __importDefault(require("./babel-plugin-adjust-imports"));
|
|
12
7
|
class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
|
|
13
8
|
constructor(params) {
|
|
14
9
|
super({
|
|
@@ -19,23 +14,6 @@ class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
|
|
|
19
14
|
});
|
|
20
15
|
this.params = params;
|
|
21
16
|
}
|
|
22
|
-
compile(moduleName, contents) {
|
|
23
|
-
let src = super.compile(moduleName, contents);
|
|
24
|
-
let resolver = this.params.resolver;
|
|
25
|
-
if (resolver) {
|
|
26
|
-
let opts = resolver.adjustImportsOptions;
|
|
27
|
-
return (0, core_1.transform)(src, {
|
|
28
|
-
filename: moduleName,
|
|
29
|
-
generatorOpts: {
|
|
30
|
-
compact: false,
|
|
31
|
-
},
|
|
32
|
-
plugins: [[babel_plugin_adjust_imports_1.default, opts]],
|
|
33
|
-
}).code;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return src;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
17
|
// Use applyTransforms on the contents of inline hbs template strings inside
|
|
40
18
|
// Javascript.
|
|
41
19
|
inlineTransformsBabelPlugin() {
|
|
@@ -49,27 +27,6 @@ class NodeTemplateCompiler extends template_compiler_common_1.TemplateCompiler {
|
|
|
49
27
|
baseDir() {
|
|
50
28
|
return (0, path_1.join)(__dirname, '..');
|
|
51
29
|
}
|
|
52
|
-
// tests for the classic ember-cli-htmlbars-inline-precompile babel plugin
|
|
53
|
-
static isInlinePrecompilePlugin(item) {
|
|
54
|
-
if (typeof item === 'string') {
|
|
55
|
-
return (0, template_compiler_common_1.matchesSourceFile)(item);
|
|
56
|
-
}
|
|
57
|
-
if (hasProperties(item) && item._parallelBabel) {
|
|
58
|
-
return (0, template_compiler_common_1.matchesSourceFile)(item._parallelBabel.requireFile);
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(item) && item.length > 0) {
|
|
61
|
-
if (typeof item[0] === 'string') {
|
|
62
|
-
return (0, template_compiler_common_1.matchesSourceFile)(item[0]);
|
|
63
|
-
}
|
|
64
|
-
if (hasProperties(item[0]) && item[0]._parallelBabel) {
|
|
65
|
-
return (0, template_compiler_common_1.matchesSourceFile)(item[0]._parallelBabel.requireFile);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
30
|
}
|
|
71
31
|
exports.NodeTemplateCompiler = NodeTemplateCompiler;
|
|
72
|
-
function hasProperties(item) {
|
|
73
|
-
return item && (typeof item === 'object' || typeof item === 'function');
|
|
74
|
-
}
|
|
75
32
|
//# sourceMappingURL=template-compiler-node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler-node.js","sourceRoot":"","sources":["template-compiler-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"template-compiler-node.js","sourceRoot":"","sources":["template-compiler-node.ts"],"names":[],"mappings":";;;AACA,+BAA4B;AAI5B,iFAAiE;AACjE,yEAA8D;AAU9D,MAAa,oBAAqB,SAAQ,2CAAgB;IACxD,YAAmB,MAAkC;QACnD,KAAK,CAAC;YACJ,yBAAyB,EAAE,GAAG,EAAE,CAAC,IAAA,8CAAe,EAAC,MAAM,CAAC,YAAY,CAAC;YACrE,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;QANc,WAAM,GAAN,MAAM,CAA4B;IAOrD,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,2BAA2B;QACzB,OAAO;YACL,IAAA,WAAI,EAAC,SAAS,EAAE,wCAAwC,CAAC;YACzD;gBACE,gBAAgB,EAAE,IAAI,CAAC,MAAM;aACT;SACvB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AAxBD,oDAwBC","sourcesContent":["import { Resolver } from './resolver';\nimport { join } from 'path';\nimport { PluginItem } from '@babel/core';\nimport type { Params as InlineBabelParams } from './babel-plugin-stage1-inline-hbs-node';\nimport { Plugins } from './ember-template-compiler-types';\nimport { getEmberExports } from './load-ember-template-compiler';\nimport { TemplateCompiler } from './template-compiler-common';\n\nexport interface NodeTemplateCompilerParams {\n compilerPath: string;\n compilerChecksum: string;\n resolver?: Resolver;\n EmberENV: unknown;\n plugins: Plugins;\n}\n\nexport class NodeTemplateCompiler extends TemplateCompiler {\n constructor(public params: NodeTemplateCompilerParams) {\n super({\n loadEmberTemplateCompiler: () => getEmberExports(params.compilerPath),\n resolver: params.resolver,\n EmberENV: params.EmberENV,\n plugins: params.plugins,\n });\n }\n\n // Use applyTransforms on the contents of inline hbs template strings inside\n // Javascript.\n inlineTransformsBabelPlugin(): PluginItem {\n return [\n join(__dirname, 'babel-plugin-stage1-inline-hbs-node.js'),\n {\n templateCompiler: this.params,\n } as InlineBabelParams,\n ];\n }\n\n baseDir() {\n return join(__dirname, '..');\n }\n}\n"]}
|