Giter Site home page Giter Site logo

Comments (5)

inxilpro avatar inxilpro commented on July 29, 2024

Can you give me a better idea of your directory structure? Like this?

app/
    node_modules/
    webapp/
        node_modules/

Or, even better, can you send me a code sample the demonstrates this behavior?

from node-app-root-path.

doublemarked avatar doublemarked commented on July 29, 2024

My directory structure looks like this,

   my-web-app/
      node_modules/
         app-root-path/
         my-module/

Normally, if I were to clone and npm install inside my-module, the directory structure would look like,

   my-module/
      node_modules/
         app-root-path/

However, npm v3 sees that the same version of app-root-path is used both by my-web-app and my-module and so it moves it up to flatten the dependency hierarchy.

I can put together a code sample!

from node-app-root-path.

doublemarked avatar doublemarked commented on July 29, 2024

Here you go:
https://github.com/doublemarked/app-root-issue-17
https://github.com/doublemarked/app-root-issue-17-module

To reproduce,

  1. Clone the module by itself, npm install then node index.js
  2. Then, clone the base project separately (which depends on the module), npm install and node index.js

Output is like:

Scallop:app-root-issue-17-module heath$ node index.js
MODULE APPROOT: /Users/heath/Projects/app-root-issue-17-module
Scallop:app-root-issue-17 heath$ node index.js 
BASE APPROOT:/Users/heath/Projects/app-root-issue-17
MODULE APPROOT: /Users/heath/Projects/app-root-issue-17
MYMOD: { appRootPath: '/Users/heath/Projects/app-root-issue-17' }

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

Oh, I inderstand. Yeah--this module isn't meant to solve that problem. app-root-path is meant to find the app's root path, regardless of the directory structure, so what you're seeing is exactly the expected behavior.

I'll try to post a code sample later tonight that would do what you're trying to do.

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

Here's a code sample that can get you the path to the current module, no matter where it's called:

function moduleDirectory(dir, pathSeparator) {
  var sep = pathSeparator || '/';
  var search = 'node_modules' + sep;
  var moduleIndex = dir.lastIndexOf(search);
  var sepIndex = dir.indexOf(sep, moduleIndex + search.length);

  if (-1 === sepIndex) {
    return dir;
  }

  return dir.substring(0, sepIndex);
}

See this JSBin for a demo:
http://jsbin.com/qazukeluve/1/edit?js,console

from node-app-root-path.

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.