@embroider/macros 1.19.3 → 1.19.5
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
CHANGED
|
@@ -100,7 +100,7 @@ module.exports = {
|
|
|
100
100
|
|
|
101
101
|
### macroCondition
|
|
102
102
|
|
|
103
|
-
The `macroCondition` macro allows branch level code isolation (and deletion in the case of production builds). Generally macroConditions are viewed as a foundation macro and are combined with
|
|
103
|
+
The `macroCondition` macro allows branch level code isolation (and deletion in the case of production builds). Generally macroConditions are viewed as a foundation macro and are combined with other macros (detailed below) to create more complex scenarios. `macroCondition` takes a single argument which must be statically known or another macro which will compile down to a static value.
|
|
104
104
|
|
|
105
105
|
```js
|
|
106
106
|
import { macroCondition } from '@embroider/macros';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/macros",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Standardized build-time macros for ember apps.",
|
|
6
6
|
"keywords": [
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"scenario-tester": "^3.0.1",
|
|
55
55
|
"typescript": "^5.4.5",
|
|
56
56
|
"vitest": "^3.2.4",
|
|
57
|
-
"@embroider/
|
|
58
|
-
"@embroider/
|
|
57
|
+
"@embroider/core": "4.2.9",
|
|
58
|
+
"@embroider/test-support": "0.36.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@glint/template": "^1.0.0"
|
|
@@ -7,57 +7,17 @@ exports.default = appEmberSatisfies;
|
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
8
|
const error_1 = __importDefault(require("./error"));
|
|
9
9
|
const evaluate_json_1 = require("./evaluate-json");
|
|
10
|
-
const url_1 = require("url");
|
|
11
|
-
const module_1 = require("module");
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const find_up_1 = __importDefault(require("find-up"));
|
|
14
|
-
const packageName = 'ember-source';
|
|
15
10
|
const CACHE = new Map();
|
|
16
|
-
/**
|
|
17
|
-
* NOTE: Since there will only ever be one app ember version, we can cache the result of looking it up.
|
|
18
|
-
* (partly to save disk i/o)
|
|
19
|
-
*/
|
|
20
11
|
function getAppEmberVersion(state) {
|
|
12
|
+
var _a, _b;
|
|
21
13
|
let appRoot = state.packageCache.appRoot;
|
|
22
14
|
if (CACHE.has(appRoot)) {
|
|
23
15
|
return CACHE.get(appRoot);
|
|
24
16
|
}
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* This version can, and often is a range (^6.4.0),
|
|
32
|
-
* and using a range for the first parameter of satisfies will cause a failure to always occur.
|
|
33
|
-
* So we must resolve the actual version on disk.
|
|
34
|
-
*/
|
|
35
|
-
let resolvedInfo = state.packageCache.resolve(packageName, root);
|
|
36
|
-
let version = resolvedInfo.version;
|
|
37
|
-
/**
|
|
38
|
-
* But, if the version is "clean", we can avoid a disk hit
|
|
39
|
-
* (which is helpful for corporate machines which intercept every disk i/o behavior)
|
|
40
|
-
*/
|
|
41
|
-
let cleanedVersion = String((0, semver_1.coerce)(version, { includePrerelease: true }));
|
|
42
|
-
/**
|
|
43
|
-
* these are the same, so we don't need to ask the disk what was installed
|
|
44
|
-
*/
|
|
45
|
-
if (cleanedVersion === version) {
|
|
46
|
-
CACHE.set(appRoot, version);
|
|
47
|
-
return version;
|
|
48
|
-
}
|
|
49
|
-
const appURL = (0, url_1.pathToFileURL)(appRoot);
|
|
50
|
-
const require = (0, module_1.createRequire)(appURL);
|
|
51
|
-
const emberSourceEntry = require.resolve(packageName, {
|
|
52
|
-
paths: [appRoot],
|
|
53
|
-
});
|
|
54
|
-
const emberSourceManifestPath = find_up_1.default.sync('package.json', { cwd: (0, path_1.dirname)(emberSourceEntry) });
|
|
55
|
-
if (!emberSourceManifestPath) {
|
|
56
|
-
throw new Error(`We resolved an ember-source package, but could not find its package.json`);
|
|
57
|
-
}
|
|
58
|
-
const emberSourceManifest = require(emberSourceManifestPath);
|
|
59
|
-
CACHE.set(appRoot, emberSourceManifest.version);
|
|
60
|
-
return emberSourceManifest.version;
|
|
17
|
+
let app = state.packageCache.get(appRoot);
|
|
18
|
+
let version = (_b = (_a = app.dependencies.find(d => d.name === 'ember-source')) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : false;
|
|
19
|
+
CACHE.set(appRoot, version);
|
|
20
|
+
return version;
|
|
61
21
|
}
|
|
62
22
|
function appEmberSatisfies(path, state) {
|
|
63
23
|
if (path.node.arguments.length !== 1) {
|
|
@@ -67,20 +27,12 @@ function appEmberSatisfies(path, state) {
|
|
|
67
27
|
if (range.type !== 'StringLiteral') {
|
|
68
28
|
throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the only argument to appEmberSatisfies must be a string literal`);
|
|
69
29
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!appEmberVersion) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return (0, semver_1.satisfies)(appEmberVersion, range.value, {
|
|
76
|
-
includePrerelease: true,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
30
|
+
let appEmberVersion = getAppEmberVersion(state);
|
|
31
|
+
if (!appEmberVersion) {
|
|
83
32
|
return false;
|
|
84
33
|
}
|
|
34
|
+
return (0, semver_1.satisfies)(appEmberVersion, range.value, {
|
|
35
|
+
includePrerelease: true,
|
|
36
|
+
});
|
|
85
37
|
}
|
|
86
38
|
//# sourceMappingURL=app-ember-satisfies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-ember-satisfies.js","sourceRoot":"","sources":["app-ember-satisfies.ts"],"names":[],"m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C,CAAC,CAAC,CAAC,CAAC,EACrC,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,eAAe,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAEhD,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAA,kBAAS,EAAC,eAAe,EAAE,KAAK,CAAC,KAAK,EAAE;QAC7C,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { satisfies } from 'semver';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\n\nconst CACHE = new Map<string, string | false>();\n\nfunction getAppEmberVersion(state: State): string | false {\n let appRoot = state.packageCache.appRoot;\n\n if (CACHE.has(appRoot)) {\n return CACHE.get(appRoot)!;\n }\n\n let app = state.packageCache.get(appRoot);\n let version: string | false = app.dependencies.find(d => d.name === 'ember-source')?.version ?? false;\n CACHE.set(appRoot, version);\n return version;\n}\n\nexport default function appEmberSatisfies(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 1) {\n throw error(path, `appEmberSatisfies takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n const [range] = path.node.arguments;\n if (range.type !== 'StringLiteral') {\n throw error(\n assertArray(path.get('arguments'))[0],\n `the only argument to appEmberSatisfies must be a string literal`\n );\n }\n\n let appEmberVersion = getAppEmberVersion(state);\n\n if (!appEmberVersion) {\n return false;\n }\n\n return satisfies(appEmberVersion, range.value, {\n includePrerelease: true,\n });\n}\n"]}
|