Skip to content

Commit ee4b307

Browse files
sebaldjaredpalmer
authored andcommitted
feat: Add transpileOnly flag to watch and build command (#307)
* add --transpileOnly flag Ref #243 * Document --transpileOnly flag * Make test check that stuff is build * fix anchor id * remove shorthand * remove docs
1 parent fd1aa64 commit ee4b307

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ Despite all the recent hype, setting up a new TypeScript (x React) library can b
99

1010
- [Features](#features)
1111
- [Quick Start](#quick-start)
12-
- [`npm start` or `yarn start`](#npm-start-or-yarn-start)
13-
- [`npm run build` or `yarn build`](#npm-run-build-or-yarn-build)
14-
- [`npm test` or `yarn test`](#npm-test-or-yarn-test)
15-
- [`npm run lint` or `yarn lint`](#npm-run-lint-or-yarn-lint)
16-
- [`prepare` script](#prepare-script)
12+
- [npm start or yarn start](#npm-start-or-yarn-start)
13+
- [npm run build or yarn build](#npm-run-build-or-yarn-build)
14+
- [npm test or yarn test](#npm-test-or-yarn-test)
15+
- [npm run lint or yarn lint](#npm-run-lint-or-yarn-lint)
16+
- [prepare script](#prepare-script)
1717
- [Optimizations](#optimizations)
1818
- [Development-only Expressions + Treeshaking](#development-only-expressions--treeshaking)
1919
- [Rollup Treeshaking](#rollup-treeshaking)
20-
- [Advanced `babel-plugin-dev-expressions`](#advanced-babel-plugin-dev-expressions)
21-
- [`__DEV__`](#__dev__)
22-
- [`invariant`](#invariant)
23-
- [`warning`](#warning)
20+
- [Advanced babel-plugin-dev-expressions](#advanced-babel-plugin-dev-expressions)
21+
- [__DEV__](#dev)
22+
- [invariant](#invariant)
23+
- [warning](#warning)
2424
- [Using lodash](#using-lodash)
2525
- [Error extraction](#error-extraction)
2626
- [Customization](#customization)
@@ -30,12 +30,13 @@ Despite all the recent hype, setting up a new TypeScript (x React) library can b
3030
- [Inspiration](#inspiration)
3131
- [Comparison to Microbundle](#comparison-to-microbundle)
3232
- [API Reference](#api-reference)
33-
- [`tsdx watch`](#tsdx-watch)
34-
- [`tsdx build`](#tsdx-build)
35-
- [`tsdx test`](#tsdx-test)
36-
- [`tsdx lint`](#tsdx-lint)
33+
- [tsdx watch](#tsdx-watch)
34+
- [tsdx build](#tsdx-build)
35+
- [tsdx test](#tsdx-test)
36+
- [tsdx lint](#tsdx-lint)
3737
- [Author](#author)
3838
- [License](#license)
39+
- [Contributors ✨](#contributors-%e2%9c%a8)
3940

4041
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4142

@@ -315,7 +316,7 @@ The `options` object contains the following:
315316
export interface TsdxOptions {
316317
// path to file
317318
input: string;
318-
// Safe name (for UMD)
319+
// Name of package
319320
name: string;
320321
// JS target
321322
target: 'node' | 'browser';
@@ -325,12 +326,14 @@ export interface TsdxOptions {
325326
env: 'development' | 'production';
326327
// Path to tsconfig file
327328
tsconfig?: string;
328-
// Is opt-in invariant error extraction active?
329+
// Is error extraction running?
329330
extractErrors?: boolean;
330331
// Is minifying?
331332
minify?: boolean;
332333
// Is this the very first rollup config (and thus should one-off metadata be extracted)?
333334
writeMeta?: boolean;
335+
// Only transpile, do not type check (makes compilation faster)
336+
transpileOnly?: boolean;
334337
}
335338
```
336339

@@ -395,6 +398,7 @@ Options
395398
--tsconfig Specify your custom tsconfig path (default <root-folder>/tsconfig.json)
396399
--verbose Keep outdated console output in watch mode instead of clearing the screen
397400
--noClean Don't clean the dist folder
401+
--transpileOnly Skip type checking
398402
-h, --help Displays this message
399403
400404
Examples
@@ -404,6 +408,7 @@ Examples
404408
$ tsdx watch --format cjs,esm,umd
405409
$ tsdx watch --tsconfig ./tsconfig.foo.json
406410
$ tsdx watch --noClean
411+
$ tsdx watch --transpileOnly
407412
```
408413
409414
### `tsdx build`
@@ -422,6 +427,7 @@ Options
422427
--format Specify module format(s) (default cjs,esm)
423428
--extractErrors Opt-in to extracting invariant error codes
424429
--tsconfig Specify your custom tsconfig path (default <root-folder>/tsconfig.json)
430+
--transpileOnly Skip type checking
425431
-h, --help Displays this message
426432
427433
Examples
@@ -431,6 +437,7 @@ Examples
431437
$ tsdx build --format cjs,esm,umd
432438
$ tsdx build --extractErrors
433439
$ tsdx build --tsconfig ./tsconfig.foo.json
440+
$ tsdx build --transpileOnly
434441
```
435442
436443
### `tsdx test`

src/createRollupConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export async function createRollupConfig(opts: TsdxOptions) {
153153
target: 'esnext',
154154
},
155155
},
156+
check: opts.transpileOnly === false,
156157
}),
157158
babelPluginTsdx({
158159
exclude: 'node_modules/**',

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ prog
335335
.example('watch --noClean')
336336
.option('--tsconfig', 'Specify custom tsconfig path')
337337
.example('watch --tsconfig ./tsconfig.foo.json')
338+
.option('--transpileOnly', 'Skip type checking', false)
339+
.example('build --transpileOnly')
338340
.option('--extractErrors', 'Extract invariant errors to ./errors/codes.json.')
339341
.example('build --extractErrors')
340342
.action(async (dirtyOpts: any) => {
@@ -397,6 +399,8 @@ prog
397399
.example('build --format cjs,esm')
398400
.option('--tsconfig', 'Specify custom tsconfig path')
399401
.example('build --tsconfig ./tsconfig.foo.json')
402+
.option('--transpileOnly', 'Skip type checking', false)
403+
.example('build --transpileOnly')
400404
.option(
401405
'--extractErrors',
402406
'Extract errors to ./errors/codes.json and provide a url for decoding.'

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface TsdxOptions {
1717
minify?: boolean;
1818
// Is this the very first rollup config (and thus should one-off metadata be extracted)?
1919
writeMeta?: boolean;
20+
// Only transpile, do not type check (makes compilation faster)
21+
transpileOnly?: boolean;
2022
}
2123

2224
export interface PackageJson {

test/tests/tsdx-build.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @jest-environment node
33
*/
4-
'use strict';
54

65
const shell = require('shelljs');
76
const util = require('../fixtures/util');
@@ -85,6 +84,24 @@ describe('tsdx build', () => {
8584
expect(code).toBe(1);
8685
});
8786

87+
it('should only transpile and not type check', () => {
88+
util.setupStageWithFixture(stageName, 'build-invalid');
89+
const code = shell.exec('node ../dist/index.js build --transpileOnly').code;
90+
91+
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
92+
expect(
93+
shell.test('-f', 'dist/build-invalid.cjs.development.js')
94+
).toBeTruthy();
95+
expect(
96+
shell.test('-f', 'dist/build-invalid.cjs.production.min.js')
97+
).toBeTruthy();
98+
expect(shell.test('-f', 'dist/build-invalid.esm.js')).toBeTruthy();
99+
100+
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();
101+
102+
expect(code).toBe(0);
103+
});
104+
88105
afterEach(() => {
89106
util.teardownStage(stageName);
90107
});

0 commit comments

Comments
 (0)