Skip to content

Commit

Permalink
refactor: Bundle cjs-hooks.ts in
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Jun 11, 2024
1 parent 220d316 commit 90362c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ 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',
'source/esm-hooks.ts',
'source/cjs-hooks.ts',
'source/esm-hooks.ts'
],
output: {
dir: 'lib',
Expand All @@ -30,7 +26,7 @@ export default defineConfig([
],
// Have to use Rollup's external option as rollup-plugin-node-externals
// only applies to Node builtins and npm dependencies.
external: /(?:esm|cjs)-hooks.js$/
external: [ './transform.cjs' ]
},

// This second configuration bundles Sucrase's parser to lib/transform.cjs
Expand Down
4 changes: 2 additions & 2 deletions source/esm-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { readFile } from 'node:fs/promises'
import { createRequire, type InitializeHook, type ResolveHook, type LoadHook } from 'node:module'
import type { InitializeHook, ResolveHook, LoadHook } from 'node:module'

const { transform } = createRequire(import.meta.url)('./transform.cjs') as typeof import('./transform.cjs')
const { transform } = await import('./transform.cjs')

let self: string
let defaultModuleType: NodeJS.ModuleType
Expand Down

0 comments on commit 90362c3

Please sign in to comment.