Skip to content

Commit

Permalink
refactor: update node types (#4764)
Browse files Browse the repository at this point in the history
* refactor: update node types

* chore: dedupe

* refactor: remove unnecessary switch

Co-authored-by: merceyz <merceyz@users.noreply.github.com>
(cherry picked from commit 6302ecb)
  • Loading branch information
paul-soporan authored and merceyz committed Dec 25, 2023
1 parent 1c93cf6 commit a258467
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 196 deletions.
56 changes: 20 additions & 36 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions .yarn/versions/392e431d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/fslib": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/pnp": patch
"@yarnpkg/pnpify": patch
"@yarnpkg/sdks": patch

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/shell"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/preset-typescript": "^7.23.3",
"@babel/register": "^7.22.15",
"@types/jest": "^28.1.6",
"@types/node": "^13.7.0",
"@types/node": "^18.7.6",
"@yarnpkg/cli": "workspace:^",
"@yarnpkg/core": "workspace:^",
"@yarnpkg/eslint-config": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const writeFile = async (target: PortablePath, body: string | Buffer): Pr
await xfs.writeFilePromise(target, body);
};

export const readFile = (source: PortablePath, encoding?: string): Promise<any> => {
export const readFile = (source: PortablePath, encoding?: BufferEncoding): Promise<any> => {
return xfs.readFilePromise(source, encoding);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/diff": "^5.0.0",
"@types/lodash": "^4.14.136",
"@types/micromatch": "^4.0.1",
"@types/node": "^13.7.0",
"@types/node": "^18.7.6",
"@types/tar": "^4.0.4",
"@types/tunnel": "^0.0.0",
"@yarnpkg/cli": "workspace:^",
Expand Down
22 changes: 11 additions & 11 deletions packages/yarnpkg-core/sources/execUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {PortablePath, npath, ppath} from '@yarnpkg/fslib';
import {ChildProcess} from 'child_process';
import crossSpawn from 'cross-spawn';
import {Readable, Writable} from 'stream';
import {PortablePath, npath, ppath, BufferEncodingOrBuffer} from '@yarnpkg/fslib';
import {ChildProcess} from 'child_process';
import crossSpawn from 'cross-spawn';
import {Readable, Writable} from 'stream';

import {Configuration} from './Configuration';
import {MessageName} from './MessageName';
import {Report, ReportError} from './Report';
import * as formatUtils from './formatUtils';
import {Configuration} from './Configuration';
import {MessageName} from './MessageName';
import {Report, ReportError} from './Report';
import * as formatUtils from './formatUtils';

export enum EndStrategy {
Never,
Expand All @@ -26,7 +26,7 @@ export type PipevpOptions = {

export type PipeErrorOptions = {
fileName: string;
code: number;
code: number | null;
signal: NodeJS.Signals | null;
};

Expand Down Expand Up @@ -151,7 +151,7 @@ export async function pipevp(fileName: string, args: Array<string>, {cwd, env =
process.off(`SIGTERM`, sigtermHandler);
}

if (end === EndStrategy.Always || (end === EndStrategy.ErrorCode && code > 0))
if (end === EndStrategy.Always || (end === EndStrategy.ErrorCode && code !== 0))
closeStreams();

if (code === 0 || !strict) {
Expand All @@ -166,7 +166,7 @@ export async function pipevp(fileName: string, args: Array<string>, {cwd, env =
export type ExecvpOptions = {
cwd: PortablePath;
env?: {[key: string]: string | undefined};
encoding?: string;
encoding?: BufferEncodingOrBuffer;
strict?: boolean;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/miscUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function dynamicRequireNoCache(path: string) {
try {
result = dynamicRequireNode(physicalPath);

const freshCacheEntry = realRequire.cache[physicalPath];
const freshCacheEntry = realRequire.cache[physicalPath]!;

const dynamicModule = eval(`module`) as NodeModule;
const freshCacheIndex = dynamicModule.children.indexOf(freshCacheEntry);
Expand Down
1 change: 0 additions & 1 deletion packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ export function isNodeScript(p: PortablePath) {
xfs.closeSync(fd);
}

// @ts-expect-error - Types are incorrect
const magic = buf.readUint32BE();
if (
magic === 0xcafebabe || // OSX Universal Binary
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/worker-zip/index.js

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions packages/yarnpkg-fslib/sources/FakeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {copyPromise, LinkStrategy} from './algorithms/copy
import {FSPath, Path, PortablePath, PathUtils, Filename} from './path';
import {convertPath, ppath} from './path';

export type BufferEncodingOrBuffer = BufferEncoding | 'buffer';

export type Stats = NodeStats & {
crc?: number;
};
Expand Down Expand Up @@ -40,12 +42,12 @@ export type OpendirOptions = Partial<{
}>;

export type CreateReadStreamOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
fd: number;
}>;

export type CreateWriteStreamOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
fd: number;
flags: 'a';
}>;
Expand All @@ -62,16 +64,16 @@ export type RmdirOptions = Partial<{
}>;

export type WriteFileOptions = Partial<{
encoding: string;
encoding: BufferEncoding;
mode: number;
flag: string;
}> | string;
}> | BufferEncoding;

export type WatchOptions = Partial<{
persistent: boolean;
recursive: boolean;
encoding: string;
}> | string;
encoding: BufferEncodingOrBuffer;
}> | BufferEncodingOrBuffer;

export type WatchFileOptions = Partial<{
bigint: boolean;
Expand Down Expand Up @@ -191,10 +193,10 @@ export abstract class FakeFS<P extends Path> {

abstract fstatPromise(fd: number): Promise<Stats>;
abstract fstatPromise(fd: number, opts: {bigint: true}): Promise<BigIntStats>;
abstract fstatPromise(fd: number, opts?: {bigint: boolean}): Promise<BigIntStats | Stats>;
abstract fstatPromise(fd: number, opts?: {bigint?: boolean}): Promise<BigIntStats | Stats>;
abstract fstatSync(fd: number): Stats;
abstract fstatSync(fd: number, opts: {bigint: true}): BigIntStats;
abstract fstatSync(fd: number, opts?: {bigint: boolean}): BigIntStats | Stats;
abstract fstatSync(fd: number, opts?: {bigint?: boolean}): BigIntStats | Stats;

// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51d793492d4c2e372b01257668dcd3afc58d7352/types/node/v16/fs.d.ts#L1042-L1059
abstract lstatPromise(p: P): Promise<Stats>;
Expand Down Expand Up @@ -240,11 +242,11 @@ export abstract class FakeFS<P extends Path> {
abstract copyFilePromise(sourceP: P, destP: P, flags?: number): Promise<void>;
abstract copyFileSync(sourceP: P, destP: P, flags?: number): void;

abstract appendFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
abstract appendFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
abstract appendFilePromise(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): Promise<void>;
abstract appendFileSync(p: FSPath<P>, content: string | Uint8Array, opts?: WriteFileOptions): void;

abstract writeFilePromise(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
abstract writeFileSync(p: FSPath<P>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
abstract writeFilePromise(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): Promise<void>;
abstract writeFileSync(p: FSPath<P>, content: string | NodeJS.ArrayBufferView, opts?: WriteFileOptions): void;

abstract unlinkPromise(p: P): Promise<void>;
abstract unlinkSync(p: P): void;
Expand All @@ -255,11 +257,13 @@ export abstract class FakeFS<P extends Path> {
lutimesPromise?(p: P, atime: Date | string | number, mtime: Date | string | number): Promise<void>;
lutimesSync?(p: P, atime: Date | string | number, mtime: Date | string | number): void;

abstract readFilePromise(p: FSPath<P>, encoding: 'utf8'): Promise<string>;
abstract readFilePromise(p: FSPath<P>, encoding?: string): Promise<Buffer>;
abstract readFilePromise(p: FSPath<P>, encoding?: null): Promise<Buffer>;
abstract readFilePromise(p: FSPath<P>, encoding: BufferEncoding): Promise<string>;
abstract readFilePromise(p: FSPath<P>, encoding?: BufferEncoding | null): Promise<Buffer | string>;

abstract readFileSync(p: FSPath<P>, encoding: 'utf8'): string;
abstract readFileSync(p: FSPath<P>, encoding?: string): Buffer;
abstract readFileSync(p: FSPath<P>, encoding?: null): Buffer;
abstract readFileSync(p: FSPath<P>, encoding: BufferEncoding): string;
abstract readFileSync(p: FSPath<P>, encoding?: BufferEncoding | null): Buffer | string;

abstract readlinkPromise(p: P): Promise<P>;
abstract readlinkSync(p: P): P;
Expand Down
Loading

0 comments on commit a258467

Please sign in to comment.