metro-transform-worker 0.70.3 → 0.71.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-transform-worker",
3
- "version": "0.70.3",
3
+ "version": "0.71.0",
4
4
  "description": "🚇 Transform worker for Metro.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -18,18 +18,18 @@
18
18
  "@babel/parser": "^7.14.0",
19
19
  "@babel/types": "^7.0.0",
20
20
  "babel-preset-fbjs": "^3.4.0",
21
- "metro": "0.70.3",
22
- "metro-babel-transformer": "0.70.3",
23
- "metro-cache": "0.70.3",
24
- "metro-cache-key": "0.70.3",
25
- "metro-hermes-compiler": "0.70.3",
26
- "metro-source-map": "0.70.3",
27
- "metro-transform-plugins": "0.70.3",
21
+ "metro": "0.71.0",
22
+ "metro-babel-transformer": "0.71.0",
23
+ "metro-cache": "0.71.0",
24
+ "metro-cache-key": "0.71.0",
25
+ "metro-hermes-compiler": "0.71.0",
26
+ "metro-source-map": "0.71.0",
27
+ "metro-transform-plugins": "0.71.0",
28
28
  "nullthrows": "^1.1.1"
29
29
  },
30
30
  "devDependencies": {
31
- "metro-memory-fs": "0.70.3",
32
- "metro-minify-uglify": "0.70.3",
33
- "metro-react-native-babel-transformer": "0.70.3"
31
+ "metro-memory-fs": "0.71.0",
32
+ "metro-minify-uglify": "0.71.0",
33
+ "metro-react-native-babel-transformer": "0.71.0"
34
34
  }
35
35
  }
package/src/index.js.flow CHANGED
@@ -78,7 +78,7 @@ export type Minifier = MinifierOptions =>
78
78
 
79
79
  export type Type = 'script' | 'module' | 'asset';
80
80
 
81
- export type JsTransformerConfig = $ReadOnly<{|
81
+ export type JsTransformerConfig = $ReadOnly<{
82
82
  assetPlugins: $ReadOnlyArray<string>,
83
83
  assetRegistryPath: string,
84
84
  asyncRequireModulePath: string,
@@ -99,11 +99,11 @@ export type JsTransformerConfig = $ReadOnly<{|
99
99
  unstable_disableModuleWrapping: boolean,
100
100
  unstable_disableNormalizePseudoGlobals: boolean,
101
101
  unstable_compactOutput: boolean,
102
- |}>;
102
+ }>;
103
103
 
104
104
  export type {CustomTransformOptions} from 'metro-babel-transformer';
105
105
 
106
- export type JsTransformOptions = $ReadOnly<{|
106
+ export type JsTransformOptions = $ReadOnly<{
107
107
  customTransformOptions?: CustomTransformOptions,
108
108
  dev: boolean,
109
109
  experimentalImportSupport?: boolean,
@@ -117,7 +117,7 @@ export type JsTransformOptions = $ReadOnly<{|
117
117
  type: Type,
118
118
  unstable_disableES6Transforms?: boolean,
119
119
  unstable_transformProfile: TransformProfile,
120
- |}>;
120
+ }>;
121
121
 
122
122
  export type BytecodeFileType =
123
123
  | 'bytecode/module'
@@ -157,20 +157,20 @@ type TransformationContext = $ReadOnly<{
157
157
  options: JsTransformOptions,
158
158
  }>;
159
159
 
160
- export type JsOutput = $ReadOnly<{|
161
- data: $ReadOnly<{|
160
+ export type JsOutput = $ReadOnly<{
161
+ data: $ReadOnly<{
162
162
  code: string,
163
163
  lineCount: number,
164
164
  map: Array<MetroSourceMapSegmentTuple>,
165
165
  functionMap: ?FBSourceFunctionMap,
166
- |}>,
166
+ }>,
167
167
  type: JSFileType,
168
- |}>;
168
+ }>;
169
169
 
170
- export type BytecodeOutput = $ReadOnly<{|
170
+ export type BytecodeOutput = $ReadOnly<{
171
171
  data: HermesCompilerResult,
172
172
  type: BytecodeFileType,
173
- |}>;
173
+ }>;
174
174
 
175
175
  type DependencySplitCondition = $PropertyType<
176
176
  $PropertyType<TransformResultDependency, 'data'>,
@@ -24,6 +24,8 @@ jest
24
24
  .mock('metro-minify-uglify');
25
25
 
26
26
  import type {JsTransformerConfig} from '../index';
27
+ import typeof TransformerType from '../index';
28
+ import typeof FSType from 'fs';
27
29
 
28
30
  const HermesCompiler = require('metro-hermes-compiler');
29
31
  const path = require('path');
@@ -38,8 +40,8 @@ const HEADER_DEV =
38
40
  '__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {';
39
41
  const HEADER_PROD = '__d(function (g, r, i, a, m, e, d) {';
40
42
 
41
- let fs;
42
- let Transformer;
43
+ let fs: FSType;
44
+ let Transformer: TransformerType;
43
45
 
44
46
  const baseConfig: JsTransformerConfig = {
45
47
  allowOptionalDependencies: false,
@@ -72,6 +74,7 @@ beforeEach(() => {
72
74
 
73
75
  fs = require('fs');
74
76
  Transformer = require('../');
77
+ // $FlowFixMe[prop-missing] Cannot call `fs.reset` because property `reset` is missing in module `fs`
75
78
  fs.reset();
76
79
 
77
80
  fs.mkdirSync('/root/local', {recursive: true});
@@ -84,7 +87,9 @@ it('transforms a simple script', async () => {
84
87
  baseConfig,
85
88
  '/root',
86
89
  'local/file.js',
90
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
87
91
  'someReallyArbitrary(code)',
92
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
88
93
  {
89
94
  dev: true,
90
95
  type: 'script',
@@ -109,7 +114,9 @@ it('transforms a simple module', async () => {
109
114
  baseConfig,
110
115
  '/root',
111
116
  'local/file.js',
117
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
112
118
  'arbitrary(code)',
119
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
113
120
  {
114
121
  dev: true,
115
122
  type: 'module',
@@ -138,7 +145,9 @@ it('transforms a module with dependencies', async () => {
138
145
  baseConfig,
139
146
  '/root',
140
147
  'local/file.js',
148
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
141
149
  contents,
150
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
142
151
  {
143
152
  dev: true,
144
153
  type: 'module',
@@ -181,7 +190,9 @@ it('transforms an es module with asyncToGenerator', async () => {
181
190
  baseConfig,
182
191
  '/root',
183
192
  'local/file.js',
193
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
184
194
  'export async function test() {}',
195
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
185
196
  {
186
197
  dev: true,
187
198
  type: 'module',
@@ -209,7 +220,9 @@ it('transforms async generators', async () => {
209
220
  baseConfig,
210
221
  '/root',
211
222
  'local/file.js',
223
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
212
224
  'export async function* test() { yield "ok"; }',
225
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
213
226
  {
214
227
  dev: true,
215
228
  type: 'module',
@@ -240,7 +253,9 @@ it('transforms import/export syntax when experimental flag is on', async () => {
240
253
  baseConfig,
241
254
  '/root',
242
255
  'local/file.js',
256
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
243
257
  contents,
258
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
244
259
  {
245
260
  dev: true,
246
261
  experimentalImportSupport: true,
@@ -275,7 +290,9 @@ it('does not add "use strict" on non-modules', async () => {
275
290
  baseConfig,
276
291
  '/root',
277
292
  'node_modules/local/file.js',
293
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
278
294
  'module.exports = {};',
295
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
279
296
  {
280
297
  dev: true,
281
298
  experimentalImportSupport: true,
@@ -299,7 +316,9 @@ it('preserves require() calls when module wrapping is disabled', async () => {
299
316
  },
300
317
  '/root',
301
318
  'local/file.js',
319
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
302
320
  contents,
321
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
303
322
  {
304
323
  dev: true,
305
324
  type: 'module',
@@ -322,7 +341,9 @@ it('reports filename when encountering unsupported dynamic dependency', async ()
322
341
  baseConfig,
323
342
  '/root',
324
343
  'local/file.js',
344
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
325
345
  contents,
346
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
326
347
  {
327
348
  dev: true,
328
349
  type: 'module',
@@ -344,7 +365,9 @@ it('supports dynamic dependencies from within `node_modules`', async () => {
344
365
  },
345
366
  '/root',
346
367
  'node_modules/foo/bar.js',
368
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
347
369
  'require(foo.bar);',
370
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
348
371
  {
349
372
  dev: true,
350
373
  type: 'module',
@@ -369,7 +392,9 @@ it('minifies the code correctly', async () => {
369
392
  baseConfig,
370
393
  '/root',
371
394
  'local/file.js',
395
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
372
396
  'arbitrary(code);',
397
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
373
398
  {
374
399
  dev: true,
375
400
  minify: true,
@@ -387,7 +412,9 @@ it('minifies a JSON file', async () => {
387
412
  baseConfig,
388
413
  '/root',
389
414
  'local/file.json',
415
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
390
416
  'arbitrary(code);',
417
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
391
418
  {
392
419
  dev: true,
393
420
  minify: true,
@@ -414,7 +441,9 @@ it('does not wrap a JSON file when disableModuleWrapping is enabled', async () =
414
441
  },
415
442
  '/root',
416
443
  'local/file.json',
444
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
417
445
  'arbitrary(code);',
446
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
418
447
  {
419
448
  dev: true,
420
449
  type: 'module',
@@ -429,7 +458,9 @@ it('transforms a script to JS source and bytecode', async () => {
429
458
  baseConfig,
430
459
  '/root',
431
460
  'local/file.js',
461
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
432
462
  'someReallyArbitrary(code)',
463
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
433
464
  {
434
465
  dev: true,
435
466
  runtimeBytecodeVersion: 1,
@@ -441,7 +472,7 @@ it('transforms a script to JS source and bytecode', async () => {
441
472
  const bytecodeOutput = result.output.find(
442
473
  output => output.type === 'bytecode/script',
443
474
  );
444
-
475
+ // $FlowFixMe[incompatible-use] Added when annotating Transformer. data missing in jsOutput.
445
476
  expect(jsOutput.data.code).toBe(
446
477
  [
447
478
  '(function (global) {',
@@ -451,6 +482,8 @@ it('transforms a script to JS source and bytecode', async () => {
451
482
  );
452
483
 
453
484
  expect(() =>
485
+ // $FlowFixMe[incompatible-use] Added when annotating Transformer. data missing in bytecodeOutput.
486
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. bytecode property is missing.
454
487
  HermesCompiler.validateBytecodeModule(bytecodeOutput.data.bytecode, 0),
455
488
  ).not.toThrow();
456
489
  });
@@ -488,7 +521,9 @@ it('allows replacing the collectDependencies implementation', async () => {
488
521
  config,
489
522
  '/root',
490
523
  'local/file.js',
524
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
491
525
  'require("foo")',
526
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
492
527
  options,
493
528
  );
494
529
 
@@ -515,7 +550,9 @@ it('uses a reserved dependency map name and prevents it from being minified', as
515
550
  {...baseConfig, unstable_dependencyMapReservedName: 'THE_DEP_MAP'},
516
551
  '/root',
517
552
  'local/file.js',
553
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
518
554
  'arbitrary(code);',
555
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
519
556
  {
520
557
  dev: false,
521
558
  minify: true,
@@ -535,7 +572,9 @@ it('throws if the reserved dependency map name appears in the input', async () =
535
572
  {...baseConfig, unstable_dependencyMapReservedName: 'THE_DEP_MAP'},
536
573
  '/root',
537
574
  'local/file.js',
575
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
538
576
  'arbitrary(code); /* the code is not allowed to mention THE_DEP_MAP, even in a comment */',
577
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
539
578
  {
540
579
  dev: false,
541
580
  minify: true,
@@ -552,7 +591,9 @@ it('allows disabling the normalizePseudoGlobals pass when minifying', async () =
552
591
  {...baseConfig, unstable_disableNormalizePseudoGlobals: true},
553
592
  '/root',
554
593
  'local/file.js',
594
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
555
595
  'arbitrary(code);',
596
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
556
597
  {
557
598
  dev: false,
558
599
  minify: true,
@@ -571,7 +612,9 @@ it('allows emitting compact code when not minifying', async () => {
571
612
  {...baseConfig, unstable_compactOutput: true},
572
613
  '/root',
573
614
  'local/file.js',
615
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
574
616
  'arbitrary(code);',
617
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
575
618
  {
576
619
  dev: false,
577
620
  minify: false,
@@ -588,7 +631,9 @@ it('skips minification in Hermes stable transform profile', async () => {
588
631
  baseConfig,
589
632
  '/root',
590
633
  'local/file.js',
634
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
591
635
  'arbitrary(code);',
636
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
592
637
  {
593
638
  dev: false,
594
639
  minify: true,
@@ -608,7 +653,9 @@ it('skips minification in Hermes canary transform profile', async () => {
608
653
  baseConfig,
609
654
  '/root',
610
655
  'local/file.js',
656
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
611
657
  'arbitrary(code);',
658
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
612
659
  {
613
660
  dev: false,
614
661
  minify: true,
@@ -627,11 +674,19 @@ it('counts all line endings correctly', async () => {
627
674
  const transformStr = (
628
675
  str: $TEMPORARY$string<'one\ntwo\nthree\nfour\nfive\nsix'> | string,
629
676
  ) =>
630
- Transformer.transform(baseConfig, '/root', 'local/file.js', str, {
631
- dev: false,
632
- minify: false,
633
- type: 'module',
634
- });
677
+ Transformer.transform(
678
+ baseConfig,
679
+ '/root',
680
+ 'local/file.js',
681
+ // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
682
+ str,
683
+ // $FlowFixMe[prop-missing] Added when annotating Transformer.
684
+ {
685
+ dev: false,
686
+ minify: false,
687
+ type: 'module',
688
+ },
689
+ );
635
690
 
636
691
  const differentEndingsResult = await transformStr(
637
692
  'one\rtwo\r\nthree\nfour\u2028five\u2029six',
package/src.real/index.js CHANGED
@@ -78,7 +78,7 @@ export type Minifier = MinifierOptions =>
78
78
 
79
79
  export type Type = 'script' | 'module' | 'asset';
80
80
 
81
- export type JsTransformerConfig = $ReadOnly<{|
81
+ export type JsTransformerConfig = $ReadOnly<{
82
82
  assetPlugins: $ReadOnlyArray<string>,
83
83
  assetRegistryPath: string,
84
84
  asyncRequireModulePath: string,
@@ -99,11 +99,11 @@ export type JsTransformerConfig = $ReadOnly<{|
99
99
  unstable_disableModuleWrapping: boolean,
100
100
  unstable_disableNormalizePseudoGlobals: boolean,
101
101
  unstable_compactOutput: boolean,
102
- |}>;
102
+ }>;
103
103
 
104
104
  export type {CustomTransformOptions} from 'metro-babel-transformer';
105
105
 
106
- export type JsTransformOptions = $ReadOnly<{|
106
+ export type JsTransformOptions = $ReadOnly<{
107
107
  customTransformOptions?: CustomTransformOptions,
108
108
  dev: boolean,
109
109
  experimentalImportSupport?: boolean,
@@ -117,7 +117,7 @@ export type JsTransformOptions = $ReadOnly<{|
117
117
  type: Type,
118
118
  unstable_disableES6Transforms?: boolean,
119
119
  unstable_transformProfile: TransformProfile,
120
- |}>;
120
+ }>;
121
121
 
122
122
  export type BytecodeFileType =
123
123
  | 'bytecode/module'
@@ -157,20 +157,20 @@ type TransformationContext = $ReadOnly<{
157
157
  options: JsTransformOptions,
158
158
  }>;
159
159
 
160
- export type JsOutput = $ReadOnly<{|
161
- data: $ReadOnly<{|
160
+ export type JsOutput = $ReadOnly<{
161
+ data: $ReadOnly<{
162
162
  code: string,
163
163
  lineCount: number,
164
164
  map: Array<MetroSourceMapSegmentTuple>,
165
165
  functionMap: ?FBSourceFunctionMap,
166
- |}>,
166
+ }>,
167
167
  type: JSFileType,
168
- |}>;
168
+ }>;
169
169
 
170
- export type BytecodeOutput = $ReadOnly<{|
170
+ export type BytecodeOutput = $ReadOnly<{
171
171
  data: HermesCompilerResult,
172
172
  type: BytecodeFileType,
173
- |}>;
173
+ }>;
174
174
 
175
175
  type DependencySplitCondition = $PropertyType<
176
176
  $PropertyType<TransformResultDependency, 'data'>,