@@ -130,10 +130,7 @@ def _process_packages_v2(
130130 integrity = integrity , resolved = info ['resolved' ]
131131 )
132132 elif resolved_url .scheme .startswith ('git+' ):
133- raise NotImplementedError (
134- 'Git sources in lockfile v2 format are not supported yet'
135- f' (package { install_path } in { lockfile } )'
136- )
133+ source = self .parse_git_source (info ['resolved' ])
137134 else :
138135 raise NotImplementedError (
139136 f"Don't know how to handle package { install_path } in { lockfile } "
@@ -425,72 +422,58 @@ def _finalize(self) -> None:
425422 )
426423
427424 if self .git_sources :
428- # Generate jq scripts to patch the package*.json files.
429- scripts = {
430- 'package.json' : r"""
431- walk(
432- if type == "object"
433- then
434- to_entries | map(
435- if (.value | type == "string") and $data[.value]
436- then .value = "git+file:\($buildroot)/\($data[.value])"
437- else .
438- end
439- ) | from_entries
440- else .
441- end
442- )
443- """ ,
444- 'package-lock.json' : r"""
445- walk(
446- if type == "object" and (.version | type == "string") and $data[.version]
447- then
448- .version = "git+file:\($buildroot)/\($data[.version])"
449- else .
450- end
451- )
452- """ ,
453- }
425+ # Generate jq script to patch the package.json file
426+ script = r"""
427+ walk(
428+ if type == "object"
429+ then
430+ to_entries | map(
431+ if (.value | type == "string") and $data[.value]
432+ then .value = "git+file:\($buildroot)/\($data[.value])"
433+ else .
434+ end
435+ ) | from_entries
436+ else .
437+ end
438+ )
439+ """
454440
455441 for lockfile , sources in self .git_sources .items ():
456442 prefix = self .relative_lockfile_dir (lockfile )
457- data : Dict [str , Dict [str , str ]] = {
458- 'package.json' : {},
459- 'package-lock.json' : {},
460- }
443+ data : Dict [str , str ] = {}
461444
462445 for path , source in sources .items ():
463446 GIT_URL_PREFIX = 'git+'
464447
465448 new_version = f'{ path } #{ source .commit } '
466- assert source . from_ is not None
467- data [ 'package.json' ][ source .from_ ] = new_version
468- data [ 'package-lock.json' ][ source . original ] = new_version
469-
470- if source . from_ . startswith (GIT_URL_PREFIX ):
471- data [ 'package.json' ][
472- source . from_ [ len ( GIT_URL_PREFIX ) :]
473- ] = new_version
474-
475- if source . original . startswith ( GIT_URL_PREFIX ):
476- data [ 'package-lock.json' ][
477- source . original [ len ( GIT_URL_PREFIX ) :]
478- ] = new_version
479-
480- for filename , script in scripts . items ():
481- target = Path ( '$FLATPAK_BUILDER_BUILDDIR' ) / prefix / filename
482- script = (
483- textwrap . dedent ( script . lstrip ( ' \n ' )). strip (). replace ( ' \n ' , '' )
484- )
485- json_data = json .dumps (data [ filename ] )
486- patch_commands [lockfile ].append (
487- 'jq'
488- ' --arg buildroot "$FLATPAK_BUILDER_BUILDDIR"'
489- f' --argjson data { shlex .quote (json_data )} '
490- f' { shlex .quote (script )} { target } '
491- f' > { target } .new'
492- )
493- patch_commands [lockfile ].append (f'mv { target } {{.new,}}' )
449+ targets = []
450+ source_url = source .from_ or source . original
451+
452+ if (
453+ source_url . startswith (GIT_URL_PREFIX + 'ssh' )
454+ and ':' not in urllib . parse . urlparse ( source_url ). netloc
455+ ):
456+ source_url = re . sub ( r'(://[^/]+)/' , r'\1:' , source_url )
457+ elif source_url . startswith ( GIT_URL_PREFIX ):
458+ targets . append ( source_url [ len ( GIT_URL_PREFIX ) :])
459+
460+ targets . append ( source_url )
461+ for t in targets :
462+ data [ t ] = new_version
463+ data [ t . replace ( '#' + source . commit , '' )] = new_version
464+
465+ filename = 'package.json'
466+ target = Path ( '$FLATPAK_BUILDER_BUILDDIR' ) / prefix / filename
467+ script = textwrap . dedent ( script . lstrip ( ' \n ' )). strip (). replace ( ' \n ' , '' )
468+ json_data = json .dumps (data )
469+ patch_commands [lockfile ].append (
470+ 'jq'
471+ ' --arg buildroot "$FLATPAK_BUILDER_BUILDDIR"'
472+ f' --argjson data { shlex .quote (json_data )} '
473+ f' { shlex .quote (script )} { target } '
474+ f' > { target } .new'
475+ )
476+ patch_commands [lockfile ].append (f'mv { target } {{.new,}}' )
494477
495478 patch_all_commands : List [str ] = []
496479 for lockfile in self .all_lockfiles :
0 commit comments