@warp-drive-mirror/build-config 5.6.0-alpha.1 → 5.6.0-alpha.12
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/declarations/-private/utils/deprecations.d.ts +10 -0
- package/declarations/-private/utils/features.d.ts +7 -0
- package/declarations/-private/utils/get-env.d.ts +9 -0
- package/declarations/-private/utils/get-env.d.ts.map +1 -0
- package/declarations/-private/utils/logging.d.ts +12 -0
- package/declarations/babel-macros.d.ts +14 -0
- package/declarations/babel-macros.d.ts.map +1 -0
- package/declarations/canary-features.d.ts +137 -0
- package/declarations/canary-features.d.ts.map +1 -0
- package/declarations/cjs-set-config.d.ts +2 -0
- package/declarations/debugging.d.ts +173 -0
- package/declarations/debugging.d.ts.map +1 -0
- package/declarations/deprecation-versions.d.ts +14 -0
- package/declarations/deprecation-versions.d.ts.map +1 -0
- package/declarations/deprecations.d.ts +517 -0
- package/declarations/deprecations.d.ts.map +1 -0
- package/declarations/env.d.ts +130 -0
- package/declarations/env.d.ts.map +1 -0
- package/declarations/index.d.ts +102 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/macros.d.ts +19 -0
- package/declarations/macros.d.ts.map +1 -0
- package/declarations/validate-exports.type-test.d.ts +2 -0
- package/dist/babel-macros.js +45 -12
- package/dist/babel-macros.js.map +1 -1
- package/dist/babel-plugin-transform-asserts.cjs +2 -2
- package/dist/babel-plugin-transform-asserts.cjs.map +1 -1
- package/dist/babel-plugin-transform-deprecations.cjs +2 -2
- package/dist/babel-plugin-transform-deprecations.cjs.map +1 -1
- package/dist/babel-plugin-transform-features.cjs +2 -2
- package/dist/babel-plugin-transform-features.cjs.map +1 -1
- package/dist/babel-plugin-transform-logging.cjs +2 -2
- package/dist/babel-plugin-transform-logging.cjs.map +1 -1
- package/dist/canary-features-CuKgaVtX.js +147 -0
- package/dist/canary-features-CuKgaVtX.js.map +1 -0
- package/dist/canary-features.js +1 -1
- package/dist/cjs-set-config.cjs +160 -608
- package/dist/cjs-set-config.cjs.map +1 -1
- package/dist/{debugging-BtpYr1v0.js → debugging-VdsvkNjX.js} +80 -62
- package/dist/debugging-VdsvkNjX.js.map +1 -0
- package/dist/debugging.js +1 -1
- package/dist/deprecations-BNNGFAiG.js +549 -0
- package/dist/deprecations-BNNGFAiG.js.map +1 -0
- package/dist/deprecations.js +1 -1
- package/dist/env.js +124 -0
- package/dist/env.js.map +1 -1
- package/dist/index.js +20 -520
- package/dist/index.js.map +1 -1
- package/dist/macros.js +18 -0
- package/dist/macros.js.map +1 -1
- package/package.json +6 -18
- package/dist/canary-features-D1wplYmb.js +0 -113
- package/dist/canary-features-D1wplYmb.js.map +0 -1
- package/dist/debugging-BtpYr1v0.js.map +0 -1
- package/dist/deprecations-D_dBAPC9.js +0 -34
- package/dist/deprecations-D_dBAPC9.js.map +0 -1
- package/unstable-preview-types/-private/utils/deprecations.d.ts +0 -12
- package/unstable-preview-types/-private/utils/features.d.ts +0 -9
- package/unstable-preview-types/-private/utils/get-env.d.ts +0 -11
- package/unstable-preview-types/-private/utils/get-env.d.ts.map +0 -1
- package/unstable-preview-types/-private/utils/logging.d.ts +0 -14
- package/unstable-preview-types/babel-macros.d.ts +0 -6
- package/unstable-preview-types/babel-macros.d.ts.map +0 -1
- package/unstable-preview-types/canary-features.d.ts +0 -105
- package/unstable-preview-types/canary-features.d.ts.map +0 -1
- package/unstable-preview-types/cjs-set-config.d.ts +0 -4
- package/unstable-preview-types/debugging.d.ts +0 -164
- package/unstable-preview-types/debugging.d.ts.map +0 -1
- package/unstable-preview-types/deprecation-versions.d.ts +0 -485
- package/unstable-preview-types/deprecation-versions.d.ts.map +0 -1
- package/unstable-preview-types/deprecations.d.ts +0 -16
- package/unstable-preview-types/deprecations.d.ts.map +0 -1
- package/unstable-preview-types/env.d.ts +0 -9
- package/unstable-preview-types/env.d.ts.map +0 -1
- package/unstable-preview-types/index.d.ts +0 -49
- package/unstable-preview-types/index.d.ts.map +0 -1
- package/unstable-preview-types/macros.d.ts +0 -5
- package/unstable-preview-types/macros.d.ts.map +0 -1
- package/unstable-preview-types/validate-exports.type-test.d.ts +0 -4
- /package/{unstable-preview-types → declarations}/-private/utils/deprecations.d.ts.map +0 -0
- /package/{unstable-preview-types → declarations}/-private/utils/features.d.ts.map +0 -0
- /package/{unstable-preview-types → declarations}/-private/utils/logging.d.ts.map +0 -0
- /package/{unstable-preview-types → declarations}/cjs-set-config.d.ts.map +0 -0
- /package/{unstable-preview-types → declarations}/validate-exports.type-test.d.ts.map +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getDeprecations } from './-private/utils/deprecations.ts';
|
|
2
|
+
import { getFeatures } from './-private/utils/features.ts';
|
|
3
|
+
import * as LOGGING from './debugging.ts';
|
|
4
|
+
export type WarpDriveConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* An object of key/value pairs of logging flags
|
|
7
|
+
*
|
|
8
|
+
* see {@link LOGGING | debugging} for the available flags.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* {
|
|
12
|
+
* LOG_CACHE: true,
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
debug?: Partial<InternalWarpDriveConfig['debug']>;
|
|
19
|
+
/**
|
|
20
|
+
* If you are using the library in an environment that does not
|
|
21
|
+
* support `window.crypto.randomUUID` you can enable a polyfill
|
|
22
|
+
* for it.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
polyfillUUID?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* By default, the integration required to support the ember-inspector
|
|
29
|
+
* browser extension is included in production builds only when using
|
|
30
|
+
* the `ember-data` package.
|
|
31
|
+
*
|
|
32
|
+
* Otherwise the default is to exclude it. This setting allows to explicitly
|
|
33
|
+
* enable/disable it in production builds.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
includeDataAdapterInProduction?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The most recent version of the library from which all
|
|
40
|
+
* deprecations have been resolved.
|
|
41
|
+
*
|
|
42
|
+
* For instance if all deprecations released prior to or
|
|
43
|
+
* within `5.3` have been resolved, then setting this to
|
|
44
|
+
* `5.3` will remove all the support for the deprecated
|
|
45
|
+
* features for associated deprecations.
|
|
46
|
+
*
|
|
47
|
+
* See {@link DEPRECATIONS | deprecations} for more details.
|
|
48
|
+
*/
|
|
49
|
+
compatWith?: `${number}.${number}`;
|
|
50
|
+
/**
|
|
51
|
+
* An object of key/value pairs of logging flags
|
|
52
|
+
*
|
|
53
|
+
* see {@link DEPRECATIONS | deprecations} for the available flags.
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* {
|
|
57
|
+
* DEPRECATE_THING: false,
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
deprecations?: Partial<InternalWarpDriveConfig['deprecations']>;
|
|
64
|
+
/**
|
|
65
|
+
* An object of key/value pairs of canary feature flags
|
|
66
|
+
* for use when testing new features gated behind a flag
|
|
67
|
+
* in a canary release version.
|
|
68
|
+
*
|
|
69
|
+
* see {@link FEATURES | features} for the available flags.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* {
|
|
73
|
+
* FEATURE_A: true,
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
features?: Partial<InternalWarpDriveConfig['features']>;
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
forceMode?: 'testing' | 'production' | 'development';
|
|
84
|
+
};
|
|
85
|
+
type InternalWarpDriveConfig = {
|
|
86
|
+
debug: typeof LOGGING;
|
|
87
|
+
polyfillUUID: boolean;
|
|
88
|
+
includeDataAdapter: boolean;
|
|
89
|
+
compatWith: `${number}.${number}` | null;
|
|
90
|
+
deprecations: ReturnType<typeof getDeprecations>;
|
|
91
|
+
features: ReturnType<typeof getFeatures>;
|
|
92
|
+
activeLogging: typeof LOGGING;
|
|
93
|
+
env: {
|
|
94
|
+
TESTING: boolean;
|
|
95
|
+
PRODUCTION: boolean;
|
|
96
|
+
DEBUG: boolean;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export declare function setConfig(macros: object, config: WarpDriveConfig): void;
|
|
100
|
+
export declare function setConfig(context: object, appRoot: string, config: WarpDriveConfig): void;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyCA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAQ1C,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC;IAElD;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;;;;OASG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAEzC;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAEnC;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC;IAEhE;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;IAExD;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;CACtD,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,OAAO,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,UAAU,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,GAAG,IAAI,CAAC;IACzC,YAAY,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;IACjD,QAAQ,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;IACzC,aAAa,EAAE,OAAO,OAAO,CAAC;IAC9B,GAAG,EAAE;QACH,OAAO,EAAE,OAAO,CAAC;QACjB,UAAU,EAAE,OAAO,CAAC;QACpB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;CACH,CAAC;AAWF,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;AACzE,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal functions for instrumenting the library's code with behaviors
|
|
3
|
+
* that are removed from production builds.
|
|
4
|
+
*
|
|
5
|
+
* @hidden
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A type-narrowing assertion function that throws an error with the supplied
|
|
10
|
+
* message if the condition is falsy.
|
|
11
|
+
*
|
|
12
|
+
* Asserts are removed from production builds, making this a "zero cost abstraction"
|
|
13
|
+
* so liberal usage of this function to ensure runtime correctness is encouraged.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function assert(message: string, condition: unknown): asserts condition;
|
|
18
|
+
export declare function assert(message: string): never;
|
|
19
|
+
//# sourceMappingURL=macros.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.d.ts","sourceRoot":"","sources":["../src/macros.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;AAC/E,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC"}
|
package/dist/babel-macros.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
import { L as LOGGING } from './debugging-
|
|
2
|
-
import { C as CURRENT_FEATURES } from './canary-features-
|
|
3
|
-
import { C as CURRENT_DEPRECATIONS } from './deprecations-
|
|
1
|
+
import { L as LOGGING } from './debugging-VdsvkNjX.js';
|
|
2
|
+
import { C as CURRENT_FEATURES } from './canary-features-CuKgaVtX.js';
|
|
3
|
+
import { C as CURRENT_DEPRECATIONS } from './deprecations-BNNGFAiG.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Babel plugins that convert constants and expressions into [macroConditions](https://www.npmjs.com/package/@embroider/macros#the-macros)
|
|
7
|
+
* so that they can be stripped from the code during the build process.
|
|
8
|
+
*
|
|
9
|
+
* This allows us to have great DX around common configuration patterns
|
|
10
|
+
* while still being able to ship a small and fast library.
|
|
11
|
+
*
|
|
12
|
+
* Transforms
|
|
13
|
+
*
|
|
14
|
+
* - deprecation constants imported from `@warp-drive-mirror/build-config/deprecations`
|
|
15
|
+
* - feature flags imported from `@warp-drive-mirror/build-config/canary-features`
|
|
16
|
+
* - debug logging constants imported from `@warp-drive-mirror/build-config/debugging`
|
|
17
|
+
* - environment constants imported from `@warp-drive-mirror/build-config/env`
|
|
18
|
+
* - expressionts imported from `@warp-drive-mirror/build-config/macros`
|
|
19
|
+
*
|
|
20
|
+
* Addons and apps can use these plugins to match the code-stripping behaviors of
|
|
21
|
+
* ***Warp*Drive**. This is useful when managing migrations for canary features
|
|
22
|
+
* and deprecations.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
5
26
|
const features = Object.keys(CURRENT_FEATURES);
|
|
6
27
|
const FEATURES = Object.assign({}, CURRENT_FEATURES);
|
|
7
28
|
features.forEach(feature => {
|
|
@@ -15,24 +36,36 @@ const config = {
|
|
|
15
36
|
deprecations: Object.assign({}, CURRENT_DEPRECATIONS),
|
|
16
37
|
debug: Object.assign({}, LOGGING)
|
|
17
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* @returns an array of Babel plugins that can be used for code-stripping
|
|
41
|
+
* based on the configuration supplied to `setConfig` and the current ENV.
|
|
42
|
+
*
|
|
43
|
+
* - deprecation constants imported from `@warp-drive-mirror/build-config/deprecations`
|
|
44
|
+
* - feature flags imported from `@warp-drive-mirror/build-config/canary-features`
|
|
45
|
+
* - debug logging constants imported from `@warp-drive-mirror/build-config/debugging`
|
|
46
|
+
* - environment constants imported from `@warp-drive-mirror/build-config/env`
|
|
47
|
+
* - expressionts imported from `@warp-drive-mirror/build-config/macros`
|
|
48
|
+
*/
|
|
18
49
|
function macros() {
|
|
19
50
|
const TransformAsserts = import.meta.resolve('./babel-plugin-transform-asserts.cjs').slice(7);
|
|
20
51
|
const TransformDeprecations = import.meta.resolve('./babel-plugin-transform-deprecations.cjs').slice(7);
|
|
21
52
|
const TransformDebugLogging = import.meta.resolve('./babel-plugin-transform-logging.cjs').slice(7);
|
|
22
53
|
const TransformFeatures = import.meta.resolve('./babel-plugin-transform-features.cjs').slice(7);
|
|
23
|
-
let plugins = [[TransformAsserts, {
|
|
24
|
-
|
|
54
|
+
let plugins = [[TransformAsserts, {
|
|
55
|
+
sources: ['@warp-drive-mirror/build-config/macros', '@warp-drive-mirror/core/build-config/macros']
|
|
56
|
+
}, '@warp-drive-mirror/core/build-config/asserts-stripping'], [TransformFeatures, {
|
|
57
|
+
sources: ['@warp-drive-mirror/build-config/canary-features', '@warp-drive-mirror/core/build-config/canary-features'],
|
|
25
58
|
flags: config.features
|
|
26
|
-
}, '@warp-drive-mirror/build-config/canary-features-stripping'], [TransformDeprecations, {
|
|
27
|
-
|
|
59
|
+
}, '@warp-drive-mirror/core/build-config/canary-features-stripping'], [TransformDeprecations, {
|
|
60
|
+
sources: ['@warp-drive-mirror/build-config/deprecations', '@warp-drive-mirror/core/build-config/deprecations'],
|
|
28
61
|
flags: config.deprecations
|
|
29
|
-
}, '@warp-drive-mirror/build-config/deprecation-stripping'], [TransformDebugLogging, {
|
|
30
|
-
|
|
62
|
+
}, '@warp-drive-mirror/core/build-config/deprecation-stripping'], [TransformDebugLogging, {
|
|
63
|
+
sources: ['@warp-drive-mirror/build-config/debugging', '@warp-drive-mirror/core/build-config/debugging'],
|
|
31
64
|
configKey: 'debug',
|
|
32
65
|
runtimeKey: 'activeLogging',
|
|
33
66
|
flags: config.debug
|
|
34
|
-
}, '@warp-drive-mirror/build-config/debugging-stripping'], [TransformDebugLogging, {
|
|
35
|
-
|
|
67
|
+
}, '@warp-drive-mirror/core/build-config/debugging-stripping'], [TransformDebugLogging, {
|
|
68
|
+
sources: ['@warp-drive-mirror/build-config/env', '@warp-drive-mirror/core/build-config/env'],
|
|
36
69
|
configKey: 'env',
|
|
37
70
|
flags: {
|
|
38
71
|
TESTING: true,
|
|
@@ -42,7 +75,7 @@ function macros() {
|
|
|
42
75
|
IS_CI: true,
|
|
43
76
|
SHOULD_RECORD: true
|
|
44
77
|
}
|
|
45
|
-
}, '@warp-drive-mirror/build-config/env']];
|
|
78
|
+
}, '@warp-drive-mirror/core/build-config/env']];
|
|
46
79
|
return plugins;
|
|
47
80
|
}
|
|
48
81
|
|
package/dist/babel-macros.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-macros.js","sources":["../src/babel-macros.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"babel-macros.js","sources":["../src/babel-macros.ts"],"sourcesContent":["/**\n * Babel plugins that convert constants and expressions into [macroConditions](https://www.npmjs.com/package/@embroider/macros#the-macros)\n * so that they can be stripped from the code during the build process.\n *\n * This allows us to have great DX around common configuration patterns\n * while still being able to ship a small and fast library.\n *\n * Transforms\n *\n * - deprecation constants imported from `@warp-drive-mirror/build-config/deprecations`\n * - feature flags imported from `@warp-drive-mirror/build-config/canary-features`\n * - debug logging constants imported from `@warp-drive-mirror/build-config/debugging`\n * - environment constants imported from `@warp-drive-mirror/build-config/env`\n * - expressionts imported from `@warp-drive-mirror/build-config/macros`\n *\n * Addons and apps can use these plugins to match the code-stripping behaviors of\n * ***Warp*Drive**. This is useful when managing migrations for canary features\n * and deprecations.\n *\n * @module\n */\nimport * as LOGGING from './debugging.ts';\nimport * as CURRENT_FEATURES from './canary-features.ts';\nimport * as CURRENT_DEPRECATIONS from './deprecations.ts';\n\ntype FEATURE = keyof typeof CURRENT_FEATURES;\nconst features = Object.keys(CURRENT_FEATURES) as FEATURE[];\nconst FEATURES = Object.assign({}, CURRENT_FEATURES) as Record<FEATURE, boolean>;\nfeatures.forEach((feature) => {\n let featureValue = FEATURES[feature];\n if (featureValue === null) {\n FEATURES[feature] = false;\n }\n});\n\nconst config = {\n features: FEATURES,\n deprecations: Object.assign({}, CURRENT_DEPRECATIONS),\n debug: Object.assign({}, LOGGING),\n};\n\ntype BabelPlugin = [string, Record<string, unknown>, string];\n\n/**\n * @returns an array of Babel plugins that can be used for code-stripping\n * based on the configuration supplied to `setConfig` and the current ENV.\n *\n * - deprecation constants imported from `@warp-drive-mirror/build-config/deprecations`\n * - feature flags imported from `@warp-drive-mirror/build-config/canary-features`\n * - debug logging constants imported from `@warp-drive-mirror/build-config/debugging`\n * - environment constants imported from `@warp-drive-mirror/build-config/env`\n * - expressionts imported from `@warp-drive-mirror/build-config/macros`\n */\nexport function macros(): BabelPlugin[] {\n const TransformAsserts = import.meta.resolve('./babel-plugin-transform-asserts.cjs').slice(7);\n const TransformDeprecations = import.meta.resolve('./babel-plugin-transform-deprecations.cjs').slice(7);\n const TransformDebugLogging = import.meta.resolve('./babel-plugin-transform-logging.cjs').slice(7);\n const TransformFeatures = import.meta.resolve('./babel-plugin-transform-features.cjs').slice(7);\n\n let plugins = [\n [\n TransformAsserts,\n {\n sources: ['@warp-drive-mirror/build-config/macros', '@warp-drive-mirror/core/build-config/macros'],\n },\n '@warp-drive-mirror/core/build-config/asserts-stripping',\n ],\n [\n TransformFeatures,\n {\n sources: ['@warp-drive-mirror/build-config/canary-features', '@warp-drive-mirror/core/build-config/canary-features'],\n flags: config.features,\n },\n '@warp-drive-mirror/core/build-config/canary-features-stripping',\n ],\n [\n TransformDeprecations,\n {\n sources: ['@warp-drive-mirror/build-config/deprecations', '@warp-drive-mirror/core/build-config/deprecations'],\n flags: config.deprecations,\n },\n '@warp-drive-mirror/core/build-config/deprecation-stripping',\n ],\n [\n TransformDebugLogging,\n {\n sources: ['@warp-drive-mirror/build-config/debugging', '@warp-drive-mirror/core/build-config/debugging'],\n configKey: 'debug',\n runtimeKey: 'activeLogging',\n flags: config.debug,\n },\n '@warp-drive-mirror/core/build-config/debugging-stripping',\n ],\n [\n TransformDebugLogging,\n {\n sources: ['@warp-drive-mirror/build-config/env', '@warp-drive-mirror/core/build-config/env'],\n configKey: 'env',\n flags: {\n TESTING: true,\n PRODUCTION: true,\n DEBUG: true,\n IS_RECORDING: true,\n IS_CI: true,\n SHOULD_RECORD: true,\n },\n },\n '@warp-drive-mirror/core/build-config/env',\n ],\n ] satisfies BabelPlugin[];\n\n return plugins;\n}\n"],"names":["features","Object","keys","CURRENT_FEATURES","FEATURES","assign","forEach","feature","featureValue","config","deprecations","CURRENT_DEPRECATIONS","debug","LOGGING","macros","TransformAsserts","import","meta","resolve","slice","TransformDeprecations","TransformDebugLogging","TransformFeatures","plugins","sources","flags","configKey","runtimeKey","TESTING","PRODUCTION","DEBUG","IS_RECORDING","IS_CI","SHOULD_RECORD"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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iC,EAAE,sCAAsC;AACrF,GAAC,EACD,iDAAiD,CAClD,EACD,CACEF,iBAAiB,EACjB;AACEE,IAAAA,OAAO,EAAE,CAAC,0CAA0C,EAAE,+CAA+C,CAAC;IACtGC,KAAK,EAAEhB,MAAM,CAACT;AAChB,GAAC,EACD,yDAAyD,CAC1D,EACD,CACEoB,qBAAqB,EACrB;AACEI,IAAAA,OAAO,EAAE,CAAC,uCAAuC,EAAE,4CAA4C,CAAC;IAChGC,KAAK,EAAEhB,MAAM,CAACC;AAChB,GAAC,EACD,qDAAqD,CACtD,EACD,CACEW,qBAAqB,EACrB;AACEG,IAAAA,OAAO,EAAE,CAAC,oCAAoC,EAAE,yCAAyC,CAAC;AAC1FE,IAAAA,SAAS,EAAE,OAAO;AAClBC,IAAAA,UAAU,EAAE,eAAe;IAC3BF,KAAK,EAAEhB,MAAM,CAACG;AAChB,GAAC,EACD,mDAAmD,CACpD,EACD,CACES,qBAAqB,EACrB;AACEG,IAAAA,OAAO,EAAE,CAAC,8BAA8B,EAAE,mCAAmC,CAAC;AAC9EE,IAAAA,SAAS,EAAE,KAAK;AAChBD,IAAAA,KAAK,EAAE;AACLG,MAAAA,OAAO,EAAE,IAAI;AACbC,MAAAA,UAAU,EAAE,IAAI;AAChBC,MAAAA,KAAK,EAAE,IAAI;AACXC,MAAAA,YAAY,EAAE,IAAI;AAClBC,MAAAA,KAAK,EAAE,IAAI;AACXC,MAAAA,aAAa,EAAE;AACjB;GACD,EACD,mCAAmC,CACpC,CACsB;AAEzB,EAAA,OAAOV,OAAO;AAChB;;;;"}
|
|
@@ -63,12 +63,12 @@ function babelPluginTransformAsserts (babel) {
|
|
|
63
63
|
visitor: {
|
|
64
64
|
ImportDeclaration(path, state) {
|
|
65
65
|
const importPath = path.node.source.value;
|
|
66
|
-
if (importPath
|
|
66
|
+
if (state.opts.sources.includes(importPath)) {
|
|
67
67
|
const specifiers = path.get('specifiers');
|
|
68
68
|
specifiers.forEach(specifier => {
|
|
69
69
|
const name = specifier.node.imported.name;
|
|
70
70
|
if (!Utils.has(name)) {
|
|
71
|
-
throw new Error(`Unexpected import '${name}' imported from '
|
|
71
|
+
throw new Error(`Unexpected import '${name}' imported from '${importPath}'`);
|
|
72
72
|
}
|
|
73
73
|
const localBindingName = specifier.node.local.name;
|
|
74
74
|
const binding = specifier.scope.getBinding(localBindingName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-transform-asserts.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-asserts.js"],"sourcesContent":["const { ImportUtil } = require('babel-import-util');\n\nconst Utils = new Set(['assert']);\n\n/*\n// Before\nimport { assert } from '@warp-drive-mirror/build-config/macros';\n\nassert('foo', true);\n\n// After\n(macroCondition(isDevelopingApp()) ? function assert(test) { if (!test) { throw new Error('foo'); } }(true) : {});\n*/\n\n// => _macros.getGlobalConfig().WarpDriveMirror.env.DEBUG\nfunction buildMacroConstDEBUG(types, binding, state) {\n return types.memberExpression(\n types.memberExpression(\n types.memberExpression(\n types.callExpression(state.importer.import(binding, '@embroider/macros', 'getGlobalConfig'), []),\n types.identifier('WarpDriveMirror')\n ),\n types.identifier('env')\n ),\n types.identifier('DEBUG')\n );\n}\n\n// => _macros.macroCondition(_macros.getGlobalConfig().WarpDriveMirror.env.DEBUG)\nfunction buildMacroConditionDEBUG(types, binding, state) {\n return types.callExpression(state.importer.import(binding, '@embroider/macros', 'macroCondition'), [\n buildMacroConstDEBUG(types, binding, state),\n ]);\n}\n\n// (test) => { if (!test) { throw new Error(someMessage); } }(someCond)\nfunction buildAssert(types, originalCallExpression) {\n const desc = originalCallExpression.arguments[0];\n const test = originalCallExpression.arguments[1] ?? types.booleanLiteral(false);\n // prettier-ignore\n return types.callExpression(\n types.arrowFunctionExpression([types.identifier('test')], // (test) =>\n types.blockStatement([ // {\n types.ifStatement( // if\n types.unaryExpression('!', types.identifier('test')), // (!test)\n types.blockStatement([ // {\n types.throwStatement( // throw\n types.newExpression(types.identifier('Error'), [desc]) // new Error(desc)\n )]) // }\n )]) // }\n ),\n [test] // (someCond)\n );\n}\n\n// => ( <debug-macro> ? <assert-exp> : {});\nfunction buildAssertTernary(types, binding, state, originalCallExpression) {\n return types.expressionStatement(\n types.conditionalExpression(\n buildMacroConditionDEBUG(types, binding, state),\n buildAssert(types, originalCallExpression),\n types.objectExpression([])\n )\n );\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (importPath
|
|
1
|
+
{"version":3,"file":"babel-plugin-transform-asserts.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-asserts.js"],"sourcesContent":["const { ImportUtil } = require('babel-import-util');\n\nconst Utils = new Set(['assert']);\n\n/*\n// Before\nimport { assert } from '@warp-drive-mirror/build-config/macros';\n\nassert('foo', true);\n\n// After\n(macroCondition(isDevelopingApp()) ? function assert(test) { if (!test) { throw new Error('foo'); } }(true) : {});\n*/\n\n// => _macros.getGlobalConfig().WarpDriveMirror.env.DEBUG\nfunction buildMacroConstDEBUG(types, binding, state) {\n return types.memberExpression(\n types.memberExpression(\n types.memberExpression(\n types.callExpression(state.importer.import(binding, '@embroider/macros', 'getGlobalConfig'), []),\n types.identifier('WarpDriveMirror')\n ),\n types.identifier('env')\n ),\n types.identifier('DEBUG')\n );\n}\n\n// => _macros.macroCondition(_macros.getGlobalConfig().WarpDriveMirror.env.DEBUG)\nfunction buildMacroConditionDEBUG(types, binding, state) {\n return types.callExpression(state.importer.import(binding, '@embroider/macros', 'macroCondition'), [\n buildMacroConstDEBUG(types, binding, state),\n ]);\n}\n\n// (test) => { if (!test) { throw new Error(someMessage); } }(someCond)\nfunction buildAssert(types, originalCallExpression) {\n const desc = originalCallExpression.arguments[0];\n const test = originalCallExpression.arguments[1] ?? types.booleanLiteral(false);\n // prettier-ignore\n return types.callExpression(\n types.arrowFunctionExpression([types.identifier('test')], // (test) =>\n types.blockStatement([ // {\n types.ifStatement( // if\n types.unaryExpression('!', types.identifier('test')), // (!test)\n types.blockStatement([ // {\n types.throwStatement( // throw\n types.newExpression(types.identifier('Error'), [desc]) // new Error(desc)\n )]) // }\n )]) // }\n ),\n [test] // (someCond)\n );\n}\n\n// => ( <debug-macro> ? <assert-exp> : {});\nfunction buildAssertTernary(types, binding, state, originalCallExpression) {\n return types.expressionStatement(\n types.conditionalExpression(\n buildMacroConditionDEBUG(types, binding, state),\n buildAssert(types, originalCallExpression),\n types.objectExpression([])\n )\n );\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (state.opts.sources.includes(importPath)) {\n const specifiers = path.get('specifiers');\n\n specifiers.forEach((specifier) => {\n const name = specifier.node.imported.name;\n if (!Utils.has(name)) {\n throw new Error(`Unexpected import '${name}' imported from '${importPath}'`);\n }\n\n const localBindingName = specifier.node.local.name;\n const binding = specifier.scope.getBinding(localBindingName);\n\n binding.referencePaths.forEach((p) => {\n const originalCallExpression = p.parentPath.node;\n\n if (!t.isCallExpression(originalCallExpression)) {\n throw new Error('Expected a call expression');\n }\n\n const assertTernary = buildAssertTernary(t, binding, state, originalCallExpression);\n p.parentPath.replaceWith(assertTernary);\n });\n specifier.scope.removeOwnBinding(localBindingName);\n specifier.remove();\n });\n\n if (path.get('specifiers').length === 0) {\n path.remove();\n }\n }\n },\n\n Program(path, state) {\n state.importer = new ImportUtil(t, path);\n },\n },\n };\n}\n"],"names":["ImportUtil","require","Utils","Set","buildMacroConstDEBUG","types","binding","state","memberExpression","callExpression","importer","import","identifier","buildMacroConditionDEBUG","buildAssert","originalCallExpression","desc","arguments","test","booleanLiteral","arrowFunctionExpression","blockStatement","ifStatement","unaryExpression","throwStatement","newExpression","buildAssertTernary","expressionStatement","conditionalExpression","objectExpression","babel","t","name","visitor","ImportDeclaration","path","importPath","node","source","value","opts","sources","includes","specifiers","get","forEach","specifier","imported","has","Error","localBindingName","local","scope","getBinding","referencePaths","p","parentPath","isCallExpression","assertTernary","replaceWith","removeOwnBinding","remove","length","Program"],"mappings":";;AAAA,MAAM;AAAEA,EAAAA;AAAW,CAAC,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAEnD,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;;AAEjC;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA,SAASC,oBAAoBA,CAACC,KAAK,EAAEC,OAAO,EAAEC,KAAK,EAAE;EACnD,OAAOF,KAAK,CAACG,gBAAgB,CAC3BH,KAAK,CAACG,gBAAgB,CACpBH,KAAK,CAACG,gBAAgB,CACpBH,KAAK,CAACI,cAAc,CAACF,KAAK,CAACG,QAAQ,CAACC,MAAM,CAACL,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,EAAE,EAAE,CAAC,EAChGD,KAAK,CAACO,UAAU,CAAC,WAAW,CAC9B,CAAC,EACDP,KAAK,CAACO,UAAU,CAAC,KAAK,CACxB,CAAC,EACDP,KAAK,CAACO,UAAU,CAAC,OAAO,CAC1B,CAAC;AACH;;AAEA;AACA,SAASC,wBAAwBA,CAACR,KAAK,EAAEC,OAAO,EAAEC,KAAK,EAAE;EACvD,OAAOF,KAAK,CAACI,cAAc,CAACF,KAAK,CAACG,QAAQ,CAACC,MAAM,CAACL,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,CACjGF,oBAAoB,CAACC,KAAK,EAAEC,OAAO,EAAEC,KAAK,CAAC,CAC5C,CAAC;AACJ;;AAEA;AACA,SAASO,WAAWA,CAACT,KAAK,EAAEU,sBAAsB,EAAE;AAClD,EAAA,MAAMC,IAAI,GAAGD,sBAAsB,CAACE,SAAS,CAAC,CAAC,CAAC;AAChD,EAAA,MAAMC,IAAI,GAAGH,sBAAsB,CAACE,SAAS,CAAC,CAAC,CAAC,IAAIZ,KAAK,CAACc,cAAc,CAAC,KA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AY,CAAC,CAACkB,MAAM,KAAK,CAAC,EAAE;YACvC3B,IAAI,CAAC0B,MAAM,EAAE;AACf;AACF;OACD;AAEDE,MAAAA,OAAOA,CAAC5B,IAAI,EAAE5B,KAAK,EAAE;QACnBA,KAAK,CAACG,QAAQ,GAAG,IAAIV,UAAU,CAAC+B,CAAC,EAAEI,IAAI,CAAC;AAC1C;AACF;GACD;AACH;;;;"}
|
|
@@ -17,12 +17,12 @@ function babelPluginTransformDeprecations (babel) {
|
|
|
17
17
|
visitor: {
|
|
18
18
|
ImportDeclaration(path, state) {
|
|
19
19
|
const importPath = path.node.source.value;
|
|
20
|
-
if (
|
|
20
|
+
if (state.opts.sources.includes(importPath)) {
|
|
21
21
|
const specifiers = path.get('specifiers');
|
|
22
22
|
specifiers.forEach(specifier => {
|
|
23
23
|
let name = specifier.node.imported.name;
|
|
24
24
|
if (!(name in state.opts.flags)) {
|
|
25
|
-
throw new Error(`Unexpected flag ${name} imported from ${
|
|
25
|
+
throw new Error(`Unexpected flag ${name} imported from ${importPath}`);
|
|
26
26
|
}
|
|
27
27
|
let localBindingName = specifier.node.local.name;
|
|
28
28
|
let binding = specifier.scope.getBinding(localBindingName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-transform-deprecations.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-deprecations.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'deprecation-flags',\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (
|
|
1
|
+
{"version":3,"file":"babel-plugin-transform-deprecations.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-deprecations.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'deprecation-flags',\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (state.opts.sources.includes(importPath)) {\n const specifiers = path.get('specifiers');\n specifiers.forEach((specifier) => {\n let name = specifier.node.imported.name;\n if (!(name in state.opts.flags)) {\n throw new Error(`Unexpected flag ${name} imported from ${importPath}`);\n }\n let localBindingName = specifier.node.local.name;\n let binding = specifier.scope.getBinding(localBindingName);\n binding.referencePaths.forEach((p, other) => {\n let negateStatement = false;\n let node = p;\n if (parentIsUnary(p)) {\n negateStatement = true;\n node = p.parentPath;\n }\n const comments =\n node.node.leadingComments ??\n (node.parent.type === 'ConditionalExpression' && node.parent.leadingComments) ??\n [];\n let shouldInlineConfigValue = false;\n if (comments?.length) {\n const lastComment = comments.at(-1);\n if (lastComment.value.trim() === 'inline-macro-config') {\n shouldInlineConfigValue = true;\n }\n }\n\n let getConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier('deprecations')\n ),\n t.identifier(name)\n );\n\n const configExp = negateStatement ? t.unaryExpression('!', getConfig) : getConfig;\n const replaceExp = shouldInlineConfigValue\n ? // if (DEPRECATE_FOO)\n // =>\n // if (getGlobalConfig('WarpDriveMirror').deprecations.FOO)\n configExp\n : // if (DEPRECATE_FOO)\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').deprecations.FOO))\n t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [configExp]);\n node.replaceWith(replaceExp);\n });\n specifier.scope.removeOwnBinding(localBindingName);\n specifier.remove();\n });\n if (path.get('specifiers').length === 0) {\n path.remove();\n }\n }\n },\n\n Program(path, state) {\n state.importer = new ImportUtil(t, path);\n },\n },\n };\n}\n"],"names":["parentIsUnary","node","parent","type","operator","babel","types","t","name","visitor","ImportDeclaration","path","state","importPath","source","value","opts","sources","includes","specifiers","get","forEach","specifier","imported","flags","Error","localBindingName","local","binding","scope","getBinding","referencePaths","p","other","negateStatement","parentPath","comments","leadingComments","shouldInlineConfigValue","length","lastComment","at","trim","getConfig","memberExpression","callExpression","importer","import","identifier","configExp","unaryExpression","replaceExp","replaceWith","removeOwnBinding","remove","Program","ImportUtil"],"mappings":";;;;AAEA,SAASA,aAAaA,CAACC,IAAI,EAAE;AAC3B,EAAA,IAAIA,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,iBAAiB,IAAIF,IAAI,CAACC,MAAM,CAACE,QAAQ,KAAK,GAAG,EAAE;AAC1E,IAAA,OAAO,IAAI;AACb;AACA,EAAA,OAAO,KAAK;AACd;AAEe,yCAAA,EAAUC,KAAK,EAAE;EAC9B,MAAM;AAAEC,IAAAA,KAAK,EAAEC;AAAE,GAAC,GAAGF,KAAK;EAE1B,OAAO;AACLG,IAAAA,IAAI,EAAE,mBAAmB;AACzBC,IAAAA,OAAO,EAAE;AACPC,MAAAA,iBAAiBA,CAACC,IAAI,EAAEC,KAAK,EAAE;QAC7B,MAAMC,UAAU,GAAGF,IAAI,CAACV,IAAI,CAACa,MAAM,CAACC,KAAK;QAEzC,IAAIH,KAAK,CAACI,IAAI,CAACC,OAAO,CAACC,QAAQ,CAACL,UAAU,CAAC,EAAE;AAC3C,UAAA,MAAMM,UAAU,GAAGR,IAAI,CAACS,GAAG,CAAC,YAAY,CAAC;AACzCD,UAAAA,UAAU,CAACE,OAAO,CAAEC,SAAS,IAAK;YAChC,IAAId,IAAI,GAAGc,SAAS,CAACrB,IAAI,CAACsB,QAAQ,CAACf,IAAI;YACvC,IAAI,EAAEA,IAAI,IAAII,KAAK,CAACI,IAAI,CAACQ,KAAK,CAAC,EAAE;cAC/B,MAAM,IAAIC,KAAK,CAAC,CAAA,gBAAA,EAAmBjB,IAAI,CAAkBK,eAAAA,EAAAA,UAAU,EAAE,CAAC;A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C,UAAU,CAACxC,IAAI,CACnB,CAAC;AAED,cAAA,MAAMyC,SAAS,GAAGf,eAAe,GAAG3B,CAAC,CAAC2C,eAAe,CAAC,GAAG,EAAEP,SAAS,CAAC,GAAGA,SAAS;cACjF,MAAMQ,UAAU,GAAGb,uBAAuB;AACtC;AACA;AACA;cACAW,SAAS;AACT;AACA;AACA;AACA1C,cAAAA,CAAC,CAACsC,cAAc,CAACjC,KAAK,CAACkC,QAAQ,CAACC,MAAM,CAACf,CAAC,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,CAACiB,SAAS,CAAC,CAAC;AAClGhD,cAAAA,IAAI,CAACmD,WAAW,CAACD,UAAU,CAAC;AAC9B,aAAC,CAAC;AACF7B,YAAAA,SAAS,CAACO,KAAK,CAACwB,gBAAgB,CAAC3B,gBAAgB,CAAC;YAClDJ,SAAS,CAACgC,MAAM,EAAE;AACpB,WAAC,CAAC;UACF,IAAI3C,IAAI,CAACS,GAAG,CAAC,YAAY,CAAC,CAACmB,MAAM,KAAK,CAAC,EAAE;YACvC5B,IAAI,CAAC2C,MAAM,EAAE;AACf;AACF;OACD;AAEDC,MAAAA,OAAOA,CAAC5C,IAAI,EAAEC,KAAK,EAAE;QACnBA,KAAK,CAACkC,QAAQ,GAAG,IAAIU,0BAAU,CAACjD,CAAC,EAAEI,IAAI,CAAC;AAC1C;AACF;GACD;AACH;;;;"}
|
|
@@ -23,12 +23,12 @@ function babelPluginTransformFeatures (babel) {
|
|
|
23
23
|
visitor: {
|
|
24
24
|
ImportDeclaration(path, state) {
|
|
25
25
|
const importPath = path.node.source.value;
|
|
26
|
-
if (
|
|
26
|
+
if (state.opts.sources.includes(importPath)) {
|
|
27
27
|
const specifiers = path.get('specifiers');
|
|
28
28
|
specifiers.forEach(specifier => {
|
|
29
29
|
let name = specifier.node.imported.name;
|
|
30
30
|
if (!(name in state.opts.flags)) {
|
|
31
|
-
throw new Error(`Unexpected flag ${name} imported from ${
|
|
31
|
+
throw new Error(`Unexpected flag ${name} imported from ${importPath}`);
|
|
32
32
|
}
|
|
33
33
|
let localBindingName = specifier.node.local.name;
|
|
34
34
|
let binding = specifier.scope.getBinding(localBindingName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-transform-features.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-features.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\nimport fs from 'fs';\n\nconst pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));\nconst version = pkg.version;\n\nconst isCanary = version.includes('alpha');\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (
|
|
1
|
+
{"version":3,"file":"babel-plugin-transform-features.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-features.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\nimport fs from 'fs';\n\nconst pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));\nconst version = pkg.version;\n\nconst isCanary = version.includes('alpha');\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (state.opts.sources.includes(importPath)) {\n const specifiers = path.get('specifiers');\n specifiers.forEach((specifier) => {\n let name = specifier.node.imported.name;\n if (!(name in state.opts.flags)) {\n throw new Error(`Unexpected flag ${name} imported from ${importPath}`);\n }\n let localBindingName = specifier.node.local.name;\n let binding = specifier.scope.getBinding(localBindingName);\n binding.referencePaths.forEach((p) => {\n let negateStatement = false;\n let node = p;\n\n if (parentIsUnary(p)) {\n negateStatement = true;\n node = p.parentPath;\n }\n let getConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier('features')\n ),\n t.identifier(name)\n );\n node.replaceWith(\n // if (LOG_FOO)\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').debug.LOG_FOO))\n t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [\n negateStatement ? t.unaryExpression('!', getConfig) : getConfig,\n ])\n );\n });\n specifier.scope.removeOwnBinding(localBindingName);\n specifier.remove();\n });\n if (path.get('specifiers').length === 0) {\n path.remove();\n }\n }\n },\n\n Program(path, state) {\n state.importer = new ImportUtil(t, path);\n },\n },\n };\n}\n"],"names":["pkg","JSON","parse","fs","readFileSync","version","includes","parentIsUnary","node","parent","type","operator","babel","types","t","name","visitor","ImportDeclaration","path","state","importPath","source","value","opts","sources","specifiers","get","forEach","specifier","imported","flags","Error","localBindingName","local","binding","scope","getBinding","referencePaths","p","negateStatement","parentPath","getConfig","memberExpression","callExpression","importer","import","identifier","replaceWith","unaryExpression","removeOwnBinding","remove","length","Program","ImportUtil"],"mappings":";;;;;;AAGA,MAAMA,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACC,EAAE,CAACC,YAAY,CAAC,IAAA,GAAA,CAAA,iBAAA,EAAA,qRAAA,CAA2C,EAAE,OAAO,CAAC,CAAC;AAC7F,MAAMC,OAAO,GAAGL,GAAG,CAACK,OAAO;AAEVA,OAAO,CAACC,QAAQ,CAAC,OAAO;AAEzC,SAASC,aAAaA,CAACC,IAAI,EAAE;AAC3B,EAAA,IAAIA,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,iBAAiB,IAAIF,IAAI,CAACC,MAAM,CAACE,QAAQ,KAAK,GAAG,EAAE;AAC1E,IAAA,OAAO,IAAI;AACb;AACA,EAAA,OAAO,KAAK;AACd;AAEe,qCAAA,EAAUC,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gBAAgB,CAChB5B,CAAC,CAAC4B,gBAAgB,CAChB5B,CAAC,CAAC6B,cAAc,CAACxB,KAAK,CAACyB,QAAQ,CAACC,MAAM,CAACP,CAAC,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,EAAE,EAAE,CAAC,EACtFxB,CAAC,CAACgC,UAAU,CAAC,WAAW,CAC1B,CAAC,EACDhC,CAAC,CAACgC,UAAU,CAAC,UAAU,CACzB,CAAC,EACDhC,CAAC,CAACgC,UAAU,CAAC/B,IAAI,CACnB,CAAC;AACDP,cAAAA,IAAI,CAACuC,WAAW;AACd;AACA;AACA;AACAjC,cAAAA,CAAC,CAAC6B,cAAc,CAACxB,KAAK,CAACyB,QAAQ,CAACC,MAAM,CAACP,CAAC,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,CAChFC,eAAe,GAAGzB,CAAC,CAACkC,eAAe,CAAC,GAAG,EAAEP,SAAS,CAAC,GAAGA,SAAS,CAChE,CACH,CAAC;AACH,aAAC,CAAC;AACFb,YAAAA,SAAS,CAACO,KAAK,CAACc,gBAAgB,CAACjB,gBAAgB,CAAC;YAClDJ,SAAS,CAACsB,MAAM,EAAE;AACpB,WAAC,CAAC;UACF,IAAIhC,IAAI,CAACQ,GAAG,CAAC,YAAY,CAAC,CAACyB,MAAM,KAAK,CAAC,EAAE;YACvCjC,IAAI,CAACgC,MAAM,EAAE;AACf;AACF;OACD;AAEDE,MAAAA,OAAOA,CAAClC,IAAI,EAAEC,KAAK,EAAE;QACnBA,KAAK,CAACyB,QAAQ,GAAG,IAAIS,0BAAU,CAACvC,CAAC,EAAEI,IAAI,CAAC;AAC1C;AACF;GACD;AACH;;;;"}
|
|
@@ -18,12 +18,12 @@ function babelPluginTransformLogging (babel) {
|
|
|
18
18
|
visitor: {
|
|
19
19
|
ImportDeclaration(path, state) {
|
|
20
20
|
const importPath = path.node.source.value;
|
|
21
|
-
if (
|
|
21
|
+
if (state.opts.sources.includes(importPath)) {
|
|
22
22
|
const specifiers = path.get('specifiers');
|
|
23
23
|
specifiers.forEach(specifier => {
|
|
24
24
|
let name = specifier.node.imported.name;
|
|
25
25
|
if (!(name in state.opts.flags)) {
|
|
26
|
-
throw new Error(`Unexpected flag ${name} imported from ${
|
|
26
|
+
throw new Error(`Unexpected flag ${name} imported from ${importPath}`);
|
|
27
27
|
}
|
|
28
28
|
let localBindingName = specifier.node.local.name;
|
|
29
29
|
let binding = specifier.scope.getBinding(localBindingName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-transform-logging.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-logging.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (importPath === state.opts.source) {\n const specifiers = path.get('specifiers');\n specifiers.forEach((specifier) => {\n let name = specifier.node.imported.name;\n if (!(name in state.opts.flags)) {\n throw new Error(`Unexpected flag ${name} imported from ${state.opts.source}`);\n }\n let localBindingName = specifier.node.local.name;\n let binding = specifier.scope.getBinding(localBindingName);\n const enableRuntimeActivation = Boolean(state.opts.runtimeKey);\n const strippableKey = enableRuntimeActivation ? state.opts.runtimeKey : state.opts.configKey;\n\n binding.referencePaths.forEach((p) => {\n let negateStatement = false;\n let node = p;\n if (parentIsUnary(p)) {\n negateStatement = true;\n node = p.parentPath;\n }\n let getConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier(strippableKey)\n ),\n t.identifier(name)\n );\n\n node.replaceWith(\n // if (LOG_FOO) {\n // // ...\n // }\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').debug.LOG_FOO)) {\n // // ...\n // }\n t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [\n negateStatement ? t.unaryExpression('!', getConfig) : getConfig,\n ])\n );\n\n if (enableRuntimeActivation) {\n // we do not yet support arbitrary runtime activation locations,\n // the only supported locations are `if (LOG)` style statements, no\n // ternaries or other more complex expressions\n const parentIfStatement = node.parentPath.type === 'IfStatement' ? node.parentPath : null;\n if (!parentIfStatement) {\n throw new Error(\n `Runtime activation of logging flags is only supported in if statements, but found node '${node.parentPath.type}'`\n );\n }\n\n // if (LOG_FOO) {\n // // ...\n // }\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').activeLogging.LOG_FOO)) {\n // if (getGlobalConfig('WarpDriveMirror').debug.LOG_FOO || globalThis.getWarpDriveRuntimeConfig().debug.LOG_FOO) {\n // // ...\n // }\n // }\n //\n // the outer-if is generated by the node-replace above. The inner if is generated here.\n const originalBody = parentIfStatement.node.consequent;\n\n // getGlobalConfig('WarpDriveMirror').debug.LOG_FOO\n const getActualConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier(state.opts.configKey)\n ),\n t.identifier(name)\n );\n\n // globalThis.getWarpDriveRuntimeConfig().debug.LOG_FOO\n const getRuntimeConfig = t.memberExpression(\n t.memberExpression(\n t.callExpression(\n t.memberExpression(t.identifier('globalThis'), t.identifier('getWarpDriveRuntimeConfig')),\n []\n ),\n t.identifier(state.opts.configKey)\n ),\n t.identifier(name)\n );\n\n // <getActualConfig> || <getRuntimeConfig>\n const ifExp = t.logicalExpression('||', getActualConfig, getRuntimeConfig);\n\n // if (<negateStatement>(<getActualConfig> || <getRuntimeConfig>)) <originalBody>\n const innerIfStatement = t.ifStatement(\n negateStatement ? t.unaryExpression('!', ifExp) : ifExp,\n originalBody\n );\n\n // replace the original body with the new if statement\n parentIfStatement.node.consequent = t.blockStatement([innerIfStatement]);\n } else {\n }\n });\n specifier.scope.removeOwnBinding(localBindingName);\n specifier.remove();\n });\n if (path.get('specifiers').length === 0) {\n path.remove();\n }\n }\n },\n\n Program(path, state) {\n state.importer = new ImportUtil(t, path);\n },\n },\n };\n}\n"],"names":["parentIsUnary","node","parent","type","operator","babel","types","t","name","visitor","ImportDeclaration","path","state","importPath","source","value","opts","specifiers","get","forEach","specifier","imported","flags","Error","localBindingName","local","binding","scope","getBinding","enableRuntimeActivation","Boolean","runtimeKey","strippableKey","configKey","referencePaths","p","negateStatement","parentPath","getConfig","memberExpression","callExpression","importer","import","identifier","replaceWith","unaryExpression","parentIfStatement","originalBody","consequent","getActualConfig","getRuntimeConfig","ifExp","logicalExpression","innerIfStatement","ifStatement","blockStatement","removeOwnBinding","remove","length","Program","ImportUtil"],"mappings":";;;;AAEA,SAASA,aAAaA,CAACC,IAAI,EAAE;AAC3B,EAAA,IAAIA,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,iBAAiB,IAAIF,IAAI,CAACC,MAAM,CAACE,QAAQ,KAAK,GAAG,EAAE;AAC1E,IAAA,OAAO,IAAI;AACb;AACA,EAAA,OAAO,KAAK;AACd;AAEe,oCAAA,EAAUC,KAAK,EAAE;EAC9B,MAAM;AAAEC,IAAAA,KAAK,EAAEC;AAAE,GAAC,GAAGF,KAAK;EAE1B,OAAO;AACLG,IAAAA,IAAI,EAAE,eAAe;AAAE;AACvBC,IAAAA,OAAO,EAAE;AACPC,MAAAA,iBAAiBA,CAACC,IAAI,EAAEC,KAAK,EAAE;QAC7B,MAAMC,UAAU,GAAGF,IAAI,CAACV,IAAI,CAACa,MAAM,CAACC,KAAK;AAEzC,QAAA,IAAIF,UAAU,KAAKD,KAAK,CAACI,IAAI,CAACF,MAAM,EAAE;AACpC,UAAA,MAAMG,UAAU,GAAGN,IAAI,CAACO,GAAG,CAAC,YAAY,CAAC;AACzCD,UAAAA,UAAU,CAACE,OAAO,CAAEC,SAAS,IAAK;YAChC,IA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;;;;"}
|
|
1
|
+
{"version":3,"file":"babel-plugin-transform-logging.cjs","sources":["../cjs-src/transforms/babel-plugin-transform-logging.js"],"sourcesContent":["import { ImportUtil } from 'babel-import-util';\n\nfunction parentIsUnary(node) {\n if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') {\n return true;\n }\n return false;\n}\n\nexport default function (babel) {\n const { types: t } = babel;\n\n return {\n name: 'ast-transform', // not required\n visitor: {\n ImportDeclaration(path, state) {\n const importPath = path.node.source.value;\n\n if (state.opts.sources.includes(importPath)) {\n const specifiers = path.get('specifiers');\n specifiers.forEach((specifier) => {\n let name = specifier.node.imported.name;\n if (!(name in state.opts.flags)) {\n throw new Error(`Unexpected flag ${name} imported from ${importPath}`);\n }\n let localBindingName = specifier.node.local.name;\n let binding = specifier.scope.getBinding(localBindingName);\n const enableRuntimeActivation = Boolean(state.opts.runtimeKey);\n const strippableKey = enableRuntimeActivation ? state.opts.runtimeKey : state.opts.configKey;\n\n binding.referencePaths.forEach((p) => {\n let negateStatement = false;\n let node = p;\n if (parentIsUnary(p)) {\n negateStatement = true;\n node = p.parentPath;\n }\n let getConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier(strippableKey)\n ),\n t.identifier(name)\n );\n\n node.replaceWith(\n // if (LOG_FOO) {\n // // ...\n // }\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').debug.LOG_FOO)) {\n // // ...\n // }\n t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [\n negateStatement ? t.unaryExpression('!', getConfig) : getConfig,\n ])\n );\n\n if (enableRuntimeActivation) {\n // we do not yet support arbitrary runtime activation locations,\n // the only supported locations are `if (LOG)` style statements, no\n // ternaries or other more complex expressions\n const parentIfStatement = node.parentPath.type === 'IfStatement' ? node.parentPath : null;\n if (!parentIfStatement) {\n throw new Error(\n `Runtime activation of logging flags is only supported in if statements, but found node '${node.parentPath.type}'`\n );\n }\n\n // if (LOG_FOO) {\n // // ...\n // }\n // =>\n // if (macroCondition(getGlobalConfig('WarpDriveMirror').activeLogging.LOG_FOO)) {\n // if (getGlobalConfig('WarpDriveMirror').debug.LOG_FOO || globalThis.getWarpDriveRuntimeConfig().debug.LOG_FOO) {\n // // ...\n // }\n // }\n //\n // the outer-if is generated by the node-replace above. The inner if is generated here.\n const originalBody = parentIfStatement.node.consequent;\n\n // getGlobalConfig('WarpDriveMirror').debug.LOG_FOO\n const getActualConfig = t.memberExpression(\n t.memberExpression(\n t.memberExpression(\n t.callExpression(state.importer.import(p, '@embroider/macros', 'getGlobalConfig'), []),\n t.identifier('WarpDriveMirror')\n ),\n t.identifier(state.opts.configKey)\n ),\n t.identifier(name)\n );\n\n // globalThis.getWarpDriveRuntimeConfig().debug.LOG_FOO\n const getRuntimeConfig = t.memberExpression(\n t.memberExpression(\n t.callExpression(\n t.memberExpression(t.identifier('globalThis'), t.identifier('getWarpDriveRuntimeConfig')),\n []\n ),\n t.identifier(state.opts.configKey)\n ),\n t.identifier(name)\n );\n\n // <getActualConfig> || <getRuntimeConfig>\n const ifExp = t.logicalExpression('||', getActualConfig, getRuntimeConfig);\n\n // if (<negateStatement>(<getActualConfig> || <getRuntimeConfig>)) <originalBody>\n const innerIfStatement = t.ifStatement(\n negateStatement ? t.unaryExpression('!', ifExp) : ifExp,\n originalBody\n );\n\n // replace the original body with the new if statement\n parentIfStatement.node.consequent = t.blockStatement([innerIfStatement]);\n } else {\n }\n });\n specifier.scope.removeOwnBinding(localBindingName);\n specifier.remove();\n });\n if (path.get('specifiers').length === 0) {\n path.remove();\n }\n }\n },\n\n Program(path, state) {\n state.importer = new ImportUtil(t, path);\n },\n },\n };\n}\n"],"names":["parentIsUnary","node","parent","type","operator","babel","types","t","name","visitor","ImportDeclaration","path","state","importPath","source","value","opts","sources","includes","specifiers","get","forEach","specifier","imported","flags","Error","localBindingName","local","binding","scope","getBinding","enableRuntimeActivation","Boolean","runtimeKey","strippableKey","configKey","referencePaths","p","negateStatement","parentPath","getConfig","memberExpression","callExpression","importer","import","identifier","replaceWith","unaryExpression","parentIfStatement","originalBody","consequent","getActualConfig","getRuntimeConfig","ifExp","logicalExpression","innerIfStatement","ifStatement","blockStatement","removeOwnBinding","remove","length","Program","ImportUtil"],"mappings":";;;;AAEA,SAASA,aAAaA,CAACC,IAAI,EAAE;AAC3B,EAAA,IAAIA,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,iBAAiB,IAAIF,IAAI,CAACC,MAAM,CAACE,QAAQ,KAAK,GAAG,EAAE;AAC1E,IAAA,OAAO,IAAI;AACb;AACA,EAAA,OAAO,KAAK;AACd;AAEe,oCAAA,EAAUC,KAAK,EAAE;EAC9B,MAAM;AAAEC,IAAAA,KAAK,EAAEC;AAAE,GAAC,GAAGF,KAAK;EAE1B,OAAO;AACLG,IAAAA,IAAI,EAAE,eAAe;AAAE;AACvBC,IAAAA,OAAO,EAAE;AACPC,MAAAA,iBAAiBA,CAACC,IAAI,EAAEC,KAAK,EAAE;QAC7B,MAAMC,UAAU,GAAGF,IAAI,CAACV,IAAI,CAACa,MAAM,CAACC,KAAK;QAEzC,IAAIH,KAAK,CAACI,IAAI,CAACC,OAAO,CAACC,QAAQ,CAACL,UAAU,CAAC,EAAE;AAC3C,UAAA,MAAMM,UAAU,GAAGR,IAAI,CAACS,GAAG,CAAC,YAAY,CAAC;AACzCD,UAAAA,UAAU,CAACE,OAAO,CAAEC,SAAS,IAAK;YAChC,IAAId,IAAI,GAAGc,SAAS,CAACrB,IAAI,CAACsB,QAAQ,CAACf,IAAI;YACvC,IAAI,EAAEA,IAAI,IAAII,KAAK,CAACI,IAAI,CAACQ,KAAK,CAAC,EAAE;cAC/B,MAAM,IAAIC,KAAK,CAAC,CAAA,gBAAA,EAAmBjB,IAAI,CAAkBK,eAAAA,EAAAA,UAAU,EAAE,CAAC;AACxE;YACA,IAAIa,gBAAgB,GAAGJ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