@embroider/macros 1.12.3-unstable.ef70747 → 1.12.3
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/LICENSE +21 -0
- package/README.md +2 -2
- package/package.json +10 -10
- package/src/babel/dependency-satisfies.js +1 -1
- package/src/babel/dependency-satisfies.js.map +1 -1
- package/src/babel/macros-babel-plugin.js +1 -1
- package/src/babel/macros-babel-plugin.js.map +1 -1
- package/src/glimmer/dependency-satisfies.js +1 -1
- package/src/glimmer/dependency-satisfies.js.map +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Edward Faulkner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -197,13 +197,13 @@ These methods can be used in conjunction with `macroCondition` to tree-shake cod
|
|
|
197
197
|
```js
|
|
198
198
|
import { isTesting, isDevelopingApp, macroCondition } from '@embroider/macros';
|
|
199
199
|
|
|
200
|
-
if (macroCondition(isTesting()) {
|
|
200
|
+
if (macroCondition(isTesting())) {
|
|
201
201
|
// some test code - stripped out when not running tests
|
|
202
202
|
} else {
|
|
203
203
|
// some non-test code
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
if (macroCondition(isDevelopingApp()) {
|
|
206
|
+
if (macroCondition(isDevelopingApp())) {
|
|
207
207
|
// some code when app is in development environment - stripped out in production builds
|
|
208
208
|
} else {
|
|
209
209
|
// some production code
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.12.3
|
|
3
|
+
"version": "1.12.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -19,25 +19,20 @@
|
|
|
19
19
|
"src/**/*.d.ts",
|
|
20
20
|
"src/**/*.js.map"
|
|
21
21
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "jest"
|
|
24
|
-
},
|
|
25
22
|
"dependencies": {
|
|
26
|
-
"@embroider/shared-internals": "2.2.3-unstable.ef70747",
|
|
27
23
|
"assert-never": "^1.2.1",
|
|
28
24
|
"babel-import-util": "^1.1.0",
|
|
29
25
|
"ember-cli-babel": "^7.26.6",
|
|
30
26
|
"find-up": "^5.0.0",
|
|
31
27
|
"lodash": "^4.17.21",
|
|
32
28
|
"resolve": "^1.20.0",
|
|
33
|
-
"semver": "^7.3.2"
|
|
29
|
+
"semver": "^7.3.2",
|
|
30
|
+
"@embroider/shared-internals": "2.2.3"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@babel/core": "^7.14.5",
|
|
37
34
|
"@babel/plugin-transform-modules-amd": "^7.19.6",
|
|
38
35
|
"@babel/traverse": "^7.14.5",
|
|
39
|
-
"@embroider/core": "3.1.3-unstable.ef70747",
|
|
40
|
-
"@embroider/test-support": "workspace:*",
|
|
41
36
|
"@glint/template": "^1.0.0",
|
|
42
37
|
"@types/babel__core": "^7.1.14",
|
|
43
38
|
"@types/babel__generator": "^7.6.2",
|
|
@@ -50,7 +45,9 @@
|
|
|
50
45
|
"babel-plugin-ember-template-compilation": "^2.0.0",
|
|
51
46
|
"code-equality-assertions": "^0.9.0",
|
|
52
47
|
"scenario-tester": "^2.1.2",
|
|
53
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^5.1.6",
|
|
49
|
+
"@embroider/core": "3.1.3",
|
|
50
|
+
"@embroider/test-support": "0.36.0"
|
|
54
51
|
},
|
|
55
52
|
"peerDependencies": {
|
|
56
53
|
"@glint/template": "^1.0.0"
|
|
@@ -68,5 +65,8 @@
|
|
|
68
65
|
},
|
|
69
66
|
"volta": {
|
|
70
67
|
"extends": "../../package.json"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"test": "jest"
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
}
|
|
@@ -19,7 +19,7 @@ function dependencySatisfies(path, state) {
|
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
let us = state.packageCache.ownerOfFile(state.sourceFile);
|
|
22
|
-
if (!us
|
|
22
|
+
if (!(us === null || us === void 0 ? void 0 : us.hasDependency(packageName.value))) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
let version = state.packageCache.resolve(packageName.value, us).version;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAGA,mCAAmC;AACnC,oDAA4B;AAC5B,mDAA8C;AAE9C,SAAwB,mBAAmB,CA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;AACH,CAAC;AAjCD,sCAiCC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nexport default function dependencySatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 2) {\n throw error(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);\n }\n const [packageName, range] = path.node.arguments;\n if (packageName.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the first argument to dependencySatisfies must be a string literal`\n );\n }\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[1],\n `the second argument to dependencySatisfies must be a string literal`\n );\n }\n try {\n let us = state.packageCache.ownerOfFile(state.sourceFile);\n if (!us?.hasDependency(packageName.value)) {\n return false;\n }\n\n let version = state.packageCache.resolve(packageName.value, us).version;\n return satisfies(version, range.value, {\n includePrerelease: true,\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;;;;AAGA,mCAAmC;AACnC,oDAA4B;AAC5B,mDAA8C;AAE9C,SAAwB,mBAAmB,CAAC,IAAgC,EAAE,KAAY;IACxF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,+DAA+D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KAChH;IACD,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACjD,IAAI,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE;QACxC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,oEAAoE,CACrE,CAAC;KACH;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE;QAClC,MAAM,IAAA,eAAK,EACT,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC,qEAAqE,CACtE,CAAC;KACH;IACD,IAAI;QACF,IAAI,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA,EAAE;YACzC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;QACxE,OAAO,IAAA,kBAAS,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE;YACrC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnC,MAAM,GAAG,CAAC;SACX;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAjCD,sCAiCC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nexport default function dependencySatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 2) {\n throw error(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);\n }\n const [packageName, range] = path.node.arguments;\n if (packageName.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the first argument to dependencySatisfies must be a string literal`\n );\n }\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[1],\n `the second argument to dependencySatisfies must be a string literal`\n );\n }\n try {\n let us = state.packageCache.ownerOfFile(state.sourceFile);\n if (!us?.hasDependency(packageName.value)) {\n return false;\n }\n\n let version = state.packageCache.resolve(packageName.value, us).version;\n return satisfies(version, range.value, {\n includePrerelease: true,\n });\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
|
|
@@ -139,7 +139,7 @@ function main(context) {
|
|
|
139
139
|
if (callee.referencesImport('@embroider/macros', 'importSync')) {
|
|
140
140
|
if (state.opts.importSyncImplementation === 'eager') {
|
|
141
141
|
let specifier = path.node.arguments[0];
|
|
142
|
-
if (specifier
|
|
142
|
+
if ((specifier === null || specifier === void 0 ? void 0 : specifier.type) !== 'StringLiteral') {
|
|
143
143
|
throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);
|
|
144
144
|
}
|
|
145
145
|
path.replaceWith(state.importUtil.import(path, specifier.value, '*'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAA2C;AAC3C,6CAAwF;AACxF,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAG3D,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG;QACZ,OAAO,EAAE;YACP,KAAK,CAAC,IAAyB,EAAE,KAAY;gBAC3C,IAAA,iBAAS,EAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5B,CAAC;YACD,IAAI,CAAC,CAAsB,EAAE,KAAY;gBACvC,iFAAiF;gBAC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AAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACzE;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE;QACnD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;oBACtC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE;wBACpB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;qBACxD;iBACF;YACH,CAAC;SACF,CAAC;KACH;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AA9MD,uBA8MC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State, { initState } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && 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 throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n path.replaceWith(state.importUtil.import(path, specifier.value, '*'));\n state.calledIdentifiers.add(callee.node);\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberPackage()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"macros-babel-plugin.js","sourceRoot":"","sources":["macros-babel-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAA2C;AAC3C,6CAAwF;AACxF,qEAAyE;AACzE,iCAAgD;AAEhD,oDAA4B;AAC5B,8DAAqC;AACrC,mDAA2D;AAG3D,SAAwB,IAAI,CAAC,OAAqB;IAChD,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IAC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AAI,CAAC;gBACvC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC;gBACjC,KAAK,CAAC,aAAa,EAAE,CAAC,cAAc,EAAE,EACtC;gBACA,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;aACzE;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE;QACnD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE;oBACtC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE;wBACpB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;qBACxD;iBACF;YACH,CAAC;SACF,CAAC;KACH;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AA9MD,uBA8MC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport State, { initState } from './state';\nimport { inlineRuntimeConfig, insertConfig, Mode as GetConfigMode } from './get-config';\nimport macroCondition, { isMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(t, path, state);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression>, state: State) {\n if (isMacroConditionPath(path)) {\n state.calledIdentifiers.add(path.get('test').get('callee').node);\n macroCondition(path, state);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && 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 throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`);\n }\n path.replaceWith(state.importUtil.import(path, specifier.value, '*'));\n state.calledIdentifiers.add(callee.node);\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n return;\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `macroCondition can only be used as the predicate of an if statement or ternary expression`);\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n state.opts.importSyncImplementation === 'cjs' &&\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberPackage()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
|
|
@@ -16,7 +16,7 @@ baseDir, moduleName, packageCache) {
|
|
|
16
16
|
let packageName = node.params[0].value;
|
|
17
17
|
let range = node.params[1].value;
|
|
18
18
|
let us = packageCache.ownerOfFile(baseDir || moduleName);
|
|
19
|
-
if (!us
|
|
19
|
+
if (!(us === null || us === void 0 ? void 0 : us.hasDependency(packageName))) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
let pkg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAGnC,SAAwB,mBAAmB,CACzC,IAAS;AACT,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,wEAAwE;AACxE,OAA2B,EAC3B,UAAkB,EAClB,YAAmC;IAEnC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACtG;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE;QAC9D,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACtF;IAED,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,IAAI,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,CAAC;IACR,IAAI;QACF,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC7C;IAAC,OAAO,GAAG,EAAE;QACZ,sEAAsE;KACvE;IAED,IAAI,GAAG,EAAE;QACP,OAAO,IAAA,kBAAS,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE;YACnC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;KACJ;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAvCD,sCAuCC","sourcesContent":["import { satisfies } from 'semver';\nimport type { RewrittenPackageCache } from '@embroider/shared-internals';\n\nexport default function dependencySatisfies(\n node: any,\n // when we're running in traditional ember-cli, baseDir is configured and we\n // do all lookups relative to that (single) package. But when we're running in\n // embroider stage3 we process all packages simultaneously, so baseDir is left\n // unconfigured and moduleName will be the full path to the source file.\n baseDir: string | undefined,\n moduleName: string,\n packageCache: RewrittenPackageCache\n) {\n if (node.params.length !== 2) {\n throw new Error(`macroDependencySatisfies requires two arguments, you passed ${node.params.length}`);\n }\n\n if (!node.params.every((p: any) => p.type === 'StringLiteral')) {\n throw new Error(`all arguments to macroDependencySatisfies must be string literals`);\n }\n\n let packageName = node.params[0].value;\n let range = node.params[1].value;\n\n let us = packageCache.ownerOfFile(baseDir || moduleName);\n if (!us?.hasDependency(packageName)) {\n return false;\n }\n\n let pkg;\n try {\n pkg = packageCache.resolve(packageName, us);\n } catch (err) {\n // it's not an error if we can't resolve it, we just don't satisfy it.\n }\n\n if (pkg) {\n return satisfies(pkg.version, range, {\n includePrerelease: true,\n });\n }\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependency-satisfies.js","sourceRoot":"","sources":["dependency-satisfies.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAGnC,SAAwB,mBAAmB,CACzC,IAAS;AACT,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,wEAAwE;AACxE,OAA2B,EAC3B,UAAkB,EAClB,YAAmC;IAEnC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACtG;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE;QAC9D,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACtF;IAED,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,IAAI,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,aAAa,CAAC,WAAW,CAAC,CAAA,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,CAAC;IACR,IAAI;QACF,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC7C;IAAC,OAAO,GAAG,EAAE;QACZ,sEAAsE;KACvE;IAED,IAAI,GAAG,EAAE;QACP,OAAO,IAAA,kBAAS,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE;YACnC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;KACJ;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAvCD,sCAuCC","sourcesContent":["import { satisfies } from 'semver';\nimport type { RewrittenPackageCache } from '@embroider/shared-internals';\n\nexport default function dependencySatisfies(\n node: any,\n // when we're running in traditional ember-cli, baseDir is configured and we\n // do all lookups relative to that (single) package. But when we're running in\n // embroider stage3 we process all packages simultaneously, so baseDir is left\n // unconfigured and moduleName will be the full path to the source file.\n baseDir: string | undefined,\n moduleName: string,\n packageCache: RewrittenPackageCache\n) {\n if (node.params.length !== 2) {\n throw new Error(`macroDependencySatisfies requires two arguments, you passed ${node.params.length}`);\n }\n\n if (!node.params.every((p: any) => p.type === 'StringLiteral')) {\n throw new Error(`all arguments to macroDependencySatisfies must be string literals`);\n }\n\n let packageName = node.params[0].value;\n let range = node.params[1].value;\n\n let us = packageCache.ownerOfFile(baseDir || moduleName);\n if (!us?.hasDependency(packageName)) {\n return false;\n }\n\n let pkg;\n try {\n pkg = packageCache.resolve(packageName, us);\n } catch (err) {\n // it's not an error if we can't resolve it, we just don't satisfy it.\n }\n\n if (pkg) {\n return satisfies(pkg.version, range, {\n includePrerelease: true,\n });\n }\n return false;\n}\n"]}
|