@vxrn/vite-plugin-metro 1.2.8 → 1.2.10
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/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +35 -67
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.js +8 -32
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.js.map +2 -2
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +11 -45
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.cjs +5 -25
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.js +5 -27
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.js.map +1 -1
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +6 -41
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
- package/dist/cjs/plugins/metroPlugin.js.map +1 -1
- package/dist/cjs/plugins/metroPlugin.native.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.js +5 -22
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +30 -51
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +6 -29
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.js +5 -27
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.js.map +1 -1
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs +5 -25
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs.map +1 -1
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +6 -41
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
- package/dist/esm/plugins/metroPlugin.js.map +1 -1
- package/dist/esm/plugins/metroPlugin.mjs.map +1 -1
- package/dist/esm/plugins/metroPlugin.native.js.map +1 -1
- package/package.json +2 -3
- package/src/metro-config/getMetroConfigFromViteConfig.ts +7 -51
- package/src/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.ts +5 -65
- package/src/plugins/metroPlugin.ts +1 -22
- package/types/metro-config/getMetroConfigFromViteConfig.d.ts.map +1 -1
- package/types/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.d.ts.map +1 -1
- package/types/plugins/metroPlugin.d.ts +1 -22
- package/types/plugins/metroPlugin.d.ts.map +1 -1
- package/types/transformer/loadBabelConfig.d.ts +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ResolvedConfig } from 'vite'
|
|
2
|
-
import micromatch from 'micromatch'
|
|
3
2
|
|
|
4
3
|
// For Metro and Expo, we only import types here.
|
|
5
4
|
// We use `projectImport` to dynamically import the actual modules
|
|
@@ -21,8 +20,7 @@ export async function getMetroConfigFromViteConfig(
|
|
|
21
20
|
): Promise<MetroConfigExtended> {
|
|
22
21
|
const extraConfig: ExtraConfig = {}
|
|
23
22
|
const { root: projectRoot } = config
|
|
24
|
-
const { mainModuleName, argv, defaultConfigOverrides
|
|
25
|
-
metroPluginOptions
|
|
23
|
+
const { mainModuleName, argv, defaultConfigOverrides } = metroPluginOptions
|
|
26
24
|
|
|
27
25
|
const { loadConfig } = await projectImport<{
|
|
28
26
|
loadConfig: typeof loadConfigT
|
|
@@ -85,19 +83,11 @@ export async function getMetroConfigFromViteConfig(
|
|
|
85
83
|
..._defaultConfig,
|
|
86
84
|
resolver: {
|
|
87
85
|
..._defaultConfig?.resolver,
|
|
88
|
-
...(watchman !== undefined ? { useWatchman: watchman } : {}),
|
|
89
86
|
sourceExts: ['js', 'jsx', 'json', 'ts', 'tsx', 'mjs', 'cjs'], // `one` related packages are using `.mjs` extensions. This somehow fixes `.native` files not being resolved correctly when `.mjs` files are present.
|
|
90
87
|
resolveRequest: (context, moduleName, platform) => {
|
|
91
88
|
const origResolveRequestFn =
|
|
92
89
|
_defaultConfig?.resolver?.resolveRequest || context.resolveRequest
|
|
93
90
|
|
|
94
|
-
// Handle excludeModules - resolve excluded modules to empty module using glob patterns
|
|
95
|
-
if (excludeModules && excludeModules.length > 0) {
|
|
96
|
-
if (micromatch.isMatch(moduleName, excludeModules)) {
|
|
97
|
-
return origResolveRequestFn(context, '@vxrn/vite-plugin-metro/empty', platform)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
91
|
// HACK: Do not assert the "import" condition for `@babel/runtime`. This
|
|
102
92
|
// is a workaround for ESM <-> CJS interop, as we need the CJS versions of
|
|
103
93
|
// `@babel/runtime` helpers.
|
|
@@ -132,45 +122,6 @@ export async function getMetroConfigFromViteConfig(
|
|
|
132
122
|
reporter: await getTerminalReporter(projectRoot),
|
|
133
123
|
}
|
|
134
124
|
|
|
135
|
-
// Apply user's defaultConfigOverrides to get the final config with user's custom resolveRequest
|
|
136
|
-
const userConfig =
|
|
137
|
-
typeof defaultConfigOverrides === 'function'
|
|
138
|
-
? defaultConfigOverrides(defaultConfig)
|
|
139
|
-
: defaultConfigOverrides
|
|
140
|
-
|
|
141
|
-
// Get the user's custom resolveRequest if they provided one
|
|
142
|
-
const userResolveRequest = userConfig?.resolver?.resolveRequest
|
|
143
|
-
|
|
144
|
-
// Build the final config, wrapping resolveRequest to handle excludeModules
|
|
145
|
-
const finalConfig: MetroInputConfig = {
|
|
146
|
-
...defaultConfig,
|
|
147
|
-
...userConfig,
|
|
148
|
-
resolver: {
|
|
149
|
-
...defaultConfig.resolver,
|
|
150
|
-
...userConfig?.resolver,
|
|
151
|
-
resolveRequest: (context, moduleName, platform) => {
|
|
152
|
-
const origResolveRequestFn =
|
|
153
|
-
_defaultConfig?.resolver?.resolveRequest || context.resolveRequest
|
|
154
|
-
|
|
155
|
-
// Handle excludeModules first - resolve excluded modules to empty module using glob patterns
|
|
156
|
-
if (excludeModules && excludeModules.length > 0) {
|
|
157
|
-
if (micromatch.isMatch(moduleName, excludeModules)) {
|
|
158
|
-
return origResolveRequestFn(context, '@vxrn/vite-plugin-metro/empty', platform)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// If user provided their own resolveRequest, use it
|
|
163
|
-
if (userResolveRequest) {
|
|
164
|
-
return userResolveRequest(context, moduleName, platform)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Otherwise use the default logic
|
|
168
|
-
const defaultResolveRequestFn = defaultConfig.resolver!.resolveRequest!
|
|
169
|
-
return defaultResolveRequestFn(context, moduleName, platform)
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
}
|
|
173
|
-
|
|
174
125
|
const metroConfig = await loadConfig(
|
|
175
126
|
{
|
|
176
127
|
cwd: projectRoot,
|
|
@@ -178,7 +129,12 @@ export async function getMetroConfigFromViteConfig(
|
|
|
178
129
|
'reset-cache': !!process.env.METRO_RESET_CACHE, // TODO: `--clean`
|
|
179
130
|
...argv,
|
|
180
131
|
},
|
|
181
|
-
|
|
132
|
+
{
|
|
133
|
+
...defaultConfig,
|
|
134
|
+
...(typeof defaultConfigOverrides === 'function'
|
|
135
|
+
? defaultConfigOverrides(defaultConfig)
|
|
136
|
+
: defaultConfigOverrides),
|
|
137
|
+
}
|
|
182
138
|
)
|
|
183
139
|
|
|
184
140
|
// @ts-expect-error TODO
|
|
@@ -5,68 +5,6 @@ import type { MetroPluginOptions } from '../plugins/metroPlugin'
|
|
|
5
5
|
import type { ViteCustomTransformOptions } from '../transformer/types'
|
|
6
6
|
import { getMetroBabelConfigFromViteConfig } from './getMetroBabelConfigFromViteConfig'
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Deep merges babel configs, properly handling arrays like plugins and presets
|
|
10
|
-
*/
|
|
11
|
-
function deepMergeBabelConfig(
|
|
12
|
-
base: TransformOptions,
|
|
13
|
-
override: TransformOptions | undefined
|
|
14
|
-
): TransformOptions {
|
|
15
|
-
if (!override) return base
|
|
16
|
-
|
|
17
|
-
const merged: TransformOptions = {
|
|
18
|
-
...base,
|
|
19
|
-
...override,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Deep merge plugins - concatenate arrays
|
|
23
|
-
if (base.plugins || override.plugins) {
|
|
24
|
-
merged.plugins = [...(base.plugins || []), ...(override.plugins || [])]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Deep merge presets - concatenate arrays
|
|
28
|
-
if (base.presets || override.presets) {
|
|
29
|
-
merged.presets = [...(base.presets || []), ...(override.presets || [])]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Deep merge env if both exist
|
|
33
|
-
if (base.env && override.env) {
|
|
34
|
-
merged.env = { ...base.env }
|
|
35
|
-
for (const [key, value] of Object.entries(override.env)) {
|
|
36
|
-
if (value) {
|
|
37
|
-
merged.env[key] = deepMergeBabelConfig(base.env[key] || {}, value)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Deep merge parserOpts if both exist
|
|
43
|
-
if (base.parserOpts && override.parserOpts) {
|
|
44
|
-
merged.parserOpts = {
|
|
45
|
-
...base.parserOpts,
|
|
46
|
-
...override.parserOpts,
|
|
47
|
-
// Merge plugins arrays if both exist
|
|
48
|
-
...(base.parserOpts.plugins || override.parserOpts.plugins
|
|
49
|
-
? {
|
|
50
|
-
plugins: [
|
|
51
|
-
...(base.parserOpts.plugins || []),
|
|
52
|
-
...(override.parserOpts.plugins || []),
|
|
53
|
-
],
|
|
54
|
-
}
|
|
55
|
-
: {}),
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Deep merge generatorOpts if both exist
|
|
60
|
-
if (base.generatorOpts && override.generatorOpts) {
|
|
61
|
-
merged.generatorOpts = {
|
|
62
|
-
...base.generatorOpts,
|
|
63
|
-
...override.generatorOpts,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return merged
|
|
68
|
-
}
|
|
69
|
-
|
|
70
8
|
export function patchMetroServerWithViteConfigAndMetroPluginOptions(
|
|
71
9
|
metroServer: Server,
|
|
72
10
|
config: ResolvedConfig,
|
|
@@ -85,10 +23,12 @@ export function patchMetroServerWithViteConfigAndMetroPluginOptions(
|
|
|
85
23
|
transformOptions: Parameters<typeof originalTransformFile>[1],
|
|
86
24
|
fileBuffer?: Parameters<typeof originalTransformFile>[2]
|
|
87
25
|
) => {
|
|
88
|
-
|
|
89
|
-
|
|
26
|
+
let babelConfig: TransformOptions = {
|
|
27
|
+
...defaultBabelConfig,
|
|
28
|
+
...options.babelConfig,
|
|
29
|
+
plugins: [...(defaultBabelConfig.plugins || []), ...(options.babelConfig?.plugins || [])],
|
|
30
|
+
}
|
|
90
31
|
|
|
91
|
-
// Apply babelConfigOverrides for full control
|
|
92
32
|
if (options.babelConfigOverrides) {
|
|
93
33
|
babelConfig = options.babelConfigOverrides(babelConfig)
|
|
94
34
|
}
|
|
@@ -26,29 +26,8 @@ export type MetroPluginOptions = {
|
|
|
26
26
|
defaultConfigOverrides?:
|
|
27
27
|
| MetroInputConfig
|
|
28
28
|
| ((defaultConfig: MetroInputConfig) => MetroInputConfig)
|
|
29
|
-
/**
|
|
30
|
-
* Shorthand for setting `useWatchman` in Metro's resolver config.
|
|
31
|
-
* When true, enables Watchman for file watching. When false, disables it.
|
|
32
|
-
*/
|
|
33
|
-
watchman?: boolean
|
|
34
|
-
/**
|
|
35
|
-
* Array of module names or glob patterns that should be resolved to an empty module.
|
|
36
|
-
* This is useful for excluding modules that break the React Native build.
|
|
37
|
-
*
|
|
38
|
-
* Supports glob patterns via micromatch:
|
|
39
|
-
* - Exact match: `'jsonwebtoken'`
|
|
40
|
-
* - Wildcard: `'@aws-sdk/*'`
|
|
41
|
-
* - Multiple wildcards: `'@aws-sdk/**'`
|
|
42
|
-
*
|
|
43
|
-
* Example: `['node:http2', 'jsonwebtoken', '@aws-sdk/*']`
|
|
44
|
-
*/
|
|
45
|
-
excludeModules?: string[]
|
|
46
|
-
/**
|
|
47
|
-
* Babel configuration that will be deep merged with the default config.
|
|
48
|
-
* This is a more convenient alternative to babelConfigOverrides.
|
|
49
|
-
*/
|
|
29
|
+
/** Consider using babelConfigOverrides instead */
|
|
50
30
|
babelConfig?: TransformOptions
|
|
51
|
-
/** Advanced: Use this for full control over babel config merging */
|
|
52
31
|
babelConfigOverrides?: (defaultConfig: TransformOptions) => TransformOptions
|
|
53
32
|
/**
|
|
54
33
|
* Overrides the main module name which is normally defined as the `main` field in `package.json`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMetroConfigFromViteConfig.d.ts","sourceRoot":"","sources":["../../src/metro-config/getMetroConfigFromViteConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"getMetroConfigFromViteConfig.d.ts","sourceRoot":"","sources":["../../src/metro-config/getMetroConfigFromViteConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAW1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAI/D,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,cAAc,EACtB,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAAC,mBAAmB,CAAC,CA6H9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patchMetroServerWithViteConfigAndMetroPluginOptions.d.ts","sourceRoot":"","sources":["../../src/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"patchMetroServerWithViteConfigAndMetroPluginOptions.d.ts","sourceRoot":"","sources":["../../src/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAIhE,wBAAgB,mDAAmD,CACjE,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,kBAAkB,QA0C5B"}
|
|
@@ -6,29 +6,8 @@ type MetroInputConfig = Parameters<typeof loadConfigT>[1];
|
|
|
6
6
|
export type MetroPluginOptions = {
|
|
7
7
|
argv?: MetroYargArguments;
|
|
8
8
|
defaultConfigOverrides?: MetroInputConfig | ((defaultConfig: MetroInputConfig) => MetroInputConfig);
|
|
9
|
-
/**
|
|
10
|
-
* Shorthand for setting `useWatchman` in Metro's resolver config.
|
|
11
|
-
* When true, enables Watchman for file watching. When false, disables it.
|
|
12
|
-
*/
|
|
13
|
-
watchman?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Array of module names or glob patterns that should be resolved to an empty module.
|
|
16
|
-
* This is useful for excluding modules that break the React Native build.
|
|
17
|
-
*
|
|
18
|
-
* Supports glob patterns via micromatch:
|
|
19
|
-
* - Exact match: `'jsonwebtoken'`
|
|
20
|
-
* - Wildcard: `'@aws-sdk/*'`
|
|
21
|
-
* - Multiple wildcards: `'@aws-sdk/**'`
|
|
22
|
-
*
|
|
23
|
-
* Example: `['node:http2', 'jsonwebtoken', '@aws-sdk/*']`
|
|
24
|
-
*/
|
|
25
|
-
excludeModules?: string[];
|
|
26
|
-
/**
|
|
27
|
-
* Babel configuration that will be deep merged with the default config.
|
|
28
|
-
* This is a more convenient alternative to babelConfigOverrides.
|
|
29
|
-
*/
|
|
9
|
+
/** Consider using babelConfigOverrides instead */
|
|
30
10
|
babelConfig?: TransformOptions;
|
|
31
|
-
/** Advanced: Use this for full control over babel config merging */
|
|
32
11
|
babelConfigOverrides?: (defaultConfig: TransformOptions) => TransformOptions;
|
|
33
12
|
/**
|
|
34
13
|
* Overrides the main module name which is normally defined as the `main` field in `package.json`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metroPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/metroPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAOxC,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,OAAO,CAAA;AAMtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAIjE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,sBAAsB,CAAC,EACnB,gBAAgB,GAChB,CAAC,CAAC,aAAa,EAAE,gBAAgB,KAAK,gBAAgB,CAAC,CAAA;IAC3D
|
|
1
|
+
{"version":3,"file":"metroPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/metroPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAOxC,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,OAAO,CAAA;AAMtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAIjE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,sBAAsB,CAAC,EACnB,gBAAgB,GAChB,CAAC,CAAC,aAAa,EAAE,gBAAgB,KAAK,gBAAgB,CAAC,CAAA;IAC3D,kDAAkD;IAClD,WAAW,CAAC,EAAE,gBAAgB,CAAA;IAC9B,oBAAoB,CAAC,EAAE,CAAC,aAAa,EAAE,gBAAgB,KAAK,gBAAgB,CAAA;IAC5E;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,YAAY,CAgJ1E"}
|
|
@@ -6,5 +6,5 @@ import type { TransformOptions } from './babel-core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const loadBabelConfig: ({ projectRoot }: {
|
|
8
8
|
projectRoot: string;
|
|
9
|
-
}) => Pick<TransformOptions, "
|
|
9
|
+
}) => Pick<TransformOptions, "extends" | "presets">;
|
|
10
10
|
//# sourceMappingURL=loadBabelConfig.d.ts.map
|