@warp-drive/build-config 0.0.0-beta.1 → 0.0.0-beta.2

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.
@@ -0,0 +1,848 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const EmbroiderMacros = require('@embroider/macros/src/node.js');
6
+ const semver = require('semver');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
+ function getEnv() {
12
+ const {
13
+ EMBER_ENV,
14
+ IS_TESTING,
15
+ EMBER_CLI_TEST_COMMAND,
16
+ NODE_ENV
17
+ } = process.env;
18
+ const PRODUCTION = EMBER_ENV === 'production' || !EMBER_ENV && NODE_ENV === 'production';
19
+ const DEBUG = !PRODUCTION;
20
+ const TESTING = DEBUG || Boolean(EMBER_ENV === 'test' || IS_TESTING || EMBER_CLI_TEST_COMMAND);
21
+ return {
22
+ TESTING,
23
+ PRODUCTION,
24
+ DEBUG
25
+ };
26
+ }
27
+
28
+ // ========================
29
+ // FOR CONTRIBUTING AUTHORS
30
+ //
31
+ // Deprecations here should also have guides PR'd to the emberjs deprecation app
32
+ //
33
+ // github: https://github.com/ember-learn/deprecation-app
34
+ // website: https://deprecations.emberjs.com
35
+ //
36
+ // Each deprecation should also be given an associated URL pointing to the
37
+ // relevant guide.
38
+ //
39
+ // URLs should be of the form: https://deprecations.emberjs.com/v<major>.x#toc_<fileName>
40
+ // where <major> is the major version of the deprecation and <fileName> is the
41
+ // name of the markdown file in the guides repo.
42
+ //
43
+ // ========================
44
+ //
45
+
46
+ /**
47
+ * ## Deprecations
48
+ *
49
+ * EmberData allows users to opt-in and remove code that exists to support deprecated
50
+ * behaviors.
51
+ *
52
+ * If your app has resolved all deprecations present in a given version,
53
+ * you may specify that version as your "compatibility" version to remove
54
+ * the code that supported the deprecated behavior from your app.
55
+ *
56
+ * For instance, if a deprecation was introduced in 3.13, and the app specifies
57
+ * 3.13 as its minimum version compatibility, any deprecations introduced before
58
+ * or during 3.13 would be stripped away.
59
+ *
60
+ * An app can use a different version than what it specifies as it's compatibility
61
+ * version. For instance, an App could be using `3.16` while specifying compatibility
62
+ * with `3.12`. This would remove any deprecations that were present in or before `3.12`
63
+ * but keep support for anything deprecated in or above `3.13`.
64
+ *
65
+ * ### Configuring Compatibility
66
+ *
67
+ * To configure your compatibility version, set the `compatWith` to the version you
68
+ * are compatible with on the `emberData` config in your `ember-cli-build.js` file.
69
+ *
70
+ * ```js
71
+ * const { setConfig } = await import('@warp-drive/build-config');
72
+ *
73
+ * let app = new EmberApp(defaults, {});
74
+ *
75
+ * setConfig(app, __dirname, { compatWith: '3.12' });
76
+ * ```
77
+ *
78
+ * Alternatively, individual deprecations can be resolved (and thus have its support stripped)
79
+ * via one of the flag names listed below. For instance, given a flag named `DEPRECATE_FOO_BEHAVIOR`.
80
+ *
81
+ * This capability is interopable with `compatWith`. You may set `compatWith` and then selectively resolve
82
+ * additional deprecations, or set compatWith and selectively un-resolve specific deprecations.
83
+ *
84
+ * Note: EmberData does not test against permutations of deprecations being stripped, our tests run against
85
+ * "all deprecated code included" and "all deprecated code removed". Unspecified behavior may sometimes occur
86
+ * when removing code for only some deprecations associated to a version number.
87
+ *
88
+ * ```js
89
+ * const { setConfig } = await import('@warp-drive/build-config');
90
+ *
91
+ * let app = new EmberApp(defaults, {});
92
+ *
93
+ * setConfig(app, __dirname, {
94
+ * deprecations: {
95
+ * DEPRECATE_FOO_BEHAVIOR: false // set to false to strip this code
96
+ * DEPRECATE_BAR_BEHAVIOR: true // force to true to not strip this code
97
+ * }
98
+ * });
99
+ * ```
100
+ *
101
+ * The complete list of which versions specific deprecations will be removed in
102
+ * can be found [here](https://github.com/emberjs/data/blob/main/packages/build-config/src/virtual/deprecation-versions.ts "List of EmberData Deprecations")
103
+ *
104
+ * @module @warp-drive/build-config/deprecations
105
+ * @main @warp-drive/build-config/deprecations
106
+ */
107
+
108
+ /**
109
+ * The following list represents deprecations currently active.
110
+ *
111
+ * Some deprecation flags guard multiple deprecation IDs. All
112
+ * associated IDs are listed.
113
+ *
114
+ * @class CurrentDeprecations
115
+ * @public
116
+ */
117
+ const DEPRECATE_CATCH_ALL = '99.0';
118
+ /**
119
+ * **id: ember-data:deprecate-non-strict-types**
120
+ *
121
+ * Currently, EmberData expects that the `type` property associated with
122
+ * a resource follows several conventions.
123
+ *
124
+ * - The `type` property must be a non-empty string
125
+ * - The `type` property must be singular
126
+ * - The `type` property must be dasherized
127
+ *
128
+ * We are deprecating support for types that do not match this pattern
129
+ * in order to unlock future improvements in which we can support `type`
130
+ * being any string of your choosing.
131
+ *
132
+ * The goal is that in the future, you will be able to use any string
133
+ * so long as it matches what your configured cache, identifier generation,
134
+ * and schemas expect.
135
+ *
136
+ * E.G. It will matter not that your string is in a specific format like
137
+ * singular, dasherized, etc. so long as everywhere you refer to the type
138
+ * you use the same string.
139
+ *
140
+ * If using @ember-data/model, there will always be a restriction that the
141
+ * `type` must match the path on disk where the model is defined.
142
+ *
143
+ * e.g. `app/models/foo/bar-bem.js` must have a type of `foo/bar-bem`
144
+ *
145
+ * @property DEPRECATE_NON_STRICT_TYPES
146
+ * @since 5.3
147
+ * @until 6.0
148
+ * @public
149
+ */
150
+ const DEPRECATE_NON_STRICT_TYPES = '5.3';
151
+
152
+ /**
153
+ * **id: ember-data:deprecate-non-strict-id**
154
+ *
155
+ * Currently, EmberData expects that the `id` property associated with
156
+ * a resource is a string.
157
+ *
158
+ * However, for legacy support in many locations we would accept a number
159
+ * which would then immediately be coerced into a string.
160
+ *
161
+ * We are deprecating this legacy support for numeric IDs.
162
+ *
163
+ * The goal is that in the future, you will be able to use any ID format
164
+ * so long as everywhere you refer to the ID you use the same format.
165
+ *
166
+ * However, for identifiers we will always use string IDs and so any
167
+ * custom identifier configuration should provide a string ID.
168
+ *
169
+ * @property DEPRECATE_NON_STRICT_ID
170
+ * @since 5.3
171
+ * @until 6.0
172
+ * @public
173
+ */
174
+ const DEPRECATE_NON_STRICT_ID = '5.3';
175
+
176
+ /**
177
+ * **id: <none yet assigned>**
178
+ *
179
+ * This is a planned deprecation which will trigger when observer or computed
180
+ * chains are used to watch for changes on any EmberData LiveArray, CollectionRecordArray,
181
+ * ManyArray or PromiseManyArray.
182
+ *
183
+ * Support for these chains is currently guarded by the deprecation flag
184
+ * listed here, enabling removal of the behavior if desired.
185
+ *
186
+ * @property DEPRECATE_COMPUTED_CHAINS
187
+ * @since 5.0
188
+ * @until 6.0
189
+ * @public
190
+ */
191
+ const DEPRECATE_COMPUTED_CHAINS = '5.0';
192
+
193
+ /**
194
+ * **id: ember-data:deprecate-legacy-imports**
195
+ *
196
+ * Deprecates when importing from `ember-data/*` instead of `@ember-data/*`
197
+ * in order to prepare for the eventual removal of the legacy `ember-data/*`
198
+ *
199
+ * All imports from `ember-data/*` should be updated to `@ember-data/*`
200
+ * except for `ember-data/store`. When you are using `ember-data` (as opposed to
201
+ * installing the indivudal packages) you should import from `ember-data/store`
202
+ * instead of `@ember-data/store` in order to receive the appropriate configuration
203
+ * of defaults.
204
+ *
205
+ * @property DEPRECATE_LEGACY_IMPORTS
206
+ * @since 5.3
207
+ * @until 6.0
208
+ * @public
209
+ */
210
+ const DEPRECATE_LEGACY_IMPORTS = '5.3';
211
+
212
+ /**
213
+ * **id: ember-data:deprecate-non-unique-collection-payloads**
214
+ *
215
+ * Deprecates when the data for a hasMany relationship contains
216
+ * duplicate identifiers.
217
+ *
218
+ * Previously, relationships would silently de-dupe the data
219
+ * when received, but this behavior is being removed in favor
220
+ * of erroring if the same related record is included multiple
221
+ * times.
222
+ *
223
+ * For instance, in JSON:API the below relationship data would
224
+ * be considered invalid:
225
+ *
226
+ * ```json
227
+ * {
228
+ * "data": {
229
+ * "type": "article",
230
+ * "id": "1",
231
+ * "relationships": {
232
+ * "comments": {
233
+ * "data": [
234
+ * { "type": "comment", "id": "1" },
235
+ * { "type": "comment", "id": "2" },
236
+ * { "type": "comment", "id": "1" } // duplicate
237
+ * ]
238
+ * }
239
+ * }
240
+ * }
241
+ * ```
242
+ *
243
+ * To resolve this deprecation, either update your server to
244
+ * not include duplicate data, or implement normalization logic
245
+ * in either a request handler or serializer which removes
246
+ * duplicate data from relationship payloads.
247
+ *
248
+ * @property DEPRECATE_NON_UNIQUE_PAYLOADS
249
+ * @since 5.3
250
+ * @until 6.0
251
+ * @public
252
+ */
253
+ const DEPRECATE_NON_UNIQUE_PAYLOADS = '5.3';
254
+
255
+ /**
256
+ * **id: ember-data:deprecate-relationship-remote-update-clearing-local-state**
257
+ *
258
+ * Deprecates when a relationship is updated remotely and the local state
259
+ * is cleared of all changes except for "new" records.
260
+ *
261
+ * Instead, any records not present in the new payload will be considered
262
+ * "removed" while any records present in the new payload will be considered "added".
263
+ *
264
+ * This allows us to "commit" local additions and removals, preserving any additions
265
+ * or removals that are not yet reflected in the remote state.
266
+ *
267
+ * For instance, given the following initial state:
268
+ *
269
+ * remote: A, B, C
270
+ * local: add D, E
271
+ * remove B, C
272
+ * => A, D, E
273
+ *
274
+ *
275
+ * If after an update, the remote state is now A, B, D, F then the new state will be
276
+ *
277
+ * remote: A, B, D, F
278
+ * local: add E
279
+ * remove B
280
+ * => A, D, E, F
281
+ *
282
+ * Under the old behavior the updated local state would instead have been
283
+ * => A, B, D, F
284
+ *
285
+ * Similarly, if a belongsTo remote State was A while its local state was B,
286
+ * then under the old behavior if the remote state changed to C, the local state
287
+ * would be updated to C. Under the new behavior, the local state would remain B.
288
+ *
289
+ * If the remote state was A while its local state was `null`, then under the old
290
+ * behavior if the remote state changed to C, the local state would be updated to C.
291
+ * Under the new behavior, the local state would remain `null`.
292
+ *
293
+ * Thus the new correct mental model is that the state of the relationship at any point
294
+ * in time is whatever the most recent remote state is, plus any local additions or removals
295
+ * you have made that have not yet been reflected by the remote state.
296
+ *
297
+ * > Note: The old behavior extended to modifying the inverse of a relationship. So if
298
+ * > you had local state not reflected in the new remote state, inverses would be notified
299
+ * > and their state reverted as well when "resetting" the relationship.
300
+ * > Under the new behavior, since the local state is preserved the inverses will also
301
+ * > not be reverted.
302
+ *
303
+ * ### Resolving this deprecation
304
+ *
305
+ * Resolving this deprecation can be done individually for each relationship
306
+ * or globally for all relationships.
307
+ *
308
+ * To resolve it globally, set the `DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE`
309
+ * to `false` in ember-cli-build.js
310
+ *
311
+ * ```js
312
+ * const { setConfig } = await import('@warp-drive/build-config');
313
+ *
314
+ * let app = new EmberApp(defaults, {});
315
+ *
316
+ * setConfig(app, __dirname, {
317
+ * deprecations: {
318
+ * // set to false to strip the deprecated code (thereby opting into the new behavior)
319
+ * DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: false
320
+ * }
321
+ * });
322
+ * ```
323
+ *
324
+ * To resolve this deprecation on an individual relationship, adjust the `options` passed to
325
+ * the relationship. For relationships with inverses, both sides MUST be migrated to the new
326
+ * behavior at the same time.
327
+ *
328
+ * ```js
329
+ * class Person extends Model {
330
+ * @hasMany('person', {
331
+ * async: false,
332
+ * inverse: null,
333
+ * resetOnRemoteUpdate: false
334
+ * }) children;
335
+ *
336
+ * @belongsTo('person', {
337
+ * async: false,
338
+ * inverse: null,
339
+ * resetOnRemoteUpdate: false
340
+ * }) parent;
341
+ * }
342
+ * ```
343
+ *
344
+ * > Note: false is the only valid value here, all other values (including missing)
345
+ * > will be treated as true, where `true` is the legacy behavior that is now deprecated.
346
+ *
347
+ * Once you have migrated all relationships, you can remove the the resetOnRemoteUpdate
348
+ * option and set the deprecation flag to false in ember-cli-build.
349
+ *
350
+ * ### What if I don't want the new behavior?
351
+ *
352
+ * EmberData's philosophy is to not make assumptions about your application. Where possible
353
+ * we seek out "100%" solutions – solutions that work for all use cases - and where that is
354
+ * not possible we default to "90%" solutions – solutions that work for the vast majority of use
355
+ * cases. In the case of "90%" solutions we look for primitives that allow you to resolve the
356
+ * 10% case in your application. If no such primitives exist, we provide an escape hatch that
357
+ * ensures you can build the behavior you need without adopting the cost of the default solution.
358
+ *
359
+ * In this case, the old behavior was a "40%" solution. The inability for an application developer
360
+ * to determine what changes were made locally, and thus what changes should be preserved, made
361
+ * it impossible to build certain features easily, or in some cases at all. The proliferation of
362
+ * feature requests, bug reports (from folks surprised by the prior behavior) and addon attempts
363
+ * in this space are all evidence of this.
364
+ *
365
+ * We believe the new behavior is a "90%" solution. It works for the vast majority of use cases,
366
+ * often without noticeable changes to existing application behavior, and provides primitives that
367
+ * allow you to build the behavior you need for the remaining 10%.
368
+ *
369
+ * The great news is that this behavior defaults to trusting your API similar to the old behavior.
370
+ * If your API is correct, you will not need to make any changes to your application to adopt
371
+ * the new behavior.
372
+ *
373
+ * This means the 10% cases are those where you can't trust your API to provide the correct
374
+ * information. In these cases, because you now have cheap access to a diff of the relationship
375
+ * state, there are a few options that weren't available before:
376
+ *
377
+ * - you can adjust returned API payloads to contain the expected changes that it doesn't include
378
+ * - you can modify local state by adding or removing records on the HasMany record array to remove
379
+ * any local changes that were not returned by the API.
380
+ * - you can use `<Cache>.mutate(mutation)` to directly modify the local cache state of the relationship
381
+ * to match the expected state.
382
+ *
383
+ * What this version (5.3) does not yet provide is a way to directly modify the cache's remote state
384
+ * for the relationship via public APIs other than via the broader action of upserting a response via
385
+ * `<Cache>.put(document)`. However, such an API was sketched in the Cache 2.1 RFC
386
+ * `<Cache>.patch(operation)` and is likely to be added in a future 5.x release of EmberData.
387
+ *
388
+ * This version (5.3) also does not yet provide a way to directly modify the graph (a general purpose
389
+ * subset of cache behaviors specific to relationships) via public APIs. However, during the
390
+ * 5.x release series we will be working on finalizing the Graph API and making it public.
391
+ *
392
+ * If none of these options work for you, you can always opt-out more broadly by implementing
393
+ * a custom Cache with the relationship behaviors you need.
394
+ *
395
+ * @property DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE
396
+ * @since 5.3
397
+ * @until 6.0
398
+ * @public
399
+ */
400
+ const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE = '5.3';
401
+
402
+ /**
403
+ * **id: ember-data:deprecate-many-array-duplicates**
404
+ *
405
+ * When the flag is `true` (default), adding duplicate records to a `ManyArray`
406
+ * is deprecated in non-production environments. In production environments,
407
+ * duplicate records added to a `ManyArray` will be deduped and no error will
408
+ * be thrown.
409
+ *
410
+ * When the flag is `false`, an error will be thrown when duplicates are added.
411
+ *
412
+ * @property DEPRECATE_MANY_ARRAY_DUPLICATES
413
+ * @since 5.3
414
+ * @until 6.0
415
+ * @public
416
+ */
417
+ const DEPRECATE_MANY_ARRAY_DUPLICATES = '5.3';
418
+
419
+ /**
420
+ * **id: ember-data:deprecate-store-extends-ember-object**
421
+ *
422
+ * When the flag is `true` (default), the Store class will extend from `@ember/object`.
423
+ * When the flag is `false` or `ember-source` is not present, the Store will not extend
424
+ * from EmberObject.
425
+ *
426
+ * @property DEPRECATE_STORE_EXTENDS_EMBER_OBJECT
427
+ * @since 5.4
428
+ * @until 6.0
429
+ * @public
430
+ */
431
+ const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = '5.4';
432
+
433
+ /**
434
+ * **id: ember-data:schema-service-updates**
435
+ *
436
+ * When the flag is `true` (default), the legacy schema
437
+ * service features will be enabled on the store and
438
+ * the service, and deprecations will be thrown when
439
+ * they are used.
440
+ *
441
+ * Deprecated features include:
442
+ *
443
+ * - `Store.registerSchema` method is deprecated in favor of the `Store.createSchemaService` hook
444
+ * - `Store.registerSchemaDefinitionService` method is deprecated in favor of the `Store.createSchemaService` hook
445
+ * - `Store.getSchemaDefinitionService` method is deprecated in favor of `Store.schema` property
446
+ * - `SchemaService.doesTypeExist` method is deprecated in favor of the `SchemaService.hasResource` method
447
+ * - `SchemaService.attributesDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
448
+ * - `SchemaService.relationshipsDefinitionFor` method is deprecated in favor of the `SchemaService.fields` method
449
+ *
450
+ * @property ENABLE_LEGACY_SCHEMA_SERVICE
451
+ * @since 5.4
452
+ * @until 6.0
453
+ * @public
454
+ */
455
+ const ENABLE_LEGACY_SCHEMA_SERVICE = '5.4';
456
+
457
+ /**
458
+ * **id: warp-drive.ember-inflector**
459
+ *
460
+ * Deprecates the use of ember-inflector for pluralization and singularization in favor
461
+ * of the `@ember-data/request-utils` package.
462
+ *
463
+ * This deprecation can be resolved by removing usage of ember-inflector or by using
464
+ * both ember-inflector and @ember-data/request-utils in parallel and updating your
465
+ * EmberData/WarpDrive build config to mark the deprecation as resolved
466
+ * in ember-cli-build
467
+ *
468
+ * ```js
469
+ * setConfig(app, __dirname, { deprecations: { DEPRECATE_EMBER_INFLECTOR: false }});
470
+ * ```
471
+ *
472
+ * @property DEPRECATE_EMBER_INFLECTOR
473
+ * @since 5.3
474
+ * @until 6.0
475
+ * @public
476
+ */
477
+ const DEPRECATE_EMBER_INFLECTOR = '5.3';
478
+
479
+ const CURRENT_DEPRECATIONS = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
480
+ __proto__: null,
481
+ DEPRECATE_CATCH_ALL,
482
+ DEPRECATE_COMPUTED_CHAINS,
483
+ DEPRECATE_EMBER_INFLECTOR,
484
+ DEPRECATE_LEGACY_IMPORTS,
485
+ DEPRECATE_MANY_ARRAY_DUPLICATES,
486
+ DEPRECATE_NON_STRICT_ID,
487
+ DEPRECATE_NON_STRICT_TYPES,
488
+ DEPRECATE_NON_UNIQUE_PAYLOADS,
489
+ DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE,
490
+ DEPRECATE_STORE_EXTENDS_EMBER_OBJECT,
491
+ ENABLE_LEGACY_SCHEMA_SERVICE
492
+ }, Symbol.toStringTag, { value: 'Module' }));
493
+
494
+ function deprecationIsResolved(deprecatedSince, compatVersion) {
495
+ return semver.lte(semver.minVersion(deprecatedSince), semver.minVersion(compatVersion));
496
+ }
497
+ function getDeprecations(compatVersion) {
498
+ const flags = {};
499
+ const keys = Object.keys(CURRENT_DEPRECATIONS);
500
+ keys.forEach(flag => {
501
+ const deprecatedSince = CURRENT_DEPRECATIONS[flag];
502
+ let flagState = true; // default to no code-stripping
503
+
504
+ // if we are told we are compatible with a version
505
+ // we check if we can strip this flag
506
+ if (compatVersion) {
507
+ const isResolved = deprecationIsResolved(deprecatedSince, compatVersion);
508
+ // if we've resolved, we strip (by setting the flag to false)
509
+ /*
510
+ if (DEPRECATED_FEATURE) {
511
+ // deprecated code path
512
+ } else {
513
+ // if needed a non-deprecated code path
514
+ }
515
+ */
516
+ flagState = !isResolved;
517
+ }
518
+
519
+ // console.log(`${flag}=${flagState} (${deprecatedSince} <= ${compatVersion})`);
520
+ flags[flag] = flagState;
521
+ });
522
+ return flags;
523
+ }
524
+
525
+ /**
526
+ * ## Canary Features
527
+ *
528
+ * EmberData allows users to test features that are implemented but not yet
529
+ * available even in canary.
530
+ *
531
+ * Typically these features represent work that might introduce a new concept,
532
+ * new API, change an API, or risk an unintended change in behavior to consuming
533
+ * applications.
534
+ *
535
+ * Such features have their implementations guarded by a "feature flag", and the
536
+ * flag is only activated once the core-data team is prepared to ship the work
537
+ * in a canary release.
538
+ *
539
+ * ### Installing Canary
540
+ *
541
+ * To test a feature you MUST be using a canary build. Canary builds are published
542
+ * to `npm` and can be installed using a precise tag (such as `ember-data@3.16.0-alpha.1`)
543
+ * or by installing the latest dist-tag published to the `canary` channel using your javascript
544
+ * package manager of choice. For instance with [pnpm](https://pnpm.io/)
545
+
546
+ ```cli
547
+ pnpm add ember-data@canary
548
+ ```
549
+ *
550
+ * ### Activating a Canary Feature
551
+ *
552
+ * Once you have installed canary, feature-flags can be activated at build-time
553
+ *
554
+ * by setting an environment variable:
555
+ *
556
+ * ```cli
557
+ * # Activate a single flag
558
+ * EMBER_DATA_FEATURE_OVERRIDE=SOME_FLAG ember build
559
+ *
560
+ * # Activate multiple flags by separating with commas
561
+ * EMBER_DATA_FEATURE_OVERRIDE=SOME_FLAG,OTHER_FLAG ember build
562
+ *
563
+ * # Activate all flags
564
+ * EMBER_DATA_FEATURE_OVERRIDE=ENABLE_ALL_OPTIONAL ember build
565
+ * ```
566
+ *
567
+ * or by setting the appropriate flag in your `ember-cli-build` file:
568
+ *
569
+ * ```ts
570
+ * let app = new EmberApp(defaults, {
571
+ * emberData: {
572
+ * features: {
573
+ * SAMPLE_FEATURE_FLAG: false // utliize existing behavior, strip code for the new feature
574
+ * OTHER_FEATURE_FLAG: true // utilize this new feature, strip code for the older behavior
575
+ * }
576
+ * }
577
+ * })
578
+ * ```
579
+ *
580
+ * **The "off" branch of feature-flagged code is always stripped from production builds.**
581
+ *
582
+ * The list of available feature-flags is located [here](https://github.com/emberjs/data/tree/main/packages/build-config/src/virtual/canary-features.ts "List of EmberData FeatureFlags")
583
+ *
584
+ *
585
+ * ### Preparing a Project to use a Canary Feature
586
+ *
587
+ * For most projects, simple version detection should be enough.
588
+ * Using the provided version compatibility helpers from [embroider-macros](https://github.com/embroider-build/embroider/tree/main/packages/macros#readme)
589
+ * the following can be done:
590
+ *
591
+ * ```js
592
+ * if (macroCondition(dependencySatisfies('@ember-data/store', '5.0'))) {
593
+ * // do thing
594
+ * }
595
+ * ```
596
+ *
597
+ @module @warp-drive/build-config/canary-features
598
+ @main @warp-drive/build-config/canary-features
599
+ */
600
+ /**
601
+ This is the current list of features used at build time for canary releases.
602
+ If empty there are no features currently gated by feature flags.
603
+
604
+ The valid values are:
605
+
606
+ - `true` | The feature is **enabled** at all times, and cannot be disabled.
607
+ - `false` | The feature is **disabled** at all times, and cannot be enabled.
608
+ - `null` | The feature is **disabled by default**, but can be enabled via configuration.
609
+
610
+ @class CanaryFeatureFlags
611
+ @public
612
+ */
613
+ const SAMPLE_FEATURE_FLAG = null;
614
+
615
+ const CURRENT_FEATURES = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
616
+ __proto__: null,
617
+ SAMPLE_FEATURE_FLAG
618
+ }, Symbol.toStringTag, { value: 'Module' }));
619
+
620
+ const dirname = new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cjs-set-config.cjs', document.baseURI).href))).pathname;
621
+ const relativePkgPath = path.join(dirname, '../../package.json');
622
+ const version = JSON.parse(fs.readFileSync(relativePkgPath, 'utf-8')).version;
623
+ const isCanary = version.includes('alpha');
624
+ function getFeatures(isProd) {
625
+ const features = Object.assign({}, CURRENT_FEATURES);
626
+ const keys = Object.keys(features);
627
+ if (!isCanary) {
628
+ // disable all features with a current value of `null`
629
+ for (const feature of keys) {
630
+ let featureValue = features[feature];
631
+ if (featureValue === null) {
632
+ features[feature] = false;
633
+ }
634
+ }
635
+ return features;
636
+ }
637
+ const FEATURE_OVERRIDES = process.env.EMBER_DATA_FEATURE_OVERRIDE;
638
+ if (FEATURE_OVERRIDES === 'ENABLE_ALL_OPTIONAL') {
639
+ // enable all features with a current value of `null`
640
+ for (const feature of keys) {
641
+ let featureValue = features[feature];
642
+ if (featureValue === null) {
643
+ features[feature] = true;
644
+ }
645
+ }
646
+ } else if (FEATURE_OVERRIDES === 'DISABLE_ALL') {
647
+ // disable all features, including those with a value of `true`
648
+ for (const feature of keys) {
649
+ features[feature] = false;
650
+ }
651
+ } else if (FEATURE_OVERRIDES) {
652
+ // enable only the specific features listed in the environment
653
+ // variable (comma separated)
654
+ const forcedFeatures = FEATURE_OVERRIDES.split(',');
655
+ for (let i = 0; i < forcedFeatures.length; i++) {
656
+ let featureName = forcedFeatures[i];
657
+ if (!keys.includes(featureName)) {
658
+ throw new Error(`Unknown feature flag: ${featureName}`);
659
+ }
660
+ features[featureName] = true;
661
+ }
662
+ }
663
+ if (isProd) {
664
+ // disable all features with a current value of `null`
665
+ for (const feature of keys) {
666
+ let featureValue = features[feature];
667
+ if (featureValue === null) {
668
+ features[feature] = false;
669
+ }
670
+ }
671
+ }
672
+ return features;
673
+ }
674
+
675
+ /**
676
+ * ## Debugging
677
+ *
678
+ * Many portions of the internals are helpfully instrumented with logging that can be activated
679
+ * at build time. This instrumentation is always removed from production builds or any builds
680
+ * that has not explicitly activated it. To activate it set the appropriate flag to `true`.
681
+ *
682
+ @module @warp-drive/build-config/debugging
683
+ @main @warp-drive/build-config/debugging
684
+ */
685
+ /**
686
+ *
687
+ * Many portions of the internals are helpfully instrumented with logging that can be activated
688
+ at build time. This instrumentation is always removed from production builds or any builds
689
+ that has not explicitly activated it. To activate it set the appropriate flag to `true`.
690
+
691
+ ```ts
692
+ let app = new EmberApp(defaults, {
693
+ emberData: {
694
+ debug: {
695
+ LOG_PAYLOADS: false, // data store received to update cache with
696
+ LOG_OPERATIONS: false, // updates to cache remote state
697
+ LOG_MUTATIONS: false, // updates to cache local state
698
+ LOG_NOTIFICATIONS: false,
699
+ LOG_REQUESTS: false,
700
+ LOG_REQUEST_STATUS: false,
701
+ LOG_IDENTIFIERS: false,
702
+ LOG_GRAPH: false,
703
+ LOG_INSTANCE_CACHE: false,
704
+ }
705
+ }
706
+ });
707
+ ```
708
+
709
+ @class DebugLogging
710
+ @public
711
+ */
712
+ /**
713
+ * log payloads received by the store
714
+ * via `push` or returned from a delete/update/create
715
+ * operation.
716
+ *
717
+ * @property {boolean} LOG_PAYLOADS
718
+ * @public
719
+ */
720
+ const LOG_PAYLOADS = false;
721
+ /**
722
+ * log remote-state updates to the cache
723
+ *
724
+ * @property {boolean} LOG_OPERATIONS
725
+ * @public
726
+ */
727
+ const LOG_OPERATIONS = false;
728
+ /**
729
+ * log local-state updates to the cache
730
+ *
731
+ * @property {boolean} LOG_MUTATIONS
732
+ * @public
733
+ */
734
+ const LOG_MUTATIONS = false;
735
+ /**
736
+ * log notifications received by the NotificationManager
737
+ *
738
+ * @property {boolean} LOG_NOTIFICATIONS
739
+ * @public
740
+ */
741
+ const LOG_NOTIFICATIONS = false;
742
+ /**
743
+ * log requests issued by the RequestManager
744
+ *
745
+ * @property {boolean} LOG_REQUESTS
746
+ * @public
747
+ */
748
+ const LOG_REQUESTS = false;
749
+ /**
750
+ * log updates to requests the store has issued to
751
+ * the network (adapter) to fulfill.
752
+ *
753
+ * @property {boolean} LOG_REQUEST_STATUS
754
+ * @public
755
+ */
756
+ const LOG_REQUEST_STATUS = false;
757
+ /**
758
+ * log peek, generation and updates to
759
+ * Record Identifiers.
760
+ *
761
+ * @property {boolean} LOG_IDENTIFIERS
762
+ * @public
763
+ */
764
+ const LOG_IDENTIFIERS = false;
765
+ /**
766
+ * log updates received by the graph (relationship pointer storage)
767
+ *
768
+ * @property {boolean} LOG_GRAPH
769
+ * @public
770
+ */
771
+ const LOG_GRAPH = false;
772
+ /**
773
+ * log creation/removal of RecordData and Record
774
+ * instances.
775
+ *
776
+ * @property {boolean} LOG_INSTANCE_CACHE
777
+ * @public
778
+ */
779
+ const LOG_INSTANCE_CACHE = false;
780
+
781
+ const LOGGING = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
782
+ __proto__: null,
783
+ LOG_GRAPH,
784
+ LOG_IDENTIFIERS,
785
+ LOG_INSTANCE_CACHE,
786
+ LOG_MUTATIONS,
787
+ LOG_NOTIFICATIONS,
788
+ LOG_OPERATIONS,
789
+ LOG_PAYLOADS,
790
+ LOG_REQUESTS,
791
+ LOG_REQUEST_STATUS
792
+ }, Symbol.toStringTag, { value: 'Module' }));
793
+
794
+ const _MacrosConfig = EmbroiderMacros.MacrosConfig;
795
+ function recastMacrosConfig(macros) {
796
+ if (!('globalConfig' in macros)) {
797
+ throw new Error('Expected MacrosConfig to have a globalConfig property');
798
+ }
799
+ return macros;
800
+ }
801
+ function setConfig(context, appRoot, config) {
802
+ const macros = recastMacrosConfig(_MacrosConfig.for(context, appRoot));
803
+ const isLegacySupport = config.___legacy_support;
804
+ const hasDeprecatedConfig = isLegacySupport && Object.keys(config).length > 1;
805
+ const hasInitiatedConfig = macros.globalConfig['WarpDrive'];
806
+
807
+ // setConfig called by user prior to legacy support called
808
+ if (isLegacySupport && hasInitiatedConfig) {
809
+ if (hasDeprecatedConfig) {
810
+ throw new Error('You have provided a config object to setConfig, but are also using the legacy emberData options key in ember-cli-build. Please remove the emberData key from options.');
811
+ }
812
+ return;
813
+ }
814
+
815
+ // legacy support called prior to user setConfig
816
+ if (isLegacySupport && hasDeprecatedConfig) {
817
+ console.warn(`You are using the legacy emberData key in your ember-cli-build.js file. This key is deprecated and will be removed in the next major version of EmberData/WarpDrive. Please use \`import { setConfig } from '@warp-drive/build-config';\` instead.`);
818
+ }
819
+
820
+ // included hooks run during class initialization of the EmberApp instance
821
+ // so our hook will run before the user has a chance to call setConfig
822
+ // else we could print a useful message here
823
+ // else if (isLegacySupport) {
824
+ // console.warn(
825
+ // `WarpDrive requires your ember-cli-build file to set a base configuration for the project.\n\nUsage:\n\t\`import { setConfig } from '@warp-drive/build-config';\n\tsetConfig(app, __dirname, {});\``
826
+ // );
827
+ // }
828
+
829
+ const debugOptions = Object.assign({}, LOGGING, config.debug);
830
+ const env = getEnv();
831
+ const DEPRECATIONS = getDeprecations(config.compatWith || null);
832
+ const FEATURES = getFeatures(env.PRODUCTION);
833
+ const includeDataAdapterInProduction = typeof config.includeDataAdapterInProduction === 'boolean' ? config.includeDataAdapterInProduction : false;
834
+ const includeDataAdapter = env.PRODUCTION ? includeDataAdapterInProduction : false;
835
+ const finalizedConfig = {
836
+ debug: debugOptions,
837
+ polyfillUUID: config.polyfillUUID ?? false,
838
+ includeDataAdapter,
839
+ compatWith: config.compatWith ?? null,
840
+ deprecations: DEPRECATIONS,
841
+ features: FEATURES,
842
+ env
843
+ };
844
+ macros.setGlobalConfig(undefined, 'WarpDrive', finalizedConfig);
845
+ }
846
+
847
+ exports.setConfig = setConfig;
848
+ //# sourceMappingURL=cjs-set-config.cjs.map