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
[NPM]: feat: npm install autosuggests from npms.io #126
Conversation
Really cool idea! I don't know why but it's a lot slower for me, the |
Hey @DannyAziz you can use |
Hey @cstrnt
|
@DannyAziz what npm version do you use? ( |
Having the same error with Node v15.9.0 and NPM v7.5.3 |
npm/cli#2845 |
Hey guys - so this generator is good, however, it would be best to switch over to running a Why? In general, I'd agree with Tim that using https://api-docs.npms.io/ is fast and works for everyone and so we should switch to it. Not gonna merge this PR until that's done |
@falky97 Bump |
Code looks good, either @mattschrage or I will test later today / tomorrow
|
|
Yeah @matt probably fair re npm local installs. The only times I have done it for local files was when I was updating the version number. Main workflow is installing foreign packages |
Overviewdev/npm.ts:Info:Script: function (out) {
if (out.trim() == "") {
return [];
}
try {
const packageContent = JSON.parse(out);
const scripts = packageContent["scripts"];
const figCompletions = packageContent["fig"];
if (scripts) {
const keys = Object.keys(scripts).map((key) => {
return Object.assign(
{},
{ icon: "fig://icon?type=npm" },
figCompletions[key],
{ name: key, insertValue: key }
); // ensure that name and insertValue are defined by "scripts" dict
});
return keys;
}
} catch (e) {}
return [];
} Script: function (out) {
if (out.trim() === "") {
return [];
}
try {
const packageContent = JSON.parse(out);
const dependencies = packageContent["dependencies"];
if (dependencies) {
const dps = Object.keys(dependencies);
return dps.map((pkg) => {
const scope = pkg.indexOf("/") + 1;
if (scope !== -1) {
pkg = pkg.substring(scope);
}
const version = pkg.indexOf("@");
if (version !== -1) {
pkg = pkg.substring(version);
}
return {
name: pkg,
icon: `fig://icon?type=file`,
description: "dependency file",
};
});
}
} catch (e) {}
return [];
} Script: function (out) {
if (out.trim() === "") {
return [];
}
try {
const packageContent = JSON.parse(out);
const dependencies = packageContent["dependencies"];
if (dependencies) {
const dps = Object.keys(dependencies);
return dps.map((pkg) => {
const scope = pkg.indexOf("/") + 1;
if (scope !== -1) {
pkg = pkg.substring(scope);
}
const version = pkg.indexOf("@");
if (version !== -1) {
pkg = pkg.substring(version);
}
return {
name: pkg,
icon: `fig://icon?type=file`,
description: "dependency file",
};
});
}
} catch (e) {}
return [];
} Single Functions:script: function (context) {
if (context[context.length - 1] === "") return "";
const searchTerm = context[context.length - 1];
return `curl -s -H "Accept: application/json" "https://api.npms.io/v2/search?q=${searchTerm}&size=250"`;
} postProcess: function (out) {
return JSON.parse(out).results.map(
(item) =>
({
name: item.package.name,
description: item.package.description,
} as Fig.Suggestion)
) as Fig.Suggestion[];
} trigger: function () {
return true;
} URLs:
|
Hello @DannyAziz,
Please add a 👍 as a reaction to this comment to show that you read this. |
Co-authored-by: Tim Raderschad <tim.raderschad@gmail.com>
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature
What is the current behavior? (You can also link to an open issue here)
Npm install returns packages that are already in the package.json
What is the new behavior (if this is a feature change)?
Uses
npm search
to search as you are typingAdditional info: