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

feat: Add transpileOnly flag to watch and build command #307

Merged
merged 7 commits into from
Dec 19, 2019
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
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Despite all the recent hype, setting up a new TypeScript (x React) library can b

- [Features](#features)
- [Quick Start](#quick-start)
- [`npm start` or `yarn start`](#npm-start-or-yarn-start)
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
- [`npm run build` or `yarn build`](#npm-run-build-or-yarn-build)
- [`npm test` or `yarn test`](#npm-test-or-yarn-test)
- [`npm run lint` or `yarn lint`](#npm-run-lint-or-yarn-lint)
- [`prepare` script](#prepare-script)
- [npm start or yarn start](#npm-start-or-yarn-start)
- [npm run build or yarn build](#npm-run-build-or-yarn-build)
- [npm test or yarn test](#npm-test-or-yarn-test)
- [npm run lint or yarn lint](#npm-run-lint-or-yarn-lint)
- [prepare script](#prepare-script)
- [Optimizations](#optimizations)
- [Development-only Expressions + Treeshaking](#development-only-expressions--treeshaking)
- [Rollup Treeshaking](#rollup-treeshaking)
- [Advanced `babel-plugin-dev-expressions`](#advanced-babel-plugin-dev-expressions)
- [`__DEV__`](#__dev__)
- [`invariant`](#invariant)
- [`warning`](#warning)
- [Advanced babel-plugin-dev-expressions](#advanced-babel-plugin-dev-expressions)
- [__DEV__](#dev)
- [invariant](#invariant)
- [warning](#warning)
- [Using lodash](#using-lodash)
- [Error extraction](#error-extraction)
- [Customization](#customization)
Expand All @@ -30,12 +30,13 @@ Despite all the recent hype, setting up a new TypeScript (x React) library can b
- [Inspiration](#inspiration)
- [Comparison to Microbundle](#comparison-to-microbundle)
- [API Reference](#api-reference)
- [`tsdx watch`](#tsdx-watch)
- [`tsdx build`](#tsdx-build)
- [`tsdx test`](#tsdx-test)
- [`tsdx lint`](#tsdx-lint)
- [tsdx watch](#tsdx-watch)
- [tsdx build](#tsdx-build)
- [tsdx test](#tsdx-test)
- [tsdx lint](#tsdx-lint)
- [Author](#author)
- [License](#license)
- [Contributors ✨](#contributors-%e2%9c%a8)

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

Expand Down Expand Up @@ -315,7 +316,7 @@ The `options` object contains the following:
export interface TsdxOptions {
// path to file
input: string;
// Safe name (for UMD)
// Name of package
name: string;
// JS target
target: 'node' | 'browser';
Expand All @@ -325,12 +326,14 @@ export interface TsdxOptions {
env: 'development' | 'production';
// Path to tsconfig file
tsconfig?: string;
// Is opt-in invariant error extraction active?
// Is error extraction running?
extractErrors?: boolean;
// Is minifying?
minify?: boolean;
// Is this the very first rollup config (and thus should one-off metadata be extracted)?
writeMeta?: boolean;
// Only transpile, do not type check (makes compilation faster)
transpileOnly?: boolean;
}
```

Expand Down Expand Up @@ -395,6 +398,7 @@ Options
--tsconfig Specify your custom tsconfig path (default <root-folder>/tsconfig.json)
--verbose Keep outdated console output in watch mode instead of clearing the screen
--noClean Don't clean the dist folder
--transpileOnly Skip type checking
-h, --help Displays this message

Examples
Expand All @@ -404,6 +408,7 @@ Examples
$ tsdx watch --format cjs,esm,umd
$ tsdx watch --tsconfig ./tsconfig.foo.json
$ tsdx watch --noClean
$ tsdx watch --transpileOnly
```

### `tsdx build`
Expand All @@ -422,6 +427,7 @@ Options
--format Specify module format(s) (default cjs,esm)
--extractErrors Opt-in to extracting invariant error codes
--tsconfig Specify your custom tsconfig path (default <root-folder>/tsconfig.json)
--transpileOnly Skip type checking
-h, --help Displays this message

Examples
Expand All @@ -431,6 +437,7 @@ Examples
$ tsdx build --format cjs,esm,umd
$ tsdx build --extractErrors
$ tsdx build --tsconfig ./tsconfig.foo.json
$ tsdx build --transpileOnly
```

### `tsdx test`
Expand Down
1 change: 1 addition & 0 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export async function createRollupConfig(opts: TsdxOptions) {
target: 'esnext',
},
},
check: opts.transpileOnly === false,
}),
babelPluginTsdx({
exclude: 'node_modules/**',
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ prog
.example('watch --noClean')
.option('--tsconfig', 'Specify custom tsconfig path')
.example('watch --tsconfig ./tsconfig.foo.json')
.option('--transpileOnly', 'Skip type checking', false)
.example('build --transpileOnly')
.option('--extractErrors', 'Extract invariant errors to ./errors/codes.json.')
.example('build --extractErrors')
.action(async (dirtyOpts: any) => {
Expand Down Expand Up @@ -397,6 +399,8 @@ prog
.example('build --format cjs,esm')
.option('--tsconfig', 'Specify custom tsconfig path')
.example('build --tsconfig ./tsconfig.foo.json')
.option('--transpileOnly', 'Skip type checking', false)
.example('build --transpileOnly')
.option(
'--extractErrors',
'Extract errors to ./errors/codes.json and provide a url for decoding.'
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface TsdxOptions {
minify?: boolean;
// Is this the very first rollup config (and thus should one-off metadata be extracted)?
writeMeta?: boolean;
// Only transpile, do not type check (makes compilation faster)
transpileOnly?: boolean;
}

export interface PackageJson {
Expand Down
19 changes: 18 additions & 1 deletion test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @jest-environment node
*/
'use strict';

const shell = require('shelljs');
const util = require('../fixtures/util');
Expand Down Expand Up @@ -85,6 +84,24 @@ describe('tsdx build', () => {
expect(code).toBe(1);
});

it('should only transpile and not type check', () => {
util.setupStageWithFixture(stageName, 'build-invalid');
const code = shell.exec('node ../dist/index.js build --transpileOnly').code;

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-invalid.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-invalid.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-invalid.esm.js')).toBeTruthy();

expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();

expect(code).toBe(0);
});

afterEach(() => {
util.teardownStage(stageName);
});
Expand Down