mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-11 02:15:57 -05:00
Update dev mode
This commit is contained in:
parent
aa0fd11e1b
commit
e5e1ed454d
3 changed files with 12 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
export { Storage } from './storage';
|
export { OVERWRITE_MODE, Storage } from './storage';
|
||||||
export * from './lib/storage-utils';
|
export * from './lib/storage-utils';
|
||||||
export * from './lib/versions-utils';
|
export * from './lib/versions-utils';
|
||||||
export * from './lib/star-utils';
|
export * from './lib/star-utils';
|
||||||
|
|
|
@ -91,12 +91,11 @@ import { IGetPackageOptionsNext, OwnerManifestBody, StarManifestBody } from './t
|
||||||
|
|
||||||
const debug = buildDebug('verdaccio:storage');
|
const debug = buildDebug('verdaccio:storage');
|
||||||
|
|
||||||
const OVERWRITE_MODE = 'allow_overwrite';
|
|
||||||
|
|
||||||
export type Filters = pluginUtils.ManifestFilter<Config>[];
|
export type Filters = pluginUtils.ManifestFilter<Config>[];
|
||||||
export const noSuchFile = 'ENOENT';
|
export const noSuchFile = 'ENOENT';
|
||||||
export const resourceNotAvailable = 'EAGAIN';
|
export const resourceNotAvailable = 'EAGAIN';
|
||||||
export const PROTO_NAME = '__proto__';
|
export const PROTO_NAME = '__proto__';
|
||||||
|
export const OVERWRITE_MODE = 'allow_overwrite';
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
public localStorage: LocalStorage;
|
public localStorage: LocalStorage;
|
||||||
|
@ -105,6 +104,8 @@ class Storage {
|
||||||
public readonly logger: Logger;
|
public readonly logger: Logger;
|
||||||
public readonly uplinks: ProxyInstanceList;
|
public readonly uplinks: ProxyInstanceList;
|
||||||
private searchService: Search;
|
private searchService: Search;
|
||||||
|
private allowPackageOverwrite: boolean;
|
||||||
|
|
||||||
public constructor(config: Config, logger: Logger) {
|
public constructor(config: Config, logger: Logger) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.logger = logger.child({ module: 'storage' });
|
this.logger = logger.child({ module: 'storage' });
|
||||||
|
@ -114,6 +115,7 @@ class Storage {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.localStorage = null;
|
this.localStorage = null;
|
||||||
debug('uplinks available %o', Object.keys(this.uplinks));
|
debug('uplinks available %o', Object.keys(this.uplinks));
|
||||||
|
this.allowPackageOverwrite = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ABBREVIATED_HEADER = 'application/vnd.npm.install-v1+json';
|
static ABBREVIATED_HEADER = 'application/vnd.npm.install-v1+json';
|
||||||
|
@ -692,12 +694,15 @@ class Storage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if developer mode is enabled via environment variable.
|
* Check if developer mode is enabled via environment variable.
|
||||||
|
*
|
||||||
|
* Overwrite mode is only allowed when the storage is empty.
|
||||||
*/
|
*/
|
||||||
private async checkDevMode() {
|
private async checkDevMode() {
|
||||||
if (process.env.VERDACCIO_DEV_MODE === OVERWRITE_MODE) {
|
if (process.env.VERDACCIO_DEV_MODE === OVERWRITE_MODE) {
|
||||||
const packages = await this.localStorage.getStoragePlugin().get();
|
const packages = await this.localStorage.getStoragePlugin().get();
|
||||||
if (packages.length === 0) {
|
if (packages.length === 0) {
|
||||||
this.logger.warn('Developer mode is enabled; you can overwrite packages');
|
this.logger.warn('Developer mode is enabled; you can overwrite packages');
|
||||||
|
this.allowPackageOverwrite = true;
|
||||||
} else {
|
} else {
|
||||||
this.logger.warn('Storage must be empty to enable developer mode');
|
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 continue, the version to be published does not exist
|
||||||
if (localManifest?.versions[versionToPublish] != null) {
|
if (localManifest?.versions[versionToPublish] != null) {
|
||||||
debug('%s version %s already exists (locally)', name, versionToPublish);
|
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);
|
const filename = composeTarballFromPackage(name, versionToPublish);
|
||||||
await this.removeTarball(name, filename, localManifest._rev, username!);
|
await this.removeTarball(name, filename, localManifest._rev, username!);
|
||||||
delete localManifest.versions[versionToPublish];
|
delete localManifest.versions[versionToPublish];
|
||||||
|
@ -1202,7 +1207,7 @@ class Storage {
|
||||||
const remoteManifest = await this.checkPackageRemote(name, uplinksLook);
|
const remoteManifest = await this.checkPackageRemote(name, uplinksLook);
|
||||||
if (remoteManifest?.versions[versionToPublish] != null) {
|
if (remoteManifest?.versions[versionToPublish] != null) {
|
||||||
debug('%s version %s already exists (upstream)', name, versionToPublish);
|
debug('%s version %s already exists (upstream)', name, versionToPublish);
|
||||||
if (process.env.VERDACCIO_DEV_MODE !== OVERWRITE_MODE) {
|
if (!this.allowPackageOverwrite) {
|
||||||
throw errorUtils.getConflict();
|
throw errorUtils.getConflict();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import {
|
||||||
Version,
|
Version,
|
||||||
} from '@verdaccio/types';
|
} from '@verdaccio/types';
|
||||||
|
|
||||||
import { Storage } from '../src';
|
import { OVERWRITE_MODE, Storage } from '../src';
|
||||||
import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json';
|
import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json';
|
||||||
import { configExample } from './helpers';
|
import { configExample } from './helpers';
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ describe('storage', () => {
|
||||||
__dirname
|
__dirname
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
process.env.VERDACCIO_DEV_MODE = 'allow_overwrite';
|
process.env.VERDACCIO_DEV_MODE = OVERWRITE_MODE;
|
||||||
const storage = new Storage(config, logger);
|
const storage = new Storage(config, logger);
|
||||||
await storage.init(config);
|
await storage.init(config);
|
||||||
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
|
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
|
||||||
|
|
Loading…
Add table
Reference in a new issue