Skip to content

Commit b2cfcfa

Browse files
committed
fix(types): add missing minimist typings to dts bundle
relates #871
1 parent a34888b commit b2cfcfa

File tree

6 files changed

+85
-5
lines changed

6 files changed

+85
-5
lines changed

.size-limit.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"name": "dts libdefs",
1818
"path": "build/*.d.ts",
19-
"limit": "31 kB",
19+
"limit": "34 kB",
2020
"brotli": false,
2121
"gzip": false
2222
},

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
6969
"pretest": "npm run build",
7070
"test": "npm run test:size && npm run fmt:check && npm run test:unit && npm run test:types && npm run test:license",
71+
"test:it": "node ./test/it/build.test.js",
7172
"test:unit": "node ./test/all.test.js",
7273
"test:coverage": "c8 -x build/deno.js -x build/vendor-extra.cjs -x build/vendor-core.cjs -x build/esblib.cjs -x 'test/**' -x scripts --check-coverage npm run test:unit",
7374
"test:circular": "madge --circular src/*",

scripts/build-dts.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const entries = [
3939
'node-fetch-native',
4040
// 'chalk',
4141
'globby',
42-
// '@types/minimist',
42+
'@types/minimist',
4343
// '@types/which',
4444
// 'zurk',
4545
// '@webpod/ps',

test-d/globals.test-d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import assert from 'node:assert'
1616
import { expectType } from 'tsd'
1717
import 'zx/globals'
18+
import { ParsedArgs } from 'minimist'
1819

1920
let p = $`cmd`
2021
assert(p instanceof ProcessPromise)
@@ -26,3 +27,5 @@ expectType<ProcessOutput>(o)
2627

2728
expectType<string>(quote('foo'))
2829
expectType<string>(quotePowerShell('foo'))
30+
31+
expectType<ParsedArgs>(minimist(['--foo', 'bar']))

test/it/build.test.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { tempdir, $, path, fs } from '../../build/index.js'
16+
import assert from 'node:assert'
17+
import { describe, before, after, it } from 'node:test'
18+
19+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
20+
const root = path.resolve(__dirname, '../../')
21+
22+
describe('npm artifact', () => {
23+
let tmp
24+
let zxdir
25+
let t$
26+
27+
const pkgJson = {
28+
name: 'zx-test',
29+
dependencies: {
30+
typescript: '^5',
31+
'@types/node': '*',
32+
'@types/fs-extra': '*'
33+
}
34+
}
35+
36+
before(async () => {
37+
tmp = tempdir()
38+
t$ = $({cwd: tmp, quiet: true})
39+
zxdir = path.resolve(tmp, 'node_modules/zx')
40+
41+
await fs.outputJSON(path.resolve(tmp, 'package.json'), pkgJson)
42+
await t$`npm i`
43+
// `file:<path>` dep mounts `node_modules` too, so we use cloning here
44+
await fs.copy(path.resolve(root, 'package.json'), path.resolve(zxdir, 'package.json'))
45+
await fs.copy(path.resolve(root, 'build'), path.resolve(zxdir, 'build'))
46+
})
47+
48+
after(() => fs.remove(tmp))
49+
50+
it('looks buildable with tsc', async () => {
51+
const indexTs = `import {$} from 'zx'
52+
(async () => {
53+
await $({verbose: true, stdio: 'pipe'})\`echo hello\`
54+
})()
55+
`
56+
const tsconfig = {
57+
compilerOptions: {
58+
module: 'commonjs',
59+
target: 'esnext',
60+
outDir: 'build-tsc',
61+
rootDir: 'src',
62+
declaration: true,
63+
declarationMap: false,
64+
esModuleInterop: true,
65+
},
66+
include: ['src'],
67+
}
68+
69+
await fs.outputJSON(path.resolve(tmp, 'tsconfig.json'), tsconfig)
70+
await fs.outputFile(path.resolve(tmp, 'src/index.ts'), indexTs)
71+
await t$`tsc`
72+
const result = await t$`node build-tsc/index.js`.text()
73+
74+
assert.strictEqual(result, '$ echo hello\nhello\n')
75+
})
76+
})

0 commit comments

Comments
 (0)