Skip to content

Commit 84e484a

Browse files
authored
feat: expose bus api (#1332)
* chore: update tsx to v4.20.5 * feat: expose internal api registry * chore: improve jsr types * refactor: conceal `bus.store`
1 parent 72b5604 commit 84e484a

17 files changed

+74
-24
lines changed

.size-limit.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build/error.d.ts",
1111
"build/esblib.cjs",
1212
"build/internals.cjs",
13+
"build/internals.d.ts",
1314
"build/log.d.ts",
1415
"build/util.cjs",
1516
"build/util.d.ts",
@@ -18,7 +19,7 @@
1819
"README.md",
1920
"LICENSE"
2021
],
21-
"limit": "127.66 kB",
22+
"limit": "128.17 kB",
2223
"brotli": false,
2324
"gzip": false
2425
},
@@ -32,14 +33,14 @@
3233
"build/globals.js",
3334
"build/deno.js"
3435
],
35-
"limit": "814.901 kB",
36+
"limit": "815.20 kB",
3637
"brotli": false,
3738
"gzip": false
3839
},
3940
{
4041
"name": "libdefs",
4142
"path": "build/*.d.ts",
42-
"limit": "40.35 kB",
43+
"limit": "40.65 kB",
4344
"brotli": false,
4445
"gzip": false
4546
},
@@ -65,7 +66,7 @@
6566
"README.md",
6667
"LICENSE"
6768
],
68-
"limit": "872.10 kB",
69+
"limit": "872.75 kB",
6970
"brotli": false,
7071
"gzip": false
7172
}

build/core.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ __export(core_exports, {
2020
Fail: () => Fail,
2121
ProcessOutput: () => ProcessOutput,
2222
ProcessPromise: () => ProcessPromise,
23+
bus: () => import_internals.bus,
2324
cd: () => cd,
2425
chalk: () => import_vendor_core3.chalk,
2526
defaults: () => defaults,
@@ -392,6 +393,7 @@ function formatCmd(cmd) {
392393
// src/core.ts
393394
var import_vendor_core2 = require("./vendor-core.cjs");
394395
var import_util = require("./util.cjs");
396+
var import_internals = require("./internals.cjs");
395397
var import_node_path = __toESM(require("path"), 1);
396398
var os = __toESM(require("os"), 1);
397399
var import_vendor_core3 = require("./vendor-core.cjs");
@@ -1145,6 +1147,7 @@ function resolveDefaults(defs = defaults, prefix = ENV_PREFIX, env = import_node
11451147
Fail,
11461148
ProcessOutput,
11471149
ProcessPromise,
1150+
bus,
11481151
cd,
11491152
chalk,
11501153
defaults,

build/core.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Fail } from './error.js';
1111
import { log } from './log.js';
1212
import { type TSpawnStore } from './vendor-core.js';
1313
import { type Duration, quote } from './util.js';
14+
export { bus } from './internals.js';
1415
export { default as path } from 'node:path';
1516
export * as os from 'node:os';
1617
export { Fail } from './error.js';

build/core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
Fail,
77
ProcessOutput,
88
ProcessPromise,
9+
bus,
910
cd,
1011
chalk,
1112
defaults,
@@ -29,6 +30,7 @@ export {
2930
Fail,
3031
ProcessOutput,
3132
ProcessPromise,
33+
bus,
3234
cd,
3335
chalk,
3436
defaults,

build/index.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ __export(index_exports, {
4141
versions: () => versions
4242
});
4343
module.exports = __toCommonJS(index_exports);
44+
var import_core2 = require("./core.cjs");
4445

4546
// src/goods.ts
4647
var import_node_buffer = require("buffer");
@@ -251,6 +252,7 @@ function spinner(title, callback) {
251252
// src/index.ts
252253
__reExport(index_exports, require("./core.cjs"), module.exports);
253254
var import_vendor2 = require("./vendor.cjs");
255+
import_core2.bus.lock();
254256
var VERSION = versions.zx || "0.0.0";
255257
var version = VERSION;
256258
function nothrow(promise) {

build/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const {
3232
Fail,
3333
ProcessOutput,
3434
ProcessPromise,
35+
bus,
3536
cd,
3637
chalk,
3738
defaults,
@@ -81,6 +82,7 @@ export {
8182
Fail,
8283
ProcessOutput,
8384
ProcessPromise,
85+
bus,
8486
cd,
8587
chalk,
8688
defaults,

build/internals.cjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ __export(internals_exports, {
1111
bus: () => bus
1212
});
1313
module.exports = __toCommonJS(internals_exports);
14+
var locked = false;
15+
var lock = () => locked = true;
1416
var store = /* @__PURE__ */ new Map();
1517
var override = store.set.bind(store);
16-
var wrap = (name, api) => {
18+
function wrap(name, api) {
19+
if (locked) throw new Error("bus is locked");
1720
override(name, api);
1821
return new Proxy(api, {
1922
get(_, key) {
@@ -24,11 +27,11 @@ var wrap = (name, api) => {
2427
return store.get(name).apply(self, args);
2528
}
2629
});
27-
};
30+
}
2831
var bus = {
2932
override,
30-
store,
31-
wrap
33+
wrap,
34+
lock
3235
};
3336
/* c8 ignore next 100 */
3437
// Annotate the CommonJS export names for ESM import in node:

build/internals.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare function wrap<T extends object>(name: string, api: T): T;
2+
/**
3+
* @internal
4+
* @private
5+
* @protected
6+
*/
7+
export declare const bus: {
8+
override: (key: string, value: any) => Map<string, any>;
9+
wrap: typeof wrap;
10+
lock: () => void;
11+
};
12+
export {};

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"fmt": "prettier --write .",
7171
"fmt:check": "prettier --check .",
7272
"prebuild": "rm -rf build",
73-
"build": "npm run build:versions && npm run build:js && npm run build:dts && npm run build:tests && npm run build:manifest",
73+
"build": "npm run build:versions && npm run build:js && npm run build:dts && npm run build:tests",
7474
"build:js": "node scripts/build-js.mjs --format=cjs --hybrid --entry='src/{cli,core,deps,globals,index,internals,util,vendor*}.ts' && npm run build:vendor",
7575
"build:vendor": "node scripts/build-js.mjs --format=cjs --entry=src/vendor-*.ts --bundle=all --external='./internals.ts'",
7676
"build:versions": "node scripts/build-versions.mjs",
@@ -81,7 +81,7 @@
8181
"build:lite": "node scripts/build-pkgjson-lite.mjs",
8282
"build:pkgjson": "node scripts/build-pkgjson-main.mjs",
8383
"build:manifest": "npm run build:pkgjson && npm run build:lite && npm run build:jsr",
84-
"postbuild": "node scripts/build-clean.mjs",
84+
"postbuild": "node scripts/build-clean.mjs && npm run build:manifest",
8585
"docs:dev": "vitepress dev docs",
8686
"docs:build": "vitepress build docs",
8787
"docs:preview": "vitepress preview docs",
@@ -145,7 +145,7 @@
145145
"size-limit": "11.2.0",
146146
"ts-node": "10.9.2",
147147
"tsd": "0.33.0",
148-
"tsx": "4.20.4",
148+
"tsx": "4.20.5",
149149
"typescript": "5.9.2",
150150
"vitepress": "1.6.4",
151151
"which": "5.0.0",

0 commit comments

Comments
 (0)