Skip to content

Commit

Permalink
fix(cli): Fix support for .d.ts (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jun 22, 2024
1 parent bf04342 commit c224d5a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
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.

0 comments on commit c224d5a

Please sign in to comment.