Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81865a1790 | ||
|
|
92083924ea | ||
|
|
80ab0548f2 |
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [3.21.0](https://github.com/cnpm/npmcore/compare/v3.20.3...v3.21.0) (2023-05-21)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* easy config ([#468](https://github.com/cnpm/npmcore/issues/468)) ([9208392](https://github.com/cnpm/npmcore/commit/92083924eaa3fbcd5f3c651d0ddc056d9affba30))
|
||||
|
||||
## [3.20.3](https://github.com/cnpm/npmcore/compare/v3.20.2...v3.20.3) (2023-05-18)
|
||||
|
||||
|
||||
|
||||
16
INTEGRATE.md
16
INTEGRATE.md
@@ -76,7 +76,21 @@
|
||||
}
|
||||
```
|
||||
|
||||
3. 修改 `config.default.ts` 文件,可以直接复制 cnpmcore 中的内容
|
||||
3. 修改 `config.default.ts` 文件,可以直接覆盖默认配置
|
||||
```typescript
|
||||
import { SyncMode } from 'cnpmcore/common/constants';
|
||||
import { cnpmcoreConfig } from 'cnpmcore/common/config';
|
||||
|
||||
export default () => {
|
||||
const config = {};
|
||||
config.cnpmcore = {
|
||||
...cnpmcoreConfig,
|
||||
enableChangesStream: false,
|
||||
syncMode: SyncMode.all,
|
||||
};
|
||||
return config;
|
||||
}
|
||||
```
|
||||
|
||||
### 🧑🤝🧑 集成 cnpmcore
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { cnpmcoreConfig } from '../port/config';
|
||||
import { Readable } from 'stream';
|
||||
import { IncomingHttpHeaders } from 'http';
|
||||
import { EggContext } from '@eggjs/tegg';
|
||||
@@ -62,3 +63,12 @@ export interface AuthClient {
|
||||
getAuthUrl(ctx: EggContext): Promise<AuthUrlResult>;
|
||||
ensureCurrentUser(): Promise<userResult | null>;
|
||||
}
|
||||
|
||||
declare module 'egg' {
|
||||
// eslint-disable-next-line
|
||||
// @ts-ignore
|
||||
// avoid TS2310 Type 'EggAppConfig' recursively references itself as a base type.
|
||||
interface EggAppConfig {
|
||||
cnpmcore: typeof cnpmcoreConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,10 +504,10 @@ export class PackageManagerService extends AbstractService {
|
||||
await this.packageRepository.removePackageVersion(pkgVersion);
|
||||
}
|
||||
|
||||
public async unpublishPackage(pkg: Package, forceRefresh = false) {
|
||||
public async unpublishPackage(pkg: Package) {
|
||||
const pkgVersions = await this.packageRepository.listPackageVersions(pkg.packageId);
|
||||
// already unpublished
|
||||
if (pkgVersions.length === 0 && !forceRefresh) {
|
||||
if (pkgVersions.length === 0) {
|
||||
this.logger.info(`[packageManagerService.unpublishPackage:skip] ${pkg.packageId} already unpublished`);
|
||||
return;
|
||||
}
|
||||
@@ -533,8 +533,14 @@ export class PackageManagerService extends AbstractService {
|
||||
}
|
||||
|
||||
public async removePackageVersion(pkg: Package, pkgVersion: PackageVersion, skipRefreshPackageManifests = false) {
|
||||
const currentVersions = await this.packageRepository.listPackageVersionNames(pkg.packageId);
|
||||
// only one version, unpublish the package
|
||||
if (currentVersions.length === 1 && currentVersions[0] === pkgVersion.version) {
|
||||
await this.unpublishPackage(pkg);
|
||||
return;
|
||||
}
|
||||
// remove version & update tags
|
||||
await this._removePackageVersionAndDist(pkgVersion);
|
||||
// all versions removed
|
||||
const versions = await this.packageRepository.listPackageVersionNames(pkg.packageId);
|
||||
if (versions.length > 0) {
|
||||
let updateTag: string | undefined;
|
||||
@@ -555,8 +561,6 @@ export class PackageManagerService extends AbstractService {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// unpublish
|
||||
await this.unpublishPackage(pkg, true);
|
||||
}
|
||||
|
||||
public async savePackageTag(pkg: Package, tag: string, version: string, skipEvent = false) {
|
||||
|
||||
1
app/port/config.ts
Normal file
1
app/port/config.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { cnpmcoreConfig } from '../../config/config.default';
|
||||
@@ -27,7 +27,7 @@ type LegacyInfo = {
|
||||
|
||||
type SiteEnvInfo = {
|
||||
sync_model: string;
|
||||
sync_binary: string;
|
||||
sync_binary: boolean;
|
||||
instance_start_time: Date;
|
||||
node_version: string;
|
||||
app_version: string;
|
||||
|
||||
@@ -5,91 +5,162 @@ import OSSClient from 'oss-cnpm';
|
||||
import { patchAjv } from '../app/port/typebox';
|
||||
import { SyncDeleteMode, SyncMode } from '../app/common/constants';
|
||||
|
||||
export const cnpmcoreConfig = {
|
||||
name: 'cnpm',
|
||||
/**
|
||||
* enable hook or not
|
||||
*/
|
||||
hookEnable: false,
|
||||
/**
|
||||
* mac custom hooks count
|
||||
*/
|
||||
hooksLimit: 20,
|
||||
/**
|
||||
* upstream registry url
|
||||
*/
|
||||
sourceRegistry: 'https://registry.npmjs.org',
|
||||
/**
|
||||
* upstream registry is base on `cnpmcore` or not
|
||||
* if your upstream is official npm registry, please turn it off
|
||||
*/
|
||||
sourceRegistryIsCNpm: false,
|
||||
/**
|
||||
* sync upstream first
|
||||
*/
|
||||
syncUpstreamFirst: false,
|
||||
/**
|
||||
* sync upstream timeout, default is 3mins
|
||||
*/
|
||||
sourceRegistrySyncTimeout: 180000,
|
||||
/**
|
||||
* sync task high water size, default is 100
|
||||
*/
|
||||
taskQueueHighWaterSize: 100,
|
||||
/**
|
||||
* sync mode
|
||||
* - none: don't sync npm package
|
||||
* - admin: don't sync npm package,only admin can create sync task by sync contorller.
|
||||
* - all: sync all npm packages
|
||||
* - exist: only sync exist packages, effected when `enableCheckRecentlyUpdated` or `enableChangesStream` is enabled
|
||||
*/
|
||||
syncMode: SyncMode.none,
|
||||
syncDeleteMode: SyncDeleteMode.delete,
|
||||
syncPackageWorkerMaxConcurrentTasks: 10,
|
||||
triggerHookWorkerMaxConcurrentTasks: 10,
|
||||
createTriggerHookWorkerMaxConcurrentTasks: 10,
|
||||
/**
|
||||
* stop syncing these packages in future
|
||||
*/
|
||||
syncPackageBlockList: [] as string[],
|
||||
/**
|
||||
* check recently from https://www.npmjs.com/browse/updated, if use set changesStreamRegistry to cnpmcore,
|
||||
* maybe you should disable it
|
||||
*/
|
||||
enableCheckRecentlyUpdated: true,
|
||||
/**
|
||||
* mirror binary, default is false
|
||||
*/
|
||||
enableSyncBinary: false,
|
||||
/**
|
||||
* sync binary source api, default is `${sourceRegistry}/-/binary`
|
||||
*/
|
||||
syncBinaryFromAPISource: '',
|
||||
/**
|
||||
* enable sync downloads data from source registry https://github.com/cnpm/cnpmcore/issues/108
|
||||
* all three parameters must be configured at the same time to take effect
|
||||
*/
|
||||
enableSyncDownloadData: false,
|
||||
syncDownloadDataSourceRegistry: '',
|
||||
/**
|
||||
* should be YYYY-MM-DD format
|
||||
*/
|
||||
syncDownloadDataMaxDate: '',
|
||||
/**
|
||||
* @see https://github.com/npm/registry-follower-tutorial
|
||||
*/
|
||||
enableChangesStream: false,
|
||||
checkChangesStreamInterval: 500,
|
||||
changesStreamRegistry: 'https://replicate.npmjs.com',
|
||||
/**
|
||||
* handle _changes request mode, default is 'streaming', please set it to 'json' when on cnpmcore registry
|
||||
*/
|
||||
changesStreamRegistryMode: 'streaming',
|
||||
/**
|
||||
* registry url
|
||||
*/
|
||||
registry: 'http://localhost:7001',
|
||||
/**
|
||||
* https://docs.npmjs.com/cli/v6/using-npm/config#always-auth npm <= 6
|
||||
* if `alwaysAuth=true`, all api request required access token
|
||||
*/
|
||||
alwaysAuth: false,
|
||||
/**
|
||||
* white scope list
|
||||
*/
|
||||
allowScopes: [
|
||||
'@cnpm',
|
||||
'@cnpmcore',
|
||||
'@example',
|
||||
],
|
||||
/**
|
||||
* allow publish non-scope package, disable by default
|
||||
*/
|
||||
allowPublishNonScopePackage: false,
|
||||
/**
|
||||
* Public registration is allowed, otherwise only admins can login
|
||||
*/
|
||||
allowPublicRegistration: true,
|
||||
/**
|
||||
* default system admins
|
||||
*/
|
||||
admins: {
|
||||
// name: email
|
||||
cnpmcore_admin: 'admin@cnpmjs.org',
|
||||
},
|
||||
/**
|
||||
* use webauthn for login, https://webauthn.guide/
|
||||
* only support platform authenticators, browser support: https://webauthn.me/browser-support
|
||||
*/
|
||||
enableWebAuthn: false,
|
||||
/**
|
||||
* http response cache control header
|
||||
*/
|
||||
enableCDN: false,
|
||||
/**
|
||||
* if you are using CDN, can override it
|
||||
* it meaning cache 300s on CDN server and client side.
|
||||
*/
|
||||
cdnCacheControlHeader: 'public, max-age=300',
|
||||
/**
|
||||
* if you are using CDN, can set it to 'Accept, Accept-Encoding'
|
||||
*/
|
||||
cdnVaryHeader: 'Accept, Accept-Encoding',
|
||||
/**
|
||||
* store full package version manifests data to database table(package_version_manifests), default is false
|
||||
*/
|
||||
enableStoreFullPackageVersionManifestsToDatabase: false,
|
||||
/**
|
||||
* only support npm as client and npm >= 7.0.0 allow publish action
|
||||
*/
|
||||
enableNpmClientAndVersionCheck: true,
|
||||
/**
|
||||
* sync when package not found, only effect when syncMode = all/exist
|
||||
*/
|
||||
syncNotFound: false,
|
||||
/**
|
||||
* redirect to source registry when package not found
|
||||
*/
|
||||
redirectNotFound: true,
|
||||
/**
|
||||
* enable unpkg features, https://github.com/cnpm/cnpmcore/issues/452
|
||||
*/
|
||||
enableUnpkg: true,
|
||||
};
|
||||
|
||||
export default (appInfo: EggAppConfig) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
|
||||
config.cnpmcore = {
|
||||
name: 'cnpm',
|
||||
hooksLimit: 20,
|
||||
sourceRegistry: 'https://registry.npmjs.org',
|
||||
// upstream registry is base on `cnpmcore` or not
|
||||
// if your upstream is official npm registry, please turn it off
|
||||
sourceRegistryIsCNpm: false,
|
||||
syncUpstreamFirst: false,
|
||||
// 3 mins
|
||||
sourceRegistrySyncTimeout: 180000,
|
||||
taskQueueHighWaterSize: 100,
|
||||
// sync mode
|
||||
// - none: don't sync npm package
|
||||
// - admin: don't sync npm package,only admin can create sync task by sync contorller.
|
||||
// - all: sync all npm packages
|
||||
// - exist: only sync exist packages, effected when `enableCheckRecentlyUpdated` or `enableChangesStream` is enabled
|
||||
syncMode: SyncMode.none,
|
||||
syncDeleteMode: SyncDeleteMode.delete,
|
||||
hookEnable: false,
|
||||
syncPackageWorkerMaxConcurrentTasks: 10,
|
||||
triggerHookWorkerMaxConcurrentTasks: 10,
|
||||
createTriggerHookWorkerMaxConcurrentTasks: 10,
|
||||
// stop syncing these packages in future
|
||||
syncPackageBlockList: [],
|
||||
// check recently from https://www.npmjs.com/browse/updated, if use set changesStreamRegistry to cnpmcore,
|
||||
// maybe you should disable it
|
||||
enableCheckRecentlyUpdated: true,
|
||||
// mirror binary, default is false
|
||||
enableSyncBinary: false,
|
||||
// cnpmcore api: https://r.cnpmjs.org/-/binary
|
||||
syncBinaryFromAPISource: '',
|
||||
// enable sync downloads data from source registry https://github.com/cnpm/cnpmcore/issues/108
|
||||
// all three parameters must be configured at the same time to take effect
|
||||
enableSyncDownloadData: false,
|
||||
syncDownloadDataSourceRegistry: '',
|
||||
syncDownloadDataMaxDate: '', // should be YYYY-MM-DD format
|
||||
// https://github.com/npm/registry-follower-tutorial
|
||||
enableChangesStream: false,
|
||||
checkChangesStreamInterval: 500,
|
||||
changesStreamRegistry: 'https://replicate.npmjs.com',
|
||||
// handle _changes request mode, default is 'streaming', please set it to 'json' when on cnpmcore registry
|
||||
changesStreamRegistryMode: 'streaming',
|
||||
registry: 'http://localhost:7001',
|
||||
// https://docs.npmjs.com/cli/v6/using-npm/config#always-auth npm <= 6
|
||||
// if `alwaysAuth=true`, all api request required access token
|
||||
alwaysAuth: false,
|
||||
// white scope list
|
||||
allowScopes: [
|
||||
'@cnpm',
|
||||
'@cnpmcore',
|
||||
'@example',
|
||||
],
|
||||
// allow publish non-scope package, disable by default
|
||||
allowPublishNonScopePackage: false,
|
||||
// Public registration is allowed, otherwise only admins can login
|
||||
allowPublicRegistration: true,
|
||||
// default system admins
|
||||
admins: {
|
||||
// name: email
|
||||
cnpmcore_admin: 'admin@cnpmjs.org',
|
||||
},
|
||||
// use webauthn for login, https://webauthn.guide/
|
||||
// only support platform authenticators, browser support: https://webauthn.me/browser-support
|
||||
enableWebAuthn: false,
|
||||
// http response cache control header
|
||||
enableCDN: false,
|
||||
// if you are using CDN, can override it
|
||||
// it meaning cache 300s on CDN server and client side.
|
||||
cdnCacheControlHeader: 'public, max-age=300',
|
||||
// if you are using CDN, can set it to 'Accept, Accept-Encoding'
|
||||
cdnVaryHeader: 'Accept, Accept-Encoding',
|
||||
// store full package version manifests data to database table(package_version_manifests), default is false
|
||||
enableStoreFullPackageVersionManifestsToDatabase: false,
|
||||
// only support npm as client and npm >= 7.0.0 allow publish action
|
||||
enableNpmClientAndVersionCheck: true,
|
||||
// sync when package not found, only effect when syncMode = all/exist
|
||||
syncNotFound: false,
|
||||
// redirect to source registry when package not found
|
||||
redirectNotFound: true,
|
||||
// enable unpkg features, https://github.com/cnpm/cnpmcore/issues/452
|
||||
enableUnpkg: true,
|
||||
};
|
||||
config.cnpmcore = cnpmcoreConfig;
|
||||
|
||||
// override config from framework / plugin
|
||||
config.dataDir = join(appInfo.root, '.cnpmcore');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cnpmcore",
|
||||
"version": "3.20.3",
|
||||
"version": "3.21.0",
|
||||
"description": "npm core",
|
||||
"files": [
|
||||
"dist/**/*"
|
||||
|
||||
Reference in New Issue
Block a user