@atlaspack/transformer-js 9.0.0 → 10.1.0
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/lib/JSTransformer.js +67 -7
- package/package.json +9 -8
- package/src/JSTransformer.ts +90 -15
package/lib/JSTransformer.js
CHANGED
|
@@ -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,13 +251,47 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
243
251
|
let inlineConstants = false;
|
|
244
252
|
let magicComments = false;
|
|
245
253
|
let addReactDisplayName = false;
|
|
246
|
-
let
|
|
247
|
-
let
|
|
254
|
+
let enableSsrTypeofReplacement = options.env.NATIVE_SSR_TYPEOF_REPLACEMENT === 'true';
|
|
255
|
+
let globalAliasingConfig = options.env.NATIVE_GLOBAL_ALIASING && JSON.parse(options.env.NATIVE_GLOBAL_ALIASING);
|
|
256
|
+
let enableLazyLoading = options.env.NATIVE_LAZY_LOADING === 'true';
|
|
257
|
+
let enableReactHooksRemoval = options.env.NATIVE_REACT_HOOKS_REMOVAL === 'true';
|
|
258
|
+
let enableReactAsyncImportLift = options.env.NATIVE_REACT_ASYNC_IMPORT_LIFT === 'true';
|
|
259
|
+
let reactAsyncLiftByDefault = options.env.REACT_ASYNC_IMPORT_LIFTING_BY_DEFAULT === 'true';
|
|
260
|
+
let reactAsyncLiftReportLevel = options.env.REACT_ASYNC_LIFT_REPORT_LEVEL || 'none';
|
|
261
|
+
let enableStaticPrevaluation = options.env.NATIVE_PREVALUATION === 'true';
|
|
262
|
+
let enableDeadReturnsRemoval = options.env.NATIVE_DEAD_RETURNS_REMOVAL === 'true';
|
|
263
|
+
let enableUnusedBindingsRemoval = options.env.NATIVE_UNUSED_BINDINGS_REMOVAL === 'true';
|
|
264
|
+
let syncDynamicImportConfig;
|
|
265
|
+
if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
|
|
266
|
+
try {
|
|
267
|
+
let config = configCache.get('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
268
|
+
if (!config) {
|
|
269
|
+
var _config;
|
|
270
|
+
config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
|
|
271
|
+
(0, _assert().default)(typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.entrypoint_filepath_suffix) === 'string');
|
|
272
|
+
(0, _assert().default)(Array.isArray(config.actual_require_paths));
|
|
273
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
|
|
274
|
+
}
|
|
275
|
+
syncDynamicImportConfig = config;
|
|
276
|
+
} catch {
|
|
277
|
+
// eslint-disable-next-line no-console
|
|
278
|
+
console.warn('Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.');
|
|
279
|
+
const fallback = {
|
|
280
|
+
entrypoint_filepath_suffix: '__NO_MATCH__',
|
|
281
|
+
actual_require_paths: []
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Set cache to fallback so we don't keep trying to parse.
|
|
285
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
|
|
286
|
+
syncDynamicImportConfig = fallback;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
248
290
|
if (conf && conf.contents) {
|
|
249
291
|
var _conf$contents, _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5;
|
|
250
292
|
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
251
293
|
data: conf.contents,
|
|
252
|
-
source: (
|
|
294
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
253
295
|
filePath: conf.filePath,
|
|
254
296
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
|
|
255
297
|
},
|
|
@@ -282,8 +324,17 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
282
324
|
decorators,
|
|
283
325
|
useDefineForClassFields,
|
|
284
326
|
magicComments,
|
|
285
|
-
|
|
286
|
-
|
|
327
|
+
globalAliasingConfig,
|
|
328
|
+
enableSsrTypeofReplacement,
|
|
329
|
+
enableLazyLoading,
|
|
330
|
+
enableDeadReturnsRemoval,
|
|
331
|
+
enableUnusedBindingsRemoval,
|
|
332
|
+
enableStaticPrevaluation,
|
|
333
|
+
enableReactHooksRemoval,
|
|
334
|
+
syncDynamicImportConfig,
|
|
335
|
+
enableReactAsyncImportLift,
|
|
336
|
+
reactAsyncLiftByDefault,
|
|
337
|
+
reactAsyncLiftReportLevel
|
|
287
338
|
};
|
|
288
339
|
},
|
|
289
340
|
async transform({
|
|
@@ -435,9 +486,18 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
435
486
|
exports_rebinding_optimisation: options.featureFlags.exportsRebindingOptimisation,
|
|
436
487
|
magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
|
|
437
488
|
is_source: asset.isSource,
|
|
438
|
-
enable_global_this_aliaser: Boolean(config.enableGlobalThisAliaser),
|
|
439
|
-
enable_lazy_loading_transformer: Boolean(config.enableLazyLoadingTransformer),
|
|
440
489
|
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
490
|
+
global_aliasing_config: config.globalAliasingConfig,
|
|
491
|
+
enable_ssr_typeof_replacement: Boolean(config.enableSsrTypeofReplacement),
|
|
492
|
+
enable_lazy_loading: Boolean(config.enableLazyLoading),
|
|
493
|
+
enable_dead_returns_removal: Boolean(config.enableDeadReturnsRemoval),
|
|
494
|
+
enable_unused_bindings_removal: Boolean(config.enableUnusedBindingsRemoval),
|
|
495
|
+
enable_static_prevaluation: Boolean(config.enableStaticPrevaluation),
|
|
496
|
+
enable_react_hooks_removal: Boolean(config.enableReactHooksRemoval),
|
|
497
|
+
enable_react_async_import_lift: Boolean(config.enableReactAsyncImportLift),
|
|
498
|
+
react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
|
|
499
|
+
react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
|
|
500
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
441
501
|
callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
|
|
442
502
|
let mod;
|
|
443
503
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
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/build-cache": "2.13.6",
|
|
27
28
|
"@atlaspack/diagnostic": "2.14.4",
|
|
28
|
-
"@atlaspack/feature-flags": "2.27.
|
|
29
|
-
"@atlaspack/plugin": "2.14.
|
|
30
|
-
"@atlaspack/rust": "3.
|
|
31
|
-
"@atlaspack/source-map": "3.1.
|
|
32
|
-
"@atlaspack/utils": "3.2.
|
|
33
|
-
"@atlaspack/workers": "2.14.
|
|
29
|
+
"@atlaspack/feature-flags": "2.27.2",
|
|
30
|
+
"@atlaspack/plugin": "2.14.41",
|
|
31
|
+
"@atlaspack/rust": "3.13.0",
|
|
32
|
+
"@atlaspack/source-map": "3.1.2",
|
|
33
|
+
"@atlaspack/utils": "3.2.2",
|
|
34
|
+
"@atlaspack/workers": "2.14.41",
|
|
34
35
|
"@swc/helpers": "^0.5.15",
|
|
35
36
|
"browserslist": "^4.6.6",
|
|
36
37
|
"nullthrows": "^1.1.1",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"semver": "^7.5.2"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@atlaspack/core": "2.
|
|
42
|
+
"@atlaspack/core": "2.29.1"
|
|
42
43
|
},
|
|
43
44
|
"type": "commonjs"
|
|
44
45
|
}
|
package/src/JSTransformer.ts
CHANGED
|
@@ -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,21 +305,73 @@ export default new Transformer({
|
|
|
302
305
|
let magicComments = false;
|
|
303
306
|
let addReactDisplayName = false;
|
|
304
307
|
|
|
305
|
-
let
|
|
306
|
-
options.env.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
options.env.
|
|
310
|
-
|
|
308
|
+
let enableSsrTypeofReplacement =
|
|
309
|
+
options.env.NATIVE_SSR_TYPEOF_REPLACEMENT === 'true';
|
|
310
|
+
let globalAliasingConfig =
|
|
311
|
+
options.env.NATIVE_GLOBAL_ALIASING &&
|
|
312
|
+
JSON.parse(options.env.NATIVE_GLOBAL_ALIASING);
|
|
313
|
+
let enableLazyLoading = options.env.NATIVE_LAZY_LOADING === 'true';
|
|
314
|
+
let enableReactHooksRemoval =
|
|
315
|
+
options.env.NATIVE_REACT_HOOKS_REMOVAL === 'true';
|
|
316
|
+
let enableReactAsyncImportLift =
|
|
317
|
+
options.env.NATIVE_REACT_ASYNC_IMPORT_LIFT === 'true';
|
|
318
|
+
let reactAsyncLiftByDefault =
|
|
319
|
+
options.env.REACT_ASYNC_IMPORT_LIFTING_BY_DEFAULT === 'true';
|
|
320
|
+
let reactAsyncLiftReportLevel =
|
|
321
|
+
options.env.REACT_ASYNC_LIFT_REPORT_LEVEL || 'none';
|
|
322
|
+
let enableStaticPrevaluation = options.env.NATIVE_PREVALUATION === 'true';
|
|
323
|
+
let enableDeadReturnsRemoval =
|
|
324
|
+
options.env.NATIVE_DEAD_RETURNS_REMOVAL === 'true';
|
|
325
|
+
let enableUnusedBindingsRemoval =
|
|
326
|
+
options.env.NATIVE_UNUSED_BINDINGS_REMOVAL === 'true';
|
|
327
|
+
let syncDynamicImportConfig:
|
|
328
|
+
| {
|
|
329
|
+
entrypoint_filepath_suffix: string;
|
|
330
|
+
actual_require_paths: string[];
|
|
331
|
+
}
|
|
332
|
+
| undefined;
|
|
333
|
+
|
|
334
|
+
if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
|
|
335
|
+
try {
|
|
336
|
+
let config = configCache.get(
|
|
337
|
+
'SYNC_DYNAMIC_IMPORT_CONFIG',
|
|
338
|
+
) as typeof syncDynamicImportConfig;
|
|
339
|
+
|
|
340
|
+
if (!config) {
|
|
341
|
+
config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
|
|
342
|
+
|
|
343
|
+
invariant(typeof config?.entrypoint_filepath_suffix === 'string');
|
|
344
|
+
invariant(Array.isArray(config.actual_require_paths));
|
|
345
|
+
|
|
346
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
syncDynamicImportConfig = config;
|
|
350
|
+
} catch {
|
|
351
|
+
// eslint-disable-next-line no-console
|
|
352
|
+
console.warn(
|
|
353
|
+
'Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.',
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const fallback = {
|
|
357
|
+
entrypoint_filepath_suffix: '__NO_MATCH__',
|
|
358
|
+
actual_require_paths: [],
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// Set cache to fallback so we don't keep trying to parse.
|
|
362
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
|
|
363
|
+
syncDynamicImportConfig = fallback;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
311
368
|
|
|
312
369
|
if (conf && conf.contents) {
|
|
313
370
|
validateSchema.diagnostic(
|
|
314
371
|
CONFIG_SCHEMA,
|
|
315
372
|
{
|
|
316
373
|
data: conf.contents,
|
|
317
|
-
source:
|
|
318
|
-
? () => options.inputFS.readFileSync(conf.filePath, 'utf8')
|
|
319
|
-
: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
374
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
320
375
|
filePath: conf.filePath,
|
|
321
376
|
prependKey: `/${encodeJSONKeyComponent('@atlaspack/transformer-js')}`,
|
|
322
377
|
},
|
|
@@ -353,8 +408,17 @@ export default new Transformer({
|
|
|
353
408
|
decorators,
|
|
354
409
|
useDefineForClassFields,
|
|
355
410
|
magicComments,
|
|
356
|
-
|
|
357
|
-
|
|
411
|
+
globalAliasingConfig,
|
|
412
|
+
enableSsrTypeofReplacement,
|
|
413
|
+
enableLazyLoading,
|
|
414
|
+
enableDeadReturnsRemoval,
|
|
415
|
+
enableUnusedBindingsRemoval,
|
|
416
|
+
enableStaticPrevaluation,
|
|
417
|
+
enableReactHooksRemoval,
|
|
418
|
+
syncDynamicImportConfig,
|
|
419
|
+
enableReactAsyncImportLift,
|
|
420
|
+
reactAsyncLiftByDefault,
|
|
421
|
+
reactAsyncLiftReportLevel,
|
|
358
422
|
};
|
|
359
423
|
},
|
|
360
424
|
async transform({asset, config, options, logger}) {
|
|
@@ -534,11 +598,22 @@ export default new Transformer({
|
|
|
534
598
|
Boolean(config?.magicComments) ||
|
|
535
599
|
getFeatureFlag('supportWebpackChunkName'),
|
|
536
600
|
is_source: asset.isSource,
|
|
537
|
-
enable_global_this_aliaser: Boolean(config.enableGlobalThisAliaser),
|
|
538
|
-
enable_lazy_loading_transformer: Boolean(
|
|
539
|
-
config.enableLazyLoadingTransformer,
|
|
540
|
-
),
|
|
541
601
|
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
602
|
+
global_aliasing_config: config.globalAliasingConfig,
|
|
603
|
+
enable_ssr_typeof_replacement: Boolean(config.enableSsrTypeofReplacement),
|
|
604
|
+
enable_lazy_loading: Boolean(config.enableLazyLoading),
|
|
605
|
+
enable_dead_returns_removal: Boolean(config.enableDeadReturnsRemoval),
|
|
606
|
+
enable_unused_bindings_removal: Boolean(
|
|
607
|
+
config.enableUnusedBindingsRemoval,
|
|
608
|
+
),
|
|
609
|
+
enable_static_prevaluation: Boolean(config.enableStaticPrevaluation),
|
|
610
|
+
enable_react_hooks_removal: Boolean(config.enableReactHooksRemoval),
|
|
611
|
+
enable_react_async_import_lift: Boolean(
|
|
612
|
+
config.enableReactAsyncImportLift,
|
|
613
|
+
),
|
|
614
|
+
react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
|
|
615
|
+
react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
|
|
616
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
542
617
|
callMacro: asset.isSource
|
|
543
618
|
? async (err: any, src: any, exportName: any, args: any, loc: any) => {
|
|
544
619
|
let mod;
|