Skip to content

Commit 8231143

Browse files
committed
Don't nuke the examples directory skip copying already copied dirs
1 parent c3a8975 commit 8231143

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/node-addon-examples/scripts/copy-examples.mts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ const ALLOW_LIST = [
5151
];
5252

5353
console.log("Copying files to", EXAMPLES_DIR);
54+
5455
// Clean up the destination directory before copying
55-
fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true });
56+
// fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true });
5657

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

@@ -67,17 +68,28 @@ let counter = 0;
6768
for (const src of ALLOW_LIST) {
6869
const srcPath = path.join(SRC_DIR, src);
6970
const destPath = path.join(EXAMPLES_DIR, src);
71+
72+
const uniquePackageName = `example-${counter++}`;
73+
74+
if (fs.existsSync(destPath)) {
75+
console.warn(
76+
`Destination path ${destPath} already exists - skipping copy of ${src}.`
77+
);
78+
continue;
79+
}
80+
7081
console.log("Copying from", srcPath, "to", destPath);
7182
fs.cpSync(srcPath, destPath, { recursive: true });
72-
// Delete all package.json files recursively, as they have duplicate names, causing collisions when hashing
83+
// Update package names in package.json files recursively,
84+
// as they have duplicate names, causing collisions when vendored into the host package.
7385
for (const entry of fs.readdirSync(destPath, {
7486
withFileTypes: true,
7587
recursive: true,
7688
})) {
7789
if (entry.name === "package.json") {
7890
const packageJson = readPackageSync({ cwd: entry.parentPath });
7991
// Ensure example package names are unique
80-
packageJson.name = `example-${counter++}`;
92+
packageJson.name = uniquePackageName;
8193
fs.writeFileSync(
8294
path.join(entry.parentPath, entry.name),
8395
JSON.stringify(packageJson, null, 2),

0 commit comments

Comments
 (0)