dtsroll 1.6.0 → 1.7.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 +17 -1
- package/dist/cli.mjs +4 -2
- package/dist/{index-Du7Kzot4.mjs → index-r9RZgCg7.mjs} +94 -0
- package/dist/index.mjs +3 -1
- package/dist/vite.mjs +3 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -134,9 +134,24 @@ If no entry files are provided, _dtsroll_ reads `package.json` to determine them
|
|
|
134
134
|
| Flag | Alias | Description |
|
|
135
135
|
| -------------- | ----- | ------------------------------------------------- |
|
|
136
136
|
| `--dry-run` | `-d` | Show what would be bundled without writing files |
|
|
137
|
+
| `--sourcemap` | `-s` | Generate source maps (`.d.ts.map` files) |
|
|
137
138
|
| `--conditions` | `-C` | Resolution conditions for [subpath exports](https://nodejs.org/api/packages.html#subpath-exports) (e.g. `production`) |
|
|
138
139
|
| `--external` | `-e` | *(Only when no `package.json`)* Packages to externalize |
|
|
139
140
|
|
|
141
|
+
#### Why use `--sourcemap`?
|
|
142
|
+
|
|
143
|
+
Without source maps, "Go to Definition" in VS Code lands you in bundled `.d.ts` files—often a flattened wall of generated types that's hard to navigate.
|
|
144
|
+
|
|
145
|
+
With `--sourcemap`, _dtsroll_ generates `.d.ts.map` files that map positions in the bundled output back to your original source files. This lets VS Code jump directly to the actual TypeScript implementation instead of the generated declarations.
|
|
146
|
+
|
|
147
|
+
This is especially useful for:
|
|
148
|
+
- **Monorepos** — Navigate seamlessly across packages to real source
|
|
149
|
+
- **Library authors** — Give consumers a better DX when exploring your types
|
|
150
|
+
- **Anyone debugging types** — Understand types at their origin, not the emitted output
|
|
151
|
+
|
|
152
|
+
> [!NOTE]
|
|
153
|
+
> For source navigation to work, the original `.ts` source files must be available (either shipped with your package or present locally). If they're not, VS Code falls back to the `.d.ts` file.
|
|
154
|
+
|
|
140
155
|
### Vite plugin
|
|
141
156
|
|
|
142
157
|
If you use `vite-plugin-dts`, _dtsroll_ will automatically bundle the emitted types immediately after generation:
|
|
@@ -161,7 +176,8 @@ import { dtsroll } from 'dtsroll'
|
|
|
161
176
|
|
|
162
177
|
await dtsroll({
|
|
163
178
|
cwd: process.cwd(),
|
|
164
|
-
dryRun: false
|
|
179
|
+
dryRun: false,
|
|
180
|
+
sourcemap: true // generates .d.ts.map files
|
|
165
181
|
})
|
|
166
182
|
```
|
|
167
183
|
|
package/dist/cli.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cli } from 'cleye';
|
|
3
|
-
import { b as bgYellow, a as black, d as dtsroll, l as logOutput, D as DtsrollBuildError } from './index-
|
|
3
|
+
import { b as bgYellow, a as black, d as dtsroll, l as logOutput, D as DtsrollBuildError } from './index-r9RZgCg7.mjs';
|
|
4
4
|
import 'node:path';
|
|
5
5
|
import 'node:fs/promises';
|
|
6
6
|
import 'rollup';
|
|
7
7
|
import 'rollup-plugin-dts';
|
|
8
8
|
import '@rollup/plugin-node-resolve';
|
|
9
|
+
import 'node:fs';
|
|
10
|
+
import 'convert-source-map';
|
|
9
11
|
import 'empathic/find';
|
|
10
12
|
import 'resolve-pkg-maps';
|
|
11
13
|
import 'byte-size';
|
|
12
14
|
|
|
13
15
|
var name = "dtsroll";
|
|
14
|
-
var version = "1.
|
|
16
|
+
var version = "1.7.0";
|
|
15
17
|
var description = "Bundle dts files";
|
|
16
18
|
|
|
17
19
|
const argv = cli({
|
|
@@ -3,6 +3,8 @@ import fs from 'node:fs/promises';
|
|
|
3
3
|
import { rollup } from 'rollup';
|
|
4
4
|
import { dts } from 'rollup-plugin-dts';
|
|
5
5
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
6
|
+
import fs$1 from 'node:fs';
|
|
7
|
+
import convert from 'convert-source-map';
|
|
6
8
|
import { up } from 'empathic/find';
|
|
7
9
|
import { resolveImports } from 'resolve-pkg-maps';
|
|
8
10
|
import byteSize from 'byte-size';
|
|
@@ -514,6 +516,96 @@ const createImportChainPlugin = () => {
|
|
|
514
516
|
};
|
|
515
517
|
};
|
|
516
518
|
|
|
519
|
+
const tryReadFile = async (filePath) => {
|
|
520
|
+
try {
|
|
521
|
+
return await fs$1.promises.readFile(filePath, "utf8");
|
|
522
|
+
} catch {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const loadSourceMap = async (codePath, code) => {
|
|
527
|
+
const adjacentMapPath = `${codePath}.map`;
|
|
528
|
+
const adjacentMapContent = await tryReadFile(adjacentMapPath);
|
|
529
|
+
if (adjacentMapContent) {
|
|
530
|
+
try {
|
|
531
|
+
const converter = convert.fromJSON(adjacentMapContent);
|
|
532
|
+
return {
|
|
533
|
+
map: converter.toObject(),
|
|
534
|
+
mapPath: adjacentMapPath
|
|
535
|
+
};
|
|
536
|
+
} catch {
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
const inlineConverter = convert.fromSource(code);
|
|
541
|
+
if (inlineConverter) {
|
|
542
|
+
return {
|
|
543
|
+
map: inlineConverter.toObject(),
|
|
544
|
+
mapPath: codePath
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
try {
|
|
550
|
+
const regex = new RegExp(convert.mapFileCommentRegex.source);
|
|
551
|
+
const commentMatch = regex.exec(code);
|
|
552
|
+
const referencedPath = commentMatch?.[1] ?? commentMatch?.[2];
|
|
553
|
+
if (!referencedPath) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const mapFilePath = path.join(path.dirname(codePath), referencedPath);
|
|
557
|
+
const mapContent = await tryReadFile(mapFilePath);
|
|
558
|
+
if (!mapContent) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const converter = convert.fromJSON(mapContent);
|
|
562
|
+
return {
|
|
563
|
+
map: converter.toObject(),
|
|
564
|
+
mapPath: mapFilePath
|
|
565
|
+
};
|
|
566
|
+
} catch {
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
const loadInputSourcemapsPlugin = () => ({
|
|
570
|
+
name: "load-input-sourcemaps",
|
|
571
|
+
async load(id) {
|
|
572
|
+
const isDts = dtsExtensions.some((extension) => id.endsWith(extension));
|
|
573
|
+
if (!isDts) {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const code = await tryReadFile(id);
|
|
577
|
+
if (!code) {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
const result = await loadSourceMap(id, code);
|
|
581
|
+
if (!result) {
|
|
582
|
+
return { code };
|
|
583
|
+
}
|
|
584
|
+
const { map: inputMap, mapPath } = result;
|
|
585
|
+
const sourceRoot = path.resolve(path.dirname(mapPath), inputMap.sourceRoot ?? ".");
|
|
586
|
+
const sources = inputMap.sources.map(
|
|
587
|
+
(source) => path.isAbsolute(source) ? source : path.resolve(sourceRoot, source)
|
|
588
|
+
);
|
|
589
|
+
const sourcesContentRaw = await Promise.all(
|
|
590
|
+
sources.map(async (source, index) => inputMap.sourcesContent?.[index] ?? tryReadFile(source))
|
|
591
|
+
);
|
|
592
|
+
const sourcesContent = sourcesContentRaw.filter(
|
|
593
|
+
(content) => content !== null
|
|
594
|
+
);
|
|
595
|
+
return {
|
|
596
|
+
code,
|
|
597
|
+
map: {
|
|
598
|
+
version: inputMap.version,
|
|
599
|
+
names: inputMap.names,
|
|
600
|
+
sources,
|
|
601
|
+
mappings: inputMap.mappings,
|
|
602
|
+
...sourcesContent.length > 0 ? { sourcesContent } : {},
|
|
603
|
+
...inputMap.file ? { file: inputMap.file } : {}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
|
|
517
609
|
const nodeModules = `${path.sep}node_modules${path.sep}`;
|
|
518
610
|
const removeBundledModulesPlugin = (outputDirectory, sizeRef) => {
|
|
519
611
|
let deleteFiles = [];
|
|
@@ -630,6 +722,8 @@ const build = async (input, outputDirectory, externals, mode, conditions, source
|
|
|
630
722
|
externalizePlugin,
|
|
631
723
|
removeBundledModulesPlugin(outputDirectory, sizeRef),
|
|
632
724
|
resolveSubpathImportsPlugin(),
|
|
725
|
+
// Load existing .d.ts.map files to chain sourcemaps back to original .ts sources
|
|
726
|
+
sourcemap && loadInputSourcemapsPlugin(),
|
|
633
727
|
nodeResolve({
|
|
634
728
|
extensions: [".ts", ...dtsExtensions],
|
|
635
729
|
exportConditions: conditions
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import 'node:path';
|
|
3
|
-
export { d as dtsroll } from './index-
|
|
3
|
+
export { d as dtsroll } from './index-r9RZgCg7.mjs';
|
|
4
4
|
import 'node:fs/promises';
|
|
5
5
|
import 'rollup';
|
|
6
6
|
import 'rollup-plugin-dts';
|
|
7
7
|
import '@rollup/plugin-node-resolve';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'convert-source-map';
|
|
8
10
|
import 'empathic/find';
|
|
9
11
|
import 'resolve-pkg-maps';
|
|
10
12
|
import 'byte-size';
|
package/dist/vite.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { d as dtsroll, l as logOutput } from './index-
|
|
2
|
+
import { d as dtsroll, l as logOutput } from './index-r9RZgCg7.mjs';
|
|
3
3
|
import 'node:path';
|
|
4
4
|
import 'node:fs/promises';
|
|
5
5
|
import 'rollup';
|
|
6
6
|
import 'rollup-plugin-dts';
|
|
7
7
|
import '@rollup/plugin-node-resolve';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'convert-source-map';
|
|
8
10
|
import 'empathic/find';
|
|
9
11
|
import 'resolve-pkg-maps';
|
|
10
12
|
import 'byte-size';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtsroll",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Bundle dts files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bundle",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
41
41
|
"byte-size": "^9.0.1",
|
|
42
42
|
"cleye": "^2.2.1",
|
|
43
|
+
"convert-source-map": "^2.0.0",
|
|
43
44
|
"empathic": "^2.0.0",
|
|
44
45
|
"resolve-pkg-maps": "^1.0.0",
|
|
45
46
|
"rollup": "^4.55.1",
|