@knighted/duel 3.2.4 → 4.0.0-rc.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 +18 -3
- package/dist/cjs/duel.cjs +337 -251
- package/dist/cjs/init.cjs +149 -39
- package/dist/cjs/init.d.cts +14 -15
- package/dist/cjs/resolver.cjs +96 -0
- package/dist/cjs/resolver.d.cts +10 -0
- package/dist/cjs/util.cjs +332 -10
- package/dist/cjs/util.d.cts +20 -2
- package/dist/esm/duel.js +342 -256
- package/dist/esm/init.d.ts +8 -0
- package/dist/esm/init.js +150 -40
- package/dist/esm/resolver.d.ts +10 -0
- package/dist/esm/resolver.js +93 -0
- package/dist/esm/util.d.ts +21 -1
- package/dist/esm/util.js +324 -11
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -60,9 +60,6 @@ It should work similarly for a CJS-first project. Except, your package.json file
|
|
|
60
60
|
> [!IMPORTANT]
|
|
61
61
|
> This works best if your CJS-first project uses file extensions in _relative_ specifiers. That is acceptable in CJS and [required in ESM](https://nodejs.org/api/esm.html#import-specifiers). `duel` does not rewrite bare specifiers or remap relative specifiers to directory indexes.
|
|
62
62
|
|
|
63
|
-
> [!NOTE]
|
|
64
|
-
> While `duel` runs it briefly swaps in a temporary package.json with the needed `type`; your original file is restored when the build finishes.
|
|
65
|
-
|
|
66
63
|
### Build orientation
|
|
67
64
|
|
|
68
65
|
`duel` infers the primary vs dual build orientation from your `package.json` `type`:
|
|
@@ -103,6 +100,15 @@ Assuming an `outDir` of `dist`, running the above will create `dist/esm` and `di
|
|
|
103
100
|
|
|
104
101
|
When `--mode` is enabled, `duel` copies sources and runs [`@knighted/module`](https://github.com/knightedcodemonkey/module) **before** `tsc`, so TypeScript sees already-mitigated sources. That pre-`tsc` step is globals-only for `--mode globals` and full lowering for `--mode full`.
|
|
105
102
|
|
|
103
|
+
### Dual package hazards
|
|
104
|
+
|
|
105
|
+
Mixed `import`/`require` of the same dual package (especially when conditional exports differ) can create two module instances. `duel` exposes the detector from `@knighted/module`:
|
|
106
|
+
|
|
107
|
+
- `--detect-dual-package-hazard [off|warn|error]` (default `warn`): emit diagnostics; `error` exits non-zero.
|
|
108
|
+
- `--dual-package-hazard-scope [file|project]` (default `file`): per-file checks or a project-wide pre-pass that aggregates package usage across all compiled sources before building.
|
|
109
|
+
|
|
110
|
+
Project scope is helpful in monorepos or hoisted installs where hazards surface only when looking across files.
|
|
111
|
+
|
|
106
112
|
## Options
|
|
107
113
|
|
|
108
114
|
The available options are limited, because you should define most of them inside your project's `tsconfig.json` file.
|
|
@@ -112,6 +118,15 @@ The available options are limited, because you should define most of them inside
|
|
|
112
118
|
- `--mode` Optional shorthand for the module transform mode: `none` (default), `globals` (globals-only), `full` (globals + full syntax lowering).
|
|
113
119
|
- `--dirs, -d` Outputs both builds to directories inside of `outDir`. Defaults to `false`.
|
|
114
120
|
- `--exports, -e` Generate `package.json` `exports` from build output. Values: `wildcard` | `dir` | `name`.
|
|
121
|
+
- `--exports-config` Provide a JSON file with `{ "entries": ["./dist/index.js", ...], "main": "./dist/index.js" }` to limit which outputs become exports.
|
|
122
|
+
- `--exports-validate` Dry-run exports generation/validation without writing package.json; combine with `--exports` or `--exports-config` to emit after validation.
|
|
123
|
+
- `--rewrite-policy [safe|warn|skip]` Control how specifier rewrites behave when a matching target is missing (`safe` warns and skips, `warn` rewrites and warns, `skip` leaves specifiers untouched).
|
|
124
|
+
- `--validate-specifiers` Validate that rewritten specifiers resolve to outputs; defaults to `true` when `--rewrite-policy` is `safe`.
|
|
125
|
+
- `--detect-dual-package-hazard [off|warn|error]` Flag mixed import/require usage of dual packages; `error` exits non-zero.
|
|
126
|
+
- `--dual-package-hazard-scope [file|project]` Run hazard checks per file (default) or aggregate across the project.
|
|
127
|
+
- `--copy-mode [sources|full]` Temp copy strategy. `sources` (default) copies only files participating in the build (plus configs); `full` mirrors the previous whole-project copy.
|
|
128
|
+
- `--verbose, -V` Verbose logging.
|
|
129
|
+
- `--help, -h` Print the help text.
|
|
115
130
|
|
|
116
131
|
> [!NOTE]
|
|
117
132
|
> Exports keys are extensionless by design; the target `import`/`require`/`types` entries keep explicit file extensions so Node resolution remains deterministic.
|