File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
recipes/repl-builtin-modules/src Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change
1
+ import os from "node:os" ;
1
2
import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement" ;
2
3
import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call" ;
3
4
import type { SgRoot , Edit } from "@codemod.com/jssg-types/main" ;
4
5
import type Js from "@codemod.com/jssg-types/langs/javascript" ;
5
6
7
+ const breakLine = os . EOL || "\n" ;
8
+
6
9
/**
7
10
* Transform function that converts deprecated repl.builtinModules and repl._builtinLibs
8
11
* to module.builtinModules API.
@@ -147,7 +150,7 @@ export default function transform(root: SgRoot<Js>): string | null {
147
150
const secondStatement = `const { builtinModules${ aliasText } } = require(${ newModule . includes ( 'node:' ) ? "'node:module'" : "'module'" } );` ;
148
151
149
152
// Replace the entire variable declaration with both statements
150
- const replacementText = `${ firstStatement } \n ${ secondStatement } ` ;
153
+ const replacementText = `${ firstStatement } ${ breakLine } ${ secondStatement } ` ;
151
154
152
155
edits . push ( variableDeclaration . replace ( replacementText ) ) ;
153
156
@@ -326,7 +329,7 @@ export default function transform(root: SgRoot<Js>): string | null {
326
329
edits . push ( {
327
330
startPos : statementEnd . index ,
328
331
endPos : statementEnd . index ,
329
- insertedText : `\n ${ newStatement } `
332
+ insertedText : `${ breakLine } ${ newStatement } `
330
333
} ) ;
331
334
332
335
// If original had _builtinLibs without alias, replace standalone references
You can’t perform that action at this time.
0 commit comments