Skip to content

Conversation

@anasalqoyyum
Copy link
Contributor

@anasalqoyyum anasalqoyyum commented Nov 18, 2025

This PR adds support for glob pattern in npm/bun/yarn workspaces and also pnpm workspaces.

This also fixes pick_package_manager behavior in monorepo scenario, currently it always falls back to npm if it's inside packages.

Tested using:

Changes

  1. Improve package manager detection by determining whether the lockfile is located alongside the package.json or not.
  2. Added glob pattern support for npm workspaces.
  3. Added support for pnpm workspaces (still uses manual parsing).
  4. Show package name in npm template task (Closes feature request: show package name in npm template tasks #436)

Screenshot

kysely (pnpm) bun-workspaces (npm)
image image

@github-actions github-actions bot requested a review from stevearc November 18, 2025 13:09
---@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)
Copy link
Owner

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

Copy link
Contributor Author

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?

Comment on lines 47 to 53
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
Copy link
Owner

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?

end
end

if #inclusions > 0 or #exclusions > 0 then
Copy link
Owner

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?

Copy link
Contributor Author

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.

Comment on lines 207 to 219
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
Copy link
Owner

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.

@github-actions github-actions bot requested a review from stevearc December 1, 2025 19:51
@stevearc
Copy link
Owner

Thanks for the PR!

@stevearc stevearc merged commit 42d15cd into stevearc:master Dec 20, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: show package name in npm template tasks

2 participants