rolldown-plugin-dts-snapshot 0.1.0 → 0.3.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 +48 -0
- package/dist/api.d.mts +5 -1
- package/dist/api.mjs +8 -6
- package/dist/index.d.mts +8 -3
- package/dist/index.mjs +3 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,6 +12,54 @@ DTS snapshot plugin for Rolldown
|
|
|
12
12
|
npm i rolldown-plugin-dts-snapshot
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### tsdown
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { DtsSnapshot } from 'rolldown-plugin-dts-snapshot'
|
|
21
|
+
import { defineConfig } from 'tsdown'
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
entry: 'src/index.ts',
|
|
25
|
+
dts: true,
|
|
26
|
+
plugins: [DtsSnapshot()],
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Rolldown
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { defineConfig } from 'rolldown'
|
|
34
|
+
import { dts } from 'rolldown-plugin-dts'
|
|
35
|
+
import { DtsSnapshot } from 'rolldown-plugin-dts-snapshot'
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
input: 'src/index.ts',
|
|
39
|
+
plugins: [dts(), DtsSnapshot()],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
export interface Options {
|
|
47
|
+
/**
|
|
48
|
+
* @default /\.d\.[cm]?ts$/
|
|
49
|
+
*/
|
|
50
|
+
include?: FilterPattern
|
|
51
|
+
exclude?: FilterPattern
|
|
52
|
+
/**
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
includeNonExport?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* @default '[cwd]/dts.snapshot.json'
|
|
58
|
+
*/
|
|
59
|
+
saveTo?: string
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
15
63
|
## Sponsors
|
|
16
64
|
|
|
17
65
|
<p align="center">
|
package/dist/api.d.mts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
//#region src/api.d.ts
|
|
2
|
-
declare function snapshot(code: string, fileName?: string
|
|
2
|
+
declare function snapshot(code: string, fileName?: string, {
|
|
3
|
+
applyExportRename
|
|
4
|
+
}?: {
|
|
5
|
+
applyExportRename?: boolean;
|
|
6
|
+
}): Record<string, string>;
|
|
3
7
|
//#endregion
|
|
4
8
|
export { snapshot };
|
package/dist/api.mjs
CHANGED
|
@@ -6,13 +6,13 @@ import { parseSync } from "rolldown/experimental";
|
|
|
6
6
|
//#region src/api.ts
|
|
7
7
|
const multilineCommentsRE = /\/\*.*?\*\//gs;
|
|
8
8
|
const singlelineCommentsRE = /\/\/.*$/gm;
|
|
9
|
-
function snapshot(code, fileName = "dummy.d.ts") {
|
|
9
|
+
function snapshot(code, fileName = "dummy.d.ts", { applyExportRename = true } = {}) {
|
|
10
10
|
code = code.replaceAll(multilineCommentsRE, "").replaceAll(singlelineCommentsRE, "");
|
|
11
11
|
const s = new MagicString(code);
|
|
12
12
|
const slice = (node) => s.slice(node.start, node.end);
|
|
13
13
|
const { program } = parseSync(fileName, code);
|
|
14
14
|
walk(program, { enter(node, parent, key) {
|
|
15
|
-
if (key === "params" && node.type === "Identifier") {
|
|
15
|
+
if (key === "params" && (node.type === "Identifier" || node.type === "ObjectPattern" || node.type === "ArrayPattern")) {
|
|
16
16
|
const end = node.typeAnnotation?.start ?? node.end;
|
|
17
17
|
s.overwrite(node.start, end, "_");
|
|
18
18
|
}
|
|
@@ -36,10 +36,12 @@ function snapshot(code, fileName = "dummy.d.ts") {
|
|
|
36
36
|
else if ("id" in decl && decl.id) register(nodeToString(decl.id), decl);
|
|
37
37
|
else if (decl.type === "ExportDefaultDeclaration" && "id" in decl.declaration && decl.declaration.id) register("default", decl.declaration);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if (applyExportRename) {
|
|
40
|
+
for (const stmt of program.body) if (stmt.type === "ExportNamedDeclaration" && stmt.declaration === null && stmt.specifiers.length) for (const specifier of stmt.specifiers) {
|
|
41
|
+
const exported = nodeToString(specifier.exported);
|
|
42
|
+
const local = nodeToString(specifier.local);
|
|
43
|
+
if (local !== exported) result[exported] = result[local];
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
return result;
|
|
45
47
|
function nodeToString(node) {
|
package/dist/index.d.mts
CHANGED
|
@@ -9,14 +9,19 @@ interface Options {
|
|
|
9
9
|
include?: FilterPattern;
|
|
10
10
|
exclude?: FilterPattern;
|
|
11
11
|
/**
|
|
12
|
-
* @default
|
|
12
|
+
* @default false
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
includeNonExport?: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* @default '[cwd]/dts.snapshot.json'
|
|
17
17
|
*/
|
|
18
18
|
saveTo?: string;
|
|
19
19
|
}
|
|
20
|
-
declare function DtsSnapshot(
|
|
20
|
+
declare function DtsSnapshot({
|
|
21
|
+
include,
|
|
22
|
+
exclude,
|
|
23
|
+
includeNonExport,
|
|
24
|
+
saveTo
|
|
25
|
+
}?: Options): Plugin;
|
|
21
26
|
//#endregion
|
|
22
27
|
export { DtsSnapshot, Options };
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,7 @@ import { createFilter } from "unplugin-utils";
|
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
7
|
-
function DtsSnapshot(
|
|
8
|
-
const { include = RE_DTS, exclude, excludeNonExport = true, saveTo = "dts.snapshot.json" } = options;
|
|
7
|
+
function DtsSnapshot({ include = RE_DTS, exclude, includeNonExport = true, saveTo = "dts.snapshot.json" } = {}) {
|
|
9
8
|
const filter = createFilter(include, exclude);
|
|
10
9
|
return {
|
|
11
10
|
name: "rolldown-plugin-dts-snapshot",
|
|
@@ -15,9 +14,9 @@ function DtsSnapshot(options = {}) {
|
|
|
15
14
|
const result = Object.create(null);
|
|
16
15
|
for (const chunk of Object.values(bundle)) {
|
|
17
16
|
if (chunk.type === "asset" || !filter(chunk.fileName)) continue;
|
|
18
|
-
const map = result[chunk.
|
|
17
|
+
const map = result[chunk.preliminaryFileName] = snapshot(chunk.code, chunk.fileName, { applyExportRename: chunk.isEntry });
|
|
19
18
|
if (chunk.isEntry) {
|
|
20
|
-
if (
|
|
19
|
+
if (!includeNonExport) {
|
|
21
20
|
for (const key of Object.keys(map)) if (key !== "#exports" && !chunk.exports.includes(key)) delete map[key];
|
|
22
21
|
}
|
|
23
22
|
map["#exports"] = chunk.exports;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-plugin-dts-snapshot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "DTS snapshot plugin for Rolldown",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@oxc-project/types": "^0.105.0",
|
|
45
|
-
"@sxzz/eslint-config": "^7.4.
|
|
45
|
+
"@sxzz/eslint-config": "^7.4.4",
|
|
46
46
|
"@sxzz/prettier-config": "^2.2.6",
|
|
47
47
|
"@types/node": "^25.0.3",
|
|
48
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
48
|
+
"@typescript/native-preview": "7.0.0-dev.20251222.1",
|
|
49
49
|
"bumpp": "^10.3.2",
|
|
50
50
|
"eslint": "^9.39.2",
|
|
51
51
|
"prettier": "^3.7.4",
|