Geocld / sparkee

A publish tool for monorepo,just like lerna but support pnpm.
3 stars 0 forks source link

bug: after fixing `pnpmWorkspace` load bug, it resolves wrong folders #18

Closed jrson83 closed 7 months ago

jrson83 commented 1 year ago

Description

Before the recent changes we used read-yaml-file:

try {
  const pnpmWorkspace = await readYamlFile<PnpmWorkspace>(fs.readFileSync(PNPM_WORKSPACE, 'utf8'))

  // ... never executed cause `read-yaml-file` expects a `path` not file content & throws error
} catch (err) {
  // always executed
  folders = await glob('packages/*')
}

I fixed this changing:

const pnpmWorkspace = await readYamlFile<PnpmWorkspace>(PNPM_WORKSPACE)
let wPackages = pnpmWorkspace.packages

// this code now is a new problem
wPackages = wPackages.map((wp) => {
  return `${wp.split('/')[0]}/*`
})

await Promise.all(
  wPackages.map(async (wp) => {
    const wFolders = await glob(wp)
      folders = folders.concat(wFolders)
  })
)

Now the problem is that pnpm-workspace.yaml can have multiple entries, with and without globs * and with and without excludes !.

packages:
  - 'docs'
  - 'another-single-package'
  - 'packages/*'
  - 'multiple-sub-packages/**/*'
  - '!**/__tests__/**'

After reading the yml, pnpmWorkspace is:

{
  packages: [
    'docs',
    'another-single-package',
    'packages/*',
    'multiple-sub-packages/**/*',
    '!**/__tests__/**'
  ]
}

After the map function folders is:

[
  'docs/node_modules',
  'docs/package.json',
  'docs/src',
  'docs/tsconfig.json',
  'packages/one',
  'packages/two',
  'multiple-sub-packages/another-subfolder',
  'multiple-sub-packages/subfolder'
]

Now the glob function fails and throws:

[Error: ENOENT: no such file or directory, open 'docs/node_modules/package.json'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: '/docs/node_modules/package.json'
}
Geocld commented 11 months ago

@jrson83 thanks, I got it. To fix this bug, Is it possible to detect there is a package.json file before we use glob?

jrson83 commented 11 months ago

@Geocld I think the fix is to remove the map function and instead use a parameter onlyDirectories or something similar for the glob function.

So it will search for as example packages/*.

Geocld commented 11 months ago

@jrson83 okey, i will try fix it in next version! you can also fix it If you have more smart idea :)

jrson83 commented 8 months ago

@Geocld it is all totally broken at the moment and ruined my changelog and npm release.

Geocld commented 7 months ago

@jrson83 sorry I am too busy recently, this issue had fixed in 1.4.0, If you still have any questions, please feel free to leave me a message.