mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
workspace: ignore writing types to modules
This commit is contained in:
1 file changed
+7
-2
+7
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user