Skip to content

Commit e5654c8

Browse files
authoredOct 4, 2023
bugfix(react-native): watch entire workspace (#19432)
1 parent 2d12daf commit e5654c8

File tree

6 files changed

+24
-38
lines changed

6 files changed

+24
-38
lines changed
 

‎packages/expo/plugins/metro-resolver.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ function tsconfigPathsResolver(
133133
platform: string,
134134
debug: boolean
135135
) {
136-
const tsConfigPathMatcher = getMatcher(debug);
137-
const match = tsConfigPathMatcher(
138-
realModuleName,
139-
undefined,
140-
undefined,
141-
extensions.map((ext) => `.${ext}`)
142-
);
143-
144-
if (match) {
136+
try {
137+
const tsConfigPathMatcher = getMatcher(debug);
138+
const match = tsConfigPathMatcher(
139+
realModuleName,
140+
undefined,
141+
undefined,
142+
extensions.map((ext) => `.${ext}`)
143+
);
145144
return metroResolver.resolve(context, match, platform);
146-
} else {
145+
} catch {
147146
if (debug) {
148147
console.log(
149148
chalk.red(`[Nx] Failed to resolve ${chalk.bold(realModuleName)}`)

‎packages/expo/plugins/with-nx-metro.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { workspaceLayout, workspaceRoot } from '@nx/devkit';
1+
import { workspaceRoot } from '@nx/devkit';
22
import { mergeConfig } from 'metro-config';
33
import type { MetroConfig } from 'metro-config';
4-
import { join } from 'path';
54
import { existsSync } from 'fs-extra';
65

76
import { getResolveRequest } from './metro-resolver';
@@ -24,12 +23,7 @@ export async function withNxMetro(
2423
if (opts.debug) process.env.NX_REACT_NATIVE_DEBUG = 'true';
2524
if (opts.extensions) extensions.push(...opts.extensions);
2625

27-
let watchFolders = [
28-
join(workspaceRoot, 'node_modules'),
29-
join(workspaceRoot, workspaceLayout().libsDir),
30-
join(workspaceRoot, 'packages'),
31-
join(workspaceRoot, '.storybook'),
32-
];
26+
let watchFolders = [workspaceRoot];
3327
if (opts.watchFolders?.length) {
3428
watchFolders = watchFolders.concat(opts.watchFolders);
3529
}

‎packages/expo/src/generators/application/files/metro.config.js.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const customConfig = {
2121
sourceExts: [...sourceExts, 'svg'],
2222
blockList: exclusionList([/^(?!.*node_modules).*\/dist\/.*/]),
2323
unstable_enableSymlinks: true,
24-
unstable_enablePackageExports: true,
24+
// unstable_enablePackageExports: true,
2525
},
2626
};
2727

‎packages/react-native/plugins/metro-resolver.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ function tsconfigPathsResolver(
133133
platform: string,
134134
debug: boolean
135135
) {
136-
const tsConfigPathMatcher = getMatcher(debug);
137-
const match = tsConfigPathMatcher(
138-
realModuleName,
139-
undefined,
140-
undefined,
141-
extensions.map((ext) => `.${ext}`)
142-
);
143-
144-
if (match) {
136+
try {
137+
const tsConfigPathMatcher = getMatcher(debug);
138+
const match = tsConfigPathMatcher(
139+
realModuleName,
140+
undefined,
141+
undefined,
142+
extensions.map((ext) => `.${ext}`)
143+
);
145144
return metroResolver.resolve(context, match, platform);
146-
} else {
145+
} catch {
147146
if (debug) {
148147
console.log(
149148
chalk.red(`[Nx] Failed to resolve ${chalk.bold(realModuleName)}`)

‎packages/react-native/plugins/with-nx-metro.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { workspaceLayout, workspaceRoot } from '@nx/devkit';
1+
import { workspaceRoot } from '@nx/devkit';
22
import { mergeConfig } from 'metro-config';
33
import type { MetroConfig } from 'metro-config';
4-
import { join } from 'path';
54
import { existsSync } from 'fs-extra';
65

76
import { getResolveRequest } from './metro-resolver';
@@ -24,12 +23,7 @@ export async function withNxMetro(
2423
if (opts.debug) process.env.NX_REACT_NATIVE_DEBUG = 'true';
2524
if (opts.extensions) extensions.push(...opts.extensions);
2625

27-
let watchFolders = [
28-
join(workspaceRoot, 'node_modules'),
29-
join(workspaceRoot, workspaceLayout().libsDir),
30-
join(workspaceRoot, 'packages'),
31-
join(workspaceRoot, '.storybook'),
32-
];
26+
let watchFolders = [workspaceRoot];
3327
if (opts.watchFolders?.length) {
3428
watchFolders = watchFolders.concat(opts.watchFolders);
3529
}

‎packages/react-native/src/generators/application/files/app/metro.config.js.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const customConfig = {
2020
sourceExts: [...sourceExts, 'svg'],
2121
blockList: exclusionList([/^(?!.*node_modules).*\/dist\/.*/]),
2222
unstable_enableSymlinks: true,
23-
unstable_enablePackageExports: true,
23+
// unstable_enablePackageExports: true,
2424
},
2525
};
2626

0 commit comments

Comments
 (0)
Please sign in to comment.