當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。