本文整理匯總了TypeScript中@bazel/typescript.parseTsconfig函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parseTsconfig函數的具體用法?TypeScript parseTsconfig怎麽用?TypeScript parseTsconfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了parseTsconfig函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: runOneBuild
export function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [parsedOptions, errors] = parseTsconfig(project);
if (errors && errors.length) {
console.error(ng.formatDiagnostics(errors));
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const expectedOuts = config['angularCompilerOptions']['expectedOut'];
const {basePath} = ng.calcProjectFileAndBasePath(project);
const compilerOpts = ng.createNgCompilerOptions(basePath, config, tsOptions);
const tsHost = ts.createCompilerHost(compilerOpts, true);
const {diagnostics} = compile({
allowNonHermeticReads: ALLOW_NON_HERMETIC_READS,
allDepsCompiledWithBazel: ALL_DEPS_COMPILED_WITH_BAZEL,
compilerOpts,
tsHost,
bazelOpts,
files,
inputs,
expectedOuts
});
if (diagnostics.length) {
console.error(ng.formatDiagnostics(diagnostics));
}
return diagnostics.every(d => d.category !== ts.DiagnosticCategory.Error);
}
示例2: runOneBuild
function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [{options: tsOptions, bazelOpts, files, config}] = parseTsconfig(project);
const expectedOuts = config['angularCompilerOptions']['expectedOut'];
const {basePath} = ng.calcProjectFileAndBasePath(project);
const compilerOpts = ng.createNgCompilerOptions(basePath, config, tsOptions);
const tsHost = ts.createCompilerHost(compilerOpts, true);
const {diagnostics} = compile({
allowNonHermeticReads: ALLOW_NON_HERMETIC_READS,
compilerOpts,
tsHost,
bazelOpts,
files,
inputs,
expectedOuts
});
return diagnostics.every(d => d.category !== ts.DiagnosticCategory.Error);
}
示例3: runOneBuild
function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
let fileLoader: FileLoader;
if (inputs) {
fileLoader = new CachedFileLoader(fileCache, ALLOW_NON_HERMETIC_READS);
// Resolve the inputs to absolute paths to match TypeScript internals
const resolvedInputs: {[path: string]: string} = {};
for (const key of Object.keys(inputs)) {
resolvedInputs[path.resolve(key)] = inputs[key];
}
fileCache.updateCache(resolvedInputs);
} else {
fileLoader = new UncachedFileLoader();
}
const [{options: tsOptions, bazelOpts, files, config}] = parseTsconfig(project);
const expectedOuts = config['angularCompilerOptions']['expectedOut'];
const {basePath} = ng.calcProjectFileAndBasePath(project);
const compilerOpts = ng.createNgCompilerOptions(basePath, config, tsOptions);
const {diagnostics} = compile({fileLoader, compilerOpts, bazelOpts, files, expectedOuts});
return diagnostics.every(d => d.category !== ts.DiagnosticCategory.Error);
}
示例4: runMain
export function runMain(
tsConfig: string, entryPoint: string, dtsBundleOut?: string, apiReviewFolder?: string,
acceptApiUpdates = false): 1|0 {
const [parsedConfig, errors] = parseTsconfig(tsConfig);
if (errors && errors.length) {
console.error(format('', errors));
return 1;
}
const pkgJson = path.resolve(path.dirname(entryPoint), 'package.json');
if (!fs.existsSync(pkgJson)) {
fs.writeFileSync(pkgJson, JSON.stringify({
'name': 'GENERATED-BY-BAZEL',
'version': '0.0.0',
'description': 'This is a dummy package.json as API Extractor always requires one.',
}));
}
// API extractor doesn't always support the version of TypeScript used in the repo
// example: at the moment it is not compatable with 3.2
// to use the internal TypeScript we shall not create a program but rather pass a parsed tsConfig.
const parsedTsConfig = parsedConfig !.config as any;
const compilerOptions = parsedTsConfig.compilerOptions;
for (const [key, values] of Object.entries<string[]>(compilerOptions.paths)) {
if (key === '*') {
continue;
}
// we shall not pass ts files as this will need to be parsed, and for example rxjs,
// cannot be compiled with our tsconfig, as ours is more strict
// hence amend the paths to point always to the '.d.ts' files.
compilerOptions.paths[key] = values.map(path => {
const pathSuffix = /(\*|index)$/.test(path) ? '.d.ts' : '/index.d.ts';
return path + pathSuffix;
});
}
const extractorOptions: IExtractorOptions = {
localBuild: acceptApiUpdates,
customLogger: DEBUG ? undefined : {
// don't log verbose messages when not in debug mode
logVerbose: _message => {}
}
};
const extractorConfig: IExtractorConfig = {
compiler: {
configType: 'tsconfig',
overrideTsconfig: parsedTsConfig,
rootFolder: path.resolve(path.dirname(tsConfig))
},
project: {
entryPointSourceFile: path.resolve(entryPoint),
},
apiReviewFile: {
enabled: !!apiReviewFolder,
apiReviewFolder: apiReviewFolder && path.resolve(apiReviewFolder),
},
apiJsonFile: {
enabled: false,
},
policies: {
namespaceSupport: 'permissive',
},
validationRules: {
missingReleaseTags: ExtractorValidationRulePolicy.allow,
},
dtsRollup: {
enabled: !!dtsBundleOut,
publishFolder: dtsBundleOut && path.resolve(path.dirname(dtsBundleOut)),
mainDtsRollupPath: dtsBundleOut && path.basename(dtsBundleOut),
},
tsdocMetadata: {
enabled: false,
}
};
const extractor = new Extractor(extractorConfig, extractorOptions);
const isSuccessful = extractor.processProject();
// API extractor errors are emitted by it's logger.
return isSuccessful ? 0 : 1;
}
示例5: runOneBuild
export function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
if (args[0] === '-p') args.shift();
// Strip leading at-signs, used to indicate a params file
const project = args[0].replace(/^@+/, '');
const [parsedOptions, errors] = parseTsconfig(project);
if (errors && errors.length) {
console.error(ng.formatDiagnostics(errors));
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};
// Allow Bazel users to control some of the bazel options.
// Since TypeScript's "extends" mechanism applies only to "compilerOptions"
// we have to repeat some of their logic to get the user's "angularCompilerOptions".
if (config['extends']) {
// Load the user's config file
// Note: this doesn't handle recursive extends so only a user's top level
// `angularCompilerOptions` will be considered. As this code is going to be
// removed with Ivy, the added complication of handling recursive extends
// is likely not needed.
let userConfigFile = resolveNormalizedPath(path.dirname(project), config['extends']);
if (!userConfigFile.endsWith('.json')) userConfigFile += '.json';
const {config: userConfig, error} = ts.readConfigFile(userConfigFile, ts.sys.readFile);
if (error) {
console.error(ng.formatDiagnostics([error]));
return false;
}
// All user angularCompilerOptions values that a user has control
// over should be collected here
if (userConfig.angularCompilerOptions) {
angularCompilerOptions.diagnostics =
angularCompilerOptions.diagnostics || userConfig.angularCompilerOptions.diagnostics;
angularCompilerOptions.trace =
angularCompilerOptions.trace || userConfig.angularCompilerOptions.trace;
angularCompilerOptions.disableExpressionLowering =
angularCompilerOptions.disableExpressionLowering ||
userConfig.angularCompilerOptions.disableExpressionLowering;
angularCompilerOptions.disableTypeScriptVersionCheck =
angularCompilerOptions.disableTypeScriptVersionCheck ||
userConfig.angularCompilerOptions.disableTypeScriptVersionCheck;
angularCompilerOptions.i18nOutLocale =
angularCompilerOptions.i18nOutLocale || userConfig.angularCompilerOptions.i18nOutLocale;
angularCompilerOptions.i18nOutFormat =
angularCompilerOptions.i18nOutFormat || userConfig.angularCompilerOptions.i18nOutFormat;
angularCompilerOptions.i18nOutFile =
angularCompilerOptions.i18nOutFile || userConfig.angularCompilerOptions.i18nOutFile;
angularCompilerOptions.i18nInFormat =
angularCompilerOptions.i18nInFormat || userConfig.angularCompilerOptions.i18nInFormat;
angularCompilerOptions.i18nInLocale =
angularCompilerOptions.i18nInLocale || userConfig.angularCompilerOptions.i18nInLocale;
angularCompilerOptions.i18nInFile =
angularCompilerOptions.i18nInFile || userConfig.angularCompilerOptions.i18nInFile;
angularCompilerOptions.i18nInMissingTranslations =
angularCompilerOptions.i18nInMissingTranslations ||
userConfig.angularCompilerOptions.i18nInMissingTranslations;
angularCompilerOptions.i18nUseExternalIds = angularCompilerOptions.i18nUseExternalIds ||
userConfig.angularCompilerOptions.i18nUseExternalIds;
angularCompilerOptions.preserveWhitespaces = angularCompilerOptions.preserveWhitespaces ||
userConfig.angularCompilerOptions.preserveWhitespaces;
}
}
const expectedOuts = config['angularCompilerOptions']['expectedOut'];
const {basePath} = ng.calcProjectFileAndBasePath(project);
const compilerOpts = ng.createNgCompilerOptions(basePath, config, tsOptions);
const tsHost = ts.createCompilerHost(compilerOpts, true);
const {diagnostics} = compile({
allDepsCompiledWithBazel: ALL_DEPS_COMPILED_WITH_BAZEL,
compilerOpts,
tsHost,
bazelOpts,
files,
inputs,
expectedOuts
});
if (diagnostics.length) {
console.error(ng.formatDiagnostics(diagnostics));
}
return diagnostics.every(d => d.category !== ts.DiagnosticCategory.Error);
}