Only use npm_package_json when we know it's correct#962
Only use npm_package_json when we know it's correct#962appsforartists wants to merge 6 commits intogoogle:mainfrom
Conversation
`.yarn/releases/yarn-4.0.1.cjs` is where it would typically be installed. See https://github.com/material-foundation/trapeze/tree/develop/third_party/.yarn/releases.
src/cli-options.ts
Outdated
| // yarn sets it to the package.json at the project root, even if we're in | ||
| // another package. |
There was a problem hiding this comment.
To be clear, that's only when -T is specified. To quote the documentation, -T "checks the root workspace for scripts and/or binaries instead of the current one", hence why npm_package_json becomes the root one.
There was a problem hiding this comment.
If I recall correctly, the -T got added because yarn run wireit wasn't finding the root wireit when in a workspace.
So from the POV of wireit, it will always been the root package (since wireit is meant to be a devDependency of the whole project).
There was a problem hiding this comment.
If I recall correctly, the -T got added because yarn run wireit wasn't finding the root wireit when in a workspace.
So from the POV of wireit, it will always been the root package (since wireit is meant to be a devDependency of the whole project).
There was a problem hiding this comment.
Right, I just don't want someone external reading this comment to think "Wait what; Yarn is broken if it doesn't run run properly" or something of the kind 🙂
cef14f5 to
80717ee
Compare
|
Just saw My last change was just updating the comment after arcanis's note - is there a way to check that this PR was fine before that push? |
|
Yeah, I think that test is flaky, re-running it. |
rictic
left a comment
There was a problem hiding this comment.
This looks good, but please add a test that fails without it. I bet this will be pretty straightforward, check out src/test/basic.test.ts
|
Thanks @rictic! That was the intent of #963, but I don't know the testing harness well enough to make progress there. In the mean time, I can add a variant of test(
'finds package directory without npm_package_json',
rigTest(async ({rig}) => {
// This confirms that we can walk up the filesystem to find the nearest
// package.json when the npm_package_json environment variable isn't set.
// This variable isn't set by yarn, pnpm, and older versions of npm.
const cmdA = await rig.newCommand();
await rig.write({
'package.json': {
scripts: {
a: 'wireit',
},
wireit: {
a: {
command: cmdA.command,
},
},
},
});
await rig.mkdir('foo/bar/baz');
const exec = rig.exec(
IS_WINDOWS
? '..\\..\\..\\node_modules\\.bin\\wireit.cmd'
: '../../../node_modules/.bin/wireit',
{
cwd: 'foo/bar/baz',
env: {
npm_lifecycle_event: 'a',
},
},
);
(await cmdA.nextInvocation()).exit(0);
const res = await exec.exit;
assert.equal(res.code, 0);
assert.equal(cmdA.numInvocations, 1);
}),
);to |
80717ee to
d2c0926
Compare
|
@rictic @aomarks I took a stab at adding a test for it, adapting the reproduction I left in yarnpkg/berry#5925. I couldn't get the test to run correctly. If you try to run Therefore, I have the rig manually writing a So something about the test environment seems to prevent I'm not sure what to do. #962 and #963 have been open for months, trying to get a relatively minor bugfix landed. The truth is that I don't have the time or the knowledge of the codebase to make progress, so I end up stealing a day here or a day there to try to land these PRs. I don't know when I'll next have space to work on these, but I'd rather not have a bugfix languishing for months waiting for tests I can't write, and I feel guilty when my dayjob project slips because I'm stuck on an open-source PR. Do either of you have tips on why |
IDK whether you'd prefer to skip
npm_package_jsoninyarn, or to only use it innpm.yarnrunswireitfrom the package root, which meansnpm_package_jsonwill always be/package.json.Fixes #960