How to use precinct - 10 common examples

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 wix / okidoc / packages / okidoc-md / src / utils / traverseEntries.js View on Github external
function traverseEntry(entryPath, visitors, { pattern, visited = [] } = {}) {
  const entryAST = parseFile(entryPath);

  visited.push(entryPath);

  precinct(entryAST, { type: 'es6', es6: { mixedImports: true } }).forEach(
    dependency => {
      // NOTE: only internal dependencies
      // TODO: allow path alias aka webpack alias https://webpack.js.org/configuration/resolve/#resolve-alias
      // https://github.com/dependents/node-filing-cabinet#usage
      if (!dependency.startsWith('.')) {
        return;
      }

      const dependencyPath = resolveDependencyPath({
        dependency,
        entryPath,
        entryAST,
      });

      if (!dependencyPath) {
        // NOTE: don't warn if dependency is not `js` or `ts`
github wix / okidoc / packages / okidoc-md / src / buildDocumentationSource / buildDocumentationSourceAST / buildDependenciesTree.js View on Github external
function resolveDependencies({ entryAST, entryPath, pattern }) {
  const relativeDependencies = precinct(entryAST, {
    type: 'es6',
    es6: { mixedImports: true },
  });

  return relativeDependencies
    .map(dependency => {
      // NOTE: only internal dependencies
      // TODO: allow path alias aka webpack alias https://webpack.js.org/configuration/resolve/#resolve-alias
      // https://github.com/dependents/node-filing-cabinet#usage
      if (!dependency.startsWith('.')) {
        return;
      }

      // convert relative path to absolute
      const dependencyPath = resolveDependencyPath({
        dependency,
github wix / okidoc / packages / okidoc-md / src / utils / traverseEntries.js View on Github external
function traverseEntry(entryPath, visitors, { pattern, visited = [] } = {}) {
  const entryAST = parseFile(entryPath);

  visited.push(entryPath);

  precinct(entryAST, { type: 'es6', es6: { mixedImports: true } }).forEach(
    dependency => {
      // NOTE: only internal dependencies
      // TODO: allow path alias aka webpack alias https://webpack.js.org/configuration/resolve/#resolve-alias
      // https://github.com/dependents/node-filing-cabinet#usage
      if (!dependency.startsWith('.')) {
        return;
      }

      const dependencyPath = resolveDependencyPath({
        dependency,
        entryPath,
        entryAST,
      });

      if (!dependencyPath) {
        // NOTE: don't warn if dependency is not `js` or `ts`
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 4 days ago

Package Health Score

89 / 100
Full package analysis

Popular precinct functions