How to use the precinct.paperwork function in precinct

To help you get started, we’ve selected a few precinct 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 netlify / zip-it-and-ship-it / src / dependencies.js View on Github external
const getFileDependencies = async function(path, packageJson, state) {
  if (state.localFiles.includes(path)) {
    return []
  }

  state.localFiles.push(path)

  const basedir = dirname(path)
  // This parses JavaScript in `path` to retrieve all the `require()` statements
  // TODO: `precinct.paperwork()` uses `fs.readFileSync()` under the hood,
  // but should use `fs.readFile()` instead
  const dependencies = precinct.paperwork(path, { includeCore: false })

  const depsPaths = await Promise.all(
    dependencies.map(dependency => getImportDependencies(dependency, basedir, packageJson, state))
  )
  return [].concat(...depsPaths)
}
github netlify / zip-it-and-ship-it / src / finders.js View on Github external
}
        }
      }
      throw e
    }
  }

  while (localFilesToProcess.length) {
    const currentLocalFile = localFilesToProcess.pop()

    if (filePaths.has(currentLocalFile)) {
      continue
    }

    filePaths.add(currentLocalFile)
    precinct.paperwork(currentLocalFile, { includeCore: false }).forEach(dependency => {
      if (dependency.indexOf('.') === 0) {
        const abs = resolve.sync(dependency, {
          basedir: path.dirname(currentLocalFile)
        })
        localFilesToProcess.push(abs)
      } else {
        handle(dependency, servicePath)
      }
    })
  }

  while (modulesToProcess.length) {
    const currentModule = modulesToProcess.pop()
    const currentModulePath = path.join(currentModule.path, '..')
    const packageJson = currentModule.packageJson
github DavidWells / serverless-manifest-plugin / src / getDeps.js View on Github external
Please ensure "${moduleName}" is installed in the project.`);
        }
      }
      throw e;
    }
  }

  while (localFilesToProcess.length) {
    const currentLocalFile = localFilesToProcess.pop();

    if (filePaths.has(currentLocalFile)) {
      continue;
    }

    filePaths.add(currentLocalFile);
    precinct
      .paperwork(currentLocalFile, { includeCore: false })
      .forEach(dependency => {
        if (dependency.indexOf(".") === 0) {
          const abs = resolve.sync(dependency, {
            basedir: path.dirname(currentLocalFile)
          });
          localFilesToProcess.push(abs);
        } else {
          handle(dependency, servicePath);
        }
      });
  }

  while (modulesToProcess.length) {
    const currentModule = modulesToProcess.pop();
    const currentModulePath = path.join(currentModule.path, "..");
github netlify / cli / src / utils / finders.js View on Github external
Please ensure "${moduleName}" is installed in the project.`)
        }
      }
      throw e
    }
  }

  while (localFilesToProcess.length) {
    const currentLocalFile = localFilesToProcess.pop()

    if (filePaths.has(currentLocalFile)) {
      continue
    }

    filePaths.add(currentLocalFile)
    precinct.paperwork(currentLocalFile, { includeCore: false }).forEach(dependency => {
      if (dependency.indexOf('.') === 0) {
        const abs = resolve.sync(dependency, {
          basedir: path.dirname(currentLocalFile)
        })
        localFilesToProcess.push(abs)
      } else {
        handle(dependency, servicePath)
      }
    })
  }

  while (modulesToProcess.length) {
    const currentModule = modulesToProcess.pop()
    const currentModulePath = path.join(currentModule.path, '..')
    const packageJson = currentModule.pkg
github meetalva / alva / packages / analyzer / src / typescript-react-analyzer / typescript-react-analyzer.ts View on Github external
function getImportsFromPath(
	path: string,
	config: { extensions: string[]; init: Set; deep: boolean } = {
		init: new Set(),
		deep: true,
		extensions: []
	}
): Set {
	const basedir = Path.dirname(path);

	const dependencyList: string[] = precinct
		.paperwork(path)
		.filter((p: string) => p.startsWith('.'))
		.map((p: string) =>
			resolve.sync(p, {
				basedir,
				extensions: config.extensions
			})
		);

	if (!config.deep) {
		return new Set(dependencyList);
	}

	return dependencyList.reduce((acc: Set, dependency: string) => {
		if (config.init.has(dependency)) {
			return acc;
github dougmoscrop / serverless-plugin-include-dependencies / get-dependency-list.js View on Github external
}
      }
      throw e;
    }
  }

  while (localFilesToProcess.length) {
    const currentLocalFile = localFilesToProcess.pop();

    if (filePaths.has(currentLocalFile)) {
      continue;
    }

    filePaths.add(currentLocalFile);

    precinct.paperwork(currentLocalFile, { includeCore: false }).forEach(dependency => {
      if (dependency.indexOf('.') === 0) {
        const abs = resolve.sync(dependency, {
          basedir: path.dirname(currentLocalFile)
        });
        localFilesToProcess.push(abs);
      } else {
        handle(dependency, servicePath);
      }
    });
  }

  while (modulesToProcess.length) {
    const currentModule = modulesToProcess.pop();
    const currentModulePath = path.join(currentModule.path, '..');

    if (modulePaths.has(currentModulePath)) {
github dependents / node-dependency-tree / index.js View on Github external
module.exports._getDependencies = function(config) {
  let dependencies;
  const precinctOptions = config.detectiveConfig;
  precinctOptions.includeCore = false;

  try {
    dependencies = precinct.paperwork(config.filename, precinctOptions);

    debug('extracted ' + dependencies.length + ' dependencies: ', dependencies);

  } catch (e) {
    debug('error getting dependencies: ' + e.message);
    debug(e.stack);
    return [];
  }

  const resolvedDependencies = [];

  for (let i = 0, l = dependencies.length; i < l; i++) {
    const dep = dependencies[i];

    const result = cabinet({
      partial: dep,

precinct

Unleash the detectives

MIT
Latest version published 17 days ago

Package Health Score

89 / 100
Full package analysis

Popular precinct functions