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: resolve all the pnpm issues without hostied config #136

Merged
merged 7 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-wasps-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-bin": patch
---

feat: resolve all the pnpm issues without hostied config
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test:
cd pkg/node-modules/npm-demo/ && npm install
cd pkg/node-modules/tar-demo/ && npm install
cd pkg/node-modules/yarn-demo/ && yarn
cd pkg/node-modules/parse-demo/ && yarn
go test -v ./pkg/...

assets:
Expand Down
26 changes: 1 addition & 25 deletions pkg/node-modules/nodeModuleCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sort"
"strings"

"github.com/develar/app-builder/pkg/fs"
"github.com/develar/app-builder/pkg/log"
"github.com/develar/errors"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -250,24 +249,7 @@ func (t *Collector) resolveDependency(parentNodeModuleDir string, name string) (
}
}

realParentNodeModuleDir := fs.FindParentWithFile(parentNodeModuleDir, name)
if realParentNodeModuleDir == "" {
return nil, nil
}

// XXX consumers expect the node_modules shape or the dependency tree ?
// hoist the depends to the actual parent
if realParentNodeModuleDir != parentNodeModuleDir {
dependencyNameToDependency = t.NodeModuleDirToDependencyMap[realParentNodeModuleDir]
if dependencyNameToDependency != nil {
dependency := (*dependencyNameToDependency)[name]
if dependency != nil {
return nil, nil
}
}
}

dependencyDir := filepath.Join(realParentNodeModuleDir, name)
dependencyDir := filepath.Join(parentNodeModuleDir, name)
info, err := os.Stat(dependencyDir)
if err == nil && !info.IsDir() {
return nil, nil
Expand Down Expand Up @@ -325,12 +307,6 @@ func findNearestNodeModuleDir(dir string) (string, error) {
return "", nil
}

realDir, err := filepath.EvalSymlinks(dir)
if err != nil {
return "", errors.WithStack(err)
}
dir = realDir

guardCount := 0
for {
nodeModuleDir := filepath.Join(dir, "node_modules")
Expand Down
27 changes: 27 additions & 0 deletions pkg/node-modules/nodeModuleCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,30 @@ func TestReadDependencyTreeForYarn(t *testing.T) {
g.Expect(collector.HoiestedDependencyMap["ms"].Version).To(Equal("2.1.1"))
g.Expect(collector.HoiestedDependencyMap["ms"].dir).To(Equal(filepath.Join(Dirname(), "yarn-demo/packages/test-app/node_modules/ms")))
}

func TestReadDependencyTreeForParse(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(), "parse-demo")

dependency, err := readPackageJson(dir)
dependency.dir = dir

g.Expect(err).NotTo(HaveOccurred())

err = collector.readDependencyTree(dependency)
g.Expect(err).NotTo(HaveOccurred())
collector.processHoistDependencyMap()

g.Expect(collector.HoiestedDependencyMap["parse-asn1"].dir).To(Equal(filepath.Join(Dirname(), "parse-demo/node_modules/parse-asn1")))
g.Expect(collector.HoiestedDependencyMap["parse-asn1"].Version).To(Equal("5.1.7"))

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"))
}
15 changes: 15 additions & 0 deletions pkg/node-modules/parse-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "parse-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"parse-asn1":"5.1.7"
}
}
Loading
Loading