Skip to content

Commit 43b7583

Browse files
committed
add browser esm export condition to not even try to load diagnostics channel
Fix: #400
1 parent e9ae122 commit 43b7583

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

.tshy/commonjs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"../src/**/*.mts",
1111
"../src/package.json",
1212
"../src/diagnostics-channel-esm.mts",
13-
"../src/diagnostics-channel-node.mts"
13+
"../src/diagnostics-channel-node.mts",
14+
"../src/diagnostics-channel-browser.mts"
1415
],
1516
"compilerOptions": {
1617
"outDir": "../.tshy-build/commonjs"

.tshy/esm-browser.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./build.json",
3+
"include": [
4+
"../src/**/*.ts",
5+
"../src/**/*.mts",
6+
"../src/**/*.tsx",
7+
"../src/**/*.json"
8+
],
9+
"exclude": [
10+
"../src/package.json",
11+
"../src/diagnostics-channel-esm.mts",
12+
"../src/diagnostics-channel-node.mts"
13+
],
14+
"compilerOptions": {
15+
"outDir": "../.tshy-build/esm/browser"
16+
}
17+
}

.tshy/esm-node.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
],
99
"exclude": [
1010
"../src/package.json",
11-
"../src/diagnostics-channel-esm.mts"
11+
"../src/diagnostics-channel-esm.mts",
12+
"../src/diagnostics-channel-browser.mts"
1213
],
1314
"compilerOptions": {
1415
"outDir": "../.tshy-build/esm/node"

.tshy/esm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
],
99
"exclude": [
1010
"../src/package.json",
11-
"../src/diagnostics-channel-node.mts"
11+
"../src/diagnostics-channel-node.mts",
12+
"../src/diagnostics-channel-browser.mts"
1213
],
1314
"compilerOptions": {
1415
"outDir": "../.tshy-build/esm"

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"types": "./dist/commonjs/index.d.ts",
3535
"tshy": {
3636
"esmDialects": [
37-
"node"
37+
"node",
38+
"browser"
3839
],
3940
"exports": {
4041
"./raw": "./src/index.ts",
@@ -85,6 +86,10 @@
8586
"types": "./dist/esm/node/index.d.ts",
8687
"default": "./dist/esm/node/index.js"
8788
},
89+
"browser": {
90+
"types": "./dist/esm/browser/index.d.ts",
91+
"default": "./dist/esm/browser/index.js"
92+
},
8893
"types": "./dist/esm/index.d.ts",
8994
"default": "./dist/esm/index.js"
9095
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// this is used in ESM environments that follow the 'browser' import
2+
// condition, to avoid even trying to load node:diagnostics_channel
3+
import {
4+
type Channel,
5+
type TracingChannel,
6+
} from 'node:diagnostics_channel'
7+
export type { TracingChannel, Channel }
8+
9+
const dummy = { hasSubscribers: false }
10+
export const metrics = dummy as Channel<unknown>
11+
export const tracing = dummy as TracingChannel<unknown>

0 commit comments

Comments
 (0)