@expo/metro-config 0.3.19 → 0.3.20

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.
@@ -1,185 +1,284 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createMultiRuleTransformer = createMultiRuleTransformer;
7
+ exports.loaders = void 0;
8
+
9
+ function _chalk() {
10
+ const data = _interopRequireDefault(require("chalk"));
11
+
12
+ _chalk = function () {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _debug() {
20
+ const data = _interopRequireDefault(require("debug"));
21
+
22
+ _debug = function () {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
28
+
29
+ function _resolveFrom() {
30
+ const data = _interopRequireDefault(require("resolve-from"));
31
+
32
+ _resolveFrom = function () {
33
+ return data;
34
+ };
35
+
36
+ return data;
37
+ }
38
+
39
+ function _generateFunctionMap() {
40
+ const data = require("./generateFunctionMap");
41
+
42
+ _generateFunctionMap = function () {
43
+ return data;
44
+ };
45
+
46
+ return data;
47
+ }
48
+
49
+ function _getBabelConfig() {
50
+ const data = require("./getBabelConfig");
51
+
52
+ _getBabelConfig = function () {
53
+ return data;
54
+ };
55
+
56
+ return data;
57
+ }
58
+
59
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
60
+
2
61
  // Copyright 2021-present 650 Industries (Expo). All rights reserved.
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.loaders = exports.createMultiRuleTransformer = void 0;
8
- const chalk_1 = __importDefault(require("chalk"));
9
- const debug_1 = __importDefault(require("debug"));
10
- const resolve_from_1 = __importDefault(require("resolve-from"));
11
- const generateFunctionMap_1 = require("./generateFunctionMap");
12
- const getBabelConfig_1 = require("./getBabelConfig");
13
- const debug = (0, debug_1.default)('expo:metro:exotic-babel-transformer');
62
+ const debug = (0, _debug().default)('expo:metro:exotic-babel-transformer');
14
63
  let babelCore;
64
+
15
65
  function getBabelCoreFromProject(projectRoot) {
16
- if (babelCore)
17
- return babelCore;
18
- babelCore = require((0, resolve_from_1.default)(projectRoot, '@babel/core'));
19
- return babelCore;
66
+ if (babelCore) return babelCore;
67
+ babelCore = require((0, _resolveFrom().default)(projectRoot, '@babel/core'));
68
+ return babelCore;
20
69
  }
70
+
21
71
  let babelParser;
72
+
22
73
  function getBabelParserFromProject(projectRoot) {
23
- if (babelParser)
24
- return babelParser;
25
- babelParser = require((0, resolve_from_1.default)(projectRoot, '@babel/parser'));
26
- return babelParser;
74
+ if (babelParser) return babelParser;
75
+ babelParser = require((0, _resolveFrom().default)(projectRoot, '@babel/parser'));
76
+ return babelParser;
27
77
  }
28
- function sucrase(args, { transforms, }) {
29
- const { src, filename, options: { dev }, } = args;
30
- const { transform } = require('sucrase');
31
- const results = transform(src, {
32
- filePath: filename,
33
- production: !dev,
34
- transforms,
35
- });
36
- return {
37
- code: results.code,
38
- functionMap: null,
39
- };
78
+
79
+ function sucrase(args, {
80
+ transforms
81
+ }) {
82
+ const {
83
+ src,
84
+ filename,
85
+ options: {
86
+ dev
87
+ }
88
+ } = args;
89
+
90
+ const {
91
+ transform
92
+ } = require('sucrase');
93
+
94
+ const results = transform(src, {
95
+ filePath: filename,
96
+ production: !dev,
97
+ transforms
98
+ });
99
+ return {
100
+ code: results.code,
101
+ functionMap: null
102
+ };
40
103
  }
41
- const getExpensiveSucraseTransforms = (filename) => [
42
- 'jsx',
43
- 'imports',
44
- /\.tsx?$/.test(filename) ? 'typescript' : 'flow',
45
- ];
104
+
105
+ const getExpensiveSucraseTransforms = filename => ['jsx', 'imports', /\.tsx?$/.test(filename) ? 'typescript' : 'flow'];
106
+
46
107
  function parseAst(projectRoot, sourceCode) {
47
- const babylon = getBabelParserFromProject(projectRoot);
48
- return babylon.parse(sourceCode, {
49
- sourceType: 'unambiguous',
50
- });
108
+ const babylon = getBabelParserFromProject(projectRoot);
109
+ return babylon.parse(sourceCode, {
110
+ sourceType: 'unambiguous'
111
+ });
51
112
  }
113
+
52
114
  /** Create a transformer that emulates Webpack's loader system. */
53
- function createMultiRuleTransformer({ getRuleType, rules, }) {
54
- // const warnings: string[] = [];
55
- return function transform(args) {
56
- const { filename, options } = args;
57
- const OLD_BABEL_ENV = process.env.BABEL_ENV;
58
- process.env.BABEL_ENV = (options === null || options === void 0 ? void 0 : options.dev) ? 'development' : process.env.BABEL_ENV || 'production';
59
- try {
60
- const ruleType = getRuleType(args);
61
- for (const rule of rules) {
62
- // optimization for checking node modules
63
- if (rule.type && rule.type !== ruleType) {
64
- continue;
65
- }
66
- const isMatched = typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);
67
- if (isMatched) {
68
- const results = rule.transform(args);
69
- // @ts-ignore: Add extra property for testing
70
- results._ruleName = rule.name;
71
- // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.
72
- if (results.code && !results.ast) {
73
- // Parse AST with babel otherwise Metro transformer will throw away the returned results.
74
- results.ast = parseAst(options === null || options === void 0 ? void 0 : options.projectRoot, results.code);
75
- }
76
- // TODO: Suboptimal warnings
77
- // if (rule.warn) {
78
- // const matchName =
79
- // filename.match(/node_modules\/((:?@[\w\d-]+\/[\w\d-]+)|(:?[\w\d-]+))\/?/)?.[1] ??
80
- // filename;
81
- // if (matchName && !warnings.includes(matchName)) {
82
- // warnings.push(matchName);
83
- // console.warn(chalk.yellow.bold`warn `, matchName);
84
- // console.warn(
85
- // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`
86
- // );
87
- // }
88
- // }
89
- return results;
90
- }
91
- }
92
- throw new Error('no loader rule to handle file: ' + filename);
115
+ function createMultiRuleTransformer({
116
+ getRuleType,
117
+ rules
118
+ }) {
119
+ // const warnings: string[] = [];
120
+ return function transform(args) {
121
+ const {
122
+ filename,
123
+ options
124
+ } = args;
125
+ const OLD_BABEL_ENV = process.env.BABEL_ENV;
126
+ process.env.BABEL_ENV = options !== null && options !== void 0 && options.dev ? 'development' : process.env.BABEL_ENV || 'production';
127
+
128
+ try {
129
+ const ruleType = getRuleType(args);
130
+
131
+ for (const rule of rules) {
132
+ // optimization for checking node modules
133
+ if (rule.type && rule.type !== ruleType) {
134
+ continue;
93
135
  }
94
- finally {
95
- if (OLD_BABEL_ENV) {
96
- process.env.BABEL_ENV = OLD_BABEL_ENV;
97
- }
136
+
137
+ const isMatched = typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);
138
+
139
+ if (isMatched) {
140
+ const results = rule.transform(args); // @ts-ignore: Add extra property for testing
141
+
142
+ results._ruleName = rule.name; // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.
143
+
144
+ if (results.code && !results.ast) {
145
+ // Parse AST with babel otherwise Metro transformer will throw away the returned results.
146
+ results.ast = parseAst(options === null || options === void 0 ? void 0 : options.projectRoot, results.code);
147
+ } // TODO: Suboptimal warnings
148
+ // if (rule.warn) {
149
+ // const matchName =
150
+ // filename.match(/node_modules\/((:?@[\w\d-]+\/[\w\d-]+)|(:?[\w\d-]+))\/?/)?.[1] ??
151
+ // filename;
152
+ // if (matchName && !warnings.includes(matchName)) {
153
+ // warnings.push(matchName);
154
+ // console.warn(chalk.yellow.bold`warn `, matchName);
155
+ // console.warn(
156
+ // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`
157
+ // );
158
+ // }
159
+ // }
160
+
161
+
162
+ return results;
98
163
  }
99
- };
164
+ }
165
+
166
+ throw new Error('no loader rule to handle file: ' + filename);
167
+ } finally {
168
+ if (OLD_BABEL_ENV) {
169
+ process.env.BABEL_ENV = OLD_BABEL_ENV;
170
+ }
171
+ }
172
+ };
100
173
  }
101
- exports.createMultiRuleTransformer = createMultiRuleTransformer;
102
- exports.loaders = {
103
- // Perform the standard, and most expensive transpilation sequence.
104
- app(args) {
105
- debug('app:', args.filename);
106
- const { filename, options, src, plugins } = args;
107
- const babelConfig = {
108
- // ES modules require sourceType='module' but OSS may not always want that
109
- sourceType: 'unambiguous',
110
- ...(0, getBabelConfig_1.getBabelConfig)(filename, options, plugins),
111
- // Variables that are exposed to the user's babel preset.
112
- caller: {
113
- name: 'metro',
114
- platform: options.platform,
115
- },
116
- ast: true,
117
- };
118
- // Surface a warning function so babel linters can be used.
119
- Object.defineProperty(babelConfig.caller, 'onWarning', {
120
- enumerable: false,
121
- writable: false,
122
- value: (babelConfig.caller.onWarning = function (msg) {
123
- // Format the file path first so users know where the warning came from.
124
- console.warn(chalk_1.default.bold.yellow `warn ` + args.filename);
125
- console.warn(msg);
126
- }),
127
- });
128
- const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);
129
- const sourceAst = parseSync(src, babelConfig);
130
- // Should never happen.
131
- if (!sourceAst)
132
- return { ast: null };
133
- const result = transformFromAstSync(sourceAst, src, babelConfig);
134
- // TODO: Disable by default
135
- const functionMap = (0, generateFunctionMap_1.generateFunctionMap)(options.projectRoot, sourceAst, { filename });
136
- // The result from `transformFromAstSync` can be null (if the file is ignored)
137
- if (!result) {
138
- return { ast: null, functionMap };
139
- }
140
- return { ast: result.ast, functionMap };
141
- },
142
- // Transpile react-native with sucrase.
143
- reactNativeModule(args) {
144
- debug('rn:', args.filename);
145
- return sucrase(args, {
146
- transforms: ['jsx', 'flow', 'imports'],
147
- });
148
- },
149
- // Transpile expo modules with sucrase.
150
- expoModule(args) {
151
- debug('expo:', args.filename);
152
- // TODO: Fix all expo packages
153
- return sucrase(args, {
154
- transforms: [
155
- 'imports',
156
- // TODO: fix expo-processing, expo/vector-icons
157
- /(expo-processing|expo\/vector-icons)/.test(args.filename) && 'jsx',
158
- // TODO: fix expo-asset-utils
159
- /(expo-asset-utils)/.test(args.filename) && 'flow',
160
- ].filter(Boolean),
161
- });
162
- },
163
- // Transpile known community modules with the most expensive sucrase
164
- untranspiledModule(args) {
165
- debug('known issues:', args.filename);
166
- return sucrase(args, {
167
- transforms: getExpensiveSucraseTransforms(args.filename),
168
- });
169
- },
170
- // Pass all modules through without transpiling them.
171
- passthroughModule(args) {
172
- const { filename, options, src } = args;
173
- debug('passthrough:', filename);
174
- // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
175
- const ast = parseAst(options.projectRoot, src);
176
- // TODO: Disable by default
177
- const functionMap = (0, generateFunctionMap_1.generateFunctionMap)(options.projectRoot, ast, { filename });
178
- return {
179
- code: src,
180
- functionMap,
181
- ast,
182
- };
183
- },
174
+
175
+ const loaders = {
176
+ // Perform the standard, and most expensive transpilation sequence.
177
+ app(args) {
178
+ debug('app:', args.filename);
179
+ const {
180
+ filename,
181
+ options,
182
+ src,
183
+ plugins
184
+ } = args;
185
+ const babelConfig = {
186
+ // ES modules require sourceType='module' but OSS may not always want that
187
+ sourceType: 'unambiguous',
188
+ ...(0, _getBabelConfig().getBabelConfig)(filename, options, plugins),
189
+ // Variables that are exposed to the user's babel preset.
190
+ caller: {
191
+ name: 'metro',
192
+ platform: options.platform
193
+ },
194
+ ast: true
195
+ }; // Surface a warning function so babel linters can be used.
196
+
197
+ Object.defineProperty(babelConfig.caller, 'onWarning', {
198
+ enumerable: false,
199
+ writable: false,
200
+ value: babelConfig.caller.onWarning = function (msg) {
201
+ // Format the file path first so users know where the warning came from.
202
+ console.warn(_chalk().default.bold.yellow`warn ` + args.filename);
203
+ console.warn(msg);
204
+ }
205
+ });
206
+ const {
207
+ parseSync,
208
+ transformFromAstSync
209
+ } = getBabelCoreFromProject(options.projectRoot);
210
+ const sourceAst = parseSync(src, babelConfig); // Should never happen.
211
+
212
+ if (!sourceAst) return {
213
+ ast: null
214
+ };
215
+ const result = transformFromAstSync(sourceAst, src, babelConfig); // TODO: Disable by default
216
+
217
+ const functionMap = (0, _generateFunctionMap().generateFunctionMap)(options.projectRoot, sourceAst, {
218
+ filename
219
+ }); // The result from `transformFromAstSync` can be null (if the file is ignored)
220
+
221
+ if (!result) {
222
+ return {
223
+ ast: null,
224
+ functionMap
225
+ };
226
+ }
227
+
228
+ return {
229
+ ast: result.ast,
230
+ functionMap
231
+ };
232
+ },
233
+
234
+ // Transpile react-native with sucrase.
235
+ reactNativeModule(args) {
236
+ debug('rn:', args.filename);
237
+ return sucrase(args, {
238
+ transforms: ['jsx', 'flow', 'imports']
239
+ });
240
+ },
241
+
242
+ // Transpile expo modules with sucrase.
243
+ expoModule(args) {
244
+ debug('expo:', args.filename); // TODO: Fix all expo packages
245
+
246
+ return sucrase(args, {
247
+ transforms: ['imports', // TODO: fix expo-processing, expo/vector-icons
248
+ /(expo-processing|expo\/vector-icons)/.test(args.filename) && 'jsx', // TODO: fix expo-asset-utils
249
+ /(expo-asset-utils)/.test(args.filename) && 'flow'].filter(Boolean)
250
+ });
251
+ },
252
+
253
+ // Transpile known community modules with the most expensive sucrase
254
+ untranspiledModule(args) {
255
+ debug('known issues:', args.filename);
256
+ return sucrase(args, {
257
+ transforms: getExpensiveSucraseTransforms(args.filename)
258
+ });
259
+ },
260
+
261
+ // Pass all modules through without transpiling them.
262
+ passthroughModule(args) {
263
+ const {
264
+ filename,
265
+ options,
266
+ src
267
+ } = args;
268
+ debug('passthrough:', filename); // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
269
+
270
+ const ast = parseAst(options.projectRoot, src); // TODO: Disable by default
271
+
272
+ const functionMap = (0, _generateFunctionMap().generateFunctionMap)(options.projectRoot, ast, {
273
+ filename
274
+ });
275
+ return {
276
+ code: src,
277
+ functionMap,
278
+ ast
279
+ };
280
+ }
281
+
184
282
  };
283
+ exports.loaders = loaders;
185
284
  //# sourceMappingURL=createMultiRuleTransformer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMultiRuleTransformer.js","sourceRoot":"","sources":["../../src/transformer/createMultiRuleTransformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,kDAA0B;AAC1B,kDAA0B;AAE1B,gEAAuC;AAEvC,+DAA4D;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A8B;QAC9B,OAAO,OAAO,CAAC,IAAI,EAAE;YACnB,UAAU,EAAE;gBACV,SAAS;gBACT,+CAA+C;gBAC/C,sCAAsC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK;gBACnE,6BAA6B;gBAC7B,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM;aACnD,CAAC,MAAM,CAAC,OAAO,CAAa;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,oEAAoE;IACpE,kBAAkB,CAAC,IAAI;QACrB,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC,IAAI,EAAE;YACnB,UAAU,EAAE,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC;SACzD,CAAC,CAAC;IACL,CAAC;IAED,qDAAqD;IACrD,iBAAiB,CAAC,IAAI;QACpB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACxC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAEhC,iGAAiG;QACjG,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAE/C,2BAA2B;QAC3B,MAAM,WAAW,GAAG,IAAA,yCAAmB,EAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhF,OAAO;YACL,IAAI,EAAE,GAAG;YACT,WAAW;YACX,GAAG;SACJ,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"]}
1
+ {"version":3,"file":"createMultiRuleTransformer.js","names":["debug","Debug","babelCore","getBabelCoreFromProject","projectRoot","require","resolveFrom","babelParser","getBabelParserFromProject","sucrase","args","transforms","src","filename","options","dev","transform","results","filePath","production","code","functionMap","getExpensiveSucraseTransforms","test","parseAst","sourceCode","babylon","parse","sourceType","createMultiRuleTransformer","getRuleType","rules","OLD_BABEL_ENV","process","env","BABEL_ENV","ruleType","rule","type","isMatched","_ruleName","name","ast","Error","loaders","app","plugins","babelConfig","getBabelConfig","caller","platform","Object","defineProperty","enumerable","writable","value","onWarning","msg","console","warn","chalk","bold","yellow","parseSync","transformFromAstSync","sourceAst","result","generateFunctionMap","reactNativeModule","expoModule","filter","Boolean","untranspiledModule","passthroughModule"],"sources":["../../src/transformer/createMultiRuleTransformer.ts"],"sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\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OJ,OAAO,CAACC,IAAD,EAAO;MACnBC,UAAU,EAAE,CACV,SADU,EAEV;MACA,uCAAuCY,IAAvC,CAA4Cb,IAAI,CAACG,QAAjD,KAA8D,KAHpD,EAIV;MACA,qBAAqBU,IAArB,CAA0Bb,IAAI,CAACG,QAA/B,KAA4C,MALlC,EAMVyD,MANU,CAMHC,OANG;IADO,CAAP,CAAd;EASD,CArEyE;;EAuE1E;EACAC,kBAAkB,CAAC9D,IAAD,EAAO;IACvBV,KAAK,CAAC,eAAD,EAAkBU,IAAI,CAACG,QAAvB,CAAL;IACA,OAAOJ,OAAO,CAACC,IAAD,EAAO;MACnBC,UAAU,EAAEW,6BAA6B,CAACZ,IAAI,CAACG,QAAN;IADtB,CAAP,CAAd;EAGD,CA7EyE;;EA+E1E;EACA4D,iBAAiB,CAAC/D,IAAD,EAAO;IACtB,MAAM;MAAEG,QAAF;MAAYC,OAAZ;MAAqBF;IAArB,IAA6BF,IAAnC;IACAV,KAAK,CAAC,cAAD,EAAiBa,QAAjB,CAAL,CAFsB,CAItB;;IACA,MAAM6B,GAAG,GAAGlB,QAAQ,CAACV,OAAO,CAACV,WAAT,EAAsBQ,GAAtB,CAApB,CALsB,CAOtB;;IACA,MAAMS,WAAW,GAAG,IAAA8C,0CAAA,EAAoBrD,OAAO,CAACV,WAA5B,EAAyCsC,GAAzC,EAA8C;MAAE7B;IAAF,CAA9C,CAApB;IAEA,OAAO;MACLO,IAAI,EAAER,GADD;MAELS,WAFK;MAGLqB;IAHK,CAAP;EAKD;;AA/FyE,CAArE"}
@@ -1,30 +1,43 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFunctionMap = void 0;
4
- const importMetroFromProject_1 = require("../importMetroFromProject");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateFunctionMap = generateFunctionMap;
7
+
8
+ function _importMetroFromProject() {
9
+ const data = require("../importMetroFromProject");
10
+
11
+ _importMetroFromProject = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
5
18
  function generateFunctionMap(projectRoot, ast, context) {
6
- // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented
7
- // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.
8
- // The feature supposedly provides improved function names for anonymous functions, but we will opt towards
9
- // linting to prevent users from adding anonymous functions for important features like React components.
10
- //
11
- // Here is an example stack trace for a component that throws an error
12
- // in the root component (which is an anonymous function):
13
- //
14
- // Before:
15
- // - <anonymous> App.js:5:9
16
- // - renderApplication renderApplication.js:54:5
17
- // - runnables.appKey.run AppRegistry.js:117:26
18
- //
19
- // After:
20
- // - _default App.js:5:9
21
- // - renderApplication renderApplication.js:54:5
22
- // - run AppRegistry.js:117:26
23
- //
24
- if (process.env.EXPO_USE_FB_SOURCES) {
25
- return (0, importMetroFromProject_1.importMetroSourceMapFromProject)(projectRoot).generateFunctionMap(ast, context);
26
- }
27
- return null;
19
+ // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented
20
+ // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.
21
+ // The feature supposedly provides improved function names for anonymous functions, but we will opt towards
22
+ // linting to prevent users from adding anonymous functions for important features like React components.
23
+ //
24
+ // Here is an example stack trace for a component that throws an error
25
+ // in the root component (which is an anonymous function):
26
+ //
27
+ // Before:
28
+ // - <anonymous> App.js:5:9
29
+ // - renderApplication renderApplication.js:54:5
30
+ // - runnables.appKey.run AppRegistry.js:117:26
31
+ //
32
+ // After:
33
+ // - _default App.js:5:9
34
+ // - renderApplication renderApplication.js:54:5
35
+ // - run AppRegistry.js:117:26
36
+ //
37
+ if (process.env.EXPO_USE_FB_SOURCES) {
38
+ return (0, _importMetroFromProject().importMetroSourceMapFromProject)(projectRoot).generateFunctionMap(ast, context);
39
+ }
40
+
41
+ return null;
28
42
  }
29
- exports.generateFunctionMap = generateFunctionMap;
30
43
  //# sourceMappingURL=generateFunctionMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateFunctionMap.js","sourceRoot":"","sources":["../../src/transformer/generateFunctionMap.ts"],"names":[],"mappings":";;;AAEA,sEAA4E;AAE5E,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,GAAkD,EAClD,OAAsD;IAEtD,qGAAqG;IACrG,sGAAsG;IACtG,2GAA2G;IAC3G,yGAAyG;IACzG,EAAE;IACF,sEAAsE;IACtE,0DAA0D;IAC1D,EAAE;IACF,UAAU;IACV,2BAA2B;IAC3B,gDAAgD;IAChD,+CAA+C;IAC/C,EAAE;IACF,SAAS;IACT,wBAAwB;IACxB,gDAAgD;IAChD,8BAA8B;IAC9B,EAAE;IACF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;QACnC,OAAO,IAAA,wDAA+B,EAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACvF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AA3BD,kDA2BC","sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"]}
1
+ {"version":3,"file":"generateFunctionMap.js","names":["generateFunctionMap","projectRoot","ast","context","process","env","EXPO_USE_FB_SOURCES","importMetroSourceMapFromProject"],"sources":["../../src/transformer/generateFunctionMap.ts"],"sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"],"mappings":";;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,SAASA,mBAAT,CACLC,WADK,EAELC,GAFK,EAGLC,OAHK,EAI8C;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIC,OAAO,CAACC,GAAR,CAAYC,mBAAhB,EAAqC;IACnC,OAAO,IAAAC,yDAAA,EAAgCN,WAAhC,EAA6CD,mBAA7C,CAAiEE,GAAjE,EAAsEC,OAAtE,CAAP;EACD;;EACD,OAAO,IAAP;AACD"}