diff --git a/.changeset/five-badgers-greet.md b/.changeset/five-badgers-greet.md new file mode 100644 index 0000000..a97934b --- /dev/null +++ b/.changeset/five-badgers-greet.md @@ -0,0 +1,5 @@ +--- +"app-builder-bin": patch +--- + +fix: pnpm install error for node module collector (https://github.com/electron-userland/electron-builder/issues/8519) diff --git a/Makefile b/Makefile index ccf63d6..f59716d 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ test: cd pkg/node-modules/tar-demo/ && npm install cd pkg/node-modules/yarn-demo/ && yarn cd pkg/node-modules/parse-demo/ && yarn + cd pkg/node-modules/es5-demo/ && pnpm install go test -v ./pkg/... assets: diff --git a/pkg/node-modules/es5-demo/package.json b/pkg/node-modules/es5-demo/package.json new file mode 100644 index 0000000..9c579bd --- /dev/null +++ b/pkg/node-modules/es5-demo/package.json @@ -0,0 +1,15 @@ +{ + "name": "pnpm-demo", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "es5-ext": "0.10.53" + } +} diff --git a/pkg/node-modules/es5-demo/pnpm-lock.yaml b/pkg/node-modules/es5-demo/pnpm-lock.yaml new file mode 100644 index 0000000..9441729 --- /dev/null +++ b/pkg/node-modules/es5-demo/pnpm-lock.yaml @@ -0,0 +1,105 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + es5-ext: + specifier: 0.10.53 + version: 0.10.53 + +packages: + + d@1.0.2: + resolution: {integrity: sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==} + engines: {node: '>=0.12'} + + es5-ext@0.10.53: + resolution: {integrity: sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==} + + es5-ext@0.10.64: + resolution: {integrity: sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==} + engines: {node: '>=0.10'} + + es6-iterator@2.0.3: + resolution: {integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==} + + es6-symbol@3.1.4: + resolution: {integrity: sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==} + engines: {node: '>=0.12'} + + esniff@2.0.1: + resolution: {integrity: sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==} + engines: {node: '>=0.10'} + + event-emitter@0.3.5: + resolution: {integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==} + + ext@1.7.0: + resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==} + + next-tick@1.0.0: + resolution: {integrity: sha512-mc/caHeUcdjnC/boPWJefDr4KUIWQNv+tlnFnJd38QMou86QtxQzBJfxgGRzvx8jazYRqrVlaHarfO72uNxPOg==} + + next-tick@1.1.0: + resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} + + type@2.7.3: + resolution: {integrity: sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==} + +snapshots: + + d@1.0.2: + dependencies: + es5-ext: 0.10.64 + type: 2.7.3 + + es5-ext@0.10.53: + dependencies: + es6-iterator: 2.0.3 + es6-symbol: 3.1.4 + next-tick: 1.0.0 + + es5-ext@0.10.64: + dependencies: + es6-iterator: 2.0.3 + es6-symbol: 3.1.4 + esniff: 2.0.1 + next-tick: 1.1.0 + + es6-iterator@2.0.3: + dependencies: + d: 1.0.2 + es5-ext: 0.10.53 + es6-symbol: 3.1.4 + + es6-symbol@3.1.4: + dependencies: + d: 1.0.2 + ext: 1.7.0 + + esniff@2.0.1: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + event-emitter: 0.3.5 + type: 2.7.3 + + event-emitter@0.3.5: + dependencies: + d: 1.0.2 + es5-ext: 0.10.53 + + ext@1.7.0: + dependencies: + type: 2.7.3 + + next-tick@1.0.0: {} + + next-tick@1.1.0: {} + + type@2.7.3: {} diff --git a/pkg/node-modules/nodeModuleCollector.go b/pkg/node-modules/nodeModuleCollector.go index 21cc108..e912901 100644 --- a/pkg/node-modules/nodeModuleCollector.go +++ b/pkg/node-modules/nodeModuleCollector.go @@ -36,6 +36,7 @@ type Collector struct { excludedDependencies map[string]bool allDependencies []*Dependency + allDependenciesMap map[string]*Dependency NodeModuleDirToDependencyMap map[string]*map[string]*Dependency `json:"nodeModuleDirToDependencyMap"` @@ -45,7 +46,13 @@ type Collector struct { func (t *Collector) readDependencyTree(dependency *Dependency) error { if t.rootDependency == nil { t.rootDependency = dependency + t.allDependenciesMap = make(map[string]*Dependency) } else { + key := dependency.alias + dependency.Version + dependency.dir + if _, ok := t.allDependenciesMap[key]; ok { + return nil + } + t.allDependenciesMap[key] = dependency t.allDependencies = append(t.allDependencies, dependency) } @@ -97,43 +104,57 @@ func (t *Collector) readDependencyTree(dependency *Dependency) error { } func (t *Collector) writeToParentConflicDependency(d *Dependency) { - p := d.parent - last := d - for p != t.rootDependency { - if p.conflictDependency != nil { - if c, ok := p.conflictDependency[d.Name]; ok { - if c.Version == d.Version { - return - } - break + for p := d.parent; p != t.rootDependency; p = p.parent { + if strings.HasPrefix(d.dir, p.dir) { + if p.conflictDependency == nil { + p.conflictDependency = make(map[string]*Dependency) } + p.conflictDependency[d.alias] = d + return } - last = p - p = p.parent } - if last.conflictDependency == nil { - last.conflictDependency = make(map[string]*Dependency) + if h, ok := t.HoiestedDependencyMap[d.alias]; ok { + if h.Version == d.Version { + return + } + + // for pnpm + p := d.parent + last := d + for p != t.rootDependency { + if t.HoiestedDependencyMap[p.alias] != nil { + last = p + break + } + + if p.conflictDependency != nil { + if c, ok := p.conflictDependency[d.alias]; ok { + if c.Version == d.Version { + return + } + break + } + } + last = p + p = p.parent + } + + if last.conflictDependency == nil { + last.conflictDependency = make(map[string]*Dependency) + } + last.conflictDependency[d.alias] = d + return } - last.conflictDependency[d.Name] = d + + t.HoiestedDependencyMap[d.alias] = d + } func (t *Collector) processHoistDependencyMap() { t.HoiestedDependencyMap = make(map[string]*Dependency) for _, d := range t.allDependencies { - if e, ok := t.HoiestedDependencyMap[d.Name]; ok { - if e.Version != d.Version { - if d.parent == t.rootDependency { - t.HoiestedDependencyMap[d.Name] = d - t.writeToParentConflicDependency(e) - } else { - t.writeToParentConflicDependency(d) - } - } - } else { - t.HoiestedDependencyMap[d.Name] = d - } - + t.writeToParentConflicDependency(d) } } diff --git a/pkg/node-modules/nodeModuleCollector_test.go b/pkg/node-modules/nodeModuleCollector_test.go index d31ee82..a2f77c6 100644 --- a/pkg/node-modules/nodeModuleCollector_test.go +++ b/pkg/node-modules/nodeModuleCollector_test.go @@ -1,6 +1,7 @@ package node_modules import ( + "fmt" "path" "path/filepath" "testing" @@ -34,7 +35,7 @@ func TestReadDependencyTreeByNpm(t *testing.T) { g.Expect(r).To(ConsistOf([]string{ "js-tokens", "react", "remote", "loose-envify", })) - remoteModule := collector.HoiestedDependencyMap["@electron/remote"] + remoteModule := collector.HoiestedDependencyMap["remote"] g.Expect(remoteModule.alias).To(Equal("remote")) g.Expect(remoteModule.Name).To(Equal("@electron/remote")) } @@ -64,7 +65,7 @@ func TestReadDependencyTreeByPnpm(t *testing.T) { "js-tokens", "react", "remote", "loose-envify", })) - remoteModule := collector.HoiestedDependencyMap["@electron/remote"] + remoteModule := collector.HoiestedDependencyMap["remote"] g.Expect(remoteModule.Name).To(Equal("@electron/remote")) g.Expect(remoteModule.alias).To(Equal("remote")) g.Expect(remoteModule.dir).To(Equal(filepath.Join(dir, "node_modules/.pnpm/@electron+remote@2.1.2_electron@31.0.0/node_modules/@electron/remote"))) @@ -99,9 +100,8 @@ func TestReadDependencyTreeForTar(t *testing.T) { g.Expect(len(r)).To(Equal(46)) g.Expect(collector.HoiestedDependencyMap["tar"].dir).To(Equal(filepath.Join(dir, "node_modules/tar"))) - g.Expect(collector.HoiestedDependencyMap["minipass"].Version).To(Equal("7.1.2")) - g.Expect(collector.HoiestedDependencyMap["minizlib"].Version).To(Equal("3.0.1")) - g.Expect(collector.HoiestedDependencyMap["tar"].conflictDependency["ansi-regex"].Version).To(Equal("5.0.1")) + g.Expect(collector.HoiestedDependencyMap["tar"].conflictDependency["minipass"].Version).To(Equal("7.1.2")) + g.Expect(collector.HoiestedDependencyMap["tar"].conflictDependency["minizlib"].Version).To(Equal("3.0.1")) } func TestReadDependencyTreeForYarn(t *testing.T) { @@ -158,3 +158,33 @@ func TestReadDependencyTreeForParse(t *testing.T) { g.Expect(collector.HoiestedDependencyMap["asn1.js"].dir).To(Equal(filepath.Join(Dirname(), "parse-demo/node_modules/asn1.js"))) g.Expect(collector.HoiestedDependencyMap["asn1.js"].Version).To(Equal("4.10.1")) } + +func TestReadDependencyTreeForEs5(t *testing.T) { + g := NewGomegaWithT(t) + + collector := &Collector{ + unresolvedDependencies: make(map[string]bool), + excludedDependencies: make(map[string]bool), + NodeModuleDirToDependencyMap: make(map[string]*map[string]*Dependency), + } + + dir := path.Join(Dirname(), "es5-demo") + + dependency, err := readPackageJson(dir) + dependency.dir = dir + + g.Expect(err).NotTo(HaveOccurred()) + + err = collector.readDependencyTree(dependency) + g.Expect(err).NotTo(HaveOccurred()) + collector.processHoistDependencyMap() + + fmt.Println(collector.HoiestedDependencyMap) + + g.Expect(collector.HoiestedDependencyMap["d"].dir).To(Equal(filepath.Join(Dirname(), "es5-demo/node_modules/.pnpm/d@1.0.2/node_modules/d"))) + g.Expect(collector.HoiestedDependencyMap["d"].Version).To(Equal("1.0.2")) + + g.Expect(collector.HoiestedDependencyMap["d"].conflictDependency["es5-ext"].dir).To(Equal(filepath.Join(Dirname(), "es5-demo/node_modules/.pnpm/es5-ext@0.10.64/node_modules/es5-ext"))) + g.Expect(collector.HoiestedDependencyMap["d"].conflictDependency["es5-ext"].Version).To(Equal("0.10.64")) + +}