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
26 changes: 14 additions & 12 deletions lib/ui5Framework/npm/Registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ class Registry {
}
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.

};
const config = libnpmconfig.read(opts, {
cwd: this._cwd
}).toJSON();
const {default: Config} = await import("@npmcli/config");
const {
default: {flatten, definitions, shorthands, defaults},
} = await import("@npmcli/config/lib/definitions/index.js");

// 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"];
}
const configuration = new Config({
npmPath: this._cwd,
RandomByte marked this conversation as resolved.
Show resolved Hide resolved
definitions,
flatten,
shorthands,
defaults
});

await configuration.load(); // Reads through the configurations
const config = configuration.flat; // JSON. Formatted via "flatten"

if (!config.proxy && !config.httpsProxy) {
// Disable usage of shared keep-alive agents unless a proxy is configured
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
31 changes: 20 additions & 11 deletions test/lib/graph/helpers/ui5Framework.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,29 @@ test.beforeEach(async (t) => {
manifest: sinon.stub()
};

class Config {
static get typeDefs() {
return {};
}

async load() {}

get flat() {
return {};
}
}
sinon.stub(Config.prototype, "flat").value({
registry: "https://registry.fake",
cache: path.join(ui5FrameworkBaseDir, "cacache"),
proxy: ""
});

t.context.Registry = await esmock.p("../../../../lib/ui5Framework/npm/Registry.js", {
"@ui5/logger": ui5Logger,
"pacote": t.context.pacote,
"libnpmconfig": {
read: sinon.stub().returns({
toJSON: () => {
return {
registry: "https://registry.fake",
cache: path.join(ui5FrameworkBaseDir, "cacache"),
proxy: ""
};
}
})
},
"@npmcli/config": {
"default": Config
}
});

const AbstractInstaller = await esmock.p("../../../../lib/ui5Framework/AbstractInstaller.js", {
Expand Down
Loading