Comments (12)
I guess it's like doing the same thing over and over again, why yarn doesn't simply embed/use @verdaccio and support in their development instead.
from node-app-root-path.
Hm, yeah. It seems like we'll need new heuristics. Sadly, it looks like PnP will fundamentally break the way this library works…
Luckily, our fallback strategy of using require.main.filename
should continue to work in most cases, but it's not ideal.
from node-app-root-path.
Yeah, that's true. I have played around a bit with require.main
and it's definitely not bullet proof, especially when running tests.
from node-app-root-path.
Yeah, test-runners and anything else that inject themselves before your app will break that method. We may need to just check for those cases and rely on require.main more heavily, though…
from node-app-root-path.
FYI with PnP it should just be a matter of doing this:
const pnp = process.versions.pnp
? require('pnpapi')
: null;
const appRoot = pnp
? pnp.getPackageInformation(pnp.topLevel).packageLocation
: null;
from node-app-root-path.
This package seems to be checking for package.json
instead of node_modules
: https://github.com/sindresorhus/pkg-dir
Would that work? Is it too simple/naive and doesn't work in some cases?
from node-app-root-path.
Good suggestion @benface. I've played around with looking for package.json. It seems a bit less robust than node_modules in my testing.
For example, if you are in a path inside node_modules, you might assume your current directory is the root because it has a package.json file when really you want the parent directory (the one that has node_modules in it).
For example:
/some/path/project/node_modules/mocha/package.json
/some/path/project/package.json
from node-app-root-path.
Oh, ok so it wouldn't work for task runners / test frameworks because those run from their own directory?
from node-app-root-path.
Note that the Yarn cache is (in most cases for now) outside of the project folder. So if you simply traverse upwards until you find the top-most node_modules
/ package.json
, the only one you'll find are your own.
For a perfect integration, I recommend my snippet above 🙂
from node-app-root-path.
Another thing to consider is that yarn
allows to override node_modules
location:
# .yarnrc file in project root
--modules-folder /path/to/node_modules/elsewhere
I'm disappointed. I thought app-root-path
is doing something smarter than making assumptions about its own location in a filesystem.
from node-app-root-path.
Look here:
lint-staged/lint-staged#477
from node-app-root-path.
Thanks @arcanis — 2.2.0 adds pnp support.
from node-app-root-path.
Related Issues (20)
- Webpack warning: Critical dependency: the request of a dependency is an expression HOT 4
- Support for yarn workspaces HOT 8
- npm package.json version != github repo version HOT 1
- Path resolution in npm linked modules report module and not root app path. HOT 6
- New version broke webpack build with TypeORM HOT 3
- Auto including index.js HOT 1
- PNPM support?
- Latest NPM release failed (3.0.0) HOT 1
- What constituted the bump in major version? HOT 1
- Incompatible with Browserify HOT 1
- Mistenken added issue HOT 1
- Issues
- Issues
- Androidapk merge HOT 1
- wrongful access
- Google Cloud Functions reports incorrect path HOT 3
- Need Yarn 2 monorepo support
- Package throws an error when imported in an ES module installed globally on Ubuntu HOT 1
- ReferenceError: __dirname is not defined in ES module scope HOT 1
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 node-app-root-path.