diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe17b0f3befe36..191eb468a38814 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -100,7 +100,7 @@ To work around this, playground packages that uses the `file:` protocol should a ```jsonc "scripts": { //... - "postinstall": "node ../../../scripts/patchFileDeps.cjs" + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" } ``` diff --git a/package.json b/package.json index dcb61a6713fb40..c4d6a04d96a1c1 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@types/fs-extra": "^9.0.13", "@types/jest": "^27.0.3", "@types/node": "^16.11.14", + "@types/prompts": "^2.0.14", "@types/semver": "^7.3.9", "@typescript-eslint/eslint-plugin": "^5.7.0", "@typescript-eslint/parser": "^5.7.0", @@ -61,7 +62,7 @@ }, "gitHooks": { "pre-commit": "lint-staged --concurrent false", - "commit-msg": "node scripts/verifyCommit.cjs" + "commit-msg": "ts-node scripts/verifyCommit.ts" }, "lint-staged": { "*": [ diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index ab62f2b95229f7..bb340a75b5773a 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -14,7 +14,7 @@ "main": "index.js", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite", - "release": "node updateVersions && node ../../scripts/release.cjs --skipBuild" + "release": "ts-node updateVersions && ts-node ../../scripts/release.ts --skipBuild" }, "engines": { "node": ">=12.0.0" diff --git a/packages/create-vite/updateVersions.js b/packages/create-vite/updateVersions.ts similarity index 50% rename from packages/create-vite/updateVersions.js rename to packages/create-vite/updateVersions.ts index 6ec2985854c64a..7125fce9119f07 100644 --- a/packages/create-vite/updateVersions.js +++ b/packages/create-vite/updateVersions.ts @@ -1,22 +1,23 @@ -const fs = require('fs') -const path = require('path') +import { readdirSync, writeFileSync } from 'fs' +import { join } from 'path' + const latestVersion = require('../vite/package.json').version const isLatestPreRelease = /beta|alpha|rc/.test(latestVersion) ;(async () => { - const templates = fs - .readdirSync(__dirname) - .filter((d) => d.startsWith('template-')) - for (const t of templates) { - const pkgPath = path.join(__dirname, t, `package.json`) + const templates = readdirSync(__dirname).filter((dir) => + dir.startsWith('template-') + ) + for (const template of templates) { + const pkgPath = join(__dirname, template, `package.json`) const pkg = require(pkgPath) if (!isLatestPreRelease) { pkg.devDependencies.vite = `^` + latestVersion } - if (t.startsWith('template-vue')) { + if (template.startsWith('template-vue')) { pkg.devDependencies['@vitejs/plugin-vue'] = `^` + require('../plugin-vue/package.json').version } - fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') } })() diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index 6d17bbe99eac6d..853a3efaf2bd93 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -7,7 +7,7 @@ "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite", "preview": "vite preview", - "postinstall": "node ../../../scripts/patchFileDeps.cjs" + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" }, "dependencies": { "aliased-module": "file:./dir/module", diff --git a/packages/playground/optimize-deps/package.json b/packages/playground/optimize-deps/package.json index ca3bbd8e5b7c1f..0606343e0dce3c 100644 --- a/packages/playground/optimize-deps/package.json +++ b/packages/playground/optimize-deps/package.json @@ -7,7 +7,7 @@ "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite", "preview": "vite preview", - "postinstall": "node ../../../scripts/patchFileDeps.cjs" + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" }, "dependencies": { "axios": "^0.24.0", diff --git a/packages/playground/optimize-missing-deps/package.json b/packages/playground/optimize-missing-deps/package.json index 74e17dd60704a6..431cf3b33c3847 100644 --- a/packages/playground/optimize-missing-deps/package.json +++ b/packages/playground/optimize-missing-deps/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "scripts": { "dev": "node server", - "postinstall": "node ../../../scripts/patchFileDeps.cjs" + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" }, "dependencies": { "missing-dep": "file:./missing-dep", diff --git a/packages/playground/ssr-deps/package.json b/packages/playground/ssr-deps/package.json index a4dfb83e6a0783..fac7c150b49924 100644 --- a/packages/playground/ssr-deps/package.json +++ b/packages/playground/ssr-deps/package.json @@ -6,7 +6,7 @@ "dev": "node server", "serve": "cross-env NODE_ENV=production node server", "debug": "node --inspect-brk server", - "postinstall": "node ../../../scripts/patchFileDeps.cjs" + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" }, "dependencies": { "bcrypt": "^5.0.1", diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index cd2ecc6a5858a9..e0556f1ddaf59c 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -11,7 +11,7 @@ "types": "index.d.ts", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-legacy", - "release": "node ../../scripts/release.cjs --skipBuild" + "release": "ts-node ../../scripts/release.ts --skipBuild" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index a58d08f6b6834a..f95a158155c400 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -18,7 +18,7 @@ "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:resolve --external:react-refresh/* --outfile=dist/index.js", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-react", - "release": "node ../../scripts/release.cjs" + "release": "ts-node ../../scripts/release.ts" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 40ef71dac734ea..b55f44b7e1228e 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -11,7 +11,7 @@ "types": "index.d.ts", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx", - "release": "node ../../scripts/release.cjs --skipBuild" + "release": "ts-node ../../scripts/release.ts --skipBuild" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index a3721f40f960b5..8e76dc4c1ec2fd 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -16,7 +16,7 @@ "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue", - "release": "node ../../scripts/release.cjs" + "release": "ts-node ../../scripts/release.ts" }, "engines": { "node": ">=12.0.0" diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index a77f5adb62043b..8541f3d92fc23b 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -1288,26 +1288,27 @@ Repository: https://github.com/mathiasbynens/cssesc.git ## debug License: MIT -By: TJ Holowaychuk, Nathan Rajlich, Andrew Rhyne, Josh Junon -Repository: git://github.com/visionmedia/debug.git +By: Josh Junon, TJ Holowaychuk, Nathan Rajlich, Andrew Rhyne +Repository: git://github.com/debug-js/debug.git > (The MIT License) > -> Copyright (c) 2014 TJ Holowaychuk +> Copyright (c) 2014-2017 TJ Holowaychuk +> Copyright (c) 2018-2021 Josh Junon > -> Permission is hereby granted, free of charge, to any person obtaining a copy of this software -> and associated documentation files (the 'Software'), to deal in the Software without restriction, -> including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software +> and associated documentation files (the 'Software'), to deal in the Software without restriction, +> including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, > and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, > subject to the following conditions: > -> The above copyright notice and this permission notice shall be included in all copies or substantial +> The above copyright notice and this permission notice shall be included in all copies or substantial > portions of the Software. > -> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -> LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -> WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +> LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +> WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE > SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------- @@ -2887,6 +2888,35 @@ Repository: git://github.com/isaacs/minimatch.git --------------------------------------- +## mrmime +License: MIT +By: Luke Edwards +Repository: lukeed/mrmime + +> The MIT License (MIT) +> +> Copyright (c) Luke Edwards (https://lukeed.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. + +--------------------------------------- + ## ms License: MIT Repository: zeit/ms diff --git a/packages/vite/package.json b/packages/vite/package.json index 46b3036da6e022..9351957e6c7f87 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -35,12 +35,12 @@ "build-types": "run-s build-temp-types patch-types roll-types", "build-temp-types": "tsc --emitDeclarationOnly --outDir temp/node -p src/node", "ci-build": "rimraf dist && run-s build-bundle build-types", - "patch-types": "node scripts/patchTypes.cjs", + "patch-types": "ts-node scripts/patchTypes.ts", "roll-types": "api-extractor run && rimraf temp", "lint": "eslint --ext .ts src/**", "format": "prettier --write --parser typescript \"src/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .", - "release": "node ../../scripts/release.cjs" + "release": "ts-node ../../scripts/release.ts" }, "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!", "dependencies": { diff --git a/packages/vite/scripts/patchTypes.cjs b/packages/vite/scripts/patchTypes.cjs deleted file mode 100644 index 8be75c47f8d2cb..00000000000000 --- a/packages/vite/scripts/patchTypes.cjs +++ /dev/null @@ -1,70 +0,0 @@ -// @ts-check -const fs = require('fs') -const path = require('path') -const chalk = require('chalk') -const { parse } = require('@babel/parser') -const MagicString = require('magic-string').default -const tempDir = path.resolve(__dirname, '../temp/node') -const typesDir = path.resolve(__dirname, '../types') - -// walk through the temp dts dir, find all import/export of types/* -// and rewrite them into relative imports - so that api-extractor actually -// includes them in the rolled-up final d.ts file. -walkDir(tempDir) -console.log(chalk.green.bold(`patched types/* imports`)) - -function slash(p) { - return p.replace(/\\/g, '/') -} - -/** - * @param {string} dir - */ -function walkDir(dir) { - const files = fs.readdirSync(dir) - for (const file of files) { - const resolved = path.resolve(dir, file) - const isDir = fs.statSync(resolved).isDirectory() - if (isDir) { - walkDir(resolved) - } else { - rewriteFile(resolved) - } - } -} - -/** - * @param {string} file - */ -function rewriteFile(file) { - const content = fs.readFileSync(file, 'utf-8') - const str = new MagicString(content) - let ast - try { - ast = parse(content, { - sourceType: 'module', - plugins: ['typescript', 'classProperties'] - }) - } catch (e) { - console.log(chalk.red(`failed to parse ${file}`)) - throw e - } - for (const statement of ast.program.body) { - if ( - (statement.type === 'ImportDeclaration' || - statement.type === 'ExportNamedDeclaration' || - statement.type === 'ExportAllDeclaration') && - statement.source && - statement.source.value.startsWith('types/') - ) { - const source = statement.source - const absoluteTypePath = path.resolve(typesDir, source.value.slice(6)) - const relativeTypePath = slash( - path.relative(path.dirname(file), absoluteTypePath) - ) - // @ts-ignore - str.overwrite(source.start, source.end, JSON.stringify(relativeTypePath)) - } - } - fs.writeFileSync(file, str.toString()) -} diff --git a/packages/vite/scripts/patchTypes.ts b/packages/vite/scripts/patchTypes.ts new file mode 100644 index 00000000000000..b54cf0389f88b2 --- /dev/null +++ b/packages/vite/scripts/patchTypes.ts @@ -0,0 +1,66 @@ +import type { ParseResult } from '@babel/parser' +import { parse } from '@babel/parser' +import type { File } from '@babel/types' +import chalk from 'chalk' +import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs' +import MagicString from 'magic-string' +import { dirname, relative, resolve } from 'path' + +const tempDir = resolve(__dirname, '../temp/node') +const typesDir = resolve(__dirname, '../types') + +// walk through the temp dts dir, find all import/export of types/* +// and rewrite them into relative imports - so that api-extractor actually +// includes them in the rolled-up final d.ts file. +walkDir(tempDir) +console.log(chalk.green.bold(`patched types/* imports`)) + +function slash(p: string): string { + return p.replace(/\\/g, '/') +} + +function walkDir(dir: string): void { + const files = readdirSync(dir) + for (const file of files) { + const resolved = resolve(dir, file) + const isDir = statSync(resolved).isDirectory() + if (isDir) { + walkDir(resolved) + } else { + rewriteFile(resolved) + } + } +} + +function rewriteFile(file: string): void { + const content = readFileSync(file, 'utf-8') + const str = new MagicString(content) + let ast: ParseResult + try { + ast = parse(content, { + sourceType: 'module', + plugins: ['typescript', 'classProperties'] + }) + } catch (e) { + console.log(chalk.red(`failed to parse ${file}`)) + throw e + } + for (const statement of ast.program.body) { + if ( + (statement.type === 'ImportDeclaration' || + statement.type === 'ExportNamedDeclaration' || + statement.type === 'ExportAllDeclaration') && + statement.source?.value.startsWith('types/') + ) { + const source = statement.source + const absoluteTypePath = resolve(typesDir, source.value.slice(6)) + const relativeTypePath = slash(relative(dirname(file), absoluteTypePath)) + str.overwrite( + source.start!, + source.end!, + JSON.stringify(relativeTypePath) + ) + } + } + writeFileSync(file, str.toString()) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a476f1e90e12d..0905c721570719 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,7 @@ importers: '@types/fs-extra': ^9.0.13 '@types/jest': ^27.0.3 '@types/node': ^16.11.14 + '@types/prompts': ^2.0.14 '@types/semver': ^7.3.9 '@typescript-eslint/eslint-plugin': ^5.7.0 '@typescript-eslint/parser': ^5.7.0 @@ -47,6 +48,7 @@ importers: '@types/fs-extra': 9.0.13 '@types/jest': 27.0.3 '@types/node': 16.11.14 + '@types/prompts': 2.0.14 '@types/semver': 7.3.9 '@typescript-eslint/eslint-plugin': 5.7.0_d7a0d6b59468b4d2ea38f782f4f112e3 '@typescript-eslint/parser': 5.7.0_eslint@8.4.1+typescript@4.4.4 @@ -2291,6 +2293,12 @@ packages: resolution: {integrity: sha512-Fo79ojj3vdEZOHg3wR9ksAMRz4P3S5fDB5e/YWZiFnyFQI1WY2Vftu9XoXVVtJfxB7Bpce/QTqWSSntkz2Znrw==} dev: true + /@types/prompts/2.0.14: + resolution: {integrity: sha512-HZBd99fKxRWpYCErtm2/yxUZv6/PBI9J7N4TNFffl5JbrYMHBwF25DjQGTW3b3jmXq+9P6/8fCIb2ee57BFfYA==} + dependencies: + '@types/node': 16.11.14 + dev: true + /@types/resolve/1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: diff --git a/scripts/patchFileDeps.cjs b/scripts/patchFileDeps.ts similarity index 61% rename from scripts/patchFileDeps.cjs rename to scripts/patchFileDeps.ts index dbb42caadd38f4..0e90bbe8adece2 100644 --- a/scripts/patchFileDeps.cjs +++ b/scripts/patchFileDeps.ts @@ -3,19 +3,20 @@ // This script is called from postinstall hooks in playground packages that // uses the file: protocol, and copies the file: deps into node_modules. -const fs = require('fs-extra') -const path = require('path') +import { copySync, removeSync } from 'fs-extra' +import { join, resolve } from 'path' + const root = process.cwd() -const pkg = require(path.join(root, 'package.json')) +const pkg = require(join(root, 'package.json')) -let hasPatched -for (const [key, val] of Object.entries(pkg.dependencies)) { +let hasPatched: boolean = false +for (const [key, val] of Object.entries(pkg.dependencies)) { if (val.startsWith('file:')) { hasPatched = true - const src = path.resolve(root, val.slice('file:'.length)) - const dest = path.resolve(root, 'node_modules', key) - fs.removeSync(dest) - fs.copySync(src, dest, { + const src = resolve(root, val.slice('file:'.length)) + const dest = resolve(root, 'node_modules', key) + removeSync(dest) + copySync(src, dest, { dereference: true }) console.log(`patched ${val}`) @@ -26,5 +27,5 @@ if (hasPatched) { // remove node_modules/.ignored as pnpm will think our patched files are // installed by another package manager and move them into this directory. // On further installs it will error out if this directory is not empty. - fs.removeSync(path.resolve(root, 'node_modules', '.ignored')) + removeSync(resolve(root, 'node_modules', '.ignored')) } diff --git a/scripts/release.cjs b/scripts/release.ts similarity index 67% rename from scripts/release.cjs rename to scripts/release.ts index d7f258bc70d140..37cd2d9cb26ecc 100644 --- a/scripts/release.cjs +++ b/scripts/release.ts @@ -1,37 +1,26 @@ -// @ts-check - /** * modified from https://github.com/vuejs/vue-next/blob/master/scripts/release.js */ -const execa = require('execa') -const path = require('path') -const fs = require('fs') +import chalk from 'chalk' +import type { ExecaChildProcess, Options as ExecaOptions } from 'execa' +import execa from 'execa' +import { readFileSync, writeFileSync } from 'fs' +import path from 'path' +import prompts from 'prompts' +import type { ReleaseType } from 'semver' +import semver from 'semver' + const args = require('minimist')(process.argv.slice(2)) -const semver = require('semver') -const chalk = require('chalk') -const prompts = require('prompts') const pkgDir = process.cwd() const pkgPath = path.resolve(pkgDir, 'package.json') -/** - * @type {{ name: string, version: string }} - */ -const pkg = require(pkgPath) +const pkg: { name: string; version: string } = require(pkgPath) const pkgName = pkg.name.replace(/^@vitejs\//, '') const currentVersion = pkg.version -/** - * @type {boolean} - */ -const isDryRun = args.dry -/** - * @type {boolean} - */ -const skipBuild = args.skipBuild +const isDryRun: boolean = args.dry +const skipBuild: boolean = args.skipBuild -/** - * @type {import('semver').ReleaseType[]} - */ -const versionIncrements = [ +const versionIncrements: ReleaseType[] = [ 'patch', 'minor', 'major', @@ -41,43 +30,33 @@ const versionIncrements = [ 'prerelease' ] -/** - * @param {import('semver').ReleaseType} i - */ -const inc = (i) => semver.inc(currentVersion, i, 'beta') +const inc: (i: ReleaseType) => string = (i) => + semver.inc(currentVersion, i, 'beta') -/** - * @param {string} bin - * @param {string[]} args - * @param {object} opts - */ -const run = (bin, args, opts = {}) => +type RunFn = ( + bin: string, + args: string[], + opts?: ExecaOptions +) => ExecaChildProcess + +const run: RunFn = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts }) -/** - * @param {string} bin - * @param {string[]} args - * @param {object} opts - */ -const dryRun = (bin, args, opts = {}) => +type DryRunFn = (bin: string, args: string[], opts?: any) => void + +const dryRun: DryRunFn = (bin, args, opts: any) => console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts) const runIfNotDry = isDryRun ? dryRun : run -/** - * @param {string} msg - */ -const step = (msg) => console.log(chalk.cyan(msg)) +const step: (msg: string) => void = (msg) => console.log(chalk.cyan(msg)) -async function main() { - let targetVersion = args._[0] +async function main(): Promise { + let targetVersion: string | undefined = args._[0] if (!targetVersion) { // no explicit version, offer suggestions - /** - * @type {{ release: string }} - */ - const { release } = await prompts({ + const { release }: { release: string } = await prompts({ type: 'select', name: 'release', message: 'Select release type', @@ -88,10 +67,7 @@ async function main() { }) if (release === 'custom') { - /** - * @type {{ version: string }} - */ - const res = await prompts({ + const res: { version: string } = await prompts({ type: 'text', name: 'version', message: 'Input custom version', @@ -111,10 +87,7 @@ async function main() { pkgName === 'vite' ? `v${targetVersion}` : `${pkgName}@${targetVersion}` if (targetVersion.includes('beta') && !args.tag) { - /** - * @type {{ tagBeta: boolean }} - */ - const { tagBeta } = await prompts({ + const { tagBeta }: { tagBeta: boolean } = await prompts({ type: 'confirm', name: 'tagBeta', message: `Publish under dist-tag "beta"?` @@ -123,10 +96,7 @@ async function main() { if (tagBeta) args.tag = 'beta' } - /** - * @type {{ yes: boolean }} - */ - const { yes } = await prompts({ + const { yes }: { yes: boolean } = await prompts({ type: 'confirm', name: 'yes', message: `Releasing ${tag}. Confirm?` @@ -173,20 +143,16 @@ async function main() { console.log() } -/** - * @param {string} version - */ -function updateVersion(version) { - const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')) +function updateVersion(version: string): void { + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) pkg.version = version - fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') } -/** - * @param {string} version - * @param {Function} runIfNotDry - */ -async function publishPackage(version, runIfNotDry) { +async function publishPackage( + version: string, + runIfNotDry: RunFn | DryRunFn +): Promise { const publicArgs = [ 'publish', '--no-git-tag-version', diff --git a/scripts/verifyCommit.cjs b/scripts/verifyCommit.ts similarity index 83% rename from scripts/verifyCommit.cjs rename to scripts/verifyCommit.ts index fbbff40796a8d7..437e723c85d17b 100644 --- a/scripts/verifyCommit.cjs +++ b/scripts/verifyCommit.ts @@ -1,8 +1,10 @@ // Invoked on the commit-msg git hook by yorkie. -const chalk = require('chalk') -const msgPath = process.env.GIT_PARAMS -const msg = require('fs').readFileSync(msgPath, 'utf-8').trim() +import chalk from 'chalk' +import { readFileSync } from 'fs' + +const msgPath = process.env.GIT_PARAMS! +const msg = readFileSync(msgPath, 'utf-8').trim() const releaseRE = /^v\d/ const commitRE =