Skip to content

Commit

Permalink
fix(fslib): fix copyPromise mkdir overwrite (#1674)
Browse files Browse the repository at this point in the history
* fix(fslib): fix copyPromise mkdir overwrite

* refactor: use pathUtils.dirname

* chore: update pnp hook
  • Loading branch information
paul-soporan committed Aug 6, 2020
1 parent 405af59 commit 5e237a3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration-workflow.yml
Expand Up @@ -66,9 +66,9 @@ jobs:

- name: 'Check that the pluginCommands file is consistent with a fresh build (fix w/ "yarn build:plugin-commands")'
run: |
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- packages/plugin-essentials/sources/pluginCommands.ts 'packages/*/sources/commands/**/*' | wc -l) -gt 0 ]]; then
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- packages/yarnpkg-cli/sources/pluginCommands.ts 'packages/*/sources/commands/**/*' | wc -l) -gt 0 ]]; then
node ./scripts/run-yarn.js build:plugin-commands
[[ $(git diff --name-only packages/plugin-essentials/sources/pluginCommands.ts | wc -l) -eq 0 ]]
[[ $(git diff --name-only packages/yarnpkg-cli/sources/pluginCommands.ts | wc -l) -eq 0 ]]
fi
shell: bash
if: |
Expand Down
2 changes: 1 addition & 1 deletion .pnp.js

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

35 changes: 35 additions & 0 deletions .yarn/versions/0358d71f.yml
@@ -0,0 +1,35 @@
releases:
"@yarnpkg/cli": prerelease
"@yarnpkg/core": patch
"@yarnpkg/fslib": patch
"@yarnpkg/pnp": patch

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/pnpify"
- "@yarnpkg/shell"
21 changes: 12 additions & 9 deletions .yarnrc.yml
Expand Up @@ -3,12 +3,13 @@ changesetIgnorePatterns:

enableGlobalCache: false

immutablePatterns:
- .pnp.*

initScope: yarnpkg

npmPublishAccess: public

telemetryUserId: yarnpkg/berry

packageExtensions:
"@babel/parser@*":
dependencies:
Expand All @@ -21,7 +22,7 @@ packageExtensions:
"@babel/core": "*"
"@webpack-cli/package-utils@*":
dependencies:
"cross-spawn": "*"
cross-spawn: "*"
fork-ts-checker-webpack-plugin@*:
peerDependencies:
typescript: "*"
Expand Down Expand Up @@ -62,6 +63,9 @@ packageExtensions:
json-ref-lite@*:
dependencies:
sync-request: "*"
monaco-editor-webpack-plugin@*:
dependencies:
webpack: ^4.5.0
rc-animate@*:
peerDependencies:
react: "*"
Expand All @@ -73,6 +77,9 @@ packageExtensions:
peerDependenciesMeta:
algoliasearch:
optional: true
react-instantsearch-dom@*:
dependencies:
react-fast-compare: "*"
typedoc@*:
peerDependenciesMeta:
"@strictsoftware/typedoc-plugin-monorepo":
Expand All @@ -81,13 +88,9 @@ packageExtensions:
optional: true
typedoc-plugin-yarn:
optional: true
monaco-editor-webpack-plugin@*:
dependencies:
"webpack": "^4.5.0"
react-instantsearch-dom@*:
dependencies:
react-fast-compare: "*"

preferInteractive: true

telemetryUserId: yarnpkg/berry

yarnPath: scripts/run-yarn.js
2 changes: 1 addition & 1 deletion packages/yarnpkg-fslib/sources/algorithms/copyPromise.ts
Expand Up @@ -25,7 +25,7 @@ export async function copyPromise<P1 extends Path, P2 extends Path>(destinationF
const prelayout: Operations = [];
const postlayout: Operations = [];

await destinationFs.mkdirPromise(destination, {recursive: true});
await destinationFs.mkdirPromise(destinationFs.pathUtils.dirname(destination), {recursive: true});

const updateTime = typeof destinationFs.lutimesPromise === `function`
? destinationFs.lutimesPromise.bind(destinationFs)
Expand Down
42 changes: 42 additions & 0 deletions packages/yarnpkg-fslib/tests/NodeFS.test.ts
@@ -0,0 +1,42 @@
import {NodeFS} from '../sources/NodeFS';
import {xfs, PortablePath} from '../sources';

const nodeFs = new NodeFS();

describe(`NodeFS`, () => {
describe(`copyPromise`, () => {
it(`should support copying files`, async () => {
const tmpdir = await xfs.mktempPromise();

const source = `${tmpdir}/foo` as PortablePath;
const destination = `${tmpdir}/bar` as PortablePath;

const sourceContent = `Hello World`;

await nodeFs.writeFilePromise(source, sourceContent);

await nodeFs.copyPromise(destination, source);

await expect(nodeFs.readFilePromise(source, `utf8`)).resolves.toStrictEqual(sourceContent);
await expect(nodeFs.readFilePromise(destination, `utf8`)).resolves.toStrictEqual(sourceContent);
});

it(`should support copying files (overwrite)`, async () => {
const tmpdir = await xfs.mktempPromise();

const source = `${tmpdir}/foo` as PortablePath;
const destination = `${tmpdir}/bar` as PortablePath;

const sourceContent = `Hello World`;
const destinationContent = `Goodbye World`;

await nodeFs.writeFilePromise(source, sourceContent);
await nodeFs.writeFilePromise(destination, destinationContent);

await nodeFs.copyPromise(destination, source);

await expect(nodeFs.readFilePromise(source, `utf8`)).resolves.toStrictEqual(sourceContent);
await expect(nodeFs.readFilePromise(destination, `utf8`)).resolves.toStrictEqual(sourceContent);
});
});
});
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

0 comments on commit 5e237a3

Please sign in to comment.