-
Notifications
You must be signed in to change notification settings - Fork 107
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
Only use npm_package_json when we know it's correct #962
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_json
inyarn
, or to only use it innpm
.yarn
runswireit
from the package root, which meansnpm_package_json
will always be/package.json
.Fixes #960