From 8693ed7b23652b4f328cda2832d309a1078309be Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 19 Jun 2026 08:37:01 +0200 Subject: [PATCH 1/2] chore(*): refactor to use built-in `--strip-types` Node.js flag --- eslint.config.mjs | 1 + genlist.ts | 2 +- mkshims.ts | 4 +-- package.json | 5 ++- sources/Engine.ts | 47 ++++++++++++++------------ sources/_cli.ts | 2 +- sources/_lib.ts | 2 +- sources/commands/Base.ts | 10 +++--- sources/commands/Cache.ts | 4 +-- sources/commands/Disable.ts | 8 ++--- sources/commands/Enable.ts | 6 ++-- sources/commands/InstallGlobal.ts | 15 ++++---- sources/commands/InstallLocal.ts | 2 +- sources/commands/Pack.ts | 4 +-- sources/commands/Up.ts | 10 +++--- sources/commands/Use.ts | 2 +- sources/commands/deprecated/Hydrate.ts | 6 ++-- sources/commands/deprecated/Prepare.ts | 8 ++--- sources/corepackUtils.ts | 40 +++++++++++----------- sources/folderUtils.ts | 2 +- sources/httpUtils.ts | 2 +- sources/main.ts | 35 ++++++++++--------- sources/npmRegistryUtils.ts | 6 ++-- sources/semverUtils.ts | 4 +-- sources/specUtils.ts | 28 +++++++-------- sources/types.ts | 19 ++++------- tests/Disable.test.ts | 11 +++--- tests/Enable.test.ts | 21 ++++++------ tests/Up.test.ts | 2 +- tests/Use.test.ts | 2 +- tests/_binHelpers.ts | 3 +- tests/_runCli.ts | 9 ++--- tests/config.test.ts | 6 ++-- tests/corepackUtils.test.ts | 2 +- tests/main.test.ts | 11 +++--- tests/npmRegistryUtils.test.ts | 6 ++-- tsconfig.json | 3 +- yarn.lock | 18 +--------- 38 files changed, 181 insertions(+), 187 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5c44502b8..594572d6f 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -17,6 +17,7 @@ export default [ name: `fetch`, message: `Use fetch from sources/httpUtils.ts`, }], + '@typescript-eslint/consistent-type-imports': `error`, '@typescript-eslint/no-unused-vars': [`error`, { caughtErrors: `none`, }], diff --git a/genlist.ts b/genlist.ts index 5f053848e..286be8259 100644 --- a/genlist.ts +++ b/genlist.ts @@ -1,5 +1,5 @@ import {readFileSync} from 'fs'; -import semverCompare from 'semver/functions/compare'; +import semverCompare from 'semver/functions/compare.js'; const lines = readFileSync(0, `utf8`).split(/\n/).filter(line => line); diff --git a/mkshims.ts b/mkshims.ts index 82849d9fc..d35e758b3 100644 --- a/mkshims.ts +++ b/mkshims.ts @@ -2,8 +2,8 @@ import cmdShim from '@zkochan/cmd-shim'; import fs from 'fs'; import path from 'path'; -import {Engine} from './sources/Engine'; -import {SupportedPackageManagerSet} from './sources/types'; +import {Engine} from './sources/Engine.ts'; +import {SupportedPackageManagerSet} from './sources/types.ts'; const engine = new Engine(); diff --git a/package.json b/package.json index 3ec1db1d0..8c6c8b397 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "semver": "^7.6.3", "supports-color": "^10.0.0", "tar": "^7.5.11", - "tsx": "^4.16.2", "typescript": "^5.7.3", "v8-compile-cache": "^2.3.0", "vitest": "^4.0.5", @@ -45,10 +44,10 @@ } }, "scripts": { - "build": "run clean && run build:bundle && tsx ./mkshims.ts", + "build": "run clean && run build:bundle && node ./mkshims.ts", "build:bundle": "esbuild ./sources/_lib.ts --bundle --platform=node --target=node22.22.2 --external:corepack --outfile='./dist/lib/corepack.cjs' --resolve-extensions='.ts,.mjs,.js'", "clean": "run rimraf dist shims", - "corepack": "tsx ./sources/_cli.ts", + "corepack": "node ./sources/_cli.ts", "lint": "eslint .", "prepack": "yarn build", "postpack": "run clean", diff --git a/sources/Engine.ts b/sources/Engine.ts index d93501596..f445d7d58 100644 --- a/sources/Engine.ts +++ b/sources/Engine.ts @@ -1,22 +1,24 @@ -import {UsageError} from 'clipanion'; -import fs from 'fs'; -import path from 'path'; -import process from 'process'; -import semverRcompare from 'semver/functions/rcompare'; -import semverValid from 'semver/functions/valid'; -import semverValidRange from 'semver/ranges/valid'; - -import defaultConfig from '../config.json'; - -import * as corepackUtils from './corepackUtils'; -import * as debugUtils from './debugUtils'; -import * as folderUtils from './folderUtils'; -import type {NodeError} from './nodeUtils'; -import * as semverUtils from './semverUtils'; -import * as specUtils from './specUtils'; -import {Config, Descriptor, LazyLocator, Locator} from './types'; -import {SupportedPackageManagers, SupportedPackageManagerSet} from './types'; -import {isSupportedPackageManager, PackageManagerSpec} from './types'; +import {UsageError} from 'clipanion'; +import fs from 'fs'; +import path from 'path'; +import process from 'process'; +import semverRcompare from 'semver/functions/rcompare.js'; +import semverValid from 'semver/functions/valid.js'; +import semverValidRange from 'semver/ranges/valid.js'; + +import defaultConfig from '../config.json' with {type: 'json'}; + +import * as corepackUtils from './corepackUtils.ts'; +import * as debugUtils from './debugUtils.ts'; +import * as folderUtils from './folderUtils.ts'; +import type {NodeError} from './nodeUtils.ts'; +import * as semverUtils from './semverUtils.ts'; +import * as specUtils from './specUtils.ts'; +import type {Config, Descriptor, LazyLocator, Locator} from './types.ts'; +import type {SupportedPackageManagers} from './types.ts'; +import {SupportedPackageManagerSet} from './types.ts'; +import type {PackageManagerSpec} from './types.ts'; +import {isSupportedPackageManager} from './types.ts'; export type PreparedPackageManagerInfo = Awaited>; @@ -94,7 +96,10 @@ export async function activatePackageManager(lastKnownGood: Record = []; - for (const name of SupportedPackageManagerSet as Set) + for (const name of SupportedPackageManagerSet) locators.push({name, range: await this.getDefaultVersion(name)}); return locators; diff --git a/sources/_cli.ts b/sources/_cli.ts index a546c9859..dd41eab34 100644 --- a/sources/_cli.ts +++ b/sources/_cli.ts @@ -1,3 +1,3 @@ -import {runMain} from './main'; +import {runMain} from './main.ts'; runMain(process.argv.slice(2)); diff --git a/sources/_lib.ts b/sources/_lib.ts index eeab174bc..5f8eecf2c 100644 --- a/sources/_lib.ts +++ b/sources/_lib.ts @@ -1 +1 @@ -export {runMain} from './main'; +export {runMain} from './main.ts'; diff --git a/sources/commands/Base.ts b/sources/commands/Base.ts index 950195427..79e3402a5 100644 --- a/sources/commands/Base.ts +++ b/sources/commands/Base.ts @@ -1,9 +1,9 @@ -import {Command, UsageError} from 'clipanion'; +import {Command, UsageError} from 'clipanion'; -import {PreparedPackageManagerInfo} from '../Engine'; -import * as corepackUtils from '../corepackUtils'; -import {Context} from '../main'; -import * as specUtils from '../specUtils'; +import type {PreparedPackageManagerInfo} from '../Engine.ts'; +import * as corepackUtils from '../corepackUtils.ts'; +import type {Context} from '../main.ts'; +import * as specUtils from '../specUtils.ts'; export abstract class BaseCommand extends Command { async resolvePatternsToDescriptors({patterns}: {patterns: Array}) { diff --git a/sources/commands/Cache.ts b/sources/commands/Cache.ts index 9f32d7616..6d67b8a59 100644 --- a/sources/commands/Cache.ts +++ b/sources/commands/Cache.ts @@ -1,8 +1,8 @@ import {Command} from 'clipanion'; import fs from 'fs'; -import {getInstallFolder} from '../folderUtils'; -import type {Context} from '../main'; +import {getInstallFolder} from '../folderUtils.ts'; +import type {Context} from '../main.ts'; export class CacheCommand extends Command { static paths = [ diff --git a/sources/commands/Disable.ts b/sources/commands/Disable.ts index bb184eba2..8d99c5494 100644 --- a/sources/commands/Disable.ts +++ b/sources/commands/Disable.ts @@ -3,10 +3,10 @@ import fs from 'f import path from 'path'; import which from 'which'; -import * as corepackUtils from '../corepackUtils'; -import {Context} from '../main'; -import type {NodeError} from '../nodeUtils'; -import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types'; +import * as corepackUtils from '../corepackUtils.ts'; +import type {Context} from '../main.ts'; +import type {NodeError} from '../nodeUtils.ts'; +import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types.ts'; export class DisableCommand extends Command { static paths = [ diff --git a/sources/commands/Enable.ts b/sources/commands/Enable.ts index 595aefe53..eba073176 100644 --- a/sources/commands/Enable.ts +++ b/sources/commands/Enable.ts @@ -4,9 +4,9 @@ import fs from 'f import path from 'path'; import which from 'which'; -import * as corepackUtils from '../corepackUtils'; -import {Context} from '../main'; -import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types'; +import * as corepackUtils from '../corepackUtils.ts'; +import type {Context} from '../main.ts'; +import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types.ts'; export class EnableCommand extends Command { static paths = [ diff --git a/sources/commands/InstallGlobal.ts b/sources/commands/InstallGlobal.ts index 045367ec6..ade5446cf 100644 --- a/sources/commands/InstallGlobal.ts +++ b/sources/commands/InstallGlobal.ts @@ -1,12 +1,13 @@ -import {Command, Option, UsageError} from 'clipanion'; -import fs from 'fs'; -import path from 'path'; +import {Command, Option, UsageError} from 'clipanion'; +import fs from 'fs'; +import path from 'path'; -import * as folderUtils from '../folderUtils'; -import * as specUtils from '../specUtils'; -import {Descriptor, Locator, isSupportedPackageManager} from '../types'; +import * as folderUtils from '../folderUtils.ts'; +import * as specUtils from '../specUtils.ts'; +import type {Descriptor, Locator} from '../types.ts'; +import {isSupportedPackageManager} from '../types.ts'; -import {BaseCommand} from './Base'; +import {BaseCommand} from './Base.ts'; export class InstallGlobalCommand extends BaseCommand { static paths = [ diff --git a/sources/commands/InstallLocal.ts b/sources/commands/InstallLocal.ts index 169d865b2..4990b4a8f 100644 --- a/sources/commands/InstallLocal.ts +++ b/sources/commands/InstallLocal.ts @@ -1,6 +1,6 @@ import {Command, UsageError} from 'clipanion'; -import {BaseCommand} from './Base'; +import {BaseCommand} from './Base.ts'; export class InstallLocalCommand extends BaseCommand { static paths = [ diff --git a/sources/commands/Pack.ts b/sources/commands/Pack.ts index d6771f196..743223e9c 100644 --- a/sources/commands/Pack.ts +++ b/sources/commands/Pack.ts @@ -2,9 +2,9 @@ import {Command, Option, UsageError} from 'clipanion'; import {mkdir} from 'fs/promises'; import path from 'path'; -import * as folderUtils from '../folderUtils'; +import * as folderUtils from '../folderUtils.ts'; -import {BaseCommand} from './Base'; +import {BaseCommand} from './Base.ts'; export class PackCommand extends BaseCommand { static paths = [ diff --git a/sources/commands/Up.ts b/sources/commands/Up.ts index 7ce4fd055..a6fb52aeb 100644 --- a/sources/commands/Up.ts +++ b/sources/commands/Up.ts @@ -1,11 +1,11 @@ import {Command, UsageError} from 'clipanion'; -import semverMajor from 'semver/functions/major'; -import semverValid from 'semver/functions/valid'; -import semverValidRange from 'semver/ranges/valid'; +import semverMajor from 'semver/functions/major.js'; +import semverValid from 'semver/functions/valid.js'; +import semverValidRange from 'semver/ranges/valid.js'; -import type {SupportedPackageManagers} from '../types'; +import type {SupportedPackageManagers} from '../types.ts'; -import {BaseCommand} from './Base'; +import {BaseCommand} from './Base.ts'; export class UpCommand extends BaseCommand { static paths = [ diff --git a/sources/commands/Use.ts b/sources/commands/Use.ts index 76696c467..508a2864e 100644 --- a/sources/commands/Use.ts +++ b/sources/commands/Use.ts @@ -1,6 +1,6 @@ import {Command, Option, UsageError} from 'clipanion'; -import {BaseCommand} from './Base'; +import {BaseCommand} from './Base.ts'; export class UseCommand extends BaseCommand { static paths = [ diff --git a/sources/commands/deprecated/Hydrate.ts b/sources/commands/deprecated/Hydrate.ts index 01c36dd24..200e282fb 100644 --- a/sources/commands/deprecated/Hydrate.ts +++ b/sources/commands/deprecated/Hydrate.ts @@ -2,9 +2,9 @@ import {Command, Option, UsageError} from 'clipanion'; import {mkdir} from 'fs/promises'; import path from 'path'; -import * as folderUtils from '../../folderUtils'; -import {Context} from '../../main'; -import {isSupportedPackageManager} from '../../types'; +import * as folderUtils from '../../folderUtils.ts'; +import type {Context} from '../../main.ts'; +import {isSupportedPackageManager} from '../../types.ts'; export class HydrateCommand extends Command { static paths = [ diff --git a/sources/commands/deprecated/Prepare.ts b/sources/commands/deprecated/Prepare.ts index 70df49324..0f33ecd19 100644 --- a/sources/commands/deprecated/Prepare.ts +++ b/sources/commands/deprecated/Prepare.ts @@ -2,10 +2,10 @@ import {Command, Option, UsageError} from 'clipanion'; import {mkdir} from 'fs/promises'; import path from 'path'; -import * as folderUtils from '../../folderUtils'; -import {Context} from '../../main'; -import * as specUtils from '../../specUtils'; -import {Descriptor} from '../../types'; +import * as folderUtils from '../../folderUtils.ts'; +import type {Context} from '../../main.ts'; +import * as specUtils from '../../specUtils.ts'; +import type {Descriptor} from '../../types.ts'; export class PrepareCommand extends Command { static paths = [ diff --git a/sources/corepackUtils.ts b/sources/corepackUtils.ts index c02571ab6..6c386bcec 100644 --- a/sources/corepackUtils.ts +++ b/sources/corepackUtils.ts @@ -1,23 +1,23 @@ -import {createHash} from 'crypto'; -import {once} from 'events'; -import fs from 'fs'; -import type {Dir} from 'fs'; -import Module from 'module'; -import path from 'path'; -import Range from 'semver/classes/range'; -import SemVer from 'semver/classes/semver'; -import semverLt from 'semver/functions/lt'; -import semverParse from 'semver/functions/parse'; -import {setTimeout as setTimeoutPromise} from 'timers/promises'; - -import * as engine from './Engine'; -import * as debugUtils from './debugUtils'; -import * as folderUtils from './folderUtils'; -import * as httpUtils from './httpUtils'; -import * as nodeUtils from './nodeUtils'; -import * as npmRegistryUtils from './npmRegistryUtils'; -import {RegistrySpec, Descriptor, Locator, PackageManagerSpec} from './types'; -import {BinList, BinSpec, InstallSpec, DownloadSpec} from './types'; +import {createHash} from 'crypto'; +import {once} from 'events'; +import fs from 'fs'; +import type {Dir} from 'fs'; +import Module from 'module'; +import path from 'path'; +import Range from 'semver/classes/range.js'; +import SemVer from 'semver/classes/semver.js'; +import semverLt from 'semver/functions/lt.js'; +import semverParse from 'semver/functions/parse.js'; +import {setTimeout as setTimeoutPromise} from 'timers/promises'; + +import * as engine from './Engine.ts'; +import * as debugUtils from './debugUtils.ts'; +import * as folderUtils from './folderUtils.ts'; +import * as httpUtils from './httpUtils.ts'; +import * as nodeUtils from './nodeUtils.ts'; +import * as npmRegistryUtils from './npmRegistryUtils.ts'; +import type {RegistrySpec, Descriptor, Locator, PackageManagerSpec} from './types.ts'; +import type {BinList, BinSpec, InstallSpec, DownloadSpec} from './types.ts'; const YARN_SWITCH_REGEX = /[/\\]switch[/\\]bin[/\\]/; diff --git a/sources/folderUtils.ts b/sources/folderUtils.ts index 7ce475aa9..84cde502c 100644 --- a/sources/folderUtils.ts +++ b/sources/folderUtils.ts @@ -4,7 +4,7 @@ import {homedir, tmpdir} from 'os'; import {join} from 'path'; import process from 'process'; -import type {NodeError} from './nodeUtils'; +import type {NodeError} from './nodeUtils.ts'; /** * If the install folder structure changes then increment this number. diff --git a/sources/httpUtils.ts b/sources/httpUtils.ts index ff11d5432..487443a8e 100644 --- a/sources/httpUtils.ts +++ b/sources/httpUtils.ts @@ -4,7 +4,7 @@ import {once} from 'events'; import {stderr, stdin} from 'process'; import {Readable} from 'stream'; -import {DEFAULT_NPM_REGISTRY_URL} from './npmRegistryUtils'; +import {DEFAULT_NPM_REGISTRY_URL} from './npmRegistryUtils.ts'; async function fetch(input: string | URL, init?: RequestInit) { if (process.env.COREPACK_ENABLE_NETWORK === `0`) diff --git a/sources/main.ts b/sources/main.ts index faa7d6cd7..e623af1f5 100644 --- a/sources/main.ts +++ b/sources/main.ts @@ -1,23 +1,26 @@ -import {BaseContext, Builtins, Cli} from 'clipanion'; -import type {UsageError} from 'clipanion'; - -import {version as corepackVersion} from '../package.json'; - -import {Engine, PackageManagerRequest} from './Engine'; -import {CacheCommand} from './commands/Cache'; -import {DisableCommand} from './commands/Disable'; -import {EnableCommand} from './commands/Enable'; -import {InstallGlobalCommand} from './commands/InstallGlobal'; -import {InstallLocalCommand} from './commands/InstallLocal'; -import {PackCommand} from './commands/Pack'; -import {UpCommand} from './commands/Up'; -import {UseCommand} from './commands/Use'; -import {HydrateCommand} from './commands/deprecated/Hydrate'; -import {PrepareCommand} from './commands/deprecated/Prepare'; +import {Builtins, Cli} from 'clipanion'; +import type {UsageError, BaseContext} from 'clipanion'; + +import pJSON from '../package.json' with {type: 'json'}; + +import type {PackageManagerRequest} from './Engine.ts'; +import {Engine} from './Engine.ts'; +import {CacheCommand} from './commands/Cache.ts'; +import {DisableCommand} from './commands/Disable.ts'; +import {EnableCommand} from './commands/Enable.ts'; +import {InstallGlobalCommand} from './commands/InstallGlobal.ts'; +import {InstallLocalCommand} from './commands/InstallLocal.ts'; +import {PackCommand} from './commands/Pack.ts'; +import {UpCommand} from './commands/Up.ts'; +import {UseCommand} from './commands/Use.ts'; +import {HydrateCommand} from './commands/deprecated/Hydrate.ts'; +import {PrepareCommand} from './commands/deprecated/Prepare.ts'; export type CustomContext = {cwd: string, engine: Engine}; export type Context = BaseContext & CustomContext; +const {version: corepackVersion} = pJSON; + function getPackageManagerRequestFromCli(parameter: string | undefined, engine: Engine): PackageManagerRequest | null { if (!parameter) return null; diff --git a/sources/npmRegistryUtils.ts b/sources/npmRegistryUtils.ts index a7d110e95..b2693c940 100644 --- a/sources/npmRegistryUtils.ts +++ b/sources/npmRegistryUtils.ts @@ -1,10 +1,10 @@ import {UsageError} from 'clipanion'; import {createVerify} from 'crypto'; -import defaultConfig from '../config.json'; +import defaultConfig from '../config.json' with {type: 'json'}; -import {shouldSkipIntegrityCheck} from './corepackUtils'; -import * as httpUtils from './httpUtils'; +import {shouldSkipIntegrityCheck} from './corepackUtils.ts'; +import * as httpUtils from './httpUtils.ts'; // load abbreviated metadata as that's all we need for these calls // see: https://github.com/npm/registry/blob/cfe04736f34db9274a780184d1cdb2fb3e4ead2a/docs/responses/package-metadata.md diff --git a/sources/semverUtils.ts b/sources/semverUtils.ts index 9e138ed3c..5d2ad5bef 100644 --- a/sources/semverUtils.ts +++ b/sources/semverUtils.ts @@ -1,5 +1,5 @@ -import Range from 'semver/classes/range'; -import SemVer from 'semver/classes/semver'; +import Range from 'semver/classes/range.js'; +import SemVer from 'semver/classes/semver.js'; /** * Returns whether the given semver version satisfies the given range. Notably diff --git a/sources/specUtils.ts b/sources/specUtils.ts index 8b73aacd2..a1915ac0b 100644 --- a/sources/specUtils.ts +++ b/sources/specUtils.ts @@ -1,17 +1,17 @@ -import {UsageError} from 'clipanion'; -import fs from 'fs'; -import path from 'path'; -import semverSatisfies from 'semver/functions/satisfies'; -import semverValid from 'semver/functions/valid'; -import semverValidRange from 'semver/ranges/valid'; -import {parseEnv} from 'util'; - -import {PreparedPackageManagerInfo} from './Engine'; -import * as debugUtils from './debugUtils'; -import {NodeError} from './nodeUtils'; -import * as nodeUtils from './nodeUtils'; -import {Descriptor, isSupportedPackageManager} from './types'; -import type {LocalEnvFile} from './types'; +import {UsageError} from 'clipanion'; +import fs from 'fs'; +import path from 'path'; +import semverSatisfies from 'semver/functions/satisfies.js'; +import semverValid from 'semver/functions/valid.js'; +import semverValidRange from 'semver/ranges/valid.js'; +import {parseEnv} from 'util'; + +import type {PreparedPackageManagerInfo} from './Engine.ts'; +import * as debugUtils from './debugUtils.ts'; +import type {NodeError} from './nodeUtils.ts'; +import * as nodeUtils from './nodeUtils.ts'; +import {isSupportedPackageManager} from './types.ts'; +import type {LocalEnvFile, Descriptor} from './types.ts'; const nodeModulesRegExp = /[\\/]node_modules[\\/](@[^\\/]*[\\/])?([^@\\/][^\\/]*)$/; diff --git a/sources/types.ts b/sources/types.ts index 382f2c3e3..9fca1dc40 100644 --- a/sources/types.ts +++ b/sources/types.ts @@ -1,22 +1,17 @@ export type BinSpec = {[key: string]: string}; export type BinList = Array; -export enum SupportedPackageManagers { - Npm = `npm`, - Pnpm = `pnpm`, - Yarn = `yarn`, -} +export type SupportedPackageManagers = `npm` | `pnpm` | `yarn`; -export const SupportedPackageManagerSet = new Set( - Object.values(SupportedPackageManagers), -); +const supportedPackageManagersList: Array = [`npm`, `pnpm`, `yarn`]; -export const SupportedPackageManagerSetWithoutNpm = new Set( - Object.values(SupportedPackageManagers), +export const SupportedPackageManagerSet: ReadonlySet = new Set( + supportedPackageManagersList, ); -// npm is distributed with Node as a builtin; we don't want Corepack to override it unless the npm team is on board -SupportedPackageManagerSetWithoutNpm.delete(SupportedPackageManagers.Npm); +export const SupportedPackageManagerSetWithoutNpm: ReadonlySet = new Set( + supportedPackageManagersList.filter(pm => pm !== `npm`), +); export function isSupportedPackageManager(value: string): value is SupportedPackageManagers { return SupportedPackageManagerSet.has(value as SupportedPackageManagers); diff --git a/tests/Disable.test.ts b/tests/Disable.test.ts index d7b8648af..66f8ab9b9 100644 --- a/tests/Disable.test.ts +++ b/tests/Disable.test.ts @@ -1,13 +1,14 @@ -import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib'; +import type {Filename} from '@yarnpkg/fslib'; +import {ppath, xfs, npath} from '@yarnpkg/fslib'; import {delimiter} from 'node:path'; import process from 'node:process'; import {describe, beforeEach, it, expect} from 'vitest'; -import {Engine} from '../sources/Engine'; -import {SupportedPackageManagerSetWithoutNpm} from '../sources/types'; +import {Engine} from '../sources/Engine.ts'; +import {SupportedPackageManagerSetWithoutNpm} from '../sources/types.ts'; -import {makeBin, getBinaryNames} from './_binHelpers'; -import {runCli} from './_runCli'; +import {makeBin, getBinaryNames} from './_binHelpers.ts'; +import {runCli} from './_runCli.ts'; const engine = new Engine(); diff --git a/tests/Enable.test.ts b/tests/Enable.test.ts index c85f91f45..f1423bca6 100644 --- a/tests/Enable.test.ts +++ b/tests/Enable.test.ts @@ -1,14 +1,15 @@ -import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib'; -import {delimiter} from 'node:path'; -import process from 'node:process'; -import {setTimeout} from 'node:timers/promises'; -import {describe, beforeEach, it, expect, test} from 'vitest'; +import type {Filename} from '@yarnpkg/fslib'; +import {ppath, xfs, npath} from '@yarnpkg/fslib'; +import {delimiter} from 'node:path'; +import process from 'node:process'; +import {setTimeout} from 'node:timers/promises'; +import {describe, beforeEach, it, expect, test} from 'vitest'; -import {Engine} from '../sources/Engine'; -import {SupportedPackageManagers, SupportedPackageManagerSetWithoutNpm} from '../sources/types'; +import {Engine} from '../sources/Engine.ts'; +import {SupportedPackageManagerSetWithoutNpm} from '../sources/types.ts'; -import {makeBin, getBinaryNames} from './_binHelpers'; -import {runCli} from './_runCli'; +import {makeBin, getBinaryNames} from './_binHelpers.ts'; +import {runCli} from './_runCli.ts'; const engine = new Engine(); @@ -81,7 +82,7 @@ describe(`EnableCommand`, () => { }); const expectedEntries: Array = [ppath.basename(corepackBin)]; - for (const binName of engine.getBinariesFor(SupportedPackageManagers.Yarn)) + for (const binName of engine.getBinariesFor(`yarn`)) expectedEntries.push(...getBinaryNames(binName)); await expect(sortedEntries).resolves.toEqual(expectedEntries.sort()); diff --git a/tests/Up.test.ts b/tests/Up.test.ts index dac6e9d96..1934202b9 100644 --- a/tests/Up.test.ts +++ b/tests/Up.test.ts @@ -2,7 +2,7 @@ import {ppath, xfs, npath} from '@yarnpkg/fslib'; import process from 'node:process'; import {describe, beforeEach, it, expect} from 'vitest'; -import {runCli} from './_runCli'; +import {runCli} from './_runCli.ts'; beforeEach(async () => { const home = await xfs.mktempPromise(); diff --git a/tests/Use.test.ts b/tests/Use.test.ts index 978c2e3a8..4010bf335 100644 --- a/tests/Use.test.ts +++ b/tests/Use.test.ts @@ -2,7 +2,7 @@ import {ppath, xfs, npath} from '@yarnpkg/fslib'; import process from 'node:process'; import {describe, beforeEach, it, expect} from 'vitest'; -import {runCli} from './_runCli'; +import {runCli} from './_runCli.ts'; beforeEach(async () => { const home = await xfs.mktempPromise(); diff --git a/tests/_binHelpers.ts b/tests/_binHelpers.ts index 5a83909fc..5201982e7 100644 --- a/tests/_binHelpers.ts +++ b/tests/_binHelpers.ts @@ -1,4 +1,5 @@ -import {Filename, ppath, xfs, PortablePath} from '@yarnpkg/fslib'; +import type {Filename, PortablePath} from '@yarnpkg/fslib'; +import {ppath, xfs} from '@yarnpkg/fslib'; export async function makeBin(cwd: PortablePath, name: Filename, {ignorePlatform = false}: {ignorePlatform?: boolean} = {}) { let path = ppath.join(cwd, name); diff --git a/tests/_runCli.ts b/tests/_runCli.ts index e53adec4a..ce7025e11 100644 --- a/tests/_runCli.ts +++ b/tests/_runCli.ts @@ -1,7 +1,8 @@ -import {PortablePath, npath} from '@yarnpkg/fslib'; -import {spawn} from 'child_process'; -import * as path from 'path'; -import {pathToFileURL} from 'url'; +import type {PortablePath} from '@yarnpkg/fslib'; +import {npath} from '@yarnpkg/fslib'; +import {spawn} from 'child_process'; +import * as path from 'path'; +import {pathToFileURL} from 'url'; export async function runCli(cwd: PortablePath, argv: Array, withCustomRegistry?: boolean): Promise<{exitCode: number | null, stdout: string, stderr: string}> { const out: Array = []; diff --git a/tests/config.test.ts b/tests/config.test.ts index 1d5b96426..f82b60e44 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -1,9 +1,9 @@ import {vi, describe, it, expect} from 'vitest'; -import defaultConfig from '../config.json'; -import {DEFAULT_NPM_REGISTRY_URL} from '../sources/npmRegistryUtils'; +import defaultConfig from '../config.json' with {type: 'json'}; +import {DEFAULT_NPM_REGISTRY_URL} from '../sources/npmRegistryUtils.ts'; -vi.mock(`../sources/httpUtils`); +vi.mock(`../sources/httpUtils.ts`); describe(`key store should be up-to-date`, () => { it(`should contain up-to-date npm keys`, async () => { diff --git a/tests/corepackUtils.test.ts b/tests/corepackUtils.test.ts index 7a0ddb5b6..1af8e7d81 100644 --- a/tests/corepackUtils.test.ts +++ b/tests/corepackUtils.test.ts @@ -1,6 +1,6 @@ import {describe, it, expect} from 'vitest'; -import {shouldSkipIntegrityCheck} from '../sources/corepackUtils'; +import {shouldSkipIntegrityCheck} from '../sources/corepackUtils.ts'; describe(`corepack utils shouldSkipIntegrityCheck`, () => { it(`should return false if COREPACK_INTEGRITY_KEYS env is not set`, () => { diff --git a/tests/main.test.ts b/tests/main.test.ts index 507db2e43..fac93914d 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,13 +1,14 @@ -import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib'; +import type {Filename, PortablePath} from '@yarnpkg/fslib'; +import {ppath, xfs, npath} from '@yarnpkg/fslib'; import os from 'node:os'; import process from 'node:process'; import {afterEach, beforeEach, describe, expect, it} from 'vitest'; -import config from '../config.json'; -import * as folderUtils from '../sources/folderUtils'; -import {SupportedPackageManagerSet} from '../sources/types'; +import config from '../config.json' with {type: 'json'}; +import * as folderUtils from '../sources/folderUtils.ts'; +import {SupportedPackageManagerSet} from '../sources/types.ts'; -import {runCli} from './_runCli'; +import {runCli} from './_runCli.ts'; beforeEach(async () => { diff --git a/tests/npmRegistryUtils.test.ts b/tests/npmRegistryUtils.test.ts index 728d6f977..aab34738d 100644 --- a/tests/npmRegistryUtils.test.ts +++ b/tests/npmRegistryUtils.test.ts @@ -2,10 +2,10 @@ import {Buffer} from 'node:buffe import process from 'node:process'; import {describe, beforeEach, it, expect, vi} from 'vitest'; -import {fetchAsJson as httpFetchAsJson} from '../sources/httpUtils'; -import {DEFAULT_HEADERS, DEFAULT_NPM_REGISTRY_URL, fetchAsJson} from '../sources/npmRegistryUtils'; +import {fetchAsJson as httpFetchAsJson} from '../sources/httpUtils.ts'; +import {DEFAULT_HEADERS, DEFAULT_NPM_REGISTRY_URL, fetchAsJson} from '../sources/npmRegistryUtils.ts'; -vi.mock(`../sources/httpUtils`); +vi.mock(`../sources/httpUtils.ts`); describe(`npm registry utils fetchAsJson`, () => { beforeEach(() => { diff --git a/tsconfig.json b/tsconfig.json index 6a6994834..ec3d22600 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "compilerOptions": { + "allowImportingTsExtensions": true, "allowSyntheticDefaultImports": true, "baseUrl": ".", "esModuleInterop": true, - "experimentalDecorators": true, + "erasableSyntaxOnly": true, "forceConsistentCasingInFileNames": true, "lib": ["ES2023"], "module": "preserve", diff --git a/yarn.lock b/yarn.lock index b2bcf4292..c4e6455e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1237,7 +1237,6 @@ __metadata: semver: "npm:^7.6.3" supports-color: "npm:^10.0.0" tar: "npm:^7.5.11" - tsx: "npm:^4.16.2" typescript: "npm:^5.7.3" v8-compile-cache: "npm:^2.3.0" vitest: "npm:^4.0.5" @@ -1515,7 +1514,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.28.0, esbuild@npm:~0.28.0": +"esbuild@npm:^0.28.0": version: 0.28.0 resolution: "esbuild@npm:0.28.0" dependencies: @@ -3419,21 +3418,6 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.16.2": - version: 4.22.0 - resolution: "tsx@npm:4.22.0" - dependencies: - esbuild: "npm:~0.28.0" - fsevents: "npm:~2.3.3" - dependenciesMeta: - fsevents: - optional: true - bin: - tsx: dist/cli.mjs - checksum: 10c0/cc7474ac13eebf6bb4d87ce21bdd79213261a37a6e247a74d7920b3e0ce7b704b42e7642e7978e2f3de5762981b3b74ed0ae14cf60934107aa0b1390f25e46ba - languageName: node - linkType: hard - "typanion@npm:^3.8.0": version: 3.14.0 resolution: "typanion@npm:3.14.0" From 9677b62d0cf36113284b606b8c8a131facf904a6 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 19 Jun 2026 08:42:10 +0200 Subject: [PATCH 2/2] fixup! chore(*): refactor to use built-in `--strip-types` Node.js flag --- mkshims.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkshims.ts b/mkshims.ts index d35e758b3..74c9078ad 100644 --- a/mkshims.ts +++ b/mkshims.ts @@ -7,8 +7,8 @@ import {SupportedPackageManagerSet} from './sources/types.ts'; const engine = new Engine(); -const distDir = path.join(__dirname, `dist`); -const shimsDir = path.join(__dirname, `shims`); +const distDir = path.join(import.meta.dirname, `dist`); +const shimsDir = path.join(import.meta.dirname, `shims`); const physicalNodewinDir = path.join(shimsDir, `nodewin`); const virtualNodewinDir = path.join(physicalNodewinDir, `node_modules/corepack`); @@ -59,7 +59,7 @@ async function main() { // Last note: cmdShim generates shims with relative paths, so it doesn't matter // that the target files don't truly exist, as long as we mock the `stat` function. - const remapPath = (p: string) => path.resolve(__dirname, path.relative(virtualNodewinDir, p)); + const remapPath = (p: string) => path.resolve(import.meta.dirname, path.relative(virtualNodewinDir, p)); const easyStatFs = Object.assign(Object.create(fs), { readFile: (p: string, encoding: BufferEncoding, cb: (err: any, str: string) => void) => fs.readFile(remapPath(p), encoding, cb),