@warp-drive/build-config 5.8.0-alpha.4 → 5.8.0-alpha.6

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.
@@ -1,7 +1,26 @@
1
1
  import { getDeprecations } from "./-private/utils/deprecations.js";
2
2
  import { getFeatures } from "./-private/utils/features.js";
3
3
  import * as LOGGING from "./debugging.js";
4
- export type WarpDriveConfig = {
4
+ import type { PluginItem } from "@babel/core";
5
+ /**
6
+ * Create the Babel plugin for WarpDrive
7
+ *
8
+ * Note: If your project already uses [@embroider/macros](https://www.npmjs.com/package/@embroider/macros)
9
+ * then you should use {@link setConfig} instead of this function.
10
+ *
11
+ * @param options WarpDrive configuration options
12
+ * @returns An array of Babel plugins
13
+ */
14
+ export declare function babelPlugin(options: WarpDriveConfig): {
15
+ gts: Function[];
16
+ js: PluginItem[];
17
+ };
18
+ /**
19
+ * Build Configuration options for WarpDrive that
20
+ * allow adjusting logging, deprecations, canary features
21
+ * and optional features.
22
+ */
23
+ export interface WarpDriveConfig {
5
24
  /**
6
25
  * An object of key/value pairs of logging flags
7
26
  *
@@ -44,6 +63,13 @@ export type WarpDriveConfig = {
44
63
  * `5.3` will remove all the support for the deprecated
45
64
  * features for associated deprecations.
46
65
  *
66
+ * :::caution **Universal Apps**
67
+ * This value should be at least `5.6` for universal/non-ember
68
+ * applications as that was the first version that builds
69
+ * without any ember-source dependencies provided all deprecations
70
+ * are resolved.
71
+ * :::
72
+ *
47
73
  * See {@link DEPRECATIONS | deprecations} for more details.
48
74
  */
49
75
  compatWith?: `${number}.${number}`;
@@ -81,8 +107,8 @@ export type WarpDriveConfig = {
81
107
  * @private
82
108
  */
83
109
  forceMode?: "testing" | "production" | "development";
84
- };
85
- type InternalWarpDriveConfig = {
110
+ }
111
+ interface InternalWarpDriveConfig {
86
112
  debug: typeof LOGGING;
87
113
  polyfillUUID: boolean;
88
114
  includeDataAdapter: boolean;
@@ -95,7 +121,57 @@ type InternalWarpDriveConfig = {
95
121
  PRODUCTION: boolean;
96
122
  DEBUG: boolean;
97
123
  };
98
- };
124
+ }
125
+ /**
126
+ * Sets the build configuration for WarpDrive that ensures
127
+ * environment specific behaviors are activated/deactivated
128
+ * and enables adjusting log instrumentation, removing code
129
+ * that supports deprecated features, enabling canary features
130
+ * and enabling/disabling optional features.
131
+ *
132
+ * The library uses [@embroider/macros](https://www.npmjs.com/package/@embroider/macros)
133
+ * to perform this final configuration code transform.
134
+ *
135
+ * This is a low level API for configuring WarpDrive. If your
136
+ * project does not use `@embroider/macros` then you should use
137
+ * {@link babelPlugin} instead of this function.
138
+ *
139
+ * ### Example
140
+ *
141
+ * ```ts
142
+ * import { setConfig } from '@warp-drive/core/build-config';
143
+ * import { buildMacros } from '@embroider/macros/babel';
144
+ *
145
+ * const Macros = buildMacros({
146
+ * configure: (config) => {
147
+ * setConfig(config, {
148
+ * compatWith: '5.6'
149
+ * });
150
+ * },
151
+ * });
152
+ *
153
+ * export default {
154
+ * plugins: [
155
+ * // babel-plugin-debug-macros is temporarily needed
156
+ * // to convert deprecation/warn calls into console.warn
157
+ * [
158
+ * 'babel-plugin-debug-macros',
159
+ * {
160
+ * flags: [],
161
+ *
162
+ * debugTools: {
163
+ * isDebug: true,
164
+ * source: '@ember/debug',
165
+ * assertPredicateIndex: 1,
166
+ * },
167
+ * },
168
+ * 'ember-data-specific-macros-stripping-test',
169
+ * ],
170
+ * ...Macros.babelMacros,
171
+ * ],
172
+ * };
173
+ * ```
174
+ */
99
175
  export declare function setConfig(macros: object, config: WarpDriveConfig): void;
100
176
  export declare function setConfig(context: object, appRoot: string, config: WarpDriveConfig): void;
101
177
  export {};
@@ -7,6 +7,7 @@ const semver = require('semver');
7
7
  const fs = require('fs');
8
8
  const path = require('path');
9
9
  const url = require('url');
10
+ require('@embroider/macros/src/babel.js');
10
11
 
11
12
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
13
  function getEnv(forceMode) {
@@ -593,17 +594,75 @@ function createLoggingConfig(env, debug) {
593
594
  * - {@link WarpDriveConfig.includeDataAdapterInProduction | includeDataAdapterInProduction}
594
595
  * - {@link WarpDriveConfig.compatWith | compatWith}
595
596
  *
596
- *
597
- *
598
597
  * @module
599
598
  */
599
+
600
600
  const _MacrosConfig = EmbroiderMacros.MacrosConfig;
601
+
602
+ /**
603
+ * Build Configuration options for WarpDrive that
604
+ * allow adjusting logging, deprecations, canary features
605
+ * and optional features.
606
+ */
607
+
601
608
  function recastMacrosConfig(macros) {
602
609
  if (!('globalConfig' in macros)) {
603
610
  throw new Error('Expected MacrosConfig to have a globalConfig property');
604
611
  }
605
612
  return macros;
606
613
  }
614
+
615
+ /**
616
+ * Sets the build configuration for WarpDrive that ensures
617
+ * environment specific behaviors are activated/deactivated
618
+ * and enables adjusting log instrumentation, removing code
619
+ * that supports deprecated features, enabling canary features
620
+ * and enabling/disabling optional features.
621
+ *
622
+ * The library uses [@embroider/macros](https://www.npmjs.com/package/@embroider/macros)
623
+ * to perform this final configuration code transform.
624
+ *
625
+ * This is a low level API for configuring WarpDrive. If your
626
+ * project does not use `@embroider/macros` then you should use
627
+ * {@link babelPlugin} instead of this function.
628
+ *
629
+ * ### Example
630
+ *
631
+ * ```ts
632
+ * import { setConfig } from '@warp-drive/core/build-config';
633
+ * import { buildMacros } from '@embroider/macros/babel';
634
+ *
635
+ * const Macros = buildMacros({
636
+ * configure: (config) => {
637
+ * setConfig(config, {
638
+ * compatWith: '5.6'
639
+ * });
640
+ * },
641
+ * });
642
+ *
643
+ * export default {
644
+ * plugins: [
645
+ * // babel-plugin-debug-macros is temporarily needed
646
+ * // to convert deprecation/warn calls into console.warn
647
+ * [
648
+ * 'babel-plugin-debug-macros',
649
+ * {
650
+ * flags: [],
651
+ *
652
+ * debugTools: {
653
+ * isDebug: true,
654
+ * source: '@ember/debug',
655
+ * assertPredicateIndex: 1,
656
+ * },
657
+ * },
658
+ * 'ember-data-specific-macros-stripping-test',
659
+ * ],
660
+ * ...Macros.babelMacros,
661
+ * ],
662
+ * };
663
+ * ```
664
+ */
665
+
607
666
  function setConfig(context, appRootOrConfig, config) {
608
667
  const isEmberClassicUsage = arguments.length === 3;
609
668
  const macros = recastMacrosConfig(isEmberClassicUsage ? _MacrosConfig.for(context, appRootOrConfig) : context);
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
6
  import { C as CURRENT_FEATURES } from './canary-features-BM0to_ys.js';
7
7
  import { L as LOGGING } from './debugging-DgRWKeE4.js';
8
+ import { buildMacros } from '@embroider/macros/src/babel.js';
8
9
 
9
10
  function getEnv(forceMode) {
10
11
  const FORCE_TESTING = forceMode === 'testing' || forceMode === 'development' || forceMode === 'debug';
@@ -229,17 +230,115 @@ function createLoggingConfig(env, debug) {
229
230
  * - {@link WarpDriveConfig.includeDataAdapterInProduction | includeDataAdapterInProduction}
230
231
  * - {@link WarpDriveConfig.compatWith | compatWith}
231
232
  *
233
+ * @module
234
+ */
235
+
236
+
237
+ /**
238
+ * Create the Babel plugin for WarpDrive
232
239
  *
240
+ * Note: If your project already uses [@embroider/macros](https://www.npmjs.com/package/@embroider/macros)
241
+ * then you should use {@link setConfig} instead of this function.
233
242
  *
234
- * @module
243
+ * @param options WarpDrive configuration options
244
+ * @returns An array of Babel plugins
235
245
  */
246
+ function babelPlugin(options) {
247
+ const macros = buildMacros({
248
+ configure: config => {
249
+ setConfig(config, options);
250
+ }
251
+ });
252
+ const env = getEnv(options.forceMode);
253
+ return {
254
+ gts: macros.templateMacros,
255
+ js: [
256
+ // babel-plugin-debug-macros is temporarily needed
257
+ // to convert deprecation/warn calls into console.warn
258
+ [resolve('babel-plugin-debug-macros'), {
259
+ flags: [],
260
+ debugTools: {
261
+ isDebug: env.DEBUG,
262
+ source: '@ember/debug',
263
+ assertPredicateIndex: 1
264
+ }
265
+ }, 'ember-data-specific-macros-stripping-test'], ...macros.babelMacros]
266
+ };
267
+ }
268
+ function resolve(module) {
269
+ const filePath = import.meta.resolve(module);
270
+ const file = filePath.replace('/node_modules/.vite-temp/', '/');
271
+ if (file.startsWith('file://')) {
272
+ return file.slice(7);
273
+ }
274
+ return file;
275
+ }
236
276
  const _MacrosConfig = EmbroiderMacros.MacrosConfig;
277
+
278
+ /**
279
+ * Build Configuration options for WarpDrive that
280
+ * allow adjusting logging, deprecations, canary features
281
+ * and optional features.
282
+ */
283
+
237
284
  function recastMacrosConfig(macros) {
238
285
  if (!('globalConfig' in macros)) {
239
286
  throw new Error('Expected MacrosConfig to have a globalConfig property');
240
287
  }
241
288
  return macros;
242
289
  }
290
+
291
+ /**
292
+ * Sets the build configuration for WarpDrive that ensures
293
+ * environment specific behaviors are activated/deactivated
294
+ * and enables adjusting log instrumentation, removing code
295
+ * that supports deprecated features, enabling canary features
296
+ * and enabling/disabling optional features.
297
+ *
298
+ * The library uses [@embroider/macros](https://www.npmjs.com/package/@embroider/macros)
299
+ * to perform this final configuration code transform.
300
+ *
301
+ * This is a low level API for configuring WarpDrive. If your
302
+ * project does not use `@embroider/macros` then you should use
303
+ * {@link babelPlugin} instead of this function.
304
+ *
305
+ * ### Example
306
+ *
307
+ * ```ts
308
+ * import { setConfig } from '@warp-drive/core/build-config';
309
+ * import { buildMacros } from '@embroider/macros/babel';
310
+ *
311
+ * const Macros = buildMacros({
312
+ * configure: (config) => {
313
+ * setConfig(config, {
314
+ * compatWith: '5.6'
315
+ * });
316
+ * },
317
+ * });
318
+ *
319
+ * export default {
320
+ * plugins: [
321
+ * // babel-plugin-debug-macros is temporarily needed
322
+ * // to convert deprecation/warn calls into console.warn
323
+ * [
324
+ * 'babel-plugin-debug-macros',
325
+ * {
326
+ * flags: [],
327
+ *
328
+ * debugTools: {
329
+ * isDebug: true,
330
+ * source: '@ember/debug',
331
+ * assertPredicateIndex: 1,
332
+ * },
333
+ * },
334
+ * 'ember-data-specific-macros-stripping-test',
335
+ * ],
336
+ * ...Macros.babelMacros,
337
+ * ],
338
+ * };
339
+ * ```
340
+ */
341
+
243
342
  function setConfig(context, appRootOrConfig, config) {
244
343
  const isEmberClassicUsage = arguments.length === 3;
245
344
  const macros = recastMacrosConfig(isEmberClassicUsage ? _MacrosConfig.for(context, appRootOrConfig) : context);
@@ -284,4 +383,4 @@ function setConfig(context, appRootOrConfig, config) {
284
383
  macros.setGlobalConfig(import.meta.filename, 'WarpDrive', finalizedConfig);
285
384
  }
286
385
 
287
- export { setConfig };
386
+ export { babelPlugin, setConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/build-config",
3
- "version": "5.8.0-alpha.4",
3
+ "version": "5.8.0-alpha.6",
4
4
  "description": "Provides Build Configuration for projects using WarpDrive or EmberData",
5
5
  "keywords": [
6
6
  "ember-data",
@@ -36,13 +36,14 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
+ "babel-plugin-debug-macros": "^2.0.0",
39
40
  "@embroider/macros": "^1.18.1",
40
41
  "@embroider/addon-shim": "^1.10.0",
41
42
  "babel-import-util": "^2.1.1",
42
43
  "semver": "^7.7.2"
43
44
  },
44
45
  "devDependencies": {
45
- "@warp-drive/internal-config": "5.8.0-alpha.4",
46
+ "@warp-drive/internal-config": "5.8.0-alpha.6",
46
47
  "@types/babel__core": "^7.20.5",
47
48
  "@types/node": "^20.19.11",
48
49
  "@babel/plugin-transform-typescript": "^7.28.0",