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 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.ts`
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, only supports `es` and `cjs` at the moment. Use `umd` flag to build umd target.
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
- ### prune (command)
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
- For `library` profile it retains: 'preinstall', 'install', 'postinstall', 'prepublish', 'preprepare', 'prepare', 'postprepare'.
249
+ ## Build plugin interface
213
250
 
214
- For `app` profile it retains in addition: 'prestart', 'start', 'poststart', 'prerestart', 'restart', 'postrestart', 'prestop', 'stop', 'poststop', 'pretest', 'test', 'posttest'.
215
-
216
- ### flatten
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
- Removes all legal comments from the package. Only works with compress.
255
+ Plugins implement one or more lifecycle methods on the object returned by the plugin module's `create()` function.
265
256
 
266
- ## Plugin API
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
- `pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
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
- Plugins suppose to implement one or more of the following interface methods on an object that returned by `create()` function exported by the plugin module.
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
- options(
275
- parsedArgs: { [key: string]: string | number },
276
- options: ReturnType<typeof getCliOptions>
277
- ): void;
278
- processPackageJson(
279
- packageJson: PackageJson,
280
- inputs: string[],
281
- logger: Logger
282
- ): void;
283
- processTsConfig(config: Json): void;
284
- providePlugins(
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
- 'use strict';
3
- import('./dist/index.mjs');
2
+
3
+ import('./src/index.js');
package/package.json CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
- "version": "1.36.0",
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": "./dist/index.mjs",
9
- "types": "./dist/index.d.ts",
10
- "files": [
11
- "dist"
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.13",
32
- "@niceties/draftlog-appender": "^1.3.3",
33
- "lodash": "^4.17.21",
34
- "rollup": "^4.34.7",
35
- "rollup-plugin-typescript2": "^0.36.0",
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": "^28.0.2",
38
- "@rollup/plugin-terser": "^0.4.4",
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.0",
41
- "@rollup-extras/plugin-clean": "^1.3.9",
42
- "@rollup-extras/plugin-binify": "^1.1.10",
43
- "@rollup-extras/plugin-externals": "^1.2.2",
44
- "@slimlib/refine-partition": "^1.0.3",
45
- "@slimlib/smart-mock": "^0.1.6",
46
- "is-builtin-module": "^3.2.1",
47
- "terser": "^5.39.0",
48
- "kleur": "^4.1.5",
49
- "cleye": "^1.3.4",
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
  }