mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
fix: store readme when publishing locally (#4493)
* fix: store readme when publishing locally * Update actions test * Update spicy-birds-flow.md
This commit is contained in:
parent
2446a11db5
commit
c807f0c4fb
4 changed files with 66 additions and 9 deletions
6
.changeset/spicy-birds-flow.md
Normal file
6
.changeset/spicy-birds-flow.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@verdaccio/store': patch
|
||||
'@verdaccio/test-helper': patch
|
||||
---
|
||||
|
||||
fix: store readme when publishing locally
|
|
@ -1098,17 +1098,17 @@ class Storage {
|
|||
|
||||
try {
|
||||
// we check if package exist already locally
|
||||
const manifest = await this.getPackagelocalByNameNext(name);
|
||||
const localManifest = await this.getPackagelocalByNameNext(name);
|
||||
// if continue, the version to be published does not exist
|
||||
if (manifest?.versions[versionToPublish] != null) {
|
||||
debug('%s version %s already exists', name, versionToPublish);
|
||||
if (localManifest?.versions[versionToPublish] != null) {
|
||||
debug('%s version %s already exists (locally)', name, versionToPublish);
|
||||
throw errorUtils.getConflict();
|
||||
}
|
||||
const uplinksLook = this.config?.publish?.allow_offline === false;
|
||||
// if execution get here, package does not exist locally, we search upstream
|
||||
const remoteManifest = await this.checkPackageRemote(name, uplinksLook);
|
||||
if (remoteManifest?.versions[versionToPublish] != null) {
|
||||
debug('%s version %s already exists', name, versionToPublish);
|
||||
debug('%s version %s already exists (upstream)', name, versionToPublish);
|
||||
throw errorUtils.getConflict();
|
||||
}
|
||||
|
||||
|
@ -1127,9 +1127,12 @@ class Storage {
|
|||
|
||||
// 1. after tarball has been successfully uploaded, we update the version
|
||||
try {
|
||||
// TODO: review why do this
|
||||
versions[versionToPublish].readme =
|
||||
_.isNil(manifest.readme) === false ? String(manifest.readme) : '';
|
||||
// Older package managers like npm6 do not send readme content as part of version but include it on root level
|
||||
if (_.isEmpty(versions[versionToPublish].readme)) {
|
||||
versions[versionToPublish].readme =
|
||||
_.isNil(manifest.readme) === false ? String(manifest.readme) : '';
|
||||
}
|
||||
// addVersion will move the readme from the the published version to the root level
|
||||
await this.addVersion(name, versionToPublish, versions[versionToPublish], null);
|
||||
} catch (err: any) {
|
||||
logger.error({ err: err.message }, 'updated version has failed: @{err}');
|
||||
|
@ -1145,7 +1148,7 @@ class Storage {
|
|||
// 1. add version
|
||||
// 2. merge versions
|
||||
// 3. upload tarball
|
||||
// 3.update once to the storage (easy peasy)
|
||||
// 4. update once to the storage (easy peasy)
|
||||
mergedManifest = await this.mergeTagsNext(name, manifest[DIST_TAGS]);
|
||||
} catch (err: any) {
|
||||
logger.error({ err: err.message }, 'merge version has failed: @{err}');
|
||||
|
|
|
@ -141,6 +141,8 @@ describe('storage', () => {
|
|||
modified: mockDate,
|
||||
});
|
||||
expect(manifest[DIST_TAGS]).toEqual({ latest: '1.0.0' });
|
||||
// verdaccio keeps latest version of readme on manifest level but not by version
|
||||
expect(manifest.versions['1.0.0'].readme).not.toBeDefined();
|
||||
expect(manifest.readme).toEqual('# test');
|
||||
expect(manifest._attachments).toEqual({});
|
||||
expect(typeof manifest._rev).toBeTruthy();
|
||||
|
@ -309,6 +311,50 @@ describe('storage', () => {
|
|||
})
|
||||
).rejects.toThrow(API_ERROR.PACKAGE_EXIST);
|
||||
});
|
||||
|
||||
test('create private package with readme only in manifest', async () => {
|
||||
const mockDate = '2018-01-14T11:17:40.712Z';
|
||||
MockDate.set(mockDate);
|
||||
const pkgName = 'upstream';
|
||||
const requestOptions = {
|
||||
host: 'localhost',
|
||||
protocol: 'http',
|
||||
headers: {},
|
||||
};
|
||||
const config = new Config(
|
||||
configExample(
|
||||
{
|
||||
...getDefaultConfig(),
|
||||
storage: generateRandomStorage(),
|
||||
},
|
||||
'./fixtures/config/updateManifest-1.yaml',
|
||||
__dirname
|
||||
)
|
||||
);
|
||||
const storage = new Storage(config);
|
||||
await storage.init(config);
|
||||
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
||||
|
||||
// Remove readme from version to simulate behaviour of older package managers like npm6
|
||||
bodyNewManifest.versions['1.0.0'].readme = '';
|
||||
|
||||
await storage.updateManifest(bodyNewManifest, {
|
||||
signal: new AbortController().signal,
|
||||
name: pkgName,
|
||||
uplinksLook: true,
|
||||
revision: '1',
|
||||
requestOptions,
|
||||
});
|
||||
const manifest = (await storage.getPackageByOptions({
|
||||
name: pkgName,
|
||||
uplinksLook: true,
|
||||
requestOptions,
|
||||
})) as Manifest;
|
||||
|
||||
// verdaccio keeps latest version of readme on manifest level but not by version
|
||||
expect(manifest.versions['1.0.0'].readme).not.toBeDefined();
|
||||
expect(manifest.readme).toEqual('# test');
|
||||
});
|
||||
});
|
||||
describe('deprecate', () => {
|
||||
test.each([['foo'], ['@scope/foo']])('deprecate package %s', async (pkgName) => {
|
||||
|
|
|
@ -10,7 +10,9 @@ const debug = buildDebug('verdaccio:tools:helpers:actions');
|
|||
|
||||
export function publishVersion(app, pkgName, version, metadata: Partial<Manifest> = {}): any {
|
||||
debug('publishVersion %s : %s : %s', pkgName, version, JSON.stringify(metadata, null, 2));
|
||||
const pkgMetadata = { ...generatePackageMetadata(pkgName, version), ...metadata };
|
||||
let pkgMetadata = { ...generatePackageMetadata(pkgName, version), ...metadata };
|
||||
// sync metadata readme to version of package
|
||||
pkgMetadata.versions[version].readme = metadata.readme ? (metadata.readme as string) : '';
|
||||
debug('metadata %s', JSON.stringify(pkgMetadata, null, 2));
|
||||
return (
|
||||
supertest(app)
|
||||
|
|
Loading…
Reference in a new issue