diff --git a/package.json b/package.json index e26c00e4..416b119a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "clean": "tsc --build --clean", "dev": "tsc --build --watch", "lint": "eslint .", - "test": "npm run test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples" + "test": "npm run test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples", + "bootstrap": "npm run build && npm run bootstrap --workspaces --if-present" }, "author": { "name": "Callstack", diff --git a/packages/host/package.json b/packages/host/package.json index 6652e9ec..510eecc4 100644 --- a/packages/host/package.json +++ b/packages/host/package.json @@ -44,7 +44,8 @@ "generate-weak-node-api": "tsx scripts/generate-weak-node-api.ts", "generate-weak-node-api-injector": "tsx scripts/generate-weak-node-api-injector.ts", "build-weak-node-api": "npm run generate-weak-node-api && cmake-rn --android --apple --no-auto-link --no-weak-node-api-linkage --xcframework-extension --source ./weak-node-api", - "test": "tsx --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout src/node/**/*.test.ts src/node/*.test.ts" + "test": "tsx --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout src/node/**/*.test.ts src/node/*.test.ts", + "bootstrap": "npm run copy-node-api-headers && npm run generate-weak-node-api-injector && npm run build-weak-node-api" }, "keywords": [ "react-native", diff --git a/packages/node-addon-examples/package.json b/packages/node-addon-examples/package.json index 1863b785..4700be7e 100644 --- a/packages/node-addon-examples/package.json +++ b/packages/node-addon-examples/package.json @@ -13,7 +13,8 @@ "build": "tsx scripts/build-examples.mts", "copy-and-build": "npm run copy-examples && npm run gyp-to-cmake && npm run build", "verify": "tsx scripts/verify-prebuilds.mts", - "test": "npm run copy-and-build && npm run verify" + "test": "npm run copy-and-build && npm run verify", + "bootstrap": "npm run copy-and-build" }, "devDependencies": { "cmake-rn": "*", diff --git a/packages/node-addon-examples/scripts/copy-examples.mts b/packages/node-addon-examples/scripts/copy-examples.mts index 43dfd205..426f07dd 100644 --- a/packages/node-addon-examples/scripts/copy-examples.mts +++ b/packages/node-addon-examples/scripts/copy-examples.mts @@ -51,8 +51,9 @@ const ALLOW_LIST = [ ]; console.log("Copying files to", EXAMPLES_DIR); + // Clean up the destination directory before copying -fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true }); +// fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true }); const require = createRequire(import.meta.url); @@ -67,9 +68,20 @@ let counter = 0; for (const src of ALLOW_LIST) { const srcPath = path.join(SRC_DIR, src); const destPath = path.join(EXAMPLES_DIR, src); + + const uniquePackageName = `example-${counter++}`; + + if (fs.existsSync(destPath)) { + console.warn( + `Destination path ${destPath} already exists - skipping copy of ${src}.` + ); + continue; + } + console.log("Copying from", srcPath, "to", destPath); fs.cpSync(srcPath, destPath, { recursive: true }); - // Delete all package.json files recursively, as they have duplicate names, causing collisions when hashing + // Update package names in package.json files recursively, + // as they have duplicate names, causing collisions when vendored into the host package. for (const entry of fs.readdirSync(destPath, { withFileTypes: true, recursive: true, @@ -77,7 +89,7 @@ for (const src of ALLOW_LIST) { if (entry.name === "package.json") { const packageJson = readPackageSync({ cwd: entry.parentPath }); // Ensure example package names are unique - packageJson.name = `example-${counter++}`; + packageJson.name = uniquePackageName; fs.writeFileSync( path.join(entry.parentPath, entry.name), JSON.stringify(packageJson, null, 2),