Skip to content

Commit 0edddbe

Browse files
GauBenarcanis
andauthored
fix(6706): pack creates sub-directories (yarnpkg#6707)
## What's the problem this PR addresses? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> It creates missing sub-directories instead of crashing; closes yarnpkg#6706. ## How did you fix it? <!-- A detailed description of your implementation. --> Added `await xfs.mkdirpPromise(ppath.dirname(target))` before packing ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Maël Nison <nison.mael@gmail.com>
1 parent 4d5ddda commit 0edddbe

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

.yarn/versions/c530da1b.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-pack": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-npm"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-patch"
16+
- "@yarnpkg/plugin-pnp"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/commands/pack.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,21 @@ describe(`Commands`, () => {
822822
}),
823823
);
824824

825+
test(
826+
`it should create missing directories when using \`--out\``,
827+
makeTemporaryEnv({
828+
name: `@scope/test`,
829+
version: `0.0.1`,
830+
}, async ({path, run, source}) => {
831+
await xfs.mkdirpPromise(path);
832+
833+
await run(`install`);
834+
835+
await run(`pack`, `--out`, `subdir/my-package.tgz`, {cwd: path});
836+
expect(xfs.existsSync(`${path}/subdir/my-package.tgz`)).toEqual(true);
837+
}),
838+
);
839+
825840
test(
826841
`it should not include any extra files when the "files" field is empty`,
827842
makeTemporaryEnv({

packages/plugin-pack/sources/commands/pack.ts

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export default class PackCommand extends BaseCommand {
9090

9191
if (!this.dryRun) {
9292
const pack = await packUtils.genPackStream(workspace, files);
93+
94+
await xfs.mkdirPromise(ppath.dirname(target), {recursive: true});
9395
const write = xfs.createWriteStream(target);
9496

9597
pack.pipe(write);

0 commit comments

Comments
 (0)