@embroider/macros 1.10.0 → 1.10.1-unstable.16dc72c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/package.json +18 -7
- package/src/babel/each.d.ts +2 -2
- package/src/babel/evaluate-json.d.ts +1 -1
- package/src/babel/get-config.d.ts +1 -1
- package/src/babel/get-config.js.map +1 -1
- package/src/babel/macro-condition.d.ts +1 -1
- package/src/babel/state.js.map +1 -1
- package/src/index.d.ts +39 -0
- package/src/index.js.map +1 -1
- package/src/macros-config.d.ts +2 -2
- package/src/macros-config.js +29 -29
- package/src/macros-config.js.map +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A standardized solution for modifying your package's Javascript and Glimmer temp
|
|
|
6
6
|
|
|
7
7
|
Traditionally, Ember addons have a lot of power to run arbitrary code during the build process. This lets them do whatever they need to do, but it also makes them hard to statically analyze and makes them play badly with some tooling (like IDEs).
|
|
8
8
|
|
|
9
|
-
The [Embroider package spec](../../
|
|
9
|
+
The [Embroider package spec](../../docs/spec.md) proposes fixing this by making Ember addons much more static. But they will still need the ability to change themselves in certain ways at app compilation time. Hence this package.
|
|
10
10
|
|
|
11
11
|
This package works in both Embroider and Classical builds, so that addon authors can switch to this newer pattern without disruption.
|
|
12
12
|
|
|
@@ -212,6 +212,23 @@ if (macroCondition(isDevelopingApp()) {
|
|
|
212
212
|
|
|
213
213
|
Note that these can be used in combination - e.g. if you run tests in the production environment, `isTesting()` will be true, but `isDevelopingApp()` will be false.
|
|
214
214
|
|
|
215
|
+
## Glint usage
|
|
216
|
+
If you are using [Glint](https://typed-ember.gitbook.io/glint/) and `environment-ember-loose`, you can add all the macros to your app at once by adding
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import type { EmbroiderMacrosRegistry } from "@embroider/macros";
|
|
220
|
+
```
|
|
221
|
+
to your app's e.g. `types/glint.d.ts` file, and making sure your registry extends from EmbroiderMacrosRegistry:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
declare module '@glint/environment-ember-loose/registry' {
|
|
225
|
+
export default interface Registry
|
|
226
|
+
extends EmbroiderMacrosRegistry {
|
|
227
|
+
// ...
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
215
232
|
## Real world examples
|
|
216
233
|
|
|
217
234
|
Below are a list of addons that have started using `@embroider/macros` so that you can get a feel for common use cases that can be solved via the macro system.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1-unstable.16dc72c",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "jest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@embroider/shared-internals": "2.0.
|
|
26
|
+
"@embroider/shared-internals": "2.0.1-unstable.16dc72c",
|
|
27
27
|
"assert-never": "^1.2.1",
|
|
28
28
|
"babel-import-util": "^1.1.0",
|
|
29
29
|
"ember-cli-babel": "^7.26.6",
|
|
@@ -36,18 +36,29 @@
|
|
|
36
36
|
"@babel/core": "^7.14.5",
|
|
37
37
|
"@babel/plugin-transform-modules-amd": "^7.19.6",
|
|
38
38
|
"@babel/traverse": "^7.14.5",
|
|
39
|
-
"@embroider/core": "2.
|
|
40
|
-
"@embroider/test-support": "
|
|
39
|
+
"@embroider/core": "2.1.2-unstable.16dc72c",
|
|
40
|
+
"@embroider/test-support": "workspace:*",
|
|
41
|
+
"@glint/template": "^1.0.0",
|
|
41
42
|
"@types/babel__core": "^7.1.14",
|
|
42
43
|
"@types/babel__generator": "^7.6.2",
|
|
43
44
|
"@types/babel__template": "^7.4.0",
|
|
45
|
+
"@types/babel__traverse": "^7.18.5",
|
|
46
|
+
"@types/lodash": "^4.14.170",
|
|
44
47
|
"@types/node": "^15.12.2",
|
|
45
48
|
"@types/resolve": "^1.20.0",
|
|
46
49
|
"@types/semver": "^7.3.6",
|
|
47
50
|
"babel-plugin-ember-template-compilation": "^2.0.0",
|
|
48
|
-
"code-equality-assertions": "^0.
|
|
49
|
-
"scenario-tester": "^2.
|
|
50
|
-
"typescript": "
|
|
51
|
+
"code-equality-assertions": "^0.9.0",
|
|
52
|
+
"scenario-tester": "^2.1.2",
|
|
53
|
+
"typescript": "^4.9.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@glint/template": "^1.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@glint/template": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
51
62
|
},
|
|
52
63
|
"engines": {
|
|
53
64
|
"node": "12.* || 14.* || >= 16"
|
package/src/babel/each.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { NodePath } from '@babel/traverse';
|
|
|
2
2
|
import type { types as t } from '@babel/core';
|
|
3
3
|
import State from './state';
|
|
4
4
|
import type * as Babel from '@babel/core';
|
|
5
|
-
|
|
5
|
+
type CallEachExpression = NodePath<t.CallExpression> & {
|
|
6
6
|
get(callee: 'callee'): NodePath<t.Identifier>;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type EachPath = NodePath<t.ForOfStatement> & {
|
|
9
9
|
get(right: 'right'): CallEachExpression;
|
|
10
10
|
};
|
|
11
11
|
export declare function isEachPath(path: NodePath<t.ForOfStatement>): path is EachPath;
|
|
@@ -9,7 +9,7 @@ export interface ConfidentResult {
|
|
|
9
9
|
export interface UnknownResult {
|
|
10
10
|
confident: false;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type EvaluateResult = ConfidentResult | UnknownResult;
|
|
13
13
|
export interface EvaluationEnv {
|
|
14
14
|
knownPaths?: Map<NodePath, EvaluateResult>;
|
|
15
15
|
locals?: {
|
|
@@ -2,7 +2,7 @@ import type { NodePath } from '@babel/traverse';
|
|
|
2
2
|
import State from './state';
|
|
3
3
|
import type * as Babel from '@babel/core';
|
|
4
4
|
import type { types as t } from '@babel/core';
|
|
5
|
-
export
|
|
5
|
+
export type Mode = 'own' | 'getGlobalConfig' | 'package';
|
|
6
6
|
export default function getConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode): unknown;
|
|
7
7
|
export declare function insertConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode, context: typeof Babel): void;
|
|
8
8
|
export declare function inlineRuntimeConfig(path: NodePath<t.FunctionDeclaration>, state: State, context: typeof Babel): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["get-config.ts"],"names":[],"mappings":";;;;;;AAGA,oDAA4B;AAC5B,mDAAyF;AACzF,gEAAuC;AAMvC,SAAS,UAAU,CAAC,IAAgC,EAAE,KAAY,EAAE,IAAuB;IACzF,IAAI,WAA+B,CAAC;IACpC,IAAI,IAAI,KAAK,KAAK,EAAE;QAClB,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,iDAAiD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SAClG;QACD,WAAW,GAAG,SAAS,CAAC;KACzB;SAAM,IAAI,IAAI,KAAK,SAAS,EAAE;QAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,oDAAoD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SACrG;QACD,IAAI,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,WAAW,CAAC,IAAI,KAAK,eAAe,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IAAI,SAAS,GAAG,IAAI,yBAAS,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAErG,OAAO,IAAI,EAAE;QACX,IAAI,UAAU,GAAG,IAAI,CAAC,UAAW,CAAC;QAClC,IAAI,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,UAAU,CAAC,sBAAsB,EAAE,EAAE;YAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAqB,CAAC,KAAK,EAAE,CAAC;SAC9E;QACD,IAAI,GAAG,UAAU,CAAC;KACnB;AACH,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAqC,EAAE,KAAY,EAAE,OAAqB;IAC5G,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG;QAC3B,OAAO,CAAC,KAAK,CAAC,eAAe,CAC3B,IAAA,6BAAa,EAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,CAAC,CAC9F;KACF,CAAC;AACJ,CAAC;AAND,kDAMC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport State from './state';\nimport { PackageCache, Package } from '@embroider/shared-internals';\nimport error from './error';\nimport { Evaluator, assertArray, buildLiterals, ConfidentResult } from './evaluate-json';\nimport assertNever from 'assert-never';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\n\nexport type Mode = 'own' | 'getGlobalConfig' | 'package';\n\nfunction getPackage(path: NodePath<t.CallExpression>, state: State, mode: 'own' | 'package'): { root: string } | null {\n let packageName: string | undefined;\n if (mode === 'own') {\n if (path.node.arguments.length !== 0) {\n throw error(path, `getOwnConfig takes zero arguments, you passed ${path.node.arguments.length}`);\n }\n packageName = undefined;\n } else if (mode === 'package') {\n if (path.node.arguments.length !== 1) {\n throw error(path, `getConfig takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n let packageNode = path.node.arguments[0];\n if (packageNode.type !== 'StringLiteral') {\n throw error(assertArray(path.get('arguments'))[0], `the argument to getConfig must be a string literal`);\n }\n packageName = packageNode.value;\n } else {\n assertNever(mode);\n }\n return targetPackage(state.sourceFile, packageName, state.packageCache);\n}\n\n// this evaluates to the actual value of the config. It can be used directly by the Evaluator.\nexport default function getConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode) {\n let config: unknown | undefined;\n if (mode === 'getGlobalConfig') {\n return state.opts.globalConfig;\n }\n let pkg = getPackage(path, state, mode);\n if (pkg) {\n config = state.opts.userConfigs[pkg.root];\n }\n return config;\n}\n\n// this is the imperative version that's invoked directly by the babel visitor\n// when we encounter getConfig. It's implemented in terms of getConfig so we can\n// be sure we have the same semantics.\nexport function insertConfig(path: NodePath<t.CallExpression>, state: State, mode: Mode, context: typeof Babel) {\n if (state.opts.mode === 'compile-time') {\n let config = getConfig(path, state, mode);\n let collapsed = collapse(path, config);\n let literalResult = buildLiterals(collapsed.config, context);\n collapsed.path.replaceWith(literalResult);\n } else {\n if (mode === 'getGlobalConfig') {\n let callee = path.get('callee');\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'getGlobalConfig'));\n } else {\n let pkg = getPackage(path, state, mode);\n let pkgRoot;\n if (pkg) {\n pkgRoot = context.types.stringLiteral(pkg.root);\n } else {\n pkgRoot = context.types.identifier('undefined');\n }\n path.replaceWith(\n context.types.callExpression(state.importUtil.import(path, state.pathToOurAddon('runtime'), 'config'), [\n pkgRoot,\n ])\n );\n }\n }\n}\n\nfunction targetPackage(fromPath: string, packageName: string | undefined, packageCache: PackageCache): Package | null {\n let us = packageCache.ownerOfFile(fromPath);\n if (!us) {\n throw new Error(`unable to determine which npm package owns the file ${fromPath}`);\n }\n if (!packageName) {\n return us;\n }\n try {\n return packageCache.resolve(packageName, us);\n } catch (err) {\n return null;\n }\n}\n\nfunction collapse(path: NodePath, config: any) {\n let evaluator = new Evaluator({ knownPaths: new Map([[path, { confident: true, value: config }]]) });\n\n while (true) {\n let parentPath = path.parentPath!;\n let result = evaluator.evaluate(parentPath);\n if (!result.confident || parentPath.isAssignmentExpression()) {\n return { path, config: (evaluator.evaluate(path) as ConfidentResult).value };\n }\n path = parentPath;\n }\n}\n\nexport function inlineRuntimeConfig(path: NodePath<t.FunctionDeclaration>, state: State, context: typeof Babel) {\n path.get('body').node.body = [\n context.types.returnStatement(\n buildLiterals({ packages: state.opts.userConfigs, global: state.opts.globalConfig }, context)\n ),\n ];\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse';
|
|
2
2
|
import type { types as t } from '@babel/core';
|
|
3
3
|
import State from './state';
|
|
4
|
-
export
|
|
4
|
+
export type MacroConditionPath = NodePath<t.IfStatement | t.ConditionalExpression> & {
|
|
5
5
|
get(test: 'test'): NodePath<t.CallExpression> & {
|
|
6
6
|
get(callee: 'callee'): NodePath<t.Identifier>;
|
|
7
7
|
};
|
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;AACtF,yDAA+C;AA8C/C,SAAgB,SAAS,CAAC,CAAqB,EAAE,IAAmC,EAAE,KAAY;IAChG,KAAK,CAAC,UAAU,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,IAAI,GAAG,EAAE,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,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAEjE,SAAS,WAAW,CAAc,UAAkB;IAClD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAChC,kEAAkE;QAClE,OAAO,IAAA,mCAAgB,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAA,WAAI,EAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC;KACvF;SAAM;QACL,sEAAsE;QACtE,aAAa;QACb,EAAE;QACF,qEAAqE;QACrE,yEAAyE;QACzE,4EAA4E;QAC5E,0EAA0E;QAC1E,eAAe;QACf,OAAO,qBAAqB,UAAU,EAAE,CAAC;KAC1C;AACH,CAAC;AAED,SAAS,aAAa;IACpB,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;KAC3F;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,SAAS,CAAc,IAAU;IACxC,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,OAAO,IAAA,uBAAa,EAAC,IAAI,EAAE,UAAU,KAAU;QAC7C,IAAI,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACtC,IAAI,MAAM,GAAG,IAAA,mBAAe,EAAC,KAAK,CAAC,CAAC;YACpC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpC,OAAO,MAAM,CAAC;SACf;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport cloneDeepWith from 'lodash/cloneDeepWith';\nimport lodashCloneDeep from 'lodash/cloneDeep';\nimport { join, dirname, resolve } from 'path';\nimport { explicitRelative, Package, PackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\nimport type * as Babel from '@babel/core';\n\nexport default interface State {\n importUtil: ImportUtil;\n generatedRequires: Set<Node>;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n packageCache: PackageCache;\n sourceFile: string;\n pathToOurAddon(moduleName: string): string;\n owningPackage(): Package;\n cloneDeep(node: Node): Node;\n\n opts: {\n userConfigs: {\n [pkgRoot: string]: unknown;\n };\n globalConfig: {\n [key: string]: unknown;\n };\n // we set this when we're running inside classic ember-cli, because in that\n // case we don't have finer-grained info available about where the files\n // we're processing are globally located. When running in embroider, we\n // don't set this, because each file is visible at its full\n // globally-relevant path.\n owningPackageRoot: string | undefined;\n\n // list of packages that are under active development, represented by the\n // path to their package root directory\n isDevelopingPackageRoots: string[];\n\n // the package root directory of the app. Needed so that we can get\n // consistent answers to `isDevelopingApp` and `isDeveopingThisPackage`, as\n // well as consistent handling of Package devDependencies vs dependencies.\n appPackageRoot: string;\n\n embroiderMacrosConfigMarker: true;\n\n mode: 'compile-time' | 'run-time';\n\n importSyncImplementation: 'cjs' | 'eager';\n };\n}\n\nexport function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State) {\n state.importUtil = new ImportUtil(t, path);\n state.generatedRequires = new Set();\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);\n state.sourceFile = state.opts.owningPackageRoot || (path.hub as any).file.opts.filename;\n state.pathToOurAddon = pathToAddon;\n state.owningPackage = owningPackage;\n state.cloneDeep = cloneDeep;\n}\n\nconst runtimeAddonPath = resolve(join(__dirname, '..', 'addon'));\n\nfunction pathToAddon(this: State, moduleName: string): string {\n if (!this.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n return explicitRelative(dirname(this.sourceFile), join(runtimeAddonPath, moduleName));\n } else {\n // running inside a classic build, so use a classic-compatible runtime\n // specifier.\n //\n // CAUTION: the module we're pointing at here gets merged between all\n // present versions of @embroider/macros, and one will win. So if you are\n // introducing incompatible changes to its API, you need to change this name\n // (by tacking on a version number, etc) and rename the corresponding file\n // in ../addon.\n return `@embroider/macros/${moduleName}`;\n }\n}\n\nfunction owningPackage(this: State): Package {\n let pkg = this.packageCache.ownerOfFile(this.sourceFile);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);\n }\n return pkg;\n}\n\nfunction cloneDeep(this: State, node: Node): Node {\n let state = this;\n return cloneDeepWith(node, function (value: any) {\n if (state.generatedRequires.has(value)) {\n let cloned = lodashCloneDeep(value);\n state.generatedRequires.add(cloned);\n return cloned;\n }\n });\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -9,3 +9,42 @@ export declare function isDevelopingApp(): boolean;
|
|
|
9
9
|
export declare function isTesting(): boolean;
|
|
10
10
|
export declare function failBuild(message: string): void;
|
|
11
11
|
export declare function moduleExists(packageName: string): boolean;
|
|
12
|
+
import type { HelperLike } from '@glint/template';
|
|
13
|
+
export interface EmbroiderMacrosRegistry {
|
|
14
|
+
macroGetOwnConfig: HelperLike<{
|
|
15
|
+
Args: {
|
|
16
|
+
Positional: [...keys: string[]];
|
|
17
|
+
};
|
|
18
|
+
Return: ReturnType<typeof getOwnConfig>;
|
|
19
|
+
}>;
|
|
20
|
+
macroGetConfig: HelperLike<{
|
|
21
|
+
Args: {
|
|
22
|
+
Positional: [packageName: string, ...keys: string[]];
|
|
23
|
+
};
|
|
24
|
+
Return: ReturnType<typeof getConfig>;
|
|
25
|
+
}>;
|
|
26
|
+
macroCondition: HelperLike<{
|
|
27
|
+
Args: {
|
|
28
|
+
Positional: [predicate: boolean];
|
|
29
|
+
};
|
|
30
|
+
Return: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
macroDependencySatisfies: HelperLike<{
|
|
33
|
+
Args: {
|
|
34
|
+
Positional: Parameters<typeof dependencySatisfies>;
|
|
35
|
+
};
|
|
36
|
+
Return: ReturnType<typeof dependencySatisfies>;
|
|
37
|
+
}>;
|
|
38
|
+
macroMaybeAttrs: HelperLike<{
|
|
39
|
+
Args: {
|
|
40
|
+
Positional: [predicate: boolean, ...bareAttrs: unknown[]];
|
|
41
|
+
};
|
|
42
|
+
Return: void;
|
|
43
|
+
}>;
|
|
44
|
+
macroFailBuild: HelperLike<{
|
|
45
|
+
Args: {
|
|
46
|
+
Positional: Parameters<typeof failBuild>;
|
|
47
|
+
};
|
|
48
|
+
Return: ReturnType<typeof failBuild>;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;AAE3B;;;;;;;;;;;;;;EAcE;AAEF,SAAgB,mBAAmB,CAAC,WAAmB,EAAE,WAAmB;IAC1E,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAFD,kDAEC;AAED,SAAgB,cAAc,CAAC,SAAkB;IAC/C,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC;AAFD,wCAEC;AAED,SAAgB,IAAI,CAAI,KAAU;IAChC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAFD,oBAEC;AAED,4BAA4B;AAC5B,mFAAmF;AACnF,kDAAkD;AAClD,SAAgB,UAAU,CAAC,SAAiB;IAC1C,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAI,WAAmB;IAC9C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY;IAC1B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,oCAEC;AAED,SAAgB,eAAe;IAC7B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,0CAEC;AAED,SAAgB,eAAe;IAC7B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,0CAEC;AAED,SAAgB,SAAS;IACvB,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,8BAEC;AAED,SAAgB,SAAS,CAAC,OAAe;IACvC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY,CAAC,WAAmB;IAC9C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAFD,oCAEC;AAED,MAAM,IAAK,SAAQ,KAAK;IAEtB,YAAY,GAAG,MAAa;QAC1B,KAAK,CACH,6HAA6H,CAC9H,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["/* Macro Type Signatures */\n\n/*\n CAUTION: this code is not necessarily what you are actually running. In\n general, the macros are implemented at build time using babel, and so calls to\n these functions get compiled away before they ever run. However, this code is\n here because it provides types to typescript users of the macros.\n\n Some macros also have runtime implementations that are useful in development\n mode, in addition to their build-time implementations in babel. You can find\n the runtime implementations in runtime.ts.\n\n Having a runtime mode lets us do things like produce a single build in\n development that works for both fastboot and browser, using the macros to\n switch between modes. For production, you would switch to the build-time macro\n implementation to get two optimized builds instead.\n*/\n\nexport function dependencySatisfies(packageName: string, semverRange: string): boolean {\n throw new Oops(packageName, semverRange);\n}\n\nexport function macroCondition(predicate: boolean): boolean {\n throw new Oops(predicate);\n}\n\nexport function each<T>(array: T[]): T[] {\n throw new Oops(array);\n}\n\n// We would prefer to write:\n// export function importSync<T extends string>(specifier: T): typeof import(T) {\n// but TS doesn't seem to support that at present.\nexport function importSync(specifier: string): unknown {\n throw new Oops(specifier);\n}\n\nexport function getConfig<T>(packageName: string): T {\n throw new Oops(packageName);\n}\n\nexport function getOwnConfig<T>(): T {\n throw new Oops();\n}\n\nexport function getGlobalConfig<T>(): T {\n throw new Oops();\n}\n\nexport function isDevelopingApp(): boolean {\n throw new Oops();\n}\n\nexport function isTesting(): boolean {\n throw new Oops();\n}\n\nexport function failBuild(message: string): void {\n throw new Oops(message);\n}\n\nexport function moduleExists(packageName: string): boolean {\n throw new Oops(packageName);\n}\n\nclass Oops extends Error {\n params: any[];\n constructor(...params: any[]) {\n super(\n `this method is really implemented at compile time via a babel plugin. If you're seeing this exception, something went wrong`\n );\n this.params = params;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;AAE3B;;;;;;;;;;;;;;EAcE;AAEF,SAAgB,mBAAmB,CAAC,WAAmB,EAAE,WAAmB;IAC1E,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAFD,kDAEC;AAED,SAAgB,cAAc,CAAC,SAAkB;IAC/C,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC;AAFD,wCAEC;AAED,SAAgB,IAAI,CAAI,KAAU;IAChC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAFD,oBAEC;AAED,4BAA4B;AAC5B,mFAAmF;AACnF,kDAAkD;AAClD,SAAgB,UAAU,CAAC,SAAiB;IAC1C,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAI,WAAmB;IAC9C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY;IAC1B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,oCAEC;AAED,SAAgB,eAAe;IAC7B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,0CAEC;AAED,SAAgB,eAAe;IAC7B,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,0CAEC;AAED,SAAgB,SAAS;IACvB,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAFD,8BAEC;AAED,SAAgB,SAAS,CAAC,OAAe;IACvC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,8BAEC;AAED,SAAgB,YAAY,CAAC,WAAmB;IAC9C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAFD,oCAEC;AAED,MAAM,IAAK,SAAQ,KAAK;IAEtB,YAAY,GAAG,MAAa;QAC1B,KAAK,CACH,6HAA6H,CAC9H,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["/* Macro Type Signatures */\n\n/*\n CAUTION: this code is not necessarily what you are actually running. In\n general, the macros are implemented at build time using babel, and so calls to\n these functions get compiled away before they ever run. However, this code is\n here because it provides types to typescript users of the macros.\n\n Some macros also have runtime implementations that are useful in development\n mode, in addition to their build-time implementations in babel. You can find\n the runtime implementations in runtime.ts.\n\n Having a runtime mode lets us do things like produce a single build in\n development that works for both fastboot and browser, using the macros to\n switch between modes. For production, you would switch to the build-time macro\n implementation to get two optimized builds instead.\n*/\n\nexport function dependencySatisfies(packageName: string, semverRange: string): boolean {\n throw new Oops(packageName, semverRange);\n}\n\nexport function macroCondition(predicate: boolean): boolean {\n throw new Oops(predicate);\n}\n\nexport function each<T>(array: T[]): T[] {\n throw new Oops(array);\n}\n\n// We would prefer to write:\n// export function importSync<T extends string>(specifier: T): typeof import(T) {\n// but TS doesn't seem to support that at present.\nexport function importSync(specifier: string): unknown {\n throw new Oops(specifier);\n}\n\nexport function getConfig<T>(packageName: string): T {\n throw new Oops(packageName);\n}\n\nexport function getOwnConfig<T>(): T {\n throw new Oops();\n}\n\nexport function getGlobalConfig<T>(): T {\n throw new Oops();\n}\n\nexport function isDevelopingApp(): boolean {\n throw new Oops();\n}\n\nexport function isTesting(): boolean {\n throw new Oops();\n}\n\nexport function failBuild(message: string): void {\n throw new Oops(message);\n}\n\nexport function moduleExists(packageName: string): boolean {\n throw new Oops(packageName);\n}\n\nclass Oops extends Error {\n params: any[];\n constructor(...params: any[]) {\n super(\n `this method is really implemented at compile time via a babel plugin. If you're seeing this exception, something went wrong`\n );\n this.params = params;\n }\n}\n\nimport type { HelperLike } from '@glint/template';\n\nexport interface EmbroiderMacrosRegistry {\n macroGetOwnConfig: HelperLike<{\n Args: { Positional: [...keys: string[]] };\n Return: ReturnType<typeof getOwnConfig>;\n }>;\n macroGetConfig: HelperLike<{\n Args: { Positional: [packageName: string, ...keys: string[]] };\n Return: ReturnType<typeof getConfig>;\n }>;\n macroCondition: HelperLike<{\n Args: { Positional: [predicate: boolean] };\n Return: boolean;\n }>;\n macroDependencySatisfies: HelperLike<{\n Args: { Positional: Parameters<typeof dependencySatisfies> };\n Return: ReturnType<typeof dependencySatisfies>;\n }>;\n macroMaybeAttrs: HelperLike<{\n Args: { Positional: [predicate: boolean, ...bareAttrs: unknown[]] };\n Return: void;\n }>;\n macroFailBuild: HelperLike<{\n Args: { Positional: Parameters<typeof failBuild> };\n Return: ReturnType<typeof failBuild>;\n }>;\n}\n"]}
|
package/src/macros-config.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { PluginItem } from '@babel/core';
|
|
2
2
|
import { FirstTransformParams } from './glimmer/ast-transform';
|
|
3
|
-
export
|
|
3
|
+
export type SourceOfConfig = (config: object) => {
|
|
4
4
|
readonly name: string;
|
|
5
5
|
readonly root: string;
|
|
6
6
|
readonly version: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type Merger = (configs: object[], params: {
|
|
9
9
|
sourceOfConfig: SourceOfConfig;
|
|
10
10
|
}) => object;
|
|
11
11
|
export default class MacrosConfig {
|
package/src/macros-config.js
CHANGED
|
@@ -42,35 +42,6 @@ function gatherAddonCacheKey(project) {
|
|
|
42
42
|
return cacheKey;
|
|
43
43
|
}
|
|
44
44
|
class MacrosConfig {
|
|
45
|
-
constructor(origAppRoot) {
|
|
46
|
-
this.origAppRoot = origAppRoot;
|
|
47
|
-
this.mode = 'compile-time';
|
|
48
|
-
this.globalConfig = {};
|
|
49
|
-
this.isDevelopingPackageRoots = new Set();
|
|
50
|
-
this._importSyncImplementation = 'cjs';
|
|
51
|
-
this._configWritable = true;
|
|
52
|
-
this.configs = new Map();
|
|
53
|
-
this.configSources = new WeakMap();
|
|
54
|
-
this.mergers = new Map();
|
|
55
|
-
this.moves = new Map();
|
|
56
|
-
// this uses globalConfig because these things truly are global. Even if a
|
|
57
|
-
// package doesn't have a dep or peerDep on @embroider/macros, it's legit
|
|
58
|
-
// for them to want to know the answer to these questions, and there is only
|
|
59
|
-
// one answer throughout the whole dependency graph.
|
|
60
|
-
this.globalConfig['@embroider/macros'] = {
|
|
61
|
-
// this powers the `isTesting` macro. It always starts out false here,
|
|
62
|
-
// because:
|
|
63
|
-
// - if this is a production build, we will evaluate all macros at build
|
|
64
|
-
// time and isTesting will stay false, so test-only code will not be
|
|
65
|
-
// included.
|
|
66
|
-
// - if this is a dev build, we evaluate macros at runtime, which allows
|
|
67
|
-
// both "I'm running my app in development" and "I'm running my test
|
|
68
|
-
// suite" to coexist within a single build. When you run the test
|
|
69
|
-
// suite, early in the runtime boot process we can flip isTesting to
|
|
70
|
-
// true to distinguish the two.
|
|
71
|
-
isTesting: false,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
45
|
static for(key, appRoot) {
|
|
75
46
|
let found = localSharedState.get(key);
|
|
76
47
|
if (found) {
|
|
@@ -128,6 +99,35 @@ class MacrosConfig {
|
|
|
128
99
|
}
|
|
129
100
|
this._importSyncImplementation = value;
|
|
130
101
|
}
|
|
102
|
+
constructor(origAppRoot) {
|
|
103
|
+
this.origAppRoot = origAppRoot;
|
|
104
|
+
this.mode = 'compile-time';
|
|
105
|
+
this.globalConfig = {};
|
|
106
|
+
this.isDevelopingPackageRoots = new Set();
|
|
107
|
+
this._importSyncImplementation = 'cjs';
|
|
108
|
+
this._configWritable = true;
|
|
109
|
+
this.configs = new Map();
|
|
110
|
+
this.configSources = new WeakMap();
|
|
111
|
+
this.mergers = new Map();
|
|
112
|
+
this.moves = new Map();
|
|
113
|
+
// this uses globalConfig because these things truly are global. Even if a
|
|
114
|
+
// package doesn't have a dep or peerDep on @embroider/macros, it's legit
|
|
115
|
+
// for them to want to know the answer to these questions, and there is only
|
|
116
|
+
// one answer throughout the whole dependency graph.
|
|
117
|
+
this.globalConfig['@embroider/macros'] = {
|
|
118
|
+
// this powers the `isTesting` macro. It always starts out false here,
|
|
119
|
+
// because:
|
|
120
|
+
// - if this is a production build, we will evaluate all macros at build
|
|
121
|
+
// time and isTesting will stay false, so test-only code will not be
|
|
122
|
+
// included.
|
|
123
|
+
// - if this is a dev build, we evaluate macros at runtime, which allows
|
|
124
|
+
// both "I'm running my app in development" and "I'm running my test
|
|
125
|
+
// suite" to coexist within a single build. When you run the test
|
|
126
|
+
// suite, early in the runtime boot process we can flip isTesting to
|
|
127
|
+
// true to distinguish the two.
|
|
128
|
+
isTesting: false,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
131
|
get packageCache() {
|
|
132
132
|
return shared_internals_1.PackageCache.shared('embroider-macros', this.origAppRoot);
|
|
133
133
|
}
|
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,CA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AAC;YACjC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;gBAC1B,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,CACL,OAAO,GAAG,KAAK,WAAW;QAC1B,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,SAAS;QACxB,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI,CACb,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,GAAQ;IAC7B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,iBAAiB,CAAC;AACvG,CAAC","sourcesContent":["import fs from 'fs';\nimport { join } from 'path';\nimport crypto from 'crypto';\nimport findUp from 'find-up';\nimport type { PluginItem } from '@babel/core';\nimport { PackageCache, getOrCreate } from '@embroider/shared-internals';\nimport { FirstTransformParams, makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';\nimport State from './babel/state';\nimport partition from 'lodash/partition';\n\nexport type SourceOfConfig = (config: object) => {\n readonly name: string;\n readonly root: string;\n readonly version: string;\n};\n\nexport type Merger = (\n configs: object[],\n params: {\n sourceOfConfig: SourceOfConfig;\n }\n) => object;\n\n// Do not change this type signature without pondering deeply the mysteries of\n// being compatible with unwritten future versions of this library.\ntype GlobalSharedState = WeakMap<\n any,\n {\n configs: Map<string, object[]>;\n configSources: WeakMap<object, string>;\n mergers: Map<string, { merger: Merger; fromPath: string }>;\n }\n>;\n\n// this is a module-scoped cache. If multiple callers ask _this copy_ of\n// @embroider/macros for a shared MacrosConfig, they'll all get the same one.\n// And if somebody asks a *different* copy of @embroider/macros for the shared\n// MacrosConfig, it will have its own instance with its own code, but will still\n// share the GlobalSharedState beneath.\nlet localSharedState: WeakMap<any, MacrosConfig> = new WeakMap();\n\nfunction gatherAddonCacheKeyWorker(item: any, memo: Set<string>) {\n item.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n}\n\nlet addonCacheKey: WeakMap<any, string> = new WeakMap();\n// creates a string representing all addons and their versions\n// (foo@1.0.0|bar@2.0.0) to use as a cachekey\nfunction gatherAddonCacheKey(project: any): string {\n let cacheKey = addonCacheKey.get(project);\n if (cacheKey) {\n return cacheKey;\n }\n\n let memo: Set<string> = new Set();\n project.addons.forEach((addon: any) => {\n let key = `${addon.pkg.name}@${addon.pkg.version}`;\n memo.add(key);\n gatherAddonCacheKeyWorker(addon, memo);\n });\n\n cacheKey = [...memo].join('|');\n addonCacheKey.set(project, cacheKey);\n\n return cacheKey;\n}\n\nexport default class MacrosConfig {\n static for(key: any, appRoot: string): MacrosConfig {\n let found = localSharedState.get(key);\n if (found) {\n return found;\n }\n\n let g = global as any as { __embroider_macros_global__: GlobalSharedState | undefined };\n if (!g.__embroider_macros_global__) {\n g.__embroider_macros_global__ = new WeakMap();\n }\n\n let shared = g.__embroider_macros_global__.get(key);\n if (shared) {\n // if an earlier version of @embroider/macros created the shared state, it\n // would have configSources.\n if (!shared.configSources) {\n shared.configSources = new WeakMap();\n }\n } else {\n shared = {\n configs: new Map(),\n configSources: new WeakMap(),\n mergers: new Map(),\n };\n g.__embroider_macros_global__.set(key, shared);\n }\n\n let config = new MacrosConfig(appRoot);\n config.configs = shared.configs;\n config.configSources = shared.configSources;\n config.mergers = shared.mergers;\n localSharedState.set(key, config);\n return config;\n }\n\n private mode: 'compile-time' | 'run-time' = 'compile-time';\n private globalConfig: { [key: string]: unknown } = {};\n\n private isDevelopingPackageRoots: Set<string> = new Set();\n\n enableRuntimeMode() {\n if (this.mode !== 'run-time') {\n if (!this._configWritable) {\n throw new Error(`[Embroider:MacrosConfig] attempted to enableRuntimeMode after configs have been finalized`);\n }\n this.mode = 'run-time';\n }\n }\n\n enablePackageDevelopment(packageRoot: string) {\n if (!this.isDevelopingPackageRoots.has(packageRoot)) {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to enablePackageDevelopment after configs have been finalized`\n );\n }\n this.isDevelopingPackageRoots.add(packageRoot);\n }\n }\n\n private _importSyncImplementation: 'cjs' | 'eager' = 'cjs';\n\n get importSyncImplementation() {\n return this._importSyncImplementation;\n }\n\n set importSyncImplementation(value: 'cjs' | 'eager') {\n if (!this._configWritable) {\n throw new Error(\n `[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`\n );\n }\n this._importSyncImplementation = value;\n }\n\n private constructor(private origAppRoot: 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 }\n\n private get packageCache() {\n return PackageCache.shared('embroider-macros', this.origAppRoot);\n }\n\n private get appRoot(): string {\n return this.moves.get(this.origAppRoot) ?? this.origAppRoot;\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\n // lazy so that packageMoved() can still affect this\n get appPackageRoot() {\n return self.appRoot;\n },\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: self.appRoot });\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 // provides the ast plugins that implement the macro system, in reverse order\n // for compatibility with the classic build, which historically always ran ast\n // plugins in backwards order.\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let result = this.transforms(owningPackageRoot);\n result.plugins.reverse();\n return result;\n }\n\n // todo: type adjuments here\n // provides the ast plugins that implement the macro system\n static transforms(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()];\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"]}
|
|
1
|
+
{"version":3,"file":"macros-config.js","sourceRoot":"","sources":["macros-config.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA4B;AAC5B,oDAA4B;AAC5B,sDAA6B;AAE7B,kEAAwE;AACxE,2DAAwG;AAExG,iEAAyC;AA0BzC,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,uCAAuC;AACvC,IAAI,gBAAgB,GAA+B,IAAI,OAAO,EAAE,CAAC;AAEjE,SAAS,yBAAyB,CAAC,IAAS,EAAE,IAAiB;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;QACjC,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACnD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,aAAa,GAAyB,IAAI,OAAO,EAAE,CAAC;AACxD,8DAA8D;AAC9D,6CAA6C;AAC7C,SAAS,mBAAmB,CAAC,OAAY;IACvC,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC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,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 constructor(private origAppRoot: 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 }\n\n private get packageCache() {\n return PackageCache.shared('embroider-macros', this.origAppRoot);\n }\n\n private get appRoot(): string {\n return this.moves.get(this.origAppRoot) ?? this.origAppRoot;\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\n // lazy so that packageMoved() can still affect this\n get appPackageRoot() {\n return self.appRoot;\n },\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: self.appRoot });\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 // provides the ast plugins that implement the macro system, in reverse order\n // for compatibility with the classic build, which historically always ran ast\n // plugins in backwards order.\n static astPlugins(owningPackageRoot?: string): {\n plugins: Function[];\n setConfig: (config: MacrosConfig) => void;\n lazyParams: FirstTransformParams;\n } {\n let result = this.transforms(owningPackageRoot);\n result.plugins.reverse();\n return result;\n }\n\n // todo: type adjuments here\n // provides the ast plugins that implement the macro system\n static transforms(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()];\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"]}
|