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