@embroider/core 2.0.1 → 2.1.0

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.
Files changed (53) hide show
  1. package/package.json +1 -1
  2. package/src/babel-plugin-adjust-imports.d.ts +3 -34
  3. package/src/babel-plugin-adjust-imports.js +94 -318
  4. package/src/babel-plugin-adjust-imports.js.map +1 -1
  5. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  6. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  7. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  8. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  9. package/src/babel-plugin-inline-hbs-deps.js +134 -0
  10. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  11. package/src/babel-plugin-inline-hbs-node.d.ts +7 -0
  12. package/src/babel-plugin-inline-hbs-node.js +15 -0
  13. package/src/babel-plugin-inline-hbs-node.js.map +1 -0
  14. package/src/babel-plugin-inline-hbs.d.ts +24 -0
  15. package/src/babel-plugin-inline-hbs.js +142 -0
  16. package/src/babel-plugin-inline-hbs.js.map +1 -0
  17. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  18. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  19. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  20. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  21. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  22. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  23. package/src/browser-index.d.ts +1 -0
  24. package/src/browser-index.js +6 -0
  25. package/src/browser-index.js.map +1 -0
  26. package/src/ember-template-compiler-types.d.ts +41 -0
  27. package/src/ember-template-compiler-types.js +3 -0
  28. package/src/ember-template-compiler-types.js.map +1 -0
  29. package/src/load-ember-template-compiler.d.ts +6 -0
  30. package/src/load-ember-template-compiler.js +57 -0
  31. package/src/load-ember-template-compiler.js.map +1 -0
  32. package/src/messages.d.ts +0 -1
  33. package/src/mini-modules-polyfill.d.ts +12 -0
  34. package/src/mini-modules-polyfill.js +80 -0
  35. package/src/mini-modules-polyfill.js.map +1 -0
  36. package/src/module-resolver.d.ts +46 -0
  37. package/src/module-resolver.js +260 -0
  38. package/src/module-resolver.js.map +1 -0
  39. package/src/patch-template-compiler.d.ts +1 -0
  40. package/src/patch-template-compiler.js +176 -0
  41. package/src/patch-template-compiler.js.map +1 -0
  42. package/src/resolver-plugin.d.ts +3 -0
  43. package/src/resolver-plugin.js +53 -0
  44. package/src/resolver-plugin.js.map +1 -0
  45. package/src/resolver.d.ts +14 -0
  46. package/src/resolver.js +3 -0
  47. package/src/resolver.js.map +1 -0
  48. package/src/template-compiler-common.d.ts +70 -0
  49. package/src/template-compiler-common.js +176 -0
  50. package/src/template-compiler-common.js.map +1 -0
  51. package/src/template-compiler-node.d.ts +17 -0
  52. package/src/template-compiler-node.js +32 -0
  53. package/src/template-compiler-node.js.map +1 -0
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /*
3
+ This babel plugins is responsible for running custom AST transform in inline
4
+ templates. It doesn't compile to wire format, because it runs at stage1.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = require("path");
8
+ const shared_internals_1 = require("@embroider/shared-internals");
9
+ function make(getCompiler) {
10
+ function stage1InlineHBSTransform(babel) {
11
+ let t = babel.types;
12
+ return {
13
+ visitor: {
14
+ TaggedTemplateExpression(path, state) {
15
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
16
+ if (path.get('tag').referencesImport(module, exportedName)) {
17
+ handleTagged(path, state, t);
18
+ }
19
+ }
20
+ },
21
+ CallExpression(path, state) {
22
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
23
+ if (path.get('callee').referencesImport(module, exportedName)) {
24
+ handleCalled(path, state, t);
25
+ }
26
+ }
27
+ },
28
+ },
29
+ };
30
+ }
31
+ stage1InlineHBSTransform._parallelBabel = {
32
+ requireFile: __filename,
33
+ };
34
+ stage1InlineHBSTransform.baseDir = function () {
35
+ return (0, path_1.join)(__dirname, '..');
36
+ };
37
+ function handleTagged(path, state, t) {
38
+ if (path.node.quasi.expressions.length) {
39
+ throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
40
+ }
41
+ let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
42
+ let compiled = compiler(state).applyTransforms(state.file.opts.filename, template);
43
+ path.get('quasi').replaceWith(t.templateLiteral([t.templateElement({ raw: compiled, cooked: compiled })], []));
44
+ }
45
+ function handleCalled(path, state, t) {
46
+ let { template, insertRuntimeErrors } = getCallArguments(path);
47
+ let compilerInstance = compiler(state);
48
+ let compiled;
49
+ try {
50
+ compiled = compilerInstance.applyTransforms(state.file.opts.filename, template);
51
+ }
52
+ catch (err) {
53
+ if (insertRuntimeErrors) {
54
+ // in stage 1 we just leave the bad template in place (we were only
55
+ // trying to run transforms and re-emit hbs), so that it will be handled
56
+ // at stage3 instead.
57
+ return;
58
+ }
59
+ throw err;
60
+ }
61
+ path.get('arguments')[0].replaceWith(t.stringLiteral(compiled));
62
+ }
63
+ function compiler(state) {
64
+ if (!state.templateCompiler) {
65
+ state.templateCompiler = getCompiler(state.opts);
66
+ }
67
+ return state.templateCompiler;
68
+ }
69
+ function getCallArguments(path) {
70
+ let [template, options] = path.node.arguments;
71
+ let insertRuntimeErrors = (options === null || options === void 0 ? void 0 : options.type) === 'ObjectExpression' &&
72
+ options.properties.some(prop => prop.type === 'ObjectProperty' &&
73
+ prop.computed === false &&
74
+ prop.key.type === 'Identifier' &&
75
+ prop.key.name === 'insertRuntimeErrors' &&
76
+ prop.value.type === 'BooleanLiteral' &&
77
+ prop.value.value);
78
+ return {
79
+ template: getTemplateString(template, path),
80
+ insertRuntimeErrors,
81
+ };
82
+ }
83
+ return stage1InlineHBSTransform;
84
+ }
85
+ exports.default = make;
86
+ function getTemplateString(template, path) {
87
+ if ((template === null || template === void 0 ? void 0 : template.type) === 'StringLiteral') {
88
+ return template.value;
89
+ }
90
+ // treat inert TemplateLiteral (without subexpressions) like a StringLiteral
91
+ if ((template === null || template === void 0 ? void 0 : template.type) === 'TemplateLiteral' && !template.expressions.length) {
92
+ return template.quasis[0].value.cooked;
93
+ }
94
+ throw path.buildCodeFrameError('hbs accepts only a string literal argument');
95
+ }
96
+ //# sourceMappingURL=babel-plugin-stage1-inline-hbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-stage1-inline-hbs.js","sourceRoot":"","sources":["babel-plugin-stage1-inline-hbs.ts"],"names":[],"mappings":";AAAA;;;EAGE;;AAEF,+BAA4B;AAK5B,kEAAyE;AAEzE,SAAwB,IAAI,CAAO,WAA6C;IAY9E,SAAS,wBAAwB,CAAC,KAAmB;QACnD,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,wBAAwB,CAAC,IAA0C,EAAE,KAAY;oBAC/E,KAAK,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,6CAA0B,EAAE;wBAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE;4BAC1D,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;yBAC9B;qBACF;gBACH,CAAC;gBACD,cAAc,CAAC,IAAgC,EAAE,KAAY;oBAC3D,KAAK,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,6CAA0B,EAAE;wBAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE;4BAC7D,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;yBAC9B;qBACF;gBACH,CAAC;aACF;SACF,CAAC;IACJ,CAAC;IAED,wBAAwB,CAAC,cAAc,GAAG;QACxC,WAAW,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AE,IAAgC;IACxE,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,eAAe,EAAE;QACtC,OAAO,QAAQ,CAAC,KAAK,CAAC;KACvB;IACD,4EAA4E;IAC5E,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,iBAAiB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE;QACxE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;KACxC;IACD,MAAM,IAAI,CAAC,mBAAmB,CAAC,4CAA4C,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/*\n This babel plugins is responsible for running custom AST transform in inline\n templates. It doesn't compile to wire format, because it runs at stage1.\n*/\n\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { templateCompilationModules } from '@embroider/shared-internals';\n\nexport default function make<Opts>(getCompiler: (opts: Opts) => TemplateCompiler) {\n interface State {\n opts: Opts;\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n templateCompiler: TemplateCompiler | undefined;\n }\n\n function stage1InlineHBSTransform(babel: typeof Babel): unknown {\n let t = babel.types;\n return {\n visitor: {\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('tag').referencesImport(module, exportedName)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('callee').referencesImport(module, exportedName)) {\n handleCalled(path, state, t);\n }\n }\n },\n },\n };\n }\n\n stage1InlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n stage1InlineHBSTransform.baseDir = function () {\n return join(__dirname, '..');\n };\n\n function handleTagged(path: NodePath<t.TaggedTemplateExpression>, state: State, t: typeof Babel.types) {\n if (path.node.quasi.expressions.length) {\n throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');\n }\n let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');\n let compiled = compiler(state).applyTransforms(state.file.opts.filename, template);\n path.get('quasi').replaceWith(t.templateLiteral([t.templateElement({ raw: compiled, cooked: compiled })], []));\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: typeof Babel.types) {\n let { template, insertRuntimeErrors } = getCallArguments(path);\n let compilerInstance = compiler(state);\n\n let compiled: string;\n try {\n compiled = compilerInstance.applyTransforms(state.file.opts.filename, template);\n } catch (err) {\n if (insertRuntimeErrors) {\n // in stage 1 we just leave the bad template in place (we were only\n // trying to run transforms and re-emit hbs), so that it will be handled\n // at stage3 instead.\n return;\n }\n throw err;\n }\n (path.get('arguments')[0] as NodePath).replaceWith(t.stringLiteral(compiled));\n }\n\n function compiler(state: State) {\n if (!state.templateCompiler) {\n state.templateCompiler = getCompiler(state.opts);\n }\n return state.templateCompiler;\n }\n\n function getCallArguments(path: NodePath<t.CallExpression>): { template: string; insertRuntimeErrors: boolean } {\n let [template, options] = path.node.arguments;\n\n let insertRuntimeErrors =\n options?.type === 'ObjectExpression' &&\n options.properties.some(\n prop =>\n prop.type === 'ObjectProperty' &&\n prop.computed === false &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'insertRuntimeErrors' &&\n prop.value.type === 'BooleanLiteral' &&\n prop.value.value\n );\n\n return {\n template: getTemplateString(template, path),\n insertRuntimeErrors,\n };\n }\n\n return stage1InlineHBSTransform;\n}\n\nfunction getTemplateString(template: any, path: NodePath<t.CallExpression>): string {\n if (template?.type === 'StringLiteral') {\n return template.value;\n }\n // treat inert TemplateLiteral (without subexpressions) like a StringLiteral\n if (template?.type === 'TemplateLiteral' && !template.expressions.length) {\n return template.quasis[0].value.cooked;\n }\n throw path.buildCodeFrameError('hbs accepts only a string literal argument');\n}\n"]}
@@ -0,0 +1 @@
1
+ export { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemplateCompiler = void 0;
4
+ var template_compiler_common_1 = require("./template-compiler-common");
5
+ Object.defineProperty(exports, "TemplateCompiler", { enumerable: true, get: function () { return template_compiler_common_1.TemplateCompiler; } });
6
+ //# sourceMappingURL=browser-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-index.js","sourceRoot":"","sources":["browser-index.ts"],"names":[],"mappings":";;;AAAA,uEAAsF;AAA7E,4HAAA,gBAAgB,OAAA","sourcesContent":["export { TemplateCompiler, TemplateCompilerParams } from './template-compiler-common';\n"]}
@@ -0,0 +1,41 @@
1
+ export interface Plugins {
2
+ ast?: unknown[];
3
+ }
4
+ export interface AST {
5
+ _deliberatelyOpaque: 'AST';
6
+ }
7
+ export interface PreprocessOptions {
8
+ contents: string;
9
+ moduleName: string;
10
+ plugins?: Plugins;
11
+ filename?: string;
12
+ parseOptions?: {
13
+ srcName?: string;
14
+ ignoreStandalone?: boolean;
15
+ };
16
+ mode?: 'codemod' | 'precompile';
17
+ strictMode?: boolean;
18
+ locals?: string[];
19
+ }
20
+ export interface PrinterOptions {
21
+ entityEncoding?: 'transformed' | 'raw';
22
+ }
23
+ export interface GlimmerSyntax {
24
+ preprocess(html: string, options?: PreprocessOptions): AST;
25
+ print(ast: AST, options?: PrinterOptions): string;
26
+ defaultOptions(options: PreprocessOptions): PreprocessOptions;
27
+ precompile(templateContents: string, options: {
28
+ contents: string;
29
+ moduleName: string;
30
+ filename: string;
31
+ plugins?: any;
32
+ parseOptions?: {
33
+ srcName?: string;
34
+ };
35
+ }): string;
36
+ _Ember: {
37
+ FEATURES: any;
38
+ ENV: any;
39
+ };
40
+ cacheKey: string;
41
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ember-template-compiler-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ember-template-compiler-types.js","sourceRoot":"","sources":["ember-template-compiler-types.ts"],"names":[],"mappings":"","sourcesContent":["export 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 cacheKey: string;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ declare type EmbersExports = {
2
+ cacheKey: string;
3
+ theExports: any;
4
+ };
5
+ export declare function getEmberExports(templateCompilerPath: string): EmbersExports;
6
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEmberExports = void 0;
4
+ const fs_1 = require("fs");
5
+ const vm_1 = require("vm");
6
+ const crypto_1 = require("crypto");
7
+ const patch_template_compiler_1 = require("./patch-template-compiler");
8
+ const CACHE = new Map();
9
+ function getEmberExports(templateCompilerPath) {
10
+ let entry = CACHE.get(templateCompilerPath);
11
+ if (entry) {
12
+ let currentStat = (0, fs_1.statSync)(templateCompilerPath);
13
+ // Let's ensure the template is still what we cached
14
+ if (currentStat.mode === entry.stat.mode &&
15
+ currentStat.size === entry.stat.size &&
16
+ currentStat.mtime.getTime() === entry.stat.mtime.getTime()) {
17
+ return entry.value;
18
+ }
19
+ }
20
+ let stat = (0, fs_1.statSync)(templateCompilerPath);
21
+ let source = (0, patch_template_compiler_1.patch)((0, fs_1.readFileSync)(templateCompilerPath, 'utf8'), templateCompilerPath);
22
+ let theExports = undefined;
23
+ // cacheKey, theExports
24
+ let cacheKey = (0, crypto_1.createHash)('md5').update(source).digest('hex');
25
+ entry = Object.freeze({
26
+ value: {
27
+ cacheKey,
28
+ get theExports() {
29
+ if (theExports) {
30
+ return theExports;
31
+ }
32
+ // matches (essentially) what ember-cli-htmlbars does in https://git.io/Jtbpj
33
+ let sandbox = {
34
+ module: { require, exports: {} },
35
+ require,
36
+ };
37
+ if (typeof globalThis === 'undefined') {
38
+ // for Node 10 usage with Ember 3.27+ we have to define the `global` global
39
+ // in order for ember-template-compiler.js to evaluate properly
40
+ // due to this code https://git.io/Jtb7
41
+ sandbox.global = sandbox;
42
+ }
43
+ // using vm.createContext / vm.Script to ensure we evaluate in a fresh sandbox context
44
+ // so that any global mutation done within ember-template-compiler.js does not leak out
45
+ let context = (0, vm_1.createContext)(sandbox);
46
+ let script = new vm_1.Script(source, { filename: templateCompilerPath });
47
+ script.runInContext(context);
48
+ return (theExports = context.module.exports);
49
+ },
50
+ },
51
+ stat, // This is stored, so we can reload the templateCompiler if it changes mid-build.
52
+ });
53
+ CACHE.set(templateCompilerPath, entry);
54
+ return entry.value;
55
+ }
56
+ exports.getEmberExports = getEmberExports;
57
+ //# sourceMappingURL=load-ember-template-compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-ember-template-compiler.js","sourceRoot":"","sources":["load-ember-template-compiler.ts"],"names":[],"mappings":";;;AAAA,2BAAgD;AAChD,2BAA2C;AAC3C,mCAAoC;AACpC,uEAAkD;AAYl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;oBAC/D,uCAAuC;oBACtC,OAAe,CAAC,MAAM,GAAG,OAAO,CAAC;iBACnC;gBACD,sFAAsF;gBACtF,uFAAuF;gBACvF,IAAI,OAAO,GAAG,IAAA,kBAAa,EAAC,OAAO,CAAC,CAAC;gBACrC,IAAI,MAAM,GAAG,IAAI,WAAM,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC,CAAC;gBAEpE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;gBAC7B,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/C,CAAC;SACF;QACD,IAAI,EAAE,iFAAiF;KACxF,CAAC,CAAC;IAEH,KAAK,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AA1DD,0CA0DC","sourcesContent":["import fs, { readFileSync, statSync } from 'fs';\nimport { createContext, Script } from 'vm';\nimport { createHash } from 'crypto';\nimport { patch } from './patch-template-compiler';\n\ntype TemplateCompilerCacheEntry = {\n value: EmbersExports;\n stat: fs.Stats;\n};\n\ntype EmbersExports = {\n cacheKey: string;\n theExports: any;\n};\n\nconst CACHE = new Map<string, TemplateCompilerCacheEntry>();\n\nexport function getEmberExports(templateCompilerPath: string): EmbersExports {\n let entry = CACHE.get(templateCompilerPath);\n\n if (entry) {\n let currentStat = statSync(templateCompilerPath);\n\n // Let's ensure the template is still what we cached\n if (\n currentStat.mode === entry.stat.mode &&\n currentStat.size === entry.stat.size &&\n currentStat.mtime.getTime() === entry.stat.mtime.getTime()\n ) {\n return entry.value;\n }\n }\n\n let stat = statSync(templateCompilerPath);\n\n let source = patch(readFileSync(templateCompilerPath, 'utf8'), templateCompilerPath);\n let theExports: any = undefined;\n\n // cacheKey, theExports\n let cacheKey = createHash('md5').update(source).digest('hex');\n\n entry = Object.freeze({\n value: {\n cacheKey,\n get theExports() {\n if (theExports) {\n return theExports;\n }\n\n // matches (essentially) what ember-cli-htmlbars does in https://git.io/Jtbpj\n let sandbox = {\n module: { require, exports: {} },\n require,\n };\n\n if (typeof globalThis === 'undefined') {\n // for Node 10 usage with Ember 3.27+ we have to define the `global` global\n // in order for ember-template-compiler.js to evaluate properly\n // due to this code https://git.io/Jtb7\n (sandbox as any).global = sandbox;\n }\n // using vm.createContext / vm.Script to ensure we evaluate in a fresh sandbox context\n // so that any global mutation done within ember-template-compiler.js does not leak out\n let context = createContext(sandbox);\n let script = new Script(source, { filename: templateCompilerPath });\n\n script.runInContext(context);\n return (theExports = context.module.exports);\n },\n },\n stat, // This is stored, so we can reload the templateCompiler if it changes mid-build.\n });\n\n CACHE.set(templateCompilerPath, entry);\n return entry.value;\n}\n"]}
package/src/messages.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="qunit" />
2
- /// <reference types="ember-qunit" />
3
2
  import makeDebug from 'debug';
4
3
  declare const todo: makeDebug.Debugger;
5
4
  declare const unsupported: makeDebug.Debugger;
@@ -0,0 +1,12 @@
1
+ import type { types as t } from '@babel/core';
2
+ import type { NodePath } from '@babel/traverse';
3
+ declare type BabelTypes = typeof t;
4
+ export default function miniModulesPolyfill(babel: unknown): {
5
+ visitor: {
6
+ Program: {
7
+ exit(path: NodePath<t.Program>): void;
8
+ };
9
+ };
10
+ };
11
+ export declare function handleImportDeclaration(t: BabelTypes, path: NodePath<t.ImportDeclaration>): undefined;
12
+ export {};
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleImportDeclaration = void 0;
4
+ // this is intentionally not the whole babel-plugin-ember-modules-api-polyfill.
5
+ // That runs very early, so any usage of polyfilled imports that gets emitted by
6
+ // our other babel plugins can't take advantage of it.
7
+ //
8
+ // If I was going to try to do this properly, I would change
9
+ // babel-plugin-ember-modules-api-polyfill to run very late in the game, like
10
+ // this code does, so that other plugins could always not worry about it. But
11
+ // seeing as modules-api-polyfill is already on the way out, it's simpler to
12
+ // just handle the small piece of its functionality that matter to us:
13
+ //
14
+ // - all our usage (emitted by our babel plugins) is static imports, not dynamic
15
+ // ones, so it's OK to just walk the top level, saving us the cost of a full
16
+ // traverse
17
+ // - we only emit a handful of specific imports that are easy to just list here
18
+ //
19
+ //
20
+ let replacements = {
21
+ '@ember/component/template-only': {
22
+ default(t) {
23
+ return t.memberExpression(t.identifier('Ember'), t.identifier('_templateOnlyComponent'));
24
+ },
25
+ },
26
+ '@ember/template-factory': {
27
+ createTemplateFactory(t) {
28
+ return t.memberExpression(t.memberExpression(t.identifier('Ember'), t.identifier('HTMLBars')), t.identifier('template'));
29
+ },
30
+ },
31
+ '@ember/component': {
32
+ default(t) {
33
+ return t.memberExpression(t.identifier('Ember'), t.identifier('Component'));
34
+ },
35
+ setComponentTemplate(t) {
36
+ return t.memberExpression(t.identifier('Ember'), t.identifier('_setComponentTemplate'));
37
+ },
38
+ },
39
+ };
40
+ function miniModulesPolyfill(babel) {
41
+ let t = babel.types;
42
+ return {
43
+ visitor: {
44
+ Program: {
45
+ exit(path) {
46
+ for (let child of path.get('body')) {
47
+ if (child.isImportDeclaration()) {
48
+ let replacement = handleImportDeclaration(t, child);
49
+ if (replacement) {
50
+ path.replaceWith(replacement);
51
+ }
52
+ }
53
+ }
54
+ },
55
+ },
56
+ },
57
+ };
58
+ }
59
+ exports.default = miniModulesPolyfill;
60
+ function handleImportDeclaration(t, path) {
61
+ let match = replacements[path.node.source.value];
62
+ if (match) {
63
+ let specifiers = path.get('specifiers');
64
+ let replacers = specifiers.map(specifier => ({ replacer: match[specifier.node.local.name], specifier }));
65
+ if (replacers.every(r => Boolean(r.replacer))) {
66
+ path.replaceWith(t.variableDeclaration('const', replacers.map(r => t.variableDeclarator(r.specifier.node.local, r.replacer(t)))));
67
+ }
68
+ else {
69
+ for (let { specifier, replacer } of replacers) {
70
+ if (replacer) {
71
+ path.insertAfter(t.variableDeclaration('const', [t.variableDeclarator(specifier.node.local, replacer(t))]));
72
+ specifier.remove();
73
+ }
74
+ }
75
+ }
76
+ }
77
+ return undefined;
78
+ }
79
+ exports.handleImportDeclaration = handleImportDeclaration;
80
+ //# sourceMappingURL=mini-modules-polyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mini-modules-polyfill.js","sourceRoot":"","sources":["mini-modules-polyfill.ts"],"names":[],"mappings":";;;AAKA,+EAA+E;AAC/E,gFAAgF;AAChF,sDAAsD;AACtD,EAAE;AACF,4DAA4D;AAC5D,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,aAAa;AACb,+EAA+E;AAC/E,EAAE;AACF,EAAE;AACF,IAAI,YAAY,GAAqG;IACnH,gCAAgC,EAAE;QAChC,OAAO,CAAC,CAAa;YACnB,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC;QAC3F,CAAC;KACF;IACD,yBAAyB,EAAE;QACzB,qBAAqB,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC,gBAAgB,CACvB,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EACnE,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CACzB,CAAC;QACJ,CAAC;KACF;IACD,kBAAkB,EAAE;QAClB,OAAO,CAAC,CAAa;YACnB,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAC9E,CAAC;QACD,oBAAoB,CAAC,CAAa;YAChC,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,OAA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CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACjF,CACF,CAAC;SACH;aAAM;YACL,KAAK,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE;gBAC7C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC5G,SAAS,CAAC,MAAM,EAAE,CAAC;iBACpB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAtBD,0DAsBC","sourcesContent":["import type { types as t } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\n\ntype BabelTypes = typeof t;\n\n// this is intentionally not the whole babel-plugin-ember-modules-api-polyfill.\n// That runs very early, so any usage of polyfilled imports that gets emitted by\n// our other babel plugins can't take advantage of it.\n//\n// If I was going to try to do this properly, I would change\n// babel-plugin-ember-modules-api-polyfill to run very late in the game, like\n// this code does, so that other plugins could always not worry about it. But\n// seeing as modules-api-polyfill is already on the way out, it's simpler to\n// just handle the small piece of its functionality that matter to us:\n//\n// - all our usage (emitted by our babel plugins) is static imports, not dynamic\n// ones, so it's OK to just walk the top level, saving us the cost of a full\n// traverse\n// - we only emit a handful of specific imports that are easy to just list here\n//\n//\nlet replacements: { [moduleSpecifier: string]: { [name: string]: ((t: BabelTypes) => t.Expression) | undefined } } = {\n '@ember/component/template-only': {\n default(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('_templateOnlyComponent'));\n },\n },\n '@ember/template-factory': {\n createTemplateFactory(t) {\n return t.memberExpression(\n t.memberExpression(t.identifier('Ember'), t.identifier('HTMLBars')),\n t.identifier('template')\n );\n },\n },\n '@ember/component': {\n default(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('Component'));\n },\n setComponentTemplate(t: BabelTypes) {\n return t.memberExpression(t.identifier('Ember'), t.identifier('_setComponentTemplate'));\n },\n },\n};\n\nexport default function miniModulesPolyfill(babel: unknown) {\n let t = (babel as any).types as BabelTypes;\n return {\n visitor: {\n Program: {\n exit(path: NodePath<t.Program>) {\n for (let child of path.get('body')) {\n if (child.isImportDeclaration()) {\n let replacement = handleImportDeclaration(t, child);\n if (replacement) {\n path.replaceWith(replacement);\n }\n }\n }\n },\n },\n },\n };\n}\n\nexport function handleImportDeclaration(t: BabelTypes, path: NodePath<t.ImportDeclaration>) {\n let match = replacements[path.node.source.value];\n if (match) {\n let specifiers = path.get('specifiers');\n let replacers = specifiers.map(specifier => ({ replacer: match[specifier.node.local.name], specifier }));\n if (replacers.every(r => Boolean(r.replacer))) {\n path.replaceWith(\n t.variableDeclaration(\n 'const',\n replacers.map(r => t.variableDeclarator(r.specifier.node.local, r.replacer!(t)))\n )\n );\n } else {\n for (let { specifier, replacer } of replacers) {\n if (replacer) {\n path.insertAfter(t.variableDeclaration('const', [t.variableDeclarator(specifier.node.local, replacer(t))]));\n specifier.remove();\n }\n }\n }\n }\n return undefined;\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { Package } from '@embroider/shared-internals';
2
+ export interface Options {
3
+ renamePackages: {
4
+ [fromName: string]: string;
5
+ };
6
+ renameModules: {
7
+ [fromName: string]: string;
8
+ };
9
+ extraImports: {
10
+ absPath: string;
11
+ target: string;
12
+ runtimeName?: string;
13
+ }[];
14
+ externalsDir: string;
15
+ activeAddons: {
16
+ [packageName: string]: string;
17
+ };
18
+ relocatedFiles: {
19
+ [relativePath: string]: string;
20
+ };
21
+ resolvableExtensions: string[];
22
+ appRoot: string;
23
+ }
24
+ export declare type Resolution = {
25
+ result: 'continue';
26
+ } | {
27
+ result: 'redirect-to';
28
+ specifier: string;
29
+ } | {
30
+ result: 'external';
31
+ specifier: string;
32
+ } | {
33
+ result: 'runtime-failure';
34
+ specifier: string;
35
+ };
36
+ export declare class Resolver {
37
+ readonly filename: string;
38
+ private options;
39
+ readonly originalFilename: string;
40
+ constructor(filename: string, options: Options);
41
+ resolve(specifier: string, isDynamic: boolean): Resolution;
42
+ owningPackage(): Package | undefined;
43
+ private relocatedIntoPackage;
44
+ private handleRenaming;
45
+ private handleExternal;
46
+ }