@embroider/macros 0.50.1 → 1.2.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.
- package/README.md +4 -0
- package/package.json +4 -3
- package/src/addon/es-compat.js +3 -0
- package/src/babel/dependency-satisfies.js +2 -4
- package/src/babel/dependency-satisfies.js.map +1 -1
- package/src/babel/each.js +2 -3
- package/src/babel/each.js.map +1 -1
- package/src/babel/evaluate-json.js +5 -5
- package/src/babel/evaluate-json.js.map +1 -1
- package/src/babel/get-config.js +6 -13
- package/src/babel/get-config.js.map +1 -1
- package/src/babel/macro-condition.js +1 -1
- package/src/babel/macro-condition.js.map +1 -1
- package/src/babel/macros-babel-plugin.js +15 -63
- package/src/babel/macros-babel-plugin.js.map +1 -1
- package/src/babel/module-exists.js +1 -3
- package/src/babel/module-exists.js.map +1 -1
- package/src/babel/state.d.ts +8 -7
- package/src/babel/state.js +25 -28
- package/src/babel/state.js.map +1 -1
- package/src/glimmer/dependency-satisfies.js +1 -1
- package/src/glimmer/dependency-satisfies.js.map +1 -1
- package/src/glimmer/macro-maybe-attrs.js +2 -2
- package/src/glimmer/macro-maybe-attrs.js.map +1 -1
- package/src/macros-config.js +50 -4
- package/src/macros-config.js.map +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,10 @@ let foo = importSync('foo');
|
|
|
121
121
|
let foo = require('foo');
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
#### hint
|
|
125
|
+
|
|
126
|
+
When using `importSync` on non ember-addon packages both the package being imported from *and* `ember-auto-import` *must* be in the `dependencies` of your addons `package.json`.
|
|
127
|
+
|
|
124
128
|
### dependencySatisfies
|
|
125
129
|
|
|
126
130
|
Tests whether a given dependency is present and satisfies the given semver range. Both arguments must be strings and the second argument will be passed into [semver's satisfies](https://github.com/npm/node-semver#usage) method.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"test": "jest"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@embroider/shared-internals": "
|
|
27
|
+
"@embroider/shared-internals": "1.2.0",
|
|
28
28
|
"assert-never": "^1.2.1",
|
|
29
|
+
"babel-import-util": "^1.1.0",
|
|
29
30
|
"ember-cli-babel": "^7.26.6",
|
|
30
31
|
"find-up": "^5.0.0",
|
|
31
32
|
"lodash": "^4.17.21",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@babel/core": "^7.14.5",
|
|
37
38
|
"@babel/traverse": "^7.14.5",
|
|
38
|
-
"@embroider/core": "
|
|
39
|
+
"@embroider/core": "1.2.0",
|
|
39
40
|
"@embroider/test-support": "0.36.0",
|
|
40
41
|
"@types/babel__core": "^7.1.14",
|
|
41
42
|
"@types/babel__generator": "^7.6.2",
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const state_1 = require("./state");
|
|
7
6
|
const semver_1 = require("semver");
|
|
8
7
|
const error_1 = __importDefault(require("./error"));
|
|
9
8
|
const evaluate_json_1 = require("./evaluate-json");
|
|
@@ -18,10 +17,9 @@ function dependencySatisfies(path, state) {
|
|
|
18
17
|
if (range.type !== 'StringLiteral') {
|
|
19
18
|
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[1], `the second argument to dependencySatisfies must be a string literal`);
|
|
20
19
|
}
|
|
21
|
-
let sourceFileName = (0, state_1.sourceFile)(path, state);
|
|
22
20
|
try {
|
|
23
|
-
let us = state.packageCache.ownerOfFile(
|
|
24
|
-
if (!us || us
|
|
21
|
+
let us = state.packageCache.ownerOfFile(state.sourceFile);
|
|
22
|
+
if (!(us === null || us === void 0 ? void 0 : us.hasDependency(packageName.value))) {
|
|
25
23
|
return false;
|
|
26
24
|
}
|
|
27
25
|
let version = state.packageCache.resolve(packageName.value, us).version;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAGA,mCAAmC;AACnC,oDAA4B;AAC5B,mDAA8C;AAE9C,SAAwB,mBAAmB,CAAC,IAAgC,EAAE,KAAY;IACxF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,+DAA+D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KAChH;IACD,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACjD,IAAI,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE;QACxC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,oEAAoE,CACrE,CAAC;KACH;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE;QAClC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,qEAAqE,CACtE,CAAC;KACH;IACD,IAAI;QACF,IAAI,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA,EAAE;YACzC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;QACxE,OAAO,IAAA,kBAAS,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE;YACrC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnC,MAAM,GAAG,CAAC;SACX;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAjCD,sCAiCC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nexport default function dependencySatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 2) {\n throw error(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);\n }\n const [packageName, range] = path.node.arguments;\n if (packageName.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the first argument to dependencySatisfies must be a string literal`\n );\n }\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[1],\n `the second argument to dependencySatisfies must be a string literal`\n );\n }\n try {\n let us = state.packageCache.ownerOfFile(state.sourceFile);\n if (!us?.hasDependency(packageName.value)) {\n return false;\n }\n\n let version = state.packageCache.resolve(packageName.value, us).version;\n return satisfies(version, range.value, {\n includePrerelease: true,\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
|
package/src/babel/each.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.insertEach = exports.isEachPath = void 0;
|
|
7
7
|
const evaluate_json_1 = require("./evaluate-json");
|
|
8
8
|
const error_1 = __importDefault(require("./error"));
|
|
9
|
-
const state_1 = require("./state");
|
|
10
9
|
function isEachPath(path) {
|
|
11
10
|
let right = path.get('right');
|
|
12
11
|
if (right.isCallExpression()) {
|
|
@@ -40,7 +39,7 @@ function insertEach(path, state, context) {
|
|
|
40
39
|
}
|
|
41
40
|
if (state.opts.mode === 'run-time') {
|
|
42
41
|
let callee = path.get('right').get('callee');
|
|
43
|
-
state.
|
|
42
|
+
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'each'));
|
|
44
43
|
}
|
|
45
44
|
else {
|
|
46
45
|
for (let element of array.value) {
|
|
@@ -48,7 +47,7 @@ function insertEach(path, state, context) {
|
|
|
48
47
|
for (let target of nameRefs) {
|
|
49
48
|
target.replaceWith(literalElement);
|
|
50
49
|
}
|
|
51
|
-
path.insertBefore(
|
|
50
|
+
path.insertBefore(state.cloneDeep(path.get('body').node));
|
|
52
51
|
}
|
|
53
52
|
path.remove();
|
|
54
53
|
}
|
package/src/babel/each.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"each.js","sourceRoot":"","sources":["each.ts"],"names":[],"mappings":";;;;;;AACA,mDAA2D;AAE3D,oDAA4B;
|
|
1
|
+
{"version":3,"file":"each.js","sourceRoot":"","sources":["each.ts"],"names":[],"mappings":";;;;;;AACA,mDAA2D;AAE3D,oDAA4B;AAY5B,SAAgB,UAAU,CAAC,IAAgC;IACzD,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,gBAAgB,EAAE,EAAE;QAC5B,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,MAAM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AE,2DAA2D,CAAC,CAAC;KACnF;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACrE,MAAM,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,mDAAmD,CAAC,CAAC;KAC3E;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;QAClC,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;KAC9F;SAAM;QACL,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;YAC/B,IAAI,cAAc,GAAG,IAAA,6BAAa,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACrD,KAAK,IAAI,MAAM,IAAI,QAAQ,EAAE;gBAC3B,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;aACpC;YACD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3D;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;KACf;AACH,CAAC;AAtCD,gCAsCC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { buildLiterals, Evaluator } from './evaluate-json';\nimport type { types as t } from '@babel/core';\nimport error from './error';\nimport State from './state';\nimport type * as Babel from '@babel/core';\n\ntype CallEachExpression = NodePath<t.CallExpression> & {\n get(callee: 'callee'): NodePath<t.Identifier>;\n};\n\nexport type EachPath = NodePath<t.ForOfStatement> & {\n get(right: 'right'): CallEachExpression;\n};\n\nexport function isEachPath(path: NodePath<t.ForOfStatement>): path is EachPath {\n let right = path.get('right');\n if (right.isCallExpression()) {\n let callee = right.get('callee');\n if (callee.referencesImport('@embroider/macros', 'each')) {\n return true;\n }\n }\n return false;\n}\n\nexport function insertEach(path: EachPath, state: State, context: typeof Babel) {\n let args = path.get('right').get('arguments');\n if (args.length !== 1) {\n throw error(path, `the each() macro accepts exactly one argument, you passed ${args.length}`);\n }\n\n let left = path.get('left');\n if (!left.isVariableDeclaration() || left.get('declarations').length !== 1) {\n throw error(left, `the each() macro doesn't support this syntax`);\n }\n\n let body = path.get('body');\n let varName = (left.get('declarations')[0].get('id') as NodePath<t.Identifier>).node.name;\n let nameRefs = body.scope.getBinding(varName)!.referencePaths;\n\n let [arrayPath] = args;\n let array = new Evaluator({ state }).evaluate(arrayPath);\n if (!array.confident) {\n throw error(args[0], `the argument to the each() macro must be statically known`);\n }\n\n if (state.opts.mode === 'compile-time' && !Array.isArray(array.value)) {\n throw error(args[0], `the argument to the each() macro must be an array`);\n }\n\n if (state.opts.mode === 'run-time') {\n let callee = path.get('right').get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'each'));\n } else {\n for (let element of array.value) {\n let literalElement = buildLiterals(element, context);\n for (let target of nameRefs) {\n target.replaceWith(literalElement);\n }\n path.insertBefore(state.cloneDeep(path.get('body').node));\n }\n path.remove();\n }\n}\n"]}
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.buildLiterals = exports.assertArray = exports.assertNotArray = exports.Evaluator = void 0;
|
|
7
|
-
const state_1 = require("./state");
|
|
8
7
|
const dependency_satisfies_1 = __importDefault(require("./dependency-satisfies"));
|
|
9
8
|
const module_exists_1 = __importDefault(require("./module-exists"));
|
|
10
9
|
const get_config_1 = __importDefault(require("./get-config"));
|
|
@@ -294,12 +293,13 @@ class Evaluator {
|
|
|
294
293
|
// to runtime. That's why we've made `value` lazy. It lets us check the
|
|
295
294
|
// confidence without actually forcing the value.
|
|
296
295
|
maybeEvaluateRuntimeConfig(path) {
|
|
297
|
-
|
|
296
|
+
if (!this.state) {
|
|
297
|
+
return { confident: false };
|
|
298
|
+
}
|
|
298
299
|
let callee = path.get('callee');
|
|
299
300
|
if (callee.isIdentifier()) {
|
|
300
|
-
let { name } = callee.node;
|
|
301
301
|
// Does the identifier refer to our runtime config?
|
|
302
|
-
if ((
|
|
302
|
+
if (callee.referencesImport(this.state.pathToOurAddon('runtime'), 'config')) {
|
|
303
303
|
return {
|
|
304
304
|
confident: true,
|
|
305
305
|
get value() {
|
|
@@ -340,7 +340,7 @@ class Evaluator {
|
|
|
340
340
|
if (callee.referencesImport('@embroider/macros', 'isDevelopingThisPackage')) {
|
|
341
341
|
return {
|
|
342
342
|
confident: true,
|
|
343
|
-
value: this.state.opts.isDevelopingPackageRoots.includes(
|
|
343
|
+
value: this.state.opts.isDevelopingPackageRoots.includes(this.state.owningPackage().root),
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
if (callee.referencesImport('@embroider/macros', 'isTesting')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate-json.js","sourceRoot":"","sources":["evaluate-json.ts"],"names":[],"mappings":";;;;;;AAGA,mCAA+C;AAC/C,kFAAyD;AACzD,oEAA2C;AAC3C,8DAAqC;AAIrC,MAAM,MAAM,GAAgC;IAC1C,IAAI,EAAE,UAAU,CAAU,EAAE,CAAU;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,IAAI,EAAE,UAAU,CAAU,EAAE,CAAU;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,GAAG,EAAE,UAAU,CAAM,EAAE,CAAM;QAC3B,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,GAAG,EAAE,UAAU,CAAM,EAA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,CAAC,IAAI,CAAC,CAAC,mBAAmB,CAAC,CAAC;YACpC,IAAI,KAAK,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;YACtC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;SACnC;QACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AAnRD,8BAmRC;AAED,6EAA6E;AAC7E,4EAA4E;AAC5E,UAAU;AACV,SAAgB,cAAc,CAAI,KAAc;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,wCAKC;AACD,SAAgB,WAAW,CAAI,KAAc;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,kCAKC;AAED,SAAgB,aAAa,CAC3B,KAA0B,EAC1B,YAA0B;IAE1B,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAChC,OAAO,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;KACnD;IACD,IAAI,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAW,CAAC;IAC5E,IAAI,UAAU,GAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAA2B,CAAC,UAA8B,CAAC;IACrG,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,CAAuB,CAAC;AACvD,CAAC;AAVD,sCAUC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport State, { owningPackage } from './state';\nimport dependencySatisfies from './dependency-satisfies';\nimport moduleExists from './module-exists';\nimport getConfig from './get-config';\n\ntype OpValue = string | boolean | number;\n\nconst binops: { [operator: string]: any } = {\n '||': function (a: OpValue, b: OpValue) {\n return a || b;\n },\n '&&': function (a: OpValue, b: OpValue) {\n return a && b;\n },\n '|': function (a: any, b: any) {\n return a | b;\n },\n '^': function (a: any, b: any) {\n return a ^ b;\n },\n '&': function (a: any, b: any) {\n return a & b;\n },\n '==': function (a: OpValue, b: OpValue) {\n // eslint-disable-next-line eqeqeq\n return a == b;\n },\n '!=': function (a: OpValue, b: OpValue) {\n // eslint-disable-next-line eqeqeq\n return a != b;\n },\n '===': function (a: OpValue, b: OpValue) {\n return a === b;\n },\n '!==': function (a: OpValue, b: OpValue) {\n return a !== b;\n },\n '<': function (a: OpValue, b: OpValue) {\n return a < b;\n },\n '>': function (a: OpValue, b: OpValue) {\n return a > b;\n },\n '<=': function (a: OpValue, b: OpValue) {\n return a <= b;\n },\n '>=': function (a: OpValue, b: OpValue) {\n return a >= b;\n },\n '<<': function (a: any, b: any) {\n return a << b;\n },\n '>>': function (a: any, b: any) {\n return a >> b;\n },\n '>>>': function (a: any, b: any) {\n return a >>> b;\n },\n '+': function (a: any, b: any) {\n return a + b;\n },\n '-': function (a: any, b: any) {\n return a - b;\n },\n '*': function (a: any, b: any) {\n return a * b;\n },\n '/': function (a: any, b: any) {\n return a / b;\n },\n '%': function (a: any, b: any) {\n return a % b;\n },\n '??': function (a: any, b: any) {\n if (a === null || a === undefined) {\n return b;\n }\n return a;\n },\n};\n\nconst unops: { [operator: string]: any } = {\n '-': function (a: OpValue) {\n return -a;\n },\n '+': function (a: OpValue) {\n return +a;\n },\n '~': function (a: OpValue) {\n return ~a;\n },\n '!': function (a: OpValue) {\n return !a;\n },\n void: function () {\n return undefined;\n },\n};\n\nexport interface ConfidentResult {\n confident: true;\n value: any;\n}\n\nexport interface UnknownResult {\n confident: false;\n}\n\nexport type EvaluateResult = ConfidentResult | UnknownResult;\n\n// this is needed to make our strict types work when inter-operating with\n// babel's own built-in evaluator\nfunction isConfidentResult(result: { confident: boolean; value: any }): result is ConfidentResult {\n return result.confident;\n}\n\nexport interface EvaluationEnv {\n knownPaths?: Map<NodePath, EvaluateResult>;\n locals?: { [localVar: string]: any };\n state?: State;\n}\n\nexport class Evaluator {\n private knownPaths: Map<NodePath, EvaluateResult>;\n private locals: { [localVar: string]: any };\n private state: State | undefined;\n\n constructor(env: EvaluationEnv = {}) {\n this.knownPaths = env.knownPaths || new Map();\n this.locals = env.locals || {};\n this.state = env.state;\n }\n\n evaluateMember(\n path: NodePath<t.MemberExpression | t.OptionalMemberExpression>,\n optionalChain: boolean\n ): EvaluateResult {\n let propertyPath = assertNotArray(path.get('property'));\n let property: EvaluateResult;\n if (path.node.computed) {\n property = this.evaluate(propertyPath);\n } else {\n property = this.evaluateKey(propertyPath);\n }\n if (property.confident) {\n let objectPath = path.get('object');\n let object = this.evaluate(objectPath);\n if (object.confident) {\n let confidentObject = object;\n let confidentProperty = property;\n return {\n confident: true,\n get value() {\n if (optionalChain) {\n return confidentObject.value != null\n ? confidentObject.value[confidentProperty.value]\n : confidentObject.value;\n } else {\n return confidentObject.value[confidentProperty.value];\n }\n },\n };\n }\n }\n return { confident: false };\n }\n\n evaluateKey(path: NodePath): EvaluateResult {\n let first = this.evaluate(path);\n if (first.confident) {\n return first;\n }\n if (path.isIdentifier()) {\n return { confident: true, value: path.node.name };\n }\n return { confident: false };\n }\n\n evaluate(path: NodePath): EvaluateResult {\n let known = this.knownPaths.get(path);\n if (known) {\n return known;\n }\n let result = this.realEvaluate(path);\n return result;\n }\n\n private realEvaluate(path: NodePath): EvaluateResult {\n let builtIn = path.evaluate();\n if (isConfidentResult(builtIn)) {\n return builtIn;\n }\n\n if (path.isMemberExpression()) {\n return this.evaluateMember(path, false);\n }\n\n // Here we are glossing over the lack of a real OptionalMemberExpression type\n // in our @babel/traverse typings.\n if (path.node.type === 'OptionalMemberExpression') {\n return this.evaluateMember(path as NodePath<t.OptionalMemberExpression>, true);\n }\n\n if (path.isStringLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isNumericLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isBooleanLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isNullLiteral()) {\n return { confident: true, value: null };\n }\n\n if (path.isObjectExpression()) {\n let props = assertArray(path.get('properties')).map(p => {\n let key = assertNotArray(p.get('key'));\n let keyEvalValue = this.evaluateKey(key);\n let value = assertNotArray(p.get('value'));\n let valueEvalValue = this.evaluate(value);\n return [keyEvalValue, valueEvalValue];\n });\n for (let [k, v] of props) {\n if (!k.confident || !v.confident) {\n return { confident: false };\n }\n }\n let confidentProps = props as ConfidentResult[][];\n return {\n confident: true,\n get value() {\n let result: any = {};\n for (let [k, v] of confidentProps) {\n result[k.value] = v.value;\n }\n return result;\n },\n };\n }\n\n if (path.isArrayExpression()) {\n let elements = path.get('elements').map(element => {\n return this.evaluate(element as NodePath);\n });\n if (elements.every(element => element.confident)) {\n let confidentElements = elements as ConfidentResult[];\n return {\n confident: true,\n get value() {\n return confidentElements.map(element => element.value);\n },\n };\n }\n }\n\n if (path.isAssignmentExpression()) {\n let leftPath = path.get('left');\n if (leftPath.isIdentifier()) {\n let rightPath = path.get('right');\n let right = this.evaluate(rightPath);\n if (right.confident) {\n this.locals[leftPath.node.name] = right.value;\n return right;\n }\n }\n }\n\n if (path.isCallExpression()) {\n let result = this.maybeEvaluateRuntimeConfig(path);\n if (result.confident) {\n return result;\n }\n result = this.evaluateMacroCall(path);\n if (result.confident) {\n return result;\n }\n }\n\n if (path.isLogicalExpression() || path.isBinaryExpression()) {\n let operator = path.node.operator as string;\n if (binops[operator]) {\n let leftOperand = this.evaluate(path.get('left') as NodePath<t.Expression>);\n if (leftOperand.confident) {\n let rightOperand = this.evaluate(path.get('right') as NodePath<t.Expression>);\n if (leftOperand.confident && rightOperand.confident) {\n let value = binops[operator](leftOperand.value, rightOperand.value);\n return { confident: true, value };\n }\n }\n }\n return { confident: false };\n }\n\n if (path.isConditionalExpression()) {\n let test = this.evaluate(path.get('test'));\n if (test.confident) {\n let result = test.value ? this.evaluate(path.get('consequent')) : this.evaluate(path.get('alternate'));\n if (result.confident) {\n return result;\n }\n }\n }\n\n if (path.isUnaryExpression()) {\n let operator = path.node.operator as string;\n if (unops[operator]) {\n let operand = this.evaluate(path.get('argument') as NodePath<t.Expression>);\n if (operand.confident) {\n let value = unops[operator](operand.value);\n return { confident: true, value };\n }\n }\n return { confident: false };\n }\n\n if (path.isIdentifier()) {\n if (!this.locals.hasOwnProperty(path.node.name)) {\n return { confident: false };\n }\n return { confident: true, value: this.locals[path.node.name] };\n }\n\n return { confident: false };\n }\n\n // This handles the presence of our runtime-mode getConfig functions. We want\n // to designate them as { confident: true }, because it's important that we\n // give feedback even in runtime-mode if the developer is trying to pass\n // non-static arguments somewhere they're not supposed to. But we don't\n // actually want to calculate their value here because that has been deferred\n // to runtime. That's why we've made `value` lazy. It lets us check the\n // confidence without actually forcing the value.\n private maybeEvaluateRuntimeConfig(path: NodePath<t.CallExpression>): EvaluateResult {\n let callee = path.get('callee');\n if (callee.isIdentifier()) {\n let { name } = callee.node;\n // Does the identifier refer to our runtime config?\n if (this.state?.neededRuntimeImports.get(name) === 'config') {\n return {\n confident: true,\n get value() {\n throw new Error(`bug in @embroider/macros: didn't expect to need to evaluate this value`);\n },\n };\n }\n }\n return { confident: false };\n }\n\n evaluateMacroCall(path: NodePath<t.CallExpression>): EvaluateResult {\n if (!this.state) {\n return { confident: false };\n }\n let callee = path.get('callee');\n if (callee.referencesImport('@embroider/macros', 'dependencySatisfies')) {\n return { confident: true, value: dependencySatisfies(path, this.state) };\n }\n if (callee.referencesImport('@embroider/macros', 'moduleExists')) {\n return { confident: true, value: moduleExists(path, this.state) };\n }\n if (callee.referencesImport('@embroider/macros', 'getConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'package') };\n }\n if (callee.referencesImport('@embroider/macros', 'getOwnConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'own') };\n }\n if (callee.referencesImport('@embroider/macros', 'getGlobalConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'getGlobalConfig') };\n }\n if (callee.referencesImport('@embroider/macros', 'isDevelopingApp')) {\n return {\n confident: true,\n value: Boolean(\n this.state.opts.appPackageRoot &&\n this.state.opts.isDevelopingPackageRoots.includes(this.state.opts.appPackageRoot)\n ),\n };\n }\n if (callee.referencesImport('@embroider/macros', 'isDevelopingThisPackage')) {\n return {\n confident: true,\n value: this.state.opts.isDevelopingPackageRoots.includes(owningPackage(path, this.state).root),\n };\n }\n if (callee.referencesImport('@embroider/macros', 'isTesting')) {\n let g = getConfig(path, this.state, 'getGlobalConfig') as any;\n let e = g && g['@embroider/macros'];\n let value = Boolean(e && e.isTesting);\n return { confident: true, value };\n }\n return { confident: false };\n }\n}\n\n// these next two functions are here because the type definitions we're using\n// don't seem to know exactly which NodePath properties are arrays and which\n// aren't.\nexport function assertNotArray<T>(input: T | T[]): T {\n if (Array.isArray(input)) {\n throw new Error(`bug: not supposed to be an array`);\n }\n return input;\n}\nexport function assertArray<T>(input: T | T[]): T[] {\n if (!Array.isArray(input)) {\n throw new Error(`bug: supposed to be an array`);\n }\n return input;\n}\n\nexport function buildLiterals(\n value: unknown | undefined,\n babelContext: typeof Babel\n): t.Identifier | t.ObjectExpression {\n if (typeof value === 'undefined') {\n return babelContext.types.identifier('undefined');\n }\n let statement = babelContext.parse(`a(${JSON.stringify(value)})`) as t.File;\n let expression = (statement.program.body[0] as t.ExpressionStatement).expression as t.CallExpression;\n return expression.arguments[0] as t.ObjectExpression;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluate-json.js","sourceRoot":"","sources":["evaluate-json.ts"],"names":[],"mappings":";;;;;;AAIA,kFAAyD;AACzD,oEAA2C;AAC3C,8DAAqC;AAIrC,MAAM,MAAM,GAAgC;IAC1C,IAAI,EAAE,UAAU,CAAU,EAAE,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,CAAW,CAAC;IAC5E,IAAI,UAAU,GAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAA2B,CAAC,UAA8B,CAAC;IACrG,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,CAAuB,CAAC;AACvD,CAAC;AAVD,sCAUC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport State from './state';\nimport dependencySatisfies from './dependency-satisfies';\nimport moduleExists from './module-exists';\nimport getConfig from './get-config';\n\ntype OpValue = string | boolean | number;\n\nconst binops: { [operator: string]: any } = {\n '||': function (a: OpValue, b: OpValue) {\n return a || b;\n },\n '&&': function (a: OpValue, b: OpValue) {\n return a && b;\n },\n '|': function (a: any, b: any) {\n return a | b;\n },\n '^': function (a: any, b: any) {\n return a ^ b;\n },\n '&': function (a: any, b: any) {\n return a & b;\n },\n '==': function (a: OpValue, b: OpValue) {\n // eslint-disable-next-line eqeqeq\n return a == b;\n },\n '!=': function (a: OpValue, b: OpValue) {\n // eslint-disable-next-line eqeqeq\n return a != b;\n },\n '===': function (a: OpValue, b: OpValue) {\n return a === b;\n },\n '!==': function (a: OpValue, b: OpValue) {\n return a !== b;\n },\n '<': function (a: OpValue, b: OpValue) {\n return a < b;\n },\n '>': function (a: OpValue, b: OpValue) {\n return a > b;\n },\n '<=': function (a: OpValue, b: OpValue) {\n return a <= b;\n },\n '>=': function (a: OpValue, b: OpValue) {\n return a >= b;\n },\n '<<': function (a: any, b: any) {\n return a << b;\n },\n '>>': function (a: any, b: any) {\n return a >> b;\n },\n '>>>': function (a: any, b: any) {\n return a >>> b;\n },\n '+': function (a: any, b: any) {\n return a + b;\n },\n '-': function (a: any, b: any) {\n return a - b;\n },\n '*': function (a: any, b: any) {\n return a * b;\n },\n '/': function (a: any, b: any) {\n return a / b;\n },\n '%': function (a: any, b: any) {\n return a % b;\n },\n '??': function (a: any, b: any) {\n if (a === null || a === undefined) {\n return b;\n }\n return a;\n },\n};\n\nconst unops: { [operator: string]: any } = {\n '-': function (a: OpValue) {\n return -a;\n },\n '+': function (a: OpValue) {\n return +a;\n },\n '~': function (a: OpValue) {\n return ~a;\n },\n '!': function (a: OpValue) {\n return !a;\n },\n void: function () {\n return undefined;\n },\n};\n\nexport interface ConfidentResult {\n confident: true;\n value: any;\n}\n\nexport interface UnknownResult {\n confident: false;\n}\n\nexport type EvaluateResult = ConfidentResult | UnknownResult;\n\n// this is needed to make our strict types work when inter-operating with\n// babel's own built-in evaluator\nfunction isConfidentResult(result: { confident: boolean; value: any }): result is ConfidentResult {\n return result.confident;\n}\n\nexport interface EvaluationEnv {\n knownPaths?: Map<NodePath, EvaluateResult>;\n locals?: { [localVar: string]: any };\n state?: State;\n}\n\nexport class Evaluator {\n private knownPaths: Map<NodePath, EvaluateResult>;\n private locals: { [localVar: string]: any };\n private state: State | undefined;\n\n constructor(env: EvaluationEnv = {}) {\n this.knownPaths = env.knownPaths || new Map();\n this.locals = env.locals || {};\n this.state = env.state;\n }\n\n evaluateMember(\n path: NodePath<t.MemberExpression | t.OptionalMemberExpression>,\n optionalChain: boolean\n ): EvaluateResult {\n let propertyPath = assertNotArray(path.get('property'));\n let property: EvaluateResult;\n if (path.node.computed) {\n property = this.evaluate(propertyPath);\n } else {\n property = this.evaluateKey(propertyPath);\n }\n if (property.confident) {\n let objectPath = path.get('object');\n let object = this.evaluate(objectPath);\n if (object.confident) {\n let confidentObject = object;\n let confidentProperty = property;\n return {\n confident: true,\n get value() {\n if (optionalChain) {\n return confidentObject.value != null\n ? confidentObject.value[confidentProperty.value]\n : confidentObject.value;\n } else {\n return confidentObject.value[confidentProperty.value];\n }\n },\n };\n }\n }\n return { confident: false };\n }\n\n evaluateKey(path: NodePath): EvaluateResult {\n let first = this.evaluate(path);\n if (first.confident) {\n return first;\n }\n if (path.isIdentifier()) {\n return { confident: true, value: path.node.name };\n }\n return { confident: false };\n }\n\n evaluate(path: NodePath): EvaluateResult {\n let known = this.knownPaths.get(path);\n if (known) {\n return known;\n }\n let result = this.realEvaluate(path);\n return result;\n }\n\n private realEvaluate(path: NodePath): EvaluateResult {\n let builtIn = path.evaluate();\n if (isConfidentResult(builtIn)) {\n return builtIn;\n }\n\n if (path.isMemberExpression()) {\n return this.evaluateMember(path, false);\n }\n\n // Here we are glossing over the lack of a real OptionalMemberExpression type\n // in our @babel/traverse typings.\n if (path.node.type === 'OptionalMemberExpression') {\n return this.evaluateMember(path as NodePath<t.OptionalMemberExpression>, true);\n }\n\n if (path.isStringLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isNumericLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isBooleanLiteral()) {\n return { confident: true, value: path.node.value };\n }\n\n if (path.isNullLiteral()) {\n return { confident: true, value: null };\n }\n\n if (path.isObjectExpression()) {\n let props = assertArray(path.get('properties')).map(p => {\n let key = assertNotArray(p.get('key'));\n let keyEvalValue = this.evaluateKey(key);\n let value = assertNotArray(p.get('value'));\n let valueEvalValue = this.evaluate(value);\n return [keyEvalValue, valueEvalValue];\n });\n for (let [k, v] of props) {\n if (!k.confident || !v.confident) {\n return { confident: false };\n }\n }\n let confidentProps = props as ConfidentResult[][];\n return {\n confident: true,\n get value() {\n let result: any = {};\n for (let [k, v] of confidentProps) {\n result[k.value] = v.value;\n }\n return result;\n },\n };\n }\n\n if (path.isArrayExpression()) {\n let elements = path.get('elements').map(element => {\n return this.evaluate(element as NodePath);\n });\n if (elements.every(element => element.confident)) {\n let confidentElements = elements as ConfidentResult[];\n return {\n confident: true,\n get value() {\n return confidentElements.map(element => element.value);\n },\n };\n }\n }\n\n if (path.isAssignmentExpression()) {\n let leftPath = path.get('left');\n if (leftPath.isIdentifier()) {\n let rightPath = path.get('right');\n let right = this.evaluate(rightPath);\n if (right.confident) {\n this.locals[leftPath.node.name] = right.value;\n return right;\n }\n }\n }\n\n if (path.isCallExpression()) {\n let result = this.maybeEvaluateRuntimeConfig(path);\n if (result.confident) {\n return result;\n }\n result = this.evaluateMacroCall(path);\n if (result.confident) {\n return result;\n }\n }\n\n if (path.isLogicalExpression() || path.isBinaryExpression()) {\n let operator = path.node.operator as string;\n if (binops[operator]) {\n let leftOperand = this.evaluate(path.get('left') as NodePath<t.Expression>);\n if (leftOperand.confident) {\n let rightOperand = this.evaluate(path.get('right') as NodePath<t.Expression>);\n if (leftOperand.confident && rightOperand.confident) {\n let value = binops[operator](leftOperand.value, rightOperand.value);\n return { confident: true, value };\n }\n }\n }\n return { confident: false };\n }\n\n if (path.isConditionalExpression()) {\n let test = this.evaluate(path.get('test'));\n if (test.confident) {\n let result = test.value ? this.evaluate(path.get('consequent')) : this.evaluate(path.get('alternate'));\n if (result.confident) {\n return result;\n }\n }\n }\n\n if (path.isUnaryExpression()) {\n let operator = path.node.operator as string;\n if (unops[operator]) {\n let operand = this.evaluate(path.get('argument') as NodePath<t.Expression>);\n if (operand.confident) {\n let value = unops[operator](operand.value);\n return { confident: true, value };\n }\n }\n return { confident: false };\n }\n\n if (path.isIdentifier()) {\n if (!this.locals.hasOwnProperty(path.node.name)) {\n return { confident: false };\n }\n return { confident: true, value: this.locals[path.node.name] };\n }\n\n return { confident: false };\n }\n\n // This handles the presence of our runtime-mode getConfig functions. We want\n // to designate them as { confident: true }, because it's important that we\n // give feedback even in runtime-mode if the developer is trying to pass\n // non-static arguments somewhere they're not supposed to. But we don't\n // actually want to calculate their value here because that has been deferred\n // to runtime. That's why we've made `value` lazy. It lets us check the\n // confidence without actually forcing the value.\n private maybeEvaluateRuntimeConfig(path: NodePath<t.CallExpression>): EvaluateResult {\n if (!this.state) {\n return { confident: false };\n }\n let callee = path.get('callee');\n if (callee.isIdentifier()) {\n // Does the identifier refer to our runtime config?\n if (callee.referencesImport(this.state.pathToOurAddon('runtime'), 'config')) {\n return {\n confident: true,\n get value() {\n throw new Error(`bug in @embroider/macros: didn't expect to need to evaluate this value`);\n },\n };\n }\n }\n return { confident: false };\n }\n\n evaluateMacroCall(path: NodePath<t.CallExpression>): EvaluateResult {\n if (!this.state) {\n return { confident: false };\n }\n let callee = path.get('callee');\n if (callee.referencesImport('@embroider/macros', 'dependencySatisfies')) {\n return { confident: true, value: dependencySatisfies(path, this.state) };\n }\n if (callee.referencesImport('@embroider/macros', 'moduleExists')) {\n return { confident: true, value: moduleExists(path, this.state) };\n }\n if (callee.referencesImport('@embroider/macros', 'getConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'package') };\n }\n if (callee.referencesImport('@embroider/macros', 'getOwnConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'own') };\n }\n if (callee.referencesImport('@embroider/macros', 'getGlobalConfig')) {\n return { confident: true, value: getConfig(path, this.state, 'getGlobalConfig') };\n }\n if (callee.referencesImport('@embroider/macros', 'isDevelopingApp')) {\n return {\n confident: true,\n value: Boolean(\n this.state.opts.appPackageRoot &&\n this.state.opts.isDevelopingPackageRoots.includes(this.state.opts.appPackageRoot)\n ),\n };\n }\n if (callee.referencesImport('@embroider/macros', 'isDevelopingThisPackage')) {\n return {\n confident: true,\n value: this.state.opts.isDevelopingPackageRoots.includes(this.state.owningPackage().root),\n };\n }\n if (callee.referencesImport('@embroider/macros', 'isTesting')) {\n let g = getConfig(path, this.state, 'getGlobalConfig') as any;\n let e = g && g['@embroider/macros'];\n let value = Boolean(e && e.isTesting);\n return { confident: true, value };\n }\n return { confident: false };\n }\n}\n\n// these next two functions are here because the type definitions we're using\n// don't seem to know exactly which NodePath properties are arrays and which\n// aren't.\nexport function assertNotArray<T>(input: T | T[]): T {\n if (Array.isArray(input)) {\n throw new Error(`bug: not supposed to be an array`);\n }\n return input;\n}\nexport function assertArray<T>(input: T | T[]): T[] {\n if (!Array.isArray(input)) {\n throw new Error(`bug: supposed to be an array`);\n }\n return input;\n}\n\nexport function buildLiterals(\n value: unknown | undefined,\n babelContext: typeof Babel\n): t.Identifier | t.ObjectExpression {\n if (typeof value === 'undefined') {\n return babelContext.types.identifier('undefined');\n }\n let statement = babelContext.parse(`a(${JSON.stringify(value)})`) as t.File;\n let expression = (statement.program.body[0] as t.ExpressionStatement).expression as t.CallExpression;\n return expression.arguments[0] as t.ObjectExpression;\n}\n"]}
|
package/src/babel/get-config.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.inlineRuntimeConfig = exports.insertConfig = void 0;
|
|
7
|
-
const state_1 = require("./state");
|
|
8
7
|
const error_1 = __importDefault(require("./error"));
|
|
9
8
|
const evaluate_json_1 = require("./evaluate-json");
|
|
10
9
|
const assert_never_1 = __importDefault(require("assert-never"));
|
|
@@ -29,7 +28,7 @@ function getPackage(path, state, mode) {
|
|
|
29
28
|
else {
|
|
30
29
|
(0, assert_never_1.default)(mode);
|
|
31
30
|
}
|
|
32
|
-
return targetPackage(
|
|
31
|
+
return targetPackage(state.sourceFile, packageName, state.packageCache);
|
|
33
32
|
}
|
|
34
33
|
// this evaluates to the actual value of the config. It can be used directly by the Evaluator.
|
|
35
34
|
function getConfig(path, state, mode) {
|
|
@@ -56,7 +55,8 @@ function insertConfig(path, state, mode, context) {
|
|
|
56
55
|
}
|
|
57
56
|
else {
|
|
58
57
|
if (mode === 'getGlobalConfig') {
|
|
59
|
-
|
|
58
|
+
let callee = path.get('callee');
|
|
59
|
+
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'getGlobalConfig'));
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
let pkg = getPackage(path, state, mode);
|
|
@@ -67,9 +67,9 @@ function insertConfig(path, state, mode, context) {
|
|
|
67
67
|
else {
|
|
68
68
|
pkgRoot = context.types.identifier('undefined');
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
path.replaceWith(context.types.callExpression(state.importUtil.import(path, state.pathToOurAddon('runtime'), 'config'), [
|
|
71
|
+
pkgRoot,
|
|
72
|
+
]));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -106,11 +106,4 @@ function inlineRuntimeConfig(path, state, context) {
|
|
|
106
106
|
];
|
|
107
107
|
}
|
|
108
108
|
exports.inlineRuntimeConfig = inlineRuntimeConfig;
|
|
109
|
-
function calleeName(path, context) {
|
|
110
|
-
let callee = path.node.callee;
|
|
111
|
-
if (context.types.isIdentifier(callee)) {
|
|
112
|
-
return callee.name;
|
|
113
|
-
}
|
|
114
|
-
throw new Error(`bug: our macros should only be invoked as identifiers`);
|
|
115
|
-
}
|
|
116
109
|
//# sourceMappingURL=get-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["get-config.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["get-config.ts"],"names":[],"mappings":";;;;;;AAGA,oDAA4B;AAC5B,mDAAyF;AACzF,gEAAuC;AAMvC,SAAS,UAAU,CAAC,IAAgC,EAAE,KAAY,EAAE,IAAuB;IACzF,IAAI,WAA+B,CAAC;IACpC,IAAI,IAAI,KAAK,KAAK,EAAE;QAClB,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,iDAAiD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SAClG;QACD,WAAW,GAAG,SAAS,CAAC;KACzB;SAAM,IAAI,IAAI,KAAK,SAAS,EAAE;QAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,oDAAoD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SACrG;QACD,IAAI,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,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AC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC9C;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,IAAc,EAAE,MAAW;IAC3C,IAAI,SAAS,GAAG,IAAI,yBAAS,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAErG,OAAO,IAAI,EAAE;QACX,IAAI,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACjC,IAAI,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,UAAU,CAAC,sBAAsB,EAAE,EAAE;YAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAqB,CAAC,KAAK,EAAE,CAAC;SAC9E;QACD,IAAI,GAAG,UAAU,CAAC;KACnB;AACH,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAqC,EAAE,KAAY,EAAE,OAAqB;IAC5G,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG;QAC3B,OAAO,CAAC,KAAK,CAAC,eAAe,CAC3B,IAAA,6BAAa,EAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,CAAC,CAC9F;KACF,CAAC;AACJ,CAAC;AAND,kDAMC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport State from './state';\nimport { PackageCache, Package } from '@embroider/shared-internals';\nimport error from './error';\nimport { Evaluator, assertArray, buildLiterals, ConfidentResult } from './evaluate-json';\nimport assertNever from 'assert-never';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\n\nexport type Mode = 'own' | 'getGlobalConfig' | 'package';\n\nfunction getPackage(path: NodePath<t.CallExpression>, state: State, mode: 'own' | 'package'): { root: string } | null {\n let packageName: string | undefined;\n if (mode === 'own') {\n if (path.node.arguments.length !== 0) {\n throw error(path, `getOwnConfig takes zero arguments, you passed ${path.node.arguments.length}`);\n }\n packageName = undefined;\n } else if (mode === 'package') {\n if (path.node.arguments.length !== 1) {\n throw error(path, `getConfig takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n let packageNode = path.node.arguments[0];\n if (packageNode.type !== 'StringLiteral') {\n throw error(assertArray(path.get('arguments'))[0], `the argument to getConfig must be a string literal`);\n }\n packageName = packageNode.value;\n } else {\n assertNever(mode);\n }\n return targetPackage(state.sourceFile, packageName, state.packageCache);\n}\n\n// this evaluates to the actual value of the config. It can be used directly by the Evaluator.\nexport default function getConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode) {\n let config: unknown | undefined;\n if (mode === 'getGlobalConfig') {\n return state.opts.globalConfig;\n }\n let pkg = getPackage(path, state, mode);\n if (pkg) {\n config = state.opts.userConfigs[pkg.root];\n }\n return config;\n}\n\n// this is the imperative version that's invoked directly by the babel visitor\n// when we encounter getConfig. It's implemented in terms of getConfig so we can\n// be sure we have the same semantics.\nexport function insertConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode, context: typeof Babel) {\n if (state.opts.mode === 'compile-time') {\n let config = getConfig(path, state, mode);\n let collapsed = collapse(path, config);\n let literalResult = buildLiterals(collapsed.config, context);\n collapsed.path.replaceWith(literalResult);\n } else {\n if (mode === 'getGlobalConfig') {\n let callee = path.get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'getGlobalConfig'));\n } else {\n let pkg = getPackage(path, state, mode);\n let pkgRoot;\n if (pkg) {\n pkgRoot = context.types.stringLiteral(pkg.root);\n } else {\n pkgRoot = context.types.identifier('undefined');\n }\n path.replaceWith(\n context.types.callExpression(state.importUtil.import(path, state.pathToOurAddon('runtime'), 'config'), [\n pkgRoot,\n ])\n );\n }\n }\n}\n\nfunction targetPackage(fromPath: string, packageName: string | undefined, packageCache: PackageCache): Package | null {\n let us = packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`unable to determine which npm package owns the file ${fromPath}`);\n }\n if (!packageName) {\n return us;\n }\n try {\n return packageCache.resolve(packageName, us);\n } catch (err) {\n return null;\n }\n}\n\nfunction collapse(path: NodePath, config: any) {\n let evaluator = new Evaluator({ knownPaths: new Map([[path, { confident: true, value: config }]]) });\n\n while (true) {\n let parentPath = path.parentPath;\n let result = evaluator.evaluate(parentPath);\n if (!result.confident || parentPath.isAssignmentExpression()) {\n return { path, config: (evaluator.evaluate(path) as ConfidentResult).value };\n }\n path = parentPath;\n }\n}\n\nexport function inlineRuntimeConfig(path: NodePath<t.FunctionDeclaration>, state: State, context: typeof Babel) {\n path.get('body').node.body = [\n context.types.returnStatement(\n buildLiterals({ packages: state.opts.userConfigs, global: state.opts.globalConfig }, context)\n ),\n ];\n}\n"]}
|
|
@@ -31,7 +31,7 @@ function macroCondition(conditionalPath, state) {
|
|
|
31
31
|
let alternate = conditionalPath.get('alternate');
|
|
32
32
|
if (state.opts.mode === 'run-time') {
|
|
33
33
|
let callee = conditionalPath.get('test').get('callee');
|
|
34
|
-
state.
|
|
34
|
+
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'macroCondition'));
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
let [kept, removed] = predicate.value ? [consequent.node, alternate.node] : [alternate.node, consequent.node];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-condition.js","sourceRoot":"","sources":["macro-condition.ts"],"names":[],"mappings":";;;;;;AACA,mDAA4C;AAE5C,oDAA4B;AAO5B,SAAgB,oBAAoB,CAClC,IAAuD;IAEvD,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAA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AC,QAAQ,CAAC,CAAC;QACvD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;KACxG;SAAM;QACL,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9G,IAAI,IAAI,EAAE;YACR,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SACnC;aAAM;YACL,eAAe,CAAC,MAAM,EAAE,CAAC;SAC1B;QACD,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAC5B;KACF;AACH,CAAC;AA7BD,iCA6BC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport { Evaluator } from './evaluate-json';\nimport type { types as t } from '@babel/core';\nimport error from './error';\nimport State from './state';\n\nexport type MacroConditionPath = NodePath<t.IfStatement | t.ConditionalExpression> & {\n get(test: 'test'): NodePath<t.CallExpression> & { get(callee: 'callee'): NodePath<t.Identifier> };\n};\n\nexport function isMacroConditionPath(\n path: NodePath<t.IfStatement | t.ConditionalExpression>\n): path is MacroConditionPath {\n let test = path.get('test');\n if (test.isCallExpression()) {\n let callee = test.get('callee');\n if (callee.referencesImport('@embroider/macros', 'macroCondition')) {\n return true;\n }\n }\n return false;\n}\n\nexport default function macroCondition(conditionalPath: MacroConditionPath, state: State) {\n let args = conditionalPath.get('test').get('arguments');\n if (args.length !== 1) {\n throw error(conditionalPath, `macroCondition accepts exactly one argument, you passed ${args.length}`);\n }\n\n let [predicatePath] = args;\n let predicate = new Evaluator({ state }).evaluate(predicatePath);\n if (!predicate.confident) {\n throw error(args[0], `the first argument to macroCondition must be statically known`);\n }\n\n let consequent = conditionalPath.get('consequent');\n let alternate = conditionalPath.get('alternate');\n\n if (state.opts.mode === 'run-time') {\n let callee = conditionalPath.get('test').get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'macroCondition'));\n } else {\n let [kept, removed] = predicate.value ? [consequent.node, alternate.node] : [alternate.node, consequent.node];\n if (kept) {\n conditionalPath.replaceWith(kept);\n } else {\n conditionalPath.remove();\n }\n if (removed) {\n state.removed.add(removed);\n }\n }\n}\n"]}
|
|
@@ -34,19 +34,13 @@ function main(context) {
|
|
|
34
34
|
let t = context.types;
|
|
35
35
|
let visitor = {
|
|
36
36
|
Program: {
|
|
37
|
-
enter(
|
|
38
|
-
|
|
39
|
-
state.jobs = [];
|
|
40
|
-
state.removed = new Set();
|
|
41
|
-
state.calledIdentifiers = new Set();
|
|
42
|
-
state.neededRuntimeImports = new Map();
|
|
43
|
-
state.neededEagerImports = new Map();
|
|
37
|
+
enter(path, state) {
|
|
38
|
+
(0, state_1.initState)(t, path, state);
|
|
44
39
|
state.packageCache = shared_internals_1.PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);
|
|
45
40
|
},
|
|
46
|
-
exit(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
addEagerImports(path, state, t);
|
|
41
|
+
exit(_, state) {
|
|
42
|
+
// @embroider/macros itself has no runtime behaviors and should always be removed
|
|
43
|
+
state.importUtil.removeAllImports('@embroider/macros');
|
|
50
44
|
for (let handler of state.jobs) {
|
|
51
45
|
handler();
|
|
52
46
|
}
|
|
@@ -72,7 +66,7 @@ function main(context) {
|
|
|
72
66
|
enter(path, state) {
|
|
73
67
|
let id = path.get('id');
|
|
74
68
|
if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {
|
|
75
|
-
let pkg = state.
|
|
69
|
+
let pkg = state.owningPackage();
|
|
76
70
|
if (pkg && pkg.name === '@embroider/macros') {
|
|
77
71
|
(0, get_config_1.inlineRuntimeConfig)(path, state, context);
|
|
78
72
|
}
|
|
@@ -121,7 +115,7 @@ function main(context) {
|
|
|
121
115
|
// instead falls through to evaluateMacroCall.
|
|
122
116
|
if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {
|
|
123
117
|
state.calledIdentifiers.add(callee.node);
|
|
124
|
-
state.
|
|
118
|
+
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));
|
|
125
119
|
return;
|
|
126
120
|
}
|
|
127
121
|
let result = new evaluate_json_1.Evaluator({ state }).evaluateMacroCall(path);
|
|
@@ -146,18 +140,18 @@ function main(context) {
|
|
|
146
140
|
if ((specifier === null || specifier === void 0 ? void 0 : specifier.type) !== 'StringLiteral') {
|
|
147
141
|
throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);
|
|
148
142
|
}
|
|
149
|
-
|
|
150
|
-
if (!replacePaths) {
|
|
151
|
-
replacePaths = [];
|
|
152
|
-
state.neededEagerImports.set(specifier.value, replacePaths);
|
|
153
|
-
}
|
|
154
|
-
replacePaths.push(path);
|
|
143
|
+
path.replaceWith(state.importUtil.import(path, specifier.value, '*'));
|
|
155
144
|
state.calledIdentifiers.add(callee.node);
|
|
156
145
|
}
|
|
157
146
|
else {
|
|
147
|
+
if (path.scope.hasBinding('require')) {
|
|
148
|
+
path.scope.rename('require');
|
|
149
|
+
}
|
|
158
150
|
let r = t.identifier('require');
|
|
159
151
|
state.generatedRequires.add(r);
|
|
160
|
-
|
|
152
|
+
path.replaceWith(t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [
|
|
153
|
+
t.callExpression(r, path.node.arguments),
|
|
154
|
+
]));
|
|
161
155
|
}
|
|
162
156
|
return;
|
|
163
157
|
}
|
|
@@ -202,7 +196,7 @@ function main(context) {
|
|
|
202
196
|
path.node.name === 'require' &&
|
|
203
197
|
!state.generatedRequires.has(path.node) &&
|
|
204
198
|
!path.scope.hasBinding('require') &&
|
|
205
|
-
|
|
199
|
+
state.owningPackage().isEmberPackage()) {
|
|
206
200
|
// Our importSync macro has been compiled to `require`. But we want to
|
|
207
201
|
// distinguish that from any pre-existing, user-written `require` in an
|
|
208
202
|
// Ember addon, which should retain its *runtime* meaning.
|
|
@@ -228,46 +222,4 @@ function main(context) {
|
|
|
228
222
|
return { visitor };
|
|
229
223
|
}
|
|
230
224
|
exports.default = main;
|
|
231
|
-
// This removes imports from "@embroider/macros" itself, because we have no
|
|
232
|
-
// runtime behavior at all.
|
|
233
|
-
function pruneMacroImports(path) {
|
|
234
|
-
if (!path.isProgram()) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
for (let topLevelPath of path.get('body')) {
|
|
238
|
-
if (topLevelPath.isImportDeclaration() && topLevelPath.get('source').node.value === '@embroider/macros') {
|
|
239
|
-
topLevelPath.remove();
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function addRuntimeImports(path, state, context) {
|
|
244
|
-
let t = context.types;
|
|
245
|
-
if (state.neededRuntimeImports.size > 0) {
|
|
246
|
-
path.node.body.push(t.importDeclaration([...state.neededRuntimeImports].map(([local, imported]) => t.importSpecifier(t.identifier(local), t.identifier(imported))), t.stringLiteral((0, state_1.pathToRuntime)(path, state))));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function addEagerImports(path, state, t) {
|
|
250
|
-
let createdNames = new Set();
|
|
251
|
-
for (let [specifier, replacePaths] of state.neededEagerImports.entries()) {
|
|
252
|
-
let local = unusedNameLike('a', replacePaths, createdNames);
|
|
253
|
-
createdNames.add(local);
|
|
254
|
-
path.node.body.push(t.importDeclaration([t.importNamespaceSpecifier(t.identifier(local))], t.stringLiteral(specifier)));
|
|
255
|
-
for (let nodePath of replacePaths) {
|
|
256
|
-
nodePath.replaceWith(t.identifier(local));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function ownedByEmberPackage(path, state) {
|
|
261
|
-
let filename = (0, state_1.sourceFile)(path, state);
|
|
262
|
-
let pkg = state.packageCache.ownerOfFile(filename);
|
|
263
|
-
return pkg && pkg.isEmberPackage();
|
|
264
|
-
}
|
|
265
|
-
function unusedNameLike(name, paths, banned) {
|
|
266
|
-
let candidate = name;
|
|
267
|
-
let counter = 0;
|
|
268
|
-
while (banned.has(candidate) || paths.some(path => path.scope.getBinding(candidate))) {
|
|
269
|
-
candidate = `${name}${counter++}`;
|
|
270
|
-
}
|
|
271
|
-
return candidate;
|
|
272
|
-
}
|
|
273
225
|
//# sourceMappingURL=macros-babel-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA,kEAA2D;AAC3D,mCAA2D;AAC3D,6CAAwF;AACxF,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAG3D,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG;QACZ,OAAO,EAAE;YACP,KAAK,CAAC,CAAsB,EAAE,KAAY;gBACxC,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;gBACpC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;gBAChB,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;gBAC1B,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;gBACpC,KAAK,CAAC,oBAAoB,GAAG,IAAI,GAAG,EAAE,CAAC;gBACvC,KAAK,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;gBACrC,KAAK,CAAC,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC,IAA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K,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,KAA0B,EAAE,MAAmB;IACnF,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE;QACpF,SAAS,GAAG,GAAG,IAAI,GAAG,OAAO,EAAE,EAAE,CAAC;KACnC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport { PackageCache } from '@embroider/shared-internals';\nimport State, { sourceFile, pathToRuntime } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(_: NodePath<t.Program>, state: State) {\n state.generatedRequires = new Set();\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.neededRuntimeImports = new Map();\n state.neededEagerImports = new Map();\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n },\n exit(path: NodePath<t.Program>, state: State) {\n pruneMacroImports(path);\n addRuntimeImports(path, state, context);\n addEagerImports(path, state, t);\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {\n let pkg = state.packageCache.ownerOfFile(sourceFile(path, state));\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n state.neededRuntimeImports.set(callee.node.name, 'isTesting');\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n if (state.opts.importSyncImplementation === 'eager') {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n let replacePaths = state.neededEagerImports.get(specifier.value);\n if (!replacePaths) {\n replacePaths = [];\n state.neededEagerImports.set(specifier.value, replacePaths);\n }\n replacePaths.push(path);\n state.calledIdentifiers.add(callee.node);\n } else {\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n callee.replaceWith(r);\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n ownedByEmberPackage(path, state)\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n\n// This removes imports from \"@embroider/macros\" itself, because we have no\n// runtime behavior at all.\nfunction pruneMacroImports(path: NodePath) {\n if (!path.isProgram()) {\n return;\n }\n for (let topLevelPath of path.get('body')) {\n if (topLevelPath.isImportDeclaration() && topLevelPath.get('source').node.value === '@embroider/macros') {\n topLevelPath.remove();\n }\n }\n}\n\nfunction addRuntimeImports(path: NodePath<t.Program>, state: State, context: typeof Babel) {\n let t = context.types;\n if (state.neededRuntimeImports.size > 0) {\n path.node.body.push(\n t.importDeclaration(\n [...state.neededRuntimeImports].map(([local, imported]) =>\n t.importSpecifier(t.identifier(local), t.identifier(imported))\n ),\n t.stringLiteral(pathToRuntime(path, state))\n )\n );\n }\n}\n\nfunction addEagerImports(path: NodePath<t.Program>, state: State, t: typeof Babel['types']) {\n let createdNames = new Set<string>();\n for (let [specifier, replacePaths] of state.neededEagerImports.entries()) {\n let local = unusedNameLike('a', replacePaths, createdNames);\n createdNames.add(local);\n path.node.body.push(\n t.importDeclaration([t.importNamespaceSpecifier(t.identifier(local))], t.stringLiteral(specifier))\n );\n for (let nodePath of replacePaths) {\n nodePath.replaceWith(t.identifier(local));\n }\n }\n}\n\nfunction ownedByEmberPackage(path: NodePath, state: State) {\n let filename = sourceFile(path, state);\n let pkg = state.packageCache.ownerOfFile(filename);\n return pkg && pkg.isEmberPackage();\n}\n\nfunction unusedNameLike(name: string, paths: NodePath<unknown>[], banned: Set<string>) {\n let candidate = name;\n let counter = 0;\n while (banned.has(candidate) || paths.some(path => path.scope.getBinding(candidate))) {\n candidate = `${name}${counter++}`;\n }\n return candidate;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA,kEAA2D;AAC3D,mCAA2C;AAC3C,6CAAwF;AACxF,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAG3D,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG;QACZ,OAAO,EAAE;YACP,KAAK,CAAC,IAAyB,EAAE,KAAY;gBAC3C,IAAA,iBAAS,EAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBAE1B,KAAK,CAAC,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC1F,CAAC;YACD,IAAI,CAAC,CAAsB,EA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AC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACzE;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE;QACnD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;oBACtC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE;wBACpB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;qBACxD;iBACF;YACH,CAAC;SACF,CAAC;KACH;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AAhND,uBAgNC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport { PackageCache } from '@embroider/shared-internals';\nimport State, { initState } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n if (state.opts.importSyncImplementation === 'eager') {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n path.replaceWith(state.importUtil.import(path, specifier.value, '*'));\n state.calledIdentifiers.add(callee.node);\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberPackage()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const state_1 = require("./state");
|
|
7
6
|
const error_1 = __importDefault(require("./error"));
|
|
8
7
|
const evaluate_json_1 = require("./evaluate-json");
|
|
9
8
|
const resolve_1 = __importDefault(require("resolve"));
|
|
@@ -16,9 +15,8 @@ function moduleExists(path, state) {
|
|
|
16
15
|
if (moduleSpecifier.type !== 'StringLiteral') {
|
|
17
16
|
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the first argument to moduleExists must be a string literal`);
|
|
18
17
|
}
|
|
19
|
-
let sourceFileName = (0, state_1.sourceFile)(path, state);
|
|
20
18
|
try {
|
|
21
|
-
resolve_1.default.sync(moduleSpecifier.value, { basedir: (0, path_1.dirname)(
|
|
19
|
+
resolve_1.default.sync(moduleSpecifier.value, { basedir: (0, path_1.dirname)(state.sourceFile) });
|
|
22
20
|
return true;
|
|
23
21
|
}
|
|
24
22
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-exists.js","sourceRoot":"","sources":["module-exists.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"module-exists.js","sourceRoot":"","sources":["module-exists.ts"],"names":[],"mappings":";;;;;AAGA,oDAA4B;AAC5B,mDAA8C;AAC9C,sDAA8B;AAC9B,+BAA+B;AAE/B,SAAwB,YAAY,CAAC,IAAgC,EAAE,KAAY;IACjF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,uDAAuD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KACxG;IACD,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,IAAI,eAAe,CAAC,IAAI,KAAK,eAAe,EAAE;QAC5C,MAAM,IAAA,eAAK,EAAC,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,6DAA6D,CAAC,CAAC;KACnH;IACD,IAAI;QACF,iBAAO,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAA,cAAO,EAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnC,MAAM,GAAG,CAAC;SACX;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAjBD,+BAiBC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State from './state';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\nimport resolve from 'resolve';\nimport { dirname } from 'path';\n\nexport default function moduleExists(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 1) {\n throw error(path, `moduleExists takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n let [moduleSpecifier] = path.node.arguments;\n if (moduleSpecifier.type !== 'StringLiteral') {\n throw error(assertArray(path.get('arguments'))[0], `the first argument to moduleExists must be a string literal`);\n }\n try {\n resolve.sync(moduleSpecifier.value, { basedir: dirname(state.sourceFile) });\n return true;\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
|
package/src/babel/state.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { NodePath, Node } from '@babel/traverse';
|
|
2
2
|
import { Package, PackageCache } from '@embroider/shared-internals';
|
|
3
|
+
import { ImportUtil } from 'babel-import-util';
|
|
4
|
+
import type * as Babel from '@babel/core';
|
|
3
5
|
export default interface State {
|
|
6
|
+
importUtil: ImportUtil;
|
|
4
7
|
generatedRequires: Set<Node>;
|
|
5
8
|
removed: Set<Node>;
|
|
6
9
|
calledIdentifiers: Set<Node>;
|
|
7
10
|
jobs: (() => void)[];
|
|
8
|
-
neededRuntimeImports: Map<string, string>;
|
|
9
|
-
neededEagerImports: Map<string, NodePath[]>;
|
|
10
11
|
packageCache: PackageCache;
|
|
12
|
+
sourceFile: string;
|
|
13
|
+
pathToOurAddon(moduleName: string): string;
|
|
14
|
+
owningPackage(): Package;
|
|
15
|
+
cloneDeep(node: Node): Node;
|
|
11
16
|
opts: {
|
|
12
17
|
userConfigs: {
|
|
13
18
|
[pkgRoot: string]: unknown;
|
|
@@ -23,8 +28,4 @@ export default interface State {
|
|
|
23
28
|
importSyncImplementation: 'cjs' | 'eager';
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function sourceFile(path: NodePath, state: State): string;
|
|
28
|
-
export declare function owningPackage(path: NodePath, state: State): Package;
|
|
29
|
-
export declare function cloneDeep(node: Node, state: State): Node;
|
|
30
|
-
export declare function unusedNameLike(name: string, path: NodePath<unknown>): string;
|
|
31
|
+
export declare function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State): void;
|
package/src/babel/state.js
CHANGED
|
@@ -3,17 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.initState = void 0;
|
|
7
7
|
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
8
8
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const shared_internals_1 = require("@embroider/shared-internals");
|
|
11
|
-
const
|
|
12
|
-
function
|
|
13
|
-
|
|
11
|
+
const babel_import_util_1 = require("babel-import-util");
|
|
12
|
+
function initState(t, path, state) {
|
|
13
|
+
state.importUtil = new babel_import_util_1.ImportUtil(t, path);
|
|
14
|
+
state.generatedRequires = new Set();
|
|
15
|
+
state.jobs = [];
|
|
16
|
+
state.removed = new Set();
|
|
17
|
+
state.calledIdentifiers = new Set();
|
|
18
|
+
state.packageCache = shared_internals_1.PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);
|
|
19
|
+
state.sourceFile = state.opts.owningPackageRoot || path.hub.file.opts.filename;
|
|
20
|
+
state.pathToOurAddon = pathToAddon;
|
|
21
|
+
state.owningPackage = owningPackage;
|
|
22
|
+
state.cloneDeep = cloneDeep;
|
|
23
|
+
}
|
|
24
|
+
exports.initState = initState;
|
|
25
|
+
const runtimeAddonPath = (0, path_1.resolve)((0, path_1.join)(__dirname, '..', 'addon'));
|
|
26
|
+
function pathToAddon(moduleName) {
|
|
27
|
+
if (!this.opts.owningPackageRoot) {
|
|
14
28
|
// running inside embroider, so make a relative path to the module
|
|
15
|
-
|
|
16
|
-
return (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(source), runtimePath);
|
|
29
|
+
return (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(this.sourceFile), (0, path_1.join)(runtimeAddonPath, moduleName));
|
|
17
30
|
}
|
|
18
31
|
else {
|
|
19
32
|
// running inside a classic build, so use a classic-compatible runtime
|
|
@@ -24,24 +37,18 @@ function pathToRuntime(path, state) {
|
|
|
24
37
|
// introducing incompatible changes to its API, you need to change this name
|
|
25
38
|
// (by tacking on a version number, etc) and rename the corresponding file
|
|
26
39
|
// in ../addon.
|
|
27
|
-
return
|
|
40
|
+
return `@embroider/macros/${moduleName}`;
|
|
28
41
|
}
|
|
29
42
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return state.opts.owningPackageRoot || path.hub.file.opts.filename;
|
|
33
|
-
}
|
|
34
|
-
exports.sourceFile = sourceFile;
|
|
35
|
-
function owningPackage(path, state) {
|
|
36
|
-
let file = sourceFile(path, state);
|
|
37
|
-
let pkg = state.packageCache.ownerOfFile(file);
|
|
43
|
+
function owningPackage() {
|
|
44
|
+
let pkg = this.packageCache.ownerOfFile(this.sourceFile);
|
|
38
45
|
if (!pkg) {
|
|
39
|
-
throw new Error(`unable to determine which npm package owns the file ${
|
|
46
|
+
throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);
|
|
40
47
|
}
|
|
41
48
|
return pkg;
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
function cloneDeep(node) {
|
|
51
|
+
let state = this;
|
|
45
52
|
return (0, cloneDeepWith_1.default)(node, function (value) {
|
|
46
53
|
if (state.generatedRequires.has(value)) {
|
|
47
54
|
let cloned = (0, cloneDeep_1.default)(value);
|
|
@@ -50,14 +57,4 @@ function cloneDeep(node, state) {
|
|
|
50
57
|
}
|
|
51
58
|
});
|
|
52
59
|
}
|
|
53
|
-
exports.cloneDeep = cloneDeep;
|
|
54
|
-
function unusedNameLike(name, path) {
|
|
55
|
-
let candidate = name;
|
|
56
|
-
let counter = 0;
|
|
57
|
-
while (path.scope.getBinding(candidate)) {
|
|
58
|
-
candidate = `${name}${counter++}`;
|
|
59
|
-
}
|
|
60
|
-
return candidate;
|
|
61
|
-
}
|
|
62
|
-
exports.unusedNameLike = unusedNameLike;
|
|
63
60
|
//# sourceMappingURL=state.js.map
|
package/src/babel/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":";;;;;;AACA,yEAAiD;AACjD,iEAA+C;AAC/C,+BAA8C;AAC9C,kEAAsF;
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":";;;;;;AACA,yEAAiD;AACjD,iEAA+C;AAC/C,+BAA8C;AAC9C,kEAAsF;AACtF,yDAA+C;AA8C/C,SAAgB,SAAS,CAAC,CAAqB,EAAE,IAAmC,EAAE,KAAY;IAChG,KAAK,CAAC,UAAU,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;IAChB,KAAK,CA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3F;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,SAAS,CAAc,IAAU;IACxC,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,OAAO,IAAA,uBAAa,EAAC,IAAI,EAAE,UAAU,KAAU;QAC7C,IAAI,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACtC,IAAI,MAAM,GAAG,IAAA,mBAAe,EAAC,KAAK,CAAC,CAAC;YACpC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpC,OAAO,MAAM,CAAC;SACf;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport cloneDeepWith from 'lodash/cloneDeepWith';\nimport lodashCloneDeep from 'lodash/cloneDeep';\nimport { join, dirname, resolve } from 'path';\nimport { explicitRelative, Package, PackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\nimport type * as Babel from '@babel/core';\n\nexport default interface State {\n importUtil: ImportUtil;\n generatedRequires: Set<Node>;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n packageCache: PackageCache;\n sourceFile: string;\n pathToOurAddon(moduleName: string): string;\n owningPackage(): Package;\n cloneDeep(node: Node): Node;\n\n opts: {\n userConfigs: {\n [pkgRoot: string]: unknown;\n };\n globalConfig: {\n [key: string]: unknown;\n };\n // we set this when we're running inside classic ember-cli, because in that\n // case we don't have finer-grained info available about where the files\n // we're processing are globally located. When running in embroider, we\n // don't set this, because each file is visible at its full\n // globally-relevant path.\n owningPackageRoot: string | undefined;\n\n // list of packages that are under active development, represented by the\n // path to their package root directory\n isDevelopingPackageRoots: string[];\n\n // the package root directory of the app. Needed so that we can get\n // consistent answers to `isDevelopingApp` and `isDeveopingThisPackage`, as\n // well as consistent handling of Package devDependencies vs dependencies.\n appPackageRoot: string;\n\n embroiderMacrosConfigMarker: true;\n\n mode: 'compile-time' | 'run-time';\n\n importSyncImplementation: 'cjs' | 'eager';\n };\n}\n\nexport function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State) {\n state.importUtil = new ImportUtil(t, path);\n state.generatedRequires = new Set();\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n state.sourceFile = state.opts.owningPackageRoot || path.hub.file.opts.filename;\n state.pathToOurAddon = pathToAddon;\n state.owningPackage = owningPackage;\n state.cloneDeep = cloneDeep;\n}\n\nconst runtimeAddonPath = resolve(join(__dirname, '..', 'addon'));\n\nfunction pathToAddon(this: State, moduleName: string): string {\n if (!this.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n return explicitRelative(dirname(this.sourceFile), join(runtimeAddonPath, moduleName));\n } else {\n // running inside a classic build, so use a classic-compatible runtime\n // specifier.\n //\n // CAUTION: the module we're pointing at here gets merged between all\n // present versions of @embroider/macros, and one will win. So if you are\n // introducing incompatible changes to its API, you need to change this name\n // (by tacking on a version number, etc) and rename the corresponding file\n // in ../addon.\n return `@embroider/macros/${moduleName}`;\n }\n}\n\nfunction owningPackage(this: State): Package {\n let pkg = this.packageCache.ownerOfFile(this.sourceFile);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);\n }\n return pkg;\n}\n\nfunction cloneDeep(this: State, node: Node): Node {\n let state = this;\n return cloneDeepWith(node, function (value: any) {\n if (state.generatedRequires.has(value)) {\n let cloned = lodashCloneDeep(value);\n state.generatedRequires.add(cloned);\n return cloned;\n }\n });\n}\n"]}
|
|
@@ -16,7 +16,7 @@ baseDir, moduleName, packageCache) {
|
|
|
16
16
|
let packageName = node.params[0].value;
|
|
17
17
|
let range = node.params[1].value;
|
|
18
18
|
let us = packageCache.ownerOfFile(baseDir || moduleName);
|
|
19
|
-
if (!us || us
|
|
19
|
+
if (!(us === null || us === void 0 ? void 0 : us.hasDependency(packageName))) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
let pkg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAGnC,SAAwB,mBAAmB,CACzC,IAAS;AACT,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,wEAAwE;AACxE,OAA2B,EAC3B,UAAkB,EAClB,YAA0B;IAE1B,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACtG;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE;QAC9D,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACtF;IAED,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,IAAI,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAGnC,SAAwB,mBAAmB,CACzC,IAAS;AACT,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,wEAAwE;AACxE,OAA2B,EAC3B,UAAkB,EAClB,YAA0B;IAE1B,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACtG;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE;QAC9D,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACtF;IAED,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,IAAI,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,aAAa,CAAC,WAAW,CAAC,CAAA,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,CAAC;IACR,IAAI;QACF,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC7C;IAAC,OAAO,GAAG,EAAE;QACZ,sEAAsE;KACvE;IAED,IAAI,GAAG,EAAE;QACP,OAAO,IAAA,kBAAS,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE;YACnC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;KACJ;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAvCD,sCAuCC","sourcesContent":["import { satisfies } from 'semver';\nimport type { PackageCache } from '@embroider/shared-internals';\n\nexport default function dependencySatisfies(\n node: any,\n // when we're running in traditional ember-cli, baseDir is configured and we\n // do all lookups relative to that (single) package. But when we're running in\n // embroider stage3 we process all packages simultaneously, so baseDir is left\n // unconfigured and moduleName will be the full path to the source file.\n baseDir: string | undefined,\n moduleName: string,\n packageCache: PackageCache\n) {\n if (node.params.length !== 2) {\n throw new Error(`macroDependencySatisfies requires two arguments, you passed ${node.params.length}`);\n }\n\n if (!node.params.every((p: any) => p.type === 'StringLiteral')) {\n throw new Error(`all arguments to macroDependencySatisfies must be string literals`);\n }\n\n let packageName = node.params[0].value;\n let range = node.params[1].value;\n\n let us = packageCache.ownerOfFile(baseDir || moduleName);\n if (!us?.hasDependency(packageName)) {\n return false;\n }\n\n let pkg;\n try {\n pkg = packageCache.resolve(packageName, us);\n } catch (err) {\n // it's not an error if we can't resolve it, we just don't satisfy it.\n }\n\n if (pkg) {\n return satisfies(pkg.version, range, {\n includePrerelease: true,\n });\n }\n return false;\n}\n"]}
|
|
@@ -21,10 +21,10 @@ function maybeAttrs(elementNode, node, builders) {
|
|
|
21
21
|
}
|
|
22
22
|
if (result.value) {
|
|
23
23
|
for (let bareAttr of bareAttrs) {
|
|
24
|
-
elementNode.attributes.push(builders.attr(bareAttr.original, builders.text('')));
|
|
24
|
+
elementNode.attributes.push(builders.attr(bareAttr.original, builders.text(''), bareAttr.loc));
|
|
25
25
|
}
|
|
26
26
|
for (let attr of node.hash.pairs) {
|
|
27
|
-
elementNode.attributes.push(builders.attr(attr.key, builders.mustache(attr.value)));
|
|
27
|
+
elementNode.attributes.push(builders.attr(attr.key, builders.mustache(attr.value), attr.loc));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-maybe-attrs.js","sourceRoot":"","sources":["macro-maybe-attrs.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAElC,SAAgB,UAAU,CAAC,WAAgB,EAAE,IAAS,EAAE,QAAa;IACnE,IAAI,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAE5C,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IAED,IAAI,MAAM,GAAG,IAAA,kBAAQ,EAAC,SAAS,CAAC,CAAC;IACjC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,QAAQ,IAAI,SAAS,EAAE;YAC9B,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;SAChG;QAED,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YAChC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;SAC/F;KACF;AACH,CAAC;AA3BD,gCA2BC","sourcesContent":["import evaluate from './evaluate';\n\nexport function maybeAttrs(elementNode: any, node: any, builders: any) {\n let [predicate, ...bareAttrs] = node.params;\n\n if (!predicate) {\n throw new Error(`macroMaybeAttrs requires at least one argument`);\n }\n\n let result = evaluate(predicate);\n if (!result.confident) {\n throw new Error(`first argument to macroMaybeAttrs must be statically analyzable`);\n }\n\n for (let bareAttr of bareAttrs) {\n if (bareAttr.type !== 'PathExpression') {\n throw new Error(`macroMaybeAttrs found a ${bareAttr.type} where it expected a PathExpression`);\n }\n }\n\n if (result.value) {\n for (let bareAttr of bareAttrs) {\n elementNode.attributes.push(builders.attr(bareAttr.original, builders.text(''), bareAttr.loc));\n }\n\n for (let attr of node.hash.pairs) {\n elementNode.attributes.push(builders.attr(attr.key, builders.mustache(attr.value), attr.loc));\n }\n }\n}\n"]}
|
package/src/macros-config.js
CHANGED
|
@@ -16,15 +16,30 @@ const partition_1 = __importDefault(require("lodash/partition"));
|
|
|
16
16
|
// MacrosConfig, it will have its own instance with its own code, but will still
|
|
17
17
|
// share the GlobalSharedState beneath.
|
|
18
18
|
let localSharedState = new WeakMap();
|
|
19
|
+
function gatherAddonCacheKeyWorker(item, memo) {
|
|
20
|
+
item.addons.forEach((addon) => {
|
|
21
|
+
let key = `${addon.pkg.name}@${addon.pkg.version}`;
|
|
22
|
+
memo.add(key);
|
|
23
|
+
gatherAddonCacheKeyWorker(addon, memo);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
let addonCacheKey = new WeakMap();
|
|
19
27
|
// creates a string representing all addons and their versions
|
|
20
28
|
// (foo@1.0.0|bar@2.0.0) to use as a cachekey
|
|
21
|
-
function gatherAddonCacheKey(
|
|
22
|
-
|
|
29
|
+
function gatherAddonCacheKey(project) {
|
|
30
|
+
let cacheKey = addonCacheKey.get(project);
|
|
31
|
+
if (cacheKey) {
|
|
32
|
+
return cacheKey;
|
|
33
|
+
}
|
|
34
|
+
let memo = new Set();
|
|
35
|
+
project.addons.forEach((addon) => {
|
|
23
36
|
let key = `${addon.pkg.name}@${addon.pkg.version}`;
|
|
24
37
|
memo.add(key);
|
|
25
|
-
|
|
38
|
+
gatherAddonCacheKeyWorker(addon, memo);
|
|
26
39
|
});
|
|
27
|
-
|
|
40
|
+
cacheKey = [...memo].join('|');
|
|
41
|
+
addonCacheKey.set(project, cacheKey);
|
|
42
|
+
return cacheKey;
|
|
28
43
|
}
|
|
29
44
|
class MacrosConfig {
|
|
30
45
|
constructor(appRoot) {
|
|
@@ -144,6 +159,9 @@ class MacrosConfig {
|
|
|
144
159
|
if (!this._configWritable) {
|
|
145
160
|
throw new Error(`[Embroider:MacrosConfig] attempted to set config after configs have been finalized from: '${fromPath}'`);
|
|
146
161
|
}
|
|
162
|
+
if (!isSerializable(config)) {
|
|
163
|
+
throw new Error(`[Embroider:MacrosConfig] the given config from '${fromPath}' for packageName '${packageName}' is not JSON serializable.`);
|
|
164
|
+
}
|
|
147
165
|
let targetPackage = this.resolvePackage(fromPath, packageName);
|
|
148
166
|
let peers = (0, shared_internals_1.getOrCreate)(this.configs, targetPackage.root, () => []);
|
|
149
167
|
peers.push(config);
|
|
@@ -337,4 +355,32 @@ function defaultMergerFor(pkgRoot) {
|
|
|
337
355
|
return Object.assign({}, ...ownConfigs, ...otherConfigs);
|
|
338
356
|
};
|
|
339
357
|
}
|
|
358
|
+
function isSerializable(obj) {
|
|
359
|
+
if (isScalar(obj)) {
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
if (Array.isArray(obj)) {
|
|
363
|
+
return !obj.some((arrayItem) => !isSerializable(arrayItem));
|
|
364
|
+
}
|
|
365
|
+
if (isPlainObject(obj)) {
|
|
366
|
+
for (let property in obj) {
|
|
367
|
+
let value = obj[property];
|
|
368
|
+
if (!isSerializable(value)) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
function isScalar(val) {
|
|
377
|
+
return (typeof val === 'undefined' ||
|
|
378
|
+
typeof val === 'string' ||
|
|
379
|
+
typeof val === 'boolean' ||
|
|
380
|
+
typeof val === 'number' ||
|
|
381
|
+
val === null);
|
|
382
|
+
}
|
|
383
|
+
function isPlainObject(obj) {
|
|
384
|
+
return typeof obj === 'object' && obj.constructor === Object && obj.toString() === '[object Object]';
|
|
385
|
+
}
|
|
340
386
|
//# sourceMappingURL=macros-config.js.map
|
package/src/macros-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros-config.js","sourceRoot":"","sources":["macros-config.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA4B;AAC5B,oDAA4B;AAC5B,sDAA6B;AAE7B,kEAAwE;AACxE,2DAAwG;AAExG,iEAAyC;AA0BzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,uCAAuC;AACvC,IAAI,gBAAgB,GAA+B,IAAI,OAAO,EAAE,CAAC;AAEjE,8DAA8D;AAC9D,6CAA6C;AAC7C,SAAS,mBAAmB,CAAC,IAAS,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;I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E,IAAI,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC,EAAE,EAAE;YACP,MAAM,IAAI,KAAK,CAAC,gFAAgF,QAAQ,EAAE,CAAC,CAAC;SAC7G;QACD,IAAI,WAAW,EAAE;YACf,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;SACnD;aAAM;YACL,OAAO,EAAE,CAAC;SACX;IACH,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,CAAC;CACF;AA1WD,+BA0WC;AAED,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,SAAS,aAAa,CAAC,OAAiB,EAAE,EAAE,cAAc,EAAsC;QACrG,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,IAAA,mBAAS,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAW,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACvG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import fs from 'fs';\nimport { join } from 'path';\nimport crypto from 'crypto';\nimport findUp from 'find-up';\nimport type { PluginItem } from '@babel/core';\nimport { PackageCache, getOrCreate } from '@embroider/shared-internals';\nimport { FirstTransformParams, makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nexport type SourceOfConfig = (config: object) => {\n readonly name: string;\n readonly root: string;\n readonly version: string;\n};\n\nexport type Merger = (\n configs: object[],\n params: {\n sourceOfConfig: SourceOfConfig;\n }\n) => object;\n\n// Do not change this type signature without pondering deeply the mysteries of\n// being compatible with unwritten future versions of this library.\ntype GlobalSharedState = WeakMap<\n any,\n {\n configs: Map<string, object[]>;\n configSources: WeakMap<object, string>;\n mergers: Map<string, { merger: Merger; fromPath: string }>;\n }\n>;\n\n// this is a module-scoped cache. If multiple callers ask _this copy_ of\n// @embroider/macros for a shared MacrosConfig, they'll all get the same one.\n// And if somebody asks a *different* copy of @embroider/macros for the shared\n// MacrosConfig, it will have its own instance with its own code, but will still\n// share the GlobalSharedState beneath.\nlet localSharedState: WeakMap<any, MacrosConfig> = new WeakMap();\n\n// creates a string representing all addons and their versions\n// (foo@1.0.0|bar@2.0.0) to use as a cachekey\nfunction gatherAddonCacheKey(item: any, memo = new Set()) {\n item.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKey(addon, memo);\n });\n\n return [...memo].join('|');\n}\n\nexport default class MacrosConfig {\n static for(key: any, appRoot: string): MacrosConfig {\n let found = localSharedState.get(key);\n if (found) {\n return found;\n }\n\n let g = global as any as { __embroider_macros_global__: GlobalSharedState | undefined };\n if (!g.__embroider_macros_global__) {\n g.__embroider_macros_global__ = new WeakMap();\n }\n\n let shared = g.__embroider_macros_global__.get(key);\n if (shared) {\n // if an earlier version of @embroider/macros created the shared state, it\n // would have configSources.\n if (!shared.configSources) {\n shared.configSources = new WeakMap();\n }\n } else {\n shared = {\n configs: new Map(),\n configSources: new WeakMap(),\n mergers: new Map(),\n };\n g.__embroider_macros_global__.set(key, shared);\n }\n\n let config = new MacrosConfig(appRoot);\n config.configs = shared.configs;\n config.configSources = shared.configSources;\n config.mergers = shared.mergers;\n localSharedState.set(key, config);\n return config;\n }\n\n private mode: 'compile-time' | 'run-time' = 'compile-time';\n private globalConfig: { [key: string]: unknown } = {};\n\n private isDevelopingPackageRoots: Set<string> = new Set();\n\n enableRuntimeMode() {\n if (this.mode !== 'run-time') {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableRuntimeMode after configs have been finalized`);\n }\n this.mode = 'run-time';\n }\n }\n\n enablePackageDevelopment(packageRoot: string) {\n if (!this.isDevelopingPackageRoots.has(packageRoot)) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to enablePackageDevelopment after configs have been finalized`\n );\n }\n this.isDevelopingPackageRoots.add(packageRoot);\n }\n }\n\n private _importSyncImplementation: 'cjs' | 'eager' = 'cjs';\n\n get importSyncImplementation() {\n return this._importSyncImplementation;\n }\n\n set importSyncImplementation(value: 'cjs' | 'eager') {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`\n );\n }\n this._importSyncImplementation = value;\n }\n\n private packageCache: PackageCache;\n\n private constructor(private appRoot: string) {\n // this uses globalConfig because these things truly are global. Even if a\n // package doesn't have a dep or peerDep on @embroider/macros, it's legit\n // for them to want to know the answer to these questions, and there is only\n // one answer throughout the whole dependency graph.\n this.globalConfig['@embroider/macros'] = {\n // this powers the `isTesting` macro. It always starts out false here,\n // because:\n // - if this is a production build, we will evaluate all macros at build\n // time and isTesting will stay false, so test-only code will not be\n // included.\n // - if this is a dev build, we evaluate macros at runtime, which allows\n // both \"I'm running my app in development\" and \"I'm running my test\n // suite\" to coexist within a single build. When you run the test\n // suite, early in the runtime boot process we can flip isTesting to\n // true to distinguish the two.\n isTesting: false,\n };\n this.packageCache = PackageCache.shared('embroider-stage3', appRoot);\n }\n\n private _configWritable = true;\n private configs: Map<string, object[]> = new Map();\n private configSources: WeakMap<object, string> = new WeakMap();\n private mergers: Map<string, { merger: Merger; fromPath: string }> = new Map();\n\n // Registers a new source of configuration to be given to the named package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setConfig(fromPath: string, packageName: string, config: object) {\n return this.internalSetConfig(fromPath, packageName, config);\n }\n\n // Registers a new source of configuration to be given to your own package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setOwnConfig(fromPath: string, config: object) {\n return this.internalSetConfig(fromPath, undefined, config);\n }\n\n // Registers a new source of configuration to be shared globally within the\n // app. USE GLOBALS SPARINGLY! Prefer setConfig or setOwnConfig instead,\n // unless your state is truly, necessarily global.\n //\n // Include a relevant package name in your key to help avoid collisions.\n //\n // Your value must be json-serializable. You must always set fromPath to\n // `__filename`.\n setGlobalConfig(fromPath: string, key: string, value: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set global config after configs have been finalized from: '${fromPath}'`\n );\n }\n this.globalConfig[key] = value;\n }\n\n private internalSetConfig(fromPath: string, packageName: string | undefined, config: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set config after configs have been finalized from: '${fromPath}'`\n );\n }\n\n let targetPackage = this.resolvePackage(fromPath, packageName);\n let peers = getOrCreate(this.configs, targetPackage.root, () => []);\n peers.push(config);\n this.configSources.set(config, fromPath);\n }\n\n // Allows you to set the merging strategy used for your package's config. The\n // merging strategy applies when multiple other packages all try to send\n // configuration to you.\n useMerger(fromPath: string, merger: Merger) {\n if (this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call useMerger after configs have been finalized`);\n }\n\n let targetPackage = this.resolvePackage(fromPath, undefined);\n let other = this.mergers.get(targetPackage.root);\n if (other) {\n throw new Error(\n `[Embroider:MacrosConfig] conflicting mergers registered for package ${targetPackage.name} at ${targetPackage.root}. See ${other.fromPath} and ${fromPath}.`\n );\n }\n this.mergers.set(targetPackage.root, { merger, fromPath });\n }\n\n private cachedUserConfigs: { [packageRoot: string]: object } | undefined;\n\n private get userConfigs() {\n if (this._configWritable) {\n throw new Error('[Embroider:MacrosConfig] cannot read userConfigs until MacrosConfig has been finalized.');\n }\n\n if (!this.cachedUserConfigs) {\n let userConfigs: { [packageRoot: string]: object } = {};\n let sourceOfConfig = this.makeConfigSourcer(this.configSources);\n for (let [pkgRoot, configs] of this.configs) {\n let combined: object;\n if (configs.length > 1) {\n combined = this.mergerFor(pkgRoot)(configs, { sourceOfConfig });\n } else {\n combined = configs[0];\n }\n userConfigs[pkgRoot] = combined;\n }\n for (let [oldPath, newPath] of this.moves) {\n userConfigs[newPath] = userConfigs[oldPath];\n }\n this.cachedUserConfigs = userConfigs;\n }\n\n return this.cachedUserConfigs;\n }\n\n private makeConfigSourcer(configSources: WeakMap<object, string>): SourceOfConfig {\n return config => {\n let fromPath = configSources.get(config);\n if (!fromPath) {\n throw new Error(\n `unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`\n );\n }\n let maybePkg = this.packageCache.ownerOfFile(fromPath);\n if (!maybePkg) {\n throw new Error(\n `bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`\n );\n }\n let pkg = maybePkg;\n return {\n get name() {\n return pkg.name;\n },\n get version() {\n return pkg.version;\n },\n get root() {\n return pkg.root;\n },\n };\n };\n }\n\n // to be called from within your build system. Returns the thing you should\n // push into your babel plugins list.\n //\n // owningPackageRoot is needed when the files you will process (1) all belongs\n // to one package, (2) will not be located in globally correct paths such that\n // normal node_modules resolution can find their dependencies. In other words,\n // owningPackageRoot is needed when you use this inside classic ember-cli, and\n // it's not appropriate inside embroider.\n babelPluginConfig(appOrAddonInstance?: any): PluginItem[] {\n let self = this;\n let owningPackageRoot = appOrAddonInstance ? appOrAddonInstance.root || appOrAddonInstance.project.root : null;\n let opts: State['opts'] = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get userConfigs() {\n return self.userConfigs;\n },\n get globalConfig() {\n return self.globalConfig;\n },\n owningPackageRoot,\n\n isDevelopingPackageRoots: [...this.isDevelopingPackageRoots].map(root => this.moves.get(root) || root),\n appPackageRoot: this.moves.get(this.appRoot) ?? this.appRoot,\n\n // This is used as a signature so we can detect ourself among the plugins\n // emitted from v1 addons.\n embroiderMacrosConfigMarker: true,\n\n get mode() {\n return self.mode;\n },\n\n importSyncImplementation: this.importSyncImplementation,\n };\n\n let lockFilePath = findUp.sync(['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'], { cwd: opts.appPackageRoot });\n\n if (!lockFilePath) {\n lockFilePath = findUp.sync('package.json', { cwd: opts.appPackageRoot });\n }\n\n let lockFileBuffer = lockFilePath ? fs.readFileSync(lockFilePath) : 'no-cache-key';\n\n // @embroider/macros provides a macro called dependencySatisfies which checks if a given\n // package name satisfies a given semver version range. Due to the way babel caches this can\n // cause a problem where the macro plugin does not run (because it has been cached) but the version\n // of the dependency being checked for changes (due to installing a different version). This will lead to\n // the old evaluated state being used which might be invalid. This cache busting plugin keeps track of a\n // hash representing the lock file of the app and if it ever changes forces babel to rerun its plugins.\n // more information in issue #906\n let hash = crypto.createHash('sha256');\n hash = hash.update(lockFileBuffer);\n if (appOrAddonInstance) {\n // ensure that the actual running addon names and versions are accounted\n // for in the cache key; this ensures that we still invalidate the cache\n // when linking another project (e.g. ember-source) which would normally\n // not cause the lockfile to change;\n hash = hash.update(gatherAddonCacheKey(appOrAddonInstance.project));\n }\n let cacheKey = hash.digest('hex');\n\n return [\n [join(__dirname, 'babel', 'macros-babel-plugin.js'), opts],\n [\n require.resolve('@embroider/shared-internals/src/babel-plugin-cache-busting.js'),\n { version: cacheKey },\n `@embroider/macros cache buster: ${owningPackageRoot}`,\n ],\n ];\n }\n\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let configs: MacrosConfig | undefined;\n\n let lazyParams = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get configs() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.userConfigs;\n },\n packageRoot: owningPackageRoot,\n get appRoot() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.appRoot;\n },\n };\n\n let plugins = [makeFirstTransform(lazyParams), makeSecondTransform()].reverse();\n function setConfig(c: MacrosConfig) {\n configs = c;\n }\n return { plugins, setConfig, lazyParams };\n }\n\n private mergerFor(pkgRoot: string) {\n let entry = this.mergers.get(pkgRoot);\n if (entry) {\n return entry.merger;\n }\n return defaultMergerFor(pkgRoot);\n }\n\n // this exists because @embroider/compat rewrites and moves v1 addons, and\n // their macro configs need to follow them to their new homes.\n packageMoved(oldPath: string, newPath: string) {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call packageMoved after configs have been finalized`);\n }\n\n this.moves.set(oldPath, newPath);\n }\n\n private moves: Map<string, string> = new Map();\n\n private resolvePackage(fromPath: string, packageName?: string | undefined) {\n let us = this.packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`[Embroider:MacrosConfig] unable to determine which npm package owns the file ${fromPath}`);\n }\n if (packageName) {\n return this.packageCache.resolve(packageName, us);\n } else {\n return us;\n }\n }\n\n finalize() {\n this._configWritable = false;\n }\n}\n\nfunction defaultMergerFor(pkgRoot: string) {\n return function defaultMerger(configs: object[], { sourceOfConfig }: { sourceOfConfig: SourceOfConfig }): object {\n let [ownConfigs, otherConfigs] = partition(configs, c => sourceOfConfig(c as object).root === pkgRoot);\n return Object.assign({}, ...ownConfigs, ...otherConfigs);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"macros-config.js","sourceRoot":"","sources":["macros-config.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA4B;AAC5B,oDAA4B;AAC5B,sDAA6B;AAE7B,kEAAwE;AACxE,2DAAwG;AAExG,iEAAyC;AA0BzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,uCAAuC;AACvC,IAAI,gBAAgB,GAA+B,IAAI,OAAO,EAAE,CAAC;AAEjE,SAAS,yBAAyB,CAAC,IAAS,EAAE,IAAiB;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;QACjC,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QAC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C,CAAC,EAAE,CAAC,cAAc,CAAC,CAAW,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACvG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE;QACjB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,SAAc,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;KAClE;IAED,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE;QACtB,KAAK,IAAI,QAAQ,IAAI,GAAG,EAAE;YACxB,IAAI,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAQ,CAAC;YACjC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;gBAC1B,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,CACL,OAAO,GAAG,KAAK,WAAW;QAC1B,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,SAAS;QACxB,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI,CACb,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,GAAQ;IAC7B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,iBAAiB,CAAC;AACvG,CAAC","sourcesContent":["import fs from 'fs';\nimport { join } from 'path';\nimport crypto from 'crypto';\nimport findUp from 'find-up';\nimport type { PluginItem } from '@babel/core';\nimport { PackageCache, getOrCreate } from '@embroider/shared-internals';\nimport { FirstTransformParams, makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nexport type SourceOfConfig = (config: object) => {\n readonly name: string;\n readonly root: string;\n readonly version: string;\n};\n\nexport type Merger = (\n configs: object[],\n params: {\n sourceOfConfig: SourceOfConfig;\n }\n) => object;\n\n// Do not change this type signature without pondering deeply the mysteries of\n// being compatible with unwritten future versions of this library.\ntype GlobalSharedState = WeakMap<\n any,\n {\n configs: Map<string, object[]>;\n configSources: WeakMap<object, string>;\n mergers: Map<string, { merger: Merger; fromPath: string }>;\n }\n>;\n\n// this is a module-scoped cache. If multiple callers ask _this copy_ of\n// @embroider/macros for a shared MacrosConfig, they'll all get the same one.\n// And if somebody asks a *different* copy of @embroider/macros for the shared\n// MacrosConfig, it will have its own instance with its own code, but will still\n// share the GlobalSharedState beneath.\nlet localSharedState: WeakMap<any, MacrosConfig> = new WeakMap();\n\nfunction gatherAddonCacheKeyWorker(item: any, memo: Set<string>) {\n item.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n}\n\nlet addonCacheKey: WeakMap<any, string> = new WeakMap();\n// creates a string representing all addons and their versions\n// (foo@1.0.0|bar@2.0.0) to use as a cachekey\nfunction gatherAddonCacheKey(project: any): string {\n let cacheKey = addonCacheKey.get(project);\n if (cacheKey) {\n return cacheKey;\n }\n\n let memo: Set<string> = new Set();\n project.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n\n cacheKey = [...memo].join('|');\n addonCacheKey.set(project, cacheKey);\n\n return cacheKey;\n}\n\nexport default class MacrosConfig {\n static for(key: any, appRoot: string): MacrosConfig {\n let found = localSharedState.get(key);\n if (found) {\n return found;\n }\n\n let g = global as any as { __embroider_macros_global__: GlobalSharedState | undefined };\n if (!g.__embroider_macros_global__) {\n g.__embroider_macros_global__ = new WeakMap();\n }\n\n let shared = g.__embroider_macros_global__.get(key);\n if (shared) {\n // if an earlier version of @embroider/macros created the shared state, it\n // would have configSources.\n if (!shared.configSources) {\n shared.configSources = new WeakMap();\n }\n } else {\n shared = {\n configs: new Map(),\n configSources: new WeakMap(),\n mergers: new Map(),\n };\n g.__embroider_macros_global__.set(key, shared);\n }\n\n let config = new MacrosConfig(appRoot);\n config.configs = shared.configs;\n config.configSources = shared.configSources;\n config.mergers = shared.mergers;\n localSharedState.set(key, config);\n return config;\n }\n\n private mode: 'compile-time' | 'run-time' = 'compile-time';\n private globalConfig: { [key: string]: unknown } = {};\n\n private isDevelopingPackageRoots: Set<string> = new Set();\n\n enableRuntimeMode() {\n if (this.mode !== 'run-time') {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableRuntimeMode after configs have been finalized`);\n }\n this.mode = 'run-time';\n }\n }\n\n enablePackageDevelopment(packageRoot: string) {\n if (!this.isDevelopingPackageRoots.has(packageRoot)) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to enablePackageDevelopment after configs have been finalized`\n );\n }\n this.isDevelopingPackageRoots.add(packageRoot);\n }\n }\n\n private _importSyncImplementation: 'cjs' | 'eager' = 'cjs';\n\n get importSyncImplementation() {\n return this._importSyncImplementation;\n }\n\n set importSyncImplementation(value: 'cjs' | 'eager') {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`\n );\n }\n this._importSyncImplementation = value;\n }\n\n private packageCache: PackageCache;\n\n private constructor(private appRoot: string) {\n // this uses globalConfig because these things truly are global. Even if a\n // package doesn't have a dep or peerDep on @embroider/macros, it's legit\n // for them to want to know the answer to these questions, and there is only\n // one answer throughout the whole dependency graph.\n this.globalConfig['@embroider/macros'] = {\n // this powers the `isTesting` macro. It always starts out false here,\n // because:\n // - if this is a production build, we will evaluate all macros at build\n // time and isTesting will stay false, so test-only code will not be\n // included.\n // - if this is a dev build, we evaluate macros at runtime, which allows\n // both \"I'm running my app in development\" and \"I'm running my test\n // suite\" to coexist within a single build. When you run the test\n // suite, early in the runtime boot process we can flip isTesting to\n // true to distinguish the two.\n isTesting: false,\n };\n this.packageCache = PackageCache.shared('embroider-stage3', appRoot);\n }\n\n private _configWritable = true;\n private configs: Map<string, object[]> = new Map();\n private configSources: WeakMap<object, string> = new WeakMap();\n private mergers: Map<string, { merger: Merger; fromPath: string }> = new Map();\n\n // Registers a new source of configuration to be given to the named package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setConfig(fromPath: string, packageName: string, config: object) {\n return this.internalSetConfig(fromPath, packageName, config);\n }\n\n // Registers a new source of configuration to be given to your own package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setOwnConfig(fromPath: string, config: object) {\n return this.internalSetConfig(fromPath, undefined, config);\n }\n\n // Registers a new source of configuration to be shared globally within the\n // app. USE GLOBALS SPARINGLY! Prefer setConfig or setOwnConfig instead,\n // unless your state is truly, necessarily global.\n //\n // Include a relevant package name in your key to help avoid collisions.\n //\n // Your value must be json-serializable. You must always set fromPath to\n // `__filename`.\n setGlobalConfig(fromPath: string, key: string, value: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set global config after configs have been finalized from: '${fromPath}'`\n );\n }\n this.globalConfig[key] = value;\n }\n\n private internalSetConfig(fromPath: string, packageName: string | undefined, config: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set config after configs have been finalized from: '${fromPath}'`\n );\n }\n\n if (!isSerializable(config)) {\n throw new Error(\n `[Embroider:MacrosConfig] the given config from '${fromPath}' for packageName '${packageName}' is not JSON serializable.`\n );\n }\n\n let targetPackage = this.resolvePackage(fromPath, packageName);\n let peers = getOrCreate(this.configs, targetPackage.root, () => []);\n peers.push(config);\n this.configSources.set(config, fromPath);\n }\n\n // Allows you to set the merging strategy used for your package's config. The\n // merging strategy applies when multiple other packages all try to send\n // configuration to you.\n useMerger(fromPath: string, merger: Merger) {\n if (this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call useMerger after configs have been finalized`);\n }\n\n let targetPackage = this.resolvePackage(fromPath, undefined);\n let other = this.mergers.get(targetPackage.root);\n if (other) {\n throw new Error(\n `[Embroider:MacrosConfig] conflicting mergers registered for package ${targetPackage.name} at ${targetPackage.root}. See ${other.fromPath} and ${fromPath}.`\n );\n }\n this.mergers.set(targetPackage.root, { merger, fromPath });\n }\n\n private cachedUserConfigs: { [packageRoot: string]: object } | undefined;\n\n private get userConfigs() {\n if (this._configWritable) {\n throw new Error('[Embroider:MacrosConfig] cannot read userConfigs until MacrosConfig has been finalized.');\n }\n\n if (!this.cachedUserConfigs) {\n let userConfigs: { [packageRoot: string]: object } = {};\n let sourceOfConfig = this.makeConfigSourcer(this.configSources);\n for (let [pkgRoot, configs] of this.configs) {\n let combined: object;\n if (configs.length > 1) {\n combined = this.mergerFor(pkgRoot)(configs, { sourceOfConfig });\n } else {\n combined = configs[0];\n }\n userConfigs[pkgRoot] = combined;\n }\n for (let [oldPath, newPath] of this.moves) {\n userConfigs[newPath] = userConfigs[oldPath];\n }\n this.cachedUserConfigs = userConfigs;\n }\n\n return this.cachedUserConfigs;\n }\n\n private makeConfigSourcer(configSources: WeakMap<object, string>): SourceOfConfig {\n return config => {\n let fromPath = configSources.get(config);\n if (!fromPath) {\n throw new Error(\n `unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`\n );\n }\n let maybePkg = this.packageCache.ownerOfFile(fromPath);\n if (!maybePkg) {\n throw new Error(\n `bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`\n );\n }\n let pkg = maybePkg;\n return {\n get name() {\n return pkg.name;\n },\n get version() {\n return pkg.version;\n },\n get root() {\n return pkg.root;\n },\n };\n };\n }\n\n // to be called from within your build system. Returns the thing you should\n // push into your babel plugins list.\n //\n // owningPackageRoot is needed when the files you will process (1) all belongs\n // to one package, (2) will not be located in globally correct paths such that\n // normal node_modules resolution can find their dependencies. In other words,\n // owningPackageRoot is needed when you use this inside classic ember-cli, and\n // it's not appropriate inside embroider.\n babelPluginConfig(appOrAddonInstance?: any): PluginItem[] {\n let self = this;\n let owningPackageRoot = appOrAddonInstance ? appOrAddonInstance.root || appOrAddonInstance.project.root : null;\n let opts: State['opts'] = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get userConfigs() {\n return self.userConfigs;\n },\n get globalConfig() {\n return self.globalConfig;\n },\n owningPackageRoot,\n\n isDevelopingPackageRoots: [...this.isDevelopingPackageRoots].map(root => this.moves.get(root) || root),\n appPackageRoot: this.moves.get(this.appRoot) ?? this.appRoot,\n\n // This is used as a signature so we can detect ourself among the plugins\n // emitted from v1 addons.\n embroiderMacrosConfigMarker: true,\n\n get mode() {\n return self.mode;\n },\n\n importSyncImplementation: this.importSyncImplementation,\n };\n\n let lockFilePath = findUp.sync(['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'], { cwd: opts.appPackageRoot });\n\n if (!lockFilePath) {\n lockFilePath = findUp.sync('package.json', { cwd: opts.appPackageRoot });\n }\n\n let lockFileBuffer = lockFilePath ? fs.readFileSync(lockFilePath) : 'no-cache-key';\n\n // @embroider/macros provides a macro called dependencySatisfies which checks if a given\n // package name satisfies a given semver version range. Due to the way babel caches this can\n // cause a problem where the macro plugin does not run (because it has been cached) but the version\n // of the dependency being checked for changes (due to installing a different version). This will lead to\n // the old evaluated state being used which might be invalid. This cache busting plugin keeps track of a\n // hash representing the lock file of the app and if it ever changes forces babel to rerun its plugins.\n // more information in issue #906\n let hash = crypto.createHash('sha256');\n hash = hash.update(lockFileBuffer);\n if (appOrAddonInstance) {\n // ensure that the actual running addon names and versions are accounted\n // for in the cache key; this ensures that we still invalidate the cache\n // when linking another project (e.g. ember-source) which would normally\n // not cause the lockfile to change;\n hash = hash.update(gatherAddonCacheKey(appOrAddonInstance.project));\n }\n let cacheKey = hash.digest('hex');\n\n return [\n [join(__dirname, 'babel', 'macros-babel-plugin.js'), opts],\n [\n require.resolve('@embroider/shared-internals/src/babel-plugin-cache-busting.js'),\n { version: cacheKey },\n `@embroider/macros cache buster: ${owningPackageRoot}`,\n ],\n ];\n }\n\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let configs: MacrosConfig | undefined;\n\n let lazyParams = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get configs() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.userConfigs;\n },\n packageRoot: owningPackageRoot,\n get appRoot() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.appRoot;\n },\n };\n\n let plugins = [makeFirstTransform(lazyParams), makeSecondTransform()].reverse();\n function setConfig(c: MacrosConfig) {\n configs = c;\n }\n return { plugins, setConfig, lazyParams };\n }\n\n private mergerFor(pkgRoot: string) {\n let entry = this.mergers.get(pkgRoot);\n if (entry) {\n return entry.merger;\n }\n return defaultMergerFor(pkgRoot);\n }\n\n // this exists because @embroider/compat rewrites and moves v1 addons, and\n // their macro configs need to follow them to their new homes.\n packageMoved(oldPath: string, newPath: string) {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call packageMoved after configs have been finalized`);\n }\n\n this.moves.set(oldPath, newPath);\n }\n\n private moves: Map<string, string> = new Map();\n\n private resolvePackage(fromPath: string, packageName?: string | undefined) {\n let us = this.packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`[Embroider:MacrosConfig] unable to determine which npm package owns the file ${fromPath}`);\n }\n if (packageName) {\n return this.packageCache.resolve(packageName, us);\n } else {\n return us;\n }\n }\n\n finalize() {\n this._configWritable = false;\n }\n}\n\nfunction defaultMergerFor(pkgRoot: string) {\n return function defaultMerger(configs: object[], { sourceOfConfig }: { sourceOfConfig: SourceOfConfig }): object {\n let [ownConfigs, otherConfigs] = partition(configs, c => sourceOfConfig(c as object).root === pkgRoot);\n return Object.assign({}, ...ownConfigs, ...otherConfigs);\n };\n}\n\nfunction isSerializable(obj: object): boolean {\n if (isScalar(obj)) {\n return true;\n }\n\n if (Array.isArray(obj)) {\n return !obj.some((arrayItem: any) => !isSerializable(arrayItem));\n }\n\n if (isPlainObject(obj)) {\n for (let property in obj) {\n let value = obj[property] as any;\n if (!isSerializable(value)) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n\nfunction isScalar(val: any): boolean {\n return (\n typeof val === 'undefined' ||\n typeof val === 'string' ||\n typeof val === 'boolean' ||\n typeof val === 'number' ||\n val === null\n );\n}\n\nfunction isPlainObject(obj: any): obj is Record<string, any> {\n return typeof obj === 'object' && obj.constructor === Object && obj.toString() === '[object Object]';\n}\n"]}
|