AngelMunoz / Perla

A cross-platform tool for unbundled front-end development that doesn't depend on Node or requires you to install a complex toolchain
https://perla-docs.web.app/
MIT License
131 stars 12 forks source link

add list subcommand #46

Closed ThisFunctionalTom closed 3 years ago

ThisFunctionalTom commented 3 years ago

Adding list subcommand to perla cli. The idea is to use it in femto for version resolution but to be independent of perla.jsonc.lock file format.

AngelMunoz commented 3 years ago

First of all THANK YOU! I really appreaciate the time you are taking to send these PRs!

I like this Idea, but I think the correct file to look for is perla.jsonc which usually contains the dependencies as well but these are not repeated take for example this lock file (it's on the docs branch)

{
  "imports": {
    "@shoelace-style/shoelace": "https://cdn.skypack.dev/pin/@shoelace-style/shoelace@v2.0.0-beta.60-eDIQV0EHf9n8X4vd3EMT/mode=imports,min/optimized/@shoelace-style/shoelace.js",
    "@shoelace-style/shoelace/dist/react/": "https://cdn.skypack.dev/pin/@shoelace-style/shoelace@v2.0.0-beta.60-eDIQV0EHf9n8X4vd3EMT/mode=imports,min/unoptimized/dist/react/",
    "@shoelace-style/shoelace/dist/utilities/": "https://cdn.skypack.dev/pin/@shoelace-style/shoelace@v2.0.0-beta.60-eDIQV0EHf9n8X4vd3EMT/mode=imports,min/unoptimized/dist/utilities/",
    "highlight.js/lib/core.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/core.js",
    "highlight.js/lib/languages/javascript.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/javascript.js",
    "highlight.js/lib/languages/plaintext.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/plaintext.js",
    "highlight.js/lib/languages/fsharp.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/fsharp.js",
    "highlight.js/lib/languages/bash.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/bash.js",
    "highlight.js/lib/languages/json.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/json.js",
    "highlight.js/lib/languages/xml.js": "https://ga.jspm.io/npm:highlight.js@11.3.1/lib/languages/xml.js",
    "markdown-it": "https://ga.jspm.io/npm:markdown-it@12.2.0/index.js",
    "navigo": "https://cdn.skypack.dev/pin/navigo@v8.11.1-P7FrCxiJCiPJPMdihh6j/mode=imports,min/optimized/navigo.js",
    "react": "https://cdn.skypack.dev/pin/react@v17.0.1-yH0aYV1FOvoIPeKBbHxg/mode=imports,min/optimized/react.js",
    "react-dom": "https://cdn.skypack.dev/pin/react-dom@v17.0.1-oZ1BXZ5opQ1DbTh7nu9r/mode=imports,min/optimized/react-dom.js",
    "rxjs": "https://cdn.skypack.dev/pin/rxjs@v7.4.0-Kfsr0poLPzx4M3FtCZC1/mode=imports,min/optimized/rxjs.js"
  },
  "scopes": {
    "https://ga.jspm.io/": {
      "entities/lib/maps/entities.json": "https://ga.jspm.io/npm:entities@2.1.0/lib/maps/entities.json.js",
      "linkify-it": "https://ga.jspm.io/npm:linkify-it@3.0.3/index.js",
      "mdurl": "https://ga.jspm.io/npm:mdurl@1.0.1/index.js",
      "punycode": "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.12/nodelibs/browser/punycode.js",
      "uc.micro": "https://ga.jspm.io/npm:uc.micro@1.0.6/index.js",
      "uc.micro/categories/Cc/regex": "https://ga.jspm.io/npm:uc.micro@1.0.6/categories/Cc/regex.js",
      "uc.micro/categories/P/regex": "https://ga.jspm.io/npm:uc.micro@1.0.6/categories/P/regex.js",
      "uc.micro/categories/Z/regex": "https://ga.jspm.io/npm:uc.micro@1.0.6/categories/Z/regex.js",
      "uc.micro/properties/Any/regex": "https://ga.jspm.io/npm:uc.micro@1.0.6/properties/Any/regex.js"
    }
  }
}

you may get repeated dependencies if I'm understanding the code correctly, feel free to tell me if I'm wrong

Also some packges might be aliased e.g.

perla add -p lodash@3 -a lodash3 and would get saved as lodash3 dependency both in the lock and the perla.jsonc

what do you think?

ThisFunctionalTom commented 3 years ago

Somehow I thought that I do not have package versions in perla.jsonc and that was the reason to use the lock file. I fixed this now and get following output in the docs directory:

Installed packages (alias: packageName@version)

@shoelace-style/shoelace: @shoelace-style/shoelace@2.0.0
highlight.js: highlight.js@11.3.1
markdown-it: markdown-it@12.2.0
navigo: navigo@8.11.1
react: react@17.0.1
react-dom: react-dom@17.0.1
rxjs: rxjs@7.4.0

and following package.json

{
  "dependencies": {
    "@shoelace-style/shoelace": "2.0.0",
    "highlight.js": "11.3.1",
    "markdown-it": "12.2.0",
    "navigo": "8.11.1",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "rxjs": "7.4.0"
  }
}

What do you think? Is this OK?

AngelMunoz commented 3 years ago

Yes this is a great approach I wanted to do something like this for #35 but I think you took it already a step into that direction the output seems to match the dependencies correctly

AngelMunoz commented 3 years ago

Thank you for this! Looks great if you are going to try adding support in femto or similar, you just need to be sure to track aliased dependencies in our case we use different names to have the same dependency but different versions which is not something npm supports example: react@16 aliased to react-sixteen and react in the same application, react would point to latest