-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: extract bundle scripts into js modules
- Loading branch information
Showing
3 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as fs from 'node:fs'; | ||
|
||
import dbg from 'dts-bundle-generator'; | ||
|
||
const [declarations] = dbg.generateDtsBundle([ | ||
{ | ||
filePath: './src/index.ts', | ||
libraries: { | ||
inlinedLibraries: [ | ||
'@nodelib/fs.stat', | ||
'@nodelib/fs.scandir', | ||
'@nodelib/fs.walk', | ||
], | ||
}, | ||
output: { | ||
exportReferencedTypes: false, | ||
}, | ||
}, | ||
]); | ||
|
||
const imports = declarations.match(/from\s'(?<filepath>[^']+)'/g); | ||
|
||
const hasOnlyNodeDependencies = imports.every((it) => it.startsWith("from 'node:")); | ||
|
||
if (!hasOnlyNodeDependencies) { | ||
throw new Error('Not only node: dependencies are found in the dts bundle.'); | ||
} | ||
|
||
fs.mkdirSync('./build', { recursive: true }); | ||
fs.writeFileSync('./build/index.d.ts', declarations, 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import esbuild from 'esbuild'; | ||
|
||
import package_ from '../package.json' with { type: 'json' }; | ||
|
||
await esbuild.build({ | ||
bundle: true, | ||
platform: 'node', | ||
target: 'node18.18', | ||
format: 'cjs', | ||
external: Object.keys(package_.dependencies), | ||
entryPoints: ['./out/index.js'], | ||
outfile: './build/index.js', | ||
}); |