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!: support tsconfig: false and inline object to disable tsconfig resolving #45

Merged
merged 2 commits into from
Jun 1, 2024
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
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
Loading