Skip to content

Commit

Permalink
build: Use bundler moduleResolution in tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Apr 23, 2024
1 parent 6b3f216 commit ba120ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 6 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import path from 'node:path'
import { readFile } from 'fs/promises'
import nodeExternals from 'rollup-plugin-node-externals'
Expand All @@ -9,6 +8,9 @@ import terser from '@rollup/plugin-terser'
import { defineConfig } from 'rollup'

export default defineConfig([
// The main entry points are not really bundled, they're only transpiled from TS to JS.
// We could use tsc itself for this but since we need Rollup to bundle Sucrase anyway,
// this configuration spares us a separate build step.
{
input: [
'source/index.ts',
Expand All @@ -27,11 +29,11 @@ export default defineConfig([
typescript('sucrase')
],
// Have to use Rollup's external option as rollup-plugin-node-externals
// only works for Node builtins and npm dependencies.
// only applies to Node builtins and npm dependencies.
external: /(?:esm|cjs)-hooks.js$/
},

// This second Rollup configuration bundles Sucrase's parser to lib/cjs-transform.cjs
// This second configuration bundles Sucrase's parser to lib/cjs-transform.cjs
{
input: 'source/cjs-transform.cts',
output: {
Expand All @@ -52,6 +54,7 @@ export default defineConfig([
terser(),

// This plugin fixes https://github.com/alangpierce/sucrase/issues/825
// by replacing sucrase's computeSourceMap.js with our own.
{
name: 'fix-sucrase',
async load(id) {
Expand Down
15 changes: 10 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"include": [ "source" ],
"include": [
"source",
"rollup.config.js"
],
"exclude": [
"source/fix-sucrase"
],
"compilerOptions": {

// Input
"rootDir": "source",
"moduleResolution": "Bundler",

// Output
"outDir": "lib",
"target": "ESNext",
"module": "Node16",
"checkJs": false,
"module": "ESNext",
"checkJs": true,
"noEmit": true,

// Libs
Expand Down

0 comments on commit ba120ff

Please sign in to comment.