Skip to content

Commit 44e207e

Browse files
fix breakline handling
1 parent f0fcaec commit 44e207e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

recipes/repl-builtin-modules/src/workflow.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import os from "node:os";
12
import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement";
23
import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call";
34
import type { SgRoot, Edit } from "@codemod.com/jssg-types/main";
45
import type Js from "@codemod.com/jssg-types/langs/javascript";
56

7+
const breakLine = os.EOL || "\n";
8+
69
/**
710
* Transform function that converts deprecated repl.builtinModules and repl._builtinLibs
811
* to module.builtinModules API.
@@ -147,7 +150,7 @@ export default function transform(root: SgRoot<Js>): string | null {
147150
const secondStatement = `const { builtinModules${aliasText} } = require(${newModule.includes('node:') ? "'node:module'" : "'module'"});`;
148151

149152
// Replace the entire variable declaration with both statements
150-
const replacementText = `${firstStatement}\n${secondStatement}`;
153+
const replacementText = `${firstStatement}${breakLine}${secondStatement}`;
151154

152155
edits.push(variableDeclaration.replace(replacementText));
153156

@@ -326,7 +329,7 @@ export default function transform(root: SgRoot<Js>): string | null {
326329
edits.push({
327330
startPos: statementEnd.index,
328331
endPos: statementEnd.index,
329-
insertedText: `\n${newStatement}`
332+
insertedText: `${breakLine}${newStatement}`
330333
});
331334

332335
// If original had _builtinLibs without alias, replace standalone references

0 commit comments

Comments
 (0)