@knighted/duel 1.0.0-alpha.2 → 1.0.0-alpha.3
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 +12 -9
- package/dist/init.cjs +3 -3
- package/dist/init.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,16 +12,17 @@ Early stages of development. Inspired by https://github.com/microsoft/TypeScript
|
|
|
12
12
|
|
|
13
13
|
* Node >= 16.19.0.
|
|
14
14
|
* TypeScript, `npm i typescript`.
|
|
15
|
+
* A `tsconfig.json` with `outDir` defined.
|
|
15
16
|
|
|
16
17
|
## Example
|
|
17
18
|
|
|
18
|
-
First, install
|
|
19
|
+
First, install this package to create the `duel` executable inside your `node_modules/.bin` directory.
|
|
19
20
|
|
|
20
21
|
```console
|
|
21
22
|
user@comp ~ $ npm i @knighted/duel
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
Then, given a `package.json` that defines `"type": "module"` and a `tsconfig.json` file that looks like the following:
|
|
25
|
+
Then, given a `package.json` that defines `"type": "module"` and a `tsconfig.json` file that looks something like the following:
|
|
25
26
|
|
|
26
27
|
```json
|
|
27
28
|
{
|
|
@@ -51,9 +52,9 @@ And then running it:
|
|
|
51
52
|
user@comp ~ $ npm run build
|
|
52
53
|
```
|
|
53
54
|
|
|
54
|
-
If everything worked, you should have an ESM build inside of `dist` and a CJS build inside of `dist/cjs`. Now you can update your `exports`
|
|
55
|
+
If everything worked, you should have an ESM build inside of `dist` and a CJS build inside of `dist/cjs`. Now you can update your [`exports`](https://nodejs.org/api/packages.html#exports) to match the build output.
|
|
55
56
|
|
|
56
|
-
It should work similarly for a CJS first project. Except, your `tsconfig.json` would define `--module` and `--moduleResolution` differently, and you'd want to pass
|
|
57
|
+
It should work similarly for a CJS first project. Except, your `tsconfig.json` would define `--module` and `--moduleResolution` differently, and you'd want to pass `--target-extension .mjs`.
|
|
57
58
|
|
|
58
59
|
See the available [options](#options).
|
|
59
60
|
|
|
@@ -71,13 +72,15 @@ You can run `duel --help` to get more info. Below is the output of that:
|
|
|
71
72
|
Usage: duel [options]
|
|
72
73
|
|
|
73
74
|
Options:
|
|
74
|
-
--project, -p
|
|
75
|
-
--target-extension, -x
|
|
76
|
-
--help, -h
|
|
75
|
+
--project, -p Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
76
|
+
--target-extension, -x Sets the file extension for the dual build. [.cjs,.mjs]
|
|
77
|
+
--help, -h Print this message.
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
## Gotchas
|
|
80
81
|
|
|
81
|
-
* Unfortunately, TypeScript doesn't really
|
|
82
|
-
|
|
82
|
+
* Unfortunately, TypeScript doesn't really build [dual packages](https://nodejs.org/api/packages.html#dual-commonjses-module-packages) very well in regards to preserving module system by file extension. For instance, it will **always** create CJS exports when `--module commonjs` is used, _even on files with an `.mts` extension_, which is contrary to [how Node determines module systems](https://nodejs.org/api/packages.html#determining-module-system). The `tsc` compiler is fundamentally broken in this regard. One reference issue is https://github.com/microsoft/TypeScript/issues/54573. If you use `.mts` extensions to enforce an ESM module system, this will break in the corresponding dual CJS build. There is no way to fix this until TypeScript fixes their compiler.
|
|
83
|
+
|
|
84
|
+
* If targeting a dual CJS build, and you are using [top level `await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await), you will most likely encounter the compilation error `error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.` during the CJS build. This is because `duel` creates a temporary `tsconfig.json` from your original and necessarily overwrites the `--module` and `--moduleResolution` based on the provided `--target-ext`. There is no workaround other than to **not** use top level await if you want a dual build.
|
|
85
|
+
|
|
83
86
|
* If doing an `import type` across module systems, i.e. from `.mts` into `.cts`, or vice versa, you might encounter the compilation error ``error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.``. This is a [known issue](https://github.com/microsoft/TypeScript/issues/49055) and TypeScript currently suggests installing the nightly build, i.e. `npm i typescript@next`.
|
package/dist/init.cjs
CHANGED
|
@@ -42,9 +42,9 @@ const init = async args => {
|
|
|
42
42
|
if (parsed.help) {
|
|
43
43
|
(0, _util.log)('Usage: duel [options]\n');
|
|
44
44
|
(0, _util.log)('Options:');
|
|
45
|
-
(0, _util.log)("--project, -p \t\t
|
|
46
|
-
(0, _util.log)('--target-extension, -x \t
|
|
47
|
-
(0, _util.log)('--help, -h \t\t
|
|
45
|
+
(0, _util.log)("--project, -p \t\t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
|
|
46
|
+
(0, _util.log)('--target-extension, -x \t Sets the file extension for the dual build. [.cjs,.mjs]');
|
|
47
|
+
(0, _util.log)('--help, -h \t\t Print this message.');
|
|
48
48
|
} else {
|
|
49
49
|
const {
|
|
50
50
|
project,
|
package/dist/init.js
CHANGED
|
@@ -36,9 +36,9 @@ const init = async args => {
|
|
|
36
36
|
if (parsed.help) {
|
|
37
37
|
log('Usage: duel [options]\n');
|
|
38
38
|
log('Options:');
|
|
39
|
-
log("--project, -p \t\t
|
|
40
|
-
log('--target-extension, -x \t
|
|
41
|
-
log('--help, -h \t\t
|
|
39
|
+
log("--project, -p \t\t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
|
|
40
|
+
log('--target-extension, -x \t Sets the file extension for the dual build. [.cjs,.mjs]');
|
|
41
|
+
log('--help, -h \t\t Print this message.');
|
|
42
42
|
} else {
|
|
43
43
|
const {
|
|
44
44
|
project,
|