Skip to content

feat(config): normalise windows workspace paths #126

Open
@boeckMt

Description

@boeckMt

Description

Get package json files patterns - paths not normalized with older npm version

Version of syncpack: 9.8.4
OS: Windows
Package Manager: NPM


I have the following root package.json in a monorepo

{
  "name": "ng-workspace-test",
  "workspaces": [
    "projects\\apps\\test-app1",
    "projects\\apps\\test-app2",
    "projects\\libs\\lib1",
    "projects\\libs\\lib2",
    "projects\\libs\\lib3"
  ],
  ...
  "syncpack": {
    "source": [
      "projects/*/package.json"
    ]
  }
}

workspaces are added through the commands (It was with an older npm version 7.24.2)

  • npm init -w ./projects/app/<name> or
  • npm init -w ./projects/libs/<name>

this added the \\ slashes somehow, this is reproducible with npm i [email protected] -g

With a more current npm version 9.5.1 this is not happening anymore, than its like

...
 "workspaces": [
    "projects/apps/test-app1",
    ...
  ],
---

With the old workspaces config patterns are not matched and therefore no package.json files are found.

E.g. in get-file-paths.ts, then the pattern looks something like projects\libs\lib1/package.json

const ERR_GLOB_MISS = `No package.json files match pattern "${pattern}"`;

Suggested Solution

replace slashes in patterns pattern = pattern.replace(/\\/g, '/');

Note Glob patterns should always use / as a path separator, even on Windows systems...
https://github.com/isaacs/node-glob

syncpack/src/lib/disk.ts

Lines 39 to 41 in 2f1ffba

globSync(pattern: string): string[] {
verbose('globSync(', pattern, ')');
return globSync(pattern, {

Workaround

For anyone using an older npm workspace configuration (maybe only on windows), replace the \\ slashes with / fixes the Issue.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions