Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: convert chmod calls to mode arguments #3254

Merged
merged 3 commits into from
Aug 12, 2021
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
61 changes: 45 additions & 16 deletions .pnp.cjs

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

38 changes: 38 additions & 0 deletions .yarn/versions/390a50ae.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/fslib": minor
"@yarnpkg/plugin-essentials": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/pnp": patch
"@yarnpkg/sdks": patch

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@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-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/json-proxy"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/shell"
3 changes: 1 addition & 2 deletions packages/plugin-essentials/sources/commands/set/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ export async function setVersion(configuration: Configuration, bundleVersion: st
await xfs.removePromise(ppath.dirname(absolutePath));
await xfs.mkdirPromise(ppath.dirname(absolutePath), {recursive: true});

await xfs.writeFilePromise(absolutePath, bundleBuffer);
await xfs.chmodPromise(absolutePath, 0o755);
await xfs.writeFilePromise(absolutePath, bundleBuffer, {mode: 0o755});

if (updateConfig) {
await Configuration.updateConfiguration(projectCwd, {
Expand Down
18 changes: 12 additions & 6 deletions packages/plugin-pnp/sources/PnpLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,25 @@ export class PnpInstaller implements Installer {
if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
const loaderFile = generateInlinedScript(pnpSettings);

await xfs.changeFilePromise(pnpPath.cjs, loaderFile, {automaticNewlines: true});
await xfs.chmodPromise(pnpPath.cjs, 0o755);
await xfs.changeFilePromise(pnpPath.cjs, loaderFile, {
automaticNewlines: true,
mode: 0o755,
});

await xfs.removePromise(pnpDataPath);
} else {
const dataLocation = ppath.relative(ppath.dirname(pnpPath.cjs), pnpDataPath);
const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});

await xfs.changeFilePromise(pnpPath.cjs, loaderFile, {automaticNewlines: true});
await xfs.chmodPromise(pnpPath.cjs, 0o755);
await xfs.changeFilePromise(pnpPath.cjs, loaderFile, {
automaticNewlines: true,
mode: 0o755,
});

await xfs.changeFilePromise(pnpDataPath, dataFile, {automaticNewlines: true});
await xfs.chmodPromise(pnpDataPath, 0o644);
await xfs.changeFilePromise(pnpDataPath, dataFile, {
automaticNewlines: true,
mode: 0o644,
});
}

const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
Expand Down
5 changes: 3 additions & 2 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ async function makePathWrapper(location: PortablePath, name: Filename, argv0: Na
await xfs.writeFilePromise(ppath.format({dir: location, name, ext: `.cmd`}), cmdScript);
}

await xfs.writeFilePromise(ppath.join(location, name), `#!/bin/sh\nexec "${argv0}" ${args.map(arg => `'${arg.replace(/'/g, `'"'"'`)}'`).join(` `)} "$@"\n`);
await xfs.chmodPromise(ppath.join(location, name), 0o755);
await xfs.writeFilePromise(ppath.join(location, name), `#!/bin/sh\nexec "${argv0}" ${args.map(arg => `'${arg.replace(/'/g, `'"'"'`)}'`).join(` `)} "$@"\n`, {
mode: 0o755,
});
}

async function detectPackageManager(location: PortablePath): Promise<PackageManagerSelection | null> {
Expand Down
6 changes: 2 additions & 4 deletions packages/yarnpkg-core/sources/tgzUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ export async function extractArchiveTo<T extends FakeFS<PortablePath>>(tgz: Buff
case `Directory`: {
targetFs.mkdirpSync(ppath.dirname(mappedPath), {chmod: 0o755, utimes: [safeTime, safeTime]});

targetFs.mkdirSync(mappedPath);
targetFs.chmodSync(mappedPath, mode);
targetFs.mkdirSync(mappedPath, {mode});
targetFs.utimesSync(mappedPath, safeTime, safeTime);
} break;

case `OldFile`:
case `File`: {
targetFs.mkdirpSync(ppath.dirname(mappedPath), {chmod: 0o755, utimes: [safeTime, safeTime]});

targetFs.writeFileSync(mappedPath, await miscUtils.bufferStream(entry as unknown as Readable));
targetFs.chmodSync(mappedPath, mode);
targetFs.writeFileSync(mappedPath, await miscUtils.bufferStream(entry as unknown as Readable), {mode});
targetFs.utimesSync(mappedPath, safeTime, safeTime);
} break;

Expand Down
21 changes: 11 additions & 10 deletions packages/yarnpkg-fslib/sources/FakeFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type WatchFileOptions = Partial<{

export type ChangeFileOptions = Partial<{
automaticNewlines: boolean,
mode: number,
}>;

export type WatchCallback = (
Expand Down Expand Up @@ -452,13 +453,13 @@ export abstract class FakeFS<P extends Path> {
async changeFilePromise(p: P, content: string, opts?: ChangeFileOptions): Promise<void>;
async changeFilePromise(p: P, content: Buffer | string, opts: ChangeFileOptions = {}) {
if (Buffer.isBuffer(content)) {
return this.changeFileBufferPromise(p, content);
return this.changeFileBufferPromise(p, content, opts);
} else {
return this.changeFileTextPromise(p, content, opts);
}
}

private async changeFileBufferPromise(p: P, content: Buffer) {
private async changeFileBufferPromise(p: P, content: Buffer, {mode}: ChangeFileOptions = {}) {
let current = Buffer.alloc(0);
try {
current = await this.readFilePromise(p);
Expand All @@ -469,10 +470,10 @@ export abstract class FakeFS<P extends Path> {
if (Buffer.compare(current, content) === 0)
return;

await this.writeFilePromise(p, content);
await this.writeFilePromise(p, content, {mode});
}

private async changeFileTextPromise(p: P, content: string, {automaticNewlines}: ChangeFileOptions = {}) {
private async changeFileTextPromise(p: P, content: string, {automaticNewlines, mode}: ChangeFileOptions = {}) {
let current = ``;
try {
current = await this.readFilePromise(p, `utf8`);
Expand All @@ -487,20 +488,20 @@ export abstract class FakeFS<P extends Path> {
if (current === normalizedContent)
return;

await this.writeFilePromise(p, normalizedContent);
await this.writeFilePromise(p, normalizedContent, {mode});
}

changeFileSync(p: P, content: Buffer): void;
changeFileSync(p: P, content: string, opts?: ChangeFileOptions): void;
changeFileSync(p: P, content: Buffer | string, opts: ChangeFileOptions = {}) {
if (Buffer.isBuffer(content)) {
return this.changeFileBufferSync(p, content);
return this.changeFileBufferSync(p, content, opts);
} else {
return this.changeFileTextSync(p, content, opts);
}
}

private changeFileBufferSync(p: P, content: Buffer) {
private changeFileBufferSync(p: P, content: Buffer, {mode}: ChangeFileOptions = {}) {
let current = Buffer.alloc(0);
try {
current = this.readFileSync(p);
Expand All @@ -511,10 +512,10 @@ export abstract class FakeFS<P extends Path> {
if (Buffer.compare(current, content) === 0)
return;

this.writeFileSync(p, content);
this.writeFileSync(p, content, {mode});
}

private changeFileTextSync(p: P, content: string, {automaticNewlines = false}: ChangeFileOptions = {}) {
private changeFileTextSync(p: P, content: string, {automaticNewlines = false, mode}: ChangeFileOptions = {}) {
let current = ``;
try {
current = this.readFileSync(p, `utf8`);
Expand All @@ -529,7 +530,7 @@ export abstract class FakeFS<P extends Path> {
if (current === normalizedContent)
return;

this.writeFileSync(p, normalizedContent);
this.writeFileSync(p, normalizedContent, {mode});
}

async movePromise(fromP: P, toP: P) {
Expand Down
Loading