Skip to content

Commit

Permalink
fix: Path does not end with the package name (#8560)
Browse files Browse the repository at this point in the history
fix #8558

The @isaacs/cliui package depends on string-width-cjs@4.2.3, but the
package that's actually downloaded is string-width@4.2.3. The name in
the path doesn't match the original name, which is causing an error.
Fix solution: Truncate based on scope depth, not by name.

```
"string-width-cjs": {
          "from": "string-width",
          "version": "4.2.3",
          "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
          "description": "Get the visual width of a string - the number of columns required to display it",
          "license": "MIT",
          "author": {
            "name": "Sindre Sorhus",
            "email": "sindresorhus@gmail.com",
            "url": "sindresorhus.com"
          },
          "homepage": "https://github.com/sindresorhus/string-width#readme",
          "repository": "git+https://github.com/sindresorhus/string-width.git",
          "path": "/Users/beyondkmp/Code/deepFocus/node_modules/.pnpm/string-width@4.2.3/node_modules/string-width",
}                 
                             
```

---------

Co-authored-by: beyondkmp <beyondkmkp@gmail.com>
  • Loading branch information
beyondkmp and beyondkmp authored Oct 6, 2024
1 parent cd1e3b0 commit 4ff778e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-apricots-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: Path does not end with the package name
10 changes: 5 additions & 5 deletions packages/app-builder-lib/src/util/appFileCopier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ export async function computeNodeModuleFileSets(platformPackager: PlatformPackag
let index = 0
const NODE_MODULES = "node_modules"
const getRealSource = (name: string, source: string) => {
const normalizedName = name.split("/").join(path.sep)
if (!source.endsWith(normalizedName)) {
throw new Error("Path does not end with the package name")
}
let parentDir = path.dirname(source)

const scopeDepth = name.split("/").length
// get the parent dir of the package, input: /root/path/node_modules/@electron/remote, output: /root/path/node_modules
const parentDir = source.slice(0, -normalizedName.length - 1)
for (let i = 0; i < scopeDepth - 1; i++) {
parentDir = path.dirname(parentDir)
}

// for the local node modules which is not in node modules
if (!parentDir.endsWith(path.sep + NODE_MODULES)) {
Expand Down
4 changes: 3 additions & 1 deletion test/src/globTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ test.ifAll.ifDevOrLinuxCi("ignore node_modules", () => {
//noinspection SpellCheckingInspection
data.dependencies = {
"ci-info": "2.0.0",
"@electron/remote": "2.1.2",
"@types/node": "14.17.0",
// this contains string-width-cjs 4.2.3
"@isaacs/cliui":"8.0.2"
}
}),
packed: context => {
Expand Down

0 comments on commit 4ff778e

Please sign in to comment.