Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado committed Jun 15, 2024
1 parent 4b2c45a commit b36bbd3
Show file tree
Hide file tree
Showing 13 changed files with 1,725 additions and 822 deletions.
2 changes: 1 addition & 1 deletion packages/server/fastify/src/endpoints/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// const { packageName } = request.params;
// const storage = fastify.storage;
// debug('pkg name %s ', packageName);
// // const data = await storage?.getPackageNext({
// // const data = await storage?.getPackage({
// // name: packageName,
// // req: request.raw,
// // uplinksLook: true,
Expand Down
7 changes: 4 additions & 3 deletions packages/store/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class Storage {
}

// we have version, so we need to return specific version
const [convertedManifest] = await this.getPackageNext(options);
const [convertedManifest] = await this.getPackage(options);

const version: Version | undefined = getVersion(convertedManifest.versions, queryVersion);

Expand Down Expand Up @@ -497,7 +497,7 @@ class Storage {

public async getPackageManifest(options: IGetPackageOptionsNext): Promise<Manifest> {
// convert dist remotes to local bars
const [manifest] = await this.getPackageNext(options);
const [manifest] = await this.getPackage(options);

// If change access is requested (?write=true), then check if logged in user is allowed to change package
if (options.byPassCache === true) {
Expand Down Expand Up @@ -1093,6 +1093,7 @@ class Storage {
if (typeof storage === 'undefined') {
throw errorUtils.getNotFound();
}
// TODO: juan
const hasPackage = await storage.hasPackage();
debug('has package %o for %o', pkgName, hasPackage);
return hasPackage;
Expand Down Expand Up @@ -1611,7 +1612,7 @@ class Storage {
* @return {*} {Promise<[Manifest, any[]]>}
* @memberof AbstractStorage
*/
private async getPackageNext(options: IGetPackageOptionsNext): Promise<[Manifest, any[]]> {
private async getPackage(options: IGetPackageOptionsNext): Promise<[Manifest, any[]]> {
const { name } = options;
debug('get package for %o', name);
let data: Manifest | null = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
uplinks:
ver:
url: https://registry.verdaccio.org/
packages:
'@*/*':
access: $all
publish: $all
proxy: ver
'upstream':
access: $all
publish: $authenticated
'*':
access: $all
publish: $all
proxy: ver
log: { type: stdout, format: pretty, level: info }
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class StoragePluginManage {
* @param callback
*/
readPackage(pkgName, callback) {
callback(null, { name: pkgName });
callback(null, {
name: pkgName,
'dist-tags': { latest: '1.0.0' },
versions: { '1.0.0': { pkgName } },
});
/**
* Example of implementation:
* this.customStorage.read(name, (err, pkg: Package) => {
Expand Down
59 changes: 57 additions & 2 deletions packages/store/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { pseudoRandomBytes } from 'crypto';
import buildDebug from 'debug';
import fs from 'fs';
import os from 'os';
import path from 'path';

import { parseConfigFile } from '@verdaccio/config';
import { Config, getDefaultConfig } from '@verdaccio/config';
import { ConfigYaml, PackageUsers } from '@verdaccio/types';

const debug = buildDebug('verdaccio:mock:config');

/**
* Override the default.yaml configuration file with any new config provided.
*/
function configExample(externalConfig: any = {}, configFile?: string, location?: string) {
export function configExample(externalConfig: any = {}, configFile?: string, location?: string) {
let config = {};
if (location && configFile) {
const locationFile = path.join(location, configFile);
Expand All @@ -19,4 +24,54 @@ function configExample(externalConfig: any = {}, configFile?: string, location?:
return { ...externalConfig, ...config };
}

export { configExample };
export function generateRandomStorage() {
const tempStorage = pseudoRandomBytes(5).toString('hex');
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), '/verdaccio-test'));

return path.join(tempRoot, tempStorage);
}

export const getConfig = (file, override: Partial<ConfigYaml> = {}): Config => {
const config = new Config(
configExample(
{
...getDefaultConfig(),
storage: generateRandomStorage(),
...override,
},
`./fixtures/config/${file}`,
__dirname
)
);
return config;
};

export const defaultRequestOptions = {
host: 'localhost',
protocol: 'http',
headers: {},
};
export const executeStarPackage = async (
storage,
options: {
users: PackageUsers;
username: string;
name: string;
_rev: string;
_id?: string;
}
) => {
const { name, _rev, _id, users, username } = options;
const starManifest = {
_rev,
_id,
users,
};
return storage.updateManifest(starManifest, {
signal: new AbortController().signal,
name,
uplinksLook: true,
revision: '1',
requestOptions: { ...defaultRequestOptions, username },
});
};
Loading

0 comments on commit b36bbd3

Please sign in to comment.