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


TypeScript resolve.sync函数代码示例

本文整理汇总了TypeScript中resolve.sync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sync函数的具体用法?TypeScript sync怎么用?TypeScript sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_options_sync

function test_options_sync() {
  var resolved = resolve.sync('typescript', {
    basedir: process.cwd(),
    package: {},
    extensions: ['.js'],
    packageFilter: function(pkg, pkgfile) {
      return pkg;
    },
    pathFilter: function(pkg, path, relativePath) {
      return path
    },
    paths: [process.cwd()],
    moduleDirectory: 'node_modules',
    readFileSync: fs.readFileSync,
    isFile: function(file) {
      try {
        return fs.statSync(file).isFile();
      } catch (error) {
        return false;
      }
    }
  });
  console.log(resolved);
  resolved = resolve.sync('typescript', {
      readFileSync(file, charset) {
          return fs.readFileSync(file, charset);
      }
  });
}
开发者ID:Engineer2B,项目名称:DefinitelyTyped,代码行数:29,代码来源:resolve-tests.ts

示例2: next

  const labeler = through.obj(function(this: any, row, _enc, next) {
    row.id = labels[row.id]

    const opts = {
      basedir: path.dirname(row.file),
      extensions: ['.js', '.coffee'],
      paths: ['./node_modules', paths.buildDir.jsTree],
    }

    for (const name in row.deps) {
      let dep = row.deps[name]

      if (dep == null) {
        dep = pkg.browser[name]

        if (dep != null)
          dep = path.resolve(dep)
        else
          dep = resolve.sync(name, opts)
      }

      row.deps[name] = labels[dep] || parentLabels[dep]
    }

    this.push(row)
    next()
  })
开发者ID:bgyarfas,项目名称:bokeh,代码行数:27,代码来源:labeler.ts

示例3: resolveConfigurationPath

/**
 * Resolve configuration file path or node_module reference
 * @param filePath Relative ("./path"), absolute ("/path"), node module ("path"), or built-in ("tslint:path")
 */
function resolveConfigurationPath(filePath: string, relativeTo?: string) {
    const matches = filePath.match(BUILT_IN_CONFIG);
    const isBuiltInConfig = matches != null && matches.length > 0;
    if (isBuiltInConfig) {
        const configName = matches![1];
        try {
            return require.resolve(`./configs/${configName}`);
        } catch (err) {
            throw new Error(`${filePath} is not a built-in config, try "tslint:recommended" instead.`);
        }
    }

    const basedir = relativeTo || process.cwd();
    try {
        return resolve.sync(filePath, { basedir });
    } catch (err) {
        try {
            return require.resolve(filePath);
        } catch (err) {
            throw new Error(`Invalid "extends" configuration value - could not require "${filePath}". ` +
                "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " +
                "for the approximate method TSLint uses to find the referenced configuration file.");
        }
    }
}
开发者ID:mark-buer,项目名称:tslint,代码行数:29,代码来源:configuration.ts

示例4: realizePath

	/**
	 * Attempts to find a module from a path
	 */
	private realizePath(caller: string, fullRelative: string): string {
		const stripPrefix = (path: string): string => {
			if (path.startsWith("/")) {
				path = path.substr(1);
			}
			if (path.endsWith("/")) {
				path = path.substr(0, path.length - 1);
			}

			return path;
		};
		const callerDirname = path.dirname(caller);
		const resolvedPath = resolve.sync(fullRelative, {
			basedir: this.baseDir ? callerDirname.startsWith(this.baseDir) ? callerDirname : path.join(this.baseDir, callerDirname) : callerDirname,
			extensions: [".js"],
			readFileSync: (file: string): string => {
				return this.readFile(stripPrefix(file));
			},
			isFile: (file: string): boolean => {
				return this.reader.exists(stripPrefix(file));
			},
		});

		return stripPrefix(resolvedPath);
	}
开发者ID:AhmadAlyTanany,项目名称:code-server,代码行数:28,代码来源:requirefs.ts

示例5: fromProject

  static fromProject(): Version {
    let packageJson: any = null;

    try {
      const angularCliPath = resolve.sync('angular-cli', {
        basedir: process.cwd(),
        packageFilter: (pkg: any, pkgFile: string) => {
          packageJson = pkg;
        }
      });
      if (angularCliPath && packageJson) {
        try {
          return new Version(packageJson.version);
        } catch (e) {
          return new Version(null);
        }
      }
    } catch (e) {
      // Fallback to reading config.
    }


    const configPath = CliConfig.configFilePath();
    const configJson = readFileSync(configPath, 'utf8');

    try {
      const json = JSON.parse(configJson);
      return new Version(json.project && json.project.version);
    } catch (e) {
      return new Version(null);
    }
  }
开发者ID:StudioProcess,项目名称:angular-cli,代码行数:32,代码来源:version.ts

示例6: getInstalledNpmPkgPath

export function getInstalledNpmPkgPath (pkgName: string, basedir: string): string | null {
  const resolvePath = require('resolve')
  try {
    return resolvePath.sync(`${pkgName}/package.json`, { basedir })
  } catch (err) {
    return null
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:8,代码来源:index.ts

示例7:

 return plugins.map(function (plugin: any) {
     var config = {};
     if (Array.isArray(plugin)) {
         config = plugin[1];
         plugin = plugin[0];
     }
     plugin = prefix && !plugin.startsWith(prefix) ? prefix + plugin : plugin;
     return [resolve.sync(plugin, { basedir: basedir }), config];
 });
开发者ID:7sharp9,项目名称:Fable,代码行数:9,代码来源:lib.ts

示例8:

const resolveModulePath = (modulePath: string, context: string) => {
  if (resolve.isCore(modulePath)) {
    return modulePath
  }
  const folder = path.dirname(context)
  const resolvedPath = resolve.sync(modulePath, {
    basedir: folder,
    extensions: ['.js', '.ts']
  })
  return fs.realpathSync(resolvedPath)
}
开发者ID:stayradiated,项目名称:unwire,代码行数:11,代码来源:core.ts

示例9: resolveConfigurationPath

/**
 * Resolve configuration file path
 * @var relativeFilePath Relative path or package name (tslint-config-X) or package short name (X)
 */
function resolveConfigurationPath(relativeFilePath: string, relativeTo?: string) {
    const basedir = relativeTo || process.cwd();
    try {
        return resolve.sync(relativeFilePath, { basedir });
    } catch (err) {
        try {
            return require.resolve(relativeFilePath);
        } catch (err) {
            throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` +
                "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " +
                "for the approximate method TSLint uses to find the referenced configuration file.");
        }
    }
}
开发者ID:DavidSouther,项目名称:tslint,代码行数:18,代码来源:configuration.ts

示例10: loadFormatterModule

function loadFormatterModule(name: string): FormatterConstructor | undefined {
    let src: string;
    try {
        // first try to find a module in the dependencies of the currently linted project
        src = resolve.sync(name, {basedir: process.cwd()});
    } catch {
        try {
            // if there is no local module, try relative to the installation of TSLint (might be global)
            src = require.resolve(name);
        } catch {
            return undefined;
        }
    }
    return (require(src) as { Formatter: FormatterConstructor }).Formatter;
}
开发者ID:andy-ms,项目名称:tslint,代码行数:15,代码来源:formatterLoader.ts


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