本文整理汇总了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);
}
});
}
示例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()
})
示例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.");
}
}
}
示例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);
}
示例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);
}
}
示例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
}
}
示例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];
});
示例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)
}
示例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.");
}
}
}
示例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;
}