Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .yarn/versions/ec8c3499.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
releases:
"@yarnpkg/cli": prerelease
"@yarnpkg/core": prerelease
"@yarnpkg/fslib": prerelease

declined:
- "@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-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/json-proxy"
- "@yarnpkg/pnp"
- "@yarnpkg/pnpify"
- "@yarnpkg/shell"
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/tgzUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function extractArchiveTo<T extends FakeFS<PortablePath>>(tgz: Buff
targetFs.mkdirpSync(ppath.dirname(mappedPath), {chmod: 0o755, utimes: [defaultTime, defaultTime]});

targetFs.symlinkSync(entry.linkpath, mappedPath);
targetFs.lutimesSync!(mappedPath, defaultTime, defaultTime);
targetFs.lutimesSync?.(mappedPath, defaultTime, defaultTime);
} break;
}
});
Expand Down
27 changes: 27 additions & 0 deletions packages/yarnpkg-fslib/sources/NodeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {CreateReadStreamOptions, CreateWriteStreamOptions} from './FakeFS';
import {Dirent, SymlinkType} from './FakeFS';
import {BasePortableFakeFS, WriteFileOptions} from './FakeFS';
import {MkdirOptions, WatchOptions, WatchCallback, Watcher} from './FakeFS';
import {ENOSYS} from './errors';
import {FSPath, PortablePath, Filename, npath} from './path';

export class NodeFS extends BasePortableFakeFS {
Expand All @@ -13,6 +14,12 @@ export class NodeFS extends BasePortableFakeFS {
super();

this.realFs = realFs;

// @ts-ignore
if (typeof this.realFs.lutimes !== `undefined`) {
this.lutimesPromise = this.lutimesPromiseImpl;
this.lutimesSync = this.lutimesSyncImpl;
}
}

getExtractHint() {
Expand Down Expand Up @@ -233,6 +240,26 @@ export class NodeFS extends BasePortableFakeFS {
this.realFs.utimesSync(npath.fromPortablePath(p), atime, mtime);
}

private async lutimesPromiseImpl(this: NodeFS, p: PortablePath, atime: Date | string | number, mtime: Date | string | number) {
// @ts-ignore: Not yet in DefinitelyTyped
const lutimes = this.realFs.lutimes;
if (typeof lutimes === `undefined`)
throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);

return await new Promise<void>((resolve, reject) => {
lutimes.call(this.realFs, npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject));
});
}

private lutimesSyncImpl(this: NodeFS, p: PortablePath, atime: Date | string | number, mtime: Date | string | number) {
// @ts-ignore: Not yet in DefinitelyTyped
const lutimesSync = this.realFs.lutimesSync;
if (typeof lutimesSync === `undefined`)
throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);

lutimesSync.call(this.realFs, npath.fromPortablePath(p), atime, mtime);
}

async mkdirPromise(p: PortablePath, opts?: MkdirOptions) {
return await new Promise<void>((resolve, reject) => {
this.realFs.mkdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
Expand Down
1 change: 0 additions & 1 deletion packages/yarnpkg-fslib/sources/algorithms/copyPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function copyPromise<P1 extends Path, P2 extends Path>(destinationF
: destinationFs.utimesPromise.bind(destinationFs);

for (const [p, atime, mtime] of lutimes) {
// await destinationFs.utimesPromise(p, atime, mtime);
await updateTime!(p, atime, mtime);
}
}
Expand Down
30 changes: 21 additions & 9 deletions packages/yarnpkg-fslib/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
`closeSync`,
`copyFileSync`,
`lstatSync`,
`lutimesSync`,
`mkdirSync`,
`openSync`,
`readSync`,
Expand All @@ -79,6 +80,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
`closePromise`,
`copyFilePromise`,
`lstatPromise`,
`lutimesPromise`,
`mkdirPromise`,
`openPromise`,
`readdirPromise`,
Expand All @@ -98,10 +100,8 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void

const setupFn = (target: any, name: string, replacement: any) => {
const orig = target[name];
if (typeof orig === `undefined`)
return;

target[name] = replacement;

if (typeof orig[promisify.custom] !== `undefined`) {
replacement[promisify.custom] = orig[promisify.custom];
}
Expand Down Expand Up @@ -142,28 +142,40 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
});

for (const fnName of ASYNC_IMPLEMENTATIONS) {
const fakeImpl: Function = (fakeFs as any)[fnName].bind(fakeFs);
const origName = fnName.replace(/Promise$/, ``);
if (typeof (patchedFs as any)[origName] === `undefined`)
continue;

const fakeImpl: Function = (fakeFs as any)[fnName];
if (typeof fakeImpl === `undefined`)
continue;

setupFn(patchedFs, origName, (...args: Array<any>) => {
const wrapper = (...args: Array<any>) => {
const hasCallback = typeof args[args.length - 1] === `function`;
const callback = hasCallback ? args.pop() : () => {};

process.nextTick(() => {
fakeImpl(...args).then((result: any) => {
fakeImpl.apply(fakeFs, args).then((result: any) => {
callback(null, result);
}, (error: Error) => {
callback(error);
});
});
});
};

setupFn(patchedFs, origName, wrapper);
}

for (const fnName of SYNC_IMPLEMENTATIONS) {
const fakeImpl: Function = (fakeFs as any)[fnName].bind(fakeFs);
const origName = fnName;
if (typeof (patchedFs as any)[origName] === `undefined`)
continue;

const fakeImpl: Function = (fakeFs as any)[fnName];
if (typeof fakeImpl === `undefined`)
continue;

setupFn(patchedFs, origName, fakeImpl);
setupFn(patchedFs, origName, fakeImpl.bind(fakeFs));
}

patchedFs.realpathSync.native = patchedFs.realpathSync;
Expand Down