tooling/lib/dependencies.js
function walk(entrypoint) {
  try {
    if (!visited.has(entrypoint)) {
      debug(`finding requires for ${entrypoint}`);
      // This whole thing is *way* easier if we do it synchronously
      // eslint-disable-next-line no-sync
      const requires = detective(fs.readFileSync(entrypoint));

      visited.set(entrypoint, requires.reduce((acc, dep) => {
        debug(`found ${dep}`);
        if (dep.startsWith('.')) {
          debug(`${dep} is relative, descending`);
          const next = walk(path.resolve(path.dirname(entrypoint), dep));

          acc = new Set([...acc, ...next]);
        }
        else if (!builtins.includes(dep)) {
          debug(`found dependency ${dep}`);
          acc.add(requireToPackage(dep));
        }

        return acc;
      }, new Set()));
    }

    return visited.get(entrypoint);
  }
  catch (err) {
    if (err.code === 'EISDIR') {
      return walk(path.resolve(entrypoint, 'index.js'));
    }
    if (err.code === 'ENOENT' && !entrypoint.endsWith('.js')) {
      return walk(`${entrypoint}.js`);
    }
    throw err;
  }
}
function walk(entrypoint) {
  try {
    if (!visited.has(entrypoint)) {
      debug(`finding requires for ${entrypoint}`);
      // This whole thing is *way* easier if we do it synchronously
      // eslint-disable-next-line no-sync
      const requires = detective(fs.readFileSync(entrypoint));

      visited.set(entrypoint, requires.reduce((acc, dep) => {
        debug(`found ${dep}`);
        if (dep.startsWith('.')) {
          debug(`${dep} is relative, descending`);
          const next = walk(path.resolve(path.dirname(entrypoint), dep));

          acc = new Set([...acc, ...next]);
        }
        else if (!builtins.includes(dep)) {
          debug(`found dependency ${dep}`);
          acc.add(requireToPackage(dep));
        }

        return acc;
      }, new Set()));
    }

    return visited.get(entrypoint);
  }
  catch (err) {
    if (err.code === 'EISDIR') {
      return walk(path.resolve(entrypoint, 'index.js'));
    }
    if (err.code === 'ENOENT' && !entrypoint.endsWith('.js')) {
      return walk(`${entrypoint}.js`);
    }
    throw err;
  }
}
function walk ( entrypoint ) { try { if ( ! visited . has ( entrypoint ) ) { debug ( ` ${ entrypoint } ` ) ; // This whole thing is *way* easier if we do it synchronously // eslint-disable-next-line no-sync const requires = detective ( fs . readFileSync ( entrypoint ) ) ; visited . set ( entrypoint , requires . reduce ( ( acc , dep ) => { debug ( ` ${ dep } ` ) ; if ( dep . startsWith ( '.' ) ) { debug ( ` ${ dep } ` ) ; const next = walk ( path . resolve ( path . dirname ( entrypoint ) , dep ) ) ; acc = new Set ( [ ... acc , ... next ] ) ; } else if ( ! builtins . includes ( dep ) ) { debug ( ` ${ dep } ` ) ; acc . add ( requireToPackage ( dep ) ) ; } return acc ; } , new Set ( ) ) ) ; } return visited . get ( entrypoint ) ; } catch ( err ) { if ( err . code === 'EISDIR' ) { return walk ( path . resolve ( entrypoint , 'index.js' ) ) ; } if ( err . code === 'ENOENT' && ! entrypoint . endsWith ( '.js' ) ) { return walk ( ` ${ entrypoint } ` ) ; } throw err ; } }
Finds all dependencies of entrypoint
@param {string} entrypoint
@returns {Set<string>}
Finds all dependencies of entrypoint