@embroider/macros 1.19.6 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +3 -3
- package/src/addon/runtime.js +10 -0
- package/src/babel/macros-babel-plugin.js +29 -0
- package/src/babel/macros-babel-plugin.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -251,6 +251,17 @@ if (macroCondition(isDevelopingApp())) {
|
|
|
251
251
|
|
|
252
252
|
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.
|
|
253
253
|
|
|
254
|
+
#### setTesting
|
|
255
|
+
|
|
256
|
+
To enable test-only code paths at runtime, you can use the `setTesting()` function. This is particularly useful in test setup files to control the behavior of the `isTesting()` macro in development builds.
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
import { setTesting } from '@embroider/macros';
|
|
260
|
+
|
|
261
|
+
// In your test setup file (e.g., test-helper.js):
|
|
262
|
+
setTesting(true);
|
|
263
|
+
```
|
|
264
|
+
|
|
254
265
|
## Glint usage
|
|
255
266
|
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
|
|
256
267
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"assert-never": "^1.2.1",
|
|
30
30
|
"babel-import-util": "^3.0.1",
|
|
31
|
-
"ember-cli-babel": "^7.26.6",
|
|
31
|
+
"ember-cli-babel": "^7.26.6 || ^8.3.1",
|
|
32
32
|
"find-up": "^5.0.0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"resolve": "^1.20.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"typescript": "^5.4.5",
|
|
56
56
|
"vitest": "^3.2.4",
|
|
57
57
|
"@embroider/test-support": "0.36.0",
|
|
58
|
-
"@embroider/core": "4.4.
|
|
58
|
+
"@embroider/core": "4.4.4"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@glint/template": "^1.0.0"
|
package/src/addon/runtime.js
CHANGED
|
@@ -45,6 +45,16 @@ export function isTesting() {
|
|
|
45
45
|
return Boolean(e && e.isTesting);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
export function setTesting(isTesting) {
|
|
49
|
+
if (!runtimeConfig.global) {
|
|
50
|
+
runtimeConfig.global = {};
|
|
51
|
+
}
|
|
52
|
+
if (!runtimeConfig.global['@embroider/macros']) {
|
|
53
|
+
runtimeConfig.global['@embroider/macros'] = {};
|
|
54
|
+
}
|
|
55
|
+
runtimeConfig.global['@embroider/macros'].isTesting = Boolean(isTesting);
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
const runtimeConfig = initializeRuntimeMacrosConfig();
|
|
49
59
|
|
|
50
60
|
// this exists to be targeted by our babel plugin
|
|
@@ -134,6 +134,34 @@ function main(context) {
|
|
|
134
134
|
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
+
if (callee.referencesImport('@embroider/macros', 'setTesting')) {
|
|
138
|
+
state.calledIdentifiers.add(callee.node);
|
|
139
|
+
if (state.opts.mode === 'run-time') {
|
|
140
|
+
callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'setTesting'));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
let args = path.get('arguments');
|
|
144
|
+
if (args.length === 0) {
|
|
145
|
+
throw (0, error_1.default)(path, `setTesting() requires a boolean argument`);
|
|
146
|
+
}
|
|
147
|
+
let arg = args[0];
|
|
148
|
+
let evaluator = new evaluate_json_1.Evaluator({ state });
|
|
149
|
+
let result = evaluator.evaluate(arg);
|
|
150
|
+
if (!result.confident) {
|
|
151
|
+
throw (0, error_1.default)(arg, `setTesting() can only be called with a statically analyzable value in compile-time mode. The argument must be a literal boolean or other macro that can resolves to a boolean at compile-time.`);
|
|
152
|
+
}
|
|
153
|
+
let macrosConfig = state.opts.globalConfig['@embroider/macros'] || {};
|
|
154
|
+
let currentIsTesting = Boolean(macrosConfig.isTesting);
|
|
155
|
+
let newIsTesting = Boolean(result.value);
|
|
156
|
+
if (currentIsTesting !== newIsTesting) {
|
|
157
|
+
throw (0, error_1.default)(path, `setTesting(${newIsTesting}) cannot change the testing state in compile-time mode. The current global config has isTesting=${currentIsTesting}. ` +
|
|
158
|
+
`setTesting() calls are compiled away at build time, so they cannot change the testing state. ` +
|
|
159
|
+
`If you need to change the testing state at runtime, use runtime mode instead.`);
|
|
160
|
+
}
|
|
161
|
+
path.remove();
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
137
165
|
let result = new evaluate_json_1.Evaluator({ state }).evaluateMacroCall(path);
|
|
138
166
|
if (result.confident) {
|
|
139
167
|
state.calledIdentifiers.add(callee.node);
|
|
@@ -225,6 +253,7 @@ function main(context) {
|
|
|
225
253
|
'isDevelopingApp',
|
|
226
254
|
'isDevelopingThisPackage',
|
|
227
255
|
'isTesting',
|
|
256
|
+
'setTesting',
|
|
228
257
|
]) {
|
|
229
258
|
if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {
|
|
230
259
|
throw (0, error_1.default)(path, `You can only use ${candidate} as a function call`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { initState } from './state';\nimport type { Mode as GetConfigMode } from './get-config';\nimport { inlineRuntimeConfig, insertConfig } from './get-config';\nimport macroCondition, { identifyMacroConditionPath } 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';\nimport { existsSync, readdirSync } from 'fs';\nimport { resolve, dirname, join } from 'path';\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(context, path, state);\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 let found = identifyMacroConditionPath(path);\n if (found) {\n state.calledIdentifiers.add(found.callExpression.get('callee').node);\n macroCondition(found, 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' && state.opts.mode === 'run-time') {\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 let relativePath = '';\n let property;\n if (specifier.type === 'TemplateLiteral') {\n relativePath = specifier.quasis[0].value.cooked!;\n property = specifier.expressions[0] as t.Expression;\n }\n // babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id)\n if (\n specifier.type === 'CallExpression' &&\n specifier.callee.type === 'MemberExpression' &&\n specifier.callee.property.type === 'Identifier' &&\n specifier.callee.property.name === 'concat' &&\n specifier.callee.object.type === 'StringLiteral'\n ) {\n relativePath = specifier.callee.object.value;\n property = specifier.arguments[0] as t.Expression;\n }\n if (property && relativePath && relativePath.startsWith('.')) {\n const resolvedPath = resolve(dirname((state as any).filename), relativePath);\n let entries: string[] = [];\n if (existsSync(resolvedPath)) {\n entries = readdirSync(resolvedPath).filter(e => !e.startsWith('.'));\n }\n const obj = t.objectExpression(\n entries.map(e => {\n let key = e.split('.')[0];\n const rest = e.split('.').slice(1, -1);\n if (rest.length) {\n key += `.${rest}`;\n }\n const id = t.callExpression(\n state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'),\n [state.importUtil.import(path, join(relativePath, key).replace(/\\\\/g, '/'), '*')]\n );\n return t.objectProperty(t.stringLiteral(key), id);\n })\n );\n const memberExpr = t.memberExpression(obj, property, true);\n path.replaceWith(memberExpr);\n state.calledIdentifiers.add(callee.node);\n return;\n } else {\n throw new Error(\n `importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier.type}`\n );\n }\n }\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n state.importUtil.import(path, specifier.value, '*'),\n ])\n );\n state.calledIdentifiers.add(callee.node);\n return;\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-compat2'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'appEmberSatisfies',\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 path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberAddon()\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,uBAySC;AAtTD,mCAAoC;AAEpC,6CAAiE;AACjE,qEAA+E;AAC/E,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAE3D,2BAA6C;AAC7C,+BAA8C;AAE9C,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,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAClC,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,CAAC;oBAC/B,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC;SACF;QACD,mCAAmC,EAAE;YACnC,KAAK,CAAC,IAAuD,EAAE,KAAY;gBACzE,IAAI,KAAK,GAAG,IAAA,4CAA0B,EAAC,IAAI,CAAC,CAAC;gBAC7C,IAAI,KAAK,EAAE,CAAC;oBACV,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK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,EACpC,CAAC;gBACD,sEAAsE;gBACtE,uEAAuE;gBACvE,0DAA0D;gBAC1D,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;QACpD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;oBACvC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { initState } from './state';\nimport type { Mode as GetConfigMode } from './get-config';\nimport { inlineRuntimeConfig, insertConfig } from './get-config';\nimport macroCondition, { identifyMacroConditionPath } 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';\nimport { existsSync, readdirSync } from 'fs';\nimport { resolve, dirname, join } from 'path';\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(context, path, state);\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 let found = identifyMacroConditionPath(path);\n if (found) {\n state.calledIdentifiers.add(found.callExpression.get('callee').node);\n macroCondition(found, 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' && state.opts.mode === 'run-time') {\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 if (callee.referencesImport('@embroider/macros', 'setTesting')) {\n state.calledIdentifiers.add(callee.node);\n\n if (state.opts.mode === 'run-time') {\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'setTesting'));\n } else {\n let args = path.get('arguments');\n if (args.length === 0) {\n throw error(path, `setTesting() requires a boolean argument`);\n }\n\n let arg = args[0];\n let evaluator = new Evaluator({ state });\n let result = evaluator.evaluate(arg);\n\n if (!result.confident) {\n throw error(\n arg,\n `setTesting() can only be called with a statically analyzable value in compile-time mode. The argument must be a literal boolean or other macro that can resolves to a boolean at compile-time.`\n );\n }\n\n let macrosConfig = (state.opts.globalConfig['@embroider/macros'] as any) || {};\n let currentIsTesting = Boolean(macrosConfig.isTesting);\n let newIsTesting = Boolean(result.value);\n\n if (currentIsTesting !== newIsTesting) {\n throw error(\n path,\n `setTesting(${newIsTesting}) cannot change the testing state in compile-time mode. The current global config has isTesting=${currentIsTesting}. ` +\n `setTesting() calls are compiled away at build time, so they cannot change the testing state. ` +\n `If you need to change the testing state at runtime, use runtime mode instead.`\n );\n }\n\n path.remove();\n }\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 let relativePath = '';\n let property;\n if (specifier.type === 'TemplateLiteral') {\n relativePath = specifier.quasis[0].value.cooked!;\n property = specifier.expressions[0] as t.Expression;\n }\n // babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id)\n if (\n specifier.type === 'CallExpression' &&\n specifier.callee.type === 'MemberExpression' &&\n specifier.callee.property.type === 'Identifier' &&\n specifier.callee.property.name === 'concat' &&\n specifier.callee.object.type === 'StringLiteral'\n ) {\n relativePath = specifier.callee.object.value;\n property = specifier.arguments[0] as t.Expression;\n }\n if (property && relativePath && relativePath.startsWith('.')) {\n const resolvedPath = resolve(dirname((state as any).filename), relativePath);\n let entries: string[] = [];\n if (existsSync(resolvedPath)) {\n entries = readdirSync(resolvedPath).filter(e => !e.startsWith('.'));\n }\n const obj = t.objectExpression(\n entries.map(e => {\n let key = e.split('.')[0];\n const rest = e.split('.').slice(1, -1);\n if (rest.length) {\n key += `.${rest}`;\n }\n const id = t.callExpression(\n state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'),\n [state.importUtil.import(path, join(relativePath, key).replace(/\\\\/g, '/'), '*')]\n );\n return t.objectProperty(t.stringLiteral(key), id);\n })\n );\n const memberExpr = t.memberExpression(obj, property, true);\n path.replaceWith(memberExpr);\n state.calledIdentifiers.add(callee.node);\n return;\n } else {\n throw new Error(\n `importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier.type}`\n );\n }\n }\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n state.importUtil.import(path, specifier.value, '*'),\n ])\n );\n state.calledIdentifiers.add(callee.node);\n return;\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-compat2'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'appEmberSatisfies',\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 'setTesting',\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 path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberAddon()\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/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare function getOwnConfig<T>(): T;
|
|
|
8
8
|
export declare function getGlobalConfig<T>(): T;
|
|
9
9
|
export declare function isDevelopingApp(): boolean;
|
|
10
10
|
export declare function isTesting(): boolean;
|
|
11
|
+
export declare function setTesting(): boolean;
|
|
11
12
|
export declare function failBuild(message: string): void;
|
|
12
13
|
export declare function moduleExists(packageName: string): boolean;
|
|
13
14
|
import type { HelperLike } from '@glint/template';
|
package/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.getOwnConfig = getOwnConfig;
|
|
|
11
11
|
exports.getGlobalConfig = getGlobalConfig;
|
|
12
12
|
exports.isDevelopingApp = isDevelopingApp;
|
|
13
13
|
exports.isTesting = isTesting;
|
|
14
|
+
exports.setTesting = setTesting;
|
|
14
15
|
exports.failBuild = failBuild;
|
|
15
16
|
exports.moduleExists = moduleExists;
|
|
16
17
|
/*
|
|
@@ -61,6 +62,9 @@ function isDevelopingApp() {
|
|
|
61
62
|
function isTesting() {
|
|
62
63
|
throw new Oops();
|
|
63
64
|
}
|
|
65
|
+
function setTesting() {
|
|
66
|
+
throw new Oops();
|
|
67
|
+
}
|
|
64
68
|
function failBuild(message) {
|
|
65
69
|
throw new Oops(message);
|
|
66
70
|
}
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,2BAA2B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,EAAE,CAAC;AACnB,CAAC;AAED,SAAgB,SAAS;IACvB,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAED,SAAgB,UAAU;IACxB,MAAM,IAAI,IAAI,EAAE,CAAC;AACnB,CAAC;AAED,SAAgB,SAAS,CAAC,OAAe;IACvC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,YAAY,CAAC,WAAmB;IAC9C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;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 appEmberSatisfies(semverRange: string): boolean {\n throw new Oops(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 setTesting(): 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 macroAppEmberSatisfies: HelperLike<{\n Args: { Positional: Parameters<typeof appEmberSatisfies> };\n Return: ReturnType<typeof appEmberSatisfies>;\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"]}
|