mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-17 23:45:29 -05:00
fix: add hasInstallScript calculation (#3509)
* fix: add hasInstallScript calculation * Update storage-utils.ts * chore: add tests
This commit is contained in:
parent
a0a0654f15
commit
0b49566176
4 changed files with 102983 additions and 1 deletions
|
@ -237,6 +237,18 @@ export function isPublishablePackage(pkg: Package): boolean {
|
||||||
return _.includes(keys, 'versions');
|
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 {
|
export function convertAbbreviatedManifest(manifest: Manifest): AbbreviatedManifest {
|
||||||
const abbreviatedVersions = Object.keys(manifest.versions).reduce((acc: AbbreviatedVersions, version: string) => {
|
const abbreviatedVersions = Object.keys(manifest.versions).reduce((acc: AbbreviatedVersions, version: string) => {
|
||||||
const _version = manifest.versions[version];
|
const _version = manifest.versions[version];
|
||||||
|
@ -262,7 +274,7 @@ export function convertAbbreviatedManifest(manifest: Manifest): AbbreviatedManif
|
||||||
bundleDependencies: _version.bundleDependencies,
|
bundleDependencies: _version.bundleDependencies,
|
||||||
// npm cli specifics
|
// npm cli specifics
|
||||||
_hasShrinkwrap: _version._hasShrinkwrap,
|
_hasShrinkwrap: _version._hasShrinkwrap,
|
||||||
hasInstallScript: _version.hasInstallScript,
|
hasInstallScript: hasInstallScript(_version),
|
||||||
};
|
};
|
||||||
acc[version] = _version_abbreviated;
|
acc[version] = _version_abbreviated;
|
||||||
return acc;
|
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 () => {
|
test('should fails with socket time out fetch tarball timeout package from remote uplink', async () => {
|
||||||
const timeOutPkg = generatePackageMetadata('timeout', '1.5.1');
|
const timeOutPkg = generatePackageMetadata('timeout', '1.5.1');
|
||||||
const responseText = 'fooooooooooooooooo';
|
const responseText = 'fooooooooooooooooo';
|
||||||
|
|
102946
test/unit/partials/mock-store/puppeteer/package.json
Normal file
102946
test/unit/partials/mock-store/puppeteer/package.json
Normal file
File diff suppressed because one or more lines are too long
BIN
test/unit/partials/mock-store/puppeteer/puppeteer-19.2.2.tgz
Normal file
BIN
test/unit/partials/mock-store/puppeteer/puppeteer-19.2.2.tgz
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue