From 512bac00c62e37f919bb9c33be73661339f5a1b9 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 11 Aug 2022 10:32:12 +0200 Subject: [PATCH] chore(scripts): enable type-checks on ci and fix all ts-errors (#24264) * chore(scripts): enable type-checks on ci and fix all ts-errors * chore(pr-deploy-site): fix ts-config --- .vscode/launch.json | 2 +- apps/pr-deploy-site/tsconfig.json | 3 ++- package.json | 6 ++--- .../perf-test-northstar/tsconfig.json | 14 +++++++++-- scripts/beachball/config.test.ts | 2 -- scripts/beachball/release-v8.config.js | 4 +++- scripts/beachball/release-vNext.config.js | 4 +++- .../gulp/plugins/util/parseTypeAnnotation.ts | 1 + scripts/gulp/tasks/browserAdapters.ts | 2 +- scripts/just-scripts.js | 2 -- scripts/package.json | 20 ++++------------ scripts/publish-beta.js | 23 ------------------- scripts/tasks/argv.spec.ts | 2 -- scripts/tsconfig.json | 14 +++++------ scripts/typescript/normalize-import.js | 4 +--- scripts/typescript/normalize-import.spec.js | 2 -- scripts/typescript/tsconfig.common.json | 22 ------------------ scripts/webpack/webpack.config.stats.ts | 10 ++------ yarn.lock | 13 +++++------ 19 files changed, 45 insertions(+), 105 deletions(-) delete mode 100755 scripts/just-scripts.js delete mode 100644 scripts/publish-beta.js delete mode 100644 scripts/typescript/tsconfig.common.json diff --git a/.vscode/launch.json b/.vscode/launch.json index e64deaaba4a4e..ad44b4feb3276 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -57,7 +57,7 @@ "name": "Build @fluentui/react", "type": "node", "request": "launch", - "program": "${workspaceRoot}/scripts/just-scripts.js", + "program": "${workspaceRoot}/node-modules/just-scripts/bin/just-scripts.js", "cwd": "${workspaceRoot}/packages/react", "stopOnEntry": false, "args": ["ts"], diff --git a/apps/pr-deploy-site/tsconfig.json b/apps/pr-deploy-site/tsconfig.json index 05b3c792324e3..164cfd41d215f 100644 --- a/apps/pr-deploy-site/tsconfig.json +++ b/apps/pr-deploy-site/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../scripts/tsconfig.json", "compilerOptions": { "noEmit": true, - "allowJs": true + "allowJs": true, + "lib": ["ES2020", "DOM"] }, "include": ["pr-deploy-site.js", "just.config.ts"] } diff --git a/package.json b/package.json index 601fc8245d559..5e99579d1ebc8 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "buildto": "lage build --verbose --to", "buildto:lerna": "node ./scripts/monorepo/buildTo.js", "bundle": "lage bundle --verbose", - "bundlesize": "cd scripts && yarn bundlesize", "bundlesizecollect": "node ./scripts/bundle-size-collect", "change": "beachball change --no-commit", "check:change": "beachball check", @@ -55,9 +54,7 @@ "runto:lerna": "node ./scripts/monorepo/runTo.js", "scrub": "node ./scripts/scrub.js", "start": "node scripts/start.js", - "start:legacy": "yarn workspace @fluentui/public-docsite-resources start", "start:northstar": "yarn workspace @fluentui/docs start", - "start-exp": "yarn workspace @fluentui/react-experiments start", "stats:build": "gulp stats", "stats:save": "gulp stats:save", "test": "lage test --verbose", @@ -119,6 +116,7 @@ "@testing-library/react": "12.1.2", "@testing-library/react-hooks": "7.0.2", "@testing-library/user-event": "13.5.0", + "@tsconfig/node14": "1.0.3", "@types/babel__helper-plugin-utils": "7.10.0", "@types/copy-webpack-plugin": "6.4.0", "@types/dedent": "0.7.0", @@ -161,7 +159,7 @@ "beachball": "2.18.0", "chalk": "4.1.0", "ci-info": "3.2.0", - "clean-webpack-plugin": "3.0.0", + "clean-webpack-plugin": "4.0.0", "cli-table3": "0.6.1", "copy-webpack-plugin": "8.1.0", "cross-env": "^5.1.4", diff --git a/packages/fluentui/perf-test-northstar/tsconfig.json b/packages/fluentui/perf-test-northstar/tsconfig.json index f99cd4602f451..c18f11c5eafcb 100644 --- a/packages/fluentui/perf-test-northstar/tsconfig.json +++ b/packages/fluentui/perf-test-northstar/tsconfig.json @@ -1,9 +1,19 @@ { - "extends": "@fluentui/scripts/typescript/tsconfig.common", "compilerOptions": { + "moduleResolution": "node", + "module": "esnext", + "target": "es5", + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "skipLibCheck": true, + "lib": ["es2015", "dom"], + "strict": true, + "jsx": "react", "rootDir": "src", "outDir": "lib", - "types": ["node", "jest", "expect-puppeteer", "jest-environment-puppeteer", "webpack-env"] + "sourceMap": true, + "types": ["node", "jest", "expect-puppeteer", "jest-environment-puppeteer", "webpack-env"], + "noUnusedLocals": true }, "include": ["src"], "references": [] diff --git a/scripts/beachball/config.test.ts b/scripts/beachball/config.test.ts index e8b1f23cbb8d6..fb023124eab36 100644 --- a/scripts/beachball/config.test.ts +++ b/scripts/beachball/config.test.ts @@ -1,5 +1,3 @@ -/// - import { config as sharedConfig } from './shared.config'; import v8Config from './release-v8.config'; import vNextConfig from './release-vNext.config'; diff --git a/scripts/beachball/release-v8.config.js b/scripts/beachball/release-v8.config.js index 1ac774b8b8271..8619e754f2efc 100644 --- a/scripts/beachball/release-v8.config.js +++ b/scripts/beachball/release-v8.config.js @@ -1,6 +1,8 @@ // @ts-check -require('../ts-node-register'); +if (process.env.NODE_ENV !== 'test') { + require('../ts-node-register'); +} const { getConfig } = require('./utils'); const { config: sharedConfig } = require('./shared.config'); diff --git a/scripts/beachball/release-vNext.config.js b/scripts/beachball/release-vNext.config.js index b13bd15fada29..6ffb8167fa2f5 100644 --- a/scripts/beachball/release-vNext.config.js +++ b/scripts/beachball/release-vNext.config.js @@ -1,6 +1,8 @@ // @ts-check -require('../ts-node-register'); +if (process.env.NODE_ENV !== 'test') { + require('../ts-node-register'); +} const { getConfig } = require('./utils'); const { config: sharedConfig } = require('./shared.config'); diff --git a/scripts/gulp/plugins/util/parseTypeAnnotation.ts b/scripts/gulp/plugins/util/parseTypeAnnotation.ts index 4996cd30c8b41..6f245a3fa3f47 100644 --- a/scripts/gulp/plugins/util/parseTypeAnnotation.ts +++ b/scripts/gulp/plugins/util/parseTypeAnnotation.ts @@ -48,6 +48,7 @@ const parseTypeAnnotation = (propName: string, propType: string, tsType: t.TSTyp } if (t.isTSLiteralType(tsType)) { + // @ts-expect-error - FIXME - `value` doesn't exist on literal return [{ name: 'literal', value: tsType.literal.value.toString() }]; } diff --git a/scripts/gulp/tasks/browserAdapters.ts b/scripts/gulp/tasks/browserAdapters.ts index 8d42fc3f551a0..d1376ed1302d2 100644 --- a/scripts/gulp/tasks/browserAdapters.ts +++ b/scripts/gulp/tasks/browserAdapters.ts @@ -68,7 +68,7 @@ async function checkDevtoolsAvailability(host, port, timeout): Promise socket.connect(port, host, () => { socket.end(); - resolve(); + resolve(undefined); }); }); diff --git a/scripts/just-scripts.js b/scripts/just-scripts.js deleted file mode 100755 index 1e6f439adc127..0000000000000 --- a/scripts/just-scripts.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('just-scripts/bin/just-scripts'); diff --git a/scripts/package.json b/scripts/package.json index f453c3709c023..2a7b1330cc60e 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -2,16 +2,10 @@ "name": "@fluentui/scripts", "version": "1.0.0", "private": true, - "main": "./index.js", - "bin": { - "just-scripts": "./just-scripts.js" - }, "scripts": { - "build": "echo no-op", - "bundlesize": "bundlesize --debug", - "clean": "", - "code-style": "node ./just-scripts.js code-style", - "test": "jest" + "code-style": "just-scripts code-style", + "test": "jest", + "type-check": "tsc -p . --noEmit" }, "devDependencies": { "@fluentui/eslint-plugin": "*" @@ -72,11 +66,5 @@ "resolve": "^1.7.1", "riceburn": "^1.3.1", "through2": "^2.0.3" - }, - "bundlesize": [ - { - "path": "../apps/test-bundles/dist/fluentui-react-Button.min.js", - "maxSize": "50.1 kB" - } - ] + } } diff --git a/scripts/publish-beta.js b/scripts/publish-beta.js deleted file mode 100644 index 2ca024d97b1de..0000000000000 --- a/scripts/publish-beta.js +++ /dev/null @@ -1,23 +0,0 @@ -// @ts-check - -const path = require('path'); -const chalk = require('chalk'); -const execSync = require('./exec-sync'); -const getAllPackageInfo = require('./monorepo/getAllPackageInfo'); - -const allPackages = getAllPackageInfo(); -const packages = []; - -Object.keys(allPackages).forEach(name => { - const info = allPackages[name]; - if (info.packageJson.private !== true) { - packages.push(info); - } -}); - -for (const package of packages) { - const packagePath = path.resolve(__dirname, '..', package.packagePath); - - console.log(`Publishing ${chalk.magenta(package.packageName)} in ${packagePath}`); - execSync('npm publish --tag next', undefined, packagePath); -} diff --git a/scripts/tasks/argv.spec.ts b/scripts/tasks/argv.spec.ts index a657985bf6afc..a246ebf7a8d0a 100644 --- a/scripts/tasks/argv.spec.ts +++ b/scripts/tasks/argv.spec.ts @@ -1,5 +1,3 @@ -/// - import { argv } from 'just-scripts'; import { Arguments } from 'yargs'; diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 04a80c9b5f33f..126d81add3579 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -1,17 +1,17 @@ { - "extends": "./typescript/tsconfig.common.json", // This config is used for running build scripts through ts-node + "extends": "@tsconfig/node14/tsconfig.json", "compilerOptions": { - "module": "CommonJS", - "target": "ES2018", // Node 10 per https://kangax.github.io/compat-table/es2016plus/#node10_9 - "lib": ["ES2018", "DOM"], // Node 10, occasional test-related stuff that uses DOM - "esModuleInterop": true, + "noEmit": true, "allowJs": true, "noImplicitAny": false, "strictNullChecks": false, + "outDir": "../../dist", + "sourceMap": true, "typeRoots": ["../typings", "../node_modules/@types"], - "types": ["node", "webpack-env"] + "types": ["node", "jest"], + "noUnusedLocals": true }, "include": ["."], - "exclude": ["./create-package/plop-templates*", "cypress.config.ts"] + "exclude": ["./cypress/**", "./cypress.js", "./cypress.config.ts"] } diff --git a/scripts/typescript/normalize-import.js b/scripts/typescript/normalize-import.js index 40f05324ad1c2..0cd5a0c1fd69a 100644 --- a/scripts/typescript/normalize-import.js +++ b/scripts/typescript/normalize-import.js @@ -1,7 +1,5 @@ // @ts-check -/// - const fs = require('fs'); const path = require('path'); const chalk = require('chalk'); @@ -84,7 +82,7 @@ function getAllFiles(dirPath, arrayOfFiles = []) { return filePath; }); - return allFiles.flat(Infinity); + return /** @type {string[]} */ (allFiles.flat(Infinity)); } /** diff --git a/scripts/typescript/normalize-import.spec.js b/scripts/typescript/normalize-import.spec.js index fbe32b799a070..bc44796963d5a 100644 --- a/scripts/typescript/normalize-import.spec.js +++ b/scripts/typescript/normalize-import.spec.js @@ -1,7 +1,5 @@ // @ts-check -/// - const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); diff --git a/scripts/typescript/tsconfig.common.json b/scripts/typescript/tsconfig.common.json deleted file mode 100644 index f9b52eb357ad0..0000000000000 --- a/scripts/typescript/tsconfig.common.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "esnext", - "moduleResolution": "node", - "lib": ["es2015", "dom"], - "jsx": "react", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "outDir": "lib", - "strict": true, - "noUnusedLocals": true, - "noImplicitAny": true, - "noImplicitThis": true, - "forceConsistentCasingInFileNames": true, - "esModuleInterop": true, - "skipDefaultLibCheck": true, - "skipLibCheck": true, - "types": ["node", "jest"] - } -} diff --git a/scripts/webpack/webpack.config.stats.ts b/scripts/webpack/webpack.config.stats.ts index 943b38f4f519f..cca7e39792c11 100644 --- a/scripts/webpack/webpack.config.stats.ts +++ b/scripts/webpack/webpack.config.stats.ts @@ -1,4 +1,4 @@ -import CleanWebpackPlugin from 'clean-webpack-plugin'; +import { CleanWebpackPlugin } from 'clean-webpack-plugin'; import fs from 'fs'; import path from 'path'; import webpack from 'webpack'; @@ -64,10 +64,7 @@ const makeConfig = (srcPath: string, name: string): webpack.Configuration => ({ optimization: { minimizer: [ new TerserWebpackPlugin({ - cache: true, parallel: true, - sourceMap: false, - terserOptions: { mangle: false, output: { @@ -81,10 +78,7 @@ const makeConfig = (srcPath: string, name: string): webpack.Configuration => ({ }, }), plugins: [ - new CleanWebpackPlugin([paths.base('stats')], { - root: paths.base(), - verbose: false, // do not log - }), + new CleanWebpackPlugin(), new IgnoreNotFoundExportPlugin(), // new BundleAnalyzerPlugin({ // reportFilename: `${name}.html`, diff --git a/yarn.lock b/yarn.lock index c65782b97b962..241a2b147ecd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4897,7 +4897,7 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== -"@tsconfig/node14@^1.0.0": +"@tsconfig/node14@1.0.3", "@tsconfig/node14@^1.0.0": version "1.0.3" resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== @@ -5972,7 +5972,7 @@ "@types/source-list-map" "*" source-map "^0.6.1" -"@types/webpack@*", "@types/webpack@^4", "@types/webpack@^4.4.31", "@types/webpack@^4.41.26", "@types/webpack@^4.41.8": +"@types/webpack@*", "@types/webpack@^4", "@types/webpack@^4.41.26", "@types/webpack@^4.41.8": version "4.41.30" resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.30.tgz#fd3db6d0d41e145a8eeeafcd3c4a7ccde9068ddc" integrity sha512-GUHyY+pfuQ6haAfzu4S14F+R5iGRwN6b2FRNJY7U0NilmFAqbsOfK6j1HwuLBAqwRIT+pVdNDJGJ6e8rpp0KHA== @@ -9054,12 +9054,11 @@ clean-stack@^2.0.0: resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== -clean-webpack-plugin@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-3.0.0.tgz#a99d8ec34c1c628a4541567aa7b457446460c62b" - integrity sha512-MciirUH5r+cYLGCOL5JX/ZLzOZbVr1ot3Fw+KcvbhUb6PM+yycqd9ZhIlcigQ5gl+XhppNmw3bEFuaaMNyLj3A== +clean-webpack-plugin@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-4.0.0.tgz#72947d4403d452f38ed61a9ff0ada8122aacd729" + integrity sha512-WuWE1nyTNAyW5T7oNyys2EN0cfP2fdRxhxnIQWiAp0bMabPdHhoGxM8A6YL2GhqwgrPnnaemVE7nv5XJ2Fhh2w== dependencies: - "@types/webpack" "^4.4.31" del "^4.1.1" cli-boxes@^1.0.0: