@atlaspack/transformer-js 3.2.3-canary.301 → 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.
- package/lib/JSTransformer.js +37 -1
- package/package.json +10 -9
- package/src/JSTransformer.ts +47 -0
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,6 +251,32 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
243
251
|
let inlineConstants = false;
|
|
244
252
|
let magicComments = false;
|
|
245
253
|
let addReactDisplayName = false;
|
|
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');
|
|
246
280
|
let enableGlobalThisAliaser = options.env.NATIVE_GLOBAL_THIS_ALIASER === 'true';
|
|
247
281
|
let enableLazyLoadingTransformer = options.env.NATIVE_LAZY_LOADING_TRANSFORMER === 'true';
|
|
248
282
|
let enableDeadReturnsRemover = options.env.NATIVE_DEAD_RETURNS_REMOVER === 'true';
|
|
@@ -287,7 +321,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
287
321
|
enableGlobalThisAliaser,
|
|
288
322
|
enableLazyLoadingTransformer,
|
|
289
323
|
enableDeadReturnsRemover,
|
|
290
|
-
enableUnusedBindingsRemover
|
|
324
|
+
enableUnusedBindingsRemover,
|
|
325
|
+
syncDynamicImportConfig
|
|
291
326
|
};
|
|
292
327
|
},
|
|
293
328
|
async transform({
|
|
@@ -441,6 +476,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
441
476
|
is_source: asset.isSource,
|
|
442
477
|
enable_global_this_aliaser: Boolean(config.enableGlobalThisAliaser),
|
|
443
478
|
enable_lazy_loading_transformer: Boolean(config.enableLazyLoadingTransformer),
|
|
479
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
444
480
|
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
445
481
|
enable_dead_returns_remover: Boolean(config.enableDeadReturnsRemover),
|
|
446
482
|
enable_unused_bindings_remover: Boolean(config.enableUnusedBindingsRemover),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-js",
|
|
3
|
-
"version": "3.2.3-canary.
|
|
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/
|
|
28
|
-
"@atlaspack/
|
|
29
|
-
"@atlaspack/
|
|
30
|
-
"@atlaspack/
|
|
31
|
-
"@atlaspack/
|
|
32
|
-
"@atlaspack/
|
|
33
|
-
"@atlaspack/
|
|
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": "
|
|
45
|
+
"gitHead": "5817226eef6f194220b994ce71332fc8ff199f84"
|
|
45
46
|
}
|
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,6 +305,48 @@ export default new Transformer({
|
|
|
302
305
|
let magicComments = false;
|
|
303
306
|
let addReactDisplayName = false;
|
|
304
307
|
|
|
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
|
+
|
|
305
350
|
let enableGlobalThisAliaser =
|
|
306
351
|
options.env.NATIVE_GLOBAL_THIS_ALIASER === 'true';
|
|
307
352
|
let enableLazyLoadingTransformer =
|
|
@@ -357,6 +402,7 @@ export default new Transformer({
|
|
|
357
402
|
enableLazyLoadingTransformer,
|
|
358
403
|
enableDeadReturnsRemover,
|
|
359
404
|
enableUnusedBindingsRemover,
|
|
405
|
+
syncDynamicImportConfig,
|
|
360
406
|
};
|
|
361
407
|
},
|
|
362
408
|
async transform({asset, config, options, logger}) {
|
|
@@ -540,6 +586,7 @@ export default new Transformer({
|
|
|
540
586
|
enable_lazy_loading_transformer: Boolean(
|
|
541
587
|
config.enableLazyLoadingTransformer,
|
|
542
588
|
),
|
|
589
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
543
590
|
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
544
591
|
enable_dead_returns_remover: Boolean(config.enableDeadReturnsRemover),
|
|
545
592
|
enable_unused_bindings_remover: Boolean(
|