Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Dec 23, 2024
1 parent 1913c77 commit d65ed2b
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import fs from "fs"
import * as devalue from "devalue"
import { parse } from "@babel/parser"
import path from "path"
import { createRequire } from "module"
import {
deadCodeElimination,
findReferencedIdentifiers,
} from "babel-dead-code-elimination"
import { bundleRequire } from "bundle-require"
import MagicString from "magic-string"
import { fileURLToPath } from "url"

// Injected by TSUP
declare const TSUP_FORMAT: "esm" | "cjs" | undefined
Expand All @@ -19,11 +17,6 @@ const req =
? createRequire(import.meta.url)
: require

const DIRNAME =
typeof __dirname === "undefined"
? path.dirname(fileURLToPath(import.meta.url))
: __dirname

const extensionsRe = /\.(([jt]sx?)|mjs|cjs|mts|cts|vue|astro|svelte)$/
type Match = { name: string; start: number; end: number }

Expand Down Expand Up @@ -141,12 +134,12 @@ export class Transformer {
_filepath = _filepath.replace(/\\/g, "/")
const content = fs.readFileSync(_filepath, "utf-8")
if (_filepath === filepath) {
// add await prefix
const s = new MagicString(content)
s.prepend(
`export const ${exportName} = {};const compileTime=fn=>typeof fn==='function'?fn():fn;`,
)

// add await prefix
for (const m of matches) {
s.prependLeft(
m.start,
Expand Down

0 comments on commit d65ed2b

Please sign in to comment.