Giter Site home page Giter Site logo

require-context's People

Contributors

wilsonlewis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

require-context's Issues

empty folder causes error

If an empty folder exists inside the recursed structure it causes this error:

node_modules/node-dir/lib/paths.js:92
results.files = results.files.concat(res.files);

TypeError: Cannot read property 'files' of undefined
at subloop (/git/mobile.reactnative.templateapp/node_modules/node-dir/lib/paths.js:92:57)
at /git/mobile.reactnative.templateapp/node_modules/node-dir/lib/paths.js:107:13

Error reproduced on MAC with node 6 and node 8

allow dangerous support for multiple directories?

I have a use case for allowing multiple directories, which you can read about a the vuejs-localization github repository. However, my fork is throwing up Critical dependency: require function is used in a way in which dependencies cannot be statically extracted ... and I'm not sure why. I revised it to test in the browser and it seems to work just fine:

c = function(d, recursive, regExp) {

  if (!Array.isArray(d)) {
    d = [d]
  }
  
  const keysMap = {}
  keysMap.keys = []
  keysMap.directories = {}
  
  d.forEach(directory => {
    let basepath = directory
    
    const dirKeys = dir[basepath]
      .filter(file => file.match(regExp || /\.(json|js)$/))
      .map(file => '.' + '/' + file.slice(basepath.length + 1))

    dirKeys.forEach(file => keysMap.directories[file] = directory)
      
    keysMap.keys = keysMap.keys.concat(dirKeys)
  })

  const context = function(key) {
    return context.resolve(key)
  }

  context.keysMap = keysMap

  context.resolve = function(key) {
    return keysMap.directories[key] + '/' + key
  }

  context.keys = function() {
    return keysMap.keys
  }

  return context
}
dir = { a: ['a/a.en', 'a/b.js'], 'c/a': ['c/a/c.js'], b: ['b/abc'] }
r = c(['a', 'c/a', 'b'], true)
r('./b.js')
//VM11433:1 "a/./b.js"
r.keys().forEach(key => console.log(r(key)))
//VM11433:1 a/./b.js
//VM11433:1 c/a/./c.js

Depth level support.

I have a big project where i need to import some files with some extensions. Something like that:

-src
* DirA
  * DirAA
    * FileToGet.ext
  * DirBB
    *  AlotOfFilesAndDirectoriesThatIDontWantToLoad (such as node_modules)
* DirB
  *DirBB
....

So, when i do require.ensure('./src', true, /ext$/) it gets the right file. The problem is that it becomes too slow because this require is maping all folders structures.

However you can set false if you dont want to look in subdirectories, but i need to search inside level 1 subdirectories. ¿Maybe could be 2nd parameter a number indicating depth instead of a boolean?. 0 stills being false and other numbers still being true.

Not exporting context

Mismatch between readme and actual API?
In the docs you said I could do...

require.context('./menues', false, /\.\/menu(\d+)\.jsx?$/i)

But you are not exporting context

Trailing Slash Beheads Key

Using a trailing slash on a dir name like

require.context("./test/", false, /\.test\.js$/);

causes the first character of keys() to be dropped

I'd like to take over the repository

Since there are a lot of outstanding issues and pull requests, and the repository is clearly not maintained, I'd like to offer my services and take over the repo/package. If this won't be possible in a considerable amount of time, I'll have to fork it and release a new package. Thanks for understanding!

How can I exclude a directory?

I would like to exclude directories.

How would I update the following line to import all the stories from components/**, except stories from components/evil-component-1 and components/evil-component-2?

const req = require.context('../components/', true, /.stories.js$/);

License

Please add OSS compatible license :)

no such file or directory

This is what I'm trying to do.

loading this into mocha to find tests:

require('coffee-babel');
requireContext = require('require-context');

const testsContext = requireContext('./src', true, /.test.coffee$/)
testsContext.keys().forEach(testsContext);

This is the error I get:

fs.js:965
  binding.stat(pathModule.toNamespacedPath(path));
          ^

Error: ENOENT: no such file or directory, stat '/Users/jameshessin/local/websites/com.grillbrickstudios/node_modules/require-context/src'
    at Object.fs.statSync (fs.js:965:11)
    at Object.files (/Users/jameshessin/local/websites/com.grillbrickstudios/node_modules/node-dir/lib/paths.js:161:21)
    at module.exports (/Users/jameshessin/local/websites/com.grillbrickstudios/node_modules/require-context/index.js:17:6)
    at Object.<anonymous> (/Users/jameshessin/local/websites/com.grillbrickstudios/test/index.js:4:22)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at /Users/jameshessin/.config/yarn/global/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>:null:null)
    at Mocha.loadFiles (/Users/jameshessin/.config/yarn/global/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/jameshessin/.config/yarn/global/node_modules/mocha/lib/mocha.js:536:10)
    at Object.<anonymous> (/Users/jameshessin/.config/yarn/global/node_modules/mocha/bin/_mocha:582:18)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

I am using the latest version:
node: 9.11.1
npm: 5.6.0
yarn: 1.5.1
macOS: 10.13.4

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.