How to use find-node-modules - 6 common examples

To help you get started, we’ve selected a few find-node-modules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github js-dxtools / webpack-validator / src / rules / no-root-files-node-modules-nameclash.js View on Github external
validate(params, path_, state, options) {
        // If the supplied resolve.root path *is* a node_module folder, we'll continue
        // The check doesn't make sense in that case
        if (/node_modules$/.test(path_)) {
          return null
        }
        // For an initial iteration this node_module resolving is quite simplistic;
        // it just takes the first node_module folder found looking upwards from the given root
        const nodeModuleFolder = findNodeModules({ cwd: path_, relative: false })[0]
        /* istanbul ignore if - it's hard to simulate this */
        if (!nodeModuleFolder) {
          return null
        }
        const nodeModules = getNodeModulesContents(nodeModuleFolder)
        const basenames = cachedBasenameLs(path_)
        const intersection = calculateIntersection(nodeModules, basenames)
        if (intersection.size > 0) {
          return this.createError('path.noRootFilesNodeModulesNameClash', {
            path: path_,
            conflictingFiles: JSON.stringify([...intersection]),
            nodeModuleFolder,
          }, state, options)
        }
        return null // Everything is OK
      },
github commitizen / cz-cli / src / commitizen / adapter.js View on Github external
function getNearestNodeModulesDirectory (options) {

  // Get the nearest node_modules directories to the current working directory
  let nodeModulesDirectories = findNodeModules(options);

  // Make sure we find a node_modules folder

  /* istanbul ignore else */
  if (nodeModulesDirectories && nodeModulesDirectories.length > 0) {
    return nodeModulesDirectories[0];
  } else {
    console.error(`Error: Could not locate node_modules in your project's root directory. Did you forget to npm init or npm install?`)
  }
}
github velop-io / server / src / classes / Webpack.js View on Github external
this.getModulesPath();

    this.externals = [];
    let modulesPath = path.resolve(process.cwd(), "node_modules");
    if (fs.existsSync(modulesPath) && fs.lstatSync(modulesPath).isDirectory())
      this.externals = fs
        .readdirSync(modulesPath)
        .filter(
          x => !/\.bin|react-universal-component|webpack-flush-chunks/.test(x)
        )
        .reduce((externals, mod) => {
          externals[mod] = `commonjs ${mod}`;
          return externals;
        }, {});

    this.excludeDirs = path.resolve(findNodeModules()[0]);

    this.clientConfig = {
      name: "client",
      target: "web",
      module: {
        rules: [
          {
            test: /\.js$/,
            use: {
              loader: "babel-loader",
              options: {
                babelrc: true,
                comments: true,
                presets: ["env", "react"],
                plugins: ["relay", "transform-runtime"]
              }
github PolymerX / polymerx-cli / src / lib / webpack / webpack-base.config.js View on Github external
const shared = argv => {
  const {
    isProd,
    src,
    srcDir,
    dest,
    pkg,
    cwd,
    https,
    workers
  } = argv;

  const ENV = isProd ? 'production' : 'development';
  const OUTPUT_PATH = isProd ? resolve(dest || 'dist') : resolve(src || 'src');
  const NODE_MODULES = findNodeModules({cwd, relative: false});

  const HOST = process.env.HOST || argv.host;
  const PORT = process.env.PORT || argv.port;
  const FULL_HOST = `http://${HOST}:${PORT}`;
  const ENTRY = isProd ? [resolve(src || 'src')] : [OUTPUT_PATH].concat([
    `webpack-dev-server/client?${FULL_HOST}`,
    'webpack/hot/dev-server'
  ]);

  const processEnv = {
    NODE_ENV: JSON.stringify(ENV),
    appVersion: JSON.stringify(pkg.version)
  };

  /**
   * === Copy static files configuration
github newsuk / times-components / packages / jest-configurator / src / jest-configurator.js View on Github external
export default (platform, cwd, options = {}) => {
  const { coverageIgnoreGlobs = [], setupFilesAfterEnv } = options;
  const [local, global] = findNodeModules(cwd);
  const module = path.resolve(cwd, local.replace("node_modules", ""));
  const rootDir = path.resolve(
    cwd,
    (global || local).replace("node_modules", "")
  );

  const platformPath = platform ? `${platform}/` : "";

  const config = {
    ...platformCode(platform),
    collectCoverageFrom: [path.join(rootDir, module)],
    coverageDirectory: path.join(module, "coverage", platformPath),
    coveragePathIgnorePatterns: coverageIgnoreGlobs,
    modulePathIgnorePatterns: [
      "node_modules/redbox-react/node_modules/react/",
      "node_modules/@storybook/"
github velop-io / server / src / classes / Webpack.js View on Github external
getModulesPath() {
    try {
      let modulesFolder = path.resolve(findNodeModules()[0]);
      let modulesPackage = path.resolve(modulesFolder, "@velop/server/lib");
      let srcFolder = path.join(modulesFolder, "..", "src");
      if (
        fs.existsSync(path.resolve(srcFolder)) &&
        fs.existsSync(path.resolve(srcFolder, "utils")) &&
        fs.existsSync(path.resolve(srcFolder, "utils", "client-render.js")) &&
        fs
          .lstatSync(path.resolve(srcFolder, "utils", "client-render.js"))
          .isFile()
      ) {
        this.modulesPath = srcFolder;
      } else if (fs.lstatSync(modulesPackage).isDirectory()) {
        this.modulesPath = modulesPackage;
      } else {
        this.parent.logger.info(
          "[VelopServer][Error] Could not find node_modules or source path...."

find-node-modules

Return an array of all parent node_modules directories

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis

Popular find-node-modules functions

Similar packages