Skip to content

Commit

Permalink
chore: more typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 9, 2022
1 parent b3149b4 commit bc2b9b1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/build.config.ts
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/tsconfig.json
Expand Up @@ -6,7 +6,7 @@
"module": "ES2020",
"moduleResolution": "Node",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"declaration": false,
"sourceMap": false,
"noUnusedLocals": true,
Expand Down
1 change: 1 addition & 0 deletions packages/vite/package.json
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/rollup.config.ts
Expand Up @@ -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(),
Expand Down Expand Up @@ -78,7 +78,7 @@ function createNodePlugins(
isProduction: boolean,
sourceMap: boolean,
declarationDir: string | false,
): Plugin[] {
): (Plugin | false)[] {
return [
nodeResolve({ preferBuiltins: true }),
typescript({
Expand Down Expand Up @@ -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)
Expand Down
@@ -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<string>) {
let withParenthesis: string[] = []
let noParenthesis: string[] = []
licenses.forEach((license) => {
if (/^\(/.test(license)) {
withParenthesis.push(license)
Expand All @@ -34,12 +32,10 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
noParenthesis = noParenthesis.sort()
return [...noParenthesis, ...withParenthesis]
}
const licenses = new Set()
const licenses = new Set<string>()
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(
({
Expand Down Expand Up @@ -96,7 +92,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
.join('\n') +
'\n'
}
licenses.add(license)
licenses.add(license!)
return text
},
)
Expand All @@ -122,5 +118,3 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) {
},
})
}

export default licensePlugin
1 change: 0 additions & 1 deletion packages/vite/tsconfig.json
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"strict": false,
"declaration": false,
"resolveJsonModule": true
},
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc2b9b1

Please sign in to comment.