Skip to content

Commit

Permalink
feat: support tsconfig: false and inline object to disable tsconfig…
Browse files Browse the repository at this point in the history
… resolving (#45)

BREAKING CHANGES:

- requires esbuild 0.18
  • Loading branch information
antfu authored and egoist committed Jun 1, 2024
1 parent 7db8ecb commit 20b0014
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 76 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"devDependencies": {
"@egoist/prettier-config": "1.0.0",
"@types/node": "18.11.18",
"esbuild": "0.17.5",
"esbuild": "0.18.20",
"prettier": "2.8.3",
"tsup": "6.5.0",
"typescript": "4.9.5",
Expand All @@ -36,9 +36,9 @@
"load-tsconfig": "^0.2.3"
},
"peerDependencies": {
"esbuild": ">=0.17"
"esbuild": ">=0.18"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
}
140 changes: 70 additions & 70 deletions pnpm-lock.yaml

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

20 changes: 17 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
BuildFailure,
BuildResult,
Plugin as EsbuildPlugin,
TsconfigRaw,
} from "esbuild"
import { loadTsConfig } from "load-tsconfig"
import { dynamicImport, getRandomId, guessFormat } from "./utils"
Expand Down Expand Up @@ -90,8 +91,13 @@ export interface Options {
*/
externalNodeModules?: boolean

/** A custom tsconfig path to read `paths` option */
tsconfig?: string
/**
* A custom tsconfig path to read `paths` option
*
* Set to `false` to disable tsconfig
* Or provide a `TsconfigRaw` object
*/
tsconfig?: string | TsconfigRaw | false

/**
* Preserve compiled temporary file for debugging
Expand Down Expand Up @@ -228,7 +234,12 @@ export function bundleRequire<T = any>(
options.preserveTemporaryFile ?? !!process.env.BUNDLE_REQUIRE_PRESERVE
const cwd = options.cwd || process.cwd()
const format = options.format ?? guessFormat(options.filepath)
const tsconfig = loadTsConfig(cwd, options.tsconfig)
const tsconfig = options.tsconfig === false
? undefined
: typeof options.tsconfig === "string" || !options.tsconfig
? loadTsConfig(cwd, options.tsconfig)
: { data: options.tsconfig, path: undefined }

const resolvePaths = tsconfigPathsToRegExp(
tsconfig?.data.compilerOptions?.paths || {},
)
Expand Down Expand Up @@ -281,6 +292,9 @@ export function bundleRequire<T = any>(
bundle: true,
metafile: true,
write: false,
...(tsconfig?.path)
? { tsconfig: tsconfig.path }
: { tsconfigRaw: tsconfig?.data || {} },
plugins: [
...(options.esbuildOptions?.plugins || []),
externalPlugin({
Expand Down

0 comments on commit 20b0014

Please sign in to comment.