diff --git a/packages/lexical-devtools/package.json b/packages/lexical-devtools/package.json index dc21c7fcbb5..a71f147c7d9 100644 --- a/packages/lexical-devtools/package.json +++ b/packages/lexical-devtools/package.json @@ -34,15 +34,15 @@ "zustand": "^4.5.1" }, "devDependencies": { + "@lexical/devtools-core": "0.14.5", + "@rollup/plugin-babel": "^6.0.4", "@types/react": "^18.2.46", "@types/react-dom": "^18.2.18", "@vitejs/plugin-react": "^4.2.1", - "typescript": "^5.3.3", "lexical": "0.14.5", - "@lexical/devtools-core": "0.14.5", - "wxt": "^0.17.0", + "typescript": "^5.3.3", "vite": "^5.2.2", - "@rollup/plugin-babel": "^6.0.4" + "wxt": "^0.17.0" }, "sideEffects": false } diff --git a/scripts/update-tsconfig.js b/scripts/update-tsconfig.js index 4efa7a9cbd6..64fa49c7c75 100644 --- a/scripts/update-tsconfig.js +++ b/scripts/update-tsconfig.js @@ -16,17 +16,24 @@ const {packagesManager} = require('./shared/packagesManager'); /** * @typedef {Object} UpdateTsconfigOptions + * @property {Array<[string, Array]>} extraPaths additional paths to add * @property {string} jsonFileName path to the tsconfig.json + * @property {import('prettier').Options} prettierConfig the monorepo prettier config * @property {boolean} test true to include the test paths (default: false) - * @property {Array<[string, Array]>} extraPaths additional paths to add */ /** * @param {opts} UpdateTsconfigOptions + * @returns {Promise} */ -function updateTsconfig({jsonFileName, test = false, extraPaths = []}) { - const tsconfig = fs.readJsonSync(jsonFileName); - const prev = JSON.stringify(tsconfig.compilerOptions.paths); +async function updateTsconfig({ + extraPaths, + jsonFileName, + prettierConfig, + test, +}) { + const prevTsconfigContents = fs.readFileSync(jsonFileName, 'utf8'); + const tsconfig = JSON.parse(prevTsconfigContents); const publicPaths = []; const privatePaths = []; const testPaths = []; @@ -67,26 +74,37 @@ function updateTsconfig({jsonFileName, test = false, extraPaths = []}) { ...privatePaths, ...testPaths, ]); - if (JSON.stringify(paths) !== prev) { - tsconfig.compilerOptions.paths = paths; - fs.writeFileSync( - jsonFileName, - prettier.format(JSON.stringify(tsconfig), {filepath: jsonFileName}), - ); + tsconfig.compilerOptions.paths = paths; + // This is async in future versions of prettier + const nextTsconfigContents = await prettier.format(JSON.stringify(tsconfig), { + ...prettierConfig, + filepath: jsonFileName, + }); + if (prevTsconfigContents !== nextTsconfigContents) { + fs.writeFileSync(jsonFileName, nextTsconfigContents); } } -updateTsconfig({ - extraPaths: [], - jsonFileName: './tsconfig.json', - test: true, -}); -updateTsconfig({ - extraPaths: [], - jsonFileName: './tsconfig.build.json', - test: false, -}); -updateTsconfig({ - extraPaths: [['lexicalOriginal', ['../lexical/src/']]], - jsonFileName: './packages/lexical-devtools/tsconfig.json', - test: false, -}); + +async function updateAllTsconfig() { + const prettierConfig = (await prettier.resolveConfig('./')) || {}; + await updateTsconfig({ + extraPaths: [], + jsonFileName: './tsconfig.json', + prettierConfig, + test: true, + }); + await updateTsconfig({ + extraPaths: [], + jsonFileName: './tsconfig.build.json', + prettierConfig, + test: false, + }); + await updateTsconfig({ + extraPaths: [['lexicalOriginal', ['../lexical/src/']]], + jsonFileName: './packages/lexical-devtools/tsconfig.json', + prettierConfig, + test: false, + }); +} + +updateAllTsconfig();