Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add npm run bootstrap in the multi-platform CI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once #118 merge I believe.
I will do that in a follow-up PR.

},
"author": {
"name": "Callstack",
Expand Down
3 changes: 2 additions & 1 deletion packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/node-addon-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
18 changes: 15 additions & 3 deletions packages/node-addon-examples/scripts/copy-examples.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to leave this commented out line in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I might regret that, but for now it seems most appropriate. It does mean that someone disabling an example above would have to manually delete the dir, but the benefit is that we're not nuking the build directories.


const require = createRequire(import.meta.url);

Expand All @@ -67,17 +68,28 @@ 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,
})) {
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),
Expand Down
Loading