metro-transform-worker 0.85.0 → 0.86.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/package.json +8 -8
- package/src/index.d.ts +3 -16
- package/src/index.js +31 -16
- package/src/index.js.flow +47 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-transform-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"description": "🚇 Transform worker for Metro.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@babel/parser": "^7.29.0",
|
|
25
25
|
"@babel/types": "^7.29.0",
|
|
26
26
|
"flow-enums-runtime": "^0.0.6",
|
|
27
|
-
"metro": "0.
|
|
28
|
-
"metro-babel-transformer": "0.
|
|
29
|
-
"metro-cache": "0.
|
|
30
|
-
"metro-cache-key": "0.
|
|
31
|
-
"metro-minify-terser": "0.
|
|
32
|
-
"metro-source-map": "0.
|
|
33
|
-
"metro-transform-plugins": "0.
|
|
27
|
+
"metro": "0.86.0",
|
|
28
|
+
"metro-babel-transformer": "0.86.0",
|
|
29
|
+
"metro-cache": "0.86.0",
|
|
30
|
+
"metro-cache-key": "0.86.0",
|
|
31
|
+
"metro-minify-terser": "0.86.0",
|
|
32
|
+
"metro-source-map": "0.86.0",
|
|
33
|
+
"metro-transform-plugins": "0.86.0",
|
|
34
34
|
"nullthrows": "^1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
package/src/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
-
* @generated SignedSource<<
|
|
9
|
+
* @generated SignedSource<<28342f12ccdb6543eff2ef94ebd19bbc>>
|
|
10
10
|
*
|
|
11
11
|
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
12
|
* Original file: packages/metro-transform-worker/src/index.js
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
import type {
|
|
23
23
|
BasicSourceMap,
|
|
24
24
|
FBSourceFunctionMap,
|
|
25
|
-
|
|
25
|
+
VlqMap,
|
|
26
26
|
} from 'metro-source-map';
|
|
27
27
|
import type {TransformResultDependency} from 'metro/private/DeltaBundler';
|
|
28
28
|
import type {AllowOptionalDependencies} from 'metro/private/DeltaBundler/types';
|
|
@@ -90,7 +90,7 @@ export type JsOutput = Readonly<{
|
|
|
90
90
|
data: Readonly<{
|
|
91
91
|
code: string;
|
|
92
92
|
lineCount: number;
|
|
93
|
-
map:
|
|
93
|
+
map: VlqMap;
|
|
94
94
|
functionMap: null | undefined | FBSourceFunctionMap;
|
|
95
95
|
}>;
|
|
96
96
|
type: JSFileType;
|
|
@@ -112,16 +112,3 @@ export declare const getCacheKey: (
|
|
|
112
112
|
opts?: Readonly<{projectRoot: string}>,
|
|
113
113
|
) => string;
|
|
114
114
|
export declare type getCacheKey = typeof getCacheKey;
|
|
115
|
-
/**
|
|
116
|
-
* Backwards-compatibility with CommonJS consumers using interopRequireDefault.
|
|
117
|
-
* Do not add to this list.
|
|
118
|
-
*
|
|
119
|
-
* @deprecated Default import from 'metro-transform-worker' is deprecated, use named exports.
|
|
120
|
-
*/
|
|
121
|
-
declare const $$EXPORT_DEFAULT_DECLARATION$$: {
|
|
122
|
-
getCacheKey: typeof getCacheKey;
|
|
123
|
-
transform: typeof transform;
|
|
124
|
-
};
|
|
125
|
-
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
|
|
126
|
-
typeof $$EXPORT_DEFAULT_DECLARATION$$;
|
|
127
|
-
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
|
-
exports.transform = exports.getCacheKey =
|
|
6
|
+
exports.transform = exports.getCacheKey = void 0;
|
|
7
7
|
var assetTransformer = _interopRequireWildcard(
|
|
8
8
|
require("./utils/assetTransformer"),
|
|
9
9
|
);
|
|
@@ -300,23 +300,35 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
300
300
|
},
|
|
301
301
|
file.code,
|
|
302
302
|
);
|
|
303
|
-
let map = result.rawMappings
|
|
304
|
-
? result.rawMappings.map(_metroSourceMap.toSegmentTuple)
|
|
305
|
-
: [];
|
|
306
303
|
let code = result.code;
|
|
304
|
+
let map;
|
|
305
|
+
let lineCount;
|
|
307
306
|
if (minify) {
|
|
308
|
-
|
|
307
|
+
let tuples = result.decodedMap
|
|
308
|
+
? (0, _metroSourceMap.tuplesFromBabelDecodedMap)(result.decodedMap)
|
|
309
|
+
: [];
|
|
310
|
+
({ map: tuples, code } = await minifyCode(
|
|
309
311
|
config,
|
|
310
312
|
projectRoot,
|
|
311
313
|
file.filename,
|
|
312
314
|
result.code,
|
|
313
315
|
file.code,
|
|
314
|
-
|
|
316
|
+
tuples,
|
|
315
317
|
reserved,
|
|
316
318
|
));
|
|
319
|
+
({ lineCount, map: tuples } = countLinesAndTerminateMap(code, tuples));
|
|
320
|
+
map = (0, _metroSourceMap.vlqMapFromTuples)(tuples);
|
|
321
|
+
} else {
|
|
322
|
+
const { lineCount: lines, lastLineColumn } = countLines(code);
|
|
323
|
+
lineCount = lines;
|
|
324
|
+
map = (0, _metroSourceMap.vlqMapFromBabelDecodedMap)(
|
|
325
|
+
result.decodedMap ?? {
|
|
326
|
+
mappings: [],
|
|
327
|
+
names: [],
|
|
328
|
+
},
|
|
329
|
+
[lines, lastLineColumn],
|
|
330
|
+
);
|
|
317
331
|
}
|
|
318
|
-
let lineCount;
|
|
319
|
-
({ lineCount, map } = countLinesAndTerminateMap(code, map));
|
|
320
332
|
const output = [
|
|
321
333
|
{
|
|
322
334
|
data: {
|
|
@@ -408,13 +420,14 @@ async function transformJSON(file, { options, config, projectRoot }) {
|
|
|
408
420
|
}
|
|
409
421
|
let lineCount;
|
|
410
422
|
({ lineCount, map } = countLinesAndTerminateMap(code, map));
|
|
423
|
+
const outputMap = (0, _metroSourceMap.vlqMapFromTuples)(map);
|
|
411
424
|
const output = [
|
|
412
425
|
{
|
|
413
426
|
data: {
|
|
414
427
|
code,
|
|
415
428
|
functionMap: null,
|
|
416
429
|
lineCount,
|
|
417
|
-
map,
|
|
430
|
+
map: outputMap,
|
|
418
431
|
},
|
|
419
432
|
type: jsType,
|
|
420
433
|
},
|
|
@@ -527,7 +540,7 @@ const getCacheKey = (config, opts) => {
|
|
|
527
540
|
].join("$");
|
|
528
541
|
};
|
|
529
542
|
exports.getCacheKey = getCacheKey;
|
|
530
|
-
function
|
|
543
|
+
function countLines(code) {
|
|
531
544
|
const NEWLINE = /\r\n?|\n|\u2028|\u2029/g;
|
|
532
545
|
let lineCount = 1;
|
|
533
546
|
let lastLineStart = 0;
|
|
@@ -535,9 +548,15 @@ function countLinesAndTerminateMap(code, map) {
|
|
|
535
548
|
lineCount++;
|
|
536
549
|
lastLineStart = match.index + match[0].length;
|
|
537
550
|
}
|
|
538
|
-
|
|
551
|
+
return {
|
|
552
|
+
lineCount,
|
|
553
|
+
lastLineColumn: code.length - lastLineStart,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function countLinesAndTerminateMap(code, map) {
|
|
557
|
+
const { lineCount, lastLineColumn } = countLines(code);
|
|
539
558
|
const lastLineIndex1Based = lineCount;
|
|
540
|
-
const lastLineNextColumn0Based =
|
|
559
|
+
const lastLineNextColumn0Based = lastLineColumn;
|
|
541
560
|
const lastMapping = map[map.length - 1];
|
|
542
561
|
const terminatingMapping = [lastLineIndex1Based, lastLineNextColumn0Based];
|
|
543
562
|
if (
|
|
@@ -555,7 +574,3 @@ function countLinesAndTerminateMap(code, map) {
|
|
|
555
574
|
map: [...map],
|
|
556
575
|
};
|
|
557
576
|
}
|
|
558
|
-
var _default = (exports.default = {
|
|
559
|
-
getCacheKey,
|
|
560
|
-
transform,
|
|
561
|
-
});
|
package/src/index.js.flow
CHANGED
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
BasicSourceMap,
|
|
21
21
|
FBSourceFunctionMap,
|
|
22
22
|
MetroSourceMapSegmentTuple,
|
|
23
|
+
VlqMap,
|
|
23
24
|
} from 'metro-source-map';
|
|
24
25
|
import type {
|
|
25
26
|
ImportExportPluginOptions,
|
|
@@ -46,6 +47,9 @@ import {
|
|
|
46
47
|
functionMapBabelPlugin,
|
|
47
48
|
toBabelSegments,
|
|
48
49
|
toSegmentTuple,
|
|
50
|
+
tuplesFromBabelDecodedMap,
|
|
51
|
+
vlqMapFromBabelDecodedMap,
|
|
52
|
+
vlqMapFromTuples,
|
|
49
53
|
} from 'metro-source-map';
|
|
50
54
|
import metroTransformPlugins from 'metro-transform-plugins';
|
|
51
55
|
import collectDependencies from 'metro/private/ModuleGraph/worker/collectDependencies';
|
|
@@ -168,7 +172,7 @@ export type JsOutput = Readonly<{
|
|
|
168
172
|
data: Readonly<{
|
|
169
173
|
code: string,
|
|
170
174
|
lineCount: number,
|
|
171
|
-
map:
|
|
175
|
+
map: VlqMap,
|
|
172
176
|
functionMap: ?FBSourceFunctionMap,
|
|
173
177
|
}>,
|
|
174
178
|
type: JSFileType,
|
|
@@ -471,23 +475,41 @@ async function transformJS(
|
|
|
471
475
|
file.code,
|
|
472
476
|
);
|
|
473
477
|
|
|
474
|
-
let map = result.rawMappings ? result.rawMappings.map(toSegmentTuple) : [];
|
|
475
478
|
let code = result.code;
|
|
479
|
+
let map: VlqMap;
|
|
480
|
+
let lineCount: number;
|
|
476
481
|
|
|
477
482
|
if (minify) {
|
|
478
|
-
(
|
|
483
|
+
// The minifier returns its own map (not Babel's `decodedMap`), so we derive
|
|
484
|
+
// tuples from Babel's eagerly-computed decoded map, hand them to the
|
|
485
|
+
// minifier, then re-encode the resulting tuples to a compact VLQ map.
|
|
486
|
+
let tuples = result.decodedMap
|
|
487
|
+
? tuplesFromBabelDecodedMap(result.decodedMap)
|
|
488
|
+
: [];
|
|
489
|
+
|
|
490
|
+
({map: tuples, code} = await minifyCode(
|
|
479
491
|
config,
|
|
480
492
|
projectRoot,
|
|
481
493
|
file.filename,
|
|
482
494
|
result.code,
|
|
483
495
|
file.code,
|
|
484
|
-
|
|
496
|
+
tuples,
|
|
485
497
|
reserved,
|
|
486
498
|
));
|
|
487
|
-
}
|
|
488
499
|
|
|
489
|
-
|
|
490
|
-
|
|
500
|
+
({lineCount, map: tuples} = countLinesAndTerminateMap(code, tuples));
|
|
501
|
+
map = vlqMapFromTuples(tuples);
|
|
502
|
+
} else {
|
|
503
|
+
// Dominant path (e.g. Hermes, which doesn't minify): encode the compact VLQ
|
|
504
|
+
// map straight from Babel's eagerly-computed decoded map, never
|
|
505
|
+
// materialising tuples.
|
|
506
|
+
const {lineCount: lines, lastLineColumn} = countLines(code);
|
|
507
|
+
lineCount = lines;
|
|
508
|
+
map = vlqMapFromBabelDecodedMap(
|
|
509
|
+
result.decodedMap ?? {mappings: [], names: []},
|
|
510
|
+
[lines, lastLineColumn],
|
|
511
|
+
);
|
|
512
|
+
}
|
|
491
513
|
|
|
492
514
|
const output: Array<JsOutput> = [
|
|
493
515
|
{
|
|
@@ -616,9 +638,12 @@ async function transformJSON(
|
|
|
616
638
|
|
|
617
639
|
let lineCount;
|
|
618
640
|
({lineCount, map} = countLinesAndTerminateMap(code, map));
|
|
641
|
+
// The JSON path builds tuples directly (no Babel `decodedMap`), so re-encode
|
|
642
|
+
// the finished tuples to a compact VLQ map.
|
|
643
|
+
const outputMap = vlqMapFromTuples(map);
|
|
619
644
|
const output: Array<JsOutput> = [
|
|
620
645
|
{
|
|
621
|
-
data: {code, functionMap: null, lineCount, map},
|
|
646
|
+
data: {code, functionMap: null, lineCount, map: outputMap},
|
|
622
647
|
type: jsType,
|
|
623
648
|
},
|
|
624
649
|
];
|
|
@@ -755,12 +780,9 @@ export const getCacheKey = (
|
|
|
755
780
|
].join('$');
|
|
756
781
|
};
|
|
757
782
|
|
|
758
|
-
function
|
|
759
|
-
code: string,
|
|
760
|
-
map: ReadonlyArray<MetroSourceMapSegmentTuple>,
|
|
761
|
-
): {
|
|
783
|
+
function countLines(code: string): {
|
|
762
784
|
lineCount: number,
|
|
763
|
-
|
|
785
|
+
lastLineColumn: number,
|
|
764
786
|
} {
|
|
765
787
|
const NEWLINE = /\r\n?|\n|\u2028|\u2029/g;
|
|
766
788
|
let lineCount = 1;
|
|
@@ -771,9 +793,19 @@ function countLinesAndTerminateMap(
|
|
|
771
793
|
lineCount++;
|
|
772
794
|
lastLineStart = match.index + match[0].length;
|
|
773
795
|
}
|
|
774
|
-
|
|
796
|
+
return {lineCount, lastLineColumn: code.length - lastLineStart};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function countLinesAndTerminateMap(
|
|
800
|
+
code: string,
|
|
801
|
+
map: ReadonlyArray<MetroSourceMapSegmentTuple>,
|
|
802
|
+
): {
|
|
803
|
+
lineCount: number,
|
|
804
|
+
map: Array<MetroSourceMapSegmentTuple>,
|
|
805
|
+
} {
|
|
806
|
+
const {lineCount, lastLineColumn} = countLines(code);
|
|
775
807
|
const lastLineIndex1Based = lineCount;
|
|
776
|
-
const lastLineNextColumn0Based =
|
|
808
|
+
const lastLineNextColumn0Based = lastLineColumn;
|
|
777
809
|
|
|
778
810
|
// If there isn't a mapping at one-past-the-last column of the last line,
|
|
779
811
|
// add one that maps to nothing. This ensures out-of-bounds lookups hit the
|
|
@@ -793,14 +825,3 @@ function countLinesAndTerminateMap(
|
|
|
793
825
|
}
|
|
794
826
|
return {lineCount, map: [...map]};
|
|
795
827
|
}
|
|
796
|
-
|
|
797
|
-
/**
|
|
798
|
-
* Backwards-compatibility with CommonJS consumers using interopRequireDefault.
|
|
799
|
-
* Do not add to this list.
|
|
800
|
-
*
|
|
801
|
-
* @deprecated Default import from 'metro-transform-worker' is deprecated, use named exports.
|
|
802
|
-
*/
|
|
803
|
-
export default {
|
|
804
|
-
getCacheKey,
|
|
805
|
-
transform,
|
|
806
|
-
};
|