@atlaspack/transformer-js 3.2.3-dev.72 → 3.2.3-dev.93
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 +30 -33
- package/package.json +8 -11
- package/src/JSTransformer.js +22 -36
package/lib/JSTransformer.js
CHANGED
|
@@ -25,9 +25,9 @@ function _rust() {
|
|
|
25
25
|
};
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const data = require("
|
|
30
|
-
|
|
28
|
+
function _assert() {
|
|
29
|
+
const data = _interopRequireDefault(require("assert"));
|
|
30
|
+
_assert = function () {
|
|
31
31
|
return data;
|
|
32
32
|
};
|
|
33
33
|
return data;
|
|
@@ -78,7 +78,6 @@ function _featureFlags() {
|
|
|
78
78
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
79
79
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
80
80
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
81
|
-
const esm_helpers_specifier = (0, _core().isSuperPackage)() ? './esmodule-helpers.js' : '@atlaspack/transformer-js/src/esmodule-helpers.js';
|
|
82
81
|
const JSX_EXTENSIONS = {
|
|
83
82
|
jsx: true,
|
|
84
83
|
tsx: true
|
|
@@ -185,7 +184,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
185
184
|
}
|
|
186
185
|
reactRefresh = options.hmrOptions && options.mode === 'development' && Boolean((packageJson === null || packageJson === void 0 || (_packageJson$dependen2 = packageJson.dependencies) === null || _packageJson$dependen2 === void 0 ? void 0 : _packageJson$dependen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen2 = packageJson.devDependencies) === null || _packageJson$devDepen2 === void 0 ? void 0 : _packageJson$devDepen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe2 = packageJson.peerDependencies) === null || _packageJson$peerDepe2 === void 0 ? void 0 : _packageJson$peerDepe2.react));
|
|
187
186
|
const compilerOptions = (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
188
|
-
readTracking:
|
|
187
|
+
readTracking: true
|
|
189
188
|
})) === null || _await$config$getConf === void 0 || (_await$config$getConf = _await$config$getConf.contents) === null || _await$config$getConf === void 0 ? void 0 : _await$config$getConf.compilerOptions;
|
|
190
189
|
|
|
191
190
|
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
@@ -314,6 +313,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
314
313
|
if (options.env.NODE_ENV != null) {
|
|
315
314
|
env.NODE_ENV = options.env.NODE_ENV;
|
|
316
315
|
}
|
|
316
|
+
if (process.env.ATLASPACK_BUILD_ENV === 'test') {
|
|
317
|
+
env.ATLASPACK_BUILD_ENV = 'test';
|
|
318
|
+
}
|
|
317
319
|
} else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
|
|
318
320
|
for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
|
|
319
321
|
env[match] = String(options.env[match]);
|
|
@@ -354,7 +356,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
354
356
|
module_id: asset.id,
|
|
355
357
|
project_root: options.projectRoot,
|
|
356
358
|
replace_env: !asset.env.isNode(),
|
|
357
|
-
inline_fs:
|
|
359
|
+
inline_fs: Boolean(config === null || config === void 0 ? void 0 : config.inlineFS) && !asset.env.isNode(),
|
|
358
360
|
insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
|
|
359
361
|
node_replacer: asset.env.isNode(),
|
|
360
362
|
is_browser: asset.env.isBrowser(),
|
|
@@ -382,8 +384,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
382
384
|
standalone: asset.query.has('standalone'),
|
|
383
385
|
inline_constants: config.inlineConstants,
|
|
384
386
|
conditional_bundling: options.featureFlags.conditionalBundlingApi,
|
|
387
|
+
hmr_improvements: options.featureFlags.hmrImprovements,
|
|
385
388
|
magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments),
|
|
386
|
-
esm_helpers_specifier,
|
|
387
389
|
callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
|
|
388
390
|
let mod;
|
|
389
391
|
try {
|
|
@@ -408,7 +410,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
408
410
|
}
|
|
409
411
|
try {
|
|
410
412
|
if (typeof mod[exportName] === 'function') {
|
|
411
|
-
|
|
413
|
+
let ctx = {
|
|
412
414
|
// Allows macros to emit additional assets to add as dependencies (e.g. css).
|
|
413
415
|
addAsset(a) {
|
|
414
416
|
let k = String(macroAssets.length);
|
|
@@ -467,7 +469,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
467
469
|
invalidateOnBuild() {
|
|
468
470
|
asset.invalidateOnBuild();
|
|
469
471
|
}
|
|
470
|
-
}
|
|
472
|
+
};
|
|
473
|
+
return mod[exportName].apply(ctx, args);
|
|
471
474
|
} else {
|
|
472
475
|
throw new Error(`"${exportName}" in "${src}" is not a function.`);
|
|
473
476
|
}
|
|
@@ -476,7 +479,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
476
479
|
let stack = (err.stack || '').split('\n').slice(1);
|
|
477
480
|
let message = err.message;
|
|
478
481
|
for (let line of stack) {
|
|
479
|
-
if (line.includes(
|
|
482
|
+
if (line.includes(__filename)) {
|
|
480
483
|
break;
|
|
481
484
|
}
|
|
482
485
|
message += '\n' + line;
|
|
@@ -639,6 +642,13 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
639
642
|
});
|
|
640
643
|
} else if (dep.kind === 'File') {
|
|
641
644
|
asset.invalidateOnFileChange(dep.specifier);
|
|
645
|
+
} else if (dep.kind === 'Id') {
|
|
646
|
+
// Record parcelRequire calls so that the dev packager can add them as dependencies.
|
|
647
|
+
// This allows the HMR runtime to collect parents across async boundaries (through runtimes).
|
|
648
|
+
// TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
|
|
649
|
+
asset.meta.hmrDeps ??= [];
|
|
650
|
+
(0, _assert().default)(Array.isArray(asset.meta.hmrDeps));
|
|
651
|
+
asset.meta.hmrDeps.push(dep.specifier);
|
|
642
652
|
} else {
|
|
643
653
|
let meta = {
|
|
644
654
|
kind: dep.kind
|
|
@@ -714,7 +724,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
714
724
|
priority: dep.kind === 'DynamicImport' ? 'lazy' : dep.kind === 'ConditionalImport' ? 'conditional' : 'sync',
|
|
715
725
|
isOptional: dep.is_optional,
|
|
716
726
|
meta,
|
|
717
|
-
resolveFrom: isHelper ?
|
|
727
|
+
resolveFrom: isHelper ? __filename : undefined,
|
|
718
728
|
range,
|
|
719
729
|
env
|
|
720
730
|
});
|
|
@@ -876,29 +886,16 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
876
886
|
}
|
|
877
887
|
}
|
|
878
888
|
if (needs_esm_helpers) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
atlaspack: true
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
} else {
|
|
891
|
-
asset.addDependency({
|
|
892
|
-
specifier: esm_helpers_specifier,
|
|
893
|
-
specifierType: 'esm',
|
|
894
|
-
resolveFrom: /*#__ATLASPACK_IGNORE__*/__filename,
|
|
895
|
-
env: {
|
|
896
|
-
includeNodeModules: {
|
|
897
|
-
'@atlaspack/transformer-js': true
|
|
898
|
-
}
|
|
889
|
+
asset.addDependency({
|
|
890
|
+
specifier: '@atlaspack/transformer-js/src/esmodule-helpers.js',
|
|
891
|
+
specifierType: 'esm',
|
|
892
|
+
resolveFrom: __filename,
|
|
893
|
+
env: {
|
|
894
|
+
includeNodeModules: {
|
|
895
|
+
'@atlaspack/transformer-js': true
|
|
899
896
|
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
897
|
+
}
|
|
898
|
+
});
|
|
902
899
|
}
|
|
903
900
|
}
|
|
904
901
|
asset.type = 'js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-js",
|
|
3
|
-
"version": "3.2.3-dev.
|
|
3
|
+
"version": "3.2.3-dev.93+207d003c0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,16 +21,13 @@
|
|
|
21
21
|
"lib",
|
|
22
22
|
"src"
|
|
23
23
|
],
|
|
24
|
-
"atlaspackReferences": [
|
|
25
|
-
"src/esmodule-helpers.js"
|
|
26
|
-
],
|
|
27
24
|
"dependencies": {
|
|
28
|
-
"@atlaspack/diagnostic": "2.14.1-dev.
|
|
29
|
-
"@atlaspack/feature-flags": "2.14.1-dev.
|
|
30
|
-
"@atlaspack/plugin": "2.14.5-dev.
|
|
31
|
-
"@atlaspack/rust": "3.2.1-dev.
|
|
32
|
-
"@atlaspack/utils": "2.14.5-dev.
|
|
33
|
-
"@atlaspack/workers": "2.14.5-dev.
|
|
25
|
+
"@atlaspack/diagnostic": "2.14.1-dev.161+207d003c0",
|
|
26
|
+
"@atlaspack/feature-flags": "2.14.1-dev.161+207d003c0",
|
|
27
|
+
"@atlaspack/plugin": "2.14.5-dev.93+207d003c0",
|
|
28
|
+
"@atlaspack/rust": "3.2.1-dev.93+207d003c0",
|
|
29
|
+
"@atlaspack/utils": "2.14.5-dev.93+207d003c0",
|
|
30
|
+
"@atlaspack/workers": "2.14.5-dev.93+207d003c0",
|
|
34
31
|
"@parcel/source-map": "^2.1.1",
|
|
35
32
|
"@swc/helpers": "^0.5.15",
|
|
36
33
|
"browserslist": "^4.6.6",
|
|
@@ -42,5 +39,5 @@
|
|
|
42
39
|
"@atlaspack/core": "^2.13.1"
|
|
43
40
|
},
|
|
44
41
|
"type": "commonjs",
|
|
45
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "207d003c0f1d4ffa6a1c52d2f8841d998616c523"
|
|
46
43
|
}
|
package/src/JSTransformer.js
CHANGED
|
@@ -12,7 +12,7 @@ import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
|
12
12
|
import SourceMap from '@parcel/source-map';
|
|
13
13
|
import {Transformer} from '@atlaspack/plugin';
|
|
14
14
|
import {transform, transformAsync} from '@atlaspack/rust';
|
|
15
|
-
import
|
|
15
|
+
import invariant from 'assert';
|
|
16
16
|
import browserslist from 'browserslist';
|
|
17
17
|
import semver from 'semver';
|
|
18
18
|
import nullthrows from 'nullthrows';
|
|
@@ -24,10 +24,6 @@ import {validateSchema, remapSourceLocation, globMatch} from '@atlaspack/utils';
|
|
|
24
24
|
import pkg from '../package.json';
|
|
25
25
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
26
26
|
|
|
27
|
-
const esm_helpers_specifier = isSuperPackage()
|
|
28
|
-
? './esmodule-helpers.js'
|
|
29
|
-
: '@atlaspack/transformer-js/src/esmodule-helpers.js';
|
|
30
|
-
|
|
31
27
|
const JSX_EXTENSIONS = {
|
|
32
28
|
jsx: true,
|
|
33
29
|
tsx: true,
|
|
@@ -216,7 +212,7 @@ export default (new Transformer({
|
|
|
216
212
|
options.projectRoot + '/index',
|
|
217
213
|
['tsconfig.json', 'jsconfig.json'],
|
|
218
214
|
{
|
|
219
|
-
readTracking:
|
|
215
|
+
readTracking: true,
|
|
220
216
|
},
|
|
221
217
|
)
|
|
222
218
|
)?.contents?.compilerOptions;
|
|
@@ -444,9 +440,7 @@ export default (new Transformer({
|
|
|
444
440
|
module_id: asset.id,
|
|
445
441
|
project_root: options.projectRoot,
|
|
446
442
|
replace_env: !asset.env.isNode(),
|
|
447
|
-
inline_fs:
|
|
448
|
-
process.env.ATLASPACK_SUPER_BUILD === 'true' ||
|
|
449
|
-
(Boolean(config?.inlineFS) && !asset.env.isNode()),
|
|
443
|
+
inline_fs: Boolean(config?.inlineFS) && !asset.env.isNode(),
|
|
450
444
|
insert_node_globals:
|
|
451
445
|
!asset.env.isNode() && asset.env.sourceType !== 'script',
|
|
452
446
|
node_replacer: asset.env.isNode(),
|
|
@@ -481,8 +475,8 @@ export default (new Transformer({
|
|
|
481
475
|
standalone: asset.query.has('standalone'),
|
|
482
476
|
inline_constants: config.inlineConstants,
|
|
483
477
|
conditional_bundling: options.featureFlags.conditionalBundlingApi,
|
|
478
|
+
hmr_improvements: options.featureFlags.hmrImprovements,
|
|
484
479
|
magic_comments: Boolean(config?.magicComments),
|
|
485
|
-
esm_helpers_specifier,
|
|
486
480
|
callMacro: asset.isSource
|
|
487
481
|
? async (err, src, exportName, args, loc) => {
|
|
488
482
|
let mod;
|
|
@@ -586,7 +580,7 @@ export default (new Transformer({
|
|
|
586
580
|
let stack = (err.stack || '').split('\n').slice(1);
|
|
587
581
|
let message = err.message;
|
|
588
582
|
for (let line of stack) {
|
|
589
|
-
if (line.includes(
|
|
583
|
+
if (line.includes(__filename)) {
|
|
590
584
|
break;
|
|
591
585
|
}
|
|
592
586
|
message += '\n' + line;
|
|
@@ -788,6 +782,13 @@ export default (new Transformer({
|
|
|
788
782
|
});
|
|
789
783
|
} else if (dep.kind === 'File') {
|
|
790
784
|
asset.invalidateOnFileChange(dep.specifier);
|
|
785
|
+
} else if (dep.kind === 'Id') {
|
|
786
|
+
// Record parcelRequire calls so that the dev packager can add them as dependencies.
|
|
787
|
+
// This allows the HMR runtime to collect parents across async boundaries (through runtimes).
|
|
788
|
+
// TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
|
|
789
|
+
asset.meta.hmrDeps ??= [];
|
|
790
|
+
invariant(Array.isArray(asset.meta.hmrDeps));
|
|
791
|
+
asset.meta.hmrDeps.push(dep.specifier);
|
|
791
792
|
} else {
|
|
792
793
|
let meta: JSONObject = {kind: dep.kind};
|
|
793
794
|
if (dep.attributes) {
|
|
@@ -890,9 +891,7 @@ export default (new Transformer({
|
|
|
890
891
|
: 'sync',
|
|
891
892
|
isOptional: dep.is_optional,
|
|
892
893
|
meta,
|
|
893
|
-
resolveFrom: isHelper
|
|
894
|
-
? /*#__ATLASPACK_IGNORE__*/ __filename
|
|
895
|
-
: undefined,
|
|
894
|
+
resolveFrom: isHelper ? __filename : undefined,
|
|
896
895
|
range,
|
|
897
896
|
env,
|
|
898
897
|
});
|
|
@@ -1080,29 +1079,16 @@ export default (new Transformer({
|
|
|
1080
1079
|
}
|
|
1081
1080
|
|
|
1082
1081
|
if (needs_esm_helpers) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
atlaspack: true,
|
|
1091
|
-
},
|
|
1092
|
-
},
|
|
1093
|
-
});
|
|
1094
|
-
} else {
|
|
1095
|
-
asset.addDependency({
|
|
1096
|
-
specifier: esm_helpers_specifier,
|
|
1097
|
-
specifierType: 'esm',
|
|
1098
|
-
resolveFrom: /*#__ATLASPACK_IGNORE__*/ __filename,
|
|
1099
|
-
env: {
|
|
1100
|
-
includeNodeModules: {
|
|
1101
|
-
'@atlaspack/transformer-js': true,
|
|
1102
|
-
},
|
|
1082
|
+
asset.addDependency({
|
|
1083
|
+
specifier: '@atlaspack/transformer-js/src/esmodule-helpers.js',
|
|
1084
|
+
specifierType: 'esm',
|
|
1085
|
+
resolveFrom: __filename,
|
|
1086
|
+
env: {
|
|
1087
|
+
includeNodeModules: {
|
|
1088
|
+
'@atlaspack/transformer-js': true,
|
|
1103
1089
|
},
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1090
|
+
},
|
|
1091
|
+
});
|
|
1106
1092
|
}
|
|
1107
1093
|
}
|
|
1108
1094
|
|