• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmcelhaney / counterfact / 7104204113

05 Dec 2023 05:14PM CUT coverage: 83.129%. Remained the same
7104204113

Pull #673

github

pmcelhaney
make sure the types.d.ts file is copied do dist
Pull Request #673: make sure the types.d.ts file is copied do dist

774 of 866 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

2473 of 3040 relevant lines covered (81.35%)

39.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.53
/src/typescript-generator/repository.js
1
import fs from "node:fs/promises";
2✔
2
import nodePath, { dirname } from "node:path";
2✔
3
import { fileURLToPath } from "node:url";
2✔
4

2✔
5
import createDebug from "debug";
2✔
6

2✔
7
import { ensureDirectoryExists } from "../util/ensure-directory-exists.js";
2✔
8
import { Script } from "./script.js";
2✔
9

2✔
10
const debug = createDebug("counterfact:server:repository");
2✔
11

2✔
12
// eslint-disable-next-line no-underscore-dangle
2✔
13
const __dirname = dirname(fileURLToPath(import.meta.url)).replaceAll("\\", "/");
2✔
14

2✔
15
debug("dirname is %s", __dirname);
2✔
16

2✔
17
export class Repository {
2✔
18
  constructor() {
2✔
19
    this.scripts = new Map();
22✔
20
  }
22✔
21

2✔
22
  get(path) {
2✔
23
    debug("getting script at %s", path);
186✔
24

186✔
25
    if (this.scripts.has(path)) {
186✔
26
      debug("already have script %s, returning it", path);
76✔
27

76✔
28
      return this.scripts.get(path);
76✔
29
    }
76✔
30

110✔
31
    debug("don't have %s, creating it", path);
110✔
32

110✔
33
    const script = new Script(this, path);
110✔
34

110✔
35
    this.scripts.set(path, script);
110✔
36

110✔
37
    return script;
110✔
38
  }
110✔
39

2✔
40
  async finished() {
2✔
41
    while (
2✔
42
      Array.from(this.scripts.values()).some((script) => script.isInProgress())
2✔
43
    ) {
2✔
44
      debug("waiting for %i scripts to finish", this.scripts.size);
2✔
45
      // eslint-disable-next-line no-await-in-loop
2✔
46
      await Promise.all(
2✔
47
        Array.from(this.scripts.values(), (script) => script.finished()),
2✔
48
      );
2✔
49
    }
2✔
50
  }
2✔
51

2✔
52
  copyCoreFiles(destination) {
2✔
53
    return fs.copyFile(
×
54
      nodePath
×
NEW
55
        .join(__dirname, "../../dist/server/types.d.ts")
×
56
        .replaceAll("\\", "/"),
×
57
      nodePath.join(destination, "types.d.ts").replaceAll("\\", "/"),
×
58
    );
×
59
  }
×
60

2✔
61
  async writeFiles(destination) {
2✔
62
    debug(
×
63
      "waiting for %i or more scripts to finish before writing files",
×
64
      this.scripts.size,
×
65
    );
×
66
    await this.finished();
×
67
    debug("all %i scripts are finished", this.scripts.size);
×
68

×
69
    const writeFiles = Array.from(
×
70
      this.scripts.entries(),
×
71
      async ([path, script]) => {
×
72
        const contents = await script.contents();
×
73

×
74
        const fullPath = nodePath.join(destination, path).replaceAll("\\", "/");
×
75

×
76
        await ensureDirectoryExists(fullPath);
×
77

×
78
        if (
×
79
          path.startsWith("paths") &&
×
80
          (await fs
×
81
            .stat(fullPath)
×
82
            .then((stat) => stat.isFile())
×
83
            .catch(() => false))
×
84
        ) {
×
85
          debug(`not overwriting ${fullPath}\n`);
×
86

×
87
          return;
×
88
        }
×
89

×
90
        debug("about to write", fullPath);
×
91
        await fs.writeFile(fullPath, contents);
×
92
        debug("did write", fullPath);
×
93
      },
×
94
    );
×
95

×
96
    await Promise.all(writeFiles);
×
97

×
98
    await this.copyCoreFiles(destination);
×
99
  }
×
100
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc