11const { mkdir, readdir, rename, rm, writeFile, copyFile, readFile, unlink, move} = require ( 'fs-extra' )
22const path = require ( 'node:path' )
3+ const packageJson = require ( '../package.json' )
34
45; ( async ( ) => {
56 const distPath = path . join ( __dirname , '../dist' )
@@ -14,6 +15,7 @@ const path = require('node:path')
1415 readdir ( distEsmHelpersPath ) ,
1516 readdir ( distHelpersPath ) ,
1617 rm ( distCjsPath , { force : true , recursive : true } ) ,
18+ writeDummyExportsFiles ( ) ,
1719 ] )
1820
1921 await Promise . all ( [
@@ -57,8 +59,33 @@ function addReferenceTypesTripleDash(folderPath, folderContentPaths) {
5759
5860 const denoFriendlyFileContents = [ `/// <reference types="${ dtsFilePath } " />` , fileContents ] . join ( '\n' )
5961
60- await unlink ( filePath )
61-
6262 await writeFile ( filePath , denoFriendlyFileContents )
6363 } )
6464}
65+
66+ async function writeDummyExportsFiles ( ) {
67+ const rootPath = path . join ( __dirname , '..' )
68+
69+ await Promise . all (
70+ Object . entries ( packageJson . exports )
71+ . filter ( ( [ exportPath ] ) => exportPath !== '.' )
72+ . flatMap ( async ( [ exportPath , exportConfig ] ) => {
73+ const [ , ...dummyPathParts ] = exportPath . split ( '/' )
74+ const dummyFilename = dummyPathParts . length > 1 ? dummyPathParts . pop ( ) : 'index'
75+
76+ const [ , ...destinationFolders ] = exportConfig . require . split ( '/' ) . slice ( 0 , - 1 )
77+
78+ const dummyFolderPathFromRoot = path . join ( rootPath , ...dummyPathParts )
79+
80+ await mkdir ( dummyFolderPathFromRoot , { recursive : true } )
81+
82+ const dummyFilePathFromRoot = path . join ( dummyFolderPathFromRoot , dummyFilename )
83+ const actualPath = path . relative ( dummyFolderPathFromRoot , path . join ( rootPath , ...destinationFolders ) )
84+
85+ return [
86+ writeFile ( dummyFilePathFromRoot + '.js' , `module.exports = require('${ actualPath } ')` ) ,
87+ writeFile ( dummyFilePathFromRoot + '.d.ts' , `export * from '${ actualPath } '` ) ,
88+ ]
89+ } ) ,
90+ )
91+ }
0 commit comments