ts-ag 1.1.26 → 1.2.0

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.
@@ -1,14 +1,43 @@
1
1
  #!/usr/bin/env bun
2
- import { r as writeIfDifferent } from "../fs-y6bE7U3-.mjs";
3
- import { t as colorText } from "../cli-CoTTeqrl.mjs";
4
- import { dirname, isAbsolute, join, relative, resolve } from "path";
5
- import { parseArgs } from "util";
6
- import console from "console";
2
+ import { t as isDirectExecution } from "../utils-DLairfc9.mjs";
3
+ import { t as colorText } from "../cli-DAs6KeZ2.mjs";
4
+ import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
5
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
6
+ import { parseArgs } from "node:util";
7
+ import console$1 from "console";
7
8
  import { existsSync, mkdirSync, readFileSync } from "fs";
8
- import { fileURLToPath } from "url";
9
+ import "url";
9
10
  import { watch } from "chokidar";
10
11
  import { parseTsconfig } from "get-tsconfig";
11
12
  import { format } from "oxfmt";
13
+ import chalk from "chalk";
14
+ //#region src/utils/fs.ts
15
+ /**
16
+ * @returns true if a filepath exists
17
+ */
18
+ async function exists(filePath) {
19
+ try {
20
+ await lstat(filePath);
21
+ return true;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ /**
27
+ * Writes data to a filepath if it is different
28
+ * @returns true if the file is written to
29
+ */
30
+ async function writeIfDifferent(filePath, newData) {
31
+ const directory = dirname(filePath);
32
+ if (!await exists(directory)) await mkdir(directory, { recursive: true });
33
+ if (await exists(filePath)) {
34
+ if (await readFile(filePath, "utf8") === newData) return false;
35
+ }
36
+ await writeFile(filePath, newData, "utf8");
37
+ console.log(chalk.green("Writing to"), filePath);
38
+ return true;
39
+ }
40
+ //#endregion
12
41
  //#region src/scripts/ts-build-config.ts
13
42
  const DEFAULT_TEST_EXCLUDES = [
14
43
  "**/*.test.ts",
@@ -21,9 +50,9 @@ const DEFAULT_TEST_EXCLUDES = [
21
50
  const GENERATED_FILE_HEADER = "// generated by ts-build-config";
22
51
  const LABEL = colorText("cyan", "[ts-build-config]");
23
52
  const formatPath = (filePath) => colorText("dim", relative(process.cwd(), filePath));
24
- const logInfo = (message) => console.log(`${LABEL} ${message}`);
25
- const logWarn = (message) => console.warn(`${LABEL} ${colorText("yellow", message)}`);
26
- const logError = (message) => console.error(`${LABEL} ${colorText("red", message)}`);
53
+ const logInfo = (message) => console$1.log(`${LABEL} ${message}`);
54
+ const logWarn = (message) => console$1.warn(`${LABEL} ${colorText("yellow", message)}`);
55
+ const logError = (message) => console$1.error(`${LABEL} ${colorText("red", message)}`);
27
56
  function unique(items) {
28
57
  return Array.from(new Set(items));
29
58
  }
@@ -152,7 +181,7 @@ async function generateBuildConfigs(entry, options) {
152
181
  else throw new Error("Null returned from getTsConfig");
153
182
  } catch (e) {
154
183
  logWarn(`Skipping unreadable config: ${formatPath(tsconfigPath)}`);
155
- if (verbose) console.warn(e);
184
+ if (verbose) console$1.warn(e);
156
185
  continue;
157
186
  }
158
187
  loadedConfigs.set(res.path, res);
@@ -283,16 +312,10 @@ async function main() {
283
312
  regenerator.syncWatchedConfigs(watcher);
284
313
  });
285
314
  }
286
- function isDirectExecution() {
287
- if (!process.argv[1]) return false;
288
- return resolve(process.argv[1]) === fileURLToPath(import.meta.url);
289
- }
290
- if (isDirectExecution()) main().catch((err) => {
315
+ if (isDirectExecution(import.meta.url)) main().catch((err) => {
291
316
  logError("Unhandled error");
292
- console.error(err);
317
+ console$1.error(err);
293
318
  process.exit(1);
294
319
  });
295
320
  //#endregion
296
321
  export { GENERATED_FILE_HEADER, computeExtraExcludes, createRegenerator, ensureDotRelative, formatBuildTsconfigJson, generateBuildConfigs, isGeneratedByThisScript, main, replaceRefsWithBuildConfigs, resolveTsConfigPath, shouldUseBuildConfig, unique, withTrailingNewline, writeBuildTsconfig };
297
-
298
- //# sourceMappingURL=ts-build-config.mjs.map
@@ -0,0 +1,15 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ //#region src/scripts/utils.ts
5
+ function isDirectExecution(importMetaUrl, argv = process.argv) {
6
+ const entrypoint = argv[1];
7
+ if (!entrypoint) return false;
8
+ try {
9
+ return realpathSync.native(resolve(entrypoint)) === realpathSync.native(fileURLToPath(importMetaUrl));
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+ //#endregion
15
+ export { isDirectExecution as t };