-
Notifications
You must be signed in to change notification settings - Fork 44
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
Refactor package manager detection, add support for detecting pnpm
#876
Conversation
🦋 Changeset detectedLatest commit: 09eedb2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -14,9 +14,7 @@ try { | |||
const globs = ['node_modules/@seek/*/package.json']; | |||
const cwd = skuCwd(); | |||
|
|||
const { rootDir, tool } = findRootSync(cwd); | |||
|
|||
if (tool === 'pnpm') { |
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.
tool
is an object, so this was always false
.
*/ | ||
const findPackageScript = (scriptContents) => { | ||
let pkg; | ||
try { | ||
pkg = requireFromCwd('package.json'); | ||
// CWD should be the root of the package | ||
pkg = requireFromCwd('./package.json'); | ||
} catch (err) { | ||
pkg = { scripts: {} }; |
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.
Resolving package.json
from cwd (package root) would always fail, so the catch
clause was executing every time, so scripts from package.json
were never suggested.
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.
Good catch 🤭
|
||
module.exports = () => { | ||
try { | ||
execSync('yarnpkg --version', { stdio: 'ignore' }); |
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.
yarnpkg
is an alias present on debian, but potentially only if the cmdtest
package is also installed. Ubuntu (debian) use at SEEK is basically non-existant, so detecting yarn
instead of yarnpkg
may actually be a bugfix that will make yarn detection work correctly.
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.
Somehow, on my machine this command returns a version number, but in my terminal yarnpkg
isn't a valid command.
Tests are failing because multiple storybooks are running simultaneously. There was only one fixture that used storybook, until this PR. One fixture has a This issue only happens if the two test suites happen to run at the same time, which seems deterministically based on something, though I don't know exactly what. It would be nice if jest had a way to explicitly disallow a test suite to run in parallel. We could make a separate folder to isolate the test, but that's not great. I think the best option would be to stop doing all our storybook config shenanigans and just emit files to a This would be beneficial for a few reasons:
This concludes my TED talk. EDIT: Addressed in #878. |
Depends on #878. |
*/ | ||
const findPackageScript = (scriptContents) => { | ||
let pkg; | ||
try { | ||
pkg = requireFromCwd('package.json'); | ||
// CWD should be the root of the package | ||
pkg = requireFromCwd('./package.json'); | ||
} catch (err) { | ||
pkg = { scripts: {} }; |
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.
Good catch 🤭
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.
A few comments related to @antfu/ni
, but looks good otherwise 👍
Co-authored-by: Remus Mate <3297808+mrm007@users.noreply.github.com>
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.
Nice work 👍
const { packageManager, isYarn } = require('../lib/packageManager'); | ||
const { getCommand } = require('@antfu/ni'); |
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.
I was thinking it would be ideal to absorb @antfu/ni
into lib/packageManager
so there's only one way to interface with the package manager. But we can iterate on that later.
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.
Good idea. I've got a follow up PR that will use getCommand
a bit more, I can refactor it there.
The primary change in this PR is refactoring how we detect package managers. This code is contained within the new
packageManager
lib, leveraging@manypkg/find-root
.During this refactor I found a few bugs too. They're detailed within the changesets, but I'll add comments explaining them a bit too.
There will be a followup PR after this one that will add
pnpm
support forsku init
, likely via CLI flag. That change will be released alongside the changes in this PR.