Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Auto-generate TypeScript declaration maps #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
93 changes: 87 additions & 6 deletions packages/plugin-ts-standard-pkg/package-lock.json

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

1 change: 1 addition & 0 deletions packages/plugin-ts-standard-pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@pika/types": "^0.8.1",
"copy-concurrently": "^1.0.5",
"execa": "^2.0.0",
"standard-pkg": "^0.5.0"
},
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-ts-standard-pkg/pkg/dist-node/index.js

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

2 changes: 1 addition & 1 deletion packages/plugin-ts-standard-pkg/pkg/dist-node/index.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/plugin-ts-standard-pkg/pkg/dist-src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy from 'copy-concurrently';
import path from 'path';
import fs from 'fs';
import execa from 'execa';
Expand Down Expand Up @@ -86,13 +87,18 @@ export function manifest(newManifest) {
return newManifest;
}
export async function build({ cwd, out, options, reporter }) {
// Original source files are needed for declaration maps
const includedSrcDirectory = path.join(out, 'src/');
await copy(path.join(cwd, 'src/'), includedSrcDirectory);
const additionalArgs = options.args || [];
const result = execa(getTscBin(cwd), [
'--outDir',
path.join(out, 'dist-src/'),
'-d',
'--declarationDir',
path.join(out, 'dist-types/'),
'--declarationMap',
'true',
'--project',
getTsConfigPath(options, cwd),
'--target',
Expand All @@ -104,7 +110,7 @@ export async function build({ cwd, out, options, reporter }) {
'--sourceMap',
'false',
...additionalArgs,
], { cwd });
], { cwd: includedSrcDirectory });
result.stderr.pipe(process.stderr);
result.stdout.pipe(process.stdout);
await result.catch(err => {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ts-standard-pkg/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@pika/types": "^0.8.1",
"copy-concurrently": "^1.0.5",
"execa": "^2.0.0",
"standard-pkg": "^0.5.0"
},
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-ts-standard-pkg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy from 'copy-concurrently';
import path from 'path';
import fs from 'fs';
import execa from 'execa';
Expand Down Expand Up @@ -105,6 +106,10 @@ export function manifest(newManifest) {
}

export async function build({cwd, out, options, reporter}: BuilderOptions): Promise<void> {
// Original source files are needed for declaration maps
const includedSrcDirectory = path.join(out, 'src/');
await copy(path.join(cwd, 'src/'), includedSrcDirectory);

const additionalArgs = options.args || [];
const result = execa(
getTscBin(cwd),
Expand All @@ -114,6 +119,8 @@ export async function build({cwd, out, options, reporter}: BuilderOptions): Prom
'-d',
'--declarationDir',
path.join(out, 'dist-types/'),
'--declarationMap',
'true',
'--project',
getTsConfigPath(options, cwd),
'--target',
Expand All @@ -126,7 +133,7 @@ export async function build({cwd, out, options, reporter}: BuilderOptions): Prom
'false',
...additionalArgs,
],
{cwd},
{cwd: includedSrcDirectory},
);
result.stderr.pipe(process.stderr);
result.stdout.pipe(process.stdout);
Expand Down