-
Notifications
You must be signed in to change notification settings - Fork 92
feat(npm): add support for glob pattern in npm workspaces and pnpm-workspaces.yaml #463
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
Conversation
| ---@param filepath string | ||
| ---@return table|nil | ||
| ---Parse pnpm-workspace.yaml and extract packages array, returning both inclusions and exclusions | ||
| local function parse_pnpm_workspace(filepath) |
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 function is pretty jank. Could we use treesitter's yaml parser instead, if it's installed? It still wouldn't cover the full yaml spec, but it would have fewer edge cases
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 point, I'll put the regex one as a fallback then if the yaml treesitter not installed. wdyt?
lua/overseer/template/npm.lua
Outdated
| for mgr, lockfiles in pairs(mgr_lockfiles) do | ||
| for _, lockfile in ipairs(lockfiles) do | ||
| if vim.uv.fs_stat(vim.fs.joinpath(package_dir, lockfile)) then | ||
| return { package = package_file, manager = mgr } | ||
| end | ||
| end | ||
| end |
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.
Could we pull this out into a helper function to reduce the nesting?
lua/overseer/template/npm.lua
Outdated
| end | ||
| end | ||
|
|
||
| if #inclusions > 0 or #exclusions > 0 then |
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.
We only care about #inclusions > 0, right? Also, we don't seem to use the exclusions anywhere. Is that intentional?
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.
Somewhat intentional, since pnpm is the only workspace manager that supports exclusion with !.
But we’re not using that part, so I’ll just return inclusions instead, which is all we need.
lua/overseer/template/npm.lua
Outdated
| local workspace_data = files.load_json_file(workspace_package_file) | ||
| if workspace_data and workspace_data.scripts then | ||
| for k in pairs(workspace_data.scripts) do | ||
| table.insert(ret, { | ||
| name = string.format("%s[workspace] %s (%s)", bin, k, workspace_data.name), | ||
| builder = function() | ||
| return { | ||
| cmd = { bin, "run", k }, | ||
| cwd = workspace_path, | ||
| } | ||
| end, | ||
| }) | ||
| end |
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 seems like it could be factored out into a function. It has a lot of similarities with the workspace loading in the previous block of code.
|
Thanks for the PR! |
This PR adds support for glob pattern in npm/bun/yarn workspaces and also pnpm workspaces.
This also fixes
pick_package_managerbehavior in monorepo scenario, currently it always falls back tonpmif it's insidepackages.Tested using:
Changes
package.jsonor not.Screenshot