Skip to content

Commit 1478ce3

Browse files
author
Arvid Nicolaas
committed
chore: move from tsup back to tsc to fix the types and dual package hazard
1 parent c499a4d commit 1478ce3

File tree

203 files changed

+1278
-1408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+1278
-1408
lines changed

config/bunnify.mjs

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
import fs from 'fs';
22
import path from 'path';
33

4-
const srcDir = `./src`;
5-
const destDir = `./dist/bun`;
4+
if (process.argv.length <= 2) {
5+
console.log(`\
6+
bunnify: utility to generate source code from a "verbatimModuleSyntax" project that
7+
is compatible with other frameworks or suitable for compilation to other frameworks
8+
9+
usage: bunnify <options>
10+
11+
available options:
12+
-mode bun sets default values to create bun-compatible code
13+
-mode cjs sets default values to create cjs-compilation compatible code
14+
-src <folder> (default: './src') the source path of the code
15+
-dest <folder> (default: './dist') the target path of the code
16+
-fileSourceExt <ext> (default: '.mts' )the file extension for the source files
17+
-fileTargetExt (default: '.mts') the file extension for the target files
18+
-sourceImportExt (default: '.mjs') the extension of the imports in the code
19+
-sourceTargetExt (default: '.mjs') the target extension of the imports in the code
20+
-removePrivate (default: 'false') replace private identifiers by non-private ones
21+
`);
22+
process.exit(1);
23+
}
24+
25+
let args = process.argv.slice(2);
26+
27+
let options = {};
28+
29+
while (args.length > 0) {
30+
const [option, value] = args;
31+
options[option.slice(1)] = value;
32+
args = args.slice(2);
33+
}
34+
35+
if (options.mode) {
36+
if (options.mode === 'bun') {
37+
options = {
38+
src: './src',
39+
dest: './dist/bun',
40+
fileSourceExt: '.mts',
41+
fileTargetExt: '.mts',
42+
sourceImportExt: '.mjs',
43+
sourceTargetExt: '.mts',
44+
removePrivate: 'false',
45+
...options,
46+
};
47+
} else if (options.mode === 'cjs') {
48+
options = {
49+
src: './src',
50+
dest: './_cjs_prepare',
51+
fileSourceExt: '.mts',
52+
fileTargetExt: '.cts',
53+
sourceImportExt: '.mjs',
54+
sourceTargetExt: '.cjs',
55+
removePrivate: 'true',
56+
...options,
57+
};
58+
} else {
59+
console.log(
60+
'bunnify: unknown options supplied to -mode. options are `bun` or `cjs`'
61+
);
62+
process.exit(1);
63+
}
64+
}
665

766
function* traverse(src) {
867
const files = fs.readdirSync(src);
@@ -19,17 +78,20 @@ function* traverse(src) {
1978
}
2079

2180
try {
22-
fs.rmSync(destDir, { recursive: true, force: true });
81+
fs.rmSync(options.dest, { recursive: true, force: true });
2382

24-
fs.mkdirSync(destDir, { force: true, recursive: true });
83+
fs.mkdirSync(options.dest, { force: true, recursive: true });
2584

26-
const srcLen = srcDir.length;
85+
const srcLen = options.src.length;
2786

28-
for (const file of traverse(srcDir)) {
29-
if (file.endsWith('.mts')) {
87+
for (const file of traverse(options.src)) {
88+
if (file.endsWith(options.fileSourceExt)) {
3089
const relativePath = file.slice(srcLen - 1);
3190

32-
const fullDestPath = path.join(destDir, relativePath);
91+
const fullDestPath = path.join(
92+
options.dest,
93+
relativePath.replace(options.fileSourceExt, options.fileTargetExt)
94+
);
3395

3496
try {
3597
fs.mkdirSync(path.dirname(fullDestPath), {
@@ -41,7 +103,14 @@ try {
41103
}
42104

43105
const contents = fs.readFileSync(file, { encoding: 'utf-8' });
44-
const result = contents.replaceAll('.mjs', '.mts');
106+
let result = contents.replaceAll(
107+
options.sourceImportExt,
108+
options.sourceTargetExt
109+
);
110+
111+
if (options.removePrivate === 'true') {
112+
result = result.replaceAll(/#(\w+)/g, '___$1');
113+
}
45114

46115
fs.writeFileSync(fullDestPath, result, { encoding: 'utf-8' });
47116
}

config/tsconfig.cjs.base.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.common.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"verbatimModuleSyntax": false,
6+
"target": "ES5",
7+
"module": "CommonJS",
8+
"moduleResolution": "Node10"
9+
}
10+
}

config/tsconfig.esm.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.common.json",
33
"compilerOptions": {
4-
"declaration": false
4+
"declaration": true
55
}
66
}

config/tsconfig.extractor.base.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
{
22
"extends": "./tsconfig.common.json",
33
"compilerOptions": {
4-
"declaration": false
4+
"declaration": false,
5+
"rootDir": "..",
6+
"baseUrl": "./packages",
7+
"paths": {
8+
"@rimbu/bimap": ["bimap/dist/esm/main/index.d.mts"],
9+
"@rimbu/bimultimap": ["bimultimap/dist/esm/main/index.d.mts"],
10+
"@rimbu/collection-types": ["collection-types/dist/esm/main/index.d.mts"],
11+
"@rimbu/common": ["common/dist/esm/index.d.mts"],
12+
"@rimbu/core": ["core/dist/esm/main/index.d.mts"],
13+
"@rimbu/deep": ["deep/dist/esm/index.d.mts"],
14+
"@rimbu/graph": ["graph/dist/esm/main/index.d.mts"],
15+
"@rimbu/hashed": ["hashed/dist/esm/main/index.d.mts"],
16+
"@rimbu/list": ["list/dist/esm/main/index.d.mts"],
17+
"@rimbu/multimap": ["multimap/dist/esm/main/index.d.mts"],
18+
"@rimbu/multiset": ["multiset/dist/esm/main/index.d.mts"],
19+
"@rimbu/ordered": ["ordered/dist/esm/main/index.d.mts"],
20+
"@rimbu/proximity": ["proximity/dist/esm/main/index.d.mts"],
21+
"@rimbu/sorted": ["sorted/dist/esm/main/index.d.mts"],
22+
"@rimbu/stream": ["stream/dist/esm/main/index.d.mts"],
23+
"@rimbu/table": ["table/dist/esm/main/index.d.mts"]
24+
}
525
}
626
}

config/tsconfig.types.base.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

deno_dist/actor/immer/slice-immer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDraft, finishDraft } from 'npm:immer@9.0.21';
1+
import { createDraft, finishDraft } from 'npm:immer@10.0.3';
22

33
import { Action, SliceConfig } from '../../actor/mod.ts';
44

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"rimraf": "^5.0.1",
6767
"ts-node": "^10.9.1",
6868
"tsd": "^0.30.4",
69-
"tsup": "^8.0.1",
7069
"typescript": "^5.3.3",
7170
"vite-tsconfig-paths": "^4.3.1",
7271
"vitest": "^1.2.1"

packages/actor/immer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"private": true,
44
"main": "../dist/cjs/immer/index.cjs",
55
"module": "../dist/esm/immer/index.mjs",
6-
"types": "../dist/types/immer/index.d.mts"
6+
"types": "../dist/cjs/immer/index.d.cts"
77
}

packages/actor/package.json

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,56 +30,62 @@
3030
"type": "module",
3131
"main": "./dist/cjs/main/index.cjs",
3232
"module": "./dist/esm/main/index.mjs",
33-
"types": "./dist/types/main/index.d.mts",
33+
"types": "./dist/cjs/main/index.d.cts",
3434
"exports": {
3535
".": {
36-
"types": "./dist/types/main/index.d.mts",
37-
"bun": "./dist/bun/main/index.mts",
38-
"import": "./dist/esm/main/index.mjs",
39-
"require": "./dist/cjs/main/index.cjs",
40-
"default": "./dist/esm/main/index.mjs"
36+
"import": {
37+
"types": "./dist/esm/main/index.d.mts",
38+
"default": "./dist/esm/main/index.mjs"
39+
},
40+
"require": {
41+
"types": "./dist/cjs/main/index.d.cts",
42+
"default": "./dist/cjs/main/index.cjs"
43+
},
44+
"bun": "./dist/bun/main/index.mts"
4145
},
4246
"./immer": {
43-
"types": "./dist/types/immer/index.d.mts",
44-
"bun": "./dist/bun/immer/index.mts",
45-
"import": "./dist/esm/immer/index.mjs",
46-
"require": "./dist/cjs/immer/index.cjs",
47-
"default": "./dist/esm/immer/index.mjs"
47+
"import": {
48+
"types": "./dist/esm/immer/index.d.mts",
49+
"default": "./dist/esm/immer/index.mjs"
50+
},
51+
"require": {
52+
"types": "./dist/cjs/immer/index.d.cts",
53+
"default": "./dist/cjs/immer/index.cjs"
54+
},
55+
"bun": "./dist/bun/immer/index.mts"
4856
},
4957
"./patch": {
50-
"types": "./dist/types/patch/index.d.mts",
51-
"bun": "./dist/bun/patch/index.mts",
52-
"import": "./dist/esm/patch/index.mjs",
53-
"require": "./dist/cjs/patch/index.cjs",
54-
"default": "./dist/esm/patch/index.mjs"
55-
},
56-
"./stream": {
57-
"types": "./dist/types/stream/index.d.mts",
58-
"bun": "./dist/bun/stream/index.mts",
59-
"import": "./dist/esm/stream/index.mjs",
60-
"require": "./dist/cjs/stream/index.cjs",
61-
"default": "./dist/esm/stream/index.mjs"
58+
"import": {
59+
"types": "./dist/esm/patch/index.d.mts",
60+
"default": "./dist/esm/patch/index.mjs"
61+
},
62+
"require": {
63+
"types": "./dist/cjs/patch/index.d.cts",
64+
"default": "./dist/cjs/patch/index.cjs"
65+
},
66+
"bun": "./dist/bun/patch/index.mts"
6267
}
6368
},
6469
"files": [
6570
"dist",
6671
"src",
6772
"immer",
68-
"patch",
69-
"stream"
73+
"patch"
7074
],
7175
"scripts": {
7276
"build": "yarn clean && yarn bundle",
7377
"build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
74-
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:types && yarn bundle:bun",
75-
"bundle:bun": "node ../../config/bunnify.mjs",
76-
"bundle:cjs": "tsup src --format cjs --clean -d dist/cjs --loader '.mts=ts' --external @rimbu/base --external @rimbu/stream",
78+
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
79+
"bundle:bun": "node ../../config/bunnify.mjs -mode bun",
80+
"bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
81+
"bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
82+
"bundle:cjs-build": "tsc -p tsconfig.cjs.json",
83+
"bundle:cjs-clean": "rimraf _cjs_prepare",
7784
"bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
7885
"bundle:deno-convert": "denoify --src _deno_prepare/src",
7986
"bundle:deno-move": "rimraf ../../deno_dist/actor && mv deno_dist ../../deno_dist/actor",
8087
"bundle:deno-clean": "rimraf _deno_prepare",
8188
"bundle:esm": "tsc --p tsconfig.esm.json",
82-
"bundle:types": "tsc --p tsconfig.types.json",
8389
"clean": "rimraf dist",
8490
"format": "yarn format:base --write",
8591
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
@@ -100,6 +106,9 @@
100106
"devDependencies": {
101107
"@rimbu/stream": "^2.1.0",
102108
"happy-dom": "^9.20.3",
103-
"immer": "^9.0.16"
109+
"immer": "^10.0.3"
110+
},
111+
"optionalDependencies": {
112+
"immer": "^10.0.3"
104113
}
105114
}

packages/actor/patch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"private": true,
44
"main": "../dist/cjs/patch/index.cjs",
55
"module": "../dist/esm/patch/index.mjs",
6-
"types": "../dist/types/patch/index.d.mts"
6+
"types": "../dist/cjs/patch/index.d.cts"
77
}

0 commit comments

Comments
 (0)