-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./", | ||
"moduleResolution": "node" | ||
}, | ||
|
||
"include": ["src", "__tests__"], | ||
"exclude": ["src/@runtime"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import chalk from 'chalk' | ||
import { Plugin } from 'esbuild' | ||
import { relative, join } from 'path' | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig({ | ||
entry: ['src'], | ||
outDir: 'lib', | ||
splitting: false, | ||
bundle: false, | ||
sourcemap: true, | ||
clean: false, | ||
target: 'node12', | ||
platform: 'node', | ||
dts: true, | ||
esbuildPlugins: [createPatchEsbuildDistPlugin()], | ||
}) | ||
|
||
// copied from https://github.com/vitejs/vite/blob/5d6ea8efc36bfdcd8b70afa8e82026ad1ccc0a77/scripts/patchEsbuildDist.ts, with a slight modification :) | ||
function createPatchEsbuildDistPlugin(): Plugin { | ||
return { | ||
name: 'patch-esbuild-dist', | ||
setup(build) { | ||
build.onEnd((result) => { | ||
const targetFile = result.outputFiles!.filter((f) => { | ||
return relative(__dirname, f.path) === join('lib', 'main.js') | ||
})[0] | ||
|
||
if (!targetFile) { | ||
console.error(chalk.red(`did not find targetFile`)) | ||
process.exit(1) | ||
} | ||
|
||
const modifiedCode = patchEsbuildDist(targetFile.text, 'Plugin') | ||
|
||
if (modifiedCode) { | ||
Object.defineProperty(targetFile, 'text', { value: modifiedCode }) | ||
} | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
function patchEsbuildDist(_code: string, varName: string) { | ||
let code = _code | ||
const moduleExportsLine = `module.exports = __toCommonJS(main_exports);` | ||
|
||
if (code.includes(moduleExportsLine)) { | ||
// overwrite for cjs require('...')() usage | ||
code = code.replace( | ||
moduleExportsLine, | ||
`module.exports = ${varName}; | ||
${varName}['default'] = ${varName};` | ||
) | ||
|
||
console.log(chalk.bold(`patched with overwrite for cjs require('...')()`)) | ||
return code | ||
} else { | ||
console.error(chalk.red(`post-esbuild bundling patch failed`)) | ||
process.exit(1) | ||
} | ||
} |
Oops, something went wrong.