Skip to content
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

fix(cli): Fix support for .d.ts #41

Merged
merged 4 commits into from
Jun 22, 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
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @swc/cli

## 0.3.14

### Patch Changes

- fe87a42: Fix dts support

## 0.3.13

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/cli",
"version": "0.3.13",
"version": "0.3.14",
"description": "CLI for the swc project",
"main": "lib/swc/index.js",
"scripts": {
Expand Down Expand Up @@ -56,7 +56,7 @@
"source-map": "^0.7.3"
},
"devDependencies": {
"@swc/cli": "=0.3.12",
"@swc/cli": "=0.3.13",
"@swc/core": "^1.6.4",
"@swc/jest": "workspace:^",
"@swc/types": "^0.1.9",
Expand Down
36 changes: 19 additions & 17 deletions packages/cli/src/swc/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,28 @@ function withSourceMap(
destFile: string,
destDir: string
) {
let dts: string | undefined;

// TODO: Remove once fixed in core
if ((output as any).output) {
const json = JSON.parse((output as any).output);

if (json.__swc_isolated_declarations__) {
dts = json.__swc_isolated_declarations__;
}
}

let dtsPath: string | undefined;

if (dts) {
dtsPath = join(destDir, basename(destFile) + ".d.ts");
}

if (!output.map || options.sourceMaps === "inline") {
return {
sourceCode: output.code,
dts,
dtsPath,
};
}
// TODO: remove once fixed in core https://github.com/swc-project/swc/issues/1388
Expand All @@ -32,23 +51,6 @@ function withSourceMap(
relative(destDir, sourceMapPath)
)}`;

let dts: string | undefined;

// TODO: Remove once fixed in core
if ((output as any).output) {
const json = JSON.parse((output as any).output);

if (json.__swc_isolated_declarations__) {
dts = json.__swc_isolated_declarations__;
}
}

let dtsPath: string | undefined;

if (dts) {
dtsPath = join(destDir, basename(destFile) + ".d.ts");
}

return {
sourceMap: output.map,
sourceMapPath,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

Loading