Giter Club home page Giter Club logo

Comments (6)

searls avatar searls commented on July 23, 2024

@jasonkarns would you mind weighing in on this?

from scripty.

jasonkarns avatar jasonkarns commented on July 23, 2024

@jimbasilio Scripty supports sharing scripts via modules, which should accomplish the use-case you described: https://github.com/testdouble/scripty/tree/00cbfad0fc66f294712fcce2dd5d513ae58af590#sharing-scripts-via-node-modules

The module(s) should have their own script directory of scripts, and in the app's package.json, tell scripty (with the scripty.modules array) that "module X" should be included in the search for matching scripts. Scripts found in the app (or by the path setting) take precedence over those provided by modules.

For instance, given the following package.json in the app:

{
  "name": "my-app",
  "devDependencies": {
    "@my-org/helper-module": "*",
    "scripty": "^2.0.0-0"
  },
  "scripts": {
    "foo": "scripty",
    "bar": "scripty",
    "baz": "scripty"
  },
  "scripty": {
    "modules": ["@my-org/helper-module"]
  }
}

Add given the app has:

script/
  foo
  baz

and @my-org/helper-module has:

script/
  bar
  baz

In the above example:

  • npm run foo would run ./script/foo from the app (foo only exists in the app)
  • npm run bar would run ./node_modules/@my-org/helper-module/script/bar (bar only exists in the helper module)
  • npm run baz would run ./script/bar from the app (baz exists in both app and helper module, but the app script takes precedence)

from scripty.

jimbasilio avatar jimbasilio commented on July 23, 2024

Thanks for the reply @searls and @jasonkarns.

I think the difference is I'm looking for the path to be an array for LOCAL files. The modules are useful for npm dependencies but if I want multiple local paths to take precedence before npm, currently that's not possible.

"scripty": {
    "path": [
      "scripts",
      "src/lib/tools/scripty-scripts"
    ],
},

from scripty.

jasonkarns avatar jasonkarns commented on July 23, 2024

I don't think that's a use case we'd want to support since it cuts against the grain for how deps are expected to be managed in node apps.

Since you mentioned the "app" taking precedence over the other directory, I'm assuming this means the two directories of scripts are coming from different git repositories? Presumably, the "tools" directory is a package of sorts that is meant to be shared among many apps? (or teams?) So making it a proper node module is the Right Way™ to go with the flow for node apps. (It needn't be published to npm to be a devDep. It merely needs a package.json to be treated as a node module. You could point to it from your private git host (or github), if you're using git. Or you could point to it using a local file path if using some other means to share the code. Even for monorepos, you'd have a package.json in each package in the repo, with devDeps pointing to each other by relative path. (Indeed, this is a first class feature in Yarn: workspaces.)

Regardless, some suggestions that might work as a workaround:

  • symlink the scripts you want the app to "pull in" from the other location
  • add a package.json file in "src/lib/tools" and then you can add it to app as a devDep, regardless how that directory is distributed

from scripty.

jimbasilio avatar jimbasilio commented on July 23, 2024

I have to support both windows and unix so the symlink is a bit more difficult.

What the request really boils down to is to support an array for the paths configuration. That would allow multiple local folders for scripty to pull from before it goes to the npm modules for external shared scripts.

Your second suggestion about the second package.json is interesting though and I hadn't thought about that. I don't really love the idea of burying dependencies within a top level package, feels too hidden.

That said, it certainly may work. I'll give it a whirl.

from scripty.

jimbasilio avatar jimbasilio commented on July 23, 2024

I'll close this issue.

Thanks for the dialog, it helped me restructure some things.

FWIW: I do like the idea of having an array for local paths to find scripts in (independent of the npm module feature). But I understand not wanting to complicate this.

from scripty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.