Skip to content

feat: use vue-tsc generate vue declarations #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,24 @@
"sass": "^1.70.0",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vue": "^3.3.4",
"vue-tsc": "^1.8.5",
"vitest": "^1.2.1"
},
"peerDependencies": {
"sass": "^1.69.7",
"typescript": ">=5.3.3"
"typescript": ">=5.3.3",
"vue-tsc": "^1.8.5"
},
"peerDependenciesMeta": {
"sass": {
"optional": true
},
"typescript": {
"optional": true
},
"vue-tsc": {
"optional": true
}
},
"packageManager": "[email protected]"
Expand Down
185 changes: 185 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions src/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Loader,
} from "./loader";
import { getDeclarations } from "./utils/dts";
import { getVueDeclarations } from "./utils/vue-dts";
import { LoaderName } from "./loaders";

export interface MkdistOptions extends LoaderOptions {
Expand Down Expand Up @@ -76,13 +77,11 @@ export async function mkdist(
// Generate declarations
const dtsOutputs = outputs.filter((o) => o.declaration && !o.skip);
if (dtsOutputs.length > 0) {
const declarations = await getDeclarations(
new Map(dtsOutputs.map((o) => [o.srcPath, o.contents || ""])),
{
addRelativeDeclarationExtensions:
options.addRelativeDeclarationExtensions,
},
);
const vfs = new Map(dtsOutputs.map((o) => [o.srcPath, o.contents || ""]));
const declarations = Object.create(null);
for (const loader of [getVueDeclarations, getDeclarations]) {
Object.assign(declarations, await loader(vfs, options));
}
for (const output of dtsOutputs) {
output.contents = declarations[output.srcPath] || "";
}
Expand Down
10 changes: 10 additions & 0 deletions src/utils/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export async function getDeclarations(
const program = ts.createProgram(inputFiles, compilerOptions, tsHost);
await program.emit();

return extractDeclarations(vfs, inputFiles, opts);
}

export function extractDeclarations(
vfs: Map<string, string>,
inputFiles: string[],
opts?: GetDeclarationsOptions,
) {
const output: Record<string, string> = {};

for (const filename of inputFiles) {
Expand All @@ -60,6 +68,8 @@ export async function getDeclarations(
}
}
output[filename] = contents;

vfs.delete(filename);
}

return output;
Expand Down
Loading