Skip to content

Commit 13d019b

Browse files
d3xter666matz3RandomByte
authored
[FIX] Migrate from libnpmconfig to @npmcli/config (#618)
Fixes: SAP/ui5-tooling#786 JIRA: CPOUI5FOUNDATION-631 --------- Co-authored-by: Matthias Oßwald <[email protected]> Co-authored-by: Merlin Beutlberger <[email protected]>
1 parent 496acd1 commit 13d019b

File tree

5 files changed

+264
-172
lines changed

5 files changed

+264
-172
lines changed

lib/ui5Framework/npm/Registry.js

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,56 +41,61 @@ class Registry {
4141
throw new Error(`Failed to extract package ${pkgName}@${version}: ${err.message}`);
4242
}
4343
}
44+
4445
async _getPacote() {
45-
return {
46-
pacote: (await import("pacote")).default,
47-
pacoteOptions: await this._getPacoteOptions()
48-
};
49-
}
50-
async _getPacoteOptions() {
51-
if (!this._npmConfig) {
52-
const {default: libnpmconfig} = await import("libnpmconfig");
53-
const opts = {
54-
cache: this._cacheDir,
46+
if (this._pGetPacote) {
47+
return this._pGetPacote;
48+
}
49+
return this._pGetPacote = (async () => {
50+
return {
51+
pacote: (await import("pacote")).default,
52+
pacoteOptions: await this._getPacoteOptions()
5553
};
56-
const config = libnpmconfig.read(opts, {
57-
cwd: this._cwd
58-
}).toJSON();
54+
})();
55+
}
5956

60-
// Rename https-proxy to httpsProxy so that it is picked up by npm-registry-fetch (via pacote)
61-
if (config["https-proxy"]) {
62-
config.httpsProxy = config["https-proxy"];
63-
delete config["https-proxy"];
64-
}
57+
async _getPacoteOptions() {
58+
const {default: Config} = await import("@npmcli/config");
59+
const {
60+
default: {flatten, definitions, shorthands, defaults},
61+
} = await import("@npmcli/config/lib/definitions/index.js");
6562

66-
if (!config.proxy && !config.httpsProxy) {
67-
// Disable usage of shared keep-alive agents unless a proxy is configured
68-
// which only works with agents.
63+
const configuration = new Config({
64+
cwd: this._cwd,
65+
npmPath: this._cwd,
66+
definitions,
67+
flatten,
68+
shorthands,
69+
defaults
70+
});
6971

70-
// make-fetch-happen uses a hard-coded 15 seconds freeSocketTimeout
71-
// that can be easily reached (Error: Socket timeout) and there doesn't
72-
// seem to be another way to disable or increase it.
73-
// Also see: https://github.com/node-modules/agentkeepalive/issues/106
74-
config.agent = false;
75-
}
72+
await configuration.load(); // Reads through the configurations
73+
const config = configuration.flat; // JSON. Formatted via "flatten"
7674

77-
log.verbose(`Using npm configuration (extract):`);
78-
// Do not log full configuration as it may contain authentication tokens
79-
logConfig(config, "registry");
80-
logConfig(config, "@sapui5:registry");
81-
logConfig(config, "@openui5:registry");
82-
logConfig(config, "proxy");
83-
logConfig(config, "httpsProxy");
84-
logConfig(config, "globalconfig");
85-
logConfig(config, "userconfig");
86-
logConfig(config, "cache");
87-
logConfig(config, "cwd");
75+
if (!config.proxy && !config.httpsProxy) {
76+
// Disable usage of shared keep-alive agents unless a proxy is configured
77+
// which only works with agents.
8878

89-
this._npmConfig = config;
79+
// make-fetch-happen uses a hard-coded 15 seconds freeSocketTimeout
80+
// that can be easily reached (Error: Socket timeout) and there doesn't
81+
// seem to be another way to disable or increase it.
82+
// Also see: https://github.com/node-modules/agentkeepalive/issues/106
83+
config.agent = false;
9084
}
9185

92-
// Use cached config
93-
return this._npmConfig;
86+
log.verbose(`Using npm configuration (extract):`);
87+
// Do not log full configuration as it may contain authentication tokens
88+
logConfig(config, "registry");
89+
logConfig(config, "@sapui5:registry");
90+
logConfig(config, "@openui5:registry");
91+
logConfig(config, "proxy");
92+
logConfig(config, "httpsProxy");
93+
logConfig(config, "globalconfig");
94+
logConfig(config, "userconfig");
95+
logConfig(config, "cache");
96+
logConfig(config, "cwd");
97+
98+
return config;
9499
}
95100
}
96101

package-lock.json

Lines changed: 127 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"globby": "^13.2.0",
130130
"graceful-fs": "^4.2.11",
131131
"js-yaml": "^4.1.0",
132-
"libnpmconfig": "^1.2.1",
132+
"@npmcli/config": "^6.2.1",
133133
"lockfile": "^1.0.4",
134134
"make-fetch-happen": "^11.1.1",
135135
"node-stream-zip": "^1.15.0",

0 commit comments

Comments
 (0)