17 lines
2.0 KiB
JavaScript
17 lines
2.0 KiB
JavaScript
// Compare with the implementation's initial baseline, preserving unrelated local edits.
|
|
const ts=require('typescript'),fs=require('node:fs'),path=require('node:path'),cp=require('node:child_process');
|
|
const root=path.resolve(__dirname,'..'),cfg=ts.readConfigFile(path.join(root,'tsconfig.json'),ts.sys.readFile).config;
|
|
const baselineRef=process.argv[2]||'bef538895219b2de19e2d917061b99337f43cff0';
|
|
cfg.include=['assets/**/*.ts','creator.d.ts'];
|
|
const parsed=ts.parseJsonConfigFileContent(cfg,ts.sys,root),options={...parsed.options,noEmit:true};
|
|
// Resolve tracked integration paths from Git instead of assuming folder locations.
|
|
const changed=cp.execFileSync('git',['diff',baselineRef,'--name-only'],{cwd:root,encoding:'utf8'}).trim().split(/\r?\n/).filter(p=>/\/(JiaZai|HomePopupQueue|HomeActivityEntryLayout)\.ts$/.test(p));
|
|
const previous=new Map(changed.map(p=>[path.normalize(path.join(root,p)),cp.execFileSync('git',['show',baselineRef+':'+p],{cwd:root,encoding:'utf8'})]));
|
|
function check(baseline){const host=ts.createCompilerHost(options),read=host.readFile;host.readFile=file=>baseline&&previous.has(path.normalize(file))?previous.get(path.normalize(file)):read(file);
|
|
const files=parsed.fileNames.filter(p=>!baseline||!(/[/\\]pyramid[/\\]|Pyramid(?:View|Service)\.ts$/.test(p)));
|
|
const program=ts.createProgram(files,options,host);return ts.getPreEmitDiagnostics(program).map(d=>({file:d.file?path.relative(root,d.file.fileName).replace(/\\/g,'/'):'',code:d.code,message:ts.flattenDiagnosticMessageText(d.messageText,' ')}));}
|
|
const baseline=check(true),current=check(false),known=new Set(baseline.map(d=>JSON.stringify(d))),introduced=current.filter(d=>!known.has(JSON.stringify(d)));
|
|
console.log(JSON.stringify({baseline:baseline.length,current:current.length,introduced},null,2));
|
|
fs.mkdirSync(path.join(root,'temp'),{recursive:true});fs.writeFileSync(path.join(root,'temp/pyramid-types.json'),JSON.stringify({baseline,current,introduced},null,2));
|
|
process.exitCode=introduced.length?1:0;
|