pkgbld 1.36.0 → 2.1.0
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 +71 -89
- package/index.js +2 -2
- package/package.json +31 -27
- package/src/build-configuration.js +406 -0
- package/src/build-entries.js +271 -0
- package/src/build-plugin-lifecycle.js +100 -0
- package/src/builtin-plugins/binify.js +31 -0
- package/src/builtin-plugins/clean.js +30 -0
- package/src/builtin-plugins/commonjs.js +14 -0
- package/src/builtin-plugins/externals.js +108 -0
- package/src/builtin-plugins/json.js +14 -0
- package/src/builtin-plugins/package-imports.js +79 -0
- package/src/builtin-plugins/preprocess.js +37 -0
- package/src/builtin-plugins/resolve.js +22 -0
- package/src/builtin-plugins/terser.js +50 -0
- package/src/eject.js +151 -0
- package/src/get-json.js +16 -0
- package/src/get-plugins.js +44 -0
- package/src/get-rollup-configs.js +261 -0
- package/src/helpers.js +229 -0
- package/src/index.js +133 -0
- package/src/load-plugins.js +37 -0
- package/src/messages.js +13 -0
- package/src/options/index.js +277 -0
- package/src/options/types.js +24 -0
- package/src/package-imports.js +240 -0
- package/src/plugin-name.js +6 -0
- package/src/priorities.js +11 -0
- package/src/process-pkg.js +244 -0
- package/src/process-ts-config.js +80 -0
- package/src/rollup-plugin-preprocess.d.ts +1 -0
- package/src/types.js +175 -0
- package/src/write-json.js +21 -0
- package/types/index.d.ts +310 -0
- package/dist/index.d.ts +0 -79
- package/dist/index.mjs +0 -1626
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npm install --save-dev pkgbld
|
|
|
24
24
|
|
|
25
25
|
1. Start by creating package.json using `npm init`
|
|
26
26
|
2. Add pkgbld `npm install --save-dev pkgbld`
|
|
27
|
-
3. Create `src/index.
|
|
27
|
+
3. Create `src/index.js`
|
|
28
28
|
4. Add pkgbld in the 'scripts' field of your package.json like:
|
|
29
29
|
|
|
30
30
|
```json
|
|
@@ -35,10 +35,38 @@ npm install --save-dev pkgbld
|
|
|
35
35
|
|
|
36
36
|
Run `npm run build`.
|
|
37
37
|
|
|
38
|
+
For TypeScript or TSX sources, also install
|
|
39
|
+
[`pkgbld-plugin-swc`](https://github.com/kshutkin/package-build/tree/main/pkgbld-plugin-swc).
|
|
40
|
+
`pkgbld` discovers the plugin from your project dependencies and uses SWC to strip types.
|
|
41
|
+
|
|
38
42
|
## package.json
|
|
39
43
|
|
|
40
44
|
`pkgbld` expects the name field to be filled in the package.json file. `exports` field defines what entries/outputs should be built for this package.
|
|
41
45
|
|
|
46
|
+
### Private package imports
|
|
47
|
+
|
|
48
|
+
When `package.json` has an `imports` map, `pkgbld` builds its local JavaScript targets alongside the public `exports` entries. For example:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"name": "example",
|
|
53
|
+
"type": "module",
|
|
54
|
+
"imports": {
|
|
55
|
+
"#utils": "./dist/utils.mjs",
|
|
56
|
+
"#env": {
|
|
57
|
+
"node": "./dist/env.node.mjs",
|
|
58
|
+
"default": "./dist/env.browser.mjs"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
With the default directories, provide `src/utils.js`, `src/env.node.js`, and `src/env.browser.js` (or supported TypeScript sources with a transform plugin). Both `#env` branches are built at the declared paths. An import of `#utils` or `#env` from this package stays as a `#` specifier in the output, so the runtime selects the matching branch. The authored `imports` map is preserved.
|
|
65
|
+
|
|
66
|
+
Exact and wildcard keys, nested conditions, and fallback arrays are supported. Repeated local targets are built once. `null` and package-specifier targets are left to runtime resolution. Local `.mjs` targets require `es`; `.cjs` targets require `cjs`; `.js` targets follow the package `type` that pkgbld writes (including an inferred `"module"` for an ESM-only build). Percent-encoded target paths refer to their decoded filenames, and URL query or fragment suffixes remain in the authored map without becoming part of the output filename. A target whose format is excluded by `--formats`, whose source is missing, or whose output path is invalid or conflicts with another entry fails the build with its manifest location. Local assets and `.d.ts` targets are not generated by this JavaScript entry process; supply them through their own producer.
|
|
67
|
+
|
|
68
|
+
Keys beginning `#/` work on Node.js 24.14+ and 25.4+; older supported Node.js versions reject those specifiers at runtime. Use names such as `#utils` when supporting Node.js 20.
|
|
69
|
+
|
|
42
70
|
## CLI options
|
|
43
71
|
|
|
44
72
|
### umd
|
|
@@ -79,7 +107,9 @@ Supported targets for this option: `es`, `cjs` and `umd`.
|
|
|
79
107
|
pkgbld --formats=es
|
|
80
108
|
```
|
|
81
109
|
|
|
82
|
-
Defines what formats to build
|
|
110
|
+
Defines what formats to build: `es`, `cjs`, and `umd`. Use `--umd` to select UMD entry points.
|
|
111
|
+
|
|
112
|
+
Private import targets must have their required format included here. They are emitted at their declared paths independently of the output filename patterns below.
|
|
83
113
|
|
|
84
114
|
### preprocess
|
|
85
115
|
|
|
@@ -127,6 +157,24 @@ pkgbld --include-externals=lodash
|
|
|
127
157
|
|
|
128
158
|
Bundles all or specified externals into a package.
|
|
129
159
|
|
|
160
|
+
This does not inline this package's own `#` imports when package-import handling is enabled. A bundled dependency's `#` imports are resolved against that dependency's map.
|
|
161
|
+
|
|
162
|
+
### no-imports
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
pkgbld --no-imports
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Disables local target discovery and `#` externalization for this package. The authored `imports` map is preserved. This restores the earlier source-import behavior and does not affect `--conditions`.
|
|
169
|
+
|
|
170
|
+
### conditions
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
pkgbld --conditions=node,development
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Adds build-time conditions when resolving bundled dependencies, including their `#` imports. Comma-separated values supplement the resolver's built-in conditions. With no flag, the resolver keeps its existing implicit `production` condition, or `development` when selected by `NODE_ENV`. The order of keys in a dependency's map determines which matching branch wins. These conditions do not choose which branches of this package's own `imports` map are built.
|
|
177
|
+
|
|
130
178
|
### eject
|
|
131
179
|
|
|
132
180
|
```
|
|
@@ -195,102 +243,36 @@ pkgbld --no-exports
|
|
|
195
243
|
|
|
196
244
|
Do not add exports field in package.json.
|
|
197
245
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
pkgbld prune
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
prune devDependencies and redundant scripts from package.json
|
|
205
|
-
|
|
206
|
-
### prune --profile=<profile>
|
|
207
|
-
|
|
208
|
-
There are two profiles: `library` and `app`. `library` is default.
|
|
209
|
-
|
|
210
|
-
Right now it only affects how `prune` command removes entries in the `scripts` field.
|
|
246
|
+
This also disables entry-point discovery from an existing `exports` field. Only the top-level `src/index` entry point is built
|
|
247
|
+
unless a plugin provides additional inputs or enabled package imports declare local JavaScript targets.
|
|
211
248
|
|
|
212
|
-
|
|
249
|
+
## Build plugin interface
|
|
213
250
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
pkgbld prune --flatten=<directory>
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Flattens file structure by moving all files from `dist` or other directory to the root directory and updating package.json.
|
|
223
|
-
|
|
224
|
-
If the directory is not specified it is guessed from package.json.
|
|
225
|
-
|
|
226
|
-
If files cannot be copied because of name conflicts the command will fail.
|
|
227
|
-
|
|
228
|
-
### removeSourcemaps
|
|
229
|
-
|
|
230
|
-
```
|
|
231
|
-
pkgbld prune --remove-sourcemaps
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
Removes all sourcemaps from the package. The logic is very simple and removes all files with `.map` extension and references in format `//# sourceMappingURL=<mapFile>`.
|
|
235
|
-
|
|
236
|
-
### optimizeFiles (default)
|
|
237
|
-
|
|
238
|
-
```
|
|
239
|
-
pkgbld prune --optimize-files=false
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Optimizes files by removing all files that are not required for pack at the given moment.
|
|
243
|
-
|
|
244
|
-
You might want to disable this option in some edge cases.
|
|
245
|
-
|
|
246
|
-
### no-subpackages
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
pkgbld --no-subpackages
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
Do not create subpackage directories with package.json files for non-index entry points.
|
|
253
|
-
|
|
254
|
-
By default, pkgbld creates a directory for each non-index entry point (e.g., `second/package.json` for a `./second` export) to enable simpler imports. Use this flag to disable this behavior.
|
|
255
|
-
|
|
256
|
-
Note: The `pkgbld-plugin-dts-buddy` plugin automatically sets this flag when loaded, as it provides alternative type resolution through the dts-buddy bundling approach.
|
|
257
|
-
|
|
258
|
-
### removeLegalComments
|
|
259
|
-
|
|
260
|
-
```
|
|
261
|
-
pkgbld prune --remove-legal-comments --compress=es,cjs
|
|
262
|
-
```
|
|
251
|
+
`pkgbld` loads plugins named `pkgbld-plugin-*` or `@scope/pkgbld-plugin-*` from
|
|
252
|
+
`dependencies`, `devDependencies`, and `peerDependencies`. The package name after
|
|
253
|
+
the optional scope must start with `pkgbld-plugin-`.
|
|
263
254
|
|
|
264
|
-
|
|
255
|
+
Plugins implement one or more lifecycle methods on the object returned by the plugin module's `create()` function.
|
|
265
256
|
|
|
266
|
-
|
|
257
|
+
Build configuration is resolved from defaults, package metadata, and explicit CLI options before `configure` runs. Plugins receive the effective mutable draft and have final authority. After all `configure` hooks finish, `pkgbld` normalizes, validates, and deeply freezes the configuration; every later hook receives that frozen value.
|
|
267
258
|
|
|
268
|
-
|
|
259
|
+
Build entries are resolved after configuration. A plugin that needs to add a source module does so during `contributeEntries`; later phases receive immutable entries containing the canonical name, concrete source path, source extension, and enabled output paths. Configured UMD and preprocessing selections must resolve to discovered Build entries.
|
|
269
260
|
|
|
270
|
-
|
|
261
|
+
`shared` is mutable state scoped to one build for coordination between plugins. Lifecycle phase boundaries are preserved, but plugin order within one phase is not guaranteed and asynchronous hooks in that phase may run in parallel. Plugins must not depend on the order of same-phase reads and writes. State owned by one plugin should remain in the closure created by `create()`.
|
|
271
262
|
|
|
272
263
|
```typescript
|
|
273
264
|
interface PkgbldPlugin {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
): void
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
provider: Provider,
|
|
286
|
-
config: Record<string, string | string[] | boolean>,
|
|
287
|
-
inputs: string[]
|
|
288
|
-
): Promise<void>;
|
|
289
|
-
getExtraOutputSettings(
|
|
290
|
-
format: InternalModuleFormat,
|
|
291
|
-
inputs: string[]
|
|
292
|
-
): Partial<OutputOptions>;
|
|
293
|
-
buildEnd(): Promise<void>;
|
|
265
|
+
configure(context: {
|
|
266
|
+
draft: BuildConfigurationDraft;
|
|
267
|
+
sources: BuildConfigurationSources;
|
|
268
|
+
shared: Map<unknown, unknown>;
|
|
269
|
+
}): void;
|
|
270
|
+
contributeEntries(context: PluginContributeEntriesContext): void;
|
|
271
|
+
processPackageJson(context: PluginPackageContext): void;
|
|
272
|
+
processTsConfig(context: PluginTsConfigContext): void;
|
|
273
|
+
providePlugins(context: PluginRollupContext): Promise<void>;
|
|
274
|
+
getExtraOutputSettings(context: PluginOutputContext): Partial<OutputOptions>;
|
|
275
|
+
buildEnd(context: PluginBuildEndContext): Promise<void>;
|
|
294
276
|
}
|
|
295
277
|
```
|
|
296
278
|
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import('./
|
|
2
|
+
|
|
3
|
+
import('./src/index.js');
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "2.1.0",
|
|
3
3
|
"name": "pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
6
6
|
"bin": "./index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "./
|
|
9
|
-
"types": "./
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
8
|
+
"main": "./src/index.js",
|
|
9
|
+
"types": "./types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./types/index.d.ts",
|
|
13
|
+
"default": "./src/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./options": {
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"default": "./src/options/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
13
21
|
"engines": {
|
|
14
22
|
"node": ">=20"
|
|
15
23
|
},
|
|
@@ -28,28 +36,24 @@
|
|
|
28
36
|
"rollup"
|
|
29
37
|
],
|
|
30
38
|
"dependencies": {
|
|
31
|
-
"@niceties/logger": "^1.1
|
|
32
|
-
"@niceties/draftlog-appender": "^1.
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"rollup
|
|
39
|
+
"@niceties/logger": "^2.1.1",
|
|
40
|
+
"@niceties/draftlog-appender": "^2.1.1",
|
|
41
|
+
"fast-is-equal": "^1.3.3",
|
|
42
|
+
"type-fest": "^5.9.0",
|
|
43
|
+
"rollup": "^4.63.1",
|
|
36
44
|
"rollup-plugin-preprocess": "^0.0.4",
|
|
37
|
-
"@rollup/plugin-commonjs": "^
|
|
38
|
-
"@rollup/plugin-terser": "^0.
|
|
45
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
46
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
39
47
|
"@rollup/plugin-json": "^6.1.0",
|
|
40
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
41
|
-
"@rollup-extras/plugin-clean": "^
|
|
42
|
-
"@rollup-extras/plugin-binify": "^
|
|
43
|
-
"@rollup-extras/plugin-externals": "^
|
|
44
|
-
"@slimlib/refine-partition": "^
|
|
45
|
-
"@slimlib/smart-mock": "^0.
|
|
46
|
-
"is-builtin-module": "^
|
|
47
|
-
"terser": "^5.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"jsonata": "^2.0.6"
|
|
51
|
-
},
|
|
52
|
-
"peerDependencies": {
|
|
53
|
-
"typescript": ">=5.3.3"
|
|
48
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
49
|
+
"@rollup-extras/plugin-clean": "^2.0.1",
|
|
50
|
+
"@rollup-extras/plugin-binify": "^2.0.0",
|
|
51
|
+
"@rollup-extras/plugin-externals": "^2.0.0",
|
|
52
|
+
"@slimlib/refine-partition": "^2.0.2",
|
|
53
|
+
"@slimlib/smart-mock": "^1.0.2",
|
|
54
|
+
"is-builtin-module": "^5.0.0",
|
|
55
|
+
"terser": "^5.51.2",
|
|
56
|
+
"@niceties/ansi": "^1.1.2",
|
|
57
|
+
"@niceties/node-parseargs-plus": "^0.6.0"
|
|
54
58
|
}
|
|
55
59
|
}
|