Skip to content

Commit 697686c

Browse files
committed
feat: bundle esm/cjs properly
1 parent 8016335 commit 697686c

File tree

6 files changed

+39
-20
lines changed

6 files changed

+39
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ _workbench.ts
1010
temp
1111
.next
1212
docs
13-
13+
package.tgz

build/copy.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {copyFileSync, readdirSync} from 'node:fs';
2+
import {join} from 'node:path';
3+
import {fileURLToPath} from 'node:url';
4+
5+
const dist = join(fileURLToPath(import.meta.url), '..', '..', 'dist');
6+
7+
const utils = readdirSync(join(dist, 'utils'));
8+
9+
const copy = (from, to) => {
10+
copyFileSync(join(dist, from), join(dist, to));
11+
};
12+
13+
copy('index.d.ts', 'index.d.cts');
14+
15+
for (const util of utils) {
16+
copy(`utils/${util}/index.d.ts`, `utils/${util}/index.d.cts`);
17+
}
18+
19+
copy('node/index.d.ts', 'node/index.d.cts');

package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
"version": "1.28.1",
44
"type": "module",
55
"main": "./dist/index.cjs",
6-
"types": "./dist/index.d.ts",
76
"module": "./dist/index.js",
87
"exports": {
98
".": {
109
"node": {
1110
"import": "./dist/node/index.js",
12-
"require": "./dist/node/index.cjs",
13-
"types": "./dist/index.d.ts"
11+
"require": "./dist/node/index.cjs"
1412
},
1513
"import": "./dist/index.js",
16-
"browser": "./dist/index.js",
17-
"require": "./dist/index.cjs",
18-
"types": "./dist/index.d.ts"
14+
"require": "./dist/index.cjs"
1915
},
2016
"./utils/zod": {
2117
"import": "./dist/utils/zod/index.js",
22-
"require": "./dist/utils/zod/index.cjs",
23-
"types": "./dist/utils/zod/index.d.ts"
18+
"require": "./dist/utils/zod/index.cjs"
2419
}
2520
},
2621
"repository": "https://github.com/hopinc/js.git",
@@ -40,7 +35,7 @@
4035
"utils"
4136
],
4237
"scripts": {
43-
"build": "rm -rf dist && tsup",
38+
"build": "rm -rf dist && tsup && node ./build/copy.js",
4439
"bench": "HOP_DEBUG=true tsx _workbench.ts",
4540
"release": "yarn build && yarn changeset publish",
4641
"api": "yarn build && api-extractor run --local --verbose",

src/sdks/ignite.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {Infer, create} from '@onehop/json-methods';
2-
import {API, Id, assertId} from '../rest/index.ts';
1+
import {type Infer, create} from '@onehop/json-methods';
2+
import {API, type Id, assertId} from '../rest/index.ts';
33
import {
4-
Deployment,
5-
DeploymentConfig,
6-
DeploymentMetaData,
7-
Gateway,
4+
type Deployment,
5+
type DeploymentConfig,
6+
type DeploymentMetadata,
7+
type Gateway,
88
GatewayType,
99
RuntimeType,
1010
} from '../rest/types/ignite.ts';
@@ -479,7 +479,7 @@ export const ignite = sdk(client => {
479479

480480
async patchMetadata(
481481
deploymentId: Id<'deployment'>,
482-
metadata: Partial<DeploymentMetaData>,
482+
metadata: Partial<DeploymentMetadata>,
483483
) {
484484
const {deployment} = await client.patch(
485485
'/v1/ignite/deployments/:deployment_id/metadata',

tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
"verbatimModuleSyntax": true
2727
},
2828
"exclude": ["node_modules", "dist"],
29-
"include": ["./**/*.ts", "./**/*.tsx"]
29+
"include": [
30+
"./**/*.ts",
31+
"./**/*.tsx",
32+
"dist/index.d.cts",
33+
"dist/utils/zod/index.d.cts"
34+
]
3035
}

tsup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ const define = ({node = false} = {}) => ({
2121
export default defineConfig([
2222
{
2323
...commonBuild,
24-
entry: ['src/index.ts', 'src/utils/*/index.ts'],
24+
entry: ['./src/index.ts', './src/utils/*/index.ts'],
2525
define: define(),
2626
},
2727
{
2828
...commonBuild,
2929
entry: ['src/index.ts'],
30-
outDir: 'dist/node',
30+
outDir: './dist/node',
3131
define: define({
3232
node: true,
3333
}),

0 commit comments

Comments
 (0)