Comments (6)
@jasonkarns would you mind weighing in on this?
from scripty.
@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.
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.
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.
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.
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)
- The scripty.path config is not work. HOT 2
- Bug while sharing scripts via node modules HOT 3
- Update dependency to remove vulnerability. HOT 2
- Scripts Path Not Read With Yarn 3
- PNPM Support HOT 3
- monorepo single config HOT 2
- In MAC, may be unenforceable directory, how can do before running scripts, automatically run chmod + x scripts/path/to/my/script HOT 7
- scripty ERR! It seems you may be running scripty from the command-line directly HOT 1
- pnpm build error, unknown options: 'commitizen_path', 'scripty_path', 'scripty_windowsPath' #
- Scripts fail with Node.js v >=18 HOT 3
- Revive builtIn scripts resolver HOT 2
- Batch scripts skip directories HOT 1
- Sharable scripts via a npm package HOT 3
- Default to silent mode; allow verbose option HOT 1
- Allow directly running using "scripty <target>" HOT 8
- npm proposal for proxying "npm run"
- Script name and content is always printed HOT 3
- Issue while running scripty on windows10 HOT 7
- Options won't work with npm >= 7 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scripty.