Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Migrate from libnpmconfig to @npmcli/config #618

Merged
merged 16 commits into from
Jun 27, 2023
Merged
87 changes: 46 additions & 41 deletions lib/ui5Framework/npm/Registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,61 @@ class Registry {
throw new Error(`Failed to extract package ${pkgName}@${version}: ${err.message}`);
}
}

async _getPacote() {
return {
pacote: (await import("pacote")).default,
pacoteOptions: await this._getPacoteOptions()
};
}
async _getPacoteOptions() {
if (!this._npmConfig) {
const {default: libnpmconfig} = await import("libnpmconfig");
const opts = {
cache: this._cacheDir,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a regression in this PR which removes the usage of a separate cacache dir within our .ui5 data directory.
With this PR the default cache of npm is unsed instead of our separate cache directory. I'll push a fix.

if (this._pGetPacote) {
return this._pGetPacote;
}
return this._pGetPacote = (async () => {
return {
pacote: (await import("pacote")).default,
pacoteOptions: await this._getPacoteOptions()
};
const config = libnpmconfig.read(opts, {
cwd: this._cwd
}).toJSON();
})();
}

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

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

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

log.verbose(`Using npm configuration (extract):`);
// Do not log full configuration as it may contain authentication tokens
logConfig(config, "registry");
logConfig(config, "@sapui5:registry");
logConfig(config, "@openui5:registry");
logConfig(config, "proxy");
logConfig(config, "httpsProxy");
logConfig(config, "globalconfig");
logConfig(config, "userconfig");
logConfig(config, "cache");
logConfig(config, "cwd");
if (!config.proxy && !config.httpsProxy) {
// Disable usage of shared keep-alive agents unless a proxy is configured
// which only works with agents.

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

// Use cached config
return this._npmConfig;
log.verbose(`Using npm configuration (extract):`);
// Do not log full configuration as it may contain authentication tokens
logConfig(config, "registry");
logConfig(config, "@sapui5:registry");
logConfig(config, "@openui5:registry");
logConfig(config, "proxy");
logConfig(config, "httpsProxy");
logConfig(config, "globalconfig");
logConfig(config, "userconfig");
logConfig(config, "cache");
logConfig(config, "cwd");

return config;
}
}

Expand Down
188 changes: 127 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"globby": "^13.2.0",
"graceful-fs": "^4.2.11",
"js-yaml": "^4.1.0",
"libnpmconfig": "^1.2.1",
"@npmcli/config": "^6.2.1",
"lockfile": "^1.0.4",
"make-fetch-happen": "^11.1.1",
"node-stream-zip": "^1.15.0",
Expand Down
Loading