@embroider/macros 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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": "1.
|
|
27
|
+
"@embroider/shared-internals": "1.7.0",
|
|
28
28
|
"assert-never": "^1.2.1",
|
|
29
29
|
"babel-import-util": "^1.1.0",
|
|
30
30
|
"ember-cli-babel": "^7.26.6",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/core": "^7.14.5",
|
|
38
38
|
"@babel/traverse": "^7.14.5",
|
|
39
|
-
"@embroider/core": "1.
|
|
39
|
+
"@embroider/core": "1.7.0",
|
|
40
40
|
"@embroider/test-support": "0.36.0",
|
|
41
41
|
"@types/babel__core": "^7.1.14",
|
|
42
42
|
"@types/babel__generator": "^7.6.2",
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k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OAAO,CAAC,CAAC,CAAC;qBACxD;iBACF;YACH,CAAC;SACF,CAAC;KACH;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AAhND,uBAgNC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport { PackageCache } from '@embroider/shared-internals';\nimport State, { initState } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n if (state.opts.importSyncImplementation === 'eager') {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n path.replaceWith(state.importUtil.import(path, specifier.value, '*'));\n state.calledIdentifiers.add(callee.node);\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberPackage()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kEAA2D;AAC3D,mCAA2C;AAC3C,6CAAwF;AACxF,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAG3D,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG;QACZ,OAAO,EAAE;YACP,KAAK,CAAC,IAAyB,EAAE,KAAY;gBAC3C,IAAA,iBAAS,EAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBAE1B,KAAK,CAAC,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC1F,CAAC;YACD,IAAI,CAAC,CAAsB,EAAE,KAAY;gBACvC,iFAAiF;gBACjF,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;gBACvD,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;oBAC9B,OAAO,EAAE,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E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;oBACtC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE;wBACpB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;qBACxD;iBACF;YACH,CAAC;SACF,CAAC;KACH;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AAhND,uBAgNC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport { PackageCache } from '@embroider/shared-internals';\nimport State, { initState } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n if (state.opts.importSyncImplementation === 'eager') {\n let specifier = path.node.arguments[0];\n if (specifier?.type !== 'StringLiteral') {\n throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n path.replaceWith(state.importUtil.import(path, specifier.value, '*'));\n state.calledIdentifiers.add(callee.node);\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberPackage()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
|
package/src/macros-config.js
CHANGED
package/src/macros-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros-config.js","sourceRoot":"","sources":["macros-config.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA4B;AAC5B,oDAA4B;AAC5B,sDAA6B;AAE7B,kEAAwE;AACxE,2DAAwG;AAExG,iEAAyC;AA0BzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,uCAAuC;AACvC,IAAI,gBAAgB,GAA+B,IAAI,OAAO,EAAE,CAAC;AAEjE,SAAS,yBAAyB,CAAC,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K,QAAQ,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,iBAAiB,CAAC;AACvG,CAAC","sourcesContent":["import fs from 'fs';\nimport { join } from 'path';\nimport crypto from 'crypto';\nimport findUp from 'find-up';\nimport type { PluginItem } from '@babel/core';\nimport { PackageCache, getOrCreate } from '@embroider/shared-internals';\nimport { FirstTransformParams, makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nexport type SourceOfConfig = (config: object) => {\n readonly name: string;\n readonly root: string;\n readonly version: string;\n};\n\nexport type Merger = (\n configs: object[],\n params: {\n sourceOfConfig: SourceOfConfig;\n }\n) => object;\n\n// Do not change this type signature without pondering deeply the mysteries of\n// being compatible with unwritten future versions of this library.\ntype GlobalSharedState = WeakMap<\n any,\n {\n configs: Map<string, object[]>;\n configSources: WeakMap<object, string>;\n mergers: Map<string, { merger: Merger; fromPath: string }>;\n }\n>;\n\n// this is a module-scoped cache. If multiple callers ask _this copy_ of\n// @embroider/macros for a shared MacrosConfig, they'll all get the same one.\n// And if somebody asks a *different* copy of @embroider/macros for the shared\n// MacrosConfig, it will have its own instance with its own code, but will still\n// share the GlobalSharedState beneath.\nlet localSharedState: WeakMap<any, MacrosConfig> = new WeakMap();\n\nfunction gatherAddonCacheKeyWorker(item: any, memo: Set<string>) {\n item.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n}\n\nlet addonCacheKey: WeakMap<any, string> = new WeakMap();\n// creates a string representing all addons and their versions\n// (foo@1.0.0|bar@2.0.0) to use as a cachekey\nfunction gatherAddonCacheKey(project: any): string {\n let cacheKey = addonCacheKey.get(project);\n if (cacheKey) {\n return cacheKey;\n }\n\n let memo: Set<string> = new Set();\n project.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n\n cacheKey = [...memo].join('|');\n addonCacheKey.set(project, cacheKey);\n\n return cacheKey;\n}\n\nexport default class MacrosConfig {\n static for(key: any, appRoot: string): MacrosConfig {\n let found = localSharedState.get(key);\n if (found) {\n return found;\n }\n\n let g = global as any as { __embroider_macros_global__: GlobalSharedState | undefined };\n if (!g.__embroider_macros_global__) {\n g.__embroider_macros_global__ = new WeakMap();\n }\n\n let shared = g.__embroider_macros_global__.get(key);\n if (shared) {\n // if an earlier version of @embroider/macros created the shared state, it\n // would have configSources.\n if (!shared.configSources) {\n shared.configSources = new WeakMap();\n }\n } else {\n shared = {\n configs: new Map(),\n configSources: new WeakMap(),\n mergers: new Map(),\n };\n g.__embroider_macros_global__.set(key, shared);\n }\n\n let config = new MacrosConfig(appRoot);\n config.configs = shared.configs;\n config.configSources = shared.configSources;\n config.mergers = shared.mergers;\n localSharedState.set(key, config);\n return config;\n }\n\n private mode: 'compile-time' | 'run-time' = 'compile-time';\n private globalConfig: { [key: string]: unknown } = {};\n\n private isDevelopingPackageRoots: Set<string> = new Set();\n\n enableRuntimeMode() {\n if (this.mode !== 'run-time') {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableRuntimeMode after configs have been finalized`);\n }\n this.mode = 'run-time';\n }\n }\n\n enablePackageDevelopment(packageRoot: string) {\n if (!this.isDevelopingPackageRoots.has(packageRoot)) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to enablePackageDevelopment after configs have been finalized`\n );\n }\n this.isDevelopingPackageRoots.add(packageRoot);\n }\n }\n\n private _importSyncImplementation: 'cjs' | 'eager' = 'cjs';\n\n get importSyncImplementation() {\n return this._importSyncImplementation;\n }\n\n set importSyncImplementation(value: 'cjs' | 'eager') {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`\n );\n }\n this._importSyncImplementation = value;\n }\n\n private packageCache: PackageCache;\n\n private constructor(private appRoot: string) {\n // this uses globalConfig because these things truly are global. Even if a\n // package doesn't have a dep or peerDep on @embroider/macros, it's legit\n // for them to want to know the answer to these questions, and there is only\n // one answer throughout the whole dependency graph.\n this.globalConfig['@embroider/macros'] = {\n // this powers the `isTesting` macro. It always starts out false here,\n // because:\n // - if this is a production build, we will evaluate all macros at build\n // time and isTesting will stay false, so test-only code will not be\n // included.\n // - if this is a dev build, we evaluate macros at runtime, which allows\n // both \"I'm running my app in development\" and \"I'm running my test\n // suite\" to coexist within a single build. When you run the test\n // suite, early in the runtime boot process we can flip isTesting to\n // true to distinguish the two.\n isTesting: false,\n };\n this.packageCache = PackageCache.shared('embroider-stage3', appRoot);\n }\n\n private _configWritable = true;\n private configs: Map<string, object[]> = new Map();\n private configSources: WeakMap<object, string> = new WeakMap();\n private mergers: Map<string, { merger: Merger; fromPath: string }> = new Map();\n\n // Registers a new source of configuration to be given to the named package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setConfig(fromPath: string, packageName: string, config: object) {\n return this.internalSetConfig(fromPath, packageName, config);\n }\n\n // Registers a new source of configuration to be given to your own package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setOwnConfig(fromPath: string, config: object) {\n return this.internalSetConfig(fromPath, undefined, config);\n }\n\n // Registers a new source of configuration to be shared globally within the\n // app. USE GLOBALS SPARINGLY! Prefer setConfig or setOwnConfig instead,\n // unless your state is truly, necessarily global.\n //\n // Include a relevant package name in your key to help avoid collisions.\n //\n // Your value must be json-serializable. You must always set fromPath to\n // `__filename`.\n setGlobalConfig(fromPath: string, key: string, value: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set global config after configs have been finalized from: '${fromPath}'`\n );\n }\n this.globalConfig[key] = value;\n }\n\n private internalSetConfig(fromPath: string, packageName: string | undefined, config: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set config after configs have been finalized from: '${fromPath}'`\n );\n }\n\n if (!isSerializable(config)) {\n throw new Error(\n `[Embroider:MacrosConfig] the given config from '${fromPath}' for packageName '${packageName}' is not JSON serializable.`\n );\n }\n\n let targetPackage = this.resolvePackage(fromPath, packageName);\n let peers = getOrCreate(this.configs, targetPackage.root, () => []);\n peers.push(config);\n this.configSources.set(config, fromPath);\n }\n\n // Allows you to set the merging strategy used for your package's config. The\n // merging strategy applies when multiple other packages all try to send\n // configuration to you.\n useMerger(fromPath: string, merger: Merger) {\n if (this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call useMerger after configs have been finalized`);\n }\n\n let targetPackage = this.resolvePackage(fromPath, undefined);\n let other = this.mergers.get(targetPackage.root);\n if (other) {\n throw new Error(\n `[Embroider:MacrosConfig] conflicting mergers registered for package ${targetPackage.name} at ${targetPackage.root}. See ${other.fromPath} and ${fromPath}.`\n );\n }\n this.mergers.set(targetPackage.root, { merger, fromPath });\n }\n\n private cachedUserConfigs: { [packageRoot: string]: object } | undefined;\n\n private get userConfigs() {\n if (this._configWritable) {\n throw new Error('[Embroider:MacrosConfig] cannot read userConfigs until MacrosConfig has been finalized.');\n }\n\n if (!this.cachedUserConfigs) {\n let userConfigs: { [packageRoot: string]: object } = {};\n let sourceOfConfig = this.makeConfigSourcer(this.configSources);\n for (let [pkgRoot, configs] of this.configs) {\n let combined: object;\n if (configs.length > 1) {\n combined = this.mergerFor(pkgRoot)(configs, { sourceOfConfig });\n } else {\n combined = configs[0];\n }\n userConfigs[pkgRoot] = combined;\n }\n for (let [oldPath, newPath] of this.moves) {\n userConfigs[newPath] = userConfigs[oldPath];\n }\n this.cachedUserConfigs = userConfigs;\n }\n\n return this.cachedUserConfigs;\n }\n\n private makeConfigSourcer(configSources: WeakMap<object, string>): SourceOfConfig {\n return config => {\n let fromPath = configSources.get(config);\n if (!fromPath) {\n throw new Error(\n `unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`\n );\n }\n let maybePkg = this.packageCache.ownerOfFile(fromPath);\n if (!maybePkg) {\n throw new Error(\n `bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`\n );\n }\n let pkg = maybePkg;\n return {\n get name() {\n return pkg.name;\n },\n get version() {\n return pkg.version;\n },\n get root() {\n return pkg.root;\n },\n };\n };\n }\n\n // to be called from within your build system. Returns the thing you should\n // push into your babel plugins list.\n //\n // owningPackageRoot is needed when the files you will process (1) all belongs\n // to one package, (2) will not be located in globally correct paths such that\n // normal node_modules resolution can find their dependencies. In other words,\n // owningPackageRoot is needed when you use this inside classic ember-cli, and\n // it's not appropriate inside embroider.\n babelPluginConfig(appOrAddonInstance?: any): PluginItem[] {\n let self = this;\n let owningPackageRoot = appOrAddonInstance ? appOrAddonInstance.root || appOrAddonInstance.project.root : null;\n let opts: State['opts'] = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get userConfigs() {\n return self.userConfigs;\n },\n get globalConfig() {\n return self.globalConfig;\n },\n owningPackageRoot,\n\n isDevelopingPackageRoots: [...this.isDevelopingPackageRoots].map(root => this.moves.get(root) || root),\n appPackageRoot: this.moves.get(this.appRoot) ?? this.appRoot,\n\n // This is used as a signature so we can detect ourself among the plugins\n // emitted from v1 addons.\n embroiderMacrosConfigMarker: true,\n\n get mode() {\n return self.mode;\n },\n\n importSyncImplementation: this.importSyncImplementation,\n };\n\n let lockFilePath = findUp.sync(['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'], { cwd: opts.appPackageRoot });\n\n if (!lockFilePath) {\n lockFilePath = findUp.sync('package.json', { cwd: opts.appPackageRoot });\n }\n\n let lockFileBuffer = lockFilePath ? fs.readFileSync(lockFilePath) : 'no-cache-key';\n\n // @embroider/macros provides a macro called dependencySatisfies which checks if a given\n // package name satisfies a given semver version range. Due to the way babel caches this can\n // cause a problem where the macro plugin does not run (because it has been cached) but the version\n // of the dependency being checked for changes (due to installing a different version). This will lead to\n // the old evaluated state being used which might be invalid. This cache busting plugin keeps track of a\n // hash representing the lock file of the app and if it ever changes forces babel to rerun its plugins.\n // more information in issue #906\n let hash = crypto.createHash('sha256');\n hash = hash.update(lockFileBuffer);\n if (appOrAddonInstance) {\n // ensure that the actual running addon names and versions are accounted\n // for in the cache key; this ensures that we still invalidate the cache\n // when linking another project (e.g. ember-source) which would normally\n // not cause the lockfile to change;\n hash = hash.update(gatherAddonCacheKey(appOrAddonInstance.project));\n }\n let cacheKey = hash.digest('hex');\n\n return [\n [join(__dirname, 'babel', 'macros-babel-plugin.js'), opts],\n [\n require.resolve('@embroider/shared-internals/src/babel-plugin-cache-busting.js'),\n { version: cacheKey },\n `@embroider/macros cache buster: ${owningPackageRoot}`,\n ],\n ];\n }\n\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let configs: MacrosConfig | undefined;\n\n let lazyParams = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get configs() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.userConfigs;\n },\n packageRoot: owningPackageRoot,\n get appRoot() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.appRoot;\n },\n };\n\n let plugins = [makeFirstTransform(lazyParams), makeSecondTransform()].reverse();\n function setConfig(c: MacrosConfig) {\n configs = c;\n }\n return { plugins, setConfig, lazyParams };\n }\n\n private mergerFor(pkgRoot: string) {\n let entry = this.mergers.get(pkgRoot);\n if (entry) {\n return entry.merger;\n }\n return defaultMergerFor(pkgRoot);\n }\n\n // this exists because @embroider/compat rewrites and moves v1 addons, and\n // their macro configs need to follow them to their new homes.\n packageMoved(oldPath: string, newPath: string) {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call packageMoved after configs have been finalized`);\n }\n\n this.moves.set(oldPath, newPath);\n }\n\n private moves: Map<string, string> = new Map();\n\n private resolvePackage(fromPath: string, packageName?: string | undefined) {\n let us = this.packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`[Embroider:MacrosConfig] unable to determine which npm package owns the file ${fromPath}`);\n }\n if (packageName) {\n return this.packageCache.resolve(packageName, us);\n } else {\n return us;\n }\n }\n\n finalize() {\n this._configWritable = false;\n }\n}\n\nfunction defaultMergerFor(pkgRoot: string) {\n return function defaultMerger(configs: object[], { sourceOfConfig }: { sourceOfConfig: SourceOfConfig }): object {\n let [ownConfigs, otherConfigs] = partition(configs, c => sourceOfConfig(c as object).root === pkgRoot);\n return Object.assign({}, ...ownConfigs, ...otherConfigs);\n };\n}\n\nfunction isSerializable(obj: object): boolean {\n if (isScalar(obj)) {\n return true;\n }\n\n if (Array.isArray(obj)) {\n return !obj.some((arrayItem: any) => !isSerializable(arrayItem));\n }\n\n if (isPlainObject(obj)) {\n for (let property in obj) {\n let value = obj[property] as any;\n if (!isSerializable(value)) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n\nfunction isScalar(val: any): boolean {\n return (\n typeof val === 'undefined' ||\n typeof val === 'string' ||\n typeof val === 'boolean' ||\n typeof val === 'number' ||\n val === null\n );\n}\n\nfunction isPlainObject(obj: any): obj is Record<string, any> {\n return typeof obj === 'object' && obj.constructor === Object && obj.toString() === '[object Object]';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"macros-config.js","sourceRoot":"","sources":["macros-config.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA4B;AAC5B,oDAA4B;AAC5B,sDAA6B;AAE7B,kEAAwE;AACxE,2DAAwG;AAExG,iEAAyC;AA0BzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,uCAAuC;AACvC,IAAI,gBAAgB,GAA+B,IAAI,OAAO,EAAE,CAAC;AAEjE,SAAS,yBAAyB,CAAC,IAAS,EAAE,IAAiB;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC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AAQ,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,iBAAiB,CAAC;AACvG,CAAC","sourcesContent":["import fs from 'fs';\nimport { join } from 'path';\nimport crypto from 'crypto';\nimport findUp from 'find-up';\nimport type { PluginItem } from '@babel/core';\nimport { PackageCache, getOrCreate } from '@embroider/shared-internals';\nimport { FirstTransformParams, makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nexport type SourceOfConfig = (config: object) => {\n readonly name: string;\n readonly root: string;\n readonly version: string;\n};\n\nexport type Merger = (\n configs: object[],\n params: {\n sourceOfConfig: SourceOfConfig;\n }\n) => object;\n\n// Do not change this type signature without pondering deeply the mysteries of\n// being compatible with unwritten future versions of this library.\ntype GlobalSharedState = WeakMap<\n any,\n {\n configs: Map<string, object[]>;\n configSources: WeakMap<object, string>;\n mergers: Map<string, { merger: Merger; fromPath: string }>;\n }\n>;\n\n// this is a module-scoped cache. If multiple callers ask _this copy_ of\n// @embroider/macros for a shared MacrosConfig, they'll all get the same one.\n// And if somebody asks a *different* copy of @embroider/macros for the shared\n// MacrosConfig, it will have its own instance with its own code, but will still\n// share the GlobalSharedState beneath.\nlet localSharedState: WeakMap<any, MacrosConfig> = new WeakMap();\n\nfunction gatherAddonCacheKeyWorker(item: any, memo: Set<string>) {\n item.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n}\n\nlet addonCacheKey: WeakMap<any, string> = new WeakMap();\n// creates a string representing all addons and their versions\n// (foo@1.0.0|bar@2.0.0) to use as a cachekey\nfunction gatherAddonCacheKey(project: any): string {\n let cacheKey = addonCacheKey.get(project);\n if (cacheKey) {\n return cacheKey;\n }\n\n let memo: Set<string> = new Set();\n project.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n\n cacheKey = [...memo].join('|');\n addonCacheKey.set(project, cacheKey);\n\n return cacheKey;\n}\n\nexport default class MacrosConfig {\n static for(key: any, appRoot: string): MacrosConfig {\n let found = localSharedState.get(key);\n if (found) {\n return found;\n }\n\n let g = global as any as { __embroider_macros_global__: GlobalSharedState | undefined };\n if (!g.__embroider_macros_global__) {\n g.__embroider_macros_global__ = new WeakMap();\n }\n\n let shared = g.__embroider_macros_global__.get(key);\n if (shared) {\n // if an earlier version of @embroider/macros created the shared state, it\n // would have configSources.\n if (!shared.configSources) {\n shared.configSources = new WeakMap();\n }\n } else {\n shared = {\n configs: new Map(),\n configSources: new WeakMap(),\n mergers: new Map(),\n };\n g.__embroider_macros_global__.set(key, shared);\n }\n\n let config = new MacrosConfig(appRoot);\n config.configs = shared.configs;\n config.configSources = shared.configSources;\n config.mergers = shared.mergers;\n localSharedState.set(key, config);\n return config;\n }\n\n private mode: 'compile-time' | 'run-time' = 'compile-time';\n private globalConfig: { [key: string]: unknown } = {};\n\n private isDevelopingPackageRoots: Set<string> = new Set();\n\n enableRuntimeMode() {\n if (this.mode !== 'run-time') {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableRuntimeMode after configs have been finalized`);\n }\n this.mode = 'run-time';\n }\n }\n\n enablePackageDevelopment(packageRoot: string) {\n if (!this.isDevelopingPackageRoots.has(packageRoot)) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to enablePackageDevelopment after configs have been finalized`\n );\n }\n this.isDevelopingPackageRoots.add(packageRoot);\n }\n }\n\n private _importSyncImplementation: 'cjs' | 'eager' = 'cjs';\n\n get importSyncImplementation() {\n return this._importSyncImplementation;\n }\n\n set importSyncImplementation(value: 'cjs' | 'eager') {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`\n );\n }\n this._importSyncImplementation = value;\n }\n\n private packageCache: PackageCache;\n\n private constructor(private appRoot: string) {\n // this uses globalConfig because these things truly are global. Even if a\n // package doesn't have a dep or peerDep on @embroider/macros, it's legit\n // for them to want to know the answer to these questions, and there is only\n // one answer throughout the whole dependency graph.\n this.globalConfig['@embroider/macros'] = {\n // this powers the `isTesting` macro. It always starts out false here,\n // because:\n // - if this is a production build, we will evaluate all macros at build\n // time and isTesting will stay false, so test-only code will not be\n // included.\n // - if this is a dev build, we evaluate macros at runtime, which allows\n // both \"I'm running my app in development\" and \"I'm running my test\n // suite\" to coexist within a single build. When you run the test\n // suite, early in the runtime boot process we can flip isTesting to\n // true to distinguish the two.\n isTesting: false,\n };\n this.packageCache = PackageCache.shared('embroider-stage3', appRoot);\n }\n\n private _configWritable = true;\n private configs: Map<string, object[]> = new Map();\n private configSources: WeakMap<object, string> = new WeakMap();\n private mergers: Map<string, { merger: Merger; fromPath: string }> = new Map();\n\n // Registers a new source of configuration to be given to the named package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setConfig(fromPath: string, packageName: string, config: object) {\n return this.internalSetConfig(fromPath, packageName, config);\n }\n\n // Registers a new source of configuration to be given to your own package.\n // Your config type must be json-serializable. You must always set fromPath to\n // `__filename`.\n setOwnConfig(fromPath: string, config: object) {\n return this.internalSetConfig(fromPath, undefined, config);\n }\n\n // Registers a new source of configuration to be shared globally within the\n // app. USE GLOBALS SPARINGLY! Prefer setConfig or setOwnConfig instead,\n // unless your state is truly, necessarily global.\n //\n // Include a relevant package name in your key to help avoid collisions.\n //\n // Your value must be json-serializable. You must always set fromPath to\n // `__filename`.\n setGlobalConfig(fromPath: string, key: string, value: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set global config after configs have been finalized from: '${fromPath}'`\n );\n }\n this.globalConfig[key] = value;\n }\n\n private internalSetConfig(fromPath: string, packageName: string | undefined, config: object) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set config after configs have been finalized from: '${fromPath}'`\n );\n }\n\n if (!isSerializable(config)) {\n throw new Error(\n `[Embroider:MacrosConfig] the given config from '${fromPath}' for packageName '${packageName}' is not JSON serializable.`\n );\n }\n\n let targetPackage = this.resolvePackage(fromPath, packageName);\n let peers = getOrCreate(this.configs, targetPackage.root, () => []);\n peers.push(config);\n this.configSources.set(config, fromPath);\n }\n\n // Allows you to set the merging strategy used for your package's config. The\n // merging strategy applies when multiple other packages all try to send\n // configuration to you.\n useMerger(fromPath: string, merger: Merger) {\n if (this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call useMerger after configs have been finalized`);\n }\n\n let targetPackage = this.resolvePackage(fromPath, undefined);\n let other = this.mergers.get(targetPackage.root);\n if (other) {\n throw new Error(\n `[Embroider:MacrosConfig] conflicting mergers registered for package ${targetPackage.name} at ${targetPackage.root}. See ${other.fromPath} and ${fromPath}.`\n );\n }\n this.mergers.set(targetPackage.root, { merger, fromPath });\n }\n\n private cachedUserConfigs: { [packageRoot: string]: object } | undefined;\n\n private get userConfigs() {\n if (this._configWritable) {\n throw new Error('[Embroider:MacrosConfig] cannot read userConfigs until MacrosConfig has been finalized.');\n }\n\n if (!this.cachedUserConfigs) {\n let userConfigs: { [packageRoot: string]: object } = {};\n let sourceOfConfig = this.makeConfigSourcer(this.configSources);\n for (let [pkgRoot, configs] of this.configs) {\n let combined: object;\n if (configs.length > 1) {\n combined = this.mergerFor(pkgRoot)(configs, { sourceOfConfig });\n } else {\n combined = configs[0];\n }\n userConfigs[pkgRoot] = combined;\n }\n for (let [oldPath, newPath] of this.moves) {\n userConfigs[newPath] = userConfigs[oldPath];\n }\n this.cachedUserConfigs = userConfigs;\n }\n\n return this.cachedUserConfigs;\n }\n\n private makeConfigSourcer(configSources: WeakMap<object, string>): SourceOfConfig {\n return config => {\n let fromPath = configSources.get(config);\n if (!fromPath) {\n throw new Error(\n `unknown object passed to sourceOfConfig(). You can only pass back the configs you were given.`\n );\n }\n let maybePkg = this.packageCache.ownerOfFile(fromPath);\n if (!maybePkg) {\n throw new Error(\n `bug: unexpected error, we always check that fromPath is owned during internalSetConfig so this should never happen`\n );\n }\n let pkg = maybePkg;\n return {\n get name() {\n return pkg.name;\n },\n get version() {\n return pkg.version;\n },\n get root() {\n return pkg.root;\n },\n };\n };\n }\n\n // to be called from within your build system. Returns the thing you should\n // push into your babel plugins list.\n //\n // owningPackageRoot is needed when the files you will process (1) all belongs\n // to one package, (2) will not be located in globally correct paths such that\n // normal node_modules resolution can find their dependencies. In other words,\n // owningPackageRoot is needed when you use this inside classic ember-cli, and\n // it's not appropriate inside embroider.\n babelPluginConfig(appOrAddonInstance?: any): PluginItem[] {\n let self = this;\n let owningPackageRoot = appOrAddonInstance ? appOrAddonInstance.root || appOrAddonInstance.project.root : null;\n let opts: State['opts'] = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get userConfigs() {\n return self.userConfigs;\n },\n get globalConfig() {\n return self.globalConfig;\n },\n owningPackageRoot,\n\n isDevelopingPackageRoots: [...this.isDevelopingPackageRoots].map(root => this.moves.get(root) || root),\n appPackageRoot: this.moves.get(this.appRoot) ?? this.appRoot,\n\n // This is used as a signature so we can detect ourself among the plugins\n // emitted from v1 addons.\n embroiderMacrosConfigMarker: true,\n\n get mode() {\n return self.mode;\n },\n\n importSyncImplementation: this.importSyncImplementation,\n };\n\n let lockFilePath = findUp.sync(['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'], { cwd: opts.appPackageRoot });\n\n if (!lockFilePath) {\n lockFilePath = findUp.sync('package.json', { cwd: opts.appPackageRoot });\n }\n\n let lockFileBuffer = lockFilePath ? fs.readFileSync(lockFilePath) : 'no-cache-key';\n\n // @embroider/macros provides a macro called dependencySatisfies which checks if a given\n // package name satisfies a given semver version range. Due to the way babel caches this can\n // cause a problem where the macro plugin does not run (because it has been cached) but the version\n // of the dependency being checked for changes (due to installing a different version). This will lead to\n // the old evaluated state being used which might be invalid. This cache busting plugin keeps track of a\n // hash representing the lock file of the app and if it ever changes forces babel to rerun its plugins.\n // more information in issue #906\n let hash = crypto.createHash('sha256');\n hash = hash.update(lockFileBuffer);\n if (appOrAddonInstance) {\n // ensure that the actual running addon names and versions are accounted\n // for in the cache key; this ensures that we still invalidate the cache\n // when linking another project (e.g. ember-source) which would normally\n // not cause the lockfile to change;\n hash = hash.update(gatherAddonCacheKey(appOrAddonInstance.project));\n }\n let cacheKey = hash.digest('hex');\n\n return [\n [join(__dirname, 'babel', 'macros-babel-plugin.js'), opts],\n [\n require.resolve('@embroider/shared-internals/src/babel-plugin-cache-busting.js'),\n { version: cacheKey },\n `@embroider/macros cache buster: ${owningPackageRoot}`,\n ],\n ];\n }\n\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let configs: MacrosConfig | undefined;\n\n let lazyParams = {\n // this is deliberately lazy because we want to allow everyone to finish\n // setting config before we generate the userConfigs\n get configs() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.userConfigs;\n },\n packageRoot: owningPackageRoot,\n get appRoot() {\n if (!configs) {\n throw new Error(`Bug: @embroider/macros ast-transforms were not plugged into a MacrosConfig`);\n }\n return configs.appRoot;\n },\n };\n\n let plugins = [makeFirstTransform(lazyParams), makeSecondTransform()].reverse();\n function setConfig(c: MacrosConfig) {\n configs = c;\n }\n return { plugins, setConfig, lazyParams };\n }\n\n private mergerFor(pkgRoot: string) {\n let entry = this.mergers.get(pkgRoot);\n if (entry) {\n return entry.merger;\n }\n return defaultMergerFor(pkgRoot);\n }\n\n // this exists because @embroider/compat rewrites and moves v1 addons, and\n // their macro configs need to follow them to their new homes.\n packageMoved(oldPath: string, newPath: string) {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to call packageMoved after configs have been finalized`);\n }\n\n this.moves.set(oldPath, newPath);\n }\n\n private moves: Map<string, string> = new Map();\n\n private resolvePackage(fromPath: string, packageName?: string | undefined) {\n let us = this.packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`[Embroider:MacrosConfig] unable to determine which npm package owns the file ${fromPath}`);\n }\n if (packageName) {\n return this.packageCache.resolve(packageName, us);\n } else {\n return us;\n }\n }\n\n finalize() {\n this._configWritable = false;\n }\n}\n\nfunction defaultMergerFor(pkgRoot: string) {\n return function defaultMerger(configs: object[], { sourceOfConfig }: { sourceOfConfig: SourceOfConfig }): object {\n let [ownConfigs, otherConfigs] = partition(configs, c => sourceOfConfig(c as object).root === pkgRoot);\n return Object.assign({}, ...ownConfigs, ...otherConfigs);\n };\n}\n\nfunction isSerializable(obj: object): boolean {\n if (isScalar(obj)) {\n return true;\n }\n\n if (Array.isArray(obj)) {\n return !obj.some((arrayItem: any) => !isSerializable(arrayItem));\n }\n\n if (isPlainObject(obj)) {\n for (let property in obj) {\n let value = obj[property] as any;\n if (!isSerializable(value)) {\n return false;\n }\n }\n\n return true;\n }\n\n console.error('non serializable item found in config:', obj);\n return false;\n}\n\nfunction isScalar(val: any): boolean {\n return (\n typeof val === 'undefined' ||\n typeof val === 'string' ||\n typeof val === 'boolean' ||\n typeof val === 'number' ||\n val === null\n );\n}\n\nfunction isPlainObject(obj: any): obj is Record<string, any> {\n return typeof obj === 'object' && obj.constructor === Object && obj.toString() === '[object Object]';\n}\n"]}
|