1- import path from "node:path" ;
2- import fse from "fs-extra" ;
31import chalk from "chalk" ;
2+ import fse from "fs-extra" ;
3+ import path from "node:path" ;
44
55const args = process . argv . slice ( 2 ) ;
66const tsc = process . env . CI || args . includes ( "--tsc" ) ;
@@ -9,6 +9,11 @@ const ROOT_DIR = process.cwd();
99const PACKAGES_PATH = path . join ( ROOT_DIR , "packages" ) ;
1010const DEFAULT_BUILD_PATH = path . join ( ROOT_DIR , "build" ) ;
1111
12+ // pnpm workspaces do not understand Deno projects and vice versa so we need to specify which projects need their node_modules updating
13+ const DENO_NODE_MODULES_PATHS = [
14+ path . join ( ROOT_DIR , "integration/helpers/vite-deno-template/node_modules" ) ,
15+ ] ;
16+
1217let activeOutputDir = DEFAULT_BUILD_PATH ;
1318if ( process . env . LOCAL_BUILD_DIRECTORY ) {
1419 let appDir = path . resolve ( process . env . LOCAL_BUILD_DIRECTORY ) ;
@@ -38,6 +43,8 @@ async function copyBuildToDist() {
3843 PACKAGES_PATH ,
3944 parentDir === "@remix-run" ? `remix-${ dirName } ` : dirName
4045 ) ,
46+ nodeModulesPath :
47+ parentDir === "@remix-run" ? `${ parentDir } /${ dirName } ` : dirName ,
4148 } ;
4249 } ) ;
4350
@@ -50,13 +57,35 @@ async function copyBuildToDist() {
5057 "node" ,
5158 "globals.d.ts"
5259 ) ;
53- console . log ( chalk . yellow ( ` 🛠 Writing globals.d.ts shim to ${ dest } ` ) ) ;
60+ console . log ( chalk . yellow ( ` 🛠 Writing globals.d.ts shim to ${ dest } ` ) ) ;
5461 await fse . writeFile ( dest , "export * from './dist/globals';" ) ;
5562
5663 /** @type {Promise<void>[] } */
5764 let copyQueue = [ ] ;
5865 for ( let pkg of packages ) {
5966 try {
67+ // Copy entire build artifact to node_modules dir for each Deno project that requires it
68+ for ( let denoNodeModulesPath of DENO_NODE_MODULES_PATHS ) {
69+ let destPath = path . join ( denoNodeModulesPath , pkg . nodeModulesPath ) ;
70+ if ( await fse . pathExists ( destPath ) ) {
71+ copyQueue . push (
72+ ( async ( ) => {
73+ console . log (
74+ chalk . yellow (
75+ ` 🛠 🦕 Copying ${ path . relative (
76+ ROOT_DIR ,
77+ pkg . build
78+ ) } to ${ path . relative ( ROOT_DIR , destPath ) } `
79+ )
80+ ) ;
81+ fse . copy ( pkg . build , destPath , {
82+ recursive : true ,
83+ } ) ;
84+ } ) ( )
85+ ) ;
86+ }
87+ }
88+
6089 let srcPath = path . join ( pkg . build , "dist" ) ;
6190 let destPath = path . join ( pkg . src , "dist" ) ;
6291 if ( ! ( await fse . stat ( srcPath ) ) . isDirectory ( ) ) {
@@ -66,7 +95,7 @@ async function copyBuildToDist() {
6695 ( async ( ) => {
6796 console . log (
6897 chalk . yellow (
69- ` 🛠 Copying ${ path . relative (
98+ ` 🛠 Copying ${ path . relative (
7099 ROOT_DIR ,
71100 srcPath
72101 ) } to ${ path . relative ( ROOT_DIR , destPath ) } `
@@ -117,7 +146,7 @@ async function copyBuildToDist() {
117146 ( async ( ) => {
118147 let src = path . relative ( ROOT_DIR , path . join ( ...srcFile . split ( "/" ) ) ) ;
119148 let dest = path . relative ( ROOT_DIR , path . join ( ...destFile . split ( "/" ) ) ) ;
120- console . log ( chalk . yellow ( ` 🛠 Copying ${ src } to ${ dest } ` ) ) ;
149+ console . log ( chalk . yellow ( ` 🛠 Copying ${ src } to ${ dest } ` ) ) ;
121150 await fse . copy ( src , dest ) ;
122151 } ) ( )
123152 )
@@ -126,7 +155,7 @@ async function copyBuildToDist() {
126155 await Promise . all ( copyQueue ) ;
127156 console . log (
128157 chalk . green (
129- " ✅ Successfully copied build files to package dist directories!"
158+ " ✅ Successfully copied build files to package dist directories!"
130159 )
131160 ) ;
132161}
0 commit comments