-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build to fix CommonJS consumers
- Loading branch information
Showing
6 changed files
with
54 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { readFile, readdir, unlink, writeFile } from "node:fs/promises"; | ||
import { join } from "node:path"; | ||
|
||
async function fixCjsFiles(dir) { | ||
const files = await readdir(dir, { withFileTypes: true }); | ||
|
||
for (const file of files) { | ||
const fullPath = join(dir, file.name); | ||
|
||
if (file.isDirectory()) { | ||
await fixCjsFiles(fullPath); | ||
continue; | ||
} | ||
|
||
// First read and fix content | ||
if (file.name.endsWith(".js") || file.name.endsWith(".cjs")) { | ||
const content = await readFile(fullPath, "utf8"); | ||
const fixedContent = content.replace( | ||
/require\("(.+?)\.js"\)/gm, | ||
'require("$1.cjs")', | ||
); | ||
|
||
// Write fixed content to .cjs file | ||
const newPath = fullPath.replace(/\.js$/, ".cjs"); | ||
await writeFile(newPath, fixedContent); | ||
|
||
// Remove old .js file if it exists | ||
if (newPath !== fullPath) { | ||
await unlink(fullPath); | ||
} | ||
} | ||
} | ||
} | ||
|
||
await fixCjsFiles("./dist/cjs"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.esm.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"declarationMap": true, | ||
"outDir": "./dist/types" | ||
} | ||
} |