@embroider/core 2.1.1 → 2.1.2-unstable.3a9d8ad

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 (73) hide show
  1. package/package.json +3 -4
  2. package/src/app-differ.d.ts +1 -1
  3. package/src/app-differ.js +21 -22
  4. package/src/app-differ.js.map +1 -1
  5. package/src/app-files.d.ts +1 -2
  6. package/src/app-files.js +0 -7
  7. package/src/app-files.js.map +1 -1
  8. package/src/app.d.ts +9 -7
  9. package/src/app.js +32 -46
  10. package/src/app.js.map +1 -1
  11. package/src/describe-exports.d.ts +0 -1
  12. package/src/describe-exports.js +8 -9
  13. package/src/describe-exports.js.map +1 -1
  14. package/src/index.d.ts +3 -0
  15. package/src/index.js +5 -1
  16. package/src/index.js.map +1 -1
  17. package/src/module-resolver.d.ts +66 -25
  18. package/src/module-resolver.js +698 -131
  19. package/src/module-resolver.js.map +1 -1
  20. package/src/options.d.ts +0 -1
  21. package/src/options.js.map +1 -1
  22. package/src/virtual-content.d.ts +9 -0
  23. package/src/virtual-content.js +131 -0
  24. package/src/virtual-content.js.map +1 -0
  25. package/src/wait-for-trees.js.map +1 -1
  26. package/src/babel-plugin-adjust-imports.d.ts +0 -31
  27. package/src/babel-plugin-adjust-imports.js +0 -224
  28. package/src/babel-plugin-adjust-imports.js.map +0 -1
  29. package/src/babel-plugin-inline-hbs-deps-node.d.ts +0 -14
  30. package/src/babel-plugin-inline-hbs-deps-node.js +0 -27
  31. package/src/babel-plugin-inline-hbs-deps-node.js.map +0 -1
  32. package/src/babel-plugin-inline-hbs-deps.d.ts +0 -10
  33. package/src/babel-plugin-inline-hbs-deps.js +0 -134
  34. package/src/babel-plugin-inline-hbs-deps.js.map +0 -1
  35. package/src/babel-plugin-inline-hbs-node.d.ts +0 -7
  36. package/src/babel-plugin-inline-hbs-node.js +0 -15
  37. package/src/babel-plugin-inline-hbs-node.js.map +0 -1
  38. package/src/babel-plugin-inline-hbs.d.ts +0 -24
  39. package/src/babel-plugin-inline-hbs.js +0 -142
  40. package/src/babel-plugin-inline-hbs.js.map +0 -1
  41. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +0 -12
  42. package/src/babel-plugin-stage1-inline-hbs-node.js +0 -9
  43. package/src/babel-plugin-stage1-inline-hbs-node.js.map +0 -1
  44. package/src/babel-plugin-stage1-inline-hbs.d.ts +0 -9
  45. package/src/babel-plugin-stage1-inline-hbs.js +0 -96
  46. package/src/babel-plugin-stage1-inline-hbs.js.map +0 -1
  47. package/src/browser-index.d.ts +0 -1
  48. package/src/browser-index.js +0 -6
  49. package/src/browser-index.js.map +0 -1
  50. package/src/ember-template-compiler-types.d.ts +0 -41
  51. package/src/ember-template-compiler-types.js +0 -3
  52. package/src/ember-template-compiler-types.js.map +0 -1
  53. package/src/load-ember-template-compiler.d.ts +0 -6
  54. package/src/load-ember-template-compiler.js +0 -57
  55. package/src/load-ember-template-compiler.js.map +0 -1
  56. package/src/mini-modules-polyfill.d.ts +0 -12
  57. package/src/mini-modules-polyfill.js +0 -80
  58. package/src/mini-modules-polyfill.js.map +0 -1
  59. package/src/patch-template-compiler.d.ts +0 -1
  60. package/src/patch-template-compiler.js +0 -176
  61. package/src/patch-template-compiler.js.map +0 -1
  62. package/src/resolver-plugin.d.ts +0 -3
  63. package/src/resolver-plugin.js +0 -53
  64. package/src/resolver-plugin.js.map +0 -1
  65. package/src/resolver.d.ts +0 -14
  66. package/src/resolver.js +0 -3
  67. package/src/resolver.js.map +0 -1
  68. package/src/template-compiler-common.d.ts +0 -70
  69. package/src/template-compiler-common.js +0 -176
  70. package/src/template-compiler-common.js.map +0 -1
  71. package/src/template-compiler-node.d.ts +0 -17
  72. package/src/template-compiler-node.js +0 -32
  73. package/src/template-compiler-node.js.map +0 -1
@@ -1,224 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isDefineExpression = exports.isDynamicImportExpression = exports.isImportSyncExpression = void 0;
7
- const path_1 = require("path");
8
- const babel_import_util_1 = require("babel-import-util");
9
- const crypto_1 = require("crypto");
10
- const fs_extra_1 = require("fs-extra");
11
- const shared_internals_1 = require("@embroider/shared-internals");
12
- const js_handlebars_1 = require("./js-handlebars");
13
- const module_resolver_1 = require("./module-resolver");
14
- const assert_never_1 = __importDefault(require("assert-never"));
15
- function isImportSyncExpression(t, path) {
16
- if (!path ||
17
- !path.isCallExpression() ||
18
- path.node.callee.type !== 'Identifier' ||
19
- !path.get('callee').referencesImport('@embroider/macros', 'importSync')) {
20
- return false;
21
- }
22
- const args = path.node.arguments;
23
- return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);
24
- }
25
- exports.isImportSyncExpression = isImportSyncExpression;
26
- function isDynamicImportExpression(t, path) {
27
- if (!path || !path.isCallExpression() || path.node.callee.type !== 'Import') {
28
- return false;
29
- }
30
- const args = path.node.arguments;
31
- return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);
32
- }
33
- exports.isDynamicImportExpression = isDynamicImportExpression;
34
- function isDefineExpression(t, path) {
35
- // should we allow nested defines, or stop at the top level?
36
- if (!path.isCallExpression() || path.node.callee.type !== 'Identifier' || path.node.callee.name !== 'define') {
37
- return false;
38
- }
39
- const args = path.node.arguments;
40
- // only match define with 3 arguments define(name: string, deps: string[], cb: Function);
41
- return (Array.isArray(args) &&
42
- args.length === 3 &&
43
- t.isStringLiteral(args[0]) &&
44
- t.isArrayExpression(args[1]) &&
45
- t.isFunction(args[2]));
46
- }
47
- exports.isDefineExpression = isDefineExpression;
48
- function main(babel) {
49
- let t = babel.types;
50
- return {
51
- visitor: {
52
- Program: {
53
- enter(path, state) {
54
- let opts = ensureOpts(state);
55
- state.resolver = new module_resolver_1.Resolver(path.hub.file.opts.filename, opts);
56
- let adder = new babel_import_util_1.ImportUtil(t, path);
57
- addExtraImports(adder, t, path, opts.extraImports);
58
- },
59
- exit(path, state) {
60
- for (let child of path.get('body')) {
61
- if (child.isImportDeclaration() || child.isExportNamedDeclaration() || child.isExportAllDeclaration()) {
62
- rewriteTopLevelImport(child, state);
63
- }
64
- }
65
- },
66
- },
67
- CallExpression(path, state) {
68
- if (isImportSyncExpression(t, path) || isDynamicImportExpression(t, path)) {
69
- const [source] = path.get('arguments');
70
- resolve(source.node.value, true, state, newSpecifier => {
71
- source.replaceWith(t.stringLiteral(newSpecifier));
72
- });
73
- return;
74
- }
75
- // Should/can we make this early exit when the first define was found?
76
- if (!isDefineExpression(t, path)) {
77
- return;
78
- }
79
- let pkg = state.resolver.owningPackage();
80
- if (pkg && pkg.isV2Ember() && !pkg.meta['auto-upgraded']) {
81
- throw new Error(`The file ${state.resolver.originalFilename} in package ${pkg.name} tried to use AMD define. Native V2 Ember addons are forbidden from using AMD define, they must use ECMA export only.`);
82
- }
83
- const dependencies = path.node.arguments[1];
84
- const specifiers = dependencies.elements.slice();
85
- specifiers.push(path.node.arguments[0]);
86
- for (const source of specifiers) {
87
- if (!source) {
88
- continue;
89
- }
90
- if (source.type !== 'StringLiteral') {
91
- throw path.buildCodeFrameError(`expected only string literal arguments`);
92
- }
93
- if (source.value === 'exports' || source.value === 'require') {
94
- // skip "special" AMD dependencies
95
- continue;
96
- }
97
- resolve(source.value, false, state, newSpecifier => {
98
- source.value = newSpecifier;
99
- });
100
- }
101
- },
102
- },
103
- };
104
- }
105
- exports.default = main;
106
- function rewriteTopLevelImport(path, state) {
107
- const { source } = path.node;
108
- if (source === null || source === undefined) {
109
- return;
110
- }
111
- resolve(source.value, false, state, newSpecifier => {
112
- source.value = newSpecifier;
113
- });
114
- }
115
- main.baseDir = function () {
116
- return (0, path_1.join)(__dirname, '..');
117
- };
118
- function addExtraImports(adder, t, path, extraImports) {
119
- for (let { absPath, target, runtimeName } of extraImports) {
120
- if (absPath === path.hub.file.opts.filename) {
121
- if (runtimeName) {
122
- path.node.body.unshift(amdDefine(t, adder, path, target, runtimeName));
123
- }
124
- else {
125
- adder.importForSideEffect(target);
126
- }
127
- }
128
- }
129
- }
130
- function amdDefine(t, adder, path, target, runtimeName) {
131
- let value = t.callExpression(adder.import(path, '@embroider/macros', 'importSync'), [t.stringLiteral(target)]);
132
- return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
133
- t.stringLiteral(runtimeName),
134
- t.functionExpression(null, [], t.blockStatement([t.returnStatement(value)])),
135
- ]));
136
- }
137
- function ensureOpts(state) {
138
- let { opts } = state;
139
- if ('adjustImportsOptionsPath' in opts) {
140
- // eslint-disable-next-line @typescript-eslint/no-require-imports
141
- return (state.opts = { ...require(opts.adjustImportsOptionsPath), ...require(opts.relocatedFilesPath) });
142
- }
143
- return opts;
144
- }
145
- function makeExternal(specifier, sourceFile, opts) {
146
- let target = (0, path_1.join)(opts.externalsDir, specifier + '.js');
147
- atomicWrite(target, externalTemplate({
148
- runtimeName: specifier,
149
- }));
150
- return (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(sourceFile), target.slice(0, -3));
151
- }
152
- function atomicWrite(path, content) {
153
- if ((0, fs_extra_1.pathExistsSync)(path)) {
154
- return;
155
- }
156
- let suffix = (0, crypto_1.randomBytes)(8).toString('hex');
157
- (0, fs_extra_1.outputFileSync)(path + suffix, content);
158
- try {
159
- (0, fs_extra_1.renameSync)(path + suffix, path);
160
- }
161
- catch (err) {
162
- // windows throws EPERM for concurrent access. For us it's not an error
163
- // condition because the other thread is writing the exact same value we
164
- // would have.
165
- if (err.code !== 'EPERM') {
166
- throw err;
167
- }
168
- }
169
- }
170
- function makeMissingModule(specifier, sourceFile, opts) {
171
- let target = (0, path_1.join)(opts.externalsDir, 'missing', specifier + '.js');
172
- atomicWrite(target, dynamicMissingModule({
173
- moduleName: specifier,
174
- }));
175
- return (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(sourceFile), target.slice(0, -3));
176
- }
177
- const dynamicMissingModule = (0, js_handlebars_1.compile)(`
178
- throw new Error('Could not find module \`{{{js-string-escape moduleName}}}\`');
179
- `);
180
- const externalTemplate = (0, js_handlebars_1.compile)(`
181
- {{#if (eq runtimeName "require")}}
182
- const m = window.requirejs;
183
- {{else}}
184
- const m = window.require("{{{js-string-escape runtimeName}}}");
185
- {{/if}}
186
- {{!-
187
- There are plenty of hand-written AMD defines floating around
188
- that lack this, and they will break when other build systems
189
- encounter them.
190
-
191
- As far as I can tell, Ember's loader was already treating this
192
- case as a module, so in theory we aren't breaking anything by
193
- marking it as such when other packagers come looking.
194
-
195
- todo: get review on this part.
196
- -}}
197
- if (m.default && !m.__esModule) {
198
- m.__esModule = true;
199
- }
200
- module.exports = m;
201
- `);
202
- function resolve(specifier, isDynamic, state, setter) {
203
- let resolution = state.resolver.resolve(specifier, isDynamic);
204
- let newSpecifier;
205
- switch (resolution.result) {
206
- case 'continue':
207
- return;
208
- case 'external':
209
- newSpecifier = makeExternal(resolution.specifier, state.resolver.filename, ensureOpts(state));
210
- break;
211
- case 'redirect-to':
212
- newSpecifier = resolution.specifier;
213
- break;
214
- case 'runtime-failure':
215
- newSpecifier = makeMissingModule(resolution.specifier, state.resolver.filename, ensureOpts(state));
216
- break;
217
- default:
218
- throw (0, assert_never_1.default)(resolution);
219
- }
220
- if (newSpecifier) {
221
- setter(newSpecifier);
222
- }
223
- }
224
- //# sourceMappingURL=babel-plugin-adjust-imports.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-adjust-imports.js","sourceRoot":"","sources":["babel-plugin-adjust-imports.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAqC;AAIrC,yDAA+C;AAC/C,mCAAqC;AACrC,uCAAsE;AACtE,kEAA+D;AAC/D,mDAA0C;AAC1C,uDAAsD;AACtD,gEAAuC;AAsBvC,SAAgB,sBAAsB,CAAC,CAAa,EAAE,IAAmB;IACvE,IACE,CAAC,IAAI;QACL,CAAC,IAAI,CAAC,gBAAgB,EAAE;QACxB,IAAI,CAAC,IAAI,CAAC,MAAM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;IACvG,IAAI,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,YAAgC,CAAC;IACrC,QAAQ,UAAU,CAAC,MAAM,EAAE;QACzB,KAAK,UAAU;YACb,OAAO;QACT,KAAK,UAAU;YACb,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9F,MAAM;QACR,KAAK,aAAa;YAChB,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC;YACpC,MAAM;QACR,KAAK,iBAAiB;YACpB,YAAY,GAAG,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACnG,MAAM;QACR;YACE,MAAM,IAAA,sBAAW,EAAC,UAAU,CAAC,CAAC;KACjC;IACD,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,YAAY,CAAC,CAAC;KACtB;AACH,CAAC","sourcesContent":["import { join, dirname } from 'path';\nimport type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { ImportUtil } from 'babel-import-util';\nimport { randomBytes } from 'crypto';\nimport { outputFileSync, pathExistsSync, renameSync } from 'fs-extra';\nimport { explicitRelative } from '@embroider/shared-internals';\nimport { compile } from './js-handlebars';\nimport { Options, Resolver } from './module-resolver';\nimport assertNever from 'assert-never';\n\ninterface State {\n resolver: Resolver;\n opts: Options | DeflatedOptions;\n}\n\nexport { Options };\n\nexport interface DeflatedOptions {\n adjustImportsOptionsPath: string;\n relocatedFilesPath: string;\n}\n\ntype BabelTypes = typeof t;\n\ntype DefineExpressionPath = NodePath<t.CallExpression> & {\n node: t.CallExpression & {\n arguments: [t.StringLiteral, t.ArrayExpression, Function];\n };\n};\n\nexport function isImportSyncExpression(t: BabelTypes, path: NodePath<any>) {\n if (\n !path ||\n !path.isCallExpression() ||\n path.node.callee.type !== 'Identifier' ||\n !path.get('callee').referencesImport('@embroider/macros', 'importSync')\n ) {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDynamicImportExpression(t: BabelTypes, path: NodePath<any>) {\n if (!path || !path.isCallExpression() || path.node.callee.type !== 'Import') {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDefineExpression(t: BabelTypes, path: NodePath<any>): path is DefineExpressionPath {\n // should we allow nested defines, or stop at the top level?\n if (!path.isCallExpression() || path.node.callee.type !== 'Identifier' || path.node.callee.name !== 'define') {\n return false;\n }\n\n const args = path.node.arguments;\n\n // only match define with 3 arguments define(name: string, deps: string[], cb: Function);\n return (\n Array.isArray(args) &&\n args.length === 3 &&\n t.isStringLiteral(args[0]) &&\n t.isArrayExpression(args[1]) &&\n t.isFunction(args[2])\n );\n}\n\nexport default function main(babel: typeof Babel) {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n let opts = ensureOpts(state);\n state.resolver = new Resolver(path.hub.file.opts.filename, opts);\n let adder = new ImportUtil(t, path);\n addExtraImports(adder, t, path, opts.extraImports);\n },\n exit(path: NodePath<t.Program>, state: State) {\n for (let child of path.get('body')) {\n if (child.isImportDeclaration() || child.isExportNamedDeclaration() || child.isExportAllDeclaration()) {\n rewriteTopLevelImport(child, state);\n }\n }\n },\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n if (isImportSyncExpression(t, path) || isDynamicImportExpression(t, path)) {\n const [source] = path.get('arguments');\n resolve((source.node as any).value, true, state, newSpecifier => {\n source.replaceWith(t.stringLiteral(newSpecifier));\n });\n return;\n }\n\n // Should/can we make this early exit when the first define was found?\n if (!isDefineExpression(t, path)) {\n return;\n }\n\n let pkg = state.resolver.owningPackage();\n if (pkg && pkg.isV2Ember() && !pkg.meta['auto-upgraded']) {\n throw new Error(\n `The file ${state.resolver.originalFilename} in package ${pkg.name} tried to use AMD define. Native V2 Ember addons are forbidden from using AMD define, they must use ECMA export only.`\n );\n }\n\n const dependencies = path.node.arguments[1];\n\n const specifiers = dependencies.elements.slice();\n specifiers.push(path.node.arguments[0]);\n\n for (const source of specifiers) {\n if (!source) {\n continue;\n }\n\n if (source.type !== 'StringLiteral') {\n throw path.buildCodeFrameError(`expected only string literal arguments`);\n }\n\n if (source.value === 'exports' || source.value === 'require') {\n // skip \"special\" AMD dependencies\n continue;\n }\n\n resolve(source.value, false, state, newSpecifier => {\n source.value = newSpecifier;\n });\n }\n },\n },\n };\n}\n\nfunction rewriteTopLevelImport(\n path: NodePath<t.ImportDeclaration | t.ExportNamedDeclaration | t.ExportAllDeclaration>,\n state: State\n) {\n const { source } = path.node;\n if (source === null || source === undefined) {\n return;\n }\n\n resolve(source.value, false, state, newSpecifier => {\n source.value = newSpecifier;\n });\n}\n\n(main as any).baseDir = function () {\n return join(__dirname, '..');\n};\n\nfunction addExtraImports(\n adder: ImportUtil,\n t: BabelTypes,\n path: NodePath<t.Program>,\n extraImports: Required<Options>['extraImports']\n) {\n for (let { absPath, target, runtimeName } of extraImports) {\n if (absPath === path.hub.file.opts.filename) {\n if (runtimeName) {\n path.node.body.unshift(amdDefine(t, adder, path, target, runtimeName));\n } else {\n adder.importForSideEffect(target);\n }\n }\n }\n}\n\nfunction amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath<t.Program>, target: string, runtimeName: string) {\n let value = t.callExpression(adder.import(path, '@embroider/macros', 'importSync'), [t.stringLiteral(target)]);\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(value)])),\n ])\n );\n}\n\nfunction ensureOpts(state: State): Options {\n let { opts } = state;\n if ('adjustImportsOptionsPath' in opts) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n return (state.opts = { ...require(opts.adjustImportsOptionsPath), ...require(opts.relocatedFilesPath) });\n }\n return opts;\n}\n\nfunction makeExternal(specifier: string, sourceFile: string, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n atomicWrite(\n target,\n externalTemplate({\n runtimeName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile), target.slice(0, -3));\n}\n\nfunction atomicWrite(path: string, content: string) {\n if (pathExistsSync(path)) {\n return;\n }\n let suffix = randomBytes(8).toString('hex');\n outputFileSync(path + suffix, content);\n try {\n renameSync(path + suffix, path);\n } catch (err: any) {\n // windows throws EPERM for concurrent access. For us it's not an error\n // condition because the other thread is writing the exact same value we\n // would have.\n if (err.code !== 'EPERM') {\n throw err;\n }\n }\n}\n\nfunction makeMissingModule(specifier: string, sourceFile: string, opts: Options): string {\n let target = join(opts.externalsDir, 'missing', specifier + '.js');\n atomicWrite(\n target,\n dynamicMissingModule({\n moduleName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile), target.slice(0, -3));\n}\n\nconst dynamicMissingModule = compile(`\n throw new Error('Could not find module \\`{{{js-string-escape moduleName}}}\\`');\n`) as (params: { moduleName: string }) => string;\n\nconst externalTemplate = compile(`\n{{#if (eq runtimeName \"require\")}}\nconst m = window.requirejs;\n{{else}}\nconst m = window.require(\"{{{js-string-escape runtimeName}}}\");\n{{/if}}\n{{!-\n There are plenty of hand-written AMD defines floating around\n that lack this, and they will break when other build systems\n encounter them.\n\n As far as I can tell, Ember's loader was already treating this\n case as a module, so in theory we aren't breaking anything by\n marking it as such when other packagers come looking.\n\n todo: get review on this part.\n-}}\nif (m.default && !m.__esModule) {\n m.__esModule = true;\n}\nmodule.exports = m;\n`) as (params: { runtimeName: string }) => string;\n\nfunction resolve(specifier: string, isDynamic: boolean, state: State, setter: (specifier: string) => void) {\n let resolution = state.resolver.resolve(specifier, isDynamic);\n let newSpecifier: string | undefined;\n switch (resolution.result) {\n case 'continue':\n return;\n case 'external':\n newSpecifier = makeExternal(resolution.specifier, state.resolver.filename, ensureOpts(state));\n break;\n case 'redirect-to':\n newSpecifier = resolution.specifier;\n break;\n case 'runtime-failure':\n newSpecifier = makeMissingModule(resolution.specifier, state.resolver.filename, ensureOpts(state));\n break;\n default:\n throw assertNever(resolution);\n }\n if (newSpecifier) {\n setter(newSpecifier);\n }\n}\n"]}
@@ -1,14 +0,0 @@
1
- import { NodeTemplateCompilerParams } from './template-compiler-node';
2
- import { precompile } from './babel-plugin-inline-hbs-deps';
3
- export interface Params {
4
- templateCompiler: NodeTemplateCompilerParams;
5
- }
6
- declare const _default: {
7
- (babel: typeof import("@babel/core")): unknown;
8
- _parallelBabel: {
9
- requireFile: string;
10
- };
11
- baseDir(): string;
12
- };
13
- export default _default;
14
- export { precompile };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.precompile = void 0;
23
- const template_compiler_node_1 = require("./template-compiler-node");
24
- const babel_plugin_inline_hbs_deps_1 = __importStar(require("./babel-plugin-inline-hbs-deps"));
25
- Object.defineProperty(exports, "precompile", { enumerable: true, get: function () { return babel_plugin_inline_hbs_deps_1.precompile; } });
26
- exports.default = (0, babel_plugin_inline_hbs_deps_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
27
- //# sourceMappingURL=babel-plugin-inline-hbs-deps-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-deps-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-deps-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qEAA4F;AAC5F,+FAAkE;AAOzD,2FAPM,yCAAU,OAON;AADnB,kBAAe,IAAA,sCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC","sourcesContent":["import { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make, { precompile } from './babel-plugin-inline-hbs-deps';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler));\nexport { precompile };\n"]}
@@ -1,10 +0,0 @@
1
- import type * as Babel from '@babel/core';
2
- import type { TemplateCompiler } from './template-compiler-common';
3
- export declare function precompile(templateSource: string, options: Record<string, unknown>): string;
4
- export default function make(getCompiler: (opts: any) => TemplateCompiler): {
5
- (babel: typeof Babel): unknown;
6
- _parallelBabel: {
7
- requireFile: string;
8
- };
9
- baseDir(): string;
10
- };
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.precompile = void 0;
4
- const path_1 = require("path");
5
- const shared_internals_1 = require("@embroider/shared-internals");
6
- const babel_import_util_1 = require("babel-import-util");
7
- /*
8
- In order to coordinate with babel-plugin-ember-template-compilation, we need
9
- to give it a `precompile` function that, as a side-effect, captures the
10
- dependencies needed within the current file. We do this coordination via this
11
- module-scoped variable, which is safe given Javascript's single-threaded
12
- nature and babel's synchronicity.
13
- */
14
- let currentState;
15
- /*
16
- This is the precompile function you should pass to
17
- babel-plugin-ember-template-compilation.
18
- */
19
- function precompile(templateSource, options) {
20
- if (!currentState) {
21
- throw new Error(`bug: babel-plugin-ember-template-compilation and babel-plugin-inline-hbs-deps aren't coordinating correctly`);
22
- }
23
- let { compiled, dependencies } = compiler(currentState).precompile(templateSource, {
24
- filename: currentState.file.opts.filename,
25
- ...options,
26
- });
27
- for (let dep of dependencies) {
28
- currentState.dependencies.set(dep.runtimeName, dep);
29
- }
30
- return compiled;
31
- }
32
- exports.precompile = precompile;
33
- function make(getCompiler) {
34
- function inlineHBSTransform(babel) {
35
- let t = babel.types;
36
- return {
37
- visitor: {
38
- Program: {
39
- enter(path, state) {
40
- state.dependencies = new Map();
41
- state.adder = new babel_import_util_1.ImportUtil(t, path);
42
- state.emittedCallExpressions = new Set();
43
- state.getCompiler = getCompiler;
44
- currentState = state;
45
- },
46
- exit(path, state) {
47
- // we are responsible for rewriting all usages of all the
48
- // templateCompilationModules to standardize on
49
- // @ember/template-compilation, so all imports other than that one
50
- // need to be cleaned up here.
51
- for (let moduleConfig of shared_internals_1.templateCompilationModules) {
52
- if (moduleConfig.module !== '@ember/template-compilation') {
53
- state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);
54
- }
55
- }
56
- let counter = 0;
57
- for (let dep of state.dependencies.values()) {
58
- path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));
59
- path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(dep.path)));
60
- }
61
- currentState = undefined;
62
- },
63
- },
64
- TaggedTemplateExpression(path, state) {
65
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
66
- if (path.get('tag').referencesImport(module, exportedName)) {
67
- handleTagged(path, state, t);
68
- }
69
- }
70
- },
71
- CallExpression(path, state) {
72
- if (state.emittedCallExpressions.has(path.node)) {
73
- return;
74
- }
75
- for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
76
- if (path.get('callee').referencesImport(module, exportedName)) {
77
- handleCalled(path, state, t);
78
- }
79
- }
80
- },
81
- },
82
- };
83
- }
84
- inlineHBSTransform._parallelBabel = {
85
- requireFile: __filename,
86
- };
87
- inlineHBSTransform.baseDir = function () {
88
- return (0, path_1.join)(__dirname, '..');
89
- };
90
- function handleTagged(path, state, t) {
91
- if (path.node.quasi.expressions.length) {
92
- throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
93
- }
94
- let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
95
- let args = [t.stringLiteral(template)];
96
- let locals = [
97
- // TODO: this is where lexically scoped dependencies go
98
- ];
99
- let opts = precompileOpts(locals, t);
100
- if (opts) {
101
- args.push(opts);
102
- }
103
- let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), args);
104
- state.emittedCallExpressions.add(newCallExpression);
105
- path.replaceWith(newCallExpression);
106
- }
107
- function handleCalled(path, state, t) {
108
- let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), path.node.arguments);
109
- state.emittedCallExpressions.add(newCallExpression);
110
- path.replaceWith(newCallExpression);
111
- }
112
- function precompileOpts(locals, t) {
113
- if (locals.length > 0) {
114
- return t.objectExpression([
115
- t.objectProperty(t.identifier('scope'), t.arrowFunctionExpression([], t.objectExpression(locals.map(name => t.objectProperty(name, name, false, true))))),
116
- ]);
117
- }
118
- }
119
- function amdDefine(runtimeName, importCounter, t) {
120
- return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
121
- t.stringLiteral(runtimeName),
122
- t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),
123
- ]));
124
- }
125
- return inlineHBSTransform;
126
- }
127
- exports.default = make;
128
- function compiler(state) {
129
- if (!state.templateCompiler) {
130
- state.templateCompiler = state.getCompiler(state.opts);
131
- }
132
- return state.templateCompiler;
133
- }
134
- //# sourceMappingURL=babel-plugin-inline-hbs-deps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-deps.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-deps.ts"],"names":[],"mappings":";;;AAGA,+BAA4B;AAG5B,kEAAyE;AACzE,yDAA+C;AAE/C;;;;;;EAME;AACF,IAAI,YAA+B,CAAC;AAEpC;;;EAGE;AACF,SAAgB,UAAU,CAAC,cAAsB,EAAE,OAAgC;IACjF,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,6GAA6G,CAC9G,CAAC;KACH;IACD,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE;QACjF,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ;QACzC,GAAG,OAAO;KACX,CAAC,CAAC;IACH,KAAK,IAAI,GAAG,IAAI,YAAY,EAAE;QAC5B,YAAY,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;KACrD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAdD,gCAcC;AAiBD,SAAwB,IAAI,CAAC,WAA4C;IACvE,SAAS,kBAAkB,CAAC,KAAmB;QAC7C,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,KAAK,CAAC,IAAyB,EAAE,KAAY;wBAC3C,KAAK,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;wBAC/B,KAAK,CAAC,KAAK,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;wBACtC,KAAK,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;wBACzC,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;wBAChC,YAAY,GAAG,K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QAAQ,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE;YACnF,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC;YAC5B,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACzG,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAzHD,uBAyHC;AAED,SAAS,QAAQ,CAAC,KAAY;IAC5B,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;QAC3B,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACxD;IACD,OAAO,KAAK,CAAC,gBAAgB,CAAC;AAChC,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport { ResolvedDep } from './resolver';\nimport { templateCompilationModules } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\n\n/*\n In order to coordinate with babel-plugin-ember-template-compilation, we need\n to give it a `precompile` function that, as a side-effect, captures the\n dependencies needed within the current file. We do this coordination via this\n module-scoped variable, which is safe given Javascript's single-threaded\n nature and babel's synchronicity.\n*/\nlet currentState: State | undefined;\n\n/*\n This is the precompile function you should pass to\n babel-plugin-ember-template-compilation.\n*/\nexport function precompile(templateSource: string, options: Record<string, unknown>) {\n if (!currentState) {\n throw new Error(\n `bug: babel-plugin-ember-template-compilation and babel-plugin-inline-hbs-deps aren't coordinating correctly`\n );\n }\n let { compiled, dependencies } = compiler(currentState).precompile(templateSource, {\n filename: currentState.file.opts.filename,\n ...options,\n });\n for (let dep of dependencies) {\n currentState.dependencies.set(dep.runtimeName, dep);\n }\n return compiled;\n}\n\ninterface State {\n opts: {};\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n dependencies: Map<string, ResolvedDep>;\n getCompiler: (opts: any) => TemplateCompiler;\n templateCompiler: TemplateCompiler | undefined;\n adder: ImportUtil;\n emittedCallExpressions: Set<t.Node>;\n}\n\nexport default function make(getCompiler: (opts: any) => TemplateCompiler) {\n function inlineHBSTransform(babel: typeof Babel): unknown {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n state.dependencies = new Map();\n state.adder = new ImportUtil(t, path);\n state.emittedCallExpressions = new Set();\n state.getCompiler = getCompiler;\n currentState = state;\n },\n exit(path: NodePath<t.Program>, state: State) {\n // we are responsible for rewriting all usages of all the\n // templateCompilationModules to standardize on\n // @ember/template-compilation, so all imports other than that one\n // need to be cleaned up here.\n for (let moduleConfig of templateCompilationModules) {\n if (moduleConfig.module !== '@ember/template-compilation') {\n state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);\n }\n }\n let counter = 0;\n for (let dep of state.dependencies.values()) {\n path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));\n path.node.body.unshift(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(`a${counter++}`))],\n t.stringLiteral(dep.path)\n )\n );\n }\n currentState = undefined;\n },\n },\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 if (state.emittedCallExpressions.has(path.node)) {\n return;\n }\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 inlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n inlineHBSTransform.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 args: t.Expression[] = [t.stringLiteral(template)];\n\n let locals: t.Identifier[] = [\n // TODO: this is where lexically scoped dependencies go\n ];\n let opts = precompileOpts(locals, t);\n if (opts) {\n args.push(opts);\n }\n\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n args\n );\n\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: typeof Babel.types) {\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n path.node.arguments\n );\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function precompileOpts(locals: t.Identifier[], t: typeof Babel.types) {\n if (locals.length > 0) {\n return t.objectExpression([\n t.objectProperty(\n t.identifier('scope'),\n t.arrowFunctionExpression(\n [],\n t.objectExpression(locals.map(name => t.objectProperty(name, name, false, true)))\n )\n ),\n ]);\n }\n }\n\n function amdDefine(runtimeName: string, importCounter: number, t: typeof Babel.types) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n }\n return inlineHBSTransform;\n}\n\nfunction compiler(state: State) {\n if (!state.templateCompiler) {\n state.templateCompiler = state.getCompiler(state.opts);\n }\n return state.templateCompiler;\n}\n"]}
@@ -1,7 +0,0 @@
1
- import { NodeTemplateCompilerParams } from './template-compiler-node';
2
- import type * as Babel from '@babel/core';
3
- export interface Params {
4
- templateCompiler: NodeTemplateCompilerParams;
5
- }
6
- declare const _default: (babel: typeof Babel) => Babel.PluginObj<unknown>;
7
- export default _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- /*
3
- This plugin is used only for Ember < 3.27. For newer Ember's we have a
4
- different implementation that shares the standard
5
- babel-plugin-ember-template-compilation and supports passing Javascript
6
- lexically scoped names into templates.
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const template_compiler_node_1 = require("./template-compiler-node");
13
- const babel_plugin_inline_hbs_1 = __importDefault(require("./babel-plugin-inline-hbs"));
14
- exports.default = (0, babel_plugin_inline_hbs_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
15
- //# sourceMappingURL=babel-plugin-inline-hbs-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-node.ts"],"names":[],"mappings":";AAAA;;;;;EAKE;;;;;AAEF,qEAA4F;AAC5F,wFAA6C;AAO7C,kBAAe,IAAA,iCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAExD,CAAC","sourcesContent":["/*\n This plugin is used only for Ember < 3.27. For newer Ember's we have a\n different implementation that shares the standard\n babel-plugin-ember-template-compilation and supports passing Javascript\n lexically scoped names into templates.\n*/\n\nimport { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make from './babel-plugin-inline-hbs';\nimport type * as Babel from '@babel/core';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler)) as (\n babel: typeof Babel\n) => babel.PluginObj<unknown>;\n"]}
@@ -1,24 +0,0 @@
1
- import type * as Babel from '@babel/core';
2
- import type { TemplateCompiler } from './template-compiler-common';
3
- import { ResolvedDep } from './resolver';
4
- import { ImportUtil } from 'babel-import-util';
5
- interface State<O> {
6
- opts: O;
7
- file: {
8
- code: string;
9
- opts: {
10
- filename: string;
11
- };
12
- };
13
- dependencies: Map<string, ResolvedDep>;
14
- templateCompiler: TemplateCompiler | undefined;
15
- adder: ImportUtil;
16
- }
17
- export default function make<O>(getCompiler: (opts: O) => TemplateCompiler): {
18
- (babel: typeof Babel): Babel.PluginObj<State<O>>;
19
- _parallelBabel: {
20
- requireFile: string;
21
- };
22
- baseDir(): string;
23
- };
24
- export {};