@knighted/duel 2.0.1 → 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 +4 -4
- package/dist/cjs/init.cjs +6 -8
- package/dist/esm/init.js +6 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ This feature is still a work in progress regarding transforming `exports` when t
|
|
|
89
89
|
The available options are limited, because you should define most of them inside your project's `tsconfig.json` file.
|
|
90
90
|
|
|
91
91
|
- `--project, -p` The path to the project's configuration file. Defaults to `tsconfig.json`.
|
|
92
|
-
- `--pkg-dir, -k` The directory to start looking for a package.json file. Defaults to
|
|
92
|
+
- `--pkg-dir, -k` The directory to start looking for a package.json file. Defaults to `--project` dir.
|
|
93
93
|
- `--modules, -m` Transform module globals for dual build target. Defaults to false.
|
|
94
94
|
- `--dirs, -d` Outputs both builds to directories inside of `outDir`. Defaults to `false`.
|
|
95
95
|
|
|
@@ -100,7 +100,7 @@ Usage: duel [options]
|
|
|
100
100
|
|
|
101
101
|
Options:
|
|
102
102
|
--project, -p [path] Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
103
|
-
--pkg-dir, -k [path] The directory to start looking for a package.json file. Defaults to
|
|
103
|
+
--pkg-dir, -k [path] The directory to start looking for a package.json file. Defaults to --project directory.
|
|
104
104
|
--modules, -m Transform module globals for dual build target. Defaults to false.
|
|
105
105
|
--dirs, -d Output both builds to directories inside of outDir. [esm, cjs].
|
|
106
106
|
--help, -h Print this message.
|
|
@@ -112,12 +112,12 @@ These are definitely edge cases, and would only really come up if your project m
|
|
|
112
112
|
|
|
113
113
|
- 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.
|
|
114
114
|
|
|
115
|
-
- Unfortunately,
|
|
115
|
+
- Unfortunately, `tsc` doesn't support [dual packages](https://nodejs.org/api/packages.html#dual-commonjses-module-packages) completely. One instance of unexpected behavior is when the compiler throws errors for ES module globals when running a dual CJS build, but not for the inverse case, despite both causing runtime errors in Node.js. See the [open issue](https://github.com/microsoft/TypeScript/issues/58658). You can circumvent this with `duel` by using the `--modules` option if your project uses module globals such as `import.meta` properties or `__dirname`, `__filename`, etc. in a CommonJS project.
|
|
116
116
|
|
|
117
117
|
- 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.
|
|
118
118
|
|
|
119
119
|
## Notes
|
|
120
120
|
|
|
121
|
-
As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` without requiring multiple `tsconfig.json` files or extra configuration. The
|
|
121
|
+
As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` without requiring multiple `tsconfig.json` files or extra configuration. The TypeScript team [keep](https://github.com/microsoft/TypeScript/pull/54546) [talking](https://github.com/microsoft/TypeScript/issues/54593) about dual build support, but they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577).
|
|
122
122
|
|
|
123
123
|
Fortunately, Node.js has added `--experimental-require-module` so that you can [`require()` ES modules](https://nodejs.org/api/esm.html#require) if they don't use top level await, which sets the stage for possibly no longer requiring dual builds.
|
package/dist/cjs/init.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = void 0;
|
|
4
|
-
const node_process_1 = require("node:process");
|
|
5
4
|
const node_util_1 = require("node:util");
|
|
6
5
|
const node_path_1 = require("node:path");
|
|
7
6
|
const promises_1 = require("node:fs/promises");
|
|
@@ -27,7 +26,6 @@ const init = async (args) => {
|
|
|
27
26
|
'pkg-dir': {
|
|
28
27
|
type: 'string',
|
|
29
28
|
short: 'k',
|
|
30
|
-
default: (0, node_process_1.cwd)(),
|
|
31
29
|
},
|
|
32
30
|
modules: {
|
|
33
31
|
type: 'boolean',
|
|
@@ -56,7 +54,7 @@ const init = async (args) => {
|
|
|
56
54
|
(0, util_js_1.log)('Usage: duel [options]\n');
|
|
57
55
|
(0, util_js_1.log)('Options:');
|
|
58
56
|
(0, util_js_1.log)("--project, -p [path] \t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
|
|
59
|
-
(0, util_js_1.log)('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to
|
|
57
|
+
(0, util_js_1.log)('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to --project directory.');
|
|
60
58
|
(0, util_js_1.log)('--modules, -m \t\t Transform module globals for dual build target. Defaults to false.');
|
|
61
59
|
(0, util_js_1.log)('--dirs, -d \t\t Output both builds to directories inside of outDir. [esm, cjs].');
|
|
62
60
|
(0, util_js_1.log)('--help, -h \t\t Print this message.');
|
|
@@ -70,11 +68,6 @@ const init = async (args) => {
|
|
|
70
68
|
(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.');
|
|
71
69
|
return false;
|
|
72
70
|
}
|
|
73
|
-
pkg = await (0, read_package_up_1.readPackageUp)({ cwd: pkgDir });
|
|
74
|
-
if (!pkg) {
|
|
75
|
-
(0, util_js_1.logError)('No package.json file found.');
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
71
|
try {
|
|
79
72
|
stats = await (0, promises_1.stat)(configPath);
|
|
80
73
|
}
|
|
@@ -82,6 +75,11 @@ const init = async (args) => {
|
|
|
82
75
|
(0, util_js_1.logError)(`Provided --project '${project}' resolves to ${configPath} which is not a file or directory.`);
|
|
83
76
|
return false;
|
|
84
77
|
}
|
|
78
|
+
pkg = await (0, read_package_up_1.readPackageUp)({ cwd: pkgDir ?? configPath });
|
|
79
|
+
if (!pkg) {
|
|
80
|
+
(0, util_js_1.logError)('No package.json file found.');
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
85
83
|
if (stats.isDirectory()) {
|
|
86
84
|
configPath = (0, node_path_1.join)(configPath, 'tsconfig.json');
|
|
87
85
|
try {
|
package/dist/esm/init.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { cwd } from 'node:process';
|
|
2
1
|
import { parseArgs } from 'node:util';
|
|
3
2
|
import { resolve, join, dirname } from 'node:path';
|
|
4
3
|
import { stat } from 'node:fs/promises';
|
|
@@ -24,7 +23,6 @@ const init = async (args) => {
|
|
|
24
23
|
'pkg-dir': {
|
|
25
24
|
type: 'string',
|
|
26
25
|
short: 'k',
|
|
27
|
-
default: cwd(),
|
|
28
26
|
},
|
|
29
27
|
modules: {
|
|
30
28
|
type: 'boolean',
|
|
@@ -53,7 +51,7 @@ const init = async (args) => {
|
|
|
53
51
|
log('Usage: duel [options]\n');
|
|
54
52
|
log('Options:');
|
|
55
53
|
log("--project, -p [path] \t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
|
|
56
|
-
log('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to
|
|
54
|
+
log('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to --project directory.');
|
|
57
55
|
log('--modules, -m \t\t Transform module globals for dual build target. Defaults to false.');
|
|
58
56
|
log('--dirs, -d \t\t Output both builds to directories inside of outDir. [esm, cjs].');
|
|
59
57
|
log('--help, -h \t\t Print this message.');
|
|
@@ -67,11 +65,6 @@ const init = async (args) => {
|
|
|
67
65
|
logError('--target-extension is deprecated. Define "type" in your package.json instead and the dual build will be inferred from that.');
|
|
68
66
|
return false;
|
|
69
67
|
}
|
|
70
|
-
pkg = await readPackageUp({ cwd: pkgDir });
|
|
71
|
-
if (!pkg) {
|
|
72
|
-
logError('No package.json file found.');
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
68
|
try {
|
|
76
69
|
stats = await stat(configPath);
|
|
77
70
|
}
|
|
@@ -79,6 +72,11 @@ const init = async (args) => {
|
|
|
79
72
|
logError(`Provided --project '${project}' resolves to ${configPath} which is not a file or directory.`);
|
|
80
73
|
return false;
|
|
81
74
|
}
|
|
75
|
+
pkg = await readPackageUp({ cwd: pkgDir ?? configPath });
|
|
76
|
+
if (!pkg) {
|
|
77
|
+
logError('No package.json file found.');
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
82
80
|
if (stats.isDirectory()) {
|
|
83
81
|
configPath = join(configPath, 'tsconfig.json');
|
|
84
82
|
try {
|