Skip to content

Commit

Permalink
fix(js): add "dts" flag to swc executor
Browse files Browse the repository at this point in the history
  • Loading branch information
Chau Tran authored and Chau Tran committed Feb 22, 2022
1 parent 6861fa9 commit 6e170aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/generated/api-js/executors/swc.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Type: `array`

List of static assets.

### dts

Default: `true`

Type: `boolean`

Whether to emit Type Declarations using tsc.

### skipTypeCheck

Default: `false`
Expand Down
5 changes: 5 additions & 0 deletions packages/js/src/executors/swc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"description": "Whether to skip TypeScript type checking.",
"default": false
},
"dts": {
"type": "boolean",
"description": "Whether to emit Type Declarations using tsc.",
"default": true
},
"swcExclude": {
"type": "array",
"description": "List of SWC Glob/Regex to be excluded from compilation (https://swc.rs/docs/configuration/compilation#exclude)",
Expand Down
6 changes: 5 additions & 1 deletion packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecutorContext } from '@nrwl/devkit';
import { ExecutorContext, logger } from '@nrwl/devkit';
import {
assetGlobsToFiles,
FileInputOutput,
Expand All @@ -25,6 +25,10 @@ function normalizeOptions(
): NormalizedSwcExecutorOptions {
const outputPath = join(contextRoot, options.outputPath);

if (options.dts == null) {
options.dts = true;
}

if (options.skipTypeCheck == null) {
options.skipTypeCheck = false;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/js/src/utils/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface NormalizedExecutorOptions extends ExecutorOptions {

export interface SwcExecutorOptions extends ExecutorOptions {
skipTypeCheck?: boolean;
dts?: boolean;
swcExclude?: string[];
}

Expand All @@ -61,6 +62,7 @@ export interface NormalizedSwcExecutorOptions
extends NormalizedExecutorOptions {
swcExclude: string[];
skipTypeCheck: boolean;
dts: boolean;
swcCliOptions: SwcCliOptions;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/js/src/utils/swc/compile-swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ function getSwcCmd(
}

function getTypeCheckOptions(normalizedOptions: NormalizedSwcExecutorOptions) {
const { projectRoot, watch, tsConfig, root, outputPath } = normalizedOptions;
const { projectRoot, watch, tsConfig, root, outputPath, dts } =
normalizedOptions;

const typeCheckOptions: TypeCheckOptions = {
mode: 'emitDeclarationOnly',
mode: dts ? 'emitDeclarationOnly' : 'noEmit',
tsConfigPath: tsConfig,
outDir: outputPath.replace(`/${projectRoot}`, ''),
workspaceRoot: root,
Expand Down

0 comments on commit 6e170aa

Please sign in to comment.