Skip to content

Commit bd42182

Browse files
committed
Using regular linking for monorepo deps
1 parent cb93534 commit bd42182

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

scripts/init-macos-test-app.ts

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ async function initializeReactNativeTemplate() {
4141
]);
4242

4343
// Clean up
44-
const CLEANUP_PATHS = ["ios", "android", "__tests__"];
44+
const CLEANUP_PATHS = [
45+
"ios",
46+
"android",
47+
"__tests__",
48+
".prettierrc.js",
49+
".gitignore",
50+
];
4551

4652
for (const cleanupPath of CLEANUP_PATHS) {
4753
await fs.promises.rm(path.join(APP_PATH, cleanupPath), {
@@ -71,18 +77,37 @@ async function patchPackageJson() {
7177
"MOCHA_REMOTE_CONTEXT=ferricExample node --run test -- ",
7278
};
7379

74-
const {
75-
"mocha-remote-cli": mochaRemoteCliSpec,
76-
"mocha-remote-react-native": mochaRemoteReactNativeSpec,
77-
} = otherPackageJson.dependencies || {};
80+
const transferredDependencies = new Set([
81+
"@rnx-kit/metro-config",
82+
"mocha-remote-cli",
83+
"mocha-remote-react-native",
84+
]);
7885

79-
assert(typeof mochaRemoteCliSpec === "string");
80-
assert(typeof mochaRemoteReactNativeSpec === "string");
86+
const { dependencies: otherDependencies = {} } = otherPackageJson;
8187

8288
packageJson.dependencies = {
83-
["mocha-remote-cli"]: mochaRemoteCliSpec,
84-
["mocha-remote-react-native"]: mochaRemoteReactNativeSpec,
85-
...packageJson.dependencies,
89+
"react-native-macos-init": "^2.1.3",
90+
"@react-native-node-api/node-addon-examples": path.relative(
91+
APP_PATH,
92+
path.join(ROOT_PATH, "packages", "node-addon-examples"),
93+
),
94+
"@react-native-node-api/node-tests": path.relative(
95+
APP_PATH,
96+
path.join(ROOT_PATH, "packages", "node-tests"),
97+
),
98+
"@react-native-node-api/ferric-example": path.relative(
99+
APP_PATH,
100+
path.join(ROOT_PATH, "packages", "ferric-example"),
101+
),
102+
"react-native-node-api": path.relative(
103+
APP_PATH,
104+
path.join(ROOT_PATH, "packages", "host"),
105+
),
106+
...Object.fromEntries(
107+
Object.entries(otherDependencies).filter(([name]) =>
108+
transferredDependencies.has(name),
109+
),
110+
),
86111
};
87112

88113
await fs.promises.writeFile(
@@ -94,29 +119,9 @@ async function patchPackageJson() {
94119

95120
function installDependencies() {
96121
console.log("Installing dependencies");
97-
exec(
98-
"npm",
99-
[
100-
"install",
101-
"--save",
102-
"--prefer-offline",
103-
"--install-links",
104-
"react-native-macos-init",
105-
path.relative(
106-
APP_PATH,
107-
path.join(ROOT_PATH, "packages", "node-addon-examples"),
108-
),
109-
path.relative(APP_PATH, path.join(ROOT_PATH, "packages", "node-tests")),
110-
path.relative(
111-
APP_PATH,
112-
path.join(ROOT_PATH, "packages", "ferric-example"),
113-
),
114-
path.relative(APP_PATH, path.join(ROOT_PATH, "packages", "host")),
115-
],
116-
{
117-
cwd: APP_PATH,
118-
},
119-
);
122+
exec("npm", ["install", "--prefer-offline"], {
123+
cwd: APP_PATH,
124+
});
120125
}
121126

122127
function initializeReactNativeMacOSTemplate() {
@@ -155,7 +160,13 @@ async function patchPodfile() {
155160

156161
async function copySourceFiles() {
157162
console.log("Copying source files from test-app into macos-test-app:");
158-
const FILE_NAMES = ["App.tsx", "babel.config.js"];
163+
const FILE_NAMES = [
164+
"App.tsx",
165+
// Adds the babel plugin needed to transform require calls
166+
"babel.config.js",
167+
// Adds the ability to reference symlinked packages
168+
"metro.config.js",
169+
];
159170
for (const fileName of FILE_NAMES) {
160171
console.log(`↳ ${fileName}`);
161172
await fs.promises.copyFile(

0 commit comments

Comments
 (0)