11import { spawn } from 'child_process' ;
2- import { dirname , join , resolve } from 'path' ;
2+ import { dirname , join , normalize , resolve , sep } from 'path' ;
33import { Consola } from 'consola' ;
44import { DepGraph } from 'dependency-graph' ;
55import fse from 'fs-extra' ;
@@ -50,7 +50,7 @@ export const runifyCommand = createCommand<
5050 const isSinglePackage = Array . isArray ( rootPackageJSON . workspaces ) === false ;
5151
5252 if ( isSinglePackage ) {
53- return runify ( join ( process . cwd ( ) , 'package.json' ) , reporter ) ;
53+ return runify ( normalize ( join ( process . cwd ( ) , 'package.json' ) ) , reporter ) ;
5454 }
5555
5656 const limit = pLimit ( 1 ) ;
@@ -104,7 +104,7 @@ export const runifyCommand = createCommand<
104104} ) ;
105105
106106async function runify ( packagePath : string , reporter : Consola ) {
107- const cwd = packagePath . replace ( '/ package.json' , '' ) ;
107+ const cwd = packagePath . replace ( ` ${ sep } package.json` , '' ) ;
108108 const pkg = await readPackageJson ( cwd ) ;
109109 const buildOptions : BuildOptions = pkg . buildOptions || { } ;
110110
@@ -172,7 +172,7 @@ async function rewritePackageJson(
172172 newPkg = modify ( newPkg ) ;
173173 }
174174
175- await fs . writeFile ( join ( cwd , 'dist/ package.json' ) , JSON . stringify ( newPkg , null , 2 ) , {
175+ await fs . writeFile ( join ( cwd , 'dist' , ' package.json') , JSON . stringify ( newPkg , null , 2 ) , {
176176 encoding : 'utf-8' ,
177177 } ) ;
178178}
@@ -191,11 +191,11 @@ async function buildNext(cwd: string, additionalRequire: string | null) {
191191 child . on ( 'error' , reject ) ;
192192 } ) ;
193193
194- await fs . mkdirp ( join ( cwd , 'dist' ) ) ;
194+ await fs . mkdirp ( normalize ( join ( cwd , 'dist' ) ) ) ;
195195 if ( additionalRequire ) {
196196 await tsup ( {
197- entryPoints : [ join ( cwd , additionalRequire ) ] ,
198- outDir : join ( cwd , 'dist' ) ,
197+ entryPoints : [ normalize ( join ( cwd , additionalRequire ) ) ] ,
198+ outDir : normalize ( join ( cwd , 'dist' ) ) ,
199199 target : 'node18' ,
200200 format : [ 'cjs' ] ,
201201 splitting : false ,
@@ -246,10 +246,10 @@ async function compile(
246246 useEsm = false ,
247247) {
248248 if ( buildOptions . tsup ) {
249- const out = join ( cwd , 'dist' ) ;
249+ const out = normalize ( join ( cwd , 'dist' ) ) ;
250250
251251 await tsup ( {
252- entryPoints : [ join ( cwd , entryPoint ) ] ,
252+ entryPoints : [ normalize ( join ( cwd , entryPoint ) ) ] ,
253253 outDir : out ,
254254 target : 'node18' ,
255255 format : [ useEsm ? 'esm' : 'cjs' ] ,
@@ -264,29 +264,29 @@ async function compile(
264264 ? {
265265 js :
266266 buildOptions . banner . includes ( '.js' ) || buildOptions . banner . includes ( '.mjs' )
267- ? await fs . readFile ( join ( cwd , buildOptions . banner ) , 'utf-8' )
267+ ? await fs . readFile ( normalize ( join ( cwd , buildOptions . banner ) ) , 'utf-8' )
268268 : buildOptions . banner ,
269269 }
270270 : { } ,
271271 } ) ;
272272 return ;
273273 }
274274
275- const { code, map, assets } = await ncc ( join ( cwd , entryPoint ) , {
275+ const { code, map, assets } = await ncc ( normalize ( join ( cwd , entryPoint ) ) , {
276276 cache : false ,
277277 sourceMap : true ,
278278 } ) ;
279279
280280 await fs . mkdirp ( join ( cwd , 'dist' ) ) ;
281281 await Promise . all ( [
282- fs . writeFile ( join ( cwd , 'dist/ index.js' ) , code , 'utf8' ) ,
283- fs . writeFile ( join ( cwd , 'dist/ index.js.map' ) , map , 'utf8' ) ,
282+ fs . writeFile ( join ( cwd , 'dist' , ' index.js') , code , 'utf8' ) ,
283+ fs . writeFile ( join ( cwd , 'dist' , ' index.js.map') , map , 'utf8' ) ,
284284 ...Object . keys ( assets ) . map ( async filepath => {
285285 if ( filepath . endsWith ( 'package.json' ) ) {
286286 return ;
287287 }
288- await fs . ensureDir ( dirname ( join ( cwd , 'dist' , filepath ) ) , { } ) ;
289- await fs . writeFile ( join ( cwd , 'dist' , filepath ) , assets [ filepath ] . source ) ;
288+ await fs . ensureDir ( dirname ( normalize ( join ( cwd , 'dist' , filepath ) ) ) , { } ) ;
289+ await fs . writeFile ( normalize ( join ( cwd , 'dist' , filepath ) ) , assets [ filepath ] . source ) ;
290290 } ) ,
291291 ] ) ;
292292}
0 commit comments