@@ -51,8 +51,9 @@ const ALLOW_LIST = [
5151] ;
5252
5353console . 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
5758const require = createRequire ( import . meta. url ) ;
5859
@@ -67,17 +68,28 @@ let counter = 0;
6768for ( 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