Skip to content

Commit ce004a7

Browse files
committed
refactor: introduce internal API bus
1 parent 89d1177 commit ce004a7

6 files changed

+57
-14
lines changed

.size-limit.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
{
1010
"name": "zx/index",
1111
"path": "build/*.{js,cjs}",
12-
"limit": "810 kB",
12+
"limit": "809 kB",
1313
"brotli": false,
1414
"gzip": false
1515
},
1616
{
1717
"name": "dts libdefs",
1818
"path": "build/*.d.ts",
19-
"limit": "38.7 kB",
19+
"limit": "38.5 kB",
2020
"brotli": false,
2121
"gzip": false
2222
},
2323
{
2424
"name": "vendor",
2525
"path": "build/vendor-*",
26-
"limit": "765 kB",
26+
"limit": "766 kB",
2727
"brotli": false,
2828
"gzip": false
2929
},
3030
{
3131
"name": "all",
3232
"path": "build/*",
33-
"limit": "849 kB",
33+
"limit": "848 kB",
3434
"brotli": false,
3535
"gzip": false
3636
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"build:js": "node scripts/build-js.mjs --format=cjs --hybrid --entry=src/*.ts:!src/error.ts:!src/repl.ts && npm run build:vendor",
6767
"build:vendor": "node scripts/build-js.mjs --format=cjs --entry=src/vendor-*.ts --bundle=all",
6868
"build:tests": "node scripts/build-tests.mjs",
69-
"build:dts": "tsc --project tsconfig.prod.json && rm build/error.d.ts build/repl.d.ts && node scripts/build-dts.mjs",
69+
"build:dts": "tsc --project tsconfig.json && rm build/error.d.ts build/repl.d.ts && node scripts/build-dts.mjs",
7070
"docs:dev": "vitepress dev docs",
7171
"docs:build": "vitepress build docs",
7272
"docs:preview": "vitepress preview docs",

scripts/build-dts.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const entries = [
6868
]
6969

7070
const compilationOptions = {
71-
preferredConfigPath: './tsconfig.prod.json', // args.project,
71+
preferredConfigPath: './tsconfig.json', // args.project,
7272
followSymlinks: true,
7373
}
7474

src/vendor-core.ts

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

15+
import { default as _chalk } from 'chalk'
16+
import { default as _which } from 'which'
17+
import { default as _ps } from '@webpod/ps'
18+
19+
type TCallable = (...args: any[]) => any
20+
const store = new Map<string, any>()
21+
22+
export const override = store.set.bind(store)
23+
24+
export const wrap = <T extends object>(name: string, api: T): T => {
25+
override(name, api)
26+
return new Proxy<T>(api, {
27+
get(_, key) {
28+
return store.get(name)[key]
29+
},
30+
apply(_, self, args) {
31+
return (store.get(name) as TCallable).apply(self, args)
32+
},
33+
})
34+
}
35+
1536
export {
1637
type TSpawnStore,
1738
type TSpawnStoreChunks,
@@ -24,6 +45,7 @@ export {
2445
export type RequestInfo = Parameters<typeof globalThis.fetch>[0]
2546
export type RequestInit = Parameters<typeof globalThis.fetch>[1]
2647

27-
export { default as chalk, type ChalkInstance } from 'chalk'
28-
export { default as which } from 'which'
29-
export { default as ps } from '@webpod/ps'
48+
export { type ChalkInstance } from 'chalk'
49+
export const chalk = wrap('chalk', _chalk)
50+
export const which = wrap('which', _which)
51+
export const ps = wrap('ps', _ps)

src/vendor.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,30 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import { wrap } from './vendor-core.js'
16+
import {
17+
depseek as _depseek,
18+
dotenv as _dotenv,
19+
type minimist as TMinimistNamespace,
20+
minimist as _minimist,
21+
fs as _fs,
22+
YAML as _YAML,
23+
glob as _glob,
24+
nodeFetch as _nodeFetch,
25+
} from './vendor-extra.js'
26+
1527
export * from './vendor-core.js'
16-
export * from './vendor-extra.js'
28+
export { createRequire } from './vendor-extra.js'
29+
30+
export const depseek: typeof _depseek = wrap('depseek', _depseek)
31+
export const dotenv: typeof _dotenv = wrap('dotenv', _dotenv)
32+
export const fs: typeof _fs = wrap('fs', _fs)
33+
export const YAML: typeof _YAML = wrap('YAML', _YAML)
34+
export const glob: typeof _glob = wrap('glob', _glob)
35+
export const nodeFetch: typeof _nodeFetch = wrap('nodeFetch', _nodeFetch)
36+
37+
export const minimist: typeof _minimist = wrap('minimist', _minimist)
38+
export namespace minimist {
39+
export type Opts = TMinimistNamespace.Opts
40+
export type ParsedArgs = TMinimistNamespace.ParsedArgs
41+
}

tsconfig.prod.json

-4
This file was deleted.

0 commit comments

Comments
 (0)