Skip to content

Commit

Permalink
fix: add hasInstallScript calculation (#3509)
Browse files Browse the repository at this point in the history
* fix: add hasInstallScript calculation

* Update storage-utils.ts

* chore: add tests
  • Loading branch information
juanpicado committed Nov 23, 2022
1 parent a0a0654 commit 0b49566
Show file tree
Hide file tree
Showing 4 changed files with 102,983 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/storage-utils.ts
Expand Up @@ -237,6 +237,18 @@ export function isPublishablePackage(pkg: Package): boolean {
return _.includes(keys, 'versions');
}

export function hasInstallScript(version: Version) {
if (version?.scripts) {
const scripts = Object.keys(version.scripts);
return (
scripts.find((item) => {
return ['install', 'preinstall', 'postinstall'].includes(item);
}) !== undefined
);
}
return false;
}

export function convertAbbreviatedManifest(manifest: Manifest): AbbreviatedManifest {
const abbreviatedVersions = Object.keys(manifest.versions).reduce((acc: AbbreviatedVersions, version: string) => {
const _version = manifest.versions[version];
Expand All @@ -262,7 +274,7 @@ export function convertAbbreviatedManifest(manifest: Manifest): AbbreviatedManif
bundleDependencies: _version.bundleDependencies,
// npm cli specifics
_hasShrinkwrap: _version._hasShrinkwrap,
hasInstallScript: _version.hasInstallScript,
hasInstallScript: hasInstallScript(_version),
};
acc[version] = _version_abbreviated;
return acc;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/modules/api/api.spec.ts
Expand Up @@ -392,6 +392,30 @@ describe('endpoint unit test', () => {
});
});

test.each([
'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
'application/vnd.npm.install-v1+json; q=1.0, */*',
'application/vnd.npm.install-v1+json',
])('should fetch abbreviated puppeteer package from remote uplink with %s', (accept, done: any) => {
request(app)
.get('/puppeteer')
.set('accept', accept)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP)
.expect(HEADERS.CONTENT_TYPE, 'application/vnd.npm.install-v1+json; charset=utf-8')
.expect(HTTP_STATUS.OK)
.end(function (err, res) {
if (err) {
return done(err);
}
const manifest = res.body;
expect(manifest).toBeDefined();
expect(manifest.name).toMatch(/puppeteer/);
expect(manifest.versions['19.2.2'].hasInstallScript).toBeTruthy();
done();
});
});

test('should fails with socket time out fetch tarball timeout package from remote uplink', async () => {
const timeOutPkg = generatePackageMetadata('timeout', '1.5.1');
const responseText = 'fooooooooooooooooo';
Expand Down

0 comments on commit 0b49566

Please sign in to comment.