@knighted/duel 4.0.1 → 4.0.2-rc.1
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/dist/cjs/duel.cjs +10 -4
- package/dist/cjs/util.cjs +12 -9
- package/dist/esm/duel.js +11 -5
- package/dist/esm/util.js +13 -10
- package/package.json +2 -3
package/dist/cjs/duel.cjs
CHANGED
|
@@ -9,7 +9,6 @@ const node_child_process_1 = require("node:child_process");
|
|
|
9
9
|
const promises_1 = require("node:fs/promises");
|
|
10
10
|
const node_crypto_1 = require("node:crypto");
|
|
11
11
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
12
|
-
const glob_1 = require("glob");
|
|
13
12
|
const find_up_1 = require("find-up");
|
|
14
13
|
const module_1 = require("@knighted/module");
|
|
15
14
|
const get_tsconfig_1 = require("get-tsconfig");
|
|
@@ -44,6 +43,13 @@ const logDiagnostics = (diags, projectDir, hazardAllowlist = null) => {
|
|
|
44
43
|
}
|
|
45
44
|
return hasError;
|
|
46
45
|
};
|
|
46
|
+
const collectGlob = async (pattern, options) => {
|
|
47
|
+
const files = [];
|
|
48
|
+
for await (const file of (0, promises_1.glob)(pattern, options)) {
|
|
49
|
+
files.push(file);
|
|
50
|
+
}
|
|
51
|
+
return files;
|
|
52
|
+
};
|
|
47
53
|
const duel = async (args) => {
|
|
48
54
|
const ctx = await (0, init_js_1.init)(args);
|
|
49
55
|
if (ctx) {
|
|
@@ -587,7 +593,7 @@ const duel = async (args) => {
|
|
|
587
593
|
* Transform ambiguous modules for the target dual build.
|
|
588
594
|
* @see https://github.com/microsoft/TypeScript/issues/58658
|
|
589
595
|
*/
|
|
590
|
-
const toTransform = await (
|
|
596
|
+
const toTransform = await collectGlob(`${subDir.replace(/\\/g, '/')}/**/*{.js,.jsx,.ts,.tsx}`, {
|
|
591
597
|
ignore: `${subDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
592
598
|
});
|
|
593
599
|
let transformDiagnosticsError = false;
|
|
@@ -666,7 +672,7 @@ const duel = async (args) => {
|
|
|
666
672
|
throw err;
|
|
667
673
|
}
|
|
668
674
|
const dualGlob = dualTarget === 'commonjs' ? '**/*{.js,.cjs,.d.ts}' : '**/*{.js,.mjs,.d.ts}';
|
|
669
|
-
const filenames = await (
|
|
675
|
+
const filenames = await collectGlob(`${absoluteDualOutDir.replace(/\\/g, '/')}/${dualGlob}`, {
|
|
670
676
|
ignore: `${absoluteDualOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
671
677
|
});
|
|
672
678
|
const rewriteSyntaxMode = dualTarget === 'commonjs' ? true : syntaxMode;
|
|
@@ -689,7 +695,7 @@ const duel = async (args) => {
|
|
|
689
695
|
onRewrite: (from, to) => logVerbose(`Rewrote specifiers in ${from} -> ${to}`),
|
|
690
696
|
});
|
|
691
697
|
if (dirs && originalType === 'commonjs') {
|
|
692
|
-
const primaryFiles = await (
|
|
698
|
+
const primaryFiles = await collectGlob(`${primaryOutDir.replace(/\\/g, '/')}/**/*{.js,.cjs,.d.ts}`, {
|
|
693
699
|
ignore: `${primaryOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
694
700
|
});
|
|
695
701
|
await (0, resolver_js_1.rewriteSpecifiersAndExtensions)(primaryFiles, {
|
package/dist/cjs/util.cjs
CHANGED
|
@@ -7,7 +7,6 @@ const node_fs_1 = require("node:fs");
|
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const node_process_1 = require("node:process");
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
|
-
const glob_1 = require("glob");
|
|
11
10
|
const find_up_1 = require("find-up");
|
|
12
11
|
const COLORS = {
|
|
13
12
|
reset: '\x1b[0m',
|
|
@@ -281,7 +280,12 @@ const generateExports = async (options) => {
|
|
|
281
280
|
return;
|
|
282
281
|
}
|
|
283
282
|
const baseEntry = baseMap.get(baseKey) ?? {};
|
|
284
|
-
|
|
283
|
+
if (kind === 'types') {
|
|
284
|
+
baseEntry.types = baseEntry.types ?? withDot;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
baseEntry[kind] = withDot;
|
|
288
|
+
}
|
|
285
289
|
baseMap.set(baseKey, baseEntry);
|
|
286
290
|
const subpath = useEntriesSubpaths
|
|
287
291
|
? ensureDotSlash(stripKnownExt(relFromRoot))
|
|
@@ -291,7 +295,8 @@ const generateExports = async (options) => {
|
|
|
291
295
|
const mappedSubpath = baseToSubpath.get(baseKey);
|
|
292
296
|
if (mappedSubpath) {
|
|
293
297
|
const subEntry = subpathMap.get(mappedSubpath) ?? {};
|
|
294
|
-
|
|
298
|
+
const nextType = useWildcard ? toWildcardValue(withDot) : withDot;
|
|
299
|
+
subEntry.types = subEntry.types ?? nextType;
|
|
295
300
|
subpathMap.set(mappedSubpath, subEntry);
|
|
296
301
|
}
|
|
297
302
|
return;
|
|
@@ -303,10 +308,9 @@ const generateExports = async (options) => {
|
|
|
303
308
|
baseToSubpath.set(baseKey, subpath);
|
|
304
309
|
}
|
|
305
310
|
};
|
|
306
|
-
const
|
|
311
|
+
for await (const file of (0, promises_1.glob)(`${esmRootPosix}/**/*.{js,mjs,d.ts,d.mts}`, {
|
|
307
312
|
ignore: esmIgnore,
|
|
308
|
-
})
|
|
309
|
-
for (const file of esmFiles) {
|
|
313
|
+
})) {
|
|
310
314
|
if (/\.d\.(ts|mts)$/.test(file)) {
|
|
311
315
|
recordPath('types', file, esmRoot);
|
|
312
316
|
}
|
|
@@ -314,10 +318,9 @@ const generateExports = async (options) => {
|
|
|
314
318
|
recordPath('import', file, esmRoot);
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
|
-
const
|
|
321
|
+
for await (const file of (0, promises_1.glob)(`${cjsRootPosix}/**/*.{js,cjs,d.ts,d.cts}`, {
|
|
318
322
|
ignore: cjsIgnore,
|
|
319
|
-
})
|
|
320
|
-
for (const file of cjsFiles) {
|
|
323
|
+
})) {
|
|
321
324
|
if (/\.d\.(ts|cts)$/.test(file)) {
|
|
322
325
|
recordPath('types', file, cjsRoot);
|
|
323
326
|
}
|
package/dist/esm/duel.js
CHANGED
|
@@ -3,10 +3,9 @@ import { argv } from 'node:process';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { join, dirname, resolve, relative, sep } from 'node:path';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import { writeFile, rm, mkdir, cp, access, readdir } from 'node:fs/promises';
|
|
6
|
+
import { writeFile, rm, mkdir, cp, access, readdir, glob } from 'node:fs/promises';
|
|
7
7
|
import { createHash } from 'node:crypto';
|
|
8
8
|
import { performance } from 'node:perf_hooks';
|
|
9
|
-
import { glob } from 'glob';
|
|
10
9
|
import { findUp } from 'find-up';
|
|
11
10
|
import { transform, collectProjectDualPackageHazards } from '@knighted/module';
|
|
12
11
|
import { getTsconfig, parseTsconfig } from 'get-tsconfig';
|
|
@@ -41,6 +40,13 @@ const logDiagnostics = (diags, projectDir, hazardAllowlist = null) => {
|
|
|
41
40
|
}
|
|
42
41
|
return hasError;
|
|
43
42
|
};
|
|
43
|
+
const collectGlob = async (pattern, options) => {
|
|
44
|
+
const files = [];
|
|
45
|
+
for await (const file of glob(pattern, options)) {
|
|
46
|
+
files.push(file);
|
|
47
|
+
}
|
|
48
|
+
return files;
|
|
49
|
+
};
|
|
44
50
|
const duel = async (args) => {
|
|
45
51
|
const ctx = await init(args);
|
|
46
52
|
if (ctx) {
|
|
@@ -584,7 +590,7 @@ const duel = async (args) => {
|
|
|
584
590
|
* Transform ambiguous modules for the target dual build.
|
|
585
591
|
* @see https://github.com/microsoft/TypeScript/issues/58658
|
|
586
592
|
*/
|
|
587
|
-
const toTransform = await
|
|
593
|
+
const toTransform = await collectGlob(`${subDir.replace(/\\/g, '/')}/**/*{.js,.jsx,.ts,.tsx}`, {
|
|
588
594
|
ignore: `${subDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
589
595
|
});
|
|
590
596
|
let transformDiagnosticsError = false;
|
|
@@ -663,7 +669,7 @@ const duel = async (args) => {
|
|
|
663
669
|
throw err;
|
|
664
670
|
}
|
|
665
671
|
const dualGlob = dualTarget === 'commonjs' ? '**/*{.js,.cjs,.d.ts}' : '**/*{.js,.mjs,.d.ts}';
|
|
666
|
-
const filenames = await
|
|
672
|
+
const filenames = await collectGlob(`${absoluteDualOutDir.replace(/\\/g, '/')}/${dualGlob}`, {
|
|
667
673
|
ignore: `${absoluteDualOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
668
674
|
});
|
|
669
675
|
const rewriteSyntaxMode = dualTarget === 'commonjs' ? true : syntaxMode;
|
|
@@ -686,7 +692,7 @@ const duel = async (args) => {
|
|
|
686
692
|
onRewrite: (from, to) => logVerbose(`Rewrote specifiers in ${from} -> ${to}`),
|
|
687
693
|
});
|
|
688
694
|
if (dirs && originalType === 'commonjs') {
|
|
689
|
-
const primaryFiles = await
|
|
695
|
+
const primaryFiles = await collectGlob(`${primaryOutDir.replace(/\\/g, '/')}/**/*{.js,.cjs,.d.ts}`, {
|
|
690
696
|
ignore: `${primaryOutDir.replace(/\\/g, '/')}/**/node_modules/**`,
|
|
691
697
|
});
|
|
692
698
|
await rewriteSpecifiersAndExtensions(primaryFiles, {
|
package/dist/esm/util.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
|
-
import { realpath, readFile, writeFile, symlink, rm } from 'node:fs/promises';
|
|
2
|
+
import { realpath, readFile, writeFile, symlink, rm, glob } from 'node:fs/promises';
|
|
3
3
|
import { existsSync, rmSync } from 'node:fs';
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
5
|
import { cwd, platform } from 'node:process';
|
|
6
6
|
import { join, resolve, relative, parse as parsePath, posix, isAbsolute, sep, normalize as normalizePath, } from 'node:path';
|
|
7
|
-
import { glob } from 'glob';
|
|
8
7
|
import { findUp } from 'find-up';
|
|
9
8
|
const COLORS = {
|
|
10
9
|
reset: '\x1b[0m',
|
|
@@ -266,7 +265,12 @@ const generateExports = async (options) => {
|
|
|
266
265
|
return;
|
|
267
266
|
}
|
|
268
267
|
const baseEntry = baseMap.get(baseKey) ?? {};
|
|
269
|
-
|
|
268
|
+
if (kind === 'types') {
|
|
269
|
+
baseEntry.types = baseEntry.types ?? withDot;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
baseEntry[kind] = withDot;
|
|
273
|
+
}
|
|
270
274
|
baseMap.set(baseKey, baseEntry);
|
|
271
275
|
const subpath = useEntriesSubpaths
|
|
272
276
|
? ensureDotSlash(stripKnownExt(relFromRoot))
|
|
@@ -276,7 +280,8 @@ const generateExports = async (options) => {
|
|
|
276
280
|
const mappedSubpath = baseToSubpath.get(baseKey);
|
|
277
281
|
if (mappedSubpath) {
|
|
278
282
|
const subEntry = subpathMap.get(mappedSubpath) ?? {};
|
|
279
|
-
|
|
283
|
+
const nextType = useWildcard ? toWildcardValue(withDot) : withDot;
|
|
284
|
+
subEntry.types = subEntry.types ?? nextType;
|
|
280
285
|
subpathMap.set(mappedSubpath, subEntry);
|
|
281
286
|
}
|
|
282
287
|
return;
|
|
@@ -288,10 +293,9 @@ const generateExports = async (options) => {
|
|
|
288
293
|
baseToSubpath.set(baseKey, subpath);
|
|
289
294
|
}
|
|
290
295
|
};
|
|
291
|
-
const
|
|
296
|
+
for await (const file of glob(`${esmRootPosix}/**/*.{js,mjs,d.ts,d.mts}`, {
|
|
292
297
|
ignore: esmIgnore,
|
|
293
|
-
})
|
|
294
|
-
for (const file of esmFiles) {
|
|
298
|
+
})) {
|
|
295
299
|
if (/\.d\.(ts|mts)$/.test(file)) {
|
|
296
300
|
recordPath('types', file, esmRoot);
|
|
297
301
|
}
|
|
@@ -299,10 +303,9 @@ const generateExports = async (options) => {
|
|
|
299
303
|
recordPath('import', file, esmRoot);
|
|
300
304
|
}
|
|
301
305
|
}
|
|
302
|
-
const
|
|
306
|
+
for await (const file of glob(`${cjsRootPosix}/**/*.{js,cjs,d.ts,d.cts}`, {
|
|
303
307
|
ignore: cjsIgnore,
|
|
304
|
-
})
|
|
305
|
-
for (const file of cjsFiles) {
|
|
308
|
+
})) {
|
|
306
309
|
if (/\.d\.(ts|cts)$/.test(file)) {
|
|
307
310
|
recordPath('types', file, cjsRoot);
|
|
308
311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knighted/duel",
|
|
3
|
-
"version": "4.0.1",
|
|
3
|
+
"version": "4.0.2-rc.1",
|
|
4
4
|
"description": "TypeScript dual packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/duel.js",
|
|
@@ -89,10 +89,9 @@
|
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@jridgewell/gen-mapping": "^0.3.13",
|
|
91
91
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
92
|
-
"@knighted/module": "^1.5.
|
|
92
|
+
"@knighted/module": "^1.5.2",
|
|
93
93
|
"find-up": "^8.0.0",
|
|
94
94
|
"get-tsconfig": "^4.13.0",
|
|
95
|
-
"glob": "^13.0.6",
|
|
96
95
|
"magic-string": "^0.30.21",
|
|
97
96
|
"read-package-up": "^12.0.0"
|
|
98
97
|
},
|