@knighted/duel 1.0.6 → 1.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 KCM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,13 +8,13 @@ Tool for building a Node.js [dual package](https://nodejs.org/api/packages.html#
8
8
 
9
9
  ## Features
10
10
 
11
- * Bidirectional ESM ↔️ CJS dual builds inferred from the package.json `type`.
12
- * Correctly preserves module systems for `.mts` and `.cts` file extensions.
13
- * Use only one package.json and tsconfig.json.
11
+ - Bidirectional ESM ↔️ CJS dual builds inferred from the package.json `type`.
12
+ - Correctly preserves module systems for `.mts` and `.cts` file extensions.
13
+ - Use only one package.json and tsconfig.json.
14
14
 
15
15
  ## Requirements
16
16
 
17
- * Node >= 16.19.0.
17
+ - Node >= 16.19.0.
18
18
 
19
19
  ## Example
20
20
 
@@ -24,7 +24,7 @@ First, install this package to create the `duel` executable inside your `node_mo
24
24
  user@comp ~ $ npm i @knighted/duel --save-dev
25
25
  ```
26
26
 
27
- Then, given a `package.json` that defines `"type": "module"` and a `tsconfig.json` file that looks something like the following:
27
+ Then, given a `package.json` that defines `"type": "module"` and a `tsconfig.json` file that looks something like the following:
28
28
 
29
29
  ```json
30
30
  {
@@ -67,7 +67,6 @@ If you prefer to have both builds in directories inside of your defined `outDir`
67
67
 
68
68
  Assuming an `outDir` of `dist`, running the above will create `dist/esm` and `dist/cjs` directories.
69
69
 
70
-
71
70
  ### Parallel builds
72
71
 
73
72
  This is experimental, as your mileage may vary based on the size of your `node_modules` directory.
@@ -84,10 +83,10 @@ You _might_ reduce your build times, but only if your project has minimal depend
84
83
 
85
84
  The available options are limited, because you should define most of them inside your project's `tsconfig.json` file.
86
85
 
87
- * `--project, -p` The path to the project's configuration file. Defaults to `tsconfig.json`.
88
- * `--pkg-dir, -k` The directory to start looking for a package.json file. Defaults to the cwd.
89
- * `--dirs, -d` Outputs both builds to directories inside of `outDir`. Defaults to `false`.
90
- * `--parallel, -l` Run the builds in parallel. Defaults to `false`.
86
+ - `--project, -p` The path to the project's configuration file. Defaults to `tsconfig.json`.
87
+ - `--pkg-dir, -k` The directory to start looking for a package.json file. Defaults to the cwd.
88
+ - `--dirs, -d` Outputs both builds to directories inside of `outDir`. Defaults to `false`.
89
+ - `--parallel, -l` Run the builds in parallel. Defaults to `false`.
91
90
 
92
91
  You can run `duel --help` to get the same info. Below is the output of that:
93
92
 
@@ -106,15 +105,15 @@ Options:
106
105
 
107
106
  These are definitely edge cases, and would only really come up if your project mixes file extensions. For example, if you have `.ts` files combined with `.mts`, and/or `.cts`. For most projects, things should just work as expected.
108
107
 
109
- * This is going to work best if your CJS-first project uses file extensions in _relative_ specifiers. This is completely acceptable in CJS projects, and [required in ESM projects](https://nodejs.org/api/esm.html#import-specifiers). This package makes no attempt to rewrite bare specifiers, or remap any relative specifiers to a directory index.
108
+ - This is going to work best if your CJS-first project uses file extensions in _relative_ specifiers. This is completely acceptable in CJS projects, and [required in ESM projects](https://nodejs.org/api/esm.html#import-specifiers). This package makes no attempt to rewrite bare specifiers, or remap any relative specifiers to a directory index.
110
109
 
111
- * 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, there doesn't appear to be a way to convert an arbitrary `.ts` file into another module system, _while also preserving the module system of `.mts` and `.cts` files_, without requiring **multiple** package.json files. In my opinion, the `tsc` compiler is fundamentally broken in this regard, and at best is enforcing usage patterns it shouldn't. This is only mentioned for transparency, `duel` will correct for this and produce files with the module system you would expect based on the file's extension, so that it works with [how Node.js determines module systems](https://nodejs.org/api/packages.html#determining-module-system).
110
+ - 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, there doesn't appear to be a way to convert an arbitrary `.ts` file into another module system, _while also preserving the module system of `.mts` and `.cts` files_, without requiring **multiple** package.json files. In my opinion, the `tsc` compiler is fundamentally broken in this regard, and at best is enforcing usage patterns it shouldn't. This is only mentioned for transparency, `duel` will correct for this and produce files with the module system you would expect based on the file's extension, so that it works with [how Node.js determines module systems](https://nodejs.org/api/packages.html#determining-module-system).
112
111
 
113
- * 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`.
112
+ - 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`.
114
113
 
115
- * If running `duel` with your project's package.json file open in your editor, you may temporarily see the content replaced. This is because `duel` dynamically creates a new package.json using the `type` necessary for the dual build. Your original package.json will be restored after the build completes.
114
+ - If running `duel` with your project's package.json file open in your editor, you may temporarily see the content replaced. This is because `duel` dynamically creates a new package.json using the `type` necessary for the dual build. Your original package.json will be restored after the build completes.
116
115
 
117
116
  ## Notes
118
117
 
119
- As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` while using only **one package.json** file and **one tsconfig.json** file, _and also preserving module system by file extension_. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/issues/54593) [talking](https://github.com/microsoft/TypeScript/pull/54546) about dual build support, but their philosophy is mainly one of self-preservation, rather than collaboration. For instance, they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577). The downside of their decisions, and the fact that `npm` does not support using alternative names for the package.json file, is that `duel` must copy your project
118
+ As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` with only **one package.json and tsconfig.json file**, _and also preserving module system by file extension_. Basically, how you expect things to work. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/pull/54546) [talking](https://github.com/microsoft/TypeScript/issues/54593) about dual build support, but their philosophy is mainly one of self-preservation, rather than collaboration. For instance, they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577). The downside of their decisions, and the fact that `npm` does not support using alternative names for the package.json file, is that `duel` must copy your project
120
119
  directory before attempting to run the builds in parallel.
package/dist/cjs/init.cjs CHANGED
@@ -8,7 +8,7 @@ const node_process_1 = require("node:process");
8
8
  const node_util_1 = require("node:util");
9
9
  const node_path_1 = require("node:path");
10
10
  const promises_1 = require("node:fs/promises");
11
- const read_pkg_up_1 = require("read-pkg-up");
11
+ const read_package_up_1 = require("read-package-up");
12
12
  const jsonc_parser_1 = __importDefault(require("jsonc-parser"));
13
13
  const util_js_1 = require("./util.cjs");
14
14
  const init = async (args) => {
@@ -73,7 +73,7 @@ const init = async (args) => {
73
73
  (0, util_js_1.logError)('--target-extension is deprecated. Define "type" in your package.json instead and the dual build will be inferred from that.');
74
74
  return false;
75
75
  }
76
- pkg = await (0, read_pkg_up_1.readPackageUp)({ cwd: pkgDir });
76
+ pkg = await (0, read_package_up_1.readPackageUp)({ cwd: pkgDir });
77
77
  if (!pkg) {
78
78
  (0, util_js_1.logError)('No package.json file found.');
79
79
  return false;
@@ -1,5 +1,5 @@
1
1
  export function init(args: any): Promise<false | {
2
- pkg: import("read-pkg-up", { with: { "resolution-mode": "import" } }).NormalizedReadResult;
2
+ pkg: import("read-package-up", { with: { "resolution-mode": "import" } }).NormalizedReadResult;
3
3
  dirs: boolean | undefined;
4
4
  parallel: boolean | undefined;
5
5
  tsconfig: any;
@@ -1,5 +1,5 @@
1
1
  export function init(args: any): Promise<false | {
2
- pkg: import("read-pkg-up").NormalizedReadResult;
2
+ pkg: import("read-package-up").NormalizedReadResult;
3
3
  dirs: boolean | undefined;
4
4
  parallel: boolean | undefined;
5
5
  tsconfig: any;
package/dist/esm/init.js CHANGED
@@ -2,7 +2,7 @@ import { cwd } from 'node:process';
2
2
  import { parseArgs } from 'node:util';
3
3
  import { resolve, join, dirname } from 'node:path';
4
4
  import { stat, readFile } from 'node:fs/promises';
5
- import { readPackageUp } from 'read-pkg-up';
5
+ import { readPackageUp } from 'read-package-up';
6
6
  import JSONC from 'jsonc-parser';
7
7
  import { logError, log } from './util.js';
8
8
  const init = async (args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/duel",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "TypeScript dual packages.",
5
5
  "type": "module",
6
6
  "main": "dist",
@@ -51,7 +51,7 @@
51
51
  "url": "https://github.com/knightedcodemonkey/duel/issues"
52
52
  },
53
53
  "peerDependencies": {
54
- "typescript": ">=4.0.0 || >=4.9.0-dev || >=5.2.0-dev || >=5.3.0-dev || 5.4.0-dev"
54
+ "typescript": ">=4.0.0 || >=4.9.0-dev || >=5.3.0-dev || 5.4.0-dev || 5.5.0-dev"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^20.4.6",
@@ -59,7 +59,7 @@
59
59
  "eslint": "^8.45.0",
60
60
  "eslint-plugin-n": "^16.0.1",
61
61
  "prettier": "^3.2.4",
62
- "typescript": "^5.4.0-dev.20231206",
62
+ "typescript": "^5.5.0-dev.20240228",
63
63
  "vite": "^5.0.12"
64
64
  },
65
65
  "dependencies": {
@@ -67,7 +67,7 @@
67
67
  "find-up": "^6.3.0",
68
68
  "glob": "^10.3.3",
69
69
  "jsonc-parser": "^3.2.0",
70
- "read-pkg-up": "^10.0.0"
70
+ "read-package-up": "^11.0.0"
71
71
  },
72
72
  "prettier": {
73
73
  "arrowParens": "avoid",