From bc2b9b1259ce6986da9d3a222b80b16003c7e339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sat, 10 Dec 2022 00:51:49 +0100 Subject: [PATCH] chore: more typecheck --- package.json | 3 +- packages/create-vite/build.config.ts | 2 +- packages/create-vite/tsconfig.json | 2 +- packages/vite/package.json | 1 + packages/vite/rollup.config.ts | 6 ++-- .../vite/rollupLicensePlugin.ts | 32 ++++++++----------- packages/vite/tsconfig.json | 1 - pnpm-lock.yaml | 4 +-- 8 files changed, 22 insertions(+), 29 deletions(-) rename scripts/rollupLicensePlugin.mjs => packages/vite/rollupLicensePlugin.ts (85%) diff --git a/package.json b/package.json index 3cecdc538eb076..0c2e85ee7f4730 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "postinstall": "simple-git-hooks", "format": "prettier --write --cache .", "lint": "eslint --cache .", - "typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit && tsc -p packages/create-vite --noEmit", + "typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit && tsc -p packages/create-vite --noEmit && tsc -p packages/vite/scripts --noEmit", "test": "run-s test-unit test-serve test-build", "test-serve": "vitest run -c vitest.config.e2e.ts", "test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts", @@ -81,7 +81,6 @@ "resolve": "^1.22.1", "rimraf": "^3.0.2", "rollup": "^3.7.0", - "rollup-plugin-license": "^2.9.1", "semver": "^7.3.8", "simple-git-hooks": "^2.8.1", "tslib": "^2.4.1", diff --git a/packages/create-vite/build.config.ts b/packages/create-vite/build.config.ts index 096269571e8526..ecf42002db6fa4 100644 --- a/packages/create-vite/build.config.ts +++ b/packages/create-vite/build.config.ts @@ -3,7 +3,7 @@ import url from 'node:url' // eslint-disable-next-line node/no-extraneous-import import type { Plugin } from 'rollup' import { defineBuildConfig } from 'unbuild' -import licensePlugin from '../../scripts/rollupLicensePlugin.mjs' +import licensePlugin from '../vite/rollupLicensePlugin' const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) diff --git a/packages/create-vite/tsconfig.json b/packages/create-vite/tsconfig.json index 00a22183bb0d56..3a66e6179b5f97 100644 --- a/packages/create-vite/tsconfig.json +++ b/packages/create-vite/tsconfig.json @@ -6,7 +6,7 @@ "module": "ES2020", "moduleResolution": "Node", "strict": true, - "allowJs": true, + "skipLibCheck": true, "declaration": false, "sourceMap": false, "noUnusedLocals": true, diff --git a/packages/vite/package.json b/packages/vite/package.json index 112eafc97ae6a9..b718f82da606d5 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -111,6 +111,7 @@ "postcss-load-config": "^4.0.1", "postcss-modules": "^6.0.0", "resolve.exports": "^1.1.0", + "rollup-plugin-license": "^2.9.1", "sirv": "^2.0.2", "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index 80b00b80822ac4..8c59ac28f26799 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -8,7 +8,7 @@ import json from '@rollup/plugin-json' import MagicString from 'magic-string' import type { Plugin, RollupOptions } from 'rollup' import { defineConfig } from 'rollup' -import licensePlugin from '../../scripts/rollupLicensePlugin.mjs' +import licensePlugin from './rollupLicensePlugin' const pkg = JSON.parse( readFileSync(new URL('./package.json', import.meta.url)).toString(), @@ -78,7 +78,7 @@ function createNodePlugins( isProduction: boolean, sourceMap: boolean, declarationDir: string | false, -): Plugin[] { +): (Plugin | false)[] { return [ nodeResolve({ preferBuiltins: true }), typescript({ @@ -284,7 +284,7 @@ const __require = require; if (!chunk.fileName.includes('chunks/dep-')) return const match = code.match(/^(?:import[\s\S]*?;\s*)+/) - const index = match ? match.index + match[0].length : 0 + const index = match ? match.index! + match[0].length : 0 const s = new MagicString(code) // inject after the last `import` s.appendRight(index, cjsPatch) diff --git a/scripts/rollupLicensePlugin.mjs b/packages/vite/rollupLicensePlugin.ts similarity index 85% rename from scripts/rollupLicensePlugin.mjs rename to packages/vite/rollupLicensePlugin.ts index 3d527afb0129f7..4a9fa344f1aef6 100644 --- a/scripts/rollupLicensePlugin.mjs +++ b/packages/vite/rollupLicensePlugin.ts @@ -1,28 +1,26 @@ -// @ts-check - import fs from 'node:fs' import path from 'node:path' import license from 'rollup-plugin-license' import colors from 'picocolors' import fg from 'fast-glob' import resolve from 'resolve' +import type { Plugin } from 'rollup' -/** - * @param {string} licenseFilePath - * @param {string} licenseTitle - * @param {string} packageName - */ -function licensePlugin(licenseFilePath, licenseTitle, packageName) { +export default function licensePlugin( + licenseFilePath: string, + licenseTitle: string, + packageName: string, +): Plugin { return license({ thirdParty(dependencies) { // https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js // MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md const coreLicense = fs.readFileSync( - new URL('../LICENSE', import.meta.url), + new URL('../../LICENSE', import.meta.url), ) - function sortLicenses(licenses) { - let withParenthesis = [] - let noParenthesis = [] + function sortLicenses(licenses: Set) { + let withParenthesis: string[] = [] + let noParenthesis: string[] = [] licenses.forEach((license) => { if (/^\(/.test(license)) { withParenthesis.push(license) @@ -34,12 +32,10 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) { noParenthesis = noParenthesis.sort() return [...noParenthesis, ...withParenthesis] } - const licenses = new Set() + const licenses = new Set() const dependencyLicenseTexts = dependencies .sort(({ name: _nameA }, { name: _nameB }) => { - const nameA = /** @type {string} */ (_nameA) - const nameB = /** @type {string} */ (_nameB) - return nameA > nameB ? 1 : nameB > nameA ? -1 : 0 + return _nameA! > _nameB! ? 1 : _nameB! > _nameA! ? -1 : 0 }) .map( ({ @@ -96,7 +92,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) { .join('\n') + '\n' } - licenses.add(license) + licenses.add(license!) return text }, ) @@ -122,5 +118,3 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) { }, }) } - -export default licensePlugin diff --git a/packages/vite/tsconfig.json b/packages/vite/tsconfig.json index 930b4b2776c594..18848cfac9a999 100644 --- a/packages/vite/tsconfig.json +++ b/packages/vite/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "strict": false, "declaration": false, "resolveJsonModule": true }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76d89d191360a5..a5b48695372d85 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -59,7 +59,6 @@ importers: resolve: ^1.22.1 rimraf: ^3.0.2 rollup: ^3.7.0 - rollup-plugin-license: ^2.9.1 semver: ^7.3.8 simple-git-hooks: ^2.8.1 tslib: ^2.4.1 @@ -116,7 +115,6 @@ importers: resolve: 1.22.1 rimraf: 3.0.2 rollup: 3.7.0 - rollup-plugin-license: 2.9.1_rollup@3.7.0 semver: 7.3.8 simple-git-hooks: 2.8.1 tslib: 2.4.1 @@ -212,6 +210,7 @@ importers: resolve: ^1.22.1 resolve.exports: ^1.1.0 rollup: ^3.7.0 + rollup-plugin-license: ^2.9.1 sirv: ^2.0.2 source-map-js: ^1.0.2 source-map-support: ^0.5.21 @@ -274,6 +273,7 @@ importers: postcss-load-config: 4.0.1_postcss@8.4.19 postcss-modules: 6.0.0_postcss@8.4.19 resolve.exports: 1.1.0 + rollup-plugin-license: 2.9.1_rollup@3.7.0 sirv: 2.0.2 source-map-js: 1.0.2 source-map-support: 0.5.21