From 7b97f95f9a67a0f3211551530d1d8f52106f167b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 27 May 2024 09:51:15 +0200 Subject: [PATCH] fixup! chore: use new performant 'type-check' for tools tagged libaries --- tools/workspace-plugin/just.config.ts | 3 - tools/workspace-plugin/package.json | 6 +- tools/workspace-plugin/scripts/type-check.js | 61 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) delete mode 100644 tools/workspace-plugin/just.config.ts create mode 100644 tools/workspace-plugin/scripts/type-check.js diff --git a/tools/workspace-plugin/just.config.ts b/tools/workspace-plugin/just.config.ts deleted file mode 100644 index b10db31a6aca51..00000000000000 --- a/tools/workspace-plugin/just.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { preset } from '@fluentui/scripts-tasks'; - -preset(); diff --git a/tools/workspace-plugin/package.json b/tools/workspace-plugin/package.json index 46d22fe7ebf15d..33b469662cdac5 100644 --- a/tools/workspace-plugin/package.json +++ b/tools/workspace-plugin/package.json @@ -6,13 +6,11 @@ "generators": "./generators.json", "scripts": { "test": "nx run @fluentui/workspace-plugin:test", - "type-check": "just-scripts type-check", + "type-check": "node ./scripts/type-check", "lint": "eslint --ext .ts,.js,.json ." }, "dependencies": { "@nx/devkit": "^17.3.2" }, - "devDependencies": { - "@fluentui/scripts-tasks": "*" - } + "devDependencies": {} } diff --git a/tools/workspace-plugin/scripts/type-check.js b/tools/workspace-plugin/scripts/type-check.js new file mode 100644 index 00000000000000..f214c9fa1a81c6 --- /dev/null +++ b/tools/workspace-plugin/scripts/type-check.js @@ -0,0 +1,61 @@ +// @ts-check + +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; +import { promisify } from 'node:util'; +import { exec } from 'node:child_process'; +import { exit } from 'node:process'; + +const asyncExec = promisify(exec); + +main().catch(err => { + console.error(err); + exit(1); +}); + +/** + * Copied from ${@link 'file://./../../../scripts/tasks/src/type-check.ts'} + */ +async function main() { + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + const rootConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '../tsconfig.json'), 'utf-8')); + + const tsConfigsRefs = getTsConfigs(rootConfig, { spec: false, e2e: false }); + + const asyncQueue = []; + + for (const ref of tsConfigsRefs) { + const program = `tsc -p ${ref} --pretty --noEmit --baseUrl .`; + asyncQueue.push(asyncExec(program)); + } + + return Promise.all(asyncQueue).catch(err => { + console.error(err.stdout); + exit(1); + }); +} + +/** + * @param {{references?: Array<{ path: string }>;}} solutionConfig + * @param {{ spec: boolean, e2e: boolean }} exclude + */ +function getTsConfigs(solutionConfig, exclude) { + const refs = solutionConfig.references ?? []; + /** @type {string[]} */ + const refsPaths = []; + + for (const ref of refs) { + if (exclude.spec && ref.path.includes('spec')) { + continue; + } + if (exclude.e2e && ref.path.includes('cy')) { + continue; + } + + refsPaths.push(ref.path); + } + + return refsPaths; +}