Skip to content

Commit ede4414

Browse files
committed
refactor: rearrange API exports
1 parent 39012e5 commit ede4414

9 files changed

+135
-18
lines changed

.size-limit.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
"README.md",
1717
"LICENSE"
1818
],
19-
"limit": "110 kB",
19+
"limit": "111 kB",
2020
"brotli": false,
2121
"gzip": false
2222
},
2323
{
2424
"name": "js parts",
2525
"path": "build/*.{js,cjs}",
26-
"limit": "813 kB",
26+
"limit": "813.5 kB",
2727
"brotli": false,
2828
"gzip": false
2929
},
3030
{
3131
"name": "libdefs",
3232
"path": "build/*.d.ts",
33-
"limit": "39.4 kB",
33+
"limit": "39.5 kB",
3434
"brotli": false,
3535
"gzip": false
3636
},

docs/.vitepress/config.mts

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default defineConfig({
6666
{ text: 'CLI Usage', link: '/cli' },
6767
{ text: 'Configuration', link: '/configuration' },
6868
{ text: 'Process Promise', link: '/process-promise' },
69+
{ text: 'Process Output', link: '/process-output' },
6970
{ text: 'Contribution Guide', link: '/contribution' },
7071
{ text: 'Migration from v7', link: '/migration-from-v7' },
7172
],

docs/process-output.md

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Represents a cmd execution result.
44

5+
```ts
6+
const p = $`command` // ProcessPromise
7+
const o = await p // ProcessOutput
8+
```
9+
510
```ts
611
interface ProcessOutput {
712
// Exit code of the process: 0 for success, non-zero for failure
@@ -15,6 +20,17 @@ interface ProcessOutput {
1520

1621
// Process errors are written to stderr
1722
stderr: string
23+
24+
buffer(): Buffer
25+
26+
json<T = any>(): T
27+
28+
blob(type = 'text/plain'): Blob
29+
30+
text(encoding: Encoding = 'utf8'): string
31+
32+
// Output lines splitted by newline
33+
lines(): string[]
1834

1935
// combined stdout and stderr
2036
toString(): string

docs/setup.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ brew install zx
3232

3333
:::
3434

35-
Dev snapshot versions are published to npm under the [`dev` tag](https://www.npmjs.com/package/zx?activeTab=versions): `npm i zx@dev`.
35+
zx-core is distributed separately to the `lite` channel on npm: `npm i zx@lite`.
36+
Dev snapshot versions are published to npm under the [`dev` tag](https://www.npmjs.com/package/zx?activeTab=versions): `npm i zx@dev`. See [versions](./versions) for more details.
3637

3738
## Bash
3839

docs/versions.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Versions
2+
3+
zx is distributed in several versions, each with its own set of features.
4+
5+
* `@latest` represents the stable full-featured version.
6+
* `@lite` separates the zx core from the extensions.
7+
* `@dev` brings experimental snapshots and RCs.
8+
9+
| Feature | latest | lite |
10+
|-------------------|--------|------|
11+
| **zx/globals** | ✔️ ||
12+
| **zx/cli** | ✔️ | |
13+
| `$` | ✔️ | ✔️ |
14+
| `ProcessPromise` | ✔️ | ✔️ |
15+
| `ProcessOutput` | ✔️ | ✔️ |
16+
| `argv` | ✔️ ||
17+
| `cd` | ✔️ | ✔️ |
18+
| `chalk` | ✔️ | ✔️ |
19+
| `defaults` | ✔️ | ✔️ |
20+
| `dotenv` | ✔️ ||
21+
| `echo` | ✔️ ||
22+
| `expBackoff` | ✔️ ||
23+
| `fetch` | ✔️ ||
24+
| `fs` | ✔️ ||
25+
| `glob` | ✔️ ||
26+
| `kill` | ✔️ | ✔️ |
27+
| `log` | ✔️ | ✔️ |
28+
| `minimist` | ✔️ ||
29+
| `nothrow` | ✔️ ||
30+
| `os` | ✔️ | ✔️ |
31+
| `parseArgv` | ✔️ ||
32+
| `path` | ✔️ | ✔️ |
33+
| `ps` | ✔️ | ✔️ |
34+
| `question` | ✔️ ||
35+
| `quiet` | ✔️ ||
36+
| `quote` | ✔️ | ✔️ |
37+
| `quotePowerShell` | ✔️ | ✔️ |
38+
| `resolveDefaults` | ✔️ | ✔️ |
39+
| `retry` | ✔️ ||
40+
| `sleep` | ✔️ ||
41+
| `spinner` | ✔️ ||
42+
| `syncProcessCwd` | ✔️ | ✔️ |
43+
| `tempdir` | ✔️ | |
44+
| `tempfile` | ✔️ | |
45+
| `updateArgv` | ✔️ | |
46+
| `useBash` | ✔️ | ✔️ |
47+
| `usePowerShell` | ✔️ | ✔️ |
48+
| `usePwsh` | ✔️ | ✔️ |
49+
| `version` | ✔️ ||
50+
| `which` | ✔️ | ✔️ |
51+
| `whithin` | ✔️ | ✔️ |
52+
| `YAML` | ✔️ ||
53+

src/core.ts

+4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ import {
6363

6464
import { log } from './log.ts'
6565

66+
export { default as path } from 'node:path'
67+
export * as os from 'node:os'
6668
export { log, type LogEntry } from './log.ts'
69+
export { chalk, which, ps } from './vendor-core.ts'
70+
export { quote, quotePowerShell } from './util.ts'
6771

6872
const CWD = Symbol('processCwd')
6973
const SYNC = Symbol('syncExec')

src/goods.ts

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import {
3131
minimist,
3232
} from './vendor.ts'
3333

34-
export { default as path } from 'node:path'
35-
export * as os from 'node:os'
36-
3734
type ArgvOpts = minimist.Opts & { camelCase?: boolean; parseBoolean?: boolean }
3835

3936
export const parseArgv = (

src/index.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ import { fs } from './vendor.ts'
1717

1818
export * from './core.ts'
1919
export * from './goods.ts'
20-
export {
21-
minimist,
22-
chalk,
23-
dotenv,
24-
fs,
25-
which,
26-
YAML,
27-
ps,
28-
glob,
29-
glob as globby,
30-
} from './vendor.ts'
20+
export { minimist, dotenv, fs, YAML, glob, glob as globby } from './vendor.ts'
3121

3222
export const VERSION: string = fs.readJsonSync(
3323
new URL('../package.json', import.meta.url)

test/export.test.js

+55
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ describe('core', () => {
2828
assert.equal(typeof core.ProcessOutput.getExitMessage, 'function', 'core.ProcessOutput.getExitMessage')
2929
assert.equal(typeof core.ProcessPromise, 'function', 'core.ProcessPromise')
3030
assert.equal(typeof core.cd, 'function', 'core.cd')
31+
assert.equal(typeof core.chalk, 'function', 'core.chalk')
32+
assert.equal(typeof core.chalk.level, 'number', 'core.chalk.level')
3133
assert.equal(typeof core.defaults, 'object', 'core.defaults')
3234
assert.equal(typeof core.defaults.detached, 'boolean', 'core.defaults.detached')
3335
assert.equal(typeof core.defaults.env, 'object', 'core.defaults.env')
@@ -49,11 +51,64 @@ describe('core', () => {
4951
assert.equal(typeof core.defaults.verbose, 'boolean', 'core.defaults.verbose')
5052
assert.equal(typeof core.kill, 'function', 'core.kill')
5153
assert.equal(typeof core.log, 'function', 'core.log')
54+
assert.equal(typeof core.os, 'object', 'core.os')
55+
assert.equal(typeof core.os.EOL, 'string', 'core.os.EOL')
56+
assert.equal(typeof core.os.arch, 'function', 'core.os.arch')
57+
assert.equal(typeof core.os.availableParallelism, 'function', 'core.os.availableParallelism')
58+
assert.equal(typeof core.os.constants, 'object', 'core.os.constants')
59+
assert.equal(typeof core.os.cpus, 'function', 'core.os.cpus')
60+
assert.equal(typeof core.os.default, 'object', 'core.os.default')
61+
assert.equal(typeof core.os.devNull, 'string', 'core.os.devNull')
62+
assert.equal(typeof core.os.endianness, 'function', 'core.os.endianness')
63+
assert.equal(typeof core.os.freemem, 'function', 'core.os.freemem')
64+
assert.equal(typeof core.os.getPriority, 'function', 'core.os.getPriority')
65+
assert.equal(typeof core.os.homedir, 'function', 'core.os.homedir')
66+
assert.equal(typeof core.os.hostname, 'function', 'core.os.hostname')
67+
assert.equal(typeof core.os.loadavg, 'function', 'core.os.loadavg')
68+
assert.equal(typeof core.os.machine, 'function', 'core.os.machine')
69+
assert.equal(typeof core.os.networkInterfaces, 'function', 'core.os.networkInterfaces')
70+
assert.equal(typeof core.os.platform, 'function', 'core.os.platform')
71+
assert.equal(typeof core.os.release, 'function', 'core.os.release')
72+
assert.equal(typeof core.os.setPriority, 'function', 'core.os.setPriority')
73+
assert.equal(typeof core.os.tmpdir, 'function', 'core.os.tmpdir')
74+
assert.equal(typeof core.os.totalmem, 'function', 'core.os.totalmem')
75+
assert.equal(typeof core.os.type, 'function', 'core.os.type')
76+
assert.equal(typeof core.os.uptime, 'function', 'core.os.uptime')
77+
assert.equal(typeof core.os.userInfo, 'function', 'core.os.userInfo')
78+
assert.equal(typeof core.os.version, 'function', 'core.os.version')
79+
assert.equal(typeof core.path, 'object', 'core.path')
80+
assert.equal(typeof core.path._makeLong, 'function', 'core.path._makeLong')
81+
assert.equal(typeof core.path.basename, 'function', 'core.path.basename')
82+
assert.equal(typeof core.path.delimiter, 'string', 'core.path.delimiter')
83+
assert.equal(typeof core.path.dirname, 'function', 'core.path.dirname')
84+
assert.equal(typeof core.path.extname, 'function', 'core.path.extname')
85+
assert.equal(typeof core.path.format, 'function', 'core.path.format')
86+
assert.equal(typeof core.path.isAbsolute, 'function', 'core.path.isAbsolute')
87+
assert.equal(typeof core.path.join, 'function', 'core.path.join')
88+
assert.equal(typeof core.path.matchesGlob, 'function', 'core.path.matchesGlob')
89+
assert.equal(typeof core.path.normalize, 'function', 'core.path.normalize')
90+
assert.equal(typeof core.path.parse, 'function', 'core.path.parse')
91+
assert.equal(typeof core.path.posix, 'object', 'core.path.posix')
92+
assert.equal(typeof core.path.relative, 'function', 'core.path.relative')
93+
assert.equal(typeof core.path.resolve, 'function', 'core.path.resolve')
94+
assert.equal(typeof core.path.sep, 'string', 'core.path.sep')
95+
assert.equal(typeof core.path.toNamespacedPath, 'function', 'core.path.toNamespacedPath')
96+
assert.equal(typeof core.path.win32, 'object', 'core.path.win32')
97+
assert.equal(typeof core.ps, 'object', 'core.ps')
98+
assert.equal(typeof core.ps.kill, 'function', 'core.ps.kill')
99+
assert.equal(typeof core.ps.lookup, 'function', 'core.ps.lookup')
100+
assert.equal(typeof core.ps.lookupSync, 'function', 'core.ps.lookupSync')
101+
assert.equal(typeof core.ps.tree, 'function', 'core.ps.tree')
102+
assert.equal(typeof core.ps.treeSync, 'function', 'core.ps.treeSync')
103+
assert.equal(typeof core.quote, 'function', 'core.quote')
104+
assert.equal(typeof core.quotePowerShell, 'function', 'core.quotePowerShell')
52105
assert.equal(typeof core.resolveDefaults, 'function', 'core.resolveDefaults')
53106
assert.equal(typeof core.syncProcessCwd, 'function', 'core.syncProcessCwd')
54107
assert.equal(typeof core.useBash, 'function', 'core.useBash')
55108
assert.equal(typeof core.usePowerShell, 'function', 'core.usePowerShell')
56109
assert.equal(typeof core.usePwsh, 'function', 'core.usePwsh')
110+
assert.equal(typeof core.which, 'function', 'core.which')
111+
assert.equal(typeof core.which.sync, 'function', 'core.which.sync')
57112
assert.equal(typeof core.within, 'function', 'core.within')
58113
})
59114
})

0 commit comments

Comments
 (0)