diff --git a/package.json b/package.json index 0ee01170c7..2c78c9a357 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "dev": "pnpm run watch", "prettier": "prettier --plugin-search-dir . \"{packages,examples}/**/src/**/*.{md,js,jsx,cjs,ts,tsx,json,vue,svelte}\"", "prettier:write": "pnpm run prettier --write", - "cipublish": "ts-node scripts/publish.ts", - "validatePackages": "ts-node scripts/validate-packages.ts" + "cipublish": "node scripts/publish.mjs", + "validatePackages": "node scripts/validate-packages.mjs" }, "nx": { "includedScripts": [ @@ -87,7 +87,7 @@ "semver": "^7.5.1", "solid-js": "^1.6.13", "stream-to-array": "^2.3.0", - "ts-node": "^10.9.1", + "type-fest": "^3.11.0", "typescript": "^5.0.4", "vitest": "^0.27.1", "vue": "^3.2.47" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5d1832d77..47ab0f355f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -177,9 +177,9 @@ importers: stream-to-array: specifier: ^2.3.0 version: 2.3.0 - ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@18.13.0)(typescript@5.0.4) + type-fest: + specifier: ^3.11.0 + version: 3.11.0 typescript: specifier: ^5.0.4 version: 5.0.4 @@ -1244,7 +1244,7 @@ importers: version: 3.4.3(@babel/core@7.21.8)(postcss@8.4.23)(svelte@3.55.0) tailwindcss: specifier: ^3.3.2 - version: 3.3.2(ts-node@10.9.1) + version: 3.3.2 tslib: specifier: ^2.5.2 version: 2.5.2 @@ -1343,7 +1343,7 @@ importers: version: 8.34.0 tsup: specifier: ^6.7.0 - version: 6.7.0(ts-node@10.9.1)(typescript@5.0.4) + version: 6.7.0(typescript@5.0.4) packages/query-async-storage-persister: dependencies: @@ -1510,7 +1510,7 @@ importers: version: 3.2.2(svelte@3.55.0) eslint-plugin-svelte: specifier: ^2.29.0 - version: 2.29.0(eslint@8.34.0)(svelte@3.55.0)(ts-node@10.9.1) + version: 2.29.0(eslint@8.34.0)(svelte@3.55.0) jsdom: specifier: ^22.0.0 version: 22.0.0 @@ -1553,7 +1553,7 @@ importers: version: 3.2.2(svelte@3.55.0) eslint-plugin-svelte: specifier: ^2.29.0 - version: 2.29.0(eslint@8.34.0)(svelte@3.55.0)(ts-node@10.9.1) + version: 2.29.0(eslint@8.34.0)(svelte@3.55.0) jsdom: specifier: ^22.0.0 version: 22.0.0 @@ -3106,13 +3106,6 @@ packages: chalk: 4.1.2 dev: true - /@cspotcode/source-map-support@0.8.1: - resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} - engines: {node: '>=12'} - dependencies: - '@jridgewell/trace-mapping': 0.3.9 - dev: true - /@egjs/hammerjs@2.0.17: resolution: {integrity: sha512-XQsZgjm2EcVUiZQf11UBJQfmZeEmOW8DpI1gsFeln6w0ae0ii4dMQEQ0kjl6DspdWX1aGY1/loyXnP0JS06e/A==} engines: {node: '>=0.8.0'} @@ -3986,13 +3979,6 @@ packages: '@jridgewell/resolve-uri': 3.1.0 '@jridgewell/sourcemap-codec': 1.4.14 - /@jridgewell/trace-mapping@0.3.9: - resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} - dependencies: - '@jridgewell/resolve-uri': 3.1.0 - '@jridgewell/sourcemap-codec': 1.4.14 - dev: true - /@mswjs/cookies@0.2.1: resolution: {integrity: sha512-0tDfcPw5/s7QsNQqS3knAvAD5w5PF1nNPagRhKO/yECY+sMbJxoC2sLWnH7Lzmh52mTSVLKDhd1r92Q3kfljnQ==} engines: {node: '>=14'} @@ -5456,22 +5442,6 @@ packages: engines: {node: '>= 10'} dev: true - /@tsconfig/node10@1.0.9: - resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} - dev: true - - /@tsconfig/node12@1.0.11: - resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} - dev: true - - /@tsconfig/node14@1.0.3: - resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} - dev: true - - /@tsconfig/node16@1.0.3: - resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} - dev: true - /@tsconfig/svelte@4.0.1: resolution: {integrity: sha512-B+XlGpmuAQzJqDoBATNCvEPqQg0HkO7S8pM14QDI5NsmtymzRexQ1N+nX2H6RTtFbuFgaZD4I8AAi8voGg0GLg==} dev: true @@ -6211,10 +6181,6 @@ packages: resolution: {integrity: sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==} dev: false - /arg@4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: true - /arg@5.0.2: resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==} dev: true @@ -7426,10 +7392,6 @@ packages: object-assign: 4.1.1 dev: false - /create-require@1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: true - /cross-fetch@3.1.5: resolution: {integrity: sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==} dependencies: @@ -7789,11 +7751,6 @@ packages: engines: {node: '>= 8.3'} dev: true - /diff@4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - dev: true - /dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -8727,7 +8684,7 @@ packages: string.prototype.matchall: 4.0.8 dev: true - /eslint-plugin-svelte@2.29.0(eslint@8.34.0)(svelte@3.55.0)(ts-node@10.9.1): + /eslint-plugin-svelte@2.29.0(eslint@8.34.0)(svelte@3.55.0): resolution: {integrity: sha512-ukEC5z9ZXwDtwD8L12ei9doF9P/mQVeiLZiUxExWN9ZNTLNwZgfmEKx+s0tNio0YnYHzKz6qELxFei4SqVbLkQ==} engines: {node: ^14.17.0 || >=16.0.0} peerDependencies: @@ -8744,7 +8701,7 @@ packages: esutils: 2.0.3 known-css-properties: 0.27.0 postcss: 8.4.23 - postcss-load-config: 3.1.4(postcss@8.4.23)(ts-node@10.9.1) + postcss-load-config: 3.1.4(postcss@8.4.23) postcss-safe-parser: 6.0.0(postcss@8.4.23) svelte: 3.55.0 svelte-eslint-parser: 0.29.0(svelte@3.55.0) @@ -11380,10 +11337,6 @@ packages: semver: 6.3.0 dev: true - /make-error@1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: true - /makeerror@1.0.12: resolution: {integrity: sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==} dependencies: @@ -13192,7 +13145,7 @@ packages: postcss: 8.4.23 dev: true - /postcss-load-config@3.1.4(postcss@8.4.23)(ts-node@10.9.1): + /postcss-load-config@3.1.4(postcss@8.4.23): resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} engines: {node: '>= 10'} peerDependencies: @@ -13206,11 +13159,10 @@ packages: dependencies: lilconfig: 2.1.0 postcss: 8.4.23 - ts-node: 10.9.1(@types/node@18.13.0)(typescript@5.0.4) yaml: 1.10.2 dev: true - /postcss-load-config@4.0.1(postcss@8.4.23)(ts-node@10.9.1): + /postcss-load-config@4.0.1(postcss@8.4.23): resolution: {integrity: sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==} engines: {node: '>= 14'} peerDependencies: @@ -13224,7 +13176,6 @@ packages: dependencies: lilconfig: 2.1.0 postcss: 8.4.23 - ts-node: 10.9.1(@types/node@18.13.0)(typescript@5.0.4) yaml: 2.3.0 dev: true @@ -15358,7 +15309,7 @@ packages: tslib: 2.5.2 dev: true - /tailwindcss@3.3.2(ts-node@10.9.1): + /tailwindcss@3.3.2: resolution: {integrity: sha512-9jPkMiIBXvPc2KywkraqsUfbfj+dHDb+JPWtSJa9MLFdrPyazI7q6WX2sUrm7R9eVR7qqv3Pas7EvQFzxKnI6w==} engines: {node: '>=14.0.0'} hasBin: true @@ -15380,7 +15331,7 @@ packages: postcss: 8.4.23 postcss-import: 15.1.0(postcss@8.4.23) postcss-js: 4.0.1(postcss@8.4.23) - postcss-load-config: 4.0.1(postcss@8.4.23)(ts-node@10.9.1) + postcss-load-config: 4.0.1(postcss@8.4.23) postcss-nested: 6.0.1(postcss@8.4.23) postcss-selector-parser: 6.0.11 postcss-value-parser: 4.2.0 @@ -15671,37 +15622,6 @@ packages: /ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} - /ts-node@10.9.1(@types/node@18.13.0)(typescript@5.0.4): - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.3 - '@types/node': 18.13.0 - acorn: 8.8.2 - acorn-walk: 8.2.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.0.4 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - dev: true - /tsconfig-paths@3.14.1: resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} dependencies: @@ -15727,7 +15647,7 @@ packages: /tslib@2.5.2: resolution: {integrity: sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==} - /tsup@6.7.0(ts-node@10.9.1)(typescript@5.0.4): + /tsup@6.7.0(typescript@5.0.4): resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==} engines: {node: '>=14.18'} hasBin: true @@ -15751,7 +15671,7 @@ packages: execa: 5.1.1 globby: 11.1.0 joycon: 3.1.1 - postcss-load-config: 3.1.4(postcss@8.4.23)(ts-node@10.9.1) + postcss-load-config: 3.1.4(postcss@8.4.23) resolve-from: 5.0.0 rollup: 3.23.0 source-map: 0.8.0-beta.0 @@ -15833,6 +15753,11 @@ packages: resolution: {integrity: sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==} engines: {node: '>=10'} + /type-fest@3.11.0: + resolution: {integrity: sha512-JaPw5U9ixP0XcpUbQoVSbxSDcK/K4nww20C3kjm9yE6cDRRhptU28AH60VWf9ltXmCrIfIbtt9J+2OUk2Uqiaw==} + engines: {node: '>=14.16'} + dev: true + /type-is@1.6.18: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} @@ -16089,10 +16014,6 @@ packages: hasBin: true dev: false - /v8-compile-cache-lib@3.0.1: - resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - dev: true - /v8-compile-cache@2.3.0: resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==} dev: true @@ -16704,11 +16625,6 @@ packages: y18n: 5.0.8 yargs-parser: 21.1.1 - /yn@3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - dev: true - /yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} diff --git a/scripts/config.ts b/scripts/config.mjs similarity index 84% rename from scripts/config.ts rename to scripts/config.mjs index 08fc37bd1a..4186948537 100644 --- a/scripts/config.ts +++ b/scripts/config.mjs @@ -1,8 +1,13 @@ -import path from 'path' -import type { BranchConfig, Package } from './types' +// @ts-check -// TODO: List your npm packages here. The first package will be used as the versioner. -export const packages: Package[] = [ +import { resolve } from 'node:path' +import { fileURLToPath } from "node:url"; + +/** + * List your npm packages here. The first package will be used as the versioner. + * @type {import('./types').Package[]} + */ +export const packages = [ { name: '@tanstack/query-core', packageDir: 'query-core', @@ -91,7 +96,8 @@ export const packages: Package[] = [ export const latestBranch = 'main' -export const branchConfigs: Record = { +/** @type {Record} */ +export const branchConfigs = { main: { prerelease: false, ghRelease: true, @@ -110,4 +116,5 @@ export const branchConfigs: Record = { }, } -export const rootDir = path.resolve(__dirname, '..') +const __dirname = fileURLToPath(new URL(".", import.meta.url)); +export const rootDir = resolve(__dirname, '..') diff --git a/scripts/publish.ts b/scripts/publish.mjs similarity index 80% rename from scripts/publish.ts rename to scripts/publish.mjs index 03395e7e97..7dcd526235 100644 --- a/scripts/publish.ts +++ b/scripts/publish.mjs @@ -1,9 +1,8 @@ -import { branchConfigs, latestBranch, packages, rootDir } from './config' -import type { BranchConfig, Commit, Package } from './types' - +// @ts-check // Originally ported to TS from https://github.com/remix-run/react-router/tree/main/scripts/{version,publish}.js -import path from 'path' -import { execSync } from 'child_process' + +import path from 'node:path' +import { execSync } from 'node:child_process' import chalk from 'chalk' import jsonfile from 'jsonfile' import * as semver from 'semver' @@ -13,18 +12,16 @@ import log from 'git-log-parser' import streamToArray from 'stream-to-array' import axios from 'axios' import { DateTime } from 'luxon' +import { branchConfigs, latestBranch, packages, rootDir } from './config.mjs' -import type { PackageJson } from 'type-fest' - -const releaseCommitMsg = (version: string) => `release: v${version}` +/** @param {string} version */ +const releaseCommitMsg = (version) => `release: v${version}` async function run() { - const branchName: string = - process.env.BRANCH ?? - // (process.env.PR_NUMBER ? `pr-${process.env.PR_NUMBER}` : currentGitBranch()) - currentGitBranch() + const branchName = /** @type {string} */ (process.env.BRANCH ?? currentGitBranch()) - const branchConfig: BranchConfig | undefined = branchConfigs[branchName] + /** @type {import('./types').BranchConfig | undefined} */ + const branchConfig = branchConfigs[branchName] if (!branchConfig) { console.log(`No publish config found for branch: ${branchName}`) @@ -36,7 +33,8 @@ async function run() { const npmTag = isLatestBranch ? 'latest' : branchName // Get tags - let tags: string[] = execSync('git tag').toString().split('\n') + /** @type {string[]} */ + let tags = execSync('git tag').toString().split('\n') // Filter tags to our branch/pre-release combo tags = tags @@ -52,7 +50,7 @@ async function run() { .sort(semver.compare) // Get the latest tag - let latestTag = [...tags].pop() + let latestTag = /** @type {string} */ ([...tags].pop()) let range = `${latestTag}..HEAD` // let range = ``; @@ -89,14 +87,17 @@ async function run() { console.info(`Git Range: ${range}`) - // Get the commits since the latest tag + /** + * Get the commits since the latest tag + * @type {import('./types').Commit[]} + */ const commitsSinceLatestTag = ( - await new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { const strm = log.parse({ _: range, }) - streamToArray(strm, function (err: any, arr: any[]) { + streamToArray(strm, function (err, arr) { if (err) return reject(err) Promise.all( @@ -108,7 +109,7 @@ async function run() { ).then((res) => resolve(res.filter(Boolean))) }) }) - ).filter((commit: Commit) => { + ).filter((/** @type {import('./types').Commit} */ commit) => { const exclude = [ commit.subject.startsWith('Merge branch '), // No merge commits commit.subject.startsWith(releaseCommitMsg('')), // No example update commits @@ -121,23 +122,28 @@ async function run() { `Parsing ${commitsSinceLatestTag.length} commits since ${latestTag}...`, ) - // Pares the commit messsages, log them, and determine the type of release needed - let recommendedReleaseLevel: number = commitsSinceLatestTag.reduce( + /** + * Parses the commit messsages, log them, and determine the type of release needed + * @type {number} + */ + let recommendedReleaseLevel = commitsSinceLatestTag.reduce( (releaseLevel, commit) => { - if (['fix', 'refactor', 'perf'].includes(commit.parsed.type!)) { - releaseLevel = Math.max(releaseLevel, 0) - } - if (['feat'].includes(commit.parsed.type!)) { - releaseLevel = Math.max(releaseLevel, 1) - } - if (commit.body.includes('BREAKING CHANGE')) { - releaseLevel = Math.max(releaseLevel, 2) - } - if ( - commit.subject.includes('RELEASE_ALL') || - commit.body.includes('RELEASE_ALL') - ) { - RELEASE_ALL = true + if (commit.parsed.type) { + if (['fix', 'refactor', 'perf'].includes(commit.parsed.type)) { + releaseLevel = Math.max(releaseLevel, 0) + } + if (['feat'].includes(commit.parsed.type)) { + releaseLevel = Math.max(releaseLevel, 1) + } + if (commit.body.includes('BREAKING CHANGE')) { + releaseLevel = Math.max(releaseLevel, 2) + } + if ( + commit.subject.includes('RELEASE_ALL') || + commit.body.includes('RELEASE_ALL') + ) { + RELEASE_ALL = true + } } return releaseLevel @@ -145,7 +151,8 @@ async function run() { -1, ) - const changedFiles: string[] = process.env.TAG + /** @type {string[]} */ + const changedFiles = process.env.TAG ? [] : execSync(`git diff ${latestTag} --name-only`) .toString() @@ -162,7 +169,7 @@ async function run() { acc.push(pkg) } return acc - }, [] as Package[]) + }, /** @type {import('./types').Package[]} */ ([])) // If a package has a dependency that has been updated, we need to update the // package that depends on it as well. @@ -213,28 +220,6 @@ async function run() { } } - function getSorterFn(sorters: ((d: TItem) => any)[]) { - return (a: TItem, b: TItem) => { - let i = 0 - - sorters.some((sorter) => { - const sortedA = sorter(a) - const sortedB = sorter(b) - if (sortedA > sortedB) { - i = 1 - return true - } - if (sortedA < sortedB) { - i = -1 - return true - } - return false - }) - - return i - } - } - const changelogCommitsMd = process.env.TAG ? `Manual Release: ${process.env.TAG}` : await Promise.all( @@ -246,7 +231,7 @@ async function run() { ...acc, [type]: [...(acc[type] || []), next], } - }, {} as Record), + }, /** @type {Record} */ ({})), ) .sort( getSorterFn([ @@ -300,7 +285,7 @@ async function run() { : `by ${commit.author.name || commit.author.email}` }` }), - ).then((c) => [type, c] as const) + ).then((c) => /** @type {const} */ ([type, c])) }), ).then((groups) => { return groups @@ -316,7 +301,7 @@ async function run() { const releaseType = branchConfig.prerelease ? 'prerelease' - : ({ 0: 'patch', 1: 'minor', 2: 'major' } as const)[recommendedReleaseLevel] + : /** @type {const} */ ({ 0: 'patch', 1: 'minor', 2: 'major' })[recommendedReleaseLevel] if (!releaseType) { throw new Error(`Invalid release level: ${recommendedReleaseLevel}`) @@ -324,7 +309,7 @@ async function run() { const version = process.env.TAG ? semver.parse(process.env.TAG)?.version - : semver.inc(latestTag!, releaseType, npmTag) + : semver.inc(latestTag, releaseType, npmTag) if (!version) { throw new Error( @@ -452,18 +437,24 @@ run().catch((err) => { process.exit(1) }) -function capitalize(str: string) { +/** @param {string} str */ +function capitalize(str) { return str.slice(0, 1).toUpperCase() + str.slice(1) } -async function readPackageJson(pathName: string) { - return (await jsonfile.readFile(pathName)) as PackageJson +/** + * @param {string} pathName + * @returns {Promise} + */ +async function readPackageJson(pathName) { + return (await jsonfile.readFile(pathName)) } -async function updatePackageJson( - pathName: string, - transform: (json: PackageJson) => Promise | void, -) { +/** + * @param {string} pathName + * @param {(json: import('type-fest').PackageJson) => Promise | void} transform + */ +async function updatePackageJson(pathName, transform) { const json = await readPackageJson(pathName) await transform(json) await jsonfile.writeFile(pathName, json, { @@ -475,3 +466,30 @@ function getTaggedVersion() { const output = execSync('git tag --list --points-at HEAD').toString() return output.replace(/^v|\n+$/g, '') } + +/** + * @template TItem + * @param {((d: TItem) => any)[]} sorters + * @returns {(a: TItem, b: TItem) => number} + */ +function getSorterFn(sorters) { + return (a, b) => { + let i = 0 + + sorters.some((sorter) => { + const sortedA = sorter(a) + const sortedB = sorter(b) + if (sortedA > sortedB) { + i = 1 + return true + } + if (sortedA < sortedB) { + i = -1 + return true + } + return false + }) + + return i + } +} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json deleted file mode 100644 index 2899ee9591..0000000000 --- a/scripts/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "target": "ES5", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitAny": true, - "skipLibCheck": true, - "checkJs": true - }, - "ts-node": { - "transpileOnly": true, - "files": true, - "compilerOptions": { - "sourceMap": true, - "inlineSources": true - } - } -} diff --git a/scripts/types.ts b/scripts/types.d.ts similarity index 73% rename from scripts/types.ts rename to scripts/types.d.ts index 65da33b2ff..d69ddcc096 100644 --- a/scripts/types.ts +++ b/scripts/types.d.ts @@ -1,3 +1,5 @@ +import type { RollupOptions } from 'rollup' + export type Commit = { commit: CommitOrTree tree: CommitOrTree @@ -45,3 +47,15 @@ export type BranchConfig = { prerelease: boolean ghRelease: boolean } + +export type Options = { + input: string | string[] + packageDir: string + external: RollupOptions['external'] + banner: string + jsName: string + outputFile: string + globals: Record + forceDevEnv: boolean + forceBundle: boolean +} diff --git a/scripts/validate-packages.ts b/scripts/validate-packages.mjs similarity index 75% rename from scripts/validate-packages.ts rename to scripts/validate-packages.mjs index 3a48df605f..3daaa1e7a7 100644 --- a/scripts/validate-packages.ts +++ b/scripts/validate-packages.mjs @@ -1,13 +1,14 @@ -import { packages, rootDir } from './config' -import path from 'path' -import fsp from 'fs/promises' -import jsonfile from 'jsonfile' +// @ts-check -import type { PackageJson } from 'type-fest' +import path from 'node:path' +import fsp from 'node:fs/promises' +import jsonfile from 'jsonfile' +import { packages, rootDir } from './config.mjs' async function run() { console.info('Validating packages...') - const failedValidations: string[] = [] + /** @type {string[]} */ + const failedValidations = [] await Promise.all( packages.map(async (pkg) => { @@ -17,7 +18,7 @@ async function run() { await Promise.all( pkg.entries.map(async (entryKey) => { - const entry = pkgJson[entryKey] as unknown + const entry = /** @type {unknown} */ (pkgJson[entryKey]) if (typeof entry !== 'string') { throw new Error( @@ -40,7 +41,7 @@ async function run() { }), ) - const defaultExport = pkgJson.exports?.['.']?.['default'] as unknown + const defaultExport = /** @type {unknown} */ (pkgJson.exports?.['.']?.['default']) if (typeof defaultExport !== 'string') { throw new Error( @@ -75,6 +76,10 @@ run().catch((err) => { process.exit(1) }) -async function readPackageJson(pathName: string) { - return (await jsonfile.readFile(pathName)) as PackageJson +/** + * @param {string} pathName + * @returns {Promise} + */ +async function readPackageJson(pathName) { + return (await jsonfile.readFile(pathName)) }