1.0.6 • Published 6 years ago

@warren-bank/root-project-directory v1.0.6

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
6 years ago

root-project-directory

Description:

This is a tiny library to help when importing CommonJS modules with paths relative to the root of the project directory.

Installation:

npm install --save '@warren-bank/root-project-directory'

Usage (tl;dr):

const root     = require('@warren-bank/root-project-directory').absolute_root
const module_A = require(root + '/foo/bar/baz/A')

Usage (verbose):

const root = require('@warren-bank/root-project-directory')

const absolute = root.absolute_root
const relative = root.get_relative_root(__dirname)

console.log('absolute path to root of project directory:', absolute)
console.log('relative path to root of project directory:', relative)

const module_A = require(absolute + '/foo/bar/baz/A')
const module_B = require(relative + '/foo/bar/baz/B')

Console Logs (from verbose usage example):

absolute path to root of project directory: /path/to/project
relative path to root of project directory: ../../..

Issues:

  • does not play well with:
    • ES6 modules
    • Webpack
      • not needed:
        • configure resolve.modules in webpack.config.js to include:
          • the root project directory
          • the node_modules directory
        • import (CommonJS and ES6) modules from paths that are relative to any of the configured directories
        • example

Legal:

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago