Skip to content

Commit 8521002

Browse files
committed
Baseline emitted files that are written even if same file contents
1 parent e43d504 commit 8521002

File tree

58 files changed

+191
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+191
-15
lines changed

src/harness/vfs.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ namespace vfs {
3333
let devCount = 0; // A monotonically increasing count of device ids
3434
let inoCount = 0; // A monotonically increasing count of inodes
3535

36+
export interface DiffOptions {
37+
includeChangedFileWithSameContent?: boolean;
38+
}
39+
3640
/**
3741
* Represents a virtual POSIX-like file system.
3842
*/
@@ -693,21 +697,25 @@ namespace vfs {
693697
* Generates a `FileSet` patch containing all the entries in this `FileSystem` that are not in `base`.
694698
* @param base The base file system. If not provided, this file system's `shadowRoot` is used (if present).
695699
*/
696-
public diff(base = this.shadowRoot) {
700+
public diff(base = this.shadowRoot, options: DiffOptions = {}) {
697701
const differences: FileSet = {};
698-
const hasDifferences = base ? FileSystem.rootDiff(differences, this, base) : FileSystem.trackCreatedInodes(differences, this, this._getRootLinks());
702+
const hasDifferences = base ?
703+
FileSystem.rootDiff(differences, this, base, options) :
704+
FileSystem.trackCreatedInodes(differences, this, this._getRootLinks());
699705
return hasDifferences ? differences : undefined;
700706
}
701707

702708
/**
703709
* Generates a `FileSet` patch containing all the entries in `chagned` that are not in `base`.
704710
*/
705-
public static diff(changed: FileSystem, base: FileSystem) {
711+
public static diff(changed: FileSystem, base: FileSystem, options: DiffOptions = {}) {
706712
const differences: FileSet = {};
707-
return FileSystem.rootDiff(differences, changed, base) ? differences : undefined;
713+
return FileSystem.rootDiff(differences, changed, base, options) ?
714+
differences :
715+
undefined;
708716
}
709717

710-
private static diffWorker(container: FileSet, changed: FileSystem, changedLinks: ReadonlyMap<string, Inode> | undefined, base: FileSystem, baseLinks: ReadonlyMap<string, Inode> | undefined) {
718+
private static diffWorker(container: FileSet, changed: FileSystem, changedLinks: ReadonlyMap<string, Inode> | undefined, base: FileSystem, baseLinks: ReadonlyMap<string, Inode> | undefined, options: DiffOptions) {
711719
if (changedLinks && !baseLinks) return FileSystem.trackCreatedInodes(container, changed, changedLinks);
712720
if (baseLinks && !changedLinks) return FileSystem.trackDeletedInodes(container, baseLinks);
713721
if (changedLinks && baseLinks) {
@@ -724,10 +732,10 @@ namespace vfs {
724732
const baseNode = baseLinks.get(basename);
725733
if (baseNode) {
726734
if (isDirectory(changedNode) && isDirectory(baseNode)) {
727-
return hasChanges = FileSystem.directoryDiff(container, basename, changed, changedNode, base, baseNode) || hasChanges;
735+
return hasChanges = FileSystem.directoryDiff(container, basename, changed, changedNode, base, baseNode, options) || hasChanges;
728736
}
729737
if (isFile(changedNode) && isFile(baseNode)) {
730-
return hasChanges = FileSystem.fileDiff(container, basename, changed, changedNode, base, baseNode) || hasChanges;
738+
return hasChanges = FileSystem.fileDiff(container, basename, changed, changedNode, base, baseNode, options) || hasChanges;
731739
}
732740
if (isSymlink(changedNode) && isSymlink(baseNode)) {
733741
return hasChanges = FileSystem.symlinkDiff(container, basename, changedNode, baseNode) || hasChanges;
@@ -740,7 +748,7 @@ namespace vfs {
740748
return false;
741749
}
742750

743-
private static rootDiff(container: FileSet, changed: FileSystem, base: FileSystem) {
751+
private static rootDiff(container: FileSet, changed: FileSystem, base: FileSystem, options: DiffOptions) {
744752
while (!changed._lazy.links && changed._shadowRoot) changed = changed._shadowRoot;
745753
while (!base._lazy.links && base._shadowRoot) base = base._shadowRoot;
746754

@@ -750,10 +758,10 @@ namespace vfs {
750758
// no difference if the root links are empty and unshadowed
751759
if (!changed._lazy.links && !changed._shadowRoot && !base._lazy.links && !base._shadowRoot) return false;
752760

753-
return FileSystem.diffWorker(container, changed, changed._getRootLinks(), base, base._getRootLinks());
761+
return FileSystem.diffWorker(container, changed, changed._getRootLinks(), base, base._getRootLinks(), options);
754762
}
755763

756-
private static directoryDiff(container: FileSet, basename: string, changed: FileSystem, changedNode: DirectoryInode, base: FileSystem, baseNode: DirectoryInode) {
764+
private static directoryDiff(container: FileSet, basename: string, changed: FileSystem, changedNode: DirectoryInode, base: FileSystem, baseNode: DirectoryInode, options: DiffOptions) {
757765
while (!changedNode.links && changedNode.shadowRoot) changedNode = changedNode.shadowRoot;
758766
while (!baseNode.links && baseNode.shadowRoot) baseNode = baseNode.shadowRoot;
759767

@@ -770,15 +778,15 @@ namespace vfs {
770778

771779
// no difference if both nodes have identical children
772780
const children: FileSet = {};
773-
if (!FileSystem.diffWorker(children, changed, changed._getLinks(changedNode), base, base._getLinks(baseNode))) {
781+
if (!FileSystem.diffWorker(children, changed, changed._getLinks(changedNode), base, base._getLinks(baseNode), options)) {
774782
return false;
775783
}
776784

777785
container[basename] = new Directory(children);
778786
return true;
779787
}
780788

781-
private static fileDiff(container: FileSet, basename: string, changed: FileSystem, changedNode: FileInode, base: FileSystem, baseNode: FileInode) {
789+
private static fileDiff(container: FileSet, basename: string, changed: FileSystem, changedNode: FileInode, base: FileSystem, baseNode: FileInode, options: DiffOptions) {
782790
while (!changedNode.buffer && changedNode.shadowRoot) changedNode = changedNode.shadowRoot;
783791
while (!baseNode.buffer && baseNode.shadowRoot) baseNode = baseNode.shadowRoot;
784792

@@ -800,7 +808,11 @@ namespace vfs {
800808
if (changedBuffer === baseBuffer) return false;
801809

802810
// no difference if both buffers are identical
803-
if (Buffer.compare(changedBuffer, baseBuffer) === 0) return false;
811+
if (Buffer.compare(changedBuffer, baseBuffer) === 0) {
812+
if (!options.includeChangedFileWithSameContent) return false;
813+
container[basename] = new SameFileContentFile(changedBuffer);
814+
return true;
815+
}
804816

805817
container[basename] = new File(changedBuffer);
806818
return true;
@@ -1360,6 +1372,12 @@ namespace vfs {
13601372
}
13611373
}
13621374

1375+
export class SameFileContentFile extends File {
1376+
constructor(data: Buffer | string, metaAndEncoding?: { encoding?: string, meta?: Record<string, any> }) {
1377+
super(data, metaAndEncoding);
1378+
}
1379+
}
1380+
13631381
/** Extended options for a hard link in a `FileSet` */
13641382
export class Link {
13651383
public readonly path: string;
@@ -1546,6 +1564,9 @@ namespace vfs {
15461564
else if (entry instanceof Directory) {
15471565
text += formatPatchWorker(file, entry.files);
15481566
}
1567+
else if (entry instanceof SameFileContentFile) {
1568+
text += `//// [${file}] file written with same contents\r\n`;
1569+
}
15491570
else if (entry instanceof File) {
15501571
const content = typeof entry.data === "string" ? entry.data : entry.data.toString("utf8");
15511572
text += `//// [${file}]\r\n${content}\r\n\r\n`;
@@ -1582,4 +1603,4 @@ namespace vfs {
15821603
}
15831604
}
15841605
}
1585-
// tslint:enable:no-null-keyword
1606+
// tslint:enable:no-null-keyword

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ interface Symbol {
285285
}
286286

287287
function generateBaseline(fs: vfs.FileSystem, proj: string, scenario: string, subScenario: string, baseFs: vfs.FileSystem) {
288-
const patch = fs.diff(baseFs);
288+
const patch = fs.diff(baseFs, { includeChangedFileWithSameContent: true });
289289
// tslint:disable-next-line:no-null-keyword
290290
Harness.Baseline.runBaseline(`tsbuild/${proj}/${subScenario.split(" ").join("-")}/${scenario.split(" ").join("-")}.js`, patch ? vfs.formatPatch(patch) : null);
291291
}

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/modules-and-globals-mixed-in-amd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ declare const myVar = 30;
332332
//// [/src/lib/file1.ts]
333333
export const x = 10;console.log(x);
334334

335+
//// [/src/lib/module.d.ts] file written with same contents
336+
//// [/src/lib/module.d.ts.map] file written with same contents
337+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
335338
//// [/src/lib/module.js]
336339
var myGlob = 20;
337340
define("file1", ["require", "exports"], function (require, exports) {

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-emitHelpers-in-all-projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ export const x = 10;function forlibfile1Rest() {
790790
const { b, ...rest } = { a: 10, b: 30, yy: 30 };
791791
}console.log(x);
792792

793+
//// [/src/lib/module.d.ts] file written with same contents
794+
//// [/src/lib/module.d.ts.map] file written with same contents
795+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
793796
//// [/src/lib/module.js]
794797
var __read = (this && this.__read) || function (o, n) {
795798
var m = typeof Symbol === "function" && o[Symbol.iterator];

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-prologues-in-all-projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ declare const myVar = 30;
482482
//// [/src/lib/file1.ts]
483483
export const x = 10;console.log(x);
484484

485+
//// [/src/lib/module.d.ts] file written with same contents
486+
//// [/src/lib/module.d.ts.map] file written with same contents
487+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
485488
//// [/src/lib/module.js]
486489
"use strict";
487490
"myPrologue";

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/shebang-in-all-projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ declare const myVar = 30;
338338
#!someshebang lib file1
339339
export const x = 10;console.log(x);
340340

341+
//// [/src/lib/module.d.ts] file written with same contents
342+
//// [/src/lib/module.d.ts.map] file written with same contents
343+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
341344
//// [/src/lib/module.js]
342345
#!someshebang lib file0
343346
var myGlob = 20;

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,9 @@ export namespace normalN {
18931893
/*@internal*/ export const internalConst = 10;
18941894
/*@internal*/ export enum internalEnum { a, b, c }console.log(x);
18951895

1896+
//// [/src/lib/module.d.ts] file written with same contents
1897+
//// [/src/lib/module.d.ts.map] file written with same contents
1898+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
18961899
//// [/src/lib/module.js]
18971900
/*@internal*/ var myGlob = 20;
18981901
define("file1", ["require", "exports"], function (require, exports) {

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/triple-slash-refs-in-all-projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ declare const myVar = 30;
432432
//// [/src/lib/file1.ts]
433433
export const x = 10;console.log(x);
434434

435+
//// [/src/lib/module.d.ts] file written with same contents
436+
//// [/src/lib/module.d.ts.map] file written with same contents
437+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
435438
//// [/src/lib/module.js]
436439
///<reference path="./tripleRef.d.ts"/>
437440
var file0Const = new libfile0();

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/multiple-emitHelpers-in-all-projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ declare function appfile4Spread(...b: number[]): void;
724724
//// [/src/lib/file1.ts]
725725
export const x = 10;function forlibfile1Rest() { }
726726

727+
//// [/src/lib/module.d.ts] file written with same contents
728+
//// [/src/lib/module.d.ts.map] file written with same contents
729+
//// [/src/lib/module.d.ts.map.baseline.txt] file written with same contents
727730
//// [/src/lib/module.js]
728731
var __read = (this && this.__read) || function (o, n) {
729732
var m = typeof Symbol === "function" && o[Symbol.iterator];

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/multiple-prologues-in-all-projects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ declare const myVar = 30;
647647
"myPrologue5"
648648
export const x = 10;
649649

650+
//// [/src/lib/module.d.ts] file written with same contents
650651
//// [/src/lib/module.d.ts.map]
651652
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["file0.ts","file1.ts","file2.ts","global.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAlB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;;ICApB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"}
652653

0 commit comments

Comments
 (0)