How to use the path-dirname function in path-dirname

To help you get started, we’ve selected a few path-dirname 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 s-yadav / relative-to-alias / src / util.js View on Github external
function addToImports(node, sourceNode) {
    const relativePath = sourceNode.value;
    const rawSource = sourceNode.raw || (sourceNode.extra && sourceNode.extra.raw);
    const preferredQuotes = (rawSource || '')[0] === "'" ? 'single' : 'double';

    if (relativePath && !isNodeModule(relativePath)) {
      const absolutePathFromRoot = path.join(pathDirname(filePath), relativePath);
      if (absolutePathFromRoot.indexOf(aliasRelativeToRoot) === 0) {
        const aliasedPath = absolutePathFromRoot.replace(aliasRelativeToRoot, alias);
        sourceNode.value = aliasedPath;

        //remove leading and trailing comments from the node
        node.leadingComments = undefined;
        node.trailingComments = undefined;

        const {start, end} = node;
        const currentImportCode = code.substring(start, end);
        const updatedImport = generate(node, {jsescOption :{quotes: preferredQuotes}}, currentImportCode).code;

        imports.push({
          start,
          end,
          updatedImport: updatedImport

path-dirname

Node.js path.dirname() ponyfill

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular path-dirname functions