Skip to content

Commit

Permalink
node: Fix non tgz index_entry not valied on npm 8 by adding reqHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
catsout authored and refi64 committed Jul 10, 2022
1 parent 341fa77 commit ed05266
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions node/flatpak_node_generator/providers/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
from . import LockfileProvider, ModuleProvider, ProviderFactory, RCFileProvider
from .special import SpecialSourceProvider

_NPM_CORGIDOC = (
'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
)


class NpmLockfileProvider(LockfileProvider):
_ALIAS_RE = re.compile(r'^npm:(.[^@]*)@(.*)$')
Expand Down Expand Up @@ -163,8 +167,14 @@ def get_cacache_content_path(self, integrity: Integrity) -> Path:
/ self.get_cacache_integrity_path(integrity)
)

def add_index_entry(self, url: str, metadata: RemoteUrlMetadata) -> None:
def add_index_entry(
self,
url: str,
metadata: RemoteUrlMetadata,
request_headers: Dict[str, str] = {},
) -> None:
key = f'make-fetch-happen:request-cache:{url}'

index_json = json.dumps(
{
'key': key,
Expand All @@ -173,7 +183,7 @@ def add_index_entry(self, url: str, metadata: RemoteUrlMetadata) -> None:
'size': metadata.size,
'metadata': {
'url': url,
'reqHeaders': {},
'reqHeaders': request_headers,
'resHeaders': {},
},
}
Expand Down Expand Up @@ -304,7 +314,9 @@ def _finalize(self) -> None:
)
content_path = self.get_cacache_content_path(metadata.integrity)
self.gen.add_data_source(raw_data, content_path)
self.add_index_entry(index.url, metadata)
self.add_index_entry(
index.url, metadata, request_headers={'accept': _NPM_CORGIDOC}
)

patch_commands: DefaultDict[Path, List[str]] = collections.defaultdict(
lambda: []
Expand Down

0 comments on commit ed05266

Please sign in to comment.