当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript posix.dirname方法代码示例

本文整理汇总了TypeScript中path.posix.dirname方法的典型用法代码示例。如果您正苦于以下问题:TypeScript posix.dirname方法的具体用法?TypeScript posix.dirname怎么用?TypeScript posix.dirname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在path.posix的用法示例。


在下文中一共展示了posix.dirname方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

 private constructor(
     relativeFlatIndexPath: string, readonly entryPoint: string,
     readonly moduleName: string|null) {
   this.flatIndexPath = path.posix.join(path.posix.dirname(entryPoint), relativeFlatIndexPath)
                            .replace(/\.js$/, '') +
       '.ts';
 }
开发者ID:cyrilletuzi,项目名称:angular,代码行数:7,代码来源:flat_index_generator.ts

示例2: ensureLeadingSlash

export function rewriteHrefBaseUrl<T>(
    href: T, oldBaseUrl: ResolvedUrl, newBaseUrl: ResolvedUrl): T|
    FileRelativeUrl {
  if (isAbsolutePath(href as any)) {
    return href;
  }
  const relativeUrl = url.resolve(oldBaseUrl, href as any);
  const parsedFrom = url.parse(newBaseUrl);
  const parsedTo = url.parse(relativeUrl);
  if (parsedFrom.protocol === parsedTo.protocol &&
      parsedFrom.host === parsedTo.host) {
    let dirFrom = path.posix.dirname(
        // Have to append a '_' to the path because path.posix.dirname('foo/')
        // returns '.' instead of 'foo'.
        parsedFrom.pathname ? parsedFrom.pathname + '_' : '');
    let pathTo = parsedTo.pathname || '';
    if (isAbsolutePath(oldBaseUrl) || isAbsolutePath(newBaseUrl)) {
      dirFrom = ensureLeadingSlash(dirFrom);
      pathTo = ensureLeadingSlash(pathTo);
    }
    const pathname = pathPosixRelative(dirFrom, pathTo);
    return url.format({
      pathname: pathname,
      search: parsedTo.search,
      hash: parsedTo.hash,
    }) as FileRelativeUrl;
  }
  return relativeUrl as FileRelativeUrl;
}
开发者ID:Polymer,项目名称:vulcanize,代码行数:29,代码来源:url-utils.ts

示例3:

        .map(match => {
          const relativePath = path.posix.relative(slashedDirname, match);

          return path.posix.dirname(match) === slashedDirname
            ? `./${relativePath}`
            : relativePath;
        })
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:helpers.ts

示例4: Buffer

    return this._getBundles().then((bundles) => {
      let sharedDepsBundle = (this.shell)
          ? this.urlFromPath(this.shell)
          : 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)
            ? []
            : [path.relative(path.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) {
              reject(err);
            } else {
              resolve({
                url: fragment,
                contents: doc,
              });
            }
          });
        }));
      }
      // vulcanize the shared bundle
      if (!this.shell && sharedDeps && sharedDeps.length !== 0) {
        logger.info(`generating shared bundle`);
        promises.push(this._generateSharedBundle(sharedDeps));
      }
      return Promise.all(promises).then((bundles) => {
        // convert {url,contents}[] into a Map
        let contentsMap = new Map();
        for (let bundle of bundles) {
          contentsMap.set(bundle.url, bundle.contents);
        }
        return contentsMap;
      });
    });
开发者ID:honzalo,项目名称:polymer-cli,代码行数:59,代码来源:bundle.ts

示例5: getRelativeUrl

export function getRelativeUrl(
    fromUrl: ConvertedDocumentUrl, toUrl: ConvertedDocumentUrl): string {
  // Error: Expects two package-root-relative URLs to compute a relative path
  if (!fromUrl.startsWith('./') || !toUrl.startsWith('./')) {
    throw new Error(
        `paths relative to package root expected (actual: ` +
        `from="${fromUrl}", to="${toUrl}")`);
  }
  let moduleJsUrl = path.relative(path.dirname(fromUrl), toUrl);
  // Correct URL format to add './' preface if none exists
  if (!moduleJsUrl.startsWith('.') && !moduleJsUrl.startsWith('/')) {
    moduleJsUrl = './' + moduleJsUrl;
  }
  return moduleJsUrl;
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例6: ensureTrailingSlash

export function stripUrlFileSearchAndHash<T>(href: T): T {
  const u = url.parse(href as any);
  // Using != so tests for null AND undefined
  if (u.pathname != null) {
    // Suffix path with `_` so that `/a/b/` is treated as `/a/b/_` and that
    // `path.posix.dirname()` returns `/a/b` because it would otherwise
    // return `/a` incorrectly.
    u.pathname = ensureTrailingSlash(
        path.posix.dirname(u.pathname + '_') as FileRelativeUrl);
  }
  // Assigning to undefined because TSC says type of these is
  // `string | undefined` as opposed to `string | null`
  u.search = undefined;
  u.hash = undefined;
  return url.format(u) as any as T;
}
开发者ID:Polymer,项目名称:vulcanize,代码行数:16,代码来源:url-utils.ts

示例7: _addSharedImportsToShell

  _addSharedImportsToShell(bundles: Map<string, string[]>): string {
    console.assert(this.shell != null);
    let shellUrl = urlFromPath(this.root, this.shell);
    let shellUrlDir = posixPath.dirname(shellUrl);
    let shellDeps = bundles.get(shellUrl)
      .map((d) => posixPath.relative(shellUrlDir, d));
    logger.debug('found shell dependencies', {
      shellUrl: shellUrl,
      shellUrlDir: shellUrlDir,
      shellDeps: shellDeps,
    });

    let file = this.analyzer.getFile(this.shell);
    console.assert(file != null);
    let contents = file.contents.toString();
    let doc = dom5.parse(contents);
    let imports = dom5.queryAll(doc, dom5.predicates.AND(
      dom5.predicates.hasTagName('link'),
      dom5.predicates.hasAttrValue('rel', 'import')
    ));
    logger.debug('found html import elements', {
      imports: imports.map((el) => dom5.getAttribute(el, 'href')),
    });

    // Remove all imports that are in the shared deps list so that we prefer
    // the ordering or shared deps. Any imports left should be independent of
    // ordering of shared deps.
    let shellDepsSet = new Set(shellDeps);
    for (let _import of imports) {
      let importHref = dom5.getAttribute(_import, 'href');
      if (shellDepsSet.has(importHref)) {
        logger.debug(`removing duplicate import element "${importHref}"...`);
        dom5.remove(_import);
      }
    }

    // Append all shared imports to the end of <head>
    let head = dom5.query(doc, dom5.predicates.hasTagName('head'));
    for (let dep of shellDeps) {
      let newImport = dom5.constructors.element('link');
      dom5.setAttribute(newImport, 'rel', 'import');
      dom5.setAttribute(newImport, 'href', dep);
      dom5.append(head, newImport);
    }
    let newContents = dom5.serialize(doc);
    return newContents;
  }
开发者ID:augint,项目名称:polymer-cli,代码行数:47,代码来源:bundle.ts

示例8: generate

  generate(): ts.SourceFile {
    const relativeEntryPoint = './' +
        path.posix.relative(path.posix.dirname(this.flatIndexPath), this.entryPoint)
            .replace(/\.tsx?$/, '');

    const contents = `/**
 * Generated bundle index. Do not edit.
 */

export * from '${relativeEntryPoint}';
`;
    const genFile = ts.createSourceFile(
        this.flatIndexPath, contents, ts.ScriptTarget.ES2015, true, ts.ScriptKind.TS);
    if (this.moduleName !== null) {
      genFile.moduleName = this.moduleName;
    }
    return genFile;
  }
开发者ID:cyrilletuzi,项目名称:angular,代码行数:18,代码来源:flat_index_generator.ts

示例9: simpleUrlRelative

 protected simpleUrlRelative(from: ResolvedUrl, to: ResolvedUrl):
     FileRelativeUrl {
   const fromUrl = parseUrl(from);
   const toUrl = parseUrl(to);
   if (toUrl.protocol && toUrl.protocol !== fromUrl.protocol) {
     return this.brandAsRelative(to);
   }
   if (toUrl.host && toUrl.host !== fromUrl.host) {
     return this.brandAsRelative(to);
   }
   let fromPath = decodeURIComponent(fromUrl.pathname || '');
   const toPath = decodeURIComponent(toUrl.pathname || '');
   if (!fromPath.endsWith('/')) {
     fromPath = posix.dirname(fromPath);
   }
   let relativized = encodeURI(posix.relative(fromPath, toPath));
   if (toPath.endsWith('/') && !relativized.endsWith('/')) {
     relativized += '/';
   }
   return this.brandAsRelative(relativized);
 }
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:21,代码来源:url-resolver.ts

示例10:

 .map((d) => path.relative(path.dirname(shellUrl), d));
开发者ID:honzalo,项目名称:polymer-cli,代码行数:1,代码来源:bundle.ts


注:本文中的path.posix.dirname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。