@embroider/macros 0.48.0 → 0.50.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/babel/dependency-satisfies.js +4 -6
- package/src/babel/dependency-satisfies.js.map +1 -1
- package/src/babel/get-config.js +1 -3
- package/src/babel/get-config.js.map +1 -1
- package/src/babel/macros-babel-plugin.js +3 -3
- package/src/babel/macros-babel-plugin.js.map +1 -1
- package/src/babel/state.d.ts +2 -1
- package/src/babel/state.js +1 -2
- package/src/babel/state.js.map +1 -1
- package/src/ember-addon-main.js +29 -24
- package/src/ember-addon-main.js.map +1 -1
- package/src/glimmer/ast-transform.d.ts +12 -10
- package/src/glimmer/ast-transform.js +14 -15
- package/src/glimmer/ast-transform.js.map +1 -1
- package/src/glimmer/dependency-satisfies.d.ts +2 -1
- package/src/glimmer/dependency-satisfies.js +2 -4
- package/src/glimmer/dependency-satisfies.js.map +1 -1
- package/src/glimmer/get-config.d.ts +2 -1
- package/src/glimmer/get-config.js +1 -3
- package/src/glimmer/get-config.js.map +1 -1
- package/src/macros-config.d.ts +6 -6
- package/src/macros-config.js +53 -76
- package/src/macros-config.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "jest"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@embroider/shared-internals": "0.
|
|
27
|
+
"@embroider/shared-internals": "0.50.1",
|
|
28
28
|
"assert-never": "^1.2.1",
|
|
29
29
|
"ember-cli-babel": "^7.26.6",
|
|
30
30
|
"find-up": "^5.0.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "^7.14.5",
|
|
37
37
|
"@babel/traverse": "^7.14.5",
|
|
38
|
-
"@embroider/core": "0.
|
|
38
|
+
"@embroider/core": "0.50.1",
|
|
39
39
|
"@embroider/test-support": "0.36.0",
|
|
40
40
|
"@types/babel__core": "^7.1.14",
|
|
41
41
|
"@types/babel__generator": "^7.6.2",
|
|
@@ -5,15 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const state_1 = require("./state");
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
|
-
const shared_internals_1 = require("@embroider/shared-internals");
|
|
9
8
|
const error_1 = __importDefault(require("./error"));
|
|
10
9
|
const evaluate_json_1 = require("./evaluate-json");
|
|
11
|
-
const packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
12
10
|
function dependencySatisfies(path, state) {
|
|
13
11
|
if (path.node.arguments.length !== 2) {
|
|
14
12
|
throw (0, error_1.default)(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);
|
|
15
13
|
}
|
|
16
|
-
|
|
14
|
+
const [packageName, range] = path.node.arguments;
|
|
17
15
|
if (packageName.type !== 'StringLiteral') {
|
|
18
16
|
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the first argument to dependencySatisfies must be a string literal`);
|
|
19
17
|
}
|
|
@@ -22,11 +20,11 @@ function dependencySatisfies(path, state) {
|
|
|
22
20
|
}
|
|
23
21
|
let sourceFileName = (0, state_1.sourceFile)(path, state);
|
|
24
22
|
try {
|
|
25
|
-
let us = packageCache.ownerOfFile(sourceFileName);
|
|
26
|
-
if (!us) {
|
|
23
|
+
let us = state.packageCache.ownerOfFile(sourceFileName);
|
|
24
|
+
if (!us || us.dependencies.every(dep => dep.name !== packageName.value)) {
|
|
27
25
|
return false;
|
|
28
26
|
}
|
|
29
|
-
let version = packageCache.resolve(packageName.value, us).version;
|
|
27
|
+
let version = state.packageCache.resolve(packageName.value, us).version;
|
|
30
28
|
return (0, semver_1.satisfies)(version, range.value, {
|
|
31
29
|
includePrerelease: true,
|
|
32
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAEA,mCAA4C;AAC5C,mCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAEA,mCAA4C;AAC5C,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,cAAc,GAAG,IAAA,kBAAU,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7C,IAAI;QACF,IAAI,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QACxD,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,KAAK,CAAC,EAAE;YACvE,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;AAlCD,sCAkCC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State, { sourceFile } 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 let sourceFileName = sourceFile(path, state);\n try {\n let us = state.packageCache.ownerOfFile(sourceFileName);\n if (!us || us.dependencies.every(dep => dep.name !== 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/get-config.js
CHANGED
|
@@ -5,11 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.inlineRuntimeConfig = exports.insertConfig = void 0;
|
|
7
7
|
const state_1 = require("./state");
|
|
8
|
-
const shared_internals_1 = require("@embroider/shared-internals");
|
|
9
8
|
const error_1 = __importDefault(require("./error"));
|
|
10
9
|
const evaluate_json_1 = require("./evaluate-json");
|
|
11
10
|
const assert_never_1 = __importDefault(require("assert-never"));
|
|
12
|
-
const packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
13
11
|
function getPackage(path, state, mode) {
|
|
14
12
|
let packageName;
|
|
15
13
|
if (mode === 'own') {
|
|
@@ -31,7 +29,7 @@ function getPackage(path, state, mode) {
|
|
|
31
29
|
else {
|
|
32
30
|
(0, assert_never_1.default)(mode);
|
|
33
31
|
}
|
|
34
|
-
return targetPackage((0, state_1.sourceFile)(path, state), packageName, packageCache);
|
|
32
|
+
return targetPackage((0, state_1.sourceFile)(path, state), packageName, state.packageCache);
|
|
35
33
|
}
|
|
36
34
|
// this evaluates to the actual value of the config. It can be used directly by the Evaluator.
|
|
37
35
|
function getConfig(path, state, mode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["get-config.ts"],"names":[],"mappings":";;;;;;AACA,mCAA4D;
|
|
1
|
+
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["get-config.ts"],"names":[],"mappings":";;;;;;AACA,mCAA4D;AAE5D,oDAA4B;AAC5B,mDAAyF;AACzF,gEAAuC;AAMvC,SAAS,UAAU,CAAC,IAAgC,EAAE,KAAY,EAAE,IAAuB;IACzF,IAAI,WAA+B,CAAC;IACpC,IAAI,IAAI,KAAK,KAAK,E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ACH,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;AAED,SAAS,UAAU,CAAC,IAAgC,EAAE,OAAqB;IACzE,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC9B,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC;KACpB;IACD,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport State, { sourceFile, unusedNameLike } 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(sourceFile(path, state), 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 state.neededRuntimeImports.set(calleeName(path, context), '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 let name = unusedNameLike('config', path);\n path.replaceWith(context.types.callExpression(context.types.identifier(name), [pkgRoot]));\n state.neededRuntimeImports.set(name, 'config');\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\nfunction calleeName(path: NodePath<t.CallExpression>, context: typeof Babel): string {\n let callee = path.node.callee;\n if (context.types.isIdentifier(callee)) {\n return callee.name;\n }\n throw new Error(`bug: our macros should only be invoked as identifiers`);\n}\n"]}
|
|
@@ -30,7 +30,6 @@ const each_1 = require("./each");
|
|
|
30
30
|
const error_1 = __importDefault(require("./error"));
|
|
31
31
|
const fail_build_1 = __importDefault(require("./fail-build"));
|
|
32
32
|
const evaluate_json_1 = require("./evaluate-json");
|
|
33
|
-
const packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
34
33
|
function main(context) {
|
|
35
34
|
let t = context.types;
|
|
36
35
|
let visitor = {
|
|
@@ -42,6 +41,7 @@ function main(context) {
|
|
|
42
41
|
state.calledIdentifiers = new Set();
|
|
43
42
|
state.neededRuntimeImports = new Map();
|
|
44
43
|
state.neededEagerImports = new Map();
|
|
44
|
+
state.packageCache = shared_internals_1.PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);
|
|
45
45
|
},
|
|
46
46
|
exit(path, state) {
|
|
47
47
|
pruneMacroImports(path);
|
|
@@ -72,7 +72,7 @@ function main(context) {
|
|
|
72
72
|
enter(path, state) {
|
|
73
73
|
let id = path.get('id');
|
|
74
74
|
if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {
|
|
75
|
-
let pkg = packageCache.ownerOfFile((0, state_1.sourceFile)(path, state));
|
|
75
|
+
let pkg = state.packageCache.ownerOfFile((0, state_1.sourceFile)(path, state));
|
|
76
76
|
if (pkg && pkg.name === '@embroider/macros') {
|
|
77
77
|
(0, get_config_1.inlineRuntimeConfig)(path, state, context);
|
|
78
78
|
}
|
|
@@ -259,7 +259,7 @@ function addEagerImports(path, state, t) {
|
|
|
259
259
|
}
|
|
260
260
|
function ownedByEmberPackage(path, state) {
|
|
261
261
|
let filename = (0, state_1.sourceFile)(path, state);
|
|
262
|
-
let pkg = packageCache.ownerOfFile(filename);
|
|
262
|
+
let pkg = state.packageCache.ownerOfFile(filename);
|
|
263
263
|
return pkg && pkg.isEmberPackage();
|
|
264
264
|
}
|
|
265
265
|
function unusedNameLike(name, paths, banned) {
|
|
@@ -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,MAAM,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE7D,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;YACvC,CAAC;YACD,IAAI,CAAC,IAAyB,EAAE,KAAY;gBAC1C,iBAAiB,CAAC,IAAI,CAAC,CAA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AAC,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\nconst packageCache = PackageCache.shared('embroider-stage3');\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 },\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 = 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 = 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,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,MA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CAAC,CAAC;IACvC,IAAI,GAAG,GAAG,KAAK,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"]}
|
package/src/babel/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodePath, Node } from '@babel/traverse';
|
|
2
|
-
import { Package } from '@embroider/shared-internals';
|
|
2
|
+
import { Package, PackageCache } from '@embroider/shared-internals';
|
|
3
3
|
export default interface State {
|
|
4
4
|
generatedRequires: Set<Node>;
|
|
5
5
|
removed: Set<Node>;
|
|
@@ -7,6 +7,7 @@ export default interface State {
|
|
|
7
7
|
jobs: (() => void)[];
|
|
8
8
|
neededRuntimeImports: Map<string, string>;
|
|
9
9
|
neededEagerImports: Map<string, NodePath[]>;
|
|
10
|
+
packageCache: PackageCache;
|
|
10
11
|
opts: {
|
|
11
12
|
userConfigs: {
|
|
12
13
|
[pkgRoot: string]: unknown;
|
package/src/babel/state.js
CHANGED
|
@@ -32,10 +32,9 @@ function sourceFile(path, state) {
|
|
|
32
32
|
return state.opts.owningPackageRoot || path.hub.file.opts.filename;
|
|
33
33
|
}
|
|
34
34
|
exports.sourceFile = sourceFile;
|
|
35
|
-
const packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
36
35
|
function owningPackage(path, state) {
|
|
37
36
|
let file = sourceFile(path, state);
|
|
38
|
-
let pkg = packageCache.ownerOfFile(file);
|
|
37
|
+
let pkg = state.packageCache.ownerOfFile(file);
|
|
39
38
|
if (!pkg) {
|
|
40
39
|
throw new Error(`unable to determine which npm package owns the file ${file}`);
|
|
41
40
|
}
|
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;AAkDtF,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAEvE,SAAgB,aAAa,CAAC,IAAc,EAAE,KAAY;IACxD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE;QACjC,kEAAkE;QAClE,IAAI,MAAM,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,IAAA,mCAAgB,EAAC,IAAA,cAAO,EAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;KACvD;SAAM;QACL,sEAAsE;QACtE,aAAa;QACb,EAAE;QACF,qEAAqE;QACrE,yEAAyE;QACzE,4EAA4E;QAC5E,0EAA0E;QAC1E,eAAe;QACf,OAAO,2BAA2B,CAAC;KACpC;AACH,CAAC;AAhBD,sCAgBC;AAED,SAAgB,UAAU,CAAC,IAAc,EAAE,KAAY;IACrD,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;AACrE,CAAC;AAFD,gCAEC;AAED,SAAgB,aAAa,CAAC,IAAc,EAAE,KAAY;IACxD,IAAI,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACnC,IAAI,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,EAAE,CAAC,CAAC;KAChF;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAPD,sCAOC;AAED,SAAgB,SAAS,CAAC,IAAU,EAAE,KAAY;IAChD,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;AARD,8BAQC;AAED,SAAgB,cAAc,CAAC,IAAY,EAAE,IAAuB;IAClE,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QACvC,SAAS,GAAG,GAAG,IAAI,GAAG,OAAO,EAAE,EAAE,CAAC;KACnC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAPD,wCAOC","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';\n\nexport default interface State {\n generatedRequires: Set<Node>;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n\n // map from local name to imported name from @embroider/macros own runtime\n // implementations.\n neededRuntimeImports: Map<string, string>;\n\n // when we're running with importSync's eager implementation, this maps from\n // module specifier to the set of nodes that should be replaced with the\n // module value.\n neededEagerImports: Map<string, NodePath[]>;\n\n packageCache: PackageCache;\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\nconst runtimePath = resolve(join(__dirname, '..', 'addon', 'runtime'));\n\nexport function pathToRuntime(path: NodePath, state: State): string {\n if (!state.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n let source = sourceFile(path, state);\n return explicitRelative(dirname(source), runtimePath);\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/runtime';\n }\n}\n\nexport function sourceFile(path: NodePath, state: State): string {\n return state.opts.owningPackageRoot || path.hub.file.opts.filename;\n}\n\nexport function owningPackage(path: NodePath, state: State): Package {\n let file = sourceFile(path, state);\n let pkg = state.packageCache.ownerOfFile(file);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${file}`);\n }\n return pkg;\n}\n\nexport function cloneDeep(node: Node, state: State): Node {\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\nexport function unusedNameLike(name: string, path: NodePath<unknown>) {\n let candidate = name;\n let counter = 0;\n while (path.scope.getBinding(candidate)) {\n candidate = `${name}${counter++}`;\n }\n return candidate;\n}\n"]}
|
package/src/ember-addon-main.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path_1 = require("path");
|
|
3
3
|
const node_1 = require("./node");
|
|
4
|
+
// this can differ from appInstance.project.root because Dummy apps are terrible
|
|
5
|
+
function getAppRoot(appInstance) {
|
|
6
|
+
return (0, path_1.join)(appInstance.project.configPath(), '..', '..');
|
|
7
|
+
}
|
|
8
|
+
function getMacrosConfig(appInstance) {
|
|
9
|
+
let appRoot = (0, path_1.join)(appInstance.project.configPath(), '..', '..');
|
|
10
|
+
return node_1.MacrosConfig.for(appInstance, appRoot);
|
|
11
|
+
}
|
|
4
12
|
module.exports = {
|
|
5
13
|
name: '@embroider/macros',
|
|
6
14
|
included(parent) {
|
|
@@ -8,28 +16,28 @@ module.exports = {
|
|
|
8
16
|
this.options.babel = { plugins: [] };
|
|
9
17
|
let parentOptions = (parent.options = parent.options || {});
|
|
10
18
|
let ownOptions = (parentOptions['@embroider/macros'] = parentOptions['@embroider/macros'] || {});
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
let appInstance = this._findHost();
|
|
20
|
+
let macrosConfig = getMacrosConfig(appInstance);
|
|
21
|
+
this.setMacrosConfig(macrosConfig);
|
|
13
22
|
// if parent is an addon it has root. If it's an app it has project.root.
|
|
14
23
|
let source = parent.root || parent.project.root;
|
|
15
24
|
if (ownOptions.setOwnConfig) {
|
|
16
|
-
|
|
25
|
+
macrosConfig.setOwnConfig(source, ownOptions.setOwnConfig);
|
|
17
26
|
}
|
|
18
27
|
if (ownOptions.setConfig) {
|
|
19
28
|
for (let [packageName, config] of Object.entries(ownOptions.setConfig)) {
|
|
20
|
-
|
|
29
|
+
macrosConfig.setConfig(source, packageName, config);
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
if (appInstance.env !== 'production') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
macros.enableAppDevelopment((0, path_1.join)(appInstance.project.configPath(), '..', '..'));
|
|
33
|
+
// tell the macros our app is under development
|
|
34
|
+
macrosConfig.enablePackageDevelopment(getAppRoot(appInstance));
|
|
27
35
|
// also tell them our root project is under development. This can be
|
|
28
36
|
// different, in the case where this is an addon and the app is the dummy
|
|
29
37
|
// app.
|
|
30
|
-
|
|
38
|
+
macrosConfig.enablePackageDevelopment(appInstance.project.root);
|
|
31
39
|
// keep the macros in runtime mode for development & testing
|
|
32
|
-
|
|
40
|
+
macrosConfig.enableRuntimeMode();
|
|
33
41
|
}
|
|
34
42
|
// add our babel plugin to our parent's babel
|
|
35
43
|
this.installBabelPlugin(parent);
|
|
@@ -43,9 +51,9 @@ module.exports = {
|
|
|
43
51
|
// forbidden and consuming it becomes allowed. There's no existing hook with
|
|
44
52
|
// that timing.
|
|
45
53
|
const originalToTree = appInstance.toTree;
|
|
46
|
-
appInstance.toTree = function () {
|
|
47
|
-
|
|
48
|
-
return originalToTree.apply(appInstance,
|
|
54
|
+
appInstance.toTree = function (...args) {
|
|
55
|
+
macrosConfig.finalize();
|
|
56
|
+
return originalToTree.apply(appInstance, args);
|
|
49
57
|
};
|
|
50
58
|
},
|
|
51
59
|
// Other addons are allowed to call this. It's needed if an addon needs to
|
|
@@ -59,7 +67,7 @@ module.exports = {
|
|
|
59
67
|
let babelPlugins = (babelOptions.plugins = babelOptions.plugins || []);
|
|
60
68
|
if (!babelPlugins.some(node_1.isEmbroiderMacrosPlugin)) {
|
|
61
69
|
let appInstance = this._findHost();
|
|
62
|
-
babelPlugins.unshift(...
|
|
70
|
+
babelPlugins.unshift(...getMacrosConfig(appInstance).babelPluginConfig(appOrAddonInstance));
|
|
63
71
|
}
|
|
64
72
|
},
|
|
65
73
|
setupPreprocessorRegistry(type, registry) {
|
|
@@ -71,27 +79,24 @@ module.exports = {
|
|
|
71
79
|
// MacrosConfig.astPlugins is static because in classic ember-cli, at this
|
|
72
80
|
// point there's not yet an appInstance, so we defer getting it and
|
|
73
81
|
// calling setConfig until our included hook.
|
|
74
|
-
let { plugins, setConfig,
|
|
82
|
+
let { plugins, setConfig, lazyParams } = node_1.MacrosConfig.astPlugins(this.parent.root);
|
|
75
83
|
this.setMacrosConfig = setConfig;
|
|
76
84
|
plugins.forEach((plugin, index) => {
|
|
77
85
|
let name = `@embroider/macros/${index}`;
|
|
78
86
|
let baseDir = (0, path_1.join)(__dirname, '..');
|
|
79
|
-
let
|
|
87
|
+
let params = {
|
|
88
|
+
name,
|
|
89
|
+
firstTransformParams: lazyParams,
|
|
90
|
+
methodName: index === 0 ? 'makeSecondTransform' : 'makeFirstTransform',
|
|
91
|
+
baseDir,
|
|
92
|
+
};
|
|
80
93
|
registry.add('htmlbars-ast-plugin', {
|
|
81
94
|
name,
|
|
82
95
|
plugin,
|
|
83
96
|
parallelBabel: {
|
|
84
97
|
requireFile: (0, path_1.join)(__dirname, 'glimmer', 'ast-transform.js'),
|
|
85
98
|
buildUsing: 'buildPlugin',
|
|
86
|
-
params
|
|
87
|
-
name,
|
|
88
|
-
get configs() {
|
|
89
|
-
return getConfigForPlugin();
|
|
90
|
-
},
|
|
91
|
-
methodName: index === 0 ? 'makeSecondTransform' : 'makeFirstTransform',
|
|
92
|
-
projectRoot: projectRoot,
|
|
93
|
-
baseDir,
|
|
94
|
-
},
|
|
99
|
+
params,
|
|
95
100
|
},
|
|
96
101
|
baseDir: () => baseDir,
|
|
97
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ember-addon-main.js","sourceRoot":"","sources":["ember-addon-main.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ember-addon-main.js","sourceRoot":"","sources":["ember-addon-main.ts"],"names":[],"mappings":";AACA,+BAA4B;AAE5B,iCAA+D;AAiH/D,gFAAgF;AAChF,SAAS,UAAU,CAAC,WAAwB;IAC1C,OAAO,IAAA,WAAI,EAAC,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,eAAe,CAAC,WAAwB;IAC/C,IAAI,OAAO,GAAG,IAAA,WAAI,EAAC,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACjE,OAAO,mBAAY,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAvHD,iBAAS;IACP,IAAI,EAAE,mBAAmB;IACzB,QAAQ,CAAY,MAAW;QAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QACrC,IAAI,aAAa,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAI,UAAU,GAAG,CAAC,aAAa,CAAC,mBAAmB,CAAC,GAAG,aAAa,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;QAEjG,IAAI,WAAW,GAAgB,IAAI,CAAC,SAAS,EAAE,CAAC;QAChD,IAAI,YAAY,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;QAChD,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAEnC,yEAAyE;QACzE,IAAI,MAAM,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,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,oBAAoB;oBACtE,OAAO;iBACR,CAAC;gBAEF,QAAQ,CAAC,GAAG,CAAC,qBAAqB,EAAE;oBAClC,IAAI;oBACJ,MAAM;oBACN,aAAa,EAAE;wBACb,WAAW,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,CAAC;wBAC3D,UAAU,EAAE,aAAa;wBACzB,MAAM;qBACP;oBACD,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;iBACvB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,OAAO,EAAE,EAAE;CACZ,CAAC","sourcesContent":["import { AppInstance } from '@embroider/shared-internals';\nimport { join } from 'path';\nimport { BuildPluginParams } from './glimmer/ast-transform';\nimport { MacrosConfig, isEmbroiderMacrosPlugin } from './node';\n\nexport = {\n name: '@embroider/macros',\n included(this: any, parent: any) {\n this._super.included.apply(this, arguments);\n this.options.babel = { plugins: [] };\n let parentOptions = (parent.options = parent.options || {});\n let ownOptions = (parentOptions['@embroider/macros'] = parentOptions['@embroider/macros'] || {});\n\n let appInstance: AppInstance = this._findHost();\n let macrosConfig = getMacrosConfig(appInstance);\n this.setMacrosConfig(macrosConfig);\n\n // if parent is an addon it has root. If it's an app it has project.root.\n let source = parent.root || parent.project.root;\n\n if (ownOptions.setOwnConfig) {\n macrosConfig.setOwnConfig(source, ownOptions.setOwnConfig);\n }\n\n if (ownOptions.setConfig) {\n for (let [packageName, config] of Object.entries(ownOptions.setConfig)) {\n macrosConfig.setConfig(source, packageName, config as object);\n }\n }\n\n if (appInstance.env !== 'production') {\n // tell the macros our app is under development\n macrosConfig.enablePackageDevelopment(getAppRoot(appInstance));\n // also tell them our root project is under development. This can be\n // different, in the case where this is an addon and the app is the dummy\n // app.\n macrosConfig.enablePackageDevelopment(appInstance.project.root);\n // keep the macros in runtime mode for development & testing\n macrosConfig.enableRuntimeMode();\n }\n\n // add our babel plugin to our parent's babel\n this.installBabelPlugin(parent);\n\n // and to our own babel, because we may need to inline runtime config into\n // our source code\n this.installBabelPlugin(this);\n\n appInstance.import('vendor/embroider-macros-test-support.js', { type: 'test' });\n\n // When we're used inside the traditional ember-cli build pipeline without\n // Embroider, we unfortunately need to hook into here uncleanly because we\n // need to delineate the point in time after which writing macro config is\n // forbidden and consuming it becomes allowed. There's no existing hook with\n // that timing.\n const originalToTree = appInstance.toTree;\n appInstance.toTree = function (...args) {\n macrosConfig.finalize();\n return originalToTree.apply(appInstance, args);\n };\n },\n\n // Other addons are allowed to call this. It's needed if an addon needs to\n // emit code containing macros into that addon's parent (via a babel plugin,\n // for exmple). This is only an issue in classic builds, under embroider all\n // babel plugins should be thought of as *language extensions* that are\n // available everywhere, we don't scope them so narrowly so this probably\n // doesn't come up.\n installBabelPlugin(this: any, appOrAddonInstance: any) {\n let babelOptions = (appOrAddonInstance.options.babel = appOrAddonInstance.options.babel || {});\n let babelPlugins = (babelOptions.plugins = babelOptions.plugins || []);\n if (!babelPlugins.some(isEmbroiderMacrosPlugin)) {\n let appInstance = this._findHost();\n babelPlugins.unshift(...getMacrosConfig(appInstance).babelPluginConfig(appOrAddonInstance));\n }\n },\n\n setupPreprocessorRegistry(this: any, type: 'parent' | 'self', registry: any) {\n if (type === 'parent') {\n // the htmlbars-ast-plugins are split into two parts because order is\n // important. Weirdly, they appear to run in the reverse order that you\n // register them here.\n //\n // MacrosConfig.astPlugins is static because in classic ember-cli, at this\n // point there's not yet an appInstance, so we defer getting it and\n // calling setConfig until our included hook.\n let { plugins, setConfig, lazyParams } = MacrosConfig.astPlugins((this as any).parent.root);\n this.setMacrosConfig = setConfig;\n plugins.forEach((plugin, index) => {\n let name = `@embroider/macros/${index}`;\n let baseDir = join(__dirname, '..');\n\n let params: BuildPluginParams = {\n name,\n firstTransformParams: lazyParams,\n methodName: index === 0 ? 'makeSecondTransform' : 'makeFirstTransform',\n baseDir,\n };\n\n registry.add('htmlbars-ast-plugin', {\n name,\n plugin,\n parallelBabel: {\n requireFile: join(__dirname, 'glimmer', 'ast-transform.js'),\n buildUsing: 'buildPlugin',\n params,\n },\n baseDir: () => baseDir,\n });\n });\n }\n },\n\n options: {},\n};\n\n// this can differ from appInstance.project.root because Dummy apps are terrible\nfunction getAppRoot(appInstance: AppInstance): string {\n return join(appInstance.project.configPath(), '..', '..');\n}\n\nfunction getMacrosConfig(appInstance: AppInstance): MacrosConfig {\n let appRoot = join(appInstance.project.configPath(), '..', '..');\n return MacrosConfig.for(appInstance, appRoot);\n}\n"]}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface BuildPluginParams {
|
|
2
2
|
name: string;
|
|
3
3
|
baseDir: string;
|
|
4
|
-
projectRoot: string;
|
|
5
4
|
methodName: string;
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
firstTransformParams: FirstTransformParams;
|
|
6
|
+
}
|
|
7
|
+
export interface FirstTransformParams {
|
|
8
|
+
packageRoot: string | undefined;
|
|
9
|
+
appRoot: string;
|
|
10
|
+
configs: {
|
|
11
|
+
[packageRoot: string]: object;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function buildPlugin(params: BuildPluginParams): {
|
|
8
15
|
name: string;
|
|
9
16
|
plugin: (env: {
|
|
10
17
|
syntax: {
|
|
@@ -27,12 +34,7 @@ export declare function buildPlugin(params: {
|
|
|
27
34
|
};
|
|
28
35
|
baseDir: () => string;
|
|
29
36
|
};
|
|
30
|
-
export declare function makeFirstTransform(opts: {
|
|
31
|
-
userConfigs: {
|
|
32
|
-
[packageRoot: string]: unknown;
|
|
33
|
-
};
|
|
34
|
-
baseDir?: string;
|
|
35
|
-
}): (env: {
|
|
37
|
+
export declare function makeFirstTransform(opts: FirstTransformParams): (env: {
|
|
36
38
|
syntax: {
|
|
37
39
|
builders: any;
|
|
38
40
|
};
|
|
@@ -10,11 +10,12 @@ const dependency_satisfies_1 = __importDefault(require("./dependency-satisfies")
|
|
|
10
10
|
const macro_maybe_attrs_1 = require("./macro-maybe-attrs");
|
|
11
11
|
const macro_condition_1 = require("./macro-condition");
|
|
12
12
|
const fail_build_1 = require("./fail-build");
|
|
13
|
+
const shared_internals_1 = require("@embroider/shared-internals");
|
|
13
14
|
function buildPlugin(params) {
|
|
14
15
|
return {
|
|
15
16
|
name: params.name,
|
|
16
17
|
plugin: params.methodName === 'makeFirstTransform'
|
|
17
|
-
? makeFirstTransform(
|
|
18
|
+
? makeFirstTransform(params.firstTransformParams)
|
|
18
19
|
: makeSecondTransform(),
|
|
19
20
|
baseDir: () => params.baseDir,
|
|
20
21
|
};
|
|
@@ -22,13 +23,14 @@ function buildPlugin(params) {
|
|
|
22
23
|
exports.buildPlugin = buildPlugin;
|
|
23
24
|
function makeFirstTransform(opts) {
|
|
24
25
|
function embroiderFirstMacrosTransform(env) {
|
|
25
|
-
if (!opts.
|
|
26
|
-
throw new Error(`bug in @embroider/macros. Running without
|
|
26
|
+
if (!opts.packageRoot && !env.filename) {
|
|
27
|
+
throw new Error(`bug in @embroider/macros. Running without packageRoot but don't have filename.`);
|
|
27
28
|
}
|
|
29
|
+
let packageCache = shared_internals_1.PackageCache.shared('embroider-stage3', opts.appRoot);
|
|
28
30
|
let scopeStack = [];
|
|
29
|
-
//
|
|
31
|
+
// packageRoot is set when we run inside classic ember-cli. Otherwise we're in
|
|
30
32
|
// Embroider, where we can use absolute filenames.
|
|
31
|
-
const moduleName = opts.
|
|
33
|
+
const moduleName = opts.packageRoot ? env.meta.moduleName : env.filename;
|
|
32
34
|
return {
|
|
33
35
|
name: '@embroider/macros/first',
|
|
34
36
|
visitor: {
|
|
@@ -52,13 +54,13 @@ function makeFirstTransform(opts) {
|
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
56
|
if (node.path.original === 'macroGetOwnConfig') {
|
|
55
|
-
return (0, literal_1.default)((0, get_config_1.default)(node, opts.
|
|
57
|
+
return (0, literal_1.default)((0, get_config_1.default)(node, opts.configs, opts.packageRoot, moduleName, true, packageCache), env.syntax.builders);
|
|
56
58
|
}
|
|
57
59
|
if (node.path.original === 'macroGetConfig') {
|
|
58
|
-
return (0, literal_1.default)((0, get_config_1.default)(node, opts.
|
|
60
|
+
return (0, literal_1.default)((0, get_config_1.default)(node, opts.configs, opts.packageRoot, moduleName, false, packageCache), env.syntax.builders);
|
|
59
61
|
}
|
|
60
62
|
if (node.path.original === 'macroDependencySatisfies') {
|
|
61
|
-
return (0, literal_1.default)((0, dependency_satisfies_1.default)(node, opts.
|
|
63
|
+
return (0, literal_1.default)((0, dependency_satisfies_1.default)(node, opts.packageRoot, moduleName, packageCache), env.syntax.builders);
|
|
62
64
|
}
|
|
63
65
|
},
|
|
64
66
|
MustacheStatement(node) {
|
|
@@ -69,13 +71,13 @@ function makeFirstTransform(opts) {
|
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
71
73
|
if (node.path.original === 'macroGetOwnConfig') {
|
|
72
|
-
return env.syntax.builders.mustache((0, literal_1.default)((0, get_config_1.default)(node, opts.
|
|
74
|
+
return env.syntax.builders.mustache((0, literal_1.default)((0, get_config_1.default)(node, opts.configs, opts.packageRoot, moduleName, true, packageCache), env.syntax.builders));
|
|
73
75
|
}
|
|
74
76
|
if (node.path.original === 'macroGetConfig') {
|
|
75
|
-
return env.syntax.builders.mustache((0, literal_1.default)((0, get_config_1.default)(node, opts.
|
|
77
|
+
return env.syntax.builders.mustache((0, literal_1.default)((0, get_config_1.default)(node, opts.configs, opts.packageRoot, moduleName, false, packageCache), env.syntax.builders));
|
|
76
78
|
}
|
|
77
79
|
if (node.path.original === 'macroDependencySatisfies') {
|
|
78
|
-
return env.syntax.builders.mustache((0, literal_1.default)((0, dependency_satisfies_1.default)(node, opts.
|
|
80
|
+
return env.syntax.builders.mustache((0, literal_1.default)((0, dependency_satisfies_1.default)(node, opts.packageRoot, moduleName, packageCache), env.syntax.builders));
|
|
79
81
|
}
|
|
80
82
|
},
|
|
81
83
|
},
|
|
@@ -86,10 +88,7 @@ function makeFirstTransform(opts) {
|
|
|
86
88
|
requireFile: __filename,
|
|
87
89
|
buildUsing: 'makeFirstTransform',
|
|
88
90
|
get params() {
|
|
89
|
-
return
|
|
90
|
-
userConfigs: opts.userConfigs,
|
|
91
|
-
baseDir: opts.baseDir,
|
|
92
|
-
};
|
|
91
|
+
return opts;
|
|
93
92
|
},
|
|
94
93
|
};
|
|
95
94
|
return embroiderFirstMacrosTransform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-transform.js","sourceRoot":"","sources":["ast-transform.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,8DAAqC;AACrC,kFAAyD;AACzD,2DAAiD;AACjD,uDAAqF;AACrF,6CAAyC;AAEzC,SAAgB,WAAW,CAAC,MAM3B;IACC,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EACJ,MAAM,CAAC,UAAU,KAAK,oBAAoB;YACxC,CAAC,CAAC,kBAAkB,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;YAClF,CAAC,CAAC,mBAAmB,EAAE;QAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC;AAfD,kCAeC;AAED,SAAgB,kBAAkB,CAAC,IAA2E;IAC5G,SAAS,6BAA6B,CAAC,GAItC;QACC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;SAC/F;QAED,IAAI,UAAU,GAAe,EAAE,CAAC;QAEhC,0EAA0E;QAC1E,kDAAkD;QAClD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,G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AAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import literal from './literal';\nimport getConfig from './get-config';\nimport dependencySatisfies from './dependency-satisfies';\nimport { maybeAttrs } from './macro-maybe-attrs';\nimport { macroIfBlock, macroIfExpression, macroIfMustache } from './macro-condition';\nimport { failBuild } from './fail-build';\n\nexport function buildPlugin(params: {\n name: string;\n baseDir: string;\n projectRoot: string;\n methodName: string;\n configs: any;\n}) {\n return {\n name: params.name,\n plugin:\n params.methodName === 'makeFirstTransform'\n ? makeFirstTransform({ userConfigs: params.configs, baseDir: params.projectRoot })\n : makeSecondTransform(),\n baseDir: () => params.baseDir,\n };\n}\n\nexport function makeFirstTransform(opts: { userConfigs: { [packageRoot: string]: unknown }; baseDir?: string }) {\n function embroiderFirstMacrosTransform(env: {\n syntax: { builders: any };\n meta: { moduleName: string };\n filename: string;\n }) {\n if (!opts.baseDir && !env.filename) {\n throw new Error(`bug in @embroider/macros. Running without baseDir but don't have filename.`);\n }\n\n let scopeStack: string[][] = [];\n\n // baseDir is set when we run inside classic ember-cli. Otherwise we're in\n // Embroider, where we can use absolute filenames.\n const moduleName = opts.baseDir ? env.meta.moduleName : env.filename;\n\n return {\n name: '@embroider/macros/first',\n\n visitor: {\n Program: {\n enter(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.push(node.blockParams);\n }\n },\n exit(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.pop();\n }\n },\n },\n SubExpression(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'macroGetOwnConfig') {\n return literal(getConfig(node, opts.userConfigs, opts.baseDir, moduleName, true), env.syntax.builders);\n }\n if (node.path.original === 'macroGetConfig') {\n return literal(getConfig(node, opts.userConfigs, opts.baseDir, moduleName, false), env.syntax.builders);\n }\n if (node.path.original === 'macroDependencySatisfies') {\n return literal(dependencySatisfies(node, opts.baseDir, moduleName), env.syntax.builders);\n }\n },\n MustacheStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'macroGetOwnConfig') {\n return env.syntax.builders.mustache(\n literal(getConfig(node, opts.userConfigs, opts.baseDir, moduleName, true), env.syntax.builders)\n );\n }\n if (node.path.original === 'macroGetConfig') {\n return env.syntax.builders.mustache(\n literal(getConfig(node, opts.userConfigs, opts.baseDir, moduleName, false), env.syntax.builders)\n );\n }\n if (node.path.original === 'macroDependencySatisfies') {\n return env.syntax.builders.mustache(\n literal(dependencySatisfies(node, opts.baseDir, moduleName), env.syntax.builders)\n );\n }\n },\n },\n };\n }\n (embroiderFirstMacrosTransform as any).embroiderMacrosASTMarker = true;\n (embroiderFirstMacrosTransform as any).parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeFirstTransform',\n get params() {\n return {\n userConfigs: opts.userConfigs,\n baseDir: opts.baseDir,\n };\n },\n };\n return embroiderFirstMacrosTransform;\n}\n\nexport function makeSecondTransform() {\n function embroiderSecondMacrosTransform(env: { syntax: { builders: any } }) {\n let scopeStack: string[][] = [];\n return {\n name: '@embroider/macros/second',\n\n visitor: {\n Program: {\n enter(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.push(node.blockParams);\n }\n },\n exit(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.pop();\n }\n },\n },\n BlockStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfBlock(node);\n }\n },\n SubExpression(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfExpression(node, env.syntax.builders);\n }\n if (node.path.original === 'macroFailBuild') {\n failBuild(node);\n }\n },\n ElementNode(node: any) {\n node.modifiers = node.modifiers.filter((modifier: any) => {\n if (\n modifier.path.type === 'SubExpression' &&\n modifier.path.path.type === 'PathExpression' &&\n modifier.path.path.original === 'if'\n ) {\n modifier.path = macroIfExpression(modifier.path, env.syntax.builders);\n if (modifier.path.type === 'UndefinedLiteral') {\n return false;\n }\n }\n if (modifier.path.type !== 'PathExpression') {\n return true;\n }\n if (inScope(scopeStack, modifier.path.parts[0])) {\n return true;\n }\n if (modifier.path.original === 'macroMaybeAttrs') {\n maybeAttrs(node, modifier, env.syntax.builders);\n } else {\n return true;\n }\n });\n },\n MustacheStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfMustache(node, env.syntax.builders);\n }\n if (node.path.original === 'macroFailBuild') {\n failBuild(node);\n }\n },\n },\n };\n }\n (embroiderSecondMacrosTransform as any).embroiderMacrosASTMarker = true;\n (embroiderSecondMacrosTransform as any).parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeSecondTransform',\n params: undefined,\n };\n return embroiderSecondMacrosTransform;\n}\n\nfunction inScope(scopeStack: string[][], name: string) {\n for (let scope of scopeStack) {\n if (scope.includes(name)) {\n return true;\n }\n }\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ast-transform.js","sourceRoot":"","sources":["ast-transform.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,8DAAqC;AACrC,kFAAyD;AACzD,2DAAiD;AACjD,uDAAqF;AACrF,6CAAyC;AACzC,kEAA2D;AA4B3D,SAAgB,WAAW,CAAC,MAAyB;IACnD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EACJ,MAAM,CAAC,UAAU,KAAK,oBAAoB;YACxC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,oBAAoB,CAAC;YACjD,CAAC,CAAC,mBAAmB,EAAE;QAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC;AATD,kCASC;AA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CAAC,CAAC;qBACjB;gBACH,CAAC;aACF;SACF,CAAC;IACJ,CAAC;IACA,8BAAsC,CAAC,wBAAwB,GAAG,IAAI,CAAC;IACvE,8BAAsC,CAAC,aAAa,GAAG;QACtD,WAAW,EAAE,UAAU;QACvB,UAAU,EAAE,qBAAqB;QACjC,MAAM,EAAE,SAAS;KAClB,CAAC;IACF,OAAO,8BAA8B,CAAC;AACxC,CAAC;AA7FD,kDA6FC;AAED,SAAS,OAAO,CAAC,UAAsB,EAAE,IAAY;IACnD,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QAC5B,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import literal from './literal';\nimport getConfig from './get-config';\nimport dependencySatisfies from './dependency-satisfies';\nimport { maybeAttrs } from './macro-maybe-attrs';\nimport { macroIfBlock, macroIfExpression, macroIfMustache } from './macro-condition';\nimport { failBuild } from './fail-build';\nimport { PackageCache } from '@embroider/shared-internals';\n\nexport interface BuildPluginParams {\n // Glimmer requires this on ast transforms.\n name: string;\n\n // this is the location of @embroider/macros itself. Glimmer requires this on\n // ast transforms.\n baseDir: string;\n\n methodName: string;\n\n firstTransformParams: FirstTransformParams;\n}\n\nexport interface FirstTransformParams {\n // this is the location of the particular package (app or addon) that is\n // depending on @embroider/macros *if* we're in a classic build. Under\n // embroider the build is global and there's no single packageRoot.\n packageRoot: string | undefined;\n\n // this is the path to the topmost package\n appRoot: string;\n\n // this holds all the actual user configs that were sent into the macros\n configs: { [packageRoot: string]: object };\n}\n\nexport function buildPlugin(params: BuildPluginParams) {\n return {\n name: params.name,\n plugin:\n params.methodName === 'makeFirstTransform'\n ? makeFirstTransform(params.firstTransformParams)\n : makeSecondTransform(),\n baseDir: () => params.baseDir,\n };\n}\n\nexport function makeFirstTransform(opts: FirstTransformParams) {\n function embroiderFirstMacrosTransform(env: {\n syntax: { builders: any };\n meta: { moduleName: string };\n filename: string;\n }) {\n if (!opts.packageRoot && !env.filename) {\n throw new Error(`bug in @embroider/macros. Running without packageRoot but don't have filename.`);\n }\n\n let packageCache = PackageCache.shared('embroider-stage3', opts.appRoot);\n\n let scopeStack: string[][] = [];\n\n // packageRoot is set when we run inside classic ember-cli. Otherwise we're in\n // Embroider, where we can use absolute filenames.\n const moduleName = opts.packageRoot ? env.meta.moduleName : env.filename;\n\n return {\n name: '@embroider/macros/first',\n\n visitor: {\n Program: {\n enter(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.push(node.blockParams);\n }\n },\n exit(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.pop();\n }\n },\n },\n SubExpression(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'macroGetOwnConfig') {\n return literal(\n getConfig(node, opts.configs, opts.packageRoot, moduleName, true, packageCache),\n env.syntax.builders\n );\n }\n if (node.path.original === 'macroGetConfig') {\n return literal(\n getConfig(node, opts.configs, opts.packageRoot, moduleName, false, packageCache),\n env.syntax.builders\n );\n }\n if (node.path.original === 'macroDependencySatisfies') {\n return literal(dependencySatisfies(node, opts.packageRoot, moduleName, packageCache), env.syntax.builders);\n }\n },\n MustacheStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'macroGetOwnConfig') {\n return env.syntax.builders.mustache(\n literal(\n getConfig(node, opts.configs, opts.packageRoot, moduleName, true, packageCache),\n env.syntax.builders\n )\n );\n }\n if (node.path.original === 'macroGetConfig') {\n return env.syntax.builders.mustache(\n literal(\n getConfig(node, opts.configs, opts.packageRoot, moduleName, false, packageCache),\n env.syntax.builders\n )\n );\n }\n if (node.path.original === 'macroDependencySatisfies') {\n return env.syntax.builders.mustache(\n literal(dependencySatisfies(node, opts.packageRoot, moduleName, packageCache), env.syntax.builders)\n );\n }\n },\n },\n };\n }\n (embroiderFirstMacrosTransform as any).embroiderMacrosASTMarker = true;\n (embroiderFirstMacrosTransform as any).parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeFirstTransform',\n get params(): FirstTransformParams {\n return opts;\n },\n };\n return embroiderFirstMacrosTransform;\n}\n\nexport function makeSecondTransform() {\n function embroiderSecondMacrosTransform(env: { syntax: { builders: any } }) {\n let scopeStack: string[][] = [];\n return {\n name: '@embroider/macros/second',\n\n visitor: {\n Program: {\n enter(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.push(node.blockParams);\n }\n },\n exit(node: any) {\n if (node.blockParams.length > 0) {\n scopeStack.pop();\n }\n },\n },\n BlockStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfBlock(node);\n }\n },\n SubExpression(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfExpression(node, env.syntax.builders);\n }\n if (node.path.original === 'macroFailBuild') {\n failBuild(node);\n }\n },\n ElementNode(node: any) {\n node.modifiers = node.modifiers.filter((modifier: any) => {\n if (\n modifier.path.type === 'SubExpression' &&\n modifier.path.path.type === 'PathExpression' &&\n modifier.path.path.original === 'if'\n ) {\n modifier.path = macroIfExpression(modifier.path, env.syntax.builders);\n if (modifier.path.type === 'UndefinedLiteral') {\n return false;\n }\n }\n if (modifier.path.type !== 'PathExpression') {\n return true;\n }\n if (inScope(scopeStack, modifier.path.parts[0])) {\n return true;\n }\n if (modifier.path.original === 'macroMaybeAttrs') {\n maybeAttrs(node, modifier, env.syntax.builders);\n } else {\n return true;\n }\n });\n },\n MustacheStatement(node: any) {\n if (node.path.type !== 'PathExpression') {\n return;\n }\n if (inScope(scopeStack, node.path.parts[0])) {\n return;\n }\n if (node.path.original === 'if') {\n return macroIfMustache(node, env.syntax.builders);\n }\n if (node.path.original === 'macroFailBuild') {\n failBuild(node);\n }\n },\n },\n };\n }\n (embroiderSecondMacrosTransform as any).embroiderMacrosASTMarker = true;\n (embroiderSecondMacrosTransform as any).parallelBabel = {\n requireFile: __filename,\n buildUsing: 'makeSecondTransform',\n params: undefined,\n };\n return embroiderSecondMacrosTransform;\n}\n\nfunction inScope(scopeStack: string[][], name: string) {\n for (let scope of scopeStack) {\n if (scope.includes(name)) {\n return true;\n }\n }\n return false;\n}\n"]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PackageCache } from '@embroider/shared-internals';
|
|
2
|
+
export default function dependencySatisfies(node: any, baseDir: string | undefined, moduleName: string, packageCache: PackageCache): boolean;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const semver_1 = require("semver");
|
|
4
|
-
const shared_internals_1 = require("@embroider/shared-internals");
|
|
5
|
-
let packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
6
4
|
function dependencySatisfies(node,
|
|
7
5
|
// when we're running in traditional ember-cli, baseDir is configured and we
|
|
8
6
|
// do all lookups relative to that (single) package. But when we're running in
|
|
9
7
|
// embroider stage3 we process all packages simultaneously, so baseDir is left
|
|
10
8
|
// unconfigured and moduleName will be the full path to the source file.
|
|
11
|
-
baseDir, moduleName) {
|
|
9
|
+
baseDir, moduleName, packageCache) {
|
|
12
10
|
if (node.params.length !== 2) {
|
|
13
11
|
throw new Error(`macroDependencySatisfies requires two arguments, you passed ${node.params.length}`);
|
|
14
12
|
}
|
|
@@ -18,7 +16,7 @@ baseDir, moduleName) {
|
|
|
18
16
|
let packageName = node.params[0].value;
|
|
19
17
|
let range = node.params[1].value;
|
|
20
18
|
let us = packageCache.ownerOfFile(baseDir || moduleName);
|
|
21
|
-
if (!us) {
|
|
19
|
+
if (!us || us.dependencies.every(dep => dep.name !== packageName)) {
|
|
22
20
|
return false;
|
|
23
21
|
}
|
|
24
22
|
let pkg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;AAAA,mCAAmC;
|
|
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,IAAI,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE;QACjE,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 || us.dependencies.every(dep => dep.name !== 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"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PackageCache } from '@embroider/shared-internals';
|
|
1
2
|
export default function getConfig(node: any, userConfigs: {
|
|
2
3
|
[packageRoot: string]: unknown;
|
|
3
|
-
}, baseDir: string | undefined, moduleName: string, own: boolean): any;
|
|
4
|
+
}, baseDir: string | undefined, moduleName: string, own: boolean, packageCache: PackageCache): any;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const shared_internals_1 = require("@embroider/shared-internals");
|
|
4
|
-
let packageCache = shared_internals_1.PackageCache.shared('embroider-stage3');
|
|
5
3
|
function getConfig(node, userConfigs,
|
|
6
4
|
// when we're running in traditional ember-cli, baseDir is configured and we
|
|
7
5
|
// do all lookups relative to that (single) package. But when we're running in
|
|
8
6
|
// embroider stage3 we process all packages simultaneously, so baseDir is left
|
|
9
7
|
// unconfigured and moduleName will be the full path to the source file.
|
|
10
|
-
baseDir, moduleName, own) {
|
|
8
|
+
baseDir, moduleName, own, packageCache) {
|
|
11
9
|
let targetConfig;
|
|
12
10
|
let params = node.params.slice();
|
|
13
11
|
if (!params.every((p) => p.type === 'StringLiteral')) {
|
|
@@ -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":";;AAEA,SAAwB,SAAS,CAC/B,IAAS,EACT,WAA+C;AAC/C,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,wEAAwE;AACxE,OAA2B,EAC3B,UAAkB,EAClB,GAAY,EACZ,YAA0B;IAE1B,IAAI,YAAY,CAAC;IACjB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE;QACzD,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,gBAAgB,0BAA0B,CAAC,CAAC;KAC7G;IAED,IAAI,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,GAAG,EAAE;QACP,YAAY,GAAG,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;KACrC;SAAM;QACL,IAAI,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SAClE;QACD,IAAI,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5D,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC5C;IACD,OAAO,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5E,IAAI,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAQ,CAAC;KAC/C;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAtCD,4BAsCC","sourcesContent":["import type { PackageCache } from '@embroider/shared-internals';\n\nexport default function getConfig(\n node: any,\n userConfigs: { [packageRoot: string]: unknown },\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 own: boolean,\n packageCache: PackageCache\n) {\n let targetConfig;\n let params = node.params.slice();\n if (!params.every((p: any) => p.type === 'StringLiteral')) {\n throw new Error(`all arguments to ${own ? 'macroGetOwnConfig' : 'macroGetConfig'} must be string literals`);\n }\n\n let us = packageCache.ownerOfFile(baseDir || moduleName);\n if (!us) {\n return undefined;\n }\n\n if (own) {\n targetConfig = userConfigs[us.root];\n } else {\n let packageName = params.shift();\n if (!packageName) {\n throw new Error(`macroGetConfig requires at least one argument`);\n }\n let targetPkg = packageCache.resolve(packageName.value, us);\n targetConfig = userConfigs[targetPkg.root];\n }\n while (typeof targetConfig === 'object' && targetConfig && params.length > 0) {\n let key = params.shift();\n targetConfig = targetConfig[key.value] as any;\n }\n return targetConfig;\n}\n"]}
|
package/src/macros-config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginItem } from '@babel/core';
|
|
2
|
+
import { FirstTransformParams } from './glimmer/ast-transform';
|
|
2
3
|
export declare type SourceOfConfig = (config: object) => {
|
|
3
4
|
readonly name: string;
|
|
4
5
|
readonly root: string;
|
|
@@ -8,17 +9,17 @@ export declare type Merger = (configs: object[], params: {
|
|
|
8
9
|
sourceOfConfig: SourceOfConfig;
|
|
9
10
|
}) => object;
|
|
10
11
|
export default class MacrosConfig {
|
|
11
|
-
|
|
12
|
+
private appRoot;
|
|
13
|
+
static for(key: any, appRoot: string): MacrosConfig;
|
|
12
14
|
private mode;
|
|
13
15
|
private globalConfig;
|
|
14
16
|
private isDevelopingPackageRoots;
|
|
15
|
-
private appPackageRoot;
|
|
16
17
|
enableRuntimeMode(): void;
|
|
17
|
-
enableAppDevelopment(appPackageRoot: string): void;
|
|
18
18
|
enablePackageDevelopment(packageRoot: string): void;
|
|
19
19
|
private _importSyncImplementation;
|
|
20
20
|
get importSyncImplementation(): 'cjs' | 'eager';
|
|
21
21
|
set importSyncImplementation(value: 'cjs' | 'eager');
|
|
22
|
+
private packageCache;
|
|
22
23
|
private constructor();
|
|
23
24
|
private _configWritable;
|
|
24
25
|
private configs;
|
|
@@ -31,17 +32,16 @@ export default class MacrosConfig {
|
|
|
31
32
|
useMerger(fromPath: string, merger: Merger): void;
|
|
32
33
|
private cachedUserConfigs;
|
|
33
34
|
private get userConfigs();
|
|
35
|
+
private makeConfigSourcer;
|
|
34
36
|
babelPluginConfig(appOrAddonInstance?: any): PluginItem[];
|
|
35
37
|
static astPlugins(owningPackageRoot?: string): {
|
|
36
38
|
plugins: Function[];
|
|
37
39
|
setConfig: (config: MacrosConfig) => void;
|
|
38
|
-
|
|
40
|
+
lazyParams: FirstTransformParams;
|
|
39
41
|
};
|
|
40
42
|
private mergerFor;
|
|
41
43
|
packageMoved(oldPath: string, newPath: string): void;
|
|
42
44
|
private moves;
|
|
43
|
-
getConfig(fromPath: string, packageName: string): object;
|
|
44
|
-
getOwnConfig(fromPath: string): object;
|
|
45
45
|
private resolvePackage;
|
|
46
46
|
finalize(): void;
|
|
47
47
|
}
|
package/src/macros-config.js
CHANGED
|
@@ -10,7 +10,6 @@ const find_up_1 = __importDefault(require("find-up"));
|
|
|
10
10
|
const shared_internals_1 = require("@embroider/shared-internals");
|
|
11
11
|
const ast_transform_1 = require("./glimmer/ast-transform");
|
|
12
12
|
const partition_1 = __importDefault(require("lodash/partition"));
|
|
13
|
-
const packageCache = new shared_internals_1.PackageCache();
|
|
14
13
|
// this is a module-scoped cache. If multiple callers ask _this copy_ of
|
|
15
14
|
// @embroider/macros for a shared MacrosConfig, they'll all get the same one.
|
|
16
15
|
// And if somebody asks a *different* copy of @embroider/macros for the shared
|
|
@@ -28,7 +27,8 @@ function gatherAddonCacheKey(item, memo = new Set()) {
|
|
|
28
27
|
return [...memo].join('|');
|
|
29
28
|
}
|
|
30
29
|
class MacrosConfig {
|
|
31
|
-
constructor() {
|
|
30
|
+
constructor(appRoot) {
|
|
31
|
+
this.appRoot = appRoot;
|
|
32
32
|
this.mode = 'compile-time';
|
|
33
33
|
this.globalConfig = {};
|
|
34
34
|
this.isDevelopingPackageRoots = new Set();
|
|
@@ -55,8 +55,9 @@ class MacrosConfig {
|
|
|
55
55
|
// true to distinguish the two.
|
|
56
56
|
isTesting: false,
|
|
57
57
|
};
|
|
58
|
+
this.packageCache = shared_internals_1.PackageCache.shared('embroider-stage3', appRoot);
|
|
58
59
|
}
|
|
59
|
-
static for(key) {
|
|
60
|
+
static for(key, appRoot) {
|
|
60
61
|
let found = localSharedState.get(key);
|
|
61
62
|
if (found) {
|
|
62
63
|
return found;
|
|
@@ -81,7 +82,7 @@ class MacrosConfig {
|
|
|
81
82
|
};
|
|
82
83
|
g.__embroider_macros_global__.set(key, shared);
|
|
83
84
|
}
|
|
84
|
-
let config = new MacrosConfig();
|
|
85
|
+
let config = new MacrosConfig(appRoot);
|
|
85
86
|
config.configs = shared.configs;
|
|
86
87
|
config.configSources = shared.configSources;
|
|
87
88
|
config.mergers = shared.mergers;
|
|
@@ -96,23 +97,6 @@ class MacrosConfig {
|
|
|
96
97
|
this.mode = 'run-time';
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
enableAppDevelopment(appPackageRoot) {
|
|
100
|
-
if (!appPackageRoot) {
|
|
101
|
-
throw new Error(`must provide appPackageRoot`);
|
|
102
|
-
}
|
|
103
|
-
if (this.appPackageRoot) {
|
|
104
|
-
if (this.appPackageRoot !== appPackageRoot && this.moves.get(this.appPackageRoot) !== appPackageRoot) {
|
|
105
|
-
throw new Error(`bug: conflicting appPackageRoots ${this.appPackageRoot} vs ${appPackageRoot}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
if (!this._configWritable) {
|
|
110
|
-
throw new Error(`[Embroider:MacrosConfig] attempted to enableAppDevelopment after configs have been finalized`);
|
|
111
|
-
}
|
|
112
|
-
this.appPackageRoot = appPackageRoot;
|
|
113
|
-
this.isDevelopingPackageRoots.add(appPackageRoot);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
100
|
enablePackageDevelopment(packageRoot) {
|
|
117
101
|
if (!this.isDevelopingPackageRoots.has(packageRoot)) {
|
|
118
102
|
if (!this._configWritable) {
|
|
@@ -185,7 +169,7 @@ class MacrosConfig {
|
|
|
185
169
|
}
|
|
186
170
|
if (!this.cachedUserConfigs) {
|
|
187
171
|
let userConfigs = {};
|
|
188
|
-
let sourceOfConfig = makeConfigSourcer(this.configSources);
|
|
172
|
+
let sourceOfConfig = this.makeConfigSourcer(this.configSources);
|
|
189
173
|
for (let [pkgRoot, configs] of this.configs) {
|
|
190
174
|
let combined;
|
|
191
175
|
if (configs.length > 1) {
|
|
@@ -203,6 +187,30 @@ class MacrosConfig {
|
|
|
203
187
|
}
|
|
204
188
|
return this.cachedUserConfigs;
|
|
205
189
|
}
|
|
190
|
+
makeConfigSourcer(configSources) {
|
|
191
|
+
return config => {
|
|
192
|
+
let fromPath = configSources.get(config);
|
|
193
|
+
if (!fromPath) {
|
|
194
|
+
throw new Error(`unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`);
|
|
195
|
+
}
|
|
196
|
+
let maybePkg = this.packageCache.ownerOfFile(fromPath);
|
|
197
|
+
if (!maybePkg) {
|
|
198
|
+
throw new Error(`bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`);
|
|
199
|
+
}
|
|
200
|
+
let pkg = maybePkg;
|
|
201
|
+
return {
|
|
202
|
+
get name() {
|
|
203
|
+
return pkg.name;
|
|
204
|
+
},
|
|
205
|
+
get version() {
|
|
206
|
+
return pkg.version;
|
|
207
|
+
},
|
|
208
|
+
get root() {
|
|
209
|
+
return pkg.root;
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
}
|
|
206
214
|
// to be called from within your build system. Returns the thing you should
|
|
207
215
|
// push into your babel plugins list.
|
|
208
216
|
//
|
|
@@ -212,6 +220,7 @@ class MacrosConfig {
|
|
|
212
220
|
// owningPackageRoot is needed when you use this inside classic ember-cli, and
|
|
213
221
|
// it's not appropriate inside embroider.
|
|
214
222
|
babelPluginConfig(appOrAddonInstance) {
|
|
223
|
+
var _a;
|
|
215
224
|
let self = this;
|
|
216
225
|
let owningPackageRoot = appOrAddonInstance ? appOrAddonInstance.root || appOrAddonInstance.project.root : null;
|
|
217
226
|
let opts = {
|
|
@@ -225,7 +234,7 @@ class MacrosConfig {
|
|
|
225
234
|
},
|
|
226
235
|
owningPackageRoot,
|
|
227
236
|
isDevelopingPackageRoots: [...this.isDevelopingPackageRoots].map(root => this.moves.get(root) || root),
|
|
228
|
-
appPackageRoot:
|
|
237
|
+
appPackageRoot: (_a = this.moves.get(this.appRoot)) !== null && _a !== void 0 ? _a : this.appRoot,
|
|
229
238
|
// This is used as a signature so we can detect ourself among the plugins
|
|
230
239
|
// emitted from v1 addons.
|
|
231
240
|
embroiderMacrosConfigMarker: true,
|
|
@@ -267,30 +276,28 @@ class MacrosConfig {
|
|
|
267
276
|
}
|
|
268
277
|
static astPlugins(owningPackageRoot) {
|
|
269
278
|
let configs;
|
|
270
|
-
let
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
let lazyParams = {
|
|
280
|
+
// this is deliberately lazy because we want to allow everyone to finish
|
|
281
|
+
// setting config before we generate the userConfigs
|
|
282
|
+
get configs() {
|
|
283
|
+
if (!configs) {
|
|
284
|
+
throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);
|
|
285
|
+
}
|
|
286
|
+
return configs.userConfigs;
|
|
287
|
+
},
|
|
288
|
+
packageRoot: owningPackageRoot,
|
|
289
|
+
get appRoot() {
|
|
290
|
+
if (!configs) {
|
|
291
|
+
throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);
|
|
292
|
+
}
|
|
293
|
+
return configs.appRoot;
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
let plugins = [(0, ast_transform_1.makeFirstTransform)(lazyParams), (0, ast_transform_1.makeSecondTransform)()].reverse();
|
|
284
297
|
function setConfig(c) {
|
|
285
298
|
configs = c;
|
|
286
299
|
}
|
|
287
|
-
|
|
288
|
-
if (!configs) {
|
|
289
|
-
throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);
|
|
290
|
-
}
|
|
291
|
-
return configs.userConfigs;
|
|
292
|
-
}
|
|
293
|
-
return { plugins, setConfig, getConfigForPlugin };
|
|
300
|
+
return { plugins, setConfig, lazyParams };
|
|
294
301
|
}
|
|
295
302
|
mergerFor(pkgRoot) {
|
|
296
303
|
let entry = this.mergers.get(pkgRoot);
|
|
@@ -307,19 +314,13 @@ class MacrosConfig {
|
|
|
307
314
|
}
|
|
308
315
|
this.moves.set(oldPath, newPath);
|
|
309
316
|
}
|
|
310
|
-
getConfig(fromPath, packageName) {
|
|
311
|
-
return this.userConfigs[this.resolvePackage(fromPath, packageName).root];
|
|
312
|
-
}
|
|
313
|
-
getOwnConfig(fromPath) {
|
|
314
|
-
return this.userConfigs[this.resolvePackage(fromPath, undefined).root];
|
|
315
|
-
}
|
|
316
317
|
resolvePackage(fromPath, packageName) {
|
|
317
|
-
let us = packageCache.ownerOfFile(fromPath);
|
|
318
|
+
let us = this.packageCache.ownerOfFile(fromPath);
|
|
318
319
|
if (!us) {
|
|
319
320
|
throw new Error(`[Embroider:MacrosConfig] unable to determine which npm package owns the file ${fromPath}`);
|
|
320
321
|
}
|
|
321
322
|
if (packageName) {
|
|
322
|
-
return packageCache.resolve(packageName, us);
|
|
323
|
+
return this.packageCache.resolve(packageName, us);
|
|
323
324
|
}
|
|
324
325
|
else {
|
|
325
326
|
return us;
|
|
@@ -336,28 +337,4 @@ function defaultMergerFor(pkgRoot) {
|
|
|
336
337
|
return Object.assign({}, ...ownConfigs, ...otherConfigs);
|
|
337
338
|
};
|
|
338
339
|
}
|
|
339
|
-
function makeConfigSourcer(configSources) {
|
|
340
|
-
return config => {
|
|
341
|
-
let fromPath = configSources.get(config);
|
|
342
|
-
if (!fromPath) {
|
|
343
|
-
throw new Error(`unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`);
|
|
344
|
-
}
|
|
345
|
-
let maybePkg = packageCache.ownerOfFile(fromPath);
|
|
346
|
-
if (!maybePkg) {
|
|
347
|
-
throw new Error(`bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`);
|
|
348
|
-
}
|
|
349
|
-
let pkg = maybePkg;
|
|
350
|
-
return {
|
|
351
|
-
get name() {
|
|
352
|
-
return pkg.name;
|
|
353
|
-
},
|
|
354
|
-
get version() {
|
|
355
|
-
return pkg.version;
|
|
356
|
-
},
|
|
357
|
-
get root() {
|
|
358
|
-
return pkg.root;
|
|
359
|
-
},
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
340
|
//# 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,2DAAkF;AAElF,iEAAyC;AAEzC,MAAM,YAAY,GAAG,IAAI,+BAAY,EAAE,CAAC;AA0BxC,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;IACtD,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;QACnD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,MAAqB,YAAY;IA8F/B;QA1DQ,SAAI,GAAgC,cAAc,CAAC;QACnD,iBAAY,GAA+B,EAAE,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;AArWD,+BAqWC;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;AAED,SAAS,iBAAiB,CAAC,aAAsC;IAC/D,OAAO,MAAM,CAAC,EAAE;QACd,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;SAClH;QACD,IAAI,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAC;SACH;QACD,IAAI,GAAG,GAAG,QAAQ,CAAC;QACnB,OAAO;YACL,IAAI,IAAI;gBACN,OAAO,GAAG,CAAC,IAAI,CAAC;YAClB,CAAC;YACD,IAAI,OAAO;gBACT,OAAO,GAAG,CAAC,OAAO,CAAC;YACrB,CAAC;YACD,IAAI,IAAI;gBACN,OAAO,GAAG,CAAC,IAAI,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,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 { makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nconst packageCache = new PackageCache();\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): 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();\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 private appPackageRoot: string | undefined;\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 enableAppDevelopment(appPackageRoot: string) {\n if (!appPackageRoot) {\n throw new Error(`must provide appPackageRoot`);\n }\n if (this.appPackageRoot) {\n if (this.appPackageRoot !== appPackageRoot && this.moves.get(this.appPackageRoot) !== appPackageRoot) {\n throw new Error(`bug: conflicting appPackageRoots ${this.appPackageRoot} vs ${appPackageRoot}`);\n }\n } else {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableAppDevelopment after configs have been finalized`);\n }\n this.appPackageRoot = appPackageRoot;\n this.isDevelopingPackageRoots.add(appPackageRoot);\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 constructor() {\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 }\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 = 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 // 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.appPackageRoot ? this.moves.get(this.appPackageRoot) || this.appPackageRoot : '',\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 getConfigForPlugin(): any;\n } {\n let configs: MacrosConfig | undefined;\n let plugins = [\n makeFirstTransform({\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 if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.userConfigs;\n },\n baseDir: owningPackageRoot,\n }),\n makeSecondTransform(),\n ].reverse();\n function setConfig(c: MacrosConfig) {\n configs = c;\n }\n function getConfigForPlugin() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n\n return configs.userConfigs;\n }\n return { plugins, setConfig, getConfigForPlugin };\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 getConfig(fromPath: string, packageName: string) {\n return this.userConfigs[this.resolvePackage(fromPath, packageName).root];\n }\n\n getOwnConfig(fromPath: string) {\n return this.userConfigs[this.resolvePackage(fromPath, undefined).root];\n }\n\n private resolvePackage(fromPath: string, packageName?: string | undefined) {\n let us = 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 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 makeConfigSourcer(configSources: WeakMap<object, string>): SourceOfConfig {\n return config => {\n let fromPath = configSources.get(config);\n if (!fromPath) {\n throw new Error(`unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`);\n }\n let maybePkg = 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"]}
|
|
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;IACtD,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;QACnD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,MAAqB,YAAY;IA8E/B,YAA4B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QA1CnC,SAAI,GAAgC,cAAc,CAAC;QACnD,iBAAY,GAA+B,EAAE,CAAC;QAE9C,6BAAwB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAsBlD,8BAAyB,GAAoB,KAAK,CAAC;QAsCnD,oBAAe,GAAG,IAAI,CAAC;QACvB,YAA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I,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"]}
|