From d6afeef8e7f4cfd43ba55b345cc0857dbbb734e7 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 15 Dec 2023 16:05:05 +0800 Subject: [PATCH] workspace: ignore writing types to modules --- build/prepare.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build/prepare.js b/build/prepare.js index 3b30b4e5c..a15453143 100644 --- a/build/prepare.js +++ b/build/prepare.js @@ -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);