0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

Update dev mode

This commit is contained in:
Marc Bernard 2024-12-02 17:52:03 -05:00
parent aa0fd11e1b
commit e5e1ed454d
3 changed files with 12 additions and 7 deletions

View file

@ -1,4 +1,4 @@
export { Storage } from './storage';
export { OVERWRITE_MODE, Storage } from './storage';
export * from './lib/storage-utils';
export * from './lib/versions-utils';
export * from './lib/star-utils';

View file

@ -91,12 +91,11 @@ import { IGetPackageOptionsNext, OwnerManifestBody, StarManifestBody } from './t
const debug = buildDebug('verdaccio:storage');
const OVERWRITE_MODE = 'allow_overwrite';
export type Filters = pluginUtils.ManifestFilter<Config>[];
export const noSuchFile = 'ENOENT';
export const resourceNotAvailable = 'EAGAIN';
export const PROTO_NAME = '__proto__';
export const OVERWRITE_MODE = 'allow_overwrite';
class Storage {
public localStorage: LocalStorage;
@ -105,6 +104,8 @@ class Storage {
public readonly logger: Logger;
public readonly uplinks: ProxyInstanceList;
private searchService: Search;
private allowPackageOverwrite: boolean;
public constructor(config: Config, logger: Logger) {
this.config = config;
this.logger = logger.child({ module: 'storage' });
@ -114,6 +115,7 @@ class Storage {
// @ts-ignore
this.localStorage = null;
debug('uplinks available %o', Object.keys(this.uplinks));
this.allowPackageOverwrite = false;
}
static ABBREVIATED_HEADER = 'application/vnd.npm.install-v1+json';
@ -692,12 +694,15 @@ class Storage {
/**
* Check if developer mode is enabled via environment variable.
*
* Overwrite mode is only allowed when the storage is empty.
*/
private async checkDevMode() {
if (process.env.VERDACCIO_DEV_MODE === OVERWRITE_MODE) {
const packages = await this.localStorage.getStoragePlugin().get();
if (packages.length === 0) {
this.logger.warn('Developer mode is enabled; you can overwrite packages');
this.allowPackageOverwrite = true;
} else {
this.logger.warn('Storage must be empty to enable developer mode');
}
@ -1188,7 +1193,7 @@ class Storage {
// if continue, the version to be published does not exist
if (localManifest?.versions[versionToPublish] != null) {
debug('%s version %s already exists (locally)', name, versionToPublish);
if (process.env.VERDACCIO_DEV_MODE === OVERWRITE_MODE) {
if (this.allowPackageOverwrite) {
const filename = composeTarballFromPackage(name, versionToPublish);
await this.removeTarball(name, filename, localManifest._rev, username!);
delete localManifest.versions[versionToPublish];
@ -1202,7 +1207,7 @@ class Storage {
const remoteManifest = await this.checkPackageRemote(name, uplinksLook);
if (remoteManifest?.versions[versionToPublish] != null) {
debug('%s version %s already exists (upstream)', name, versionToPublish);
if (process.env.VERDACCIO_DEV_MODE !== OVERWRITE_MODE) {
if (!this.allowPackageOverwrite) {
throw errorUtils.getConflict();
}
}

View file

@ -35,7 +35,7 @@ import {
Version,
} from '@verdaccio/types';
import { Storage } from '../src';
import { OVERWRITE_MODE, Storage } from '../src';
import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json';
import { configExample } from './helpers';
@ -368,7 +368,7 @@ describe('storage', () => {
__dirname
)
);
process.env.VERDACCIO_DEV_MODE = 'allow_overwrite';
process.env.VERDACCIO_DEV_MODE = OVERWRITE_MODE;
const storage = new Storage(config, logger);
await storage.init(config);
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');