Skip to content

Commit

Permalink
Chore: Prevent changing timestamps on files to not confuse Yarn insta…
Browse files Browse the repository at this point in the history
…ll-state.gz
  • Loading branch information
SBoudrias committed Aug 5, 2023
1 parent c1864d9 commit 4ad31ef
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/setup-packages.mts
Expand Up @@ -6,8 +6,12 @@ import prettier from 'prettier';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

function readFile(filepath: string): Promise<string> {
return fs.promises.readFile(filepath, 'utf-8');
}

function readJSONFile(filepath: string): Promise<any> {
return fs.promises.readFile(filepath, 'utf-8').then(JSON.parse);
return readFile(filepath).then(JSON.parse);
}

function fileExists(filepath: string): Promise<boolean> {
Expand All @@ -17,6 +21,12 @@ function fileExists(filepath: string): Promise<boolean> {
);
}

async function writeFile(filepath: string, content: string): Promise<any> {
if ((await fileExists(filepath)) && (await readFile(filepath)) !== content) {
await fs.promises.writeFile(filepath, content);
}
}

const rootPkg = await readJSONFile(path.join(__dirname, '../package.json'));
const paths = await globby(['packages/**/package.json', '!**/node_modules']);

Expand Down Expand Up @@ -101,12 +111,9 @@ paths.forEach(async (pkgPath) => {
},
};

fs.promises.writeFile(path.join(dir, 'tsconfig.json'), await formatJSON(esmTsconfig));
fs.promises.writeFile(
path.join(dir, 'tsconfig.cjs.json'),
await formatJSON(cjsTsconfig),
);
writeFile(path.join(dir, 'tsconfig.json'), await formatJSON(esmTsconfig));
writeFile(path.join(dir, 'tsconfig.cjs.json'), await formatJSON(cjsTsconfig));
}

fs.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
});

0 comments on commit 4ad31ef

Please sign in to comment.