Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
No EOL
3.7 KiB
Text
80 lines
No EOL
3.7 KiB
Text
import path from 'path';
|
|
import { getFormattedDiagnostic } from './diagnosticFormatter';
|
|
import { getTypeScriptConfiguration } from './getTypeScriptConfiguration';
|
|
import { getRequiredConfiguration } from './writeConfigurationDefaults';
|
|
import { CompileError } from '../compile-error';
|
|
import { warn } from '../../build/output/log';
|
|
export async function runTypeCheck(typescript, baseDir, distDir, tsConfigPath, cacheDir, isAppDirEnabled) {
|
|
const effectiveConfiguration = await getTypeScriptConfiguration(typescript, tsConfigPath);
|
|
if (effectiveConfiguration.fileNames.length < 1) {
|
|
return {
|
|
hasWarnings: false,
|
|
inputFilesCount: 0,
|
|
totalFilesCount: 0,
|
|
incremental: false
|
|
};
|
|
}
|
|
const requiredConfig = getRequiredConfiguration(typescript);
|
|
const options = {
|
|
...requiredConfig,
|
|
...effectiveConfiguration.options,
|
|
declarationMap: false,
|
|
emitDeclarationOnly: false,
|
|
noEmit: true
|
|
};
|
|
let program;
|
|
let incremental = false;
|
|
if ((options.incremental || options.composite) && cacheDir) {
|
|
if (options.composite) {
|
|
warn('TypeScript project references are not fully supported. Attempting to build in incremental mode.');
|
|
}
|
|
incremental = true;
|
|
program = typescript.createIncrementalProgram({
|
|
rootNames: effectiveConfiguration.fileNames,
|
|
options: {
|
|
...options,
|
|
composite: false,
|
|
incremental: true,
|
|
tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo')
|
|
}
|
|
});
|
|
} else {
|
|
program = typescript.createProgram(effectiveConfiguration.fileNames, options);
|
|
}
|
|
const result = program.emit();
|
|
const ignoreRegex = [
|
|
// matches **/__(tests|mocks)__/**
|
|
/[\\/]__(?:tests|mocks)__[\\/]/,
|
|
// matches **/*.(spec|test).*
|
|
/(?<=[\\/.])(?:spec|test)\.[^\\/]+$/
|
|
];
|
|
const regexIgnoredFile = new RegExp(ignoreRegex.map((r)=>r.source).join('|'));
|
|
const allDiagnostics = typescript.getPreEmitDiagnostics(program).concat(result.diagnostics).filter((d)=>!(d.file && regexIgnoredFile.test(d.file.fileName)));
|
|
const firstError = allDiagnostics.find((d)=>d.category === typescript.DiagnosticCategory.Error && Boolean(d.file)) ?? allDiagnostics.find((d)=>d.category === typescript.DiagnosticCategory.Error);
|
|
// In test mode, we want to check all diagnostics, not just the first one.
|
|
if (process.env.__NEXT_TEST_MODE) {
|
|
if (firstError) {
|
|
const allErrors = allDiagnostics.filter((d)=>d.category === typescript.DiagnosticCategory.Error).map((d)=>'[Test Mode] ' + getFormattedDiagnostic(typescript, baseDir, distDir, d, isAppDirEnabled));
|
|
console.error('\n\n===== TS errors =====\n\n' + allErrors.join('\n\n') + '\n\n===== TS errors =====\n\n');
|
|
// Make sure all stdout is flushed before we exit.
|
|
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
}
|
|
}
|
|
if (firstError) {
|
|
throw Object.defineProperty(new CompileError(getFormattedDiagnostic(typescript, baseDir, distDir, firstError, isAppDirEnabled)), "__NEXT_ERROR_CODE", {
|
|
value: "E394",
|
|
enumerable: false,
|
|
configurable: true
|
|
});
|
|
}
|
|
const warnings = allDiagnostics.filter((d)=>d.category === typescript.DiagnosticCategory.Warning).map((d)=>getFormattedDiagnostic(typescript, baseDir, distDir, d, isAppDirEnabled));
|
|
return {
|
|
hasWarnings: true,
|
|
warnings,
|
|
inputFilesCount: effectiveConfiguration.fileNames.length,
|
|
totalFilesCount: program.getSourceFiles().length,
|
|
incremental
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=runTypeCheck.js.map |