Skip to content

Commit ae26811

Browse files
Copilotfregante
andcommitted
Simplify file writing and use actual file path in ts-morph
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent 60950f1 commit ae26811

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

add-examples-to-dts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable n/prefer-global/process, unicorn/no-process-exit, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */
2-
import {readFileSync} from 'node:fs';
2+
import {readFileSync, writeFileSync} from 'node:fs';
33
import {execSync} from 'node:child_process';
44
import {Project, type JSDocableNode} from 'ts-morph';
55
// Import index.ts to populate the test data via side effect
@@ -20,7 +20,7 @@ if (dtsContent.includes(marker)) {
2020

2121
// Create a ts-morph project and load the file
2222
const project = new Project();
23-
const sourceFile = project.createSourceFile('temp.d.ts', dtsContent, {overwrite: true});
23+
const sourceFile = project.createSourceFile(dtsPath, dtsContent, {overwrite: true});
2424

2525
let examplesAdded = 0;
2626

@@ -125,7 +125,7 @@ const modifiedContent = sourceFile.getFullText();
125125
const finalContent = `${marker}\n${modifiedContent}`;
126126

127127
// Write the modified content back
128-
sourceFile.getProject().createSourceFile(dtsPath, finalContent, {overwrite: true}).saveSync();
128+
writeFileSync(dtsPath, finalContent, 'utf8');
129129

130130
console.log(`✓ Added ${examplesAdded} example URLs to index.d.ts`);
131131

0 commit comments

Comments
 (0)