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

Feature Request: auto detect and write dependencies #491

Open
daKmoR opened this issue Oct 30, 2022 · 2 comments
Open

Feature Request: auto detect and write dependencies #491

daKmoR opened this issue Oct 30, 2022 · 2 comments

Comments

@daKmoR
Copy link

daKmoR commented Oct 30, 2022

Description

Let's say I have these dependencies in my package which resides within a monorepo

  "dependencies": {
    "@rocket/cli": "^0.20.4",
    "@rocket/components": "^0.2.0",
    "@rocket/engine": "^0.2.7",
  },

now when I execute npm run ts it should run ts in all my "dependencies" (and its dependencies) first...
you can archive it via

  "scripts": {
    "ts": "wireit",
  },
  "wireit": {
    "ts": {
      "command": "tsc --build --pretty",
      "dependencies": [
        "../cli:ts",
        "../components:ts",
        "../engine:ts"
      ],
    }
  }

but it feels like duplicating the dependency tree...

  "dependencies": {
    "@rocket/cli": "^0.20.4",
    "@rocket/components": "^0.2.0",
    "@rocket/engine": "^0.2.7",
  },
  // and 
  "dependencies": [
    "../cli:ts",
    "../components:ts",
    "../engine:ts"
  ],

Don't get me wrong I like that it is very explicit to say what is depending on what... but can get quite hard to maintain as you always need not think of 2 kind of dependencies

Suggestion

Maybe we could introduce a "command" like wireit detect-dependencies.

What it could then do is

  1. go through all dependencies and look if it has an npm command with the same name
  2. if it has then add it to the wireit commands dependencies

Example

This is the starting point

  "dependencies": {
    "@rocket/cli": "^0.20.4",
    "@rocket/components": "^0.2.0",
    "@rocket/engine": "^0.2.7",
  },
  "scripts": {
    "ts": "wireit",
  },
  "wireit": {
    "ts": {
      "command": "tsc --build --pretty",
    }
  }

We execute wireit detect-dependencies and this is what we would get

  "dependencies": {
    "@rocket/cli": "^0.20.4",
    "@rocket/components": "^0.2.0",
    "@rocket/engine": "^0.2.7",
  },
  "scripts": {
    "ts": "wireit",
  },
  "wireit": {
    "ts": {
      "command": "tsc --build --pretty",
      "dependencies": [
        "../cli:ts",
        "../components:ts",
        "../engine:ts"
      ],
    }
  }

This would be sort of a "helper" script to sync dependencies... executing it and verifying would be a manual process.

Would probably be nice to also offer it as "linting"...
And as it's all just "helpers" it could also be "just" in the vs-code extension.

What do you think?

@aomarks
Copy link
Member

aomarks commented Oct 31, 2022

Very interesting idea, thank you!

A related issue is #23, where I had suggested having a way to specify dependencies like this directly with a special syntax.

But I do quite like the idea of doing this, along with potentially other kinds of automatic configuration that updates the package.json, using a lint --fix style command, instead of baking automation directly into the standard execution.

@cefn
Copy link

cefn commented Apr 11, 2023

I found myself following the proposed pattern in a recent experimental monorepo.

I authored routines that either validate or fix the wireit structures in package.json across multiple packages, with logic that reads their dependencies.

These link to a commit from work-in-progress but they show the pattern...

https://github.com/cefn/watchable/blob/55736dd28a8d5030c033926e3bfb9ab6ba1e8c36/tooling/validate/ruleConfig.ts#L41-L79

https://github.com/cefn/watchable/blob/55736dd28a8d5030c033926e3bfb9ab6ba1e8c36/package.json#L19-L20

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

No branches or pull requests

3 participants