build-ts 17.1.31 → 17.1.32

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.
Files changed (3) hide show
  1. package/NOTICE +15 -0
  2. package/README.md +96 -58
  3. package/package.json +14 -10
package/NOTICE ADDED
@@ -0,0 +1,15 @@
1
+ build-ts
2
+
3
+ Copyright (c) 2022 WillBooster Inc. and contributors.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md CHANGED
@@ -3,99 +3,137 @@
3
3
  [![Test](https://github.com/WillBooster/build-ts/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/build-ts/actions/workflows/test.yml)
4
4
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
5
5
 
6
- An opinionated tool for building a Node.js app and library written in TypeScript.
6
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
7
7
 
8
- ## Features
8
+ An opinionated, low-config build tool for Node.js applications and libraries written in TypeScript, powered by [Rolldown](https://rolldown.rs/).
9
9
 
10
- - Builder / Bundler (`rolldown` wrapper)
11
- - [x] `build-ts app`
12
- - [x] Bundle TypeScript code as Node.js application
13
- - [x] `build-ts functions`
14
- - [x] Bundle TypeScript code as GCP/Firebase Functions
15
- - [x] Generate optimized `package.json` for Functions
16
- - [x] `build-ts lib`
17
- - [x] Bundle TypeScript code as Node.js / Pure JavaScript / React Library
18
- - [x] Remove global `console` calls automatically without Babel
19
- - Executor (`tsx` wrapper)
20
- - [x] `build-ts run <TypeScript file>`
21
- - [x] Run TypeScript code as Node.js script
10
+ ## Highlights
22
11
 
23
- ## Build Toolchain
12
+ - **No build-ts-specific config** — point it at a package and it bundles `src/index.{ts,tsx,cts,mts}` into `dist/` with sensible defaults (minification, sourcemaps, and tree-shaking enabled).
13
+ - **Fast by design** — bundling is handled by Rolldown, declaration files are generated by `tsgo` ([TypeScript native preview](https://github.com/microsoft/typescript-go)), and console removal uses [Oxc](https://oxc.rs/) parsing. Babel is used only for features that require it, such as `core-js` polyfill injection and decorator transforms.
14
+ - **Multiple targets** — Node.js apps, GCP/Firebase Functions, and Node.js / browser / React libraries.
15
+ - **Dual-format libraries** — emits CommonJS and ES modules side by side, with configurable file extensions (`.js` / `.cjs` / `.mjs`).
16
+ - **TypeScript runner** — executes TypeScript files directly via [tsx](https://tsx.is/) (or Bun when running on Bun).
24
17
 
25
- `build-ts` uses `rolldown` as the bundler. It no longer depends on Rollup or Rollup plugins for normal builds.
18
+ ## Requirements
26
19
 
27
- The build pipeline keeps Babel out of the hot path as much as possible:
20
+ - Node.js >= 24
28
21
 
29
- - JavaScript and TypeScript bundling is handled by Rolldown.
30
- - Declaration files are generated by `tsgo`.
31
- - Global `console` removal is implemented as a Rolldown plugin using Oxc parsing, not `babel-plugin-transform-remove-console`.
32
- - Babel is still used only for features that currently require it, such as `core-js` polyfill injection or decorator transforms.
22
+ ## Usage
33
23
 
34
- ## Console Removal
24
+ `build-ts` works without installation via `npx build-ts` (or `yarn dlx build-ts`), or can be added as a dev dependency:
35
25
 
36
- `build-ts app`, `build-ts functions`, and `build-ts lib` remove global `console` calls during production builds by default. The build command sets `NODE_ENV=production` when `NODE_ENV` is not already set.
26
+ ```sh
27
+ npm install --save-dev build-ts
28
+ ```
37
29
 
38
- The restored behavior follows the previous Babel-based `transform-remove-console` behavior:
30
+ ### Build a Node.js application
39
31
 
40
- - In `production`, `console.log`, `console.debug`, and other non-excluded global console methods are removed. `console.error`, `console.info`, and `console.warn` are preserved.
41
- - In `test`, `console.log` and other non-excluded methods are removed. `console.debug`, `console.error`, `console.info`, and `console.warn` are preserved.
42
- - If `NODE_ENV` is set to another value, console removal is disabled.
43
- - Local bindings named `console` are preserved, including function parameters, imports, `let`/`const`/`var`, classes, namespaces, switch scopes, and other shadowing forms.
32
+ Bundles the app into a single directory, `dist/`:
44
33
 
45
- There is no `--drop-console` option. Console removal is controlled by `NODE_ENV` to preserve the historical behavior.
34
+ ```sh
35
+ npx build-ts app [package]
36
+ ```
46
37
 
47
- ## Node.js Application
38
+ ### Build GCP/Firebase Functions
48
39
 
49
- `npx build-ts app [project path]`, e.g.,
40
+ Bundles the functions and generates an optimized `package.json` for deployment in `dist/` (removing `scripts` and `devDependencies`):
50
41
 
51
42
  ```sh
52
- npx build-ts app test/fixtures/app-node
53
- # or
54
- cd test/fixtures/app-node && npx build-ts app
43
+ npx build-ts functions [package]
55
44
  ```
56
45
 
57
- ## Firebase Functions
46
+ To generate only the optimized `package.json` without bundling:
58
47
 
59
- `npx build-ts functions [project path]`, e.g.,
48
+ ```sh
49
+ npx build-ts functions --only-package-json
50
+ ```
51
+
52
+ ### Build a Node.js / browser / React library
53
+
54
+ Bundles the library into `dist/` with `.d.ts` declaration files, preserving the module structure of `src/`:
60
55
 
61
56
  ```sh
62
- npx build-ts app test/fixtures/functions
63
- # or
64
- cd test/fixtures/functions && npx build-ts app
57
+ npx build-ts lib [package]
65
58
  ```
66
59
 
67
- ## Node.js / Browser Library
60
+ React libraries are detected automatically when `src/` contains `.tsx` files.
61
+
62
+ Declaration file generation requires a `tsconfig.json` in the package directory (or an ancestor directory).
63
+
64
+ ### Run a TypeScript file
68
65
 
69
- `npx build-ts lib [project path]`, e.g.,
66
+ Runs a TypeScript file directly, passing along any arguments after `--`:
70
67
 
71
68
  ```sh
72
- npx build-ts lib test/fixtures/lib
73
- # or
74
- cd test/fixtures/lib && npx build-ts lib
69
+ npx build-ts run src/main.ts -- --foo bar
75
70
  ```
76
71
 
77
- ## React Library
72
+ ## Options
73
+
74
+ ### Common build options (`app`, `functions`, and `lib`)
75
+
76
+ | Option | Alias | Default | Description |
77
+ | -------------------------------- | ----- | -------- | ------------------------------------------------------------------------------------------------------ |
78
+ | `--input` | `-i` | (auto) | Source files to build. The first file is the main entry. Defaults to `src/index.{ts,tsx,cts,mts}`. |
79
+ | `--module-type` | `-m` | (varies) | Output module format: `esm`, `cjs`, `either` (follow `package.json`'s `type`), or `both` (`lib` only). |
80
+ | `--minify` / `--no-minify` | | `true` | Enable/disable minification. |
81
+ | `--sourcemap` / `--no-sourcemap` | | `true` | Enable/disable sourcemaps. |
82
+ | `--watch` | `-w` | `false` | Rebuild on file changes. |
83
+ | `--external` | | | Additional dependencies to keep external (not bundled). |
84
+ | `--core-js` | | `false` | Inject `core-js` polyfills via Babel. |
85
+ | `--core-js-proposals` | | `false` | Inject `core-js` polyfills including proposals via Babel. |
86
+ | `--inline` | | | Names of environment variables to inline into the bundle. |
87
+ | `--auto-inline` | | `false` | Inline all environment variables defined in `.env` files. |
88
+ | `--keep-import` | | | Identifiers to keep as import statements. |
89
+ | `--bundle-builtins` | | | Module names that shadow Node.js builtins (e.g., `undici`) to be bundled. |
90
+ | `--silent` | `-s` | `false` | Suppress non-error output. |
78
91
 
79
- `npx build-ts lib [project path]`, e.g.,
92
+ ### `functions`-specific options
93
+
94
+ | Option | Alias | Default | Description |
95
+ | --------------------- | ----- | ------- | ------------------------------------------------------- |
96
+ | `--only-package-json` | | `false` | Generate only the optimized `package.json` for `dist/`. |
97
+
98
+ ### `lib`-specific options
99
+
100
+ | Option | Alias | Default | Description |
101
+ | ---------------- | ----- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
102
+ | `--js-extension` | `-j` | `either` | Which format uses the `.js` extension: `either`, `both`, or `none`. Other formats use `.cjs` / `.mjs`. Avoid `both` together with `--module-type both`, since the two formats would write the same `.js` files. |
103
+
104
+ Run `npx build-ts <command> --help` for the full list of options, including environment-variable handling shared with other WillBooster tools.
105
+
106
+ ## Console Removal
107
+
108
+ `build-ts app`, `build-ts functions`, and `build-ts lib` remove global `console` calls during production builds. The build command sets `NODE_ENV=production` when `NODE_ENV` is not already set.
109
+
110
+ - When `NODE_ENV` is `production`, `console.log`, `console.debug`, and other non-excluded global console methods are removed; `console.error`, `console.info`, and `console.warn` are preserved.
111
+ - When `NODE_ENV` is `test`, `console.log` and other non-excluded methods are removed; `console.debug`, `console.error`, `console.info`, and `console.warn` are preserved.
112
+ - When `NODE_ENV` is any other value, console removal is disabled.
113
+ - Local bindings named `console` (function parameters, imports, `let`/`const`/`var` declarations, classes, and other shadowing forms) are always preserved.
114
+
115
+ Console removal is controlled solely by `NODE_ENV`; there is no `--drop-console` option.
116
+
117
+ ## Examples
118
+
119
+ The [`test/fixtures`](test/fixtures) directory contains ready-to-build sample projects:
80
120
 
81
121
  ```sh
122
+ npx build-ts app test/fixtures/app-node
123
+ npx build-ts functions test/fixtures/functions
124
+ npx build-ts lib test/fixtures/lib
82
125
  npx build-ts lib test/fixtures/lib-react
83
- # or
84
- cd test/fixtures/lib-react && npx build-ts lib
85
126
  ```
86
127
 
87
- ## Run TypeScript code with arguments
128
+ ## Development
88
129
 
89
130
  ```sh
90
- echo "console.log(process.argv)" > example.ts
91
- npx build-ts run example.ts -- --foo bar
131
+ yarn # install dependencies
132
+ yarn test # run tests
133
+ yarn verify # type check and lint
134
+ yarn verify-full # type check, lint, and all tests
92
135
  ```
93
136
 
94
- The output is like this:
137
+ ## License
95
138
 
96
- ```
97
- [ '/path/to/node',
98
- '/path/to/build-ts/dist/bin/run.js',
99
- '--foo',
100
- 'bar' ]
101
- ```
139
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE) for details.
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "build-ts",
3
- "version": "17.1.31",
3
+ "version": "17.1.32",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WillBooster/build-ts.git"
7
7
  },
8
- "license": "UNLICENSED",
8
+ "license": "Apache-2.0",
9
9
  "author": "WillBooster Inc.",
10
10
  "type": "module",
11
11
  "bin": "bin/index.js",
12
12
  "files": [
13
13
  "bin/",
14
14
  "dist/",
15
- "babel.*"
15
+ "babel.*",
16
+ "NOTICE"
16
17
  ],
17
18
  "scripts": {
18
19
  "build": "wb buildIfNeeded --command 'yarn start app'",
@@ -36,14 +37,13 @@
36
37
  "@babel/preset-env": "8.0.2",
37
38
  "@babel/preset-react": "8.0.1",
38
39
  "@babel/preset-typescript": "8.0.1",
39
- "@typescript/native-preview": "7.0.0-dev.20260620.1",
40
40
  "@willbooster/shared-lib-node": "8.5.23",
41
41
  "babel-plugin-polyfill-corejs3": "1.0.0",
42
42
  "core-js": "3.49.0",
43
43
  "core-js-pure": "3.49.0",
44
44
  "magic-string": "0.30.21",
45
45
  "oxc-parser": "0.137.0",
46
- "rolldown": "1.1.2",
46
+ "rolldown": "1.1.4",
47
47
  "signal-exit": "4.1.0",
48
48
  "tsx": "4.22.4",
49
49
  "yargs": "18.0.0"
@@ -55,20 +55,24 @@
55
55
  "@types/yargs": "17.0.35",
56
56
  "@willbooster/oxfmt-config": "1.2.2",
57
57
  "@willbooster/oxlint-config": "1.4.8",
58
- "@willbooster/wb": "13.22.19",
59
- "build-ts": "17.1.30",
58
+ "@willbooster/wb": "13.26.0",
59
+ "build-ts": "17.1.31",
60
60
  "conventional-changelog-conventionalcommits": "9.3.1",
61
61
  "lefthook": "2.1.9",
62
- "oxfmt": "0.57.0",
63
- "oxlint": "1.72.0",
62
+ "oxfmt": "0.58.0",
63
+ "oxlint": "1.73.0",
64
64
  "oxlint-tsgolint": "0.24.0",
65
65
  "semantic-release": "25.0.5",
66
66
  "sort-package-json": "4.0.0",
67
67
  "type-fest": "5.7.0",
68
+ "typescript": "7.0.2",
68
69
  "vitest": "4.1.9"
69
70
  },
70
- "packageManager": "yarn@4.17.0",
71
+ "packageManager": "yarn@4.17.1",
71
72
  "engines": {
72
73
  "node": ">=24"
74
+ },
75
+ "publishConfig": {
76
+ "access": "public"
73
77
  }
74
78
  }