-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Update npm to use the cli for package and version queries #2356
base: master
Are you sure you want to change the base?
Conversation
Overviewsrc/npm.ts:Info:Single Functions:custom: async function (tokens, executeShellCommand) {
if (!tokens.includes("-g") && !tokens.includes("--global")) {
const { stdout: npmPrefix } = await executeShellCommand({
command: "npm",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: ["prefix"],
});
const { stdout: out } = await executeShellCommand({
command: "cat",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: [`${npmPrefix}/package.json`],
});
const packageContent = JSON.parse(out);
const dependencies = packageContent["dependencies"] ?? {};
const devDependencies = packageContent["devDependencies"];
const optionalDependencies = packageContent["optionalDependencies"] ?? {};
Object.assign(dependencies, devDependencies, optionalDependencies);
return Object.keys(dependencies)
.filter((pkgName) => {
const isListed = tokens.some((current) => current === pkgName);
return !isListed;
})
.map((pkgName) => ({
name: pkgName,
icon: "📦",
description: dependencies[pkgName]
? "dependency"
: optionalDependencies[pkgName]
? "optionalDependency"
: "devDependency",
}));
} else {
const { stdout } = await executeShellCommand({
command: "bash",
args: ["-c", "ls -1 `npm root -g`"],
});
return stdout.split("\n").map((name) => ({
name,
icon: "📦",
description: "Global dependency",
}));
}
} postProcess: function (out, [npmClient]) {
if (out.trim() == "") {
return [];
}
try {
const packageContent = JSON.parse(out);
const scripts = packageContent["scripts"];
const figCompletions = packageContent["fig"] || {};
if (scripts) {
return Object.entries(scripts).map(([scriptName, scriptContents]) => {
const icon =
npmClient === "yarn"
? "fig://icon?type=yarn"
: "fig://icon?type=npm";
const customScripts: Fig.Suggestion = figCompletions[scriptName];
return {
name: scriptName,
icon,
description: scriptContents as string,
priority: 51,
/**
* If there are custom definitions for the scripts
* we want to override the default values
* */
...customScripts,
};
});
}
} catch (e) {
console.error(e);
}
return [];
} |
Hello @bondz,
Please add a 👍 as a reaction to this comment to show that you read this. |
This could potentially break I don't have enough information about the tool. |
@grant0417 @mschrage any changes you'd like me to make? |
I think the changes are good, I just need to stress test them and ensure we dont have any regressions. Will try to do this soon. |
Fixes #2255
Tested locally with public and scoped packages. Also, fixes an issue where scoped packages would not previously show up because the
@
symbol was not considered part of the search.