@verdaccio/config 9.0.0-next-9.2 → 9.0.0-next-9.4
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/build/_virtual/_rolldown/runtime.js +23 -0
- package/build/_virtual/_rolldown/runtime.mjs +7 -0
- package/build/address.d.ts +1 -1
- package/build/address.js +80 -102
- package/build/address.js.map +1 -1
- package/build/address.mjs +86 -0
- package/build/address.mjs.map +1 -0
- package/build/agent.js +11 -16
- package/build/agent.js.map +1 -1
- package/build/agent.mjs +12 -0
- package/build/agent.mjs.map +1 -0
- package/build/builder.d.ts +2 -1
- package/build/builder.js +58 -58
- package/build/builder.js.map +1 -1
- package/build/builder.mjs +60 -0
- package/build/builder.mjs.map +1 -0
- package/build/conf/default.yaml +6 -0
- package/build/conf/docker.yaml +6 -0
- package/build/conf/index.d.ts +1 -1
- package/build/conf/index.js +9 -11
- package/build/conf/index.js.map +1 -1
- package/build/conf/index.mjs +10 -0
- package/build/conf/index.mjs.map +1 -0
- package/build/config-path.js +152 -163
- package/build/config-path.js.map +1 -1
- package/build/config-path.mjs +169 -0
- package/build/config-path.mjs.map +1 -0
- package/build/config-utils.js +37 -41
- package/build/config-utils.js.map +1 -1
- package/build/config-utils.mjs +40 -0
- package/build/config-utils.mjs.map +1 -0
- package/build/config.d.ts +1 -1
- package/build/config.js +170 -201
- package/build/config.js.map +1 -1
- package/build/config.mjs +171 -0
- package/build/config.mjs.map +1 -0
- package/build/index.js +52 -167
- package/build/index.mjs +14 -0
- package/build/package-access.d.ts +1 -1
- package/build/package-access.js +52 -68
- package/build/package-access.js.map +1 -1
- package/build/package-access.mjs +52 -0
- package/build/package-access.mjs.map +1 -0
- package/build/parse.d.ts +1 -1
- package/build/parse.js +80 -99
- package/build/parse.js.map +1 -1
- package/build/parse.mjs +83 -0
- package/build/parse.mjs.map +1 -0
- package/build/security.d.ts +1 -1
- package/build/security.js +15 -22
- package/build/security.js.map +1 -1
- package/build/security.mjs +16 -0
- package/build/security.mjs.map +1 -0
- package/build/serverSettings.js +10 -15
- package/build/serverSettings.js.map +1 -1
- package/build/serverSettings.mjs +12 -0
- package/build/serverSettings.mjs.map +1 -0
- package/build/token.js +11 -13
- package/build/token.js.map +1 -1
- package/build/token.mjs +13 -0
- package/build/token.mjs.map +1 -0
- package/build/uplinks.d.ts +1 -1
- package/build/uplinks.js +47 -55
- package/build/uplinks.js.map +1 -1
- package/build/uplinks.mjs +50 -0
- package/build/uplinks.mjs.map +1 -0
- package/build/user.d.ts +1 -1
- package/build/user.js +42 -37
- package/build/user.js.map +1 -1
- package/build/user.mjs +48 -0
- package/build/user.mjs.map +1 -0
- package/package.json +19 -8
- package/build/index.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fromJStoYAML } from "./parse.mjs";
|
|
2
|
+
import "./index.mjs";
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
//#region src/builder.ts
|
|
5
|
+
/**
|
|
6
|
+
* Helper configuration builder constructor, used to build the configuration for testing or
|
|
7
|
+
* programatically creating a configuration.
|
|
8
|
+
*/
|
|
9
|
+
var ConfigBuilder = class ConfigBuilder {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = merge(config, {
|
|
13
|
+
uplinks: {},
|
|
14
|
+
packages: {},
|
|
15
|
+
security: {}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static build(config) {
|
|
19
|
+
return new ConfigBuilder(config);
|
|
20
|
+
}
|
|
21
|
+
addPackageAccess(pattern, pkgAccess) {
|
|
22
|
+
this.config.packages[pattern] = pkgAccess;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
addUplink(id, uplink) {
|
|
26
|
+
this.config.uplinks[id] = uplink;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
addSecurity(security) {
|
|
30
|
+
this.config.security = merge(this.config.security, security);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
addAuth(auth) {
|
|
34
|
+
this.config.auth = merge(this.config.auth, auth);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
addLogger(log) {
|
|
38
|
+
this.config.log = log;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
addServer(server) {
|
|
42
|
+
this.config.server = merge(this.config.server, server);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
addStorage(storage) {
|
|
46
|
+
if (typeof storage === "string") this.config.storage = storage;
|
|
47
|
+
else this.config.store = storage;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
getConfig() {
|
|
51
|
+
return this.config;
|
|
52
|
+
}
|
|
53
|
+
getAsYaml() {
|
|
54
|
+
return fromJStoYAML(this.config);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ConfigBuilder as default };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=builder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash';\n\nimport type {\n AuthConf,\n ConfigYaml,\n LoggerConfigItem,\n PackageAccessYaml,\n Security,\n ServerSettingsConf,\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: LoggerConfigItem) {\n this.config.log = log;\n return this;\n }\n\n public addServer(server: Partial<ServerSettingsConf>) {\n this.config.server = merge(this.config.server, server);\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":";;;;;;;;AAkBA,IAAqB,gBAArB,MAAqB,cAAc;CACjC;CAEA,YAAmB,QAA8B;AAC/C,OAAK,SAAS,MAAM,QAAQ;GAAE,SAAS,EAAE;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,CAAC;;CAG1E,OAAc,MAAM,QAA6C;AAC/D,SAAO,IAAI,cAAc,OAAO;;CAGlC,iBAAwB,SAAiB,WAA8B;AAErE,OAAK,OAAO,SAAS,WAAW;AAChC,SAAO;;CAGT,UAAiB,IAAY,QAAoB;AAC/C,OAAK,OAAO,QAAQ,MAAM;AAC1B,SAAO;;CAGT,YAAmB,UAA6B;AAC9C,OAAK,OAAO,WAAW,MAAM,KAAK,OAAO,UAAU,SAAS;AAC5D,SAAO;;CAGT,QAAe,MAAyB;AACtC,OAAK,OAAO,OAAO,MAAM,KAAK,OAAO,MAAM,KAAK;AAChD,SAAO;;CAGT,UAAiB,KAAuB;AACtC,OAAK,OAAO,MAAM;AAClB,SAAO;;CAGT,UAAiB,QAAqC;AACpD,OAAK,OAAO,SAAS,MAAM,KAAK,OAAO,QAAQ,OAAO;AACtD,SAAO;;CAGT,WAAkB,SAA0B;AAC1C,MAAI,OAAO,YAAY,SACrB,MAAK,OAAO,UAAU;MAEtB,MAAK,OAAO,QAAQ;AAEtB,SAAO;;CAGT,YAA+B;AAC7B,SAAO,KAAK;;CAGd,YAA2B;AACzB,SAAO,aAAa,KAAK,OAAO"}
|
package/build/conf/default.yaml
CHANGED
|
@@ -120,6 +120,12 @@ packages:
|
|
|
120
120
|
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
|
|
121
121
|
server:
|
|
122
122
|
keepAliveTimeout: 60
|
|
123
|
+
# Controls how requests with dotfile path segments (e.g. /.env, /.well-known/) are handled.
|
|
124
|
+
# 'deny' returns 403, 'ignore' returns 404 (default), 'allow' passes through.
|
|
125
|
+
dotfiles: ignore
|
|
126
|
+
# Hide static file requests (/-/static/*) from pino logs.
|
|
127
|
+
# They remain visible via DEBUG=verdaccio:middleware:log.
|
|
128
|
+
# hideStaticLogs: true
|
|
123
129
|
# The pluginPrefix replaces the default plugins prefix which is `verdaccio`. Please don't include `-`. If `something` is provided
|
|
124
130
|
# the resolved package will be `something-xxxx`.
|
|
125
131
|
# pluginPrefix: something
|
package/build/conf/docker.yaml
CHANGED
|
@@ -116,6 +116,12 @@ packages:
|
|
|
116
116
|
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
|
|
117
117
|
server:
|
|
118
118
|
keepAliveTimeout: 60
|
|
119
|
+
# Controls how requests with dotfile path segments (e.g. /.env, /.well-known/) are handled.
|
|
120
|
+
# 'deny' returns 403, 'ignore' returns 404 (default), 'allow' passes through.
|
|
121
|
+
dotfiles: ignore
|
|
122
|
+
# Hide static file requests (/-/static/*) from pino logs.
|
|
123
|
+
# They remain visible via DEBUG=verdaccio:middleware:log.
|
|
124
|
+
# hideStaticLogs: true
|
|
119
125
|
# The pluginPrefix replaces the default plugins prefix which is `verdaccio`. Please don't include `-`. If `something` is provided
|
|
120
126
|
# the resolved package will be `something-xxxx`.
|
|
121
127
|
# pluginPrefix: something
|
package/build/conf/index.d.ts
CHANGED
package/build/conf/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _nodePath = require("node:path");
|
|
8
|
-
var _parse = require("../parse");
|
|
9
|
-
function getDefaultConfig(fileName = 'default.yaml') {
|
|
10
|
-
const file = (0, _nodePath.join)(__dirname, `./${fileName}`);
|
|
11
|
-
return (0, _parse.parseConfigFile)(file);
|
|
1
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_parse = require("../parse.js");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
//#region src/conf/index.ts
|
|
5
|
+
function getDefaultConfig(fileName = "default.yaml") {
|
|
6
|
+
return require_parse.parseConfigFile((0, node_path.join)(__dirname, `./${fileName}`));
|
|
12
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
10
|
+
|
|
13
11
|
//# sourceMappingURL=index.js.map
|
package/build/conf/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/conf/index.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { parseConfigFile } from '../parse';\n\nexport function getDefaultConfig(fileName: string = 'default.yaml') {\n const file = join(__dirname, `./${fileName}`);\n return parseConfigFile(file);\n}\n"],"mappings":";;;;AAIA,SAAgB,iBAAiB,WAAmB,gBAAgB;AAElE,QAAO,cAAA,iBAAA,GAAA,UAAA,MADW,WAAW,KAAK,WAAW,CACjB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parseConfigFile } from "../parse.mjs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
//#region src/conf/index.ts
|
|
4
|
+
function getDefaultConfig(fileName = "default.yaml") {
|
|
5
|
+
return parseConfigFile(join(__dirname, `./${fileName}`));
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getDefaultConfig };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/conf/index.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { parseConfigFile } from '../parse';\n\nexport function getDefaultConfig(fileName: string = 'default.yaml') {\n const file = join(__dirname, `./${fileName}`);\n return parseConfigFile(file);\n}\n"],"mappings":";;;AAIA,SAAgB,iBAAiB,WAAmB,gBAAgB;AAElE,QAAO,gBADM,KAAK,WAAW,KAAK,WAAW,CACjB"}
|
package/build/config-path.js
CHANGED
|
@@ -1,187 +1,176 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
name: 'verdaccio'
|
|
19
|
-
};
|
|
20
|
-
const debug = (0, _debug.default)('verdaccio:config:config-path');
|
|
21
|
-
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_config_utils = require("./config-utils.js");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_runtime.__toESM(debug);
|
|
5
|
+
let lodash = require("lodash");
|
|
6
|
+
lodash = require_runtime.__toESM(lodash);
|
|
7
|
+
let node_fs = require("node:fs");
|
|
8
|
+
node_fs = require_runtime.__toESM(node_fs);
|
|
9
|
+
let node_os = require("node:os");
|
|
10
|
+
node_os = require_runtime.__toESM(node_os);
|
|
11
|
+
let node_path = require("node:path");
|
|
12
|
+
node_path = require_runtime.__toESM(node_path);
|
|
13
|
+
//#region src/config-path.ts
|
|
14
|
+
var CONFIG_FILE = "config.yaml";
|
|
15
|
+
var XDG = "xdg";
|
|
16
|
+
var pkgJSON = { name: "verdaccio" };
|
|
17
|
+
var debug$1 = (0, debug.default)("verdaccio:config:config-path");
|
|
22
18
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
* Find and get the first config file that match.
|
|
20
|
+
* @return {String} the config file path
|
|
21
|
+
*/
|
|
26
22
|
function findConfigFile(configPath) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
debug('no previous location found, creating a new one');
|
|
48
|
-
debug('generating the first match path location %s', configPaths[0].path);
|
|
49
|
-
return createConfigFile(configPaths[0]).path;
|
|
23
|
+
debug$1("searching for config file %o", configPath);
|
|
24
|
+
if (typeof configPath !== "undefined") {
|
|
25
|
+
const configLocation = node_path.default.resolve(configPath);
|
|
26
|
+
debug$1("custom location %s", configLocation);
|
|
27
|
+
return configLocation;
|
|
28
|
+
}
|
|
29
|
+
const configPaths = getConfigPaths();
|
|
30
|
+
debug$1("%o posible locations found", configPaths.length);
|
|
31
|
+
if (configPaths.length === 0) {
|
|
32
|
+
debug$1("no configuration files can be processed");
|
|
33
|
+
throw new Error("no configuration files can be processed");
|
|
34
|
+
}
|
|
35
|
+
const primaryConf = lodash.default.find(configPaths, (configLocation) => require_config_utils.fileExists(configLocation.path));
|
|
36
|
+
if (typeof primaryConf !== "undefined") {
|
|
37
|
+
debug$1("at least one primary location detected at %s", primaryConf?.path);
|
|
38
|
+
return primaryConf.path;
|
|
39
|
+
}
|
|
40
|
+
debug$1("no previous location found, creating a new one");
|
|
41
|
+
debug$1("generating the first match path location %s", configPaths[0].path);
|
|
42
|
+
return createConfigFile(configPaths[0]).path;
|
|
50
43
|
}
|
|
51
44
|
function createConfigFile(configLocation) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
createConfigFolder(configLocation);
|
|
46
|
+
const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());
|
|
47
|
+
node_fs.default.writeFileSync(configLocation.path, defaultConfig);
|
|
48
|
+
return configLocation;
|
|
56
49
|
}
|
|
57
50
|
function readDefaultConfig() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
const pathDefaultConf = node_path.default.resolve(__dirname, "conf/default.yaml");
|
|
52
|
+
try {
|
|
53
|
+
debug$1("the path of default config used from %s", pathDefaultConf);
|
|
54
|
+
node_fs.default.accessSync(pathDefaultConf, node_fs.default.constants.R_OK);
|
|
55
|
+
debug$1("configuration file has enough permissions for reading");
|
|
56
|
+
} catch {
|
|
57
|
+
debug$1("configuration file does not have enough permissions for reading");
|
|
58
|
+
throw new TypeError("configuration file does not have enough permissions for reading");
|
|
59
|
+
}
|
|
60
|
+
return node_fs.default.readFileSync(pathDefaultConf, "utf8");
|
|
68
61
|
}
|
|
69
62
|
function createConfigFolder(configLocation) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
debug(`folder %o created`, folder);
|
|
63
|
+
const folder = node_path.default.dirname(configLocation.path);
|
|
64
|
+
debug$1(`creating default config file folder at %o`, folder);
|
|
65
|
+
node_fs.default.mkdirSync(folder, { recursive: true });
|
|
66
|
+
debug$1(`folder %o created`, folder);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
* Update the storage links to the new location if it is necessary.
|
|
70
|
+
* @param configLocation
|
|
71
|
+
* @param defaultConfig
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
84
74
|
function updateStorageLinks(configLocation, defaultConfig) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
|
|
100
|
-
}
|
|
101
|
-
debug(`could not find a previous storage location, skip override`);
|
|
102
|
-
return defaultConfig;
|
|
75
|
+
debug$1("checking storage links for %s and type %s", configLocation.path, configLocation.type);
|
|
76
|
+
if (configLocation.type !== XDG) {
|
|
77
|
+
debug$1(`skip storage override for %s`, configLocation.type);
|
|
78
|
+
return defaultConfig;
|
|
79
|
+
}
|
|
80
|
+
let dataDir = process.env.XDG_DATA_HOME || node_path.default.join(process.env.HOME, ".local", "share");
|
|
81
|
+
if (require_config_utils.folderExists(dataDir)) {
|
|
82
|
+
debug$1(`previous storage located`);
|
|
83
|
+
debug$1(`update storage links to %s`, dataDir);
|
|
84
|
+
dataDir = node_path.default.resolve(node_path.default.join(dataDir, pkgJSON.name, "storage"));
|
|
85
|
+
return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
|
|
86
|
+
}
|
|
87
|
+
debug$1(`could not find a previous storage location, skip override`);
|
|
88
|
+
return defaultConfig;
|
|
103
89
|
}
|
|
104
|
-
|
|
105
90
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
* Return a list of configuration locations by platform.
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
109
94
|
function getConfigPaths() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
95
|
+
return [
|
|
96
|
+
getXDGDirectory(),
|
|
97
|
+
getWindowsDirectory(),
|
|
98
|
+
getRelativeDefaultDirectory(),
|
|
99
|
+
getOldDirectory()
|
|
100
|
+
].reduce(function(acc, currentValue) {
|
|
101
|
+
if (typeof currentValue !== "undefined") {
|
|
102
|
+
debug$1("posible directory path generated %s for type %s", currentValue?.path, currentValue.type);
|
|
103
|
+
acc.push(currentValue);
|
|
104
|
+
}
|
|
105
|
+
return acc;
|
|
106
|
+
}, []);
|
|
118
107
|
}
|
|
119
|
-
|
|
120
108
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
109
|
+
* Get XDG_CONFIG_HOME or HOME location (usually unix)
|
|
110
|
+
*
|
|
111
|
+
* The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
|
|
112
|
+
* which aims to standardize the locations where applications store configuration files and other
|
|
113
|
+
* user-specific data on Unix-like operating systems.
|
|
114
|
+
*
|
|
115
|
+
*
|
|
116
|
+
*
|
|
117
|
+
* https://specifications.freedesktop.org/basedir-spec/latest/
|
|
118
|
+
*
|
|
119
|
+
*
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
var getXDGDirectory = () => {
|
|
123
|
+
const xDGConfigPath = process.env.XDG_CONFIG_HOME || process.env.HOME && node_path.default.join(process.env.HOME, ".config");
|
|
124
|
+
debug$1("XDGConfig folder path %s", xDGConfigPath);
|
|
125
|
+
if (xDGConfigPath && require_config_utils.folderExists(xDGConfigPath)) {
|
|
126
|
+
debug$1("XDGConfig folder path %s", xDGConfigPath);
|
|
127
|
+
return {
|
|
128
|
+
path: node_path.default.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),
|
|
129
|
+
type: XDG
|
|
130
|
+
};
|
|
131
|
+
}
|
|
144
132
|
};
|
|
145
|
-
|
|
146
133
|
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
134
|
+
* Detect windows location, APPDATA
|
|
135
|
+
* usually something like C:\User\<Build User>\AppData\Local
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
var getWindowsDirectory = () => {
|
|
139
|
+
if (node_os.default.platform() === "win32" && process.env.APPDATA && require_config_utils.folderExists(process.env.APPDATA)) {
|
|
140
|
+
debug$1("windows appdata folder path %s", process.env.APPDATA);
|
|
141
|
+
return {
|
|
142
|
+
path: node_path.default.resolve(node_path.default.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
|
|
143
|
+
type: "win"
|
|
144
|
+
};
|
|
145
|
+
}
|
|
159
146
|
};
|
|
160
|
-
|
|
161
147
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
148
|
+
* Return relative directory, this is the default.
|
|
149
|
+
* It will cretate config in your {currentLocation/verdaccio/config.yaml}
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
var getRelativeDefaultDirectory = () => {
|
|
153
|
+
const relativePath = node_path.default.resolve(node_path.default.join(".", pkgJSON.name, CONFIG_FILE));
|
|
154
|
+
debug$1("relative folder path %s", relativePath);
|
|
155
|
+
return {
|
|
156
|
+
path: relativePath,
|
|
157
|
+
type: "def"
|
|
158
|
+
};
|
|
173
159
|
};
|
|
174
|
-
|
|
175
160
|
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
161
|
+
* This should never happens, consider it DEPRECATED
|
|
162
|
+
* @returns
|
|
163
|
+
*/
|
|
164
|
+
var getOldDirectory = () => {
|
|
165
|
+
const oldPath = node_path.default.resolve(node_path.default.join(".", CONFIG_FILE));
|
|
166
|
+
debug$1("old folder path %s", oldPath);
|
|
167
|
+
return {
|
|
168
|
+
path: oldPath,
|
|
169
|
+
type: "old"
|
|
170
|
+
};
|
|
186
171
|
};
|
|
172
|
+
//#endregion
|
|
173
|
+
exports.findConfigFile = findConfigFile;
|
|
174
|
+
exports.readDefaultConfig = readDefaultConfig;
|
|
175
|
+
|
|
187
176
|
//# sourceMappingURL=config-path.js.map
|
package/build/config-path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-path.js","names":["_debug","_interopRequireDefault","require","_lodash","_nodeFs","_nodeOs","_nodePath","_configUtils","e","__esModule","default","CONFIG_FILE","XDG","pkgJSON","name","debug","buildDebug","findConfigFile","configPath","configLocation","path","resolve","configPaths","getConfigPaths","length","Error","primaryConf","_","find","fileExists","createConfigFile","createConfigFolder","defaultConfig","updateStorageLinks","readDefaultConfig","fs","writeFileSync","pathDefaultConf","__dirname","accessSync","constants","R_OK","TypeError","readFileSync","folder","dirname","mkdirSync","recursive","type","dataDir","process","env","XDG_DATA_HOME","join","HOME","folderExists","replace","listPaths","getXDGDirectory","getWindowsDirectory","getRelativeDefaultDirectory","getOldDirectory","reduce","acc","currentValue","push","xDGConfigPath","XDG_CONFIG_HOME","os","platform","APPDATA","relativePath","oldPath"],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: 'xdg' | 'win' | 'win32' | 'def' | 'old';\n};\n\nconst debug = buildDebug('verdaccio:config:config-path');\n\n/**\n * Find and get the first config file that match.\n * @return {String} the config file path\n */\nfunction findConfigFile(configPath?: string): string {\n debug('searching for config file %o', configPath);\n if (typeof configPath !== 'undefined') {\n const configLocation = path.resolve(configPath);\n debug('custom location %s', configLocation);\n return configLocation;\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (configPaths.length === 0) {\n debug('no configuration files can be processed');\n // this should never happens\n throw new Error('no configuration files can be processed');\n }\n\n // find the first location that already exist\n const primaryConf: SetupDirectory | void = _.find(configPaths, (configLocation: SetupDirectory) =>\n fileExists(configLocation.path)\n );\n\n if (typeof primaryConf !== 'undefined') {\n debug('at least one primary location detected at %s', primaryConf?.path);\n return primaryConf.path;\n }\n debug('no previous location found, creating a new one');\n debug('generating the first match path location %s', configPaths[0].path);\n return createConfigFile(configPaths[0]).path;\n}\n\nfunction createConfigFile(configLocation: SetupDirectory): SetupDirectory {\n createConfigFolder(configLocation);\n\n const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());\n\n fs.writeFileSync(configLocation.path, defaultConfig);\n\n return configLocation;\n}\n\nexport function readDefaultConfig(): string {\n const pathDefaultConf: string = path.resolve(__dirname, 'conf/default.yaml');\n try {\n debug('the path of default config used from %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n debug('configuration file has enough permissions for reading');\n } catch {\n debug('configuration file does not have enough permissions for reading');\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n\n return fs.readFileSync(pathDefaultConf, 'utf8');\n}\n\nfunction createConfigFolder(configLocation: SetupDirectory): void {\n const folder = path.dirname(configLocation.path);\n debug(`creating default config file folder at %o`, folder);\n fs.mkdirSync(folder, { recursive: true });\n debug(`folder %o created`, folder);\n}\n\n/**\n * Update the storage links to the new location if it is necessary.\n * @param configLocation\n * @param defaultConfig\n * @returns\n */\nfunction updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {\n debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);\n if (configLocation.type !== XDG) {\n debug(`skip storage override for %s`, configLocation.type);\n return defaultConfig;\n }\n\n // $XDG_DATA_HOME defines the base directory relative to which user specific data\n // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default\n // equal to $HOME/.local/share should be used.\n let dataDir =\n process.env.XDG_DATA_HOME || path.join(process.env.HOME as string, '.local', 'share');\n if (folderExists(dataDir)) {\n debug(`previous storage located`);\n debug(`update storage links to %s`, dataDir);\n dataDir = path.resolve(path.join(dataDir, pkgJSON.name, 'storage'));\n return defaultConfig.replace(/^storage: .\\/storage$/m, `storage: ${dataDir}`);\n }\n debug(`could not find a previous storage location, skip override`);\n return defaultConfig;\n}\n\n/**\n * Return a list of configuration locations by platform.\n * @returns\n */\nfunction getConfigPaths(): SetupDirectory[] {\n const listPaths: (SetupDirectory | void)[] = [\n getXDGDirectory(),\n getWindowsDirectory(),\n getRelativeDefaultDirectory(),\n getOldDirectory(),\n ];\n\n return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {\n if (typeof currentValue !== 'undefined') {\n debug(\n 'posible directory path generated %s for type %s',\n currentValue?.path,\n currentValue.type\n );\n acc.push(currentValue);\n }\n return acc;\n }, [] as SetupDirectory[]);\n}\n\n/**\n * Get XDG_CONFIG_HOME or HOME location (usually unix)\n *\n * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,\n * which aims to standardize the locations where applications store configuration files and other\n * user-specific data on Unix-like operating systems.\n *\n *\n *\n * https://specifications.freedesktop.org/basedir-spec/latest/\n *\n *\n * @returns\n */\nconst getXDGDirectory = (): SetupDirectory | void => {\n const xDGConfigPath =\n process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));\n debug('XDGConfig folder path %s', xDGConfigPath);\n if (xDGConfigPath && folderExists(xDGConfigPath)) {\n debug('XDGConfig folder path %s', xDGConfigPath);\n return {\n path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),\n type: XDG,\n };\n }\n};\n\n/**\n * Detect windows location, APPDATA\n * usually something like C:\\User\\<Build User>\\AppData\\Local\n * @returns\n */\nconst getWindowsDirectory = (): SetupDirectory | void => {\n if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('windows appdata folder path %s', process.env.APPDATA);\n return {\n path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),\n type: 'win',\n };\n }\n};\n\n/**\n * Return relative directory, this is the default.\n * It will cretate config in your {currentLocation/verdaccio/config.yaml}\n * @returns\n */\nconst getRelativeDefaultDirectory = (): SetupDirectory => {\n const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));\n debug('relative folder path %s', relativePath);\n return {\n path: relativePath,\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n const oldPath = path.resolve(path.join('.', CONFIG_FILE));\n debug('old folder path %s', oldPath);\n return {\n path: oldPath,\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA0D,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1D,MAAMG,WAAW,GAAG,aAAa;AACjC,MAAMC,GAAG,GAAG,KAAK;AAEjB,MAAMC,OAAO,GAAG;EACdC,IAAI,EAAE;AACR,CAAC;AAOD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,IAAI,EAAE;EACR,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMa,eAAe,GAAGA,CAAA,KAAsB;EAC5C,MAAMW,OAAO,GAAGpD,iBAAI,CAACC,OAAO,CAACD,iBAAI,CAACiC,IAAI,CAAC,GAAG,EAAE1C,WAAW,CAAC,CAAC;EACzDI,KAAK,CAAC,oBAAoB,EAAEyD,OAAO,CAAC;EACpC,OAAO;IACLpD,IAAI,EAAEoD,OAAO;IACbxB,IAAI,EAAE;EACR,CAAC;AACH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"config-path.js","names":[],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: 'xdg' | 'win' | 'win32' | 'def' | 'old';\n};\n\nconst debug = buildDebug('verdaccio:config:config-path');\n\n/**\n * Find and get the first config file that match.\n * @return {String} the config file path\n */\nfunction findConfigFile(configPath?: string): string {\n debug('searching for config file %o', configPath);\n if (typeof configPath !== 'undefined') {\n const configLocation = path.resolve(configPath);\n debug('custom location %s', configLocation);\n return configLocation;\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (configPaths.length === 0) {\n debug('no configuration files can be processed');\n // this should never happens\n throw new Error('no configuration files can be processed');\n }\n\n // find the first location that already exist\n const primaryConf: SetupDirectory | void = _.find(configPaths, (configLocation: SetupDirectory) =>\n fileExists(configLocation.path)\n );\n\n if (typeof primaryConf !== 'undefined') {\n debug('at least one primary location detected at %s', primaryConf?.path);\n return primaryConf.path;\n }\n debug('no previous location found, creating a new one');\n debug('generating the first match path location %s', configPaths[0].path);\n return createConfigFile(configPaths[0]).path;\n}\n\nfunction createConfigFile(configLocation: SetupDirectory): SetupDirectory {\n createConfigFolder(configLocation);\n\n const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());\n\n fs.writeFileSync(configLocation.path, defaultConfig);\n\n return configLocation;\n}\n\nexport function readDefaultConfig(): string {\n const pathDefaultConf: string = path.resolve(__dirname, 'conf/default.yaml');\n try {\n debug('the path of default config used from %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n debug('configuration file has enough permissions for reading');\n } catch {\n debug('configuration file does not have enough permissions for reading');\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n\n return fs.readFileSync(pathDefaultConf, 'utf8');\n}\n\nfunction createConfigFolder(configLocation: SetupDirectory): void {\n const folder = path.dirname(configLocation.path);\n debug(`creating default config file folder at %o`, folder);\n fs.mkdirSync(folder, { recursive: true });\n debug(`folder %o created`, folder);\n}\n\n/**\n * Update the storage links to the new location if it is necessary.\n * @param configLocation\n * @param defaultConfig\n * @returns\n */\nfunction updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {\n debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);\n if (configLocation.type !== XDG) {\n debug(`skip storage override for %s`, configLocation.type);\n return defaultConfig;\n }\n\n // $XDG_DATA_HOME defines the base directory relative to which user specific data\n // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default\n // equal to $HOME/.local/share should be used.\n let dataDir =\n process.env.XDG_DATA_HOME || path.join(process.env.HOME as string, '.local', 'share');\n if (folderExists(dataDir)) {\n debug(`previous storage located`);\n debug(`update storage links to %s`, dataDir);\n dataDir = path.resolve(path.join(dataDir, pkgJSON.name, 'storage'));\n return defaultConfig.replace(/^storage: .\\/storage$/m, `storage: ${dataDir}`);\n }\n debug(`could not find a previous storage location, skip override`);\n return defaultConfig;\n}\n\n/**\n * Return a list of configuration locations by platform.\n * @returns\n */\nfunction getConfigPaths(): SetupDirectory[] {\n const listPaths: (SetupDirectory | void)[] = [\n getXDGDirectory(),\n getWindowsDirectory(),\n getRelativeDefaultDirectory(),\n getOldDirectory(),\n ];\n\n return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {\n if (typeof currentValue !== 'undefined') {\n debug(\n 'posible directory path generated %s for type %s',\n currentValue?.path,\n currentValue.type\n );\n acc.push(currentValue);\n }\n return acc;\n }, [] as SetupDirectory[]);\n}\n\n/**\n * Get XDG_CONFIG_HOME or HOME location (usually unix)\n *\n * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,\n * which aims to standardize the locations where applications store configuration files and other\n * user-specific data on Unix-like operating systems.\n *\n *\n *\n * https://specifications.freedesktop.org/basedir-spec/latest/\n *\n *\n * @returns\n */\nconst getXDGDirectory = (): SetupDirectory | void => {\n const xDGConfigPath =\n process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));\n debug('XDGConfig folder path %s', xDGConfigPath);\n if (xDGConfigPath && folderExists(xDGConfigPath)) {\n debug('XDGConfig folder path %s', xDGConfigPath);\n return {\n path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),\n type: XDG,\n };\n }\n};\n\n/**\n * Detect windows location, APPDATA\n * usually something like C:\\User\\<Build User>\\AppData\\Local\n * @returns\n */\nconst getWindowsDirectory = (): SetupDirectory | void => {\n if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('windows appdata folder path %s', process.env.APPDATA);\n return {\n path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),\n type: 'win',\n };\n }\n};\n\n/**\n * Return relative directory, this is the default.\n * It will cretate config in your {currentLocation/verdaccio/config.yaml}\n * @returns\n */\nconst getRelativeDefaultDirectory = (): SetupDirectory => {\n const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));\n debug('relative folder path %s', relativePath);\n return {\n path: relativePath,\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n const oldPath = path.resolve(path.join('.', CONFIG_FILE));\n debug('old folder path %s', oldPath);\n return {\n path: oldPath,\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAM,cAAc;AACpB,IAAM,MAAM;AAEZ,IAAM,UAAU,EACd,MAAM,aACP;AAOD,IAAM,WAAA,GAAA,MAAA,SAAmB,+BAA+B;;;;;AAMxD,SAAS,eAAe,YAA6B;AACnD,SAAM,gCAAgC,WAAW;AACjD,KAAI,OAAO,eAAe,aAAa;EACrC,MAAM,iBAAiB,UAAA,QAAK,QAAQ,WAAW;AAC/C,UAAM,sBAAsB,eAAe;AAC3C,SAAO;;CAGT,MAAM,cAAgC,gBAAgB;AACtD,SAAM,8BAA8B,YAAY,OAAO;AACvD,KAAI,YAAY,WAAW,GAAG;AAC5B,UAAM,0CAA0C;AAEhD,QAAM,IAAI,MAAM,0CAA0C;;CAI5D,MAAM,cAAqC,OAAA,QAAE,KAAK,cAAc,mBAC9D,qBAAA,WAAW,eAAe,KAAK,CAChC;AAED,KAAI,OAAO,gBAAgB,aAAa;AACtC,UAAM,gDAAgD,aAAa,KAAK;AACxE,SAAO,YAAY;;AAErB,SAAM,iDAAiD;AACvD,SAAM,gDAAgD,YAAY,GAAG,KAAK;AAC1E,QAAO,iBAAiB,YAAY,GAAG,CAAC;;AAG1C,SAAS,iBAAiB,gBAAgD;AACxE,oBAAmB,eAAe;CAElC,MAAM,gBAAgB,mBAAmB,gBAAgB,mBAAmB,CAAC;AAE7E,SAAA,QAAG,cAAc,eAAe,MAAM,cAAc;AAEpD,QAAO;;AAGT,SAAgB,oBAA4B;CAC1C,MAAM,kBAA0B,UAAA,QAAK,QAAQ,WAAW,oBAAoB;AAC5E,KAAI;AACF,UAAM,2CAA2C,gBAAgB;AACjE,UAAA,QAAG,WAAW,iBAAiB,QAAA,QAAG,UAAU,KAAK;AACjD,UAAM,wDAAwD;SACxD;AACN,UAAM,kEAAkE;AACx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