Skip to content

Commit

Permalink
node: support shortcut git urls for lockfile v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2020 committed Nov 16, 2023
1 parent 9e4677e commit f28defd
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 8 deletions.
37 changes: 29 additions & 8 deletions node/flatpak_node_generator/providers/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,38 @@ def _finalize(self) -> None:

new_version = f'{path}#{source.commit}'
targets = []
source_url = source.from_ or source.original
source_url = urllib.parse.urlparse(source.from_ or source.original)

# https://github.com/npm/hosted-git-info
hosted_git = [
('@github.com', 'github'),
('@bitbucket.org', 'bitbucket'),
('@gitlab.com', 'gitlab'),
('@gist.github.com', 'gist'),
('@git.sr.ht', 'sourcehut'),
]
for domain, shortcut in hosted_git:
if domain in source_url.netloc.lower():
targets.append(
f"{shortcut}:{source_url.path[1:].replace('.git', '')}"
f'#{source_url.fragment}'
)
break

if (
source_url.startswith(GIT_URL_PREFIX + 'ssh')
and ':' not in urllib.parse.urlparse(source_url).netloc
source_url.scheme.startswith(GIT_URL_PREFIX + 'ssh')
and ':' not in source_url.netloc
):
source_url = re.sub(r'(://[^/]+)/', r'\1:', source_url)
elif source_url.startswith(GIT_URL_PREFIX):
targets.append(source_url[len(GIT_URL_PREFIX) :])

targets.append(source_url)
path_match = re.compile(r'^/([^/]+)(.*)').match(source_url.path)
if path_match:
parent, child = path_match.groups()
source_url = source_url._replace(
netloc=f'{source_url.netloc}:{parent}', path=child
)
elif source_url.scheme.startswith(GIT_URL_PREFIX):
targets.append(source_url.geturl()[len(GIT_URL_PREFIX) :])

targets.append(source_url.geturl())
for t in targets:
data[t] = new_version
data[t.replace('#' + source.commit, '')] = new_version
Expand Down
12 changes: 12 additions & 0 deletions node/tests/data/packages/git/package-lock.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"is-empty-object": {
"version": "git+ssh://[email protected]/gummesson/is-empty-object.git#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"from": "is-empty-object@github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8"
},
"is-number": {
"version": "git+ssh://[email protected]/jonschlinkert/is-number.git#98e8ff1da1a89f93d1397a24d7413ed15421c139",
"from": "is-number@github:jonschlinkert/is-number"
},
"person-lib": {
"version": "git+ssh://[email protected]/volodymyrkr/person-lib.git#752fd1828b1eb3a9635bf725ae5e1704a375e524",
"from": "person-lib@gitlab:volodymyrkr/person-lib"
},
"to-camel-case": {
"version": "git+ssh://[email protected]/ianstormtaylor/to-camel-case.git#00a20429b600ddb6e4f8ff5b17c52914f40fe67d",
"from": "git+ssh://[email protected]/ianstormtaylor/to-camel-case.git",
Expand Down
35 changes: 35 additions & 0 deletions node/tests/data/packages/git/package-lock.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,34 @@
"name": "@flatpak-node-generator-tests/git",
"version": "1.0.0",
"dependencies": {
"is-empty-object": "github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"is-number": "github:jonschlinkert/is-number",
"person-lib": "gitlab:volodymyrkr/person-lib",
"to-camel-case": "git+ssh://[email protected]:ianstormtaylor/to-camel-case.git",
"to-capital-case": "git+https://[email protected]/ianstormtaylor/to-capital-case.git",
"to-no-case": "git+https://[email protected]/ianstormtaylor/to-no-case.git#9078578dcf394e63f34fd7c6666772192e537b90",
"to-space-case": "git+ssh://[email protected]:ianstormtaylor/to-space-case.git#aa68213d1211745ce7c6c725ba072e6b13bef640"
}
},
"node_modules/is-empty-object": {
"version": "1.1.1",
"resolved": "git+ssh://[email protected]/gummesson/is-empty-object.git#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"integrity": "sha512-OQNk2je1cKQ0Y0AYZ2X9hwapnDsOaKIa9wDdCjtmaU6JsnNHmbk27kPn1HNtgeIuLca3HvrBocDRt6y7+2aHJA==",
"license": "MIT"
},
"node_modules/is-number": {
"version": "7.0.0",
"resolved": "git+ssh://[email protected]/jonschlinkert/is-number.git#98e8ff1da1a89f93d1397a24d7413ed15421c139",
"license": "MIT",
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/person-lib": {
"version": "1.0.1",
"resolved": "git+ssh://[email protected]/volodymyrkr/person-lib.git#752fd1828b1eb3a9635bf725ae5e1704a375e524",
"license": "ISC"
},
"node_modules/to-camel-case": {
"version": "1.0.0",
"resolved": "git+ssh://[email protected]/ianstormtaylor/to-camel-case.git#00a20429b600ddb6e4f8ff5b17c52914f40fe67d",
Expand Down Expand Up @@ -47,6 +69,19 @@
}
},
"dependencies": {
"is-empty-object": {
"version": "git+ssh://[email protected]/gummesson/is-empty-object.git#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"integrity": "sha512-OQNk2je1cKQ0Y0AYZ2X9hwapnDsOaKIa9wDdCjtmaU6JsnNHmbk27kPn1HNtgeIuLca3HvrBocDRt6y7+2aHJA==",
"from": "is-empty-object@github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8"
},
"is-number": {
"version": "git+ssh://[email protected]/jonschlinkert/is-number.git#98e8ff1da1a89f93d1397a24d7413ed15421c139",
"from": "is-number@github:jonschlinkert/is-number"
},
"person-lib": {
"version": "git+ssh://[email protected]/volodymyrkr/person-lib.git#752fd1828b1eb3a9635bf725ae5e1704a375e524",
"from": "person-lib@gitlab:volodymyrkr/person-lib"
},
"to-camel-case": {
"version": "git+ssh://[email protected]/ianstormtaylor/to-camel-case.git#00a20429b600ddb6e4f8ff5b17c52914f40fe67d",
"from": "to-camel-case@git+ssh://[email protected]:ianstormtaylor/to-camel-case.git",
Expand Down
22 changes: 22 additions & 0 deletions node/tests/data/packages/git/package-lock.v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,34 @@
"name": "@flatpak-node-generator-tests/git",
"version": "1.0.0",
"dependencies": {
"is-empty-object": "github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"is-number": "github:jonschlinkert/is-number",
"person-lib": "gitlab:volodymyrkr/person-lib",
"to-camel-case": "git+ssh://[email protected]:ianstormtaylor/to-camel-case.git",
"to-capital-case": "git+https://[email protected]/ianstormtaylor/to-capital-case.git",
"to-no-case": "git+https://[email protected]/ianstormtaylor/to-no-case.git#9078578dcf394e63f34fd7c6666772192e537b90",
"to-space-case": "git+ssh://[email protected]:ianstormtaylor/to-space-case.git#aa68213d1211745ce7c6c725ba072e6b13bef640"
}
},
"node_modules/is-empty-object": {
"version": "1.1.1",
"resolved": "git+ssh://[email protected]/gummesson/is-empty-object.git#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"integrity": "sha512-OQNk2je1cKQ0Y0AYZ2X9hwapnDsOaKIa9wDdCjtmaU6JsnNHmbk27kPn1HNtgeIuLca3HvrBocDRt6y7+2aHJA==",
"license": "MIT"
},
"node_modules/is-number": {
"version": "7.0.0",
"resolved": "git+ssh://[email protected]/jonschlinkert/is-number.git#98e8ff1da1a89f93d1397a24d7413ed15421c139",
"license": "MIT",
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/person-lib": {
"version": "1.0.1",
"resolved": "git+ssh://[email protected]/volodymyrkr/person-lib.git#752fd1828b1eb3a9635bf725ae5e1704a375e524",
"license": "ISC"
},
"node_modules/to-camel-case": {
"version": "1.0.0",
"resolved": "git+ssh://[email protected]/ianstormtaylor/to-camel-case.git#00a20429b600ddb6e4f8ff5b17c52914f40fe67d",
Expand Down
3 changes: 3 additions & 0 deletions node/tests/data/packages/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@flatpak-node-generator-tests/git",
"version": "1.0.0",
"dependencies": {
"is-empty-object": "github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8",
"is-number": "github:jonschlinkert/is-number",
"person-lib": "gitlab:volodymyrkr/person-lib",
"to-camel-case": "git+ssh://[email protected]:ianstormtaylor/to-camel-case.git",
"to-capital-case": "git+https://[email protected]/ianstormtaylor/to-capital-case.git",
"to-no-case": "git+https://[email protected]/ianstormtaylor/to-no-case.git#9078578dcf394e63f34fd7c6666772192e537b90",
Expand Down
12 changes: 12 additions & 0 deletions node/tests/data/packages/git/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# yarn lockfile v1


"is-empty-object@github:gummesson/is-empty-object#7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8":
version "1.1.1"
resolved "https://codeload.github.com/gummesson/is-empty-object/tar.gz/7b50c8eb4e14135631f7c94e01c0c8a36e5d75f8"

"is-number@github:jonschlinkert/is-number":
version "7.0.0"
resolved "https://codeload.github.com/jonschlinkert/is-number/tar.gz/98e8ff1da1a89f93d1397a24d7413ed15421c139"

"person-lib@gitlab:volodymyrkr/person-lib":
version "1.0.1"
resolved "git+ssh://[email protected]/volodymyrkr/person-lib.git#752fd1828b1eb3a9635bf725ae5e1704a375e524"

"to-camel-case@git+ssh://[email protected]:ianstormtaylor/to-camel-case.git":
version "1.0.0"
resolved "git+ssh://[email protected]:ianstormtaylor/to-camel-case.git#00a20429b600ddb6e4f8ff5b17c52914f40fe67d"
Expand Down

0 comments on commit f28defd

Please sign in to comment.