Skip to content

Commit b753ce9

Browse files
authored
Fixes publishing archives (#6905)
## What's the problem this PR addresses? We shipped a change that had the unfortunate effect of breaking publishing packages. It somehow didn't break our tests, which is something we'll have to investigate. In the meantime I want to fix it quick. ## How did you fix it? Revert the probable cause; it wasn't a very important change, and I found another to achieve what we intended to do. ## 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.
1 parent 2eb9830 commit b753ce9

File tree

2 files changed

+67
-44
lines changed

2 files changed

+67
-44
lines changed

.yarn/versions/65c28eb2.yml

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

packages/plugin-pack/sources/packUtils.ts

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,63 +79,61 @@ export async function genPackStream(workspace: Workspace, files?: Array<Portable
7979

8080
const pack = tar.pack();
8181

82-
// I don't recall why this was necessary, but probably something to do
83-
// with how Node.js streams process their events vs their drains.
84-
await new Promise(process.nextTick);
82+
process.nextTick(async () => {
83+
for (const fileRequest of files!) {
84+
const file = ppath.normalize(fileRequest);
8585

86-
for (const fileRequest of files!) {
87-
const file = ppath.normalize(fileRequest);
86+
const source = ppath.resolve(workspace.cwd, file);
87+
const dest = ppath.join(`package`, file);
8888

89-
const source = ppath.resolve(workspace.cwd, file);
90-
const dest = ppath.join(`package`, file);
89+
const stat = await xfs.lstatPromise(source);
9190

92-
const stat = await xfs.lstatPromise(source);
91+
const opts = {
92+
name: dest,
93+
mtime: new Date(constants.SAFE_TIME * 1000),
94+
};
9395

94-
const opts = {
95-
name: dest,
96-
mtime: new Date(constants.SAFE_TIME * 1000),
97-
};
96+
const mode = executableFiles.has(file)
97+
? 0o755
98+
: 0o644;
9899

99-
const mode = executableFiles.has(file)
100-
? 0o755
101-
: 0o644;
100+
let resolveFn: Function;
101+
let rejectFn: Function;
102102

103-
let resolveFn: Function;
104-
let rejectFn: Function;
103+
const awaitTarget = new Promise((resolve, reject) => {
104+
resolveFn = resolve;
105+
rejectFn = reject;
106+
});
105107

106-
const awaitTarget = new Promise((resolve, reject) => {
107-
resolveFn = resolve;
108-
rejectFn = reject;
109-
});
108+
const cb = (error: any) => {
109+
if (error) {
110+
rejectFn(error);
111+
} else {
112+
resolveFn();
113+
}
114+
};
110115

111-
const cb = (error: any) => {
112-
if (error) {
113-
rejectFn(error);
114-
} else {
115-
resolveFn();
116-
}
117-
};
116+
if (stat.isFile()) {
117+
let content: Buffer;
118118

119-
if (stat.isFile()) {
120-
let content: Buffer;
119+
// The root package.json supports replacement fields in publishConfig
120+
if (file === `package.json`)
121+
content = Buffer.from(JSON.stringify(await genPackageManifest(workspace), null, 2));
122+
else
123+
content = await xfs.readFilePromise(source);
121124

122-
// The root package.json supports replacement fields in publishConfig
123-
if (file === `package.json`)
124-
content = Buffer.from(JSON.stringify(await genPackageManifest(workspace), null, 2));
125-
else
126-
content = await xfs.readFilePromise(source);
125+
pack.entry({...opts, mode, type: `file`}, content, cb);
126+
} else if (stat.isSymbolicLink()) {
127+
pack.entry({...opts, mode, type: `symlink`, linkname: await xfs.readlinkPromise(source)}, cb);
128+
} else {
129+
cb(new Error(`Unsupported file type ${stat.mode} for ${npath.fromPortablePath(file)}`));
130+
}
127131

128-
pack.entry({...opts, mode, type: `file`}, content, cb);
129-
} else if (stat.isSymbolicLink()) {
130-
pack.entry({...opts, mode, type: `symlink`, linkname: await xfs.readlinkPromise(source)}, cb);
131-
} else {
132-
cb(new Error(`Unsupported file type ${stat.mode} for ${npath.fromPortablePath(file)}`));
132+
await awaitTarget;
133133
}
134134

135-
await awaitTarget;
136-
}
137-
138-
pack.finalize();
135+
pack.finalize();
136+
});
139137

140138
const tgz = createGzip();
141139
pack.pipe(tgz);

0 commit comments

Comments
 (0)