forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
55 lines (44 loc) · 1.5 KB
/
Copy pathinput.js
File metadata and controls
55 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// @ts-check
import * as assert from "node:assert";
import * as fs from "node:fs";
import * as path from "node:path";
import { setup } from "#dev/process";
const { execBuild, execClean } = setup(import.meta.dirname);
const isWindows = process.platform === "win32";
// Use a node script for cross-platform path logging
const logFile = path.join(import.meta.dirname, "post-build-paths.txt");
// Clean up any previous log file
if (fs.existsSync(logFile)) {
fs.unlinkSync(logFile);
}
const out = await execBuild();
if (out.status !== 0) {
assert.fail(out.stdout + out.stderr);
}
try {
// Verify that the post-build command received the correct paths
assert.ok(fs.existsSync(logFile), "post-build-paths.txt should exist");
const paths = fs.readFileSync(logFile, "utf-8").trim().split("\n");
// With in-source: true, the paths should be next to the source files
// e.g., /path/to/post-build/src/demo.js (Unix)
// e.g., C:\path\to\post-build\src\demo.js (Windows)
const srcSep = isWindows ? "\\src\\" : "/src/";
const libBsSep = isWindows ? "\\lib\\bs\\" : "/lib/bs/";
for (const p of paths) {
assert.ok(
p.includes(srcSep) && p.endsWith(".js"),
`Path should be in src/ directory: ${p}`,
);
// Should NOT be in lib/bs/ when in-source is true
assert.ok(
!p.includes(libBsSep),
`Path should not be in lib/bs/ when in-source is true: ${p}`,
);
}
} finally {
// Clean up log file
if (fs.existsSync(logFile)) {
fs.unlinkSync(logFile);
}
await execClean();
}