Skip to content

Commit

Permalink
fix: only resolve package.json files for mono packages pattern (#330)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
tjx666 and JounQin committed May 24, 2023
1 parent 0861d01 commit 52c7f39
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/gorgeous-seals-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pkgr/rollup": patch
"@pkgr/utils": patch
---

fix: only resolve package.json files for mono packages pattern - close #329
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"private": true,
"workspaces": [
"packages/*"
"packages/**"
],
"packageManager": "yarn@1.22.19",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion packages/rollup/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,15 @@ ConfigOptions = {}): RollupOptions[] => {
monorepo === false
? [CWD]
: Array.isArray(monorepo)
? tryGlob(monorepo)
? tryGlob(
monorepo.map(pkg =>
pkg.endsWith('/package.json') ? pkg : `${pkg}/package.json`,
),
)
: monorepoPkgs

pkgs = pkgs.map(pkg => pkg.replace(/\/package\.json$/, ''))

if (monorepo == null && pkgs.length === 0) {
pkgs = [CWD]
}
Expand Down
9 changes: 7 additions & 2 deletions packages/utils/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ export const tryGlob = (
| {
absolute?: boolean
baseDir?: string
ignore?: [string]
} = {},
) => {
const { absolute = true, baseDir = CWD } =
typeof options === 'string' ? { baseDir: options } : options
const {
absolute = true,
baseDir = CWD,
ignore = ['**/node_modules/**'],
} = typeof options === 'string' ? { baseDir: options } : options
return paths.reduce<string[]>(
(acc, pkg) =>
[
Expand All @@ -81,6 +85,7 @@ export const tryGlob = (
? tryRequirePkg<typeof import('fast-glob')>('fast-glob')!.sync(pkg, {
absolute,
cwd: baseDir,
ignore,
onlyFiles: false,
})
: [tryFile(path.resolve(baseDir, pkg), true)]),
Expand Down
8 changes: 7 additions & 1 deletion packages/utils/src/monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ const pkgsPath = lernaConfig.packages ?? pkg.workspaces ?? []

export const isMonorepo = Array.isArray(pkgsPath) && pkgsPath.length > 0

export const monorepoPkgs = isMonorepo ? tryGlob(pkgsPath) : []
export const monorepoPkgs = isMonorepo
? tryGlob(
pkgsPath.map(pkg =>
pkg.endsWith('/package.json') ? pkg : `${pkg}/package.json`,
),
)
: []

0 comments on commit 52c7f39

Please sign in to comment.