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

feat(yarn): add options #1612

Merged
merged 9 commits into from
Oct 11, 2022
Merged

feat(yarn): add options #1612

merged 9 commits into from
Oct 11, 2022

Conversation

vatana7
Copy link
Contributor

@vatana7 vatana7 commented Oct 10, 2022

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Adding more specs to yarn

Important
This is a code solution submitted for Closes #1611

@withfig-bot
Copy link
Collaborator

withfig-bot commented Oct 10, 2022

Overview

src/yarn.ts:

Info:

Script:
yarn config list
postProcess(function):

 function (out) {
    if (out.trim() == "") {
      return [];
    }

    try {
      const startIndex = out.indexOf("{");
      const endIndex = out.indexOf("}");
      let output = out.substring(startIndex, endIndex + 1);
      // TODO: fix hacky code
      // reason: JSON parse was not working without double quotes
      output = output
        .replace(/\'/gi, '"')
        .replace("lastUpdateCheck", '"lastUpdateCheck"')
        .replace("registry", '"lastUpdateCheck"');
      const configObject = JSON.parse(output);
      if (configObject) {
        return Object.keys(configObject).map((key) => ({ name: key }));
      }
    } catch (e) {}

    return [];
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out, context = []) {
    if (out.trim() === "") {
      return [];
    }

    try {
      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 = context.some((current) => current === pkgName);
          return !isListed;
        })
        .map((pkgName) => ({
          name: pkgName,
          icon: "📦",
          description: dependencies[pkgName]
            ? "dependency"
            : optionalDependencies[pkgName]
            ? "optionalDependency"
            : "devDependency",
        }));
    } catch (e) {
      console.error(e);
      return [];
    }
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
script(function):

 function (context) {
    if (context[context.length - 1] === "") return "";
    const searchTerm = "create-" + context[context.length - 1];
    return `curl -s -H "Accept: application/json" "https://api.npms.io/v2/search?q=${searchTerm}&size=20"`;
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out) {
    try {
      return JSON.parse(out).results.map(
        (item) =>
          ({
            name: item.package.name.substring(7),
            description: item.package.description,
          } as Fig.Suggestion)
      ) as Fig.Suggestion[];
    } catch (e) {
      return [];
    }
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out: string) {
                    if (out.trim() == "") {
                      return [];
                    }
                    try {
                      const packageContent = JSON.parse(out);
                      const scripts = packageContent["scripts"];
                      if (scripts) {
                        return Object.keys(scripts).map((script) => ({
                          name: script,
                        }));
                      }
                    } catch (e) {}
                    return [];
                  }

URLs:

  • https://api.npms.io/v2/search?q=

@withfig-bot
Copy link
Collaborator

Hello @vatana7,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments include the args property (args: {})?
  • Are all options modular? E.g. -a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

@vatana7 vatana7 changed the title Update yarn feat: yarn specs Oct 10, 2022
@vatana7 vatana7 changed the title feat: yarn specs feat: yarn specs Oct 10, 2022
Copy link
Contributor

@fedeci fedeci left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I left a few things to get fixed before merging this in.

src/yarn.ts Outdated Show resolved Hide resolved
src/yarn.ts Outdated Show resolved Hide resolved
src/yarn.ts Outdated Show resolved Hide resolved
src/yarn.ts Outdated Show resolved Hide resolved
src/yarn.ts Outdated Show resolved Hide resolved
src/yarn.ts Outdated Show resolved Hide resolved
@vatana7
Copy link
Contributor Author

vatana7 commented Oct 11, 2022

Thanks! Can you label this as hacktoberfest PR please 🤟🏻

@clo4
Copy link
Contributor

clo4 commented Oct 11, 2022

@vatana7 PRs are automatically counted for hacktoberfest because the repo itself has the label 🙂

vatana7 and others added 6 commits October 11, 2022 10:55
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
@vatana7
Copy link
Contributor Author

vatana7 commented Oct 11, 2022

@separaterecords Everything should be able to merge now. Thanks for the suggestion!

@clo4
Copy link
Contributor

clo4 commented Oct 11, 2022

Just one thing to fix up first! Either prettier or eslint is unhappy. Easy fix: npx eslint --fix src/yarn.ts; npx prettier -w src/yarn.ts

@vatana7
Copy link
Contributor Author

vatana7 commented Oct 11, 2022

What version of node does this project use?

@fedeci
Copy link
Contributor

fedeci commented Oct 11, 2022

That's not strictly relevant. I believe node@16 is good.

@clo4
Copy link
Contributor

clo4 commented Oct 11, 2022

Any version of node should be fine for this. Personally I just use the latest (node@18) and only change per project if required

@vatana7
Copy link
Contributor Author

vatana7 commented Oct 11, 2022

I have run both command and made changes. Can you take a look at it again?

Copy link
Contributor

@fedeci fedeci left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +1299 to +1301
args: {
name: "<scope:team> <user>",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
args: {
name: "<scope:team> <user>",
},
args: [
{
name: "<scope:team>",
},
{
name: "<user>",
},
],

@fedeci fedeci changed the title feat: yarn specs feat(yarn): add options Oct 11, 2022
@fedeci fedeci merged commit 027504d into withfig:master Oct 11, 2022
@vatana7 vatana7 deleted the update-yarn branch October 13, 2022 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[YARN] Missing Specs
4 participants