@atlaspack/transformer-js 3.2.3-canary.300 → 3.2.3-canary.302

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.
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ function _buildCache() {
8
+ const data = require("@atlaspack/build-cache");
9
+ _buildCache = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _sourceMap() {
8
15
  const data = _interopRequireDefault(require("@atlaspack/source-map"));
9
16
  _sourceMap = function () {
@@ -149,6 +156,7 @@ const CONFIG_SCHEMA = {
149
156
  },
150
157
  additionalProperties: false
151
158
  };
159
+ const configCache = (0, _buildCache().createBuildCache)();
152
160
  const SCRIPT_ERRORS = {
153
161
  browser: {
154
162
  message: 'Browser scripts cannot have imports or exports.',
@@ -243,8 +251,36 @@ var _default = exports.default = new (_plugin().Transformer)({
243
251
  let inlineConstants = false;
244
252
  let magicComments = false;
245
253
  let addReactDisplayName = false;
246
- let enableGlobalThisAliaser = Boolean(options.env.NATIVE_GLOBAL_THIS_ALIASER);
247
- let enableLazyLoadingTransformer = Boolean(options.env.NATIVE_LAZY_LOADING_TRANSFORMER);
254
+ let syncDynamicImportConfig;
255
+ if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
256
+ try {
257
+ let config = configCache.get('SYNC_DYNAMIC_IMPORT_CONFIG');
258
+ if (!config) {
259
+ var _config;
260
+ config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
261
+ (0, _assert().default)(typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.entrypoint_filepath_suffix) === 'string');
262
+ (0, _assert().default)(Array.isArray(config.actual_require_paths));
263
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
264
+ }
265
+ syncDynamicImportConfig = config;
266
+ } catch {
267
+ // eslint-disable-next-line no-console
268
+ console.warn('Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.');
269
+ const fallback = {
270
+ entrypoint_filepath_suffix: '__NO_MATCH__',
271
+ actual_require_paths: []
272
+ };
273
+
274
+ // Set cache to fallback so we don't keep trying to parse.
275
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
276
+ syncDynamicImportConfig = fallback;
277
+ }
278
+ }
279
+ config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
280
+ let enableGlobalThisAliaser = options.env.NATIVE_GLOBAL_THIS_ALIASER === 'true';
281
+ let enableLazyLoadingTransformer = options.env.NATIVE_LAZY_LOADING_TRANSFORMER === 'true';
282
+ let enableDeadReturnsRemover = options.env.NATIVE_DEAD_RETURNS_REMOVER === 'true';
283
+ let enableUnusedBindingsRemover = options.env.NATIVE_UNUSED_BINDINGS_REMOVER === 'true';
248
284
  if (conf && conf.contents) {
249
285
  var _conf$contents, _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5;
250
286
  _utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
@@ -283,7 +319,10 @@ var _default = exports.default = new (_plugin().Transformer)({
283
319
  useDefineForClassFields,
284
320
  magicComments,
285
321
  enableGlobalThisAliaser,
286
- enableLazyLoadingTransformer
322
+ enableLazyLoadingTransformer,
323
+ enableDeadReturnsRemover,
324
+ enableUnusedBindingsRemover,
325
+ syncDynamicImportConfig
287
326
  };
288
327
  },
289
328
  async transform({
@@ -437,7 +476,10 @@ var _default = exports.default = new (_plugin().Transformer)({
437
476
  is_source: asset.isSource,
438
477
  enable_global_this_aliaser: Boolean(config.enableGlobalThisAliaser),
439
478
  enable_lazy_loading_transformer: Boolean(config.enableLazyLoadingTransformer),
479
+ sync_dynamic_import_config: config.syncDynamicImportConfig,
440
480
  nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
481
+ enable_dead_returns_remover: Boolean(config.enableDeadReturnsRemover),
482
+ enable_unused_bindings_remover: Boolean(config.enableUnusedBindingsRemover),
441
483
  callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
442
484
  let mod;
443
485
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-js",
3
- "version": "3.2.3-canary.300+2f3af9374",
3
+ "version": "3.2.3-canary.302+5817226ee",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,13 +24,14 @@
24
24
  "src"
25
25
  ],
26
26
  "dependencies": {
27
- "@atlaspack/diagnostic": "2.14.1-canary.368+2f3af9374",
28
- "@atlaspack/feature-flags": "2.14.1-canary.368+2f3af9374",
29
- "@atlaspack/plugin": "2.14.5-canary.300+2f3af9374",
30
- "@atlaspack/rust": "3.2.1-canary.300+2f3af9374",
31
- "@atlaspack/source-map": "3.1.1-canary.4079+2f3af9374",
32
- "@atlaspack/utils": "2.14.5-canary.300+2f3af9374",
33
- "@atlaspack/workers": "2.14.5-canary.300+2f3af9374",
27
+ "@atlaspack/build-cache": "2.13.3-canary.370+5817226ee",
28
+ "@atlaspack/diagnostic": "2.14.1-canary.370+5817226ee",
29
+ "@atlaspack/feature-flags": "2.14.1-canary.370+5817226ee",
30
+ "@atlaspack/plugin": "2.14.5-canary.302+5817226ee",
31
+ "@atlaspack/rust": "3.2.1-canary.302+5817226ee",
32
+ "@atlaspack/source-map": "3.1.1-canary.4081+5817226ee",
33
+ "@atlaspack/utils": "2.14.5-canary.302+5817226ee",
34
+ "@atlaspack/workers": "2.14.5-canary.302+5817226ee",
34
35
  "@swc/helpers": "^0.5.15",
35
36
  "browserslist": "^4.6.6",
36
37
  "nullthrows": "^1.1.1",
@@ -41,5 +42,5 @@
41
42
  "@atlaspack/core": "2.28.0"
42
43
  },
43
44
  "type": "commonjs",
44
- "gitHead": "2f3af9374bcc082e6f4835f6f5a2b98e32ea45b4"
45
+ "gitHead": "5817226eef6f194220b994ce71332fc8ff199f84"
45
46
  }
@@ -5,6 +5,7 @@ import type {
5
5
  FilePath,
6
6
  FileCreateInvalidation,
7
7
  } from '@atlaspack/types';
8
+ import {createBuildCache} from '@atlaspack/build-cache';
8
9
  import type {SchemaEntity} from '@atlaspack/utils';
9
10
  import type {Diagnostic} from '@atlaspack/diagnostic';
10
11
  import SourceMap from '@atlaspack/source-map';
@@ -120,6 +121,8 @@ const CONFIG_SCHEMA: SchemaEntity = {
120
121
  additionalProperties: false,
121
122
  };
122
123
 
124
+ const configCache = createBuildCache();
125
+
123
126
  const SCRIPT_ERRORS = {
124
127
  browser: {
125
128
  message: 'Browser scripts cannot have imports or exports.',
@@ -302,12 +305,56 @@ export default new Transformer({
302
305
  let magicComments = false;
303
306
  let addReactDisplayName = false;
304
307
 
305
- let enableGlobalThisAliaser = Boolean(
306
- options.env.NATIVE_GLOBAL_THIS_ALIASER,
307
- );
308
- let enableLazyLoadingTransformer = Boolean(
309
- options.env.NATIVE_LAZY_LOADING_TRANSFORMER,
310
- );
308
+ let syncDynamicImportConfig:
309
+ | {
310
+ entrypoint_filepath_suffix: string;
311
+ actual_require_paths: string[];
312
+ }
313
+ | undefined;
314
+
315
+ if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
316
+ try {
317
+ let config = configCache.get(
318
+ 'SYNC_DYNAMIC_IMPORT_CONFIG',
319
+ ) as typeof syncDynamicImportConfig;
320
+
321
+ if (!config) {
322
+ config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
323
+
324
+ invariant(typeof config?.entrypoint_filepath_suffix === 'string');
325
+ invariant(Array.isArray(config.actual_require_paths));
326
+
327
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
328
+ }
329
+
330
+ syncDynamicImportConfig = config;
331
+ } catch {
332
+ // eslint-disable-next-line no-console
333
+ console.warn(
334
+ 'Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.',
335
+ );
336
+
337
+ const fallback = {
338
+ entrypoint_filepath_suffix: '__NO_MATCH__',
339
+ actual_require_paths: [],
340
+ };
341
+
342
+ // Set cache to fallback so we don't keep trying to parse.
343
+ configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
344
+ syncDynamicImportConfig = fallback;
345
+ }
346
+ }
347
+
348
+ config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
349
+
350
+ let enableGlobalThisAliaser =
351
+ options.env.NATIVE_GLOBAL_THIS_ALIASER === 'true';
352
+ let enableLazyLoadingTransformer =
353
+ options.env.NATIVE_LAZY_LOADING_TRANSFORMER === 'true';
354
+ let enableDeadReturnsRemover =
355
+ options.env.NATIVE_DEAD_RETURNS_REMOVER === 'true';
356
+ let enableUnusedBindingsRemover =
357
+ options.env.NATIVE_UNUSED_BINDINGS_REMOVER === 'true';
311
358
 
312
359
  if (conf && conf.contents) {
313
360
  validateSchema.diagnostic(
@@ -353,6 +400,9 @@ export default new Transformer({
353
400
  magicComments,
354
401
  enableGlobalThisAliaser,
355
402
  enableLazyLoadingTransformer,
403
+ enableDeadReturnsRemover,
404
+ enableUnusedBindingsRemover,
405
+ syncDynamicImportConfig,
356
406
  };
357
407
  },
358
408
  async transform({asset, config, options, logger}) {
@@ -536,7 +586,12 @@ export default new Transformer({
536
586
  enable_lazy_loading_transformer: Boolean(
537
587
  config.enableLazyLoadingTransformer,
538
588
  ),
589
+ sync_dynamic_import_config: config.syncDynamicImportConfig,
539
590
  nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
591
+ enable_dead_returns_remover: Boolean(config.enableDeadReturnsRemover),
592
+ enable_unused_bindings_remover: Boolean(
593
+ config.enableUnusedBindingsRemover,
594
+ ),
540
595
  callMacro: asset.isSource
541
596
  ? async (err: any, src: any, exportName: any, args: any, loc: any) => {
542
597
  let mod;