Skip to content

Commit 743f42b

Browse files
resources: Move mkdirSync into writeGeneratedFile (#3697)
1 parent 30d51c3 commit 743f42b

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

resources/build-deno.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ for (const filepath of srcFiles) {
3333
transformed.dispose();
3434

3535
const destPath = path.join('./denoDist', filepath);
36-
fs.mkdirSync(path.dirname(destPath), { recursive: true });
3736
writeGeneratedFile(destPath, newContent);
3837
}
3938
}

resources/build-npm.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ assert(
4848
);
4949

5050
const tsHost = ts.createCompilerHost(tsOptions);
51-
tsHost.writeFile = (filepath, body) => {
52-
fs.mkdirSync(path.dirname(filepath), { recursive: true });
53-
writeGeneratedFile(filepath, body);
54-
};
51+
tsHost.writeFile = writeGeneratedFile;
5552

5653
const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
5754
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {

resources/diff-npm-package.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
33
import * as os from 'node:os';
44
import * as path from 'node:path';
55

6-
import { exec, execOutput, localRepoPath } from './utils';
6+
import { exec, execOutput, localRepoPath, writeGeneratedFile } from './utils';
77

88
const LOCAL = 'local';
99
const tmpDir = path.join(os.tmpdir(), 'graphql-js-npm-diff');
@@ -32,12 +32,8 @@ const diff = execOutput(`npm diff --diff=${fromPackage} --diff=${toPackage}`);
3232
if (diff === '') {
3333
console.log('No changes found!');
3434
} else {
35-
const reportsDir = localRepoPath('reports');
36-
if (!fs.existsSync(reportsDir)) {
37-
fs.mkdirSync(reportsDir);
38-
}
39-
const reportPath = path.join(reportsDir, 'npm-dist-diff.html');
40-
fs.writeFileSync(reportPath, generateReport(diff));
35+
const reportPath = localRepoPath('reports', 'npm-dist-diff.html');
36+
writeGeneratedFile(reportPath, generateReport(diff));
4137
console.log('Report saved to: ', reportPath);
4238
}
4339

resources/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const prettierConfig = JSON.parse(
106106

107107
export function writeGeneratedFile(filepath: string, body: string): void {
108108
const formatted = prettier.format(body, { filepath, ...prettierConfig });
109+
fs.mkdirSync(path.dirname(filepath), { recursive: true });
109110
fs.writeFileSync(filepath, formatted);
110111
}
111112

0 commit comments

Comments
 (0)