Skip to content

Commit

Permalink
feat: add no-check flag to disable tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Mar 14, 2022
1 parent d760b36 commit a3c832d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 29 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

Quickbundle allows you to bundle a library in a **quick**, **fast** and **easy** way:

- Fast build and watch mode thanks to [ESBuild bundler](https://github.com/evanw/esbuild)
- Fast build and watch mode thanks to [esbuild](https://esbuild.github.io/)
- Zero configuration: define the build artifacts in your `package.json` and you're all set!
- JavaScript, TypeScript, JSX, CSS, JSON and Text support following [ESBuild support](https://esbuild.github.io/content-types/)
- JavaScript, TypeScript, JSX, CSS, JSON and Text support following [esbuild support](https://esbuild.github.io/content-types/)
- Support of multiple module formats including `cjs` & `esm`
- Bundling can be done for several platform targets including `browser` or `node`
- Optimized build such as `peerDependencies` not bundled in the final output
Expand Down Expand Up @@ -41,10 +41,10 @@ yarn add quickbundle
"types": "./dist/lib.d.ts", // Typing output file
"platform": "node", // Platform target (optional, by default "browser")
"scripts": {
"prod": "quickbundle build", // Production mode (optimizes bundle)
"dev": "quickbundle watch", // Development mode (watches each file change)
"prod:fast": "quickbundle build --no-check", // Production mode with fast transpilation time. This mode disables TypeScript type checking (ie. not using `tsc`) and, consequently, the `types` asset is no more managed by the tool
"dev:fast": "quickbundle watch --no-check" // Development mode with fast transpilation time
"build": "quickbundle build", // Production mode (optimizes bundle)
"watch": "quickbundle watch", // Development mode (watches each file change)
"build:fast": "quickbundle build --no-check", // Production mode with fast transpilation time. This mode disables TypeScript type checking (ie. not using `tsc`) and, consequently, the `types` asset is no more managed by the tool
"watch:fast": "quickbundle watch --no-check" // Development mode with fast transpilation time
}
}
```
Expand Down
6 changes: 0 additions & 6 deletions TODO.md

This file was deleted.

4 changes: 3 additions & 1 deletion examples/ts-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"clean": "rm -rf dist",
"start": "yarn build && open public/index.html",
"build": "quickbundle build",
"watch": "quickbundle watch"
"watch": "quickbundle watch",
"build:fast": "quickbundle build --no-check",
"watch:fast": "quickbundle watch --no-check"
},
"devDependencies": {
"preact": "10.6.6",
Expand Down
4 changes: 3 additions & 1 deletion examples/ts-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"clean": "rm -rf dist",
"start": "yarn build && open public/index.html",
"build": "quickbundle build",
"watch": "quickbundle watch"
"watch": "quickbundle watch",
"build:fast": "quickbundle build --no-check",
"watch:fast": "quickbundle watch --no-check"
},
"dependencies": {
"ora": "5.4.0"
Expand Down
4 changes: 3 additions & 1 deletion examples/ts-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"clean": "rm -rf dist",
"start": "yarn build && open public/index.html",
"build": "quickbundle build",
"watch": "quickbundle watch"
"watch": "quickbundle watch",
"build:fast": "quickbundle build --no-check",
"watch:fast": "quickbundle watch --no-check"
},
"devDependencies": {
"typescript": "4.6.2"
Expand Down
4 changes: 3 additions & 1 deletion examples/ts-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"clean": "rm -rf dist",
"start": "yarn build && open public/index.html",
"build": "quickbundle build",
"watch": "quickbundle watch"
"watch": "quickbundle watch",
"build:fast": "quickbundle build --no-check",
"watch:fast": "quickbundle watch --no-check"
},
"devDependencies": {
"@types/react": "17.0.40",
Expand Down
18 changes: 10 additions & 8 deletions src/bundler/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { getPackageMetadata } from "./package";
import { jsxPlugin } from "./plugins";
import { getTypeScriptConfiguration } from "./typescript";

type BundlerOptions = {
type BundleParameters = {
isProduction: boolean;
onWatch: (error: Error | null) => void;
isFast: boolean;
onWatch?: (error: Error | null) => void;
};

export const bundle = async ({
isProduction = false,
isProduction,
isFast,
onWatch,
}: Partial<BundlerOptions>) => {
}: BundleParameters) => {
const {
destination,
externalDependencies,
Expand All @@ -25,8 +27,8 @@ export const bundle = async ({
source,
types,
} = getPackageMetadata();
const isWatchMode = typeof onWatch === "function";
const isTypingRequested = typeof types === "string";
const isWatching = typeof onWatch === "function";
const isTypingRequested = typeof types === "string" && !isFast;
const tsConfig = await getTypeScriptConfiguration();

const getType = async () => {
Expand Down Expand Up @@ -73,7 +75,7 @@ export const bundle = async ({
sourcemap: true,
target: tsConfig?.target || "esnext",
treeShaking: true,
watch: isWatchMode && {
watch: isWatching && {
async onRebuild(bundleError) {
let error: Error | null = bundleError as Error;

Expand Down Expand Up @@ -102,7 +104,7 @@ export const bundle = async ({
};

const promises = [
...(isWatchMode
...(isWatching
? [getJavaScript(hasModule ? "esm" : "cjs")]
: [getJavaScript("cjs"), getJavaScript("esm")]),
...(isTypingRequested ? [getType()] : []),
Expand Down
6 changes: 4 additions & 2 deletions src/program/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import gzipSize from "gzip-size";
import { Termost } from "termost";
import { bundle } from "../../bundler";
import { readFile } from "../../helpers";
import { ProgramContext } from "../types";

interface BuildCommandContext {
interface BuildCommandContext extends ProgramContext {
sizes: Array<{ filename: string; raw: number; gzip: number }>;
outfiles: Array<string>;
}
Expand All @@ -17,8 +18,9 @@ export const createBuildCommand = (program: Termost<BuildCommandContext>) => {
.task({
key: "outfiles",
label: "Bundle assets 📦",
async handler() {
async handler({ values }) {
const outfiles = await bundle({
isFast: values.noCheck,
isProduction: true,
});

Expand Down
6 changes: 4 additions & 2 deletions src/program/commands/watch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Termost } from "termost";
import { bundle } from "../../bundler";
import { ProgramContext } from "../types";

interface WatchCommandContext {
interface WatchCommandContext extends ProgramContext {
callbacks: {
onError: (message: string) => void;
onSuccess: () => void;
Expand All @@ -17,13 +18,14 @@ export const createWatchCommand = (program: Termost<WatchCommandContext>) => {
.task({
key: "callbacks",
label: "Setup watcher",
async handler() {
async handler({ values }) {
const callbacks: WatchCommandContext["callbacks"] = {
onError() {},
onSuccess() {},
};

bundle({
isFast: values.noCheck,
isProduction: false,
onWatch(error) {
if (error) {
Expand Down
11 changes: 10 additions & 1 deletion src/program/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { Termost, termost } from "termost";
import { createBuildCommand } from "./commands/build";
import { ProgramContext } from "./types";
import { createWatchCommand } from "./commands/watch";

const createProgram = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...commandBuilders: Array<(program: Termost<any>) => void>
) => {
const program = termost(
const program = termost<ProgramContext>(
"The zero-configuration bundler powered by ESBuild"
);

program.option({
key: "noCheck",
name: "no-check",
description:
"Enable fast mode by forcing the deactivation of `tsc` checking and types generation",
defaultValue: false,
});

for (const commandBuilder of commandBuilders) {
commandBuilder(program);
}
Expand Down
3 changes: 3 additions & 0 deletions src/program/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type ProgramContext = {
noCheck: boolean;
};

0 comments on commit a3c832d

Please sign in to comment.