ts-builds 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/dist/cli.js +45 -9
- package/dist/vite.config.base.js +17 -0
- package/package.json +13 -7
- package/prettier-config.cjs +18 -0
- package/prettier-config.js +0 -12
package/README.md
CHANGED
|
@@ -65,8 +65,9 @@ npx ts-builds typecheck # TypeScript type checking
|
|
|
65
65
|
npx ts-builds test # Run tests once
|
|
66
66
|
npx ts-builds test:watch # Watch mode
|
|
67
67
|
npx ts-builds test:coverage # With coverage
|
|
68
|
-
npx ts-builds build # Production build
|
|
69
|
-
npx ts-builds dev #
|
|
68
|
+
npx ts-builds build # Production build (tsdown or vite)
|
|
69
|
+
npx ts-builds dev # Dev mode (tsdown --watch or vite dev server)
|
|
70
|
+
npx ts-builds preview # Preview production build (vite preview)
|
|
70
71
|
```
|
|
71
72
|
|
|
72
73
|
## Package.json Scripts
|
|
@@ -119,6 +120,27 @@ If your project uses ESLint plugins not bundled with ts-builds (e.g., `eslint-pl
|
|
|
119
120
|
|
|
120
121
|
This tells ts-builds to use your project's ESLint installation instead of the bundled version.
|
|
121
122
|
|
|
123
|
+
### For SPAs/React Apps (Vite)
|
|
124
|
+
|
|
125
|
+
Use Vite instead of tsdown for SPA builds:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm add -D ts-builds vite
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"srcDir": "./src",
|
|
134
|
+
"buildMode": "vite"
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
With `buildMode: "vite"`:
|
|
139
|
+
|
|
140
|
+
- `ts-builds build` → `vite build`
|
|
141
|
+
- `ts-builds dev` → `vite` (dev server with HMR)
|
|
142
|
+
- `ts-builds preview` → `vite preview`
|
|
143
|
+
|
|
122
144
|
### Advanced (Monorepos, Custom Commands)
|
|
123
145
|
|
|
124
146
|
```json
|
|
@@ -195,6 +217,20 @@ export default baseConfig
|
|
|
195
217
|
}
|
|
196
218
|
```
|
|
197
219
|
|
|
220
|
+
### Vite (for SPAs)
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// vite.config.ts
|
|
224
|
+
import { vite } from "ts-builds/vite"
|
|
225
|
+
import { defineConfig, mergeConfig } from "vite"
|
|
226
|
+
|
|
227
|
+
export default defineConfig(
|
|
228
|
+
mergeConfig(vite, {
|
|
229
|
+
// your customizations
|
|
230
|
+
}),
|
|
231
|
+
)
|
|
232
|
+
```
|
|
233
|
+
|
|
198
234
|
## Bundled Packages
|
|
199
235
|
|
|
200
236
|
Run `npx ts-builds info` to see all bundled packages. You don't need to install:
|
package/dist/cli.js
CHANGED
|
@@ -29,6 +29,7 @@ function loadConfig() {
|
|
|
29
29
|
return {
|
|
30
30
|
srcDir: userConfig.srcDir ?? "./src",
|
|
31
31
|
testDir: userConfig.testDir ?? "./test",
|
|
32
|
+
buildMode: userConfig.buildMode ?? "tsdown",
|
|
32
33
|
lint: { useProjectEslint: userConfig.lint?.useProjectEslint ?? false },
|
|
33
34
|
commands,
|
|
34
35
|
chains
|
|
@@ -136,9 +137,10 @@ SCRIPT COMMANDS:
|
|
|
136
137
|
test:watch Run tests in watch mode
|
|
137
138
|
test:coverage Run tests with coverage
|
|
138
139
|
test:ui Launch Vitest UI
|
|
139
|
-
build Production build (
|
|
140
|
+
build Production build (tsdown or vite build, based on buildMode)
|
|
140
141
|
build:watch Watch mode build
|
|
141
|
-
dev
|
|
142
|
+
dev Development mode (tsdown --watch or vite dev server)
|
|
143
|
+
preview Preview production build (vite preview)
|
|
142
144
|
|
|
143
145
|
CONFIGURATION:
|
|
144
146
|
Create ts-builds.config.json in your project root:
|
|
@@ -149,6 +151,12 @@ CONFIGURATION:
|
|
|
149
151
|
"validateChain": ["format", "lint", "typecheck", "test", "build"]
|
|
150
152
|
}
|
|
151
153
|
|
|
154
|
+
For SPAs/React apps using Vite:
|
|
155
|
+
{
|
|
156
|
+
"srcDir": "./src",
|
|
157
|
+
"buildMode": "vite"
|
|
158
|
+
}
|
|
159
|
+
|
|
152
160
|
With custom ESLint plugins (e.g., eslint-plugin-functional):
|
|
153
161
|
{
|
|
154
162
|
"srcDir": "./src",
|
|
@@ -198,13 +206,22 @@ ${bundledPackages.map((pkg) => ` - ${pkg}`).join("\n")}
|
|
|
198
206
|
|
|
199
207
|
You ONLY need to install:
|
|
200
208
|
- ts-builds (this package)
|
|
201
|
-
- tsdown (peer dependency, optional)
|
|
209
|
+
- tsdown (peer dependency, for library builds - optional)
|
|
210
|
+
- vite (peer dependency, for SPA builds - optional)
|
|
211
|
+
|
|
212
|
+
Example minimal package.json for libraries:
|
|
213
|
+
{
|
|
214
|
+
"devDependencies": {
|
|
215
|
+
"ts-builds": "^3.0.0",
|
|
216
|
+
"tsdown": "^0.19.0"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
202
219
|
|
|
203
|
-
Example minimal package.json
|
|
220
|
+
Example minimal package.json for SPAs/React apps:
|
|
204
221
|
{
|
|
205
222
|
"devDependencies": {
|
|
206
223
|
"ts-builds": "^3.0.0",
|
|
207
|
-
"
|
|
224
|
+
"vite": "^7.0.0"
|
|
208
225
|
}
|
|
209
226
|
}
|
|
210
227
|
`);
|
|
@@ -289,6 +306,7 @@ function createConfig(force = false) {
|
|
|
289
306
|
Configuration options:
|
|
290
307
|
srcDir Source directory for linting (default: "./src")
|
|
291
308
|
testDir Test directory (default: "./test")
|
|
309
|
+
buildMode "tsdown" (default, libraries) or "vite" (SPAs/React apps)
|
|
292
310
|
lint Lint settings: { "useProjectEslint": true }
|
|
293
311
|
validateChain Commands to run for validate (default shown above)
|
|
294
312
|
commands Custom commands: { "name": "shell command" }
|
|
@@ -335,13 +353,25 @@ async function runTest(mode = "run") {
|
|
|
335
353
|
}
|
|
336
354
|
}
|
|
337
355
|
async function runBuild(watch = false) {
|
|
356
|
+
if (loadConfig().buildMode === "vite") {
|
|
357
|
+
if (watch) return runCommand("vite", ["build", "--watch"]);
|
|
358
|
+
const cleanCode$1 = await runCommand("rimraf", ["dist"]);
|
|
359
|
+
if (cleanCode$1 !== 0) return cleanCode$1;
|
|
360
|
+
return runCommand("vite", ["build"]);
|
|
361
|
+
}
|
|
338
362
|
if (watch) return runCommand("tsdown", ["--watch"]);
|
|
339
363
|
const cleanCode = await runCommand("rimraf", ["dist"]);
|
|
340
364
|
if (cleanCode !== 0) return cleanCode;
|
|
341
365
|
return runCommand("cross-env", ["NODE_ENV=production", "tsdown"]);
|
|
342
366
|
}
|
|
367
|
+
async function runDev() {
|
|
368
|
+
return loadConfig().buildMode === "vite" ? runCommand("vite", []) : runCommand("tsdown", ["--watch"]);
|
|
369
|
+
}
|
|
343
370
|
function getBuiltinCommands(config) {
|
|
344
371
|
const eslintCmd = config.lint.useProjectEslint ? "npx eslint" : "eslint";
|
|
372
|
+
const buildCmd = config.buildMode === "vite" ? { run: "rimraf dist && vite build" } : { run: "rimraf dist && cross-env NODE_ENV=production tsdown" };
|
|
373
|
+
const buildWatchCmd = config.buildMode === "vite" ? { run: "vite build --watch" } : { run: "tsdown --watch" };
|
|
374
|
+
const devCmd = config.buildMode === "vite" ? { run: "vite" } : { run: "tsdown --watch" };
|
|
345
375
|
return {
|
|
346
376
|
format: { run: "prettier --write ." },
|
|
347
377
|
"format:check": { run: "prettier --check ." },
|
|
@@ -353,9 +383,10 @@ function getBuiltinCommands(config) {
|
|
|
353
383
|
"test:watch": { run: "vitest" },
|
|
354
384
|
"test:coverage": { run: "vitest run --coverage" },
|
|
355
385
|
"test:ui": { run: "vitest --ui" },
|
|
356
|
-
build:
|
|
357
|
-
"build:watch":
|
|
358
|
-
dev:
|
|
386
|
+
build: buildCmd,
|
|
387
|
+
"build:watch": buildWatchCmd,
|
|
388
|
+
dev: devCmd,
|
|
389
|
+
preview: { run: "vite preview" },
|
|
359
390
|
compile: { run: "tsc" }
|
|
360
391
|
};
|
|
361
392
|
}
|
|
@@ -445,9 +476,14 @@ switch (command) {
|
|
|
445
476
|
process.exit(await runBuild(subCommand === "watch"));
|
|
446
477
|
break;
|
|
447
478
|
case "build:watch":
|
|
448
|
-
case "dev":
|
|
449
479
|
process.exit(await runBuild(true));
|
|
450
480
|
break;
|
|
481
|
+
case "dev":
|
|
482
|
+
process.exit(await runDev());
|
|
483
|
+
break;
|
|
484
|
+
case "preview":
|
|
485
|
+
process.exit(await runCommand("vite", ["preview"]));
|
|
486
|
+
break;
|
|
451
487
|
case "validate":
|
|
452
488
|
process.exit(await runValidate());
|
|
453
489
|
break;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
//#region src/vite.config.base.ts
|
|
4
|
+
/** Base Vite config for SPAs */
|
|
5
|
+
const vite = {
|
|
6
|
+
build: {
|
|
7
|
+
outDir: "dist",
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
target: "es2020",
|
|
10
|
+
minify: process.env.NODE_ENV === "production"
|
|
11
|
+
},
|
|
12
|
+
resolve: { alias: { "@": resolve(process.cwd(), "src") } }
|
|
13
|
+
};
|
|
14
|
+
var vite_config_base_default = vite;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { vite_config_base_default as default, vite };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-builds",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Shared TypeScript configuration files for library templates. Provides standardized ESLint, Prettier, Vitest, TypeScript, and build configs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"prettier",
|
|
11
11
|
"vitest",
|
|
12
12
|
"tsdown",
|
|
13
|
+
"vite",
|
|
13
14
|
"shared-config"
|
|
14
15
|
],
|
|
15
16
|
"author": "jordan.burke@gmail.com",
|
|
@@ -20,23 +21,24 @@
|
|
|
20
21
|
"type": "git",
|
|
21
22
|
"url": "git+https://github.com/jordanburke/ts-builds.git"
|
|
22
23
|
},
|
|
23
|
-
"main": "./prettier-config.
|
|
24
|
+
"main": "./prettier-config.cjs",
|
|
24
25
|
"bin": {
|
|
25
26
|
"ts-builds": "dist/cli.js"
|
|
26
27
|
},
|
|
27
28
|
"exports": {
|
|
28
|
-
".": "./prettier-config.
|
|
29
|
-
"./prettier": "./prettier-config.
|
|
29
|
+
".": "./prettier-config.cjs",
|
|
30
|
+
"./prettier": "./prettier-config.cjs",
|
|
30
31
|
"./prettier-ignore": "./.prettierignore",
|
|
31
32
|
"./eslint": "./eslint.config.base.mjs",
|
|
32
33
|
"./vitest": "./dist/vitest.config.base.js",
|
|
33
34
|
"./tsconfig": "./tsconfig.base.json",
|
|
34
35
|
"./tsdown": "./dist/tsdown.config.base.js",
|
|
36
|
+
"./vite": "./dist/vite.config.base.js",
|
|
35
37
|
"./scripts": "./package-scripts.json",
|
|
36
38
|
"./package.json": "./package.json"
|
|
37
39
|
},
|
|
38
40
|
"files": [
|
|
39
|
-
"prettier-config.
|
|
41
|
+
"prettier-config.cjs",
|
|
40
42
|
".prettierignore",
|
|
41
43
|
"eslint.config.base.mjs",
|
|
42
44
|
"dist",
|
|
@@ -60,7 +62,7 @@
|
|
|
60
62
|
"eslint-plugin-import": "^2.32.0",
|
|
61
63
|
"eslint-plugin-prettier": "^5.5.5",
|
|
62
64
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
63
|
-
"globals": "^
|
|
65
|
+
"globals": "^17.0.0",
|
|
64
66
|
"prettier": "^3.8.0",
|
|
65
67
|
"rimraf": "^6.1.2",
|
|
66
68
|
"ts-node": "^10.9.2",
|
|
@@ -71,11 +73,15 @@
|
|
|
71
73
|
"tsdown": "^0.19.0"
|
|
72
74
|
},
|
|
73
75
|
"peerDependencies": {
|
|
74
|
-
"tsdown": "^0.x"
|
|
76
|
+
"tsdown": "^0.x",
|
|
77
|
+
"vite": "^7.x"
|
|
75
78
|
},
|
|
76
79
|
"peerDependenciesMeta": {
|
|
77
80
|
"tsdown": {
|
|
78
81
|
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"vite": {
|
|
84
|
+
"optional": true
|
|
79
85
|
}
|
|
80
86
|
},
|
|
81
87
|
"scripts": {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shareable Prettier configuration for TypeScript library templates
|
|
3
|
+
*
|
|
4
|
+
* Uses CommonJS format for compatibility with prettier's shareable config feature.
|
|
5
|
+
* When using "prettier": "ts-builds/prettier" in package.json, prettier uses
|
|
6
|
+
* require() internally which doesn't handle ESM default exports properly.
|
|
7
|
+
*
|
|
8
|
+
* @see https://prettier.io/docs/sharing-configurations
|
|
9
|
+
* @see https://github.com/prettier/prettier/issues/15388 - ESM support tracking
|
|
10
|
+
*/
|
|
11
|
+
module.exports = {
|
|
12
|
+
semi: false,
|
|
13
|
+
trailingComma: "all",
|
|
14
|
+
singleQuote: false,
|
|
15
|
+
printWidth: 120,
|
|
16
|
+
tabWidth: 2,
|
|
17
|
+
endOfLine: "auto",
|
|
18
|
+
}
|
package/prettier-config.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shareable Prettier configuration for TypeScript library templates
|
|
3
|
-
* @see https://prettier.io/docs/sharing-configurations
|
|
4
|
-
*/
|
|
5
|
-
export default {
|
|
6
|
-
semi: false,
|
|
7
|
-
trailingComma: "all",
|
|
8
|
-
singleQuote: false,
|
|
9
|
-
printWidth: 120,
|
|
10
|
-
tabWidth: 2,
|
|
11
|
-
endOfLine: "auto",
|
|
12
|
-
}
|