Skip to content
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

feat(config): normalise windows workspace paths #126

Open
boeckMt opened this issue Apr 7, 2023 · 1 comment
Open

feat(config): normalise windows workspace paths #126

boeckMt opened this issue Apr 7, 2023 · 1 comment

Comments

@boeckMt
Copy link

boeckMt commented Apr 7, 2023

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 npm@7.24.2 -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.

@boeckMt boeckMt changed the title Get package json files patterns - paths not normalized with older npm version syncpack list-mismatches not finding package json files Apr 7, 2023
@JamieMason
Copy link
Owner

Thanks Mathias

@JamieMason JamieMason changed the title syncpack list-mismatches not finding package json files handling windows paths found in package manager configuration May 11, 2023
@JamieMason JamieMason changed the title handling windows paths found in package manager configuration feat(config): normalise windows workspace paths May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants