1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-21 07:29:37 +01:00

fix: add hasInstallScript calculation (#3509)

* fix: add hasInstallScript calculation

* Update storage-utils.ts

* chore: add tests
This commit is contained in:
Juan Picado 2022-11-23 07:35:10 +01:00 committed by GitHub
parent a0a0654f15
commit 0b49566176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102983 additions and 1 deletions

@ -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];
@ -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;

@ -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';

File diff suppressed because one or more lines are too long