Giter Club home page Giter Club logo

runtime-required's Introduction

runtime-required

travis score-codeclimate npm-downloads npm-version dm-david

Haven't you ever always needed to know what files are being required by your app? Okay, maybe not always, but once? No? Just me? Fine, move along then. But in case you need it, here's how it all works:

Install

It's in npm, of course:

npm install runtime-required

Usage

require('runtime-required') โ†’ EventEmitter

Yup, you just include it in your project and it exposes an event emitter. There is only a single file event, and it has the following properties:

  • type {string}: one of
    • builtin (node's default modules)
    • module (ones that appear inside the node_modules directory)
    • file (from your own project... or I guess elsewhere on the filesystem)
  • id {string}: the identifier for this module. For module and file types, it will be a fully-resolved file path. For builtin types, it will be the name of the module.

Example

const required = require('runtime-required');

required.on('file', data => {
  console.log(`a ${data.type} module was required at "${data.id}"`);
});

runtime-required's People

Contributors

catdad avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

runtime-required's Issues

use node's internal module resolution instead of resolve-from

const originalLoad = Module._load;
Module._load = function (request, parent) {
  const filename = Module._resolveFilename.apply(this, arguments);

  if (filename) {
    emit(request, filename);
  }

  return originalLoad.apply(this, arguments);
};

This avoids issues of dealing with all the different possibilities for the parent object.

move builds to GitHub Actions

I thought Travis was no longer building open-source projects for organizations, but it is in fact no longer building any open-source projects at all [1] [2]. So this transition needs to happen before I can do any more work on this project.

sometimes modules are incorrectly detected as files

found >>> "process-nextick-args" "D:\Git\electronmon\node_modules\process-nextick-args\index.js"
module D:\Git\electronmon\node_modules\process-nextick-args\index.js

found >>> "core-util-is" "D:\Git\electronmon\node_modules\core-util-is\lib\util.js"
module D:\Git\electronmon\node_modules\core-util-is\lib\util.js

found >>> "inherits" "D:\Git\electronmon\node_modules\inherits\inherits.js"
module D:\Git\electronmon\node_modules\inherits\inherits.js

found >>> "./_stream_readable" "D:\Git\electronmon\node_modules\readable-stream\lib\_stream_readable.js"
file D:\Git\electronmon\node_modules\readable-stream\lib\_stream_readable.js

found >>> "./_stream_writable" "D:\Git\electronmon\node_modules\readable-stream\lib\_stream_writable.js"
file D:\Git\electronmon\node_modules\readable-stream\lib\_stream_writable.js

found >>> "./lib/_stream_transform.js" "D:\Git\electronmon\node_modules\readable-stream\lib\_stream_transform.js"
file D:\Git\electronmon\node_modules\readable-stream\lib\_stream_transform.js

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.