Skip to content

Commit e907c0a

Browse files
committed
fix: replace fork import file extension in cjs
1 parent be0477d commit e907c0a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/shy-terms-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/agents': patch
3+
---
4+
5+
Fork files with cjs extension when running cjs file

tsup.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@ const defaultOptions: Options = {
2424
// require('../path') → require('../path.cjs') in `.cjs` files
2525
// from './path' → from './path.cjs' in `.cjs` files
2626
// from '../path' → from '../path.cjs' in `.cjs` files
27+
// (0, import_node_child_process.fork)(new URL("./path.js" → (0, import_node_child_process.fork)(new URL("./path.cjs" in `.cjs` files
2728
name: 'fix-cjs-imports',
2829
renderChunk(code) {
2930
if (this.format === 'cjs') {
3031
const regexCjs = /require\((?<quote>['"])(?<import>\.[^'"]+)\.js['"]\)/g;
3132
const regexDynamic = /import\((?<quote>['"])(?<import>\.[^'"]+)\.js['"]\)/g;
3233
const regexEsm = /from(?<space>[\s]*)(?<quote>['"])(?<import>\.[^'"]+)\.js['"]/g;
34+
const regexForkCompiled =
35+
/\(0, import_node_child_process\.fork\)\(new URL\((?<quote>['"])(?<import>\.\/[^'"]+)\.js['"]/g;
3336
return {
3437
code: code
3538
.replace(regexCjs, 'require($<quote>$<import>.cjs$<quote>)')
3639
.replace(regexDynamic, 'import($<quote>$<import>.cjs$<quote>)')
37-
.replace(regexEsm, 'from$<space>$<quote>$<import>.cjs$<quote>'),
40+
.replace(regexEsm, 'from$<space>$<quote>$<import>.cjs$<quote>')
41+
.replace(
42+
regexForkCompiled,
43+
'(0, import_node_child_process.fork)(new URL($<quote>$<import>.cjs$<quote>',
44+
),
3845
};
3946
}
4047
},

0 commit comments

Comments
 (0)