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

refactor!: don't resolve tsconfig #370

Merged
merged 1 commit into from
Sep 20, 2023
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
7 changes: 7 additions & 0 deletions example/class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class A {
foo = 'bar'
num
constructor() {
this.num ||= 2
}
}
3 changes: 2 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import * as Vue from 'vue'
import React from 'react'
import * as Three from 'three'
import * as _ from 'lodash'
import * as clz from './class'

export { Foo, Vue, React, Three, _ }
export { Foo, Vue, React, Three, _, clz }
5 changes: 5 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"useDefineForClassFields": false
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
"@rollup/pluginutils": "^5.0.4",
"debug": "^4.3.4",
"es-module-lexer": "^1.3.1",
"joycon": "^3.1.1",
"jsonc-parser": "^3.2.0"
"joycon": "^3.1.1"
},
"peerDependencies": {
"esbuild": ">=0.10.1",
"esbuild": ">=0.18.0",
"rollup": "^1.20.0 || ^2.0.0 || ^3.0.0"
},
"engines": {
Expand Down
4 changes: 1 addition & 3 deletions pnpm-lock.yaml

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

22 changes: 9 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { existsSync, statSync } from 'fs'
import { extname, resolve, dirname, join } from 'path'
import { Plugin as RollupPlugin } from 'rollup'
import { readFile } from 'fs/promises'
import { transform, Loader, TransformOptions } from 'esbuild'
import { MarkOptional } from 'ts-essentials'
import { createFilter, FilterPattern } from '@rollup/pluginutils'
import createDebug from 'debug'
import { getOptions } from './options'
import { minify, getRenderChunk } from './minify'
import { warn } from './warn'
import {
optimizeDeps as doOptimizeDeps,
OptimizeDepsOptions,
OptimizeDepsResult,
} from './optimizer/optmize-deps'
import { getTsconfig } from './tsconfig'

export { minify }

Expand All @@ -25,10 +26,7 @@ const defaultLoaders: { [ext: string]: Loader } = {
'.tsx': 'tsx',
}

export type Options = Omit<
TransformOptions,
'sourcemap' | 'loader' | 'tsconfigRaw'
> & {
export type Options = Omit<TransformOptions, 'sourcemap' | 'loader'> & {
include?: FilterPattern
exclude?: FilterPattern
sourceMap?: boolean
Expand Down Expand Up @@ -152,19 +150,17 @@ export default ({
return null
}

const defaultOptions =
tsconfig === false ? {} : await getOptions(dirname(id), tsconfig)
const tsconfigRaw =
tsconfig === false
? undefined
: await getTsconfig(dirname(id), tsconfig)

const result = await transform(code, {
loader,
target: defaultOptions.target || 'es2017',
jsxFactory: defaultOptions.jsxFactory,
jsxFragment: defaultOptions.jsxFragment,
jsx: defaultOptions.jsx,
// Compat: passing this option in older esbuild version will result in error
...(defaultOptions.jsxDev ? { jsxDev: true } : {}),
sourcemap: sourceMap,
sourcefile: id,
tsconfigRaw,
target: 'es2020',
...esbuildOptions,
})

Expand Down
56 changes: 0 additions & 56 deletions src/options.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { readFile } from 'fs/promises'
import JoyCon from 'joycon'

const joycon = new JoyCon()

joycon.addLoader({
test: /\.json$/,
load: (file) => readFile(file, 'utf8'),
})

export const getTsconfig = async (
cwd: string,
tsconfig?: string,
): Promise<string> => {
// This call is cached
const { data } = await joycon.load([tsconfig || 'tsconfig.json'], cwd)
return data
}