Skip to content

Commit be335f1

Browse files
authored
ci: configure zx-lite publishing (#1131)
1 parent 8cb4212 commit be335f1

15 files changed

+244
-33
lines changed

.github/workflows/dev-publish.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- run: npm test
2121
env:
2222
FORCE_COLOR: 3
23-
- run: node scripts/clean-package-json.mjs
23+
- run: node scripts/prepublish-clean.mjs
2424
- uses: actions/upload-artifact@v4
2525
with:
2626
name: build-${{ github.run_id }}
@@ -46,12 +46,24 @@ jobs:
4646
with:
4747
node-version: 22
4848
cache: 'npm'
49-
- uses: actions/download-artifact@v4
50-
with:
51-
name: build-${{ github.run_id }}
49+
5250
- run: echo "//wombat-dressing-room.appspot.com/:_authToken=$AUTH_TOKEN" >> .npmrc
5351
env:
5452
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
53+
54+
# publishing lite snapshot version: 1.2.3-lite-dev.abcd1234
55+
- uses: actions/download-artifact@v4
56+
with:
57+
name: build-${{ github.run_id }}
58+
- run: |
59+
node scripts/prepublish-lite.mjs
60+
npm version $(node --eval="process.stdout.write(require('./package.json').version)")-dev.$(git rev-parse --short HEAD) --no-git-tag-version
61+
npm publish --provenance --access=public --no-git-tag-version --tag dev
62+
63+
# publishing regular snapshot version: 1.2.3-dev.abcd1234
64+
- uses: actions/download-artifact@v4
65+
with:
66+
name: build-${{ github.run_id }}
5567
- run: |
5668
npm version $(node --eval="process.stdout.write(require('./package.json').version)")-dev.$(git rev-parse --short HEAD) --no-git-tag-version
5769
npm publish --provenance --access=public --no-git-tag-version --tag dev

.github/workflows/npm-publish.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- run: npm test
2323
env:
2424
FORCE_COLOR: 3
25-
- run: node scripts/clean-package-json.mjs
25+
- run: node scripts/prepublish-clean.mjs
2626
- uses: actions/upload-artifact@v4
2727
with:
2828
name: build-${{ github.run_id }}
@@ -54,4 +54,7 @@ jobs:
5454
- run: echo "//wombat-dressing-room.appspot.com/:_authToken=$AUTH_TOKEN" >> .npmrc
5555
env:
5656
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
57-
- run: npm publish --provenance --access=public
57+
- run: |
58+
npm publish --provenance --access=public
59+
node scripts/prepublish-lite.mjs
60+
npm publish --provenance --access=public --no-git-tag-version --tag lite

.size-limit.json

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
[
22
{
3-
"name": "zx/core",
4-
"path": ["build/core.cjs", "build/util.cjs", "build/vendor-core.cjs"],
5-
"limit": "77.3 kB",
3+
"name": "zx-lite",
4+
"path": [
5+
"build/core.cjs",
6+
"build/core.js",
7+
"build/core.d.ts",
8+
"build/deno.js",
9+
"build/esblib.js",
10+
"build/util.cjs",
11+
"build/util.js",
12+
"build/util.d.ts",
13+
"build/vendor-core.cjs",
14+
"build/vendor-core.js",
15+
"build/vendor-core.d.ts",
16+
"README.md",
17+
"LICENSE"
18+
],
19+
"limit": "111 kB",
620
"brotli": false,
721
"gzip": false
822
},
923
{
10-
"name": "zx/index",
24+
"name": "js parts",
1125
"path": "build/*.{js,cjs}",
12-
"limit": "813 kB",
26+
"limit": "813.5 kB",
1327
"brotli": false,
1428
"gzip": false
1529
},
1630
{
17-
"name": "dts libdefs",
31+
"name": "libdefs",
1832
"path": "build/*.d.ts",
19-
"limit": "39.42 kB",
33+
"limit": "40 kB",
2034
"brotli": false,
2135
"gzip": false
2236
},
@@ -29,8 +43,8 @@
2943
},
3044
{
3145
"name": "all",
32-
"path": "build/*",
33-
"limit": "852.5 kB",
46+
"path": ["build/*", "man/*", "README.md", "LICENSE"],
47+
"limit": "866.5 kB",
3448
"brotli": false,
3549
"gzip": false
3650
}

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
Represents a cmd execution result.
44

55
```ts
6-
interface ProcessOutput {
6+
const p = $`command` // ProcessPromise
7+
const o = await p // ProcessOutput
8+
```
9+
10+
```ts
11+
interface ProcessOutput extends Error {
712
// Exit code of the process: 0 for success, non-zero for failure
813
exitCode: number
914

@@ -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/process-promise.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Process Promise
22

3-
The `$` returns a `ProcessPromise` instance. When resolved, it becomes a [`ProcessOutput`](./process-output.md).
3+
The `$` returns a `ProcessPromise` instance, which inherits native `Promise`. When resolved, it becomes a [`ProcessOutput`](./process-output.md).
44

55
```js
66
const p = $`command` // ProcessPromise

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+

scripts/clean-package-json.mjs scripts/prepublish-clean.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Optimizes package.json for npm publishing
16+
1517
import fs from 'node:fs'
1618
import path from 'node:path'
1719

@@ -46,3 +48,5 @@ const pkgJson = Object.fromEntries(
4648
Object.entries(_pkgJson).filter(([k]) => whitelist.has(k))
4749
)
4850
fs.writeFileSync(pkgJsonFile, JSON.stringify(pkgJson, null, 2))
51+
52+
console.log('package.json optimized for npm publishing')

scripts/prepublish-lite.mjs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
// Prepares lite (core) version of zx to publish
16+
17+
import fs from 'node:fs'
18+
import path from 'node:path'
19+
20+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
21+
const root = path.resolve(__dirname, '..')
22+
const pkgJsonFile = path.join(root, 'package.json')
23+
const _pkgJson = JSON.parse(fs.readFileSync(pkgJsonFile, 'utf-8'))
24+
25+
const pkgJson = {
26+
..._pkgJson,
27+
version: _pkgJson.version + '-lite',
28+
exports: {
29+
'.': {
30+
types: './build/core.d.ts',
31+
import: './build/core.js',
32+
require: './build/core.cjs',
33+
default: './build/core.js',
34+
},
35+
'./package.json': './package.json',
36+
},
37+
main: './build/core.cjs',
38+
types: './build/core.d.ts',
39+
typesVersions: {
40+
'*': {
41+
'.': ['./build/core.d.ts'],
42+
},
43+
},
44+
man: undefined,
45+
files: [
46+
'build/core.cjs',
47+
'build/core.js',
48+
'build/core.d.ts',
49+
'build/deno.js',
50+
'build/esblib.js',
51+
'build/util.cjs',
52+
'build/util.js',
53+
'build/util.d.ts',
54+
'build/vendor-core.cjs',
55+
'build/vendor-core.js',
56+
'build/vendor-core.d.ts',
57+
],
58+
}
59+
60+
fs.writeFileSync(pkgJsonFile, JSON.stringify(pkgJson, null, 2))
61+
62+
console.log('package.json prepared for zx-lite publishing')

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/core.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,6 @@ describe('core', () => {
11341134
assert.deepEqual(await p1.lines(), ['foo', 'bar', 'baz'])
11351135

11361136
const p2 = $.sync`echo 'foo\nbar\r\nbaz'`
1137-
console.log('p2', p2)
11381137
assert.deepEqual(p2.lines(), ['foo', 'bar', 'baz'])
11391138
})
11401139

0 commit comments

Comments
 (0)