-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add support for git-hosted urls as sibling package dependencies #1033
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { escapeRegExp } from "lodash"; | ||
import hostedGitInfo from "hosted-git-info"; | ||
|
||
export default class GitVersionParser { | ||
constructor(versionPrefix = "v") { | ||
this._gitUrlPattern = new RegExp(`(.+?#${escapeRegExp(versionPrefix)})(.+)$`); | ||
} | ||
|
||
parseVersion(version) { | ||
const gitInfo = hostedGitInfo.fromUrl(version); | ||
let targetMatches; | ||
|
||
if (gitInfo && gitInfo.committish) { | ||
targetMatches = this._gitUrlPattern.exec(version); | ||
} | ||
|
||
return { | ||
prefix: targetMatches ? targetMatches[1] : null, | ||
version: targetMatches ? targetMatches[2] : version | ||
}; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export default class VersionSerializer { | ||
constructor({ graphDependencies, versionParser }) { | ||
this._graphDependencies = graphDependencies; | ||
this._versionParser = versionParser; | ||
this._dependenciesKeys = ["dependencies", "devDependencies", "peerDependencies"]; | ||
this._strippedPrefixes = new Map(); | ||
} | ||
|
||
serialize(pkg) { | ||
this._dependenciesKeys.forEach((key) => { | ||
this._prependPrefix(pkg[key] || {}); | ||
}); | ||
|
||
return pkg; | ||
} | ||
|
||
deserialize(pkg) { | ||
this._dependenciesKeys.forEach((key) => { | ||
this._stripPrefix(pkg[key] || {}); | ||
}); | ||
|
||
return pkg; | ||
} | ||
|
||
_prependPrefix(dependencies) { | ||
this._strippedPrefixes.forEach((prefix, name) => { | ||
const version = dependencies[name]; | ||
if (version) { | ||
dependencies[name] = `${prefix}${version}`; | ||
} | ||
}); | ||
} | ||
|
||
_stripPrefix(dependencies) { | ||
Object.keys(dependencies).forEach((name) => { | ||
if (this._graphDependencies.includes(name)) { | ||
const result = this._versionParser.parseVersion(dependencies[name]); | ||
|
||
if (result.prefix) { | ||
dependencies[name] = result.version; | ||
this._strippedPrefixes.set(name, result.prefix); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
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.
Can we move this
cloneDeep
into the version serializer methods? It seems overly defensive for the non-serialized case.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.
We can, there's a couple of reasons why this is done like this:
toJSON
was returning its internalpkg
object, any outside changes on it will affect PackagetoJSON
behave differently - in one case it will return its internal object the other time it would return a deep copyThere 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.
Despite
.toJSON()
currently being used only in one place, I think you've raised some good points that will ultimately help future use cases (such as when I actually get around to refactoring lerna into a lerna-managed monorepo and the Package class is exposed in a package of its own). I was being overly-cautious about performance in a place where it really, really doesn't matter (package.json files aren't particularly large, and not deeply nested at all).Thanks for the clear explanation. :)