-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix: fix tar node module #134
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
805d7fe
fix tar node module
16c8fbb
fix ut
ae074b5
add ut
23c2ed5
fix ut
3a504c8
fix ut
09af3bb
fix ut
68f098c
fix ut
889bae0
order by the length of string
df87676
Create gold-hats-kneel.md
mmaietta 6f6bc54
fix test-app-yarn-workspace-version-conflict
bcf0f63
fix ut
4d2a0c9
optimization
500c90a
delete exe
ce78ac6
optimization
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"app-builder-bin": patch | ||
--- | ||
|
||
fix: fix for handling native dependencies, such as `tar` node module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,15 @@ func TestReadDependencyTreeByNpm(t *testing.T) { | |
|
||
err = collector.readDependencyTree(dependency) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
collector.processHoistDependencyMap() | ||
|
||
r := lo.FlatMap(lo.Values(collector.NodeModuleDirToDependencyMap), func(it *map[string]*Dependency, i int) []string { | ||
return lo.Keys(*it) | ||
}) | ||
g.Expect(r).To(ConsistOf([]string{ | ||
"js-tokens", "react", "remote", "loose-envify", | ||
})) | ||
remoteModule := collector.DependencyMap["@electron/remote"] | ||
remoteModule := collector.HoiestedDependencyMap["@electron/remote"] | ||
g.Expect(remoteModule.alias).To(Equal("remote")) | ||
g.Expect(remoteModule.Name).To(Equal("@electron/remote")) | ||
} | ||
|
@@ -54,18 +56,78 @@ func TestReadDependencyTreeByPnpm(t *testing.T) { | |
|
||
err = collector.readDependencyTree(dependency) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
collector.processHoistDependencyMap() | ||
r := lo.FlatMap(lo.Values(collector.NodeModuleDirToDependencyMap), func(it *map[string]*Dependency, i int) []string { | ||
return lo.Keys(*it) | ||
}) | ||
g.Expect(r).To(ConsistOf([]string{ | ||
"js-tokens", "react", "remote", "loose-envify", | ||
})) | ||
|
||
remoteModule := collector.DependencyMap["@electron/remote"] | ||
remoteModule := collector.HoiestedDependencyMap["@electron/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/@[email protected][email protected]/node_modules/@electron/remote"))) | ||
|
||
reactModule := collector.DependencyMap["react"] | ||
reactModule := collector.HoiestedDependencyMap["react"] | ||
g.Expect(reactModule.dir).To(Equal(filepath.Join(dir, "node_modules/.pnpm/[email protected]/node_modules/react"))) | ||
} | ||
|
||
func TestReadDependencyTreeForTar(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(), "tar-demo") | ||
|
||
dependency, err := readPackageJson(dir) | ||
dependency.dir = dir | ||
|
||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = collector.readDependencyTree(dependency) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
collector.processHoistDependencyMap() | ||
|
||
r := lo.FlatMap(lo.Values(collector.NodeModuleDirToDependencyMap), func(it *map[string]*Dependency, i int) []string { | ||
return lo.Keys(*it) | ||
}) | ||
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")) | ||
} | ||
|
||
func TestReadDependencyTreeForYarn(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(), "yarn-demo/packages/test-app") | ||
|
||
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["foo"].dir).To(Equal(filepath.Join(Dirname(), "yarn-demo/packages/foo"))) | ||
g.Expect(collector.HoiestedDependencyMap["foo"].Version).To(Equal("1.0.0")) | ||
g.Expect(collector.HoiestedDependencyMap["foo"].conflictDependency["ms"].dir).To(Equal(filepath.Join(Dirname(), "yarn-demo/node_modules/ms"))) | ||
g.Expect(collector.HoiestedDependencyMap["foo"].conflictDependency["ms"].Version).To(Equal("2.0.0")) | ||
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"))) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The electron-builder pipeline(https://github.com/electron-userland/electron-builder/actions/runs/10856416053/job/30131018855) occasionally failed, and I finally found the root cause. The map in Golang doesn't maintain a fixed order, so sometimes it returns
[foo, ms]
, and other times it returns[ms, foo]
. If the order is incorrect, it leads to different results. Now that we've fixed the order, it won't fail anymore.