as-test 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +1 -4
- package/assembly/index.ts +66 -47
- package/assembly/src/expectation.ts +44 -86
- package/assembly/src/fuzz.ts +10 -10
- package/assembly/src/log.ts +3 -3
- package/assembly/src/reflect.ts +122 -0
- package/assembly/src/stringify.ts +240 -0
- package/assembly/src/suite.ts +48 -27
- package/assembly/src/tests.ts +7 -7
- package/assembly/util/wipc.ts +2 -2
- package/bin/build-worker-pool.js +9 -0
- package/bin/build-worker.js +27 -3
- package/bin/commands/build-core.js +144 -82
- package/bin/commands/init-core.js +0 -3
- package/bin/commands/run-core.js +165 -41
- package/bin/commands/run.js +2 -1
- package/bin/commands/test.js +2 -1
- package/bin/dependency-graph.js +132 -0
- package/bin/index.js +534 -79
- package/bin/reporters/default.js +34 -0
- package/bin/util.js +9 -0
- package/package.json +4 -7
- package/transform/lib/equals.js +388 -0
- package/transform/lib/index.js +2 -0
- package/transform/lib/log.js +3 -7
- package/transform/lib/types.js +4 -2
- package/transform/lib/transform.js +0 -502
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
const MODE_KEY_DEFAULT = "__default__";
|
|
3
|
+
function modeKey(mode) {
|
|
4
|
+
return mode ?? MODE_KEY_DEFAULT;
|
|
5
|
+
}
|
|
6
|
+
function specKey(mode, specEntry) {
|
|
7
|
+
// NUL delimiter: it cannot appear in a mode name or a filesystem path, so
|
|
8
|
+
// the (mode, path) key can never collide. Written as an escape (not a raw
|
|
9
|
+
// NUL byte) to keep this file text — a literal NUL flags it binary to git/grep.
|
|
10
|
+
return `${modeKey(mode)}\u0000${path.resolve(specEntry)}`;
|
|
11
|
+
}
|
|
12
|
+
// asc reads many files we never care about for watch purposes — its own
|
|
13
|
+
// bundled stdlib and the package on disk. They never change between runs and
|
|
14
|
+
// would balloon both indices.
|
|
15
|
+
function isUninterestingForWatch(absPath) {
|
|
16
|
+
const normalized = absPath.replace(/\\/g, "/");
|
|
17
|
+
if (normalized.includes("/node_modules/assemblyscript/")) return true;
|
|
18
|
+
if (normalized.includes("/node_modules/binaryen/")) return true;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export class DependencyGraph {
|
|
22
|
+
constructor() {
|
|
23
|
+
// (mode, spec entry) -> set of absolute paths asc loaded for that build
|
|
24
|
+
this.specToFiles = new Map();
|
|
25
|
+
// absolute path -> set of (mode, spec entry) keys that depend on it
|
|
26
|
+
this.fileToSpecs = new Map();
|
|
27
|
+
// mode-prefixed key -> the absolute spec path (so we can return it cheaply)
|
|
28
|
+
this.specPaths = new Map();
|
|
29
|
+
// mode-prefixed key -> mode name (or undefined for default)
|
|
30
|
+
this.specModes = new Map();
|
|
31
|
+
}
|
|
32
|
+
recordBuild(specEntry, mode, files) {
|
|
33
|
+
const absSpec = path.resolve(specEntry);
|
|
34
|
+
const key = specKey(mode, absSpec);
|
|
35
|
+
const prior = this.specToFiles.get(key);
|
|
36
|
+
if (prior) {
|
|
37
|
+
for (const file of prior) {
|
|
38
|
+
const set = this.fileToSpecs.get(file);
|
|
39
|
+
if (!set) continue;
|
|
40
|
+
set.delete(key);
|
|
41
|
+
if (set.size === 0) this.fileToSpecs.delete(file);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const next = new Set();
|
|
45
|
+
next.add(absSpec);
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const abs = path.resolve(file);
|
|
48
|
+
if (isUninterestingForWatch(abs)) continue;
|
|
49
|
+
next.add(abs);
|
|
50
|
+
}
|
|
51
|
+
this.specToFiles.set(key, next);
|
|
52
|
+
this.specPaths.set(key, absSpec);
|
|
53
|
+
this.specModes.set(key, mode);
|
|
54
|
+
for (const file of next) {
|
|
55
|
+
let set = this.fileToSpecs.get(file);
|
|
56
|
+
if (!set) {
|
|
57
|
+
set = new Set();
|
|
58
|
+
this.fileToSpecs.set(file, set);
|
|
59
|
+
}
|
|
60
|
+
set.add(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Returns the set of absolute spec entry paths whose dependency set
|
|
64
|
+
// contains the changed file (across all recorded modes).
|
|
65
|
+
specsAffectedBy(changedFile) {
|
|
66
|
+
const abs = path.resolve(changedFile);
|
|
67
|
+
const keys = this.fileToSpecs.get(abs);
|
|
68
|
+
const out = new Set();
|
|
69
|
+
if (!keys) return out;
|
|
70
|
+
for (const key of keys) {
|
|
71
|
+
const spec = this.specPaths.get(key);
|
|
72
|
+
if (spec) out.add(spec);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
// Returns the set of (modeKey, absoluteSpecPath) tuples affected by the
|
|
77
|
+
// changed file. Useful when builds must be re-run per mode rather than
|
|
78
|
+
// once per spec.
|
|
79
|
+
affectedEntries(changedFile) {
|
|
80
|
+
const abs = path.resolve(changedFile);
|
|
81
|
+
const keys = this.fileToSpecs.get(abs);
|
|
82
|
+
const out = [];
|
|
83
|
+
if (!keys) return out;
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
const spec = this.specPaths.get(key);
|
|
86
|
+
if (!spec) continue;
|
|
87
|
+
out.push({ mode: this.specModes.get(key), spec });
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
knownSpecs(mode) {
|
|
92
|
+
const prefix = modeKey(mode) + "\u0000";
|
|
93
|
+
const out = new Set();
|
|
94
|
+
for (const [key, spec] of this.specPaths) {
|
|
95
|
+
if (key.startsWith(prefix)) out.add(spec);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
hasSpec(specEntry, mode) {
|
|
100
|
+
return this.specToFiles.has(specKey(mode, path.resolve(specEntry)));
|
|
101
|
+
}
|
|
102
|
+
forget(specEntry, mode) {
|
|
103
|
+
const key = specKey(mode, path.resolve(specEntry));
|
|
104
|
+
const prior = this.specToFiles.get(key);
|
|
105
|
+
if (prior) {
|
|
106
|
+
for (const file of prior) {
|
|
107
|
+
const set = this.fileToSpecs.get(file);
|
|
108
|
+
if (!set) continue;
|
|
109
|
+
set.delete(key);
|
|
110
|
+
if (set.size === 0) this.fileToSpecs.delete(file);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.specToFiles.delete(key);
|
|
114
|
+
this.specPaths.delete(key);
|
|
115
|
+
this.specModes.delete(key);
|
|
116
|
+
}
|
|
117
|
+
clear() {
|
|
118
|
+
this.specToFiles.clear();
|
|
119
|
+
this.fileToSpecs.clear();
|
|
120
|
+
this.specPaths.clear();
|
|
121
|
+
this.specModes.clear();
|
|
122
|
+
}
|
|
123
|
+
// Returns every recorded absolute file path (across all modes/specs).
|
|
124
|
+
// Used by the watch loop to extend its watched-directory set.
|
|
125
|
+
allRecordedFiles() {
|
|
126
|
+
const out = new Set();
|
|
127
|
+
for (const set of this.specToFiles.values()) {
|
|
128
|
+
for (const file of set) out.add(file);
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
}
|