How to use the path.posix.dirname function in path

To help you get started, we’ve selected a few path 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 npm / node-tar / lib / header.js View on Github external
const splitPrefix = (p, prefixSize) => {
  const pathSize = 100
  let pp = p
  let prefix = ''
  let ret
  const root = pathModule.parse(p).root || '.'

  if (Buffer.byteLength(pp) < pathSize)
    ret = [pp, prefix, false]
  else {
    // first set prefix to the dir, and path to the base
    prefix = pathModule.dirname(pp)
    pp = pathModule.basename(pp)

    do {
      // both fit!
      if (Buffer.byteLength(pp) <= pathSize &&
          Buffer.byteLength(prefix) <= prefixSize)
        ret = [pp, prefix, false]

      // prefix fits in prefix, but path doesn't fit in path
      else if (Buffer.byteLength(pp) > pathSize &&
          Buffer.byteLength(prefix) <= prefixSize)
        ret = [pp.substr(0, pathSize - 1), prefix, true]

      else {
        // make path take a bit from prefix
        pp = pathModule.join(pathModule.basename(prefix), pp)
github yarnpkg / berry / packages / berry-zipfs / sources / ZipFS.ts View on Github external
lstat(p: string) {
    const origP = p;
    p = posix.join(this.realpath(posix.dirname(p)), posix.basename(p));

    // Ensures that it's a directory
    if (origP[origP.length - 1] === `/`)
      this.ensurePathCorrectness(p, `lstat`, true);

    return this.statImpl(p);
  }
github Quramy / better-name / src / functions.ts View on Github external
export function shouldBeReplaced({
  targetFileId,
  toFileId,
  targetModuleName,
} : {
  targetFileId: string,
  toFileId: string,
  targetModuleName: string,
}) : ShouldBeReplacedResult {
  if (!/^\./.test(targetModuleName)) return { hit: false };
  const fromDir = path.dirname(targetFileId), toDir = path.dirname(toFileId);
  if (fromDir === toDir) return { hit: false };
  const newModulePath = path.normalize(path.relative(toDir, path.join(fromDir, targetModuleName)));
  return {
    hit: true,
    newModuleId: newModulePath.startsWith(".") ? newModulePath : "./" + newModulePath,
  };
}
github postlight / lux / src / packages / cli / generator / utils / generate-type.js View on Github external
const generate = createGenerator({
    dir,
    template: controllerTemplate
  })

  if (!name.endsWith('application')) {
    name = pluralize(name)
  }

  await generate({
    ...opts,
    cwd,
    name
  })

  const namespace = posix.dirname(name)

  if (namespace !== '.') {
    const hasParent = await exists(
      joinPath(cwd, dir, ...[...namespace.split('/'), 'application.js'])
    )

    if (!hasParent) {
      await controller({
        ...opts,
        cwd,
        name: `${namespace}/application`,
        attrs: []
      })
    }
  }
}
github Polymer / polymer-cli / src / build / bundle.ts View on Github external
: this.sharedBundleUrl;
      let sharedDeps = bundles.get(sharedDepsBundle) || [];
      let promises = [];

      if (this.shell) {
        let shellFile = this.analyzer.getFile(this.shell);
        console.assert(shellFile != null);
        let newShellContent = this._addSharedImportsToShell(bundles);
        shellFile.contents = new Buffer(newShellContent);
      }

      for (let fragment of this.allFragments) {
        let fragmentUrl = this.urlFromPath(fragment);
        let addedImports = (fragment === this.shell && this.shell)
            ? []
            : [posixPath.relative(posixPath.dirname(fragmentUrl), sharedDepsBundle)];
        let excludes = (fragment === this.shell && this.shell)
            ? []
            : sharedDeps.concat(sharedDepsBundle);

        promises.push(new Promise((resolve, reject) => {
          let vulcanize = new Vulcanize({
            abspath: null,
            fsResolver: this.analyzer.resolver,
            addedImports: addedImports,
            stripExcludes: excludes,
            inlineScripts: true,
            inlineCss: true,
            inputUrl: fragmentUrl,
          });
          vulcanize.process(null, (err, doc) => {
            if (err) {
github postlight / lux / src / packages / loader / resolver / utils / closest-ancestor.js View on Github external
export default function closestAncestor(
  source: Bundle$Namespace,
  key: string
): void | T {
  const name = posix.basename(key)
  let namespace = posix.dirname(key)

  if (namespace === '.') {
    return source.get(name)
  }

  namespace = posix.dirname(namespace)

  const ancestor = source.get(posix.join(namespace, name))

  if (ancestor) {
    return ancestor
  }

  return closestAncestor(
    source,
    posix.join(posix.dirname(namespace), name)
  )
}
github nprapps / book-concierge / tasks / sync.js View on Github external
}, function(err, data) {
            if (err) return callback(err);
            fs.mkdirSync(path.dirname(path.join(localSynced, item.file)), { recursive: true });
            fs.writeFileSync(path.join(localSynced, item.file), data.Body);
            callback();
          })
        }, err => next(err, up));
github yarnpkg / berry / packages / plugin-essentials / sources / commands / policies / set-version.ts View on Github external
const asset = getBundleAsset(release);
      if (!asset)
        throw new Error(`The bundle asset should exist`);

      bundleUrl = asset.browser_download_url;
      bundleVersion = release.version.version;
    }

    stdout.write(`Downloading ${configuration.format(bundleUrl, `green`)}...\n`);
    const bundle = await httpUtils.get(bundleUrl, configuration);

    const yarnPath = `.yarn/releases/yarn-${bundleVersion}.js`;
    const absoluteYarn = posix.resolve(project.cwd, yarnPath);

    stdout.write(`Saving it into ${configuration.format(yarnPath, `magenta`)}...\n`);
    await xfs.mkdirpPromise(posix.dirname(absoluteYarn));
    await xfs.writeFilePromise(absoluteYarn, bundle);
    await xfs.chmodPromise(absoluteYarn, 0o755);

    await Configuration.updateConfiguration(project.cwd, {
      yarnPath,
    });
  });
github yarnpkg / berry / packages / berry-zipfs / sources / ZipFS.ts View on Github external
private registerEntry(p: string, index: number) {
    const parentListing = this.registerListing(posix.dirname(p));
    parentListing.add(posix.basename(p));

    this.entries.set(p, index);
  }
github novacrazy / scriptor / src / script.js View on Github external
get baseUrl() {
        return path.dirname( this.filename );
    }