Skip to content

Commit

Permalink
build with dummy helpers folder outside of dist.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed May 20, 2023
1 parent c144aa3 commit 171c9fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ coverage/
dist/
node_modules/
*.log
.env*
.env*
helpers/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
}
},
"files": [
"dist"
"dist",
"helpers"
],
"keywords": [
"kysely",
Expand Down
31 changes: 29 additions & 2 deletions scripts/dist-fix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {mkdir, readdir, rename, rm, writeFile, copyFile, readFile, unlink, move} = require('fs-extra')
const path = require('node:path')
const packageJson = require('../package.json')

;(async () => {
const distPath = path.join(__dirname, '../dist')
Expand All @@ -14,6 +15,7 @@ const path = require('node:path')
readdir(distEsmHelpersPath),
readdir(distHelpersPath),
rm(distCjsPath, {force: true, recursive: true}),
writeDummyExportsFiles(),
])

await Promise.all([
Expand Down Expand Up @@ -57,8 +59,33 @@ function addReferenceTypesTripleDash(folderPath, folderContentPaths) {

const denoFriendlyFileContents = [`/// <reference types="${dtsFilePath}" />`, fileContents].join('\n')

await unlink(filePath)

await writeFile(filePath, denoFriendlyFileContents)
})
}

async function writeDummyExportsFiles() {
const rootPath = path.join(__dirname, '..')

await Promise.all(
Object.entries(packageJson.exports)
.filter(([exportPath]) => exportPath !== '.')
.flatMap(async ([exportPath, exportConfig]) => {
const [, ...dummyPathParts] = exportPath.split('/')
const dummyFilename = dummyPathParts.length > 1 ? dummyPathParts.pop() : 'index'

const [, ...destinationFolders] = exportConfig.require.split('/').slice(0, -1)

const dummyFolderPathFromRoot = path.join(rootPath, ...dummyPathParts)

await mkdir(dummyFolderPathFromRoot, {recursive: true})

const dummyFilePathFromRoot = path.join(dummyFolderPathFromRoot, dummyFilename)
const actualPath = path.relative(dummyFolderPathFromRoot, path.join(rootPath, ...destinationFolders))

return [
writeFile(dummyFilePathFromRoot + '.js', `module.exports = require('${actualPath}')`),
writeFile(dummyFilePathFromRoot + '.d.ts', `export * from '${actualPath}'`),
]
}),
)
}

0 comments on commit 171c9fd

Please sign in to comment.