Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(pkg): replace types deps with triple-spash refs #1102

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
{
"name": "dts libdefs",
"path": "build/*.d.ts",
"limit": "38.5 kB",
"limit": "38.7 kB",
"brotli": false,
"gzip": false
},
8 changes: 2 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zx",
"version": "8.3.2",
"version": "8.4.0",
"description": "A tool for writing better scripts",
"type": "module",
"main": "./build/index.cjs",
@@ -92,10 +92,6 @@
"test:smoke:deno": "deno test ./test/smoke/deno.test.js --allow-read --allow-sys --allow-env --allow-run",
"test:workflow": "zizmor .github/workflows -v -p"
},
"optionalDependencies": {
"@types/fs-extra": ">=11",
"@types/node": ">=20"
},
"devDependencies": {
"@size-limit/file": "11.1.6",
"@types/fs-extra": "11.0.4",
18 changes: 13 additions & 5 deletions scripts/build-dts.mjs
Original file line number Diff line number Diff line change
@@ -99,12 +99,20 @@ for (const i in results) {
await fs.writeFile(entry.outFile, result, 'utf8')
}

// Replaces redundant triple-slash directives
// Properly formats triple-slash directives
const pkgEntries = ['core', 'index', 'vendor']
const prefix = `/// <reference types="node" />
/// <reference types="fs-extra" />

`

for (const dts of await glob(['build/**/*.d.ts', '!build/vendor-*.d.ts'])) {
const contents = (await fs.readFile(dts, 'utf8'))
.split('\n')
.filter((line) => !line.startsWith('/// <reference types'))
.join('\n')
const contents =
(pkgEntries.some((e) => dts.includes(e)) ? prefix : '') +
(await fs.readFile(dts, 'utf8'))
.split('\n')
.filter((line) => !line.startsWith('/// <reference types'))
.join('\n')

await fs.writeFile(dts, contents, 'utf8')
}
Loading