How to use the precinct 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 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 patternplate / patternplate / packages / patternplate-transform-babel / source / index.js View on Github external
function walk(file, apply) {
  const pool = uniqByPath(flatten(file.dependencies));
  const source =
    typeof file.buffer === "string"
      ? file.buffer
      : file.buffer.toString("utf-8");

  const id = md5(source);
  stash[id] = stash[id] || precinct(source);

  stash[id]
    .map(localName => (file.dependencies[localName] || {}).path)
    .filter(Boolean)
    .map(dependencyPath => pool.find(dep => dep.path === dependencyPath))
    .filter(Boolean)
    .forEach(dependency => {
      dependency.buffer = apply(dependency).buffer;
      walk(dependency, apply);
    });
}
github mariusGundersen / module-pusher / src / analyze.js View on Github external
const nameAndContent = files.map(async name => {
    const content = await fs.readFile(path.join('public', name), 'utf-8');
    const depTree = precinct(content, {type: 'es6'});
    return ['/'+name, depTree];
  });

precinct

Unleash the detectives

MIT
Latest version published 17 days ago

Package Health Score

89 / 100
Full package analysis

Popular precinct functions