workspace: ignore writing types to modules

This commit is contained in:
undefined committed 2023-12-15 16:05:05 +08:00
1 parent 6d37f5a132
commit d6afeef8e7
1 file changed
+7 -2
+7 -2
View File
@@ -2,7 +2,7 @@ const fs = require('fs-extra');
const path = require('path');
const child = require('child_process');
if (process.env.npm_execpath.includes('yarn')) {
if (process.env.npm_execpath?.includes('yarn')) {
if (fs.existsSync('plugins/patch-package/package.json') && fs.existsSync('node_modules/patch-package/package.json')) {
child.execSync('npx patch-package --patch-dir=plugins/patch-package/patches', { stdio: 'inherit' });
}
@@ -10,6 +10,10 @@ if (process.env.npm_execpath.includes('yarn')) {
const dir = path.dirname(path.dirname(require.resolve('@types/node/package.json')));
const types = fs.readdirSync(dir).filter((i) => !['sharedworker', 'serviceworker'].includes(i));
const withoutTypes = (data) => ({
...data,
compilerOptions: Object.fromEntries(Object.entries(data.compilerOptions).filter(([k]) => k !== 'types')),
});
/** @type {import('typescript/lib/typescript').CompilerOptions} */
const compilerOptionsBase = {
@@ -119,7 +123,8 @@ for (const package of modules) {
} catch (e) { }
if (!files.includes('src') && !files.filter((i) => i.endsWith('.ts')).length && package !== 'packages/utils') continue;
config.references.push({ path: package });
const expectedConfig = JSON.stringify((files.includes('src') ? configSrc : configFlat)(package));
const origConfig = (files.includes('src') ? configSrc : configFlat)(package);
const expectedConfig = JSON.stringify(package.startsWith('modules/') ? withoutTypes(origConfig) : origConfig);
const configPath = path.resolve(basedir, 'tsconfig.json');
const currentConfig = fs.existsSync(configPath) ? fs.readFileSync(configPath, 'utf-8') : '';
if (expectedConfig !== currentConfig) fs.writeFileSync(configPath, expectedConfig);