@verdaccio/config 7.0.0-next-7.12 → 7.0.0-next-7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +69 -0
- package/build/builder.js +2 -3
- package/build/builder.js.map +1 -1
- package/package.json +3 -3
- package/src/builder.ts +1 -2
- package/test/builder.spec.ts +53 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @verdaccio/config
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next-7.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @verdaccio/core@7.0.0-next-7.14
|
|
8
|
+
- @verdaccio/utils@7.0.0-next-7.14
|
|
9
|
+
|
|
10
|
+
## 7.0.0-next-7.13
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a99a4bb: fix config builder erroring when passed partial config
|
|
15
|
+
- @verdaccio/core@7.0.0-next-7.13
|
|
16
|
+
- @verdaccio/utils@7.0.0-next-7.13
|
|
17
|
+
|
|
3
18
|
## 7.0.0-next-7.12
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# @verdaccio/config
|
|
2
2
|
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The `@verdaccio/config` package provides a powerful configuration builder constructor for programmatically creating configuration objects for Verdaccio, a lightweight private npm proxy registry. With this package, users can easily manage various configuration aspects such as package access, uplinks, security settings, authentication, logging, and storage options.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can install via npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @verdaccio/config
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
To start using `@verdaccio/config`, import the `ConfigBuilder` class and begin constructing your configuration object:
|
|
18
|
+
|
|
19
|
+
## `ConfigBuilder` constructor
|
|
20
|
+
|
|
21
|
+
The `ConfigBuilder` class is a helper configuration builder constructor used to programmatically create configuration objects for testing or other purposes.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
|
|
25
|
+
import { ConfigBuilder } from '@verdaccio/config';
|
|
26
|
+
|
|
27
|
+
// Create a new configuration builder instance
|
|
28
|
+
const config = ConfigBuilder.build({ security: { api: { legacy: false } } });
|
|
29
|
+
|
|
30
|
+
// Add package access configuration
|
|
31
|
+
configBuilder.addPackageAccess('@scope/*', { access: 'read', publish: 'write' });
|
|
32
|
+
|
|
33
|
+
// Add an uplink configuration
|
|
34
|
+
configBuilder.addUplink('npmjs', { url: 'https://registry.npmjs.org/' });
|
|
35
|
+
|
|
36
|
+
// Add security configuration
|
|
37
|
+
configBuilder.addSecurity({ allow_offline: true });
|
|
38
|
+
|
|
39
|
+
// Get the configuration object
|
|
40
|
+
const config = configBuilder.getConfig();
|
|
41
|
+
|
|
42
|
+
// Get the configuration yaml text
|
|
43
|
+
const config = configBuilder.getAsYaml();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Methods
|
|
47
|
+
|
|
48
|
+
- `addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml)`: Adds package access configuration.
|
|
49
|
+
- `addUplink(id: string, uplink: UpLinkConf)`: Adds an uplink configuration.
|
|
50
|
+
- `addSecurity(security: Partial<Security>)`: Adds security configuration.
|
|
51
|
+
- `addAuth(auth: Partial<AuthConf>)`: Adds authentication configuration.
|
|
52
|
+
- `addLogger(log: LoggerConfItem)`: Adds logger configuration.
|
|
53
|
+
- `addStorage(storage: string | object)`: Adds storage configuration.
|
|
54
|
+
- `getConfig(): ConfigYaml`: Retrieves the configuration object.
|
|
55
|
+
- `getAsYaml(): string`: Retrieves the configuration object as YAML format.
|
|
56
|
+
|
|
57
|
+
## `getDefaultConfig`
|
|
58
|
+
|
|
59
|
+
This method is available in the package's index and retrieves the default configuration object.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { getDefaultConfig } from '@verdaccio/config';
|
|
63
|
+
|
|
64
|
+
const defaultConfig = getDefaultConfig();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Other Methods
|
|
68
|
+
|
|
69
|
+
- `fromJStoYAML(config: ConfigYaml): string`: Converts a JavaScript configuration object to YAML format.
|
|
70
|
+
- `parseConfigFile(filePath: string): ConfigYaml`: Parses a configuration file from the specified path and returns the configuration object.
|
|
71
|
+
|
|
3
72
|
### License
|
|
4
73
|
|
|
5
74
|
Verdaccio is [MIT licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)
|
package/build/builder.js
CHANGED
|
@@ -12,12 +12,11 @@ var _ = require(".");
|
|
|
12
12
|
*/
|
|
13
13
|
class ConfigBuilder {
|
|
14
14
|
constructor(config) {
|
|
15
|
-
|
|
16
|
-
this.config = config !== null && config !== void 0 ? config : {
|
|
15
|
+
this.config = (0, _lodash.merge)(config, {
|
|
17
16
|
uplinks: {},
|
|
18
17
|
packages: {},
|
|
19
18
|
security: {}
|
|
20
|
-
};
|
|
19
|
+
});
|
|
21
20
|
}
|
|
22
21
|
static build(config) {
|
|
23
22
|
return new ConfigBuilder(config);
|
package/build/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","names":["_lodash","require","_","ConfigBuilder","constructor","config","uplinks","packages","security","build","addPackageAccess","pattern","pkgAccess","addUplink","id","uplink","addSecurity","
|
|
1
|
+
{"version":3,"file":"builder.js","names":["_lodash","require","_","ConfigBuilder","constructor","config","merge","uplinks","packages","security","build","addPackageAccess","pattern","pkgAccess","addUplink","id","uplink","addSecurity","addAuth","auth","addLogger","log","addStorage","storage","store","getConfig","getAsYaml","fromJStoYAML","exports","default"],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash';\n\nimport {\n AuthConf,\n ConfigYaml,\n LoggerConfItem,\n PackageAccessYaml,\n Security,\n UpLinkConf,\n} from '@verdaccio/types';\n\nimport { fromJStoYAML } from '.';\n\n/**\n * Helper configuration builder constructor, used to build the configuration for testing or\n * programatically creating a configuration.\n */\nexport default class ConfigBuilder {\n private config: ConfigYaml;\n\n public constructor(config?: Partial<ConfigYaml>) {\n this.config = merge(config, { uplinks: {}, packages: {}, security: {} });\n }\n\n public static build(config?: Partial<ConfigYaml>): ConfigBuilder {\n return new ConfigBuilder(config);\n }\n\n public addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml) {\n // @ts-ignore\n this.config.packages[pattern] = pkgAccess;\n return this;\n }\n\n public addUplink(id: string, uplink: UpLinkConf) {\n this.config.uplinks[id] = uplink;\n return this;\n }\n\n public addSecurity(security: Partial<Security>) {\n this.config.security = merge(this.config.security, security);\n return this;\n }\n\n public addAuth(auth: Partial<AuthConf>) {\n this.config.auth = merge(this.config.auth, auth);\n return this;\n }\n\n public addLogger(log: LoggerConfItem) {\n this.config.log = log;\n return this;\n }\n\n public addStorage(storage: string | object) {\n if (typeof storage === 'string') {\n this.config.storage = storage;\n } else {\n this.config.store = storage;\n }\n return this;\n }\n\n public getConfig(): ConfigYaml {\n return this.config;\n }\n\n public getAsYaml(): string {\n return fromJStoYAML(this.config) as string;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAWA,IAAAC,CAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACe,MAAME,aAAa,CAAC;EAG1BC,WAAWA,CAACC,MAA4B,EAAE;IAC/C,IAAI,CAACA,MAAM,GAAG,IAAAC,aAAK,EAACD,MAAM,EAAE;MAAEE,OAAO,EAAE,CAAC,CAAC;MAAEC,QAAQ,EAAE,CAAC,CAAC;MAAEC,QAAQ,EAAE,CAAC;IAAE,CAAC,CAAC;EAC1E;EAEA,OAAcC,KAAKA,CAACL,MAA4B,EAAiB;IAC/D,OAAO,IAAIF,aAAa,CAACE,MAAM,CAAC;EAClC;EAEOM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verdaccio/config",
|
|
3
|
-
"version": "7.0.0-next-7.
|
|
3
|
+
"version": "7.0.0-next-7.14",
|
|
4
4
|
"description": "logger",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"node": ">=12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@verdaccio/core": "7.0.0-next-7.
|
|
33
|
-
"@verdaccio/utils": "7.0.0-next-7.
|
|
32
|
+
"@verdaccio/core": "7.0.0-next-7.14",
|
|
33
|
+
"@verdaccio/utils": "7.0.0-next-7.14",
|
|
34
34
|
"debug": "4.3.4",
|
|
35
35
|
"js-yaml": "4.1.0",
|
|
36
36
|
"lodash": "4.17.21",
|
package/src/builder.ts
CHANGED
|
@@ -19,8 +19,7 @@ export default class ConfigBuilder {
|
|
|
19
19
|
private config: ConfigYaml;
|
|
20
20
|
|
|
21
21
|
public constructor(config?: Partial<ConfigYaml>) {
|
|
22
|
-
|
|
23
|
-
this.config = config ?? { uplinks: {}, packages: {}, security: {} };
|
|
22
|
+
this.config = merge(config, { uplinks: {}, packages: {}, security: {} });
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
public static build(config?: Partial<ConfigYaml>): ConfigBuilder {
|
package/test/builder.spec.ts
CHANGED
|
@@ -67,5 +67,58 @@ describe('Config builder', () => {
|
|
|
67
67
|
.addStorage('/tmp/verdaccio')
|
|
68
68
|
.addSecurity({ api: { legacy: true } });
|
|
69
69
|
expect(config.getAsYaml()).toMatchSnapshot();
|
|
70
|
+
|
|
71
|
+
expect(config.getConfig()).toEqual({
|
|
72
|
+
uplinks: {
|
|
73
|
+
upstream: {
|
|
74
|
+
url: 'https://registry.verdaccio.org',
|
|
75
|
+
},
|
|
76
|
+
upstream2: {
|
|
77
|
+
url: 'https://registry.verdaccio.org',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
packages: {
|
|
81
|
+
'upstream/*': {
|
|
82
|
+
access: 'public',
|
|
83
|
+
publish: 'foo, bar',
|
|
84
|
+
unpublish: 'foo, bar',
|
|
85
|
+
proxy: 'some',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
security: {
|
|
89
|
+
api: {
|
|
90
|
+
legacy: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
log: {
|
|
94
|
+
level: 'info',
|
|
95
|
+
type: 'stdout',
|
|
96
|
+
format: 'json',
|
|
97
|
+
},
|
|
98
|
+
storage: '/tmp/verdaccio',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('should merge configurations', () => {
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
const config = ConfigBuilder.build({ security: { api: { legacy: false } } });
|
|
105
|
+
config.addSecurity({ web: { verify: {}, sign: { algorithm: 'ES256' } } });
|
|
106
|
+
config.addStorage('/tmp/verdaccio');
|
|
107
|
+
expect(config.getConfig()).toEqual({
|
|
108
|
+
security: {
|
|
109
|
+
api: {
|
|
110
|
+
legacy: false,
|
|
111
|
+
},
|
|
112
|
+
web: {
|
|
113
|
+
verify: {},
|
|
114
|
+
sign: {
|
|
115
|
+
algorithm: 'ES256',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
uplinks: {},
|
|
120
|
+
packages: {},
|
|
121
|
+
storage: '/tmp/verdaccio',
|
|
122
|
+
});
|
|
70
123
|
});
|
|
71
124
|
});
|