Skip to content

Commit 964f23e

Browse files
authored
chore(*): refactor to use built-in --strip-types Node.js flag (#863)
1 parent 44e847b commit 964f23e

38 files changed

Lines changed: 184 additions & 190 deletions

‎eslint.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default [
1717
name: `fetch`,
1818
message: `Use fetch from sources/httpUtils.ts`,
1919
}],
20+
'@typescript-eslint/consistent-type-imports': `error`,
2021
'@typescript-eslint/no-unused-vars': [`error`, {
2122
caughtErrors: `none`,
2223
}],

‎genlist.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {readFileSync} from 'fs';
2-
import semverCompare from 'semver/functions/compare';
2+
import semverCompare from 'semver/functions/compare.js';
33

44
const lines = readFileSync(0, `utf8`).split(/\n/).filter(line => line);
55

‎mkshims.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import cmdShim from '@zkochan/cmd-shim';
22
import fs from 'fs';
33
import path from 'path';
44

5-
import {Engine} from './sources/Engine';
6-
import {SupportedPackageManagerSet} from './sources/types';
5+
import {Engine} from './sources/Engine.ts';
6+
import {SupportedPackageManagerSet} from './sources/types.ts';
77

88
const engine = new Engine();
99

10-
const distDir = path.join(__dirname, `dist`);
11-
const shimsDir = path.join(__dirname, `shims`);
10+
const distDir = path.join(import.meta.dirname, `dist`);
11+
const shimsDir = path.join(import.meta.dirname, `shims`);
1212

1313
const physicalNodewinDir = path.join(shimsDir, `nodewin`);
1414
const virtualNodewinDir = path.join(physicalNodewinDir, `node_modules/corepack`);
@@ -59,7 +59,7 @@ async function main() {
5959

6060
// Last note: cmdShim generates shims with relative paths, so it doesn't matter
6161
// that the target files don't truly exist, as long as we mock the `stat` function.
62-
const remapPath = (p: string) => path.resolve(__dirname, path.relative(virtualNodewinDir, p));
62+
const remapPath = (p: string) => path.resolve(import.meta.dirname, path.relative(virtualNodewinDir, p));
6363

6464
const easyStatFs = Object.assign(Object.create(fs), {
6565
readFile: (p: string, encoding: BufferEncoding, cb: (err: any, str: string) => void) => fs.readFile(remapPath(p), encoding, cb),

‎package.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"semver": "^7.6.3",
3434
"supports-color": "^10.0.0",
3535
"tar": "^7.5.11",
36-
"tsx": "^4.16.2",
3736
"typescript": "^5.7.3",
3837
"v8-compile-cache": "^2.3.0",
3938
"vitest": "^4.0.5",
@@ -45,10 +44,10 @@
4544
}
4645
},
4746
"scripts": {
48-
"build": "run clean && run build:bundle && tsx ./mkshims.ts",
47+
"build": "run clean && run build:bundle && node ./mkshims.ts",
4948
"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'",
5049
"clean": "run rimraf dist shims",
51-
"corepack": "tsx ./sources/_cli.ts",
50+
"corepack": "node ./sources/_cli.ts",
5251
"lint": "eslint .",
5352
"prepack": "yarn build",
5453
"postpack": "run clean",

‎sources/Engine.ts‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import {UsageError} from 'clipanion';
2-
import fs from 'fs';
3-
import path from 'path';
4-
import process from 'process';
5-
import semverRcompare from 'semver/functions/rcompare';
6-
import semverValid from 'semver/functions/valid';
7-
import semverValidRange from 'semver/ranges/valid';
8-
9-
import defaultConfig from '../config.json';
10-
11-
import * as corepackUtils from './corepackUtils';
12-
import * as debugUtils from './debugUtils';
13-
import * as folderUtils from './folderUtils';
14-
import type {NodeError} from './nodeUtils';
15-
import * as semverUtils from './semverUtils';
16-
import * as specUtils from './specUtils';
17-
import {Config, Descriptor, LazyLocator, Locator} from './types';
18-
import {SupportedPackageManagers, SupportedPackageManagerSet} from './types';
19-
import {isSupportedPackageManager, PackageManagerSpec} from './types';
1+
import {UsageError} from 'clipanion';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import process from 'process';
5+
import semverRcompare from 'semver/functions/rcompare.js';
6+
import semverValid from 'semver/functions/valid.js';
7+
import semverValidRange from 'semver/ranges/valid.js';
8+
9+
import defaultConfig from '../config.json' with {type: 'json'};
10+
11+
import * as corepackUtils from './corepackUtils.ts';
12+
import * as debugUtils from './debugUtils.ts';
13+
import * as folderUtils from './folderUtils.ts';
14+
import type {NodeError} from './nodeUtils.ts';
15+
import * as semverUtils from './semverUtils.ts';
16+
import * as specUtils from './specUtils.ts';
17+
import type {Config, Descriptor, LazyLocator, Locator} from './types.ts';
18+
import type {SupportedPackageManagers} from './types.ts';
19+
import {SupportedPackageManagerSet} from './types.ts';
20+
import type {PackageManagerSpec} from './types.ts';
21+
import {isSupportedPackageManager} from './types.ts';
2022

2123
export type PreparedPackageManagerInfo = Awaited<ReturnType<Engine[`ensurePackageManager`]>>;
2224

@@ -94,7 +96,10 @@ export async function activatePackageManager(lastKnownGood: Record<string, strin
9496
}
9597

9698
export class Engine {
97-
constructor(public config: Config = defaultConfig as Config) {
99+
config: Config;
100+
101+
constructor(config: Config = defaultConfig as Config) {
102+
this.config = config;
98103
}
99104

100105
getPackageManagerFor(binaryName: string): SupportedPackageManagers | null {
@@ -161,7 +166,7 @@ export class Engine {
161166
async getDefaultDescriptors() {
162167
const locators: Array<Descriptor> = [];
163168

164-
for (const name of SupportedPackageManagerSet as Set<SupportedPackageManagers>)
169+
for (const name of SupportedPackageManagerSet)
165170
locators.push({name, range: await this.getDefaultVersion(name)});
166171

167172
return locators;

‎sources/_cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import {runMain} from './main';
1+
import {runMain} from './main.ts';
22

33
runMain(process.argv.slice(2));

‎sources/_lib.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {runMain} from './main';
1+
export {runMain} from './main.ts';

‎sources/commands/Base.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Command, UsageError} from 'clipanion';
1+
import {Command, UsageError} from 'clipanion';
22

3-
import {PreparedPackageManagerInfo} from '../Engine';
4-
import * as corepackUtils from '../corepackUtils';
5-
import {Context} from '../main';
6-
import * as specUtils from '../specUtils';
3+
import type {PreparedPackageManagerInfo} from '../Engine.ts';
4+
import * as corepackUtils from '../corepackUtils.ts';
5+
import type {Context} from '../main.ts';
6+
import * as specUtils from '../specUtils.ts';
77

88
export abstract class BaseCommand extends Command<Context> {
99
async resolvePatternsToDescriptors({patterns}: {patterns: Array<string>}) {

‎sources/commands/Cache.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Command} from 'clipanion';
22
import fs from 'fs';
33

4-
import {getInstallFolder} from '../folderUtils';
5-
import type {Context} from '../main';
4+
import {getInstallFolder} from '../folderUtils.ts';
5+
import type {Context} from '../main.ts';
66

77
export class CacheCommand extends Command<Context> {
88
static paths = [

‎sources/commands/Disable.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import fs from 'f
33
import path from 'path';
44
import which from 'which';
55

6-
import * as corepackUtils from '../corepackUtils';
7-
import {Context} from '../main';
8-
import type {NodeError} from '../nodeUtils';
9-
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types';
6+
import * as corepackUtils from '../corepackUtils.ts';
7+
import type {Context} from '../main.ts';
8+
import type {NodeError} from '../nodeUtils.ts';
9+
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types.ts';
1010

1111
export class DisableCommand extends Command<Context> {
1212
static paths = [

0 commit comments

Comments
 (0)