@adamhl8/configs 3.1.0 → 3.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.
Files changed (74) hide show
  1. package/README.md +307 -73
  2. package/dist/configs/bask.base.d.ts +0 -2
  3. package/dist/configs/bask.base.d.ts.map +1 -1
  4. package/dist/configs/bask.base.js +1 -2
  5. package/dist/configs/bask.base.js.map +1 -1
  6. package/dist/configs/bunfig.base.toml +2 -2
  7. package/dist/configs/commitlint.base.d.ts +0 -2
  8. package/dist/configs/commitlint.base.d.ts.map +1 -1
  9. package/dist/configs/commitlint.base.js +1 -2
  10. package/dist/configs/knip.base.d.ts +1 -3
  11. package/dist/configs/knip.base.d.ts.map +1 -1
  12. package/dist/configs/knip.base.js +5 -2
  13. package/dist/configs/knip.base.js.map +1 -1
  14. package/dist/configs/oxfmt.base.d.ts +0 -2
  15. package/dist/configs/oxfmt.base.d.ts.map +1 -1
  16. package/dist/configs/oxfmt.base.js +1 -2
  17. package/dist/configs/oxlint.base.d.ts +1 -2
  18. package/dist/configs/oxlint.base.d.ts.map +1 -1
  19. package/dist/configs/oxlint.base.js +2 -2
  20. package/dist/configs/oxlint.base.js.map +1 -1
  21. package/dist/configs/release-it.base.d.ts +0 -2
  22. package/dist/configs/release-it.base.d.ts.map +1 -1
  23. package/dist/configs/release-it.base.js +1 -2
  24. package/dist/configs/tsconfig.base.json +2 -0
  25. package/dist/configs/tsdown.base.d.ts +3 -7
  26. package/dist/configs/tsdown.base.d.ts.map +1 -1
  27. package/dist/configs/tsdown.base.js +3 -8
  28. package/dist/configs/tsdown.base.js.map +1 -1
  29. package/dist/env/index.d.ts +0 -2
  30. package/dist/env/index.d.ts.map +1 -1
  31. package/dist/env/index.js +1 -2
  32. package/dist/env/utils.d.ts +0 -2
  33. package/dist/env/utils.d.ts.map +1 -1
  34. package/dist/env/utils.js +1 -2
  35. package/dist/merge-config/merge-config.d.ts +0 -2
  36. package/dist/merge-config/merge-config.d.ts.map +1 -1
  37. package/dist/merge-config/merge-config.js +1 -2
  38. package/dist/merge-config/merge.types.d.ts +0 -2
  39. package/dist/merge-config/merge.types.d.ts.map +1 -1
  40. package/dist/test-utils/fixture.d.ts +17 -0
  41. package/dist/test-utils/fixture.d.ts.map +1 -0
  42. package/dist/test-utils/fixture.js +20 -0
  43. package/dist/test-utils/fixture.js.map +1 -0
  44. package/dist/test-utils/index.d.ts +7 -0
  45. package/dist/test-utils/index.js +6 -0
  46. package/dist/test-utils/pack.d.ts +3 -0
  47. package/dist/test-utils/pack.d.ts.map +1 -0
  48. package/dist/test-utils/pack.js +16 -0
  49. package/dist/test-utils/pack.js.map +1 -0
  50. package/dist/test-utils/preload.d.ts +1 -0
  51. package/dist/test-utils/preload.js +7 -0
  52. package/dist/test-utils/preload.js.map +1 -0
  53. package/dist/test-utils/shell/bin-dirs.js +19 -0
  54. package/dist/test-utils/shell/bin-dirs.js.map +1 -0
  55. package/dist/test-utils/shell/command.d.ts +18 -0
  56. package/dist/test-utils/shell/command.d.ts.map +1 -0
  57. package/dist/test-utils/shell/command.js +63 -0
  58. package/dist/test-utils/shell/command.js.map +1 -0
  59. package/dist/test-utils/shell/env.d.ts +4 -0
  60. package/dist/test-utils/shell/env.d.ts.map +1 -0
  61. package/dist/test-utils/shell/env.js +11 -0
  62. package/dist/test-utils/shell/env.js.map +1 -0
  63. package/dist/test-utils/shell/node-shim.js +18 -0
  64. package/dist/test-utils/shell/node-shim.js.map +1 -0
  65. package/dist/test-utils/shell/shell.d.ts +42 -0
  66. package/dist/test-utils/shell/shell.d.ts.map +1 -0
  67. package/dist/test-utils/shell/shell.js +24 -0
  68. package/dist/test-utils/shell/shell.js.map +1 -0
  69. package/dist/test-utils/temp-dir.d.ts +3 -0
  70. package/dist/test-utils/temp-dir.d.ts.map +1 -0
  71. package/dist/test-utils/temp-dir.js +21 -0
  72. package/dist/test-utils/temp-dir.js.map +1 -0
  73. package/dist/utils.js +1 -2
  74. package/package.json +31 -23
@@ -0,0 +1,6 @@
1
+ import { minimalEnv } from "./shell/env.js";
2
+ import { createShell } from "./shell/shell.js";
3
+ import { makeTempDir } from "./temp-dir.js";
4
+ import { copyFixture } from "./fixture.js";
5
+ import { packPackage } from "./pack.js";
6
+ export { copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
@@ -0,0 +1,3 @@
1
+ /** Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path. */
2
+ export declare const packPackage: (root: string) => Promise<string>;
3
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","names":[],"sources":["../../src/test-utils/pack.ts"],"mappings":";qBAQa,cAAW,iBAAsB"}
@@ -0,0 +1,16 @@
1
+ import { createShell } from "./shell/shell.js";
2
+ import { makeTempDir } from "./temp-dir.js";
3
+ import path from "node:path";
4
+ import bun from "bun";
5
+ // src/test-utils/pack.ts
6
+ /** Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path. */
7
+ const packPackage = async (root) => {
8
+ const run = createShell({ cwd: root });
9
+ if (await bun.file(path.join(root, "tsdown.config.ts")).exists()) await run`bun tsdown`;
10
+ const destination = await makeTempDir(`${path.basename(root)}-pack-`);
11
+ const { stdout } = await run`bun pm pack --ignore-scripts --quiet --destination ${destination}`;
12
+ return path.resolve(destination, stdout);
13
+ };
14
+ export { packPackage };
15
+
16
+ //# sourceMappingURL=pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.js","names":[],"sources":["../../src/test-utils/pack.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport bun from \"bun\"\n\nimport { createShell } from \"#test-utils/shell/shell.ts\"\nimport { makeTempDir } from \"#test-utils/temp-dir.ts\"\n\n/** Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path. */\nexport const packPackage = async (root: string) => {\n const run = createShell({ cwd: root })\n if (await bun.file(path.join(root, \"tsdown.config.ts\")).exists()) await run`bun tsdown`\n\n const destination = await makeTempDir(`${path.basename(root)}-pack-`)\n // Skip lifecycle scripts because a `prepare` script would rebuild and run the package's own tasks.\n const { stdout } = await run`bun pm pack --ignore-scripts --quiet --destination ${destination}`\n return path.resolve(destination, stdout)\n}\n"],"mappings":";;;;;;AAQA,MAAa,cAAc,OAAO,SAAiB;CACjD,MAAM,MAAM,YAAY,EAAE,KAAK,KAAK,CAAC;CACrC,IAAI,MAAM,IAAI,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAC,CAAC,CAAC,OAAO,GAAG,MAAM,GAAG;CAE3E,MAAM,cAAc,MAAM,YAAY,GAAG,KAAK,SAAS,IAAI,EAAE,OAAO;CAEpE,MAAM,EAAE,WAAW,MAAM,GAAG,sDAAsD;CAClF,OAAO,KAAK,QAAQ,aAAa,MAAM;AACzC"}
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,7 @@
1
+ import { removeTempDirs } from "./temp-dir.js";
2
+ import { afterAll } from "bun:test";
3
+ // src/test-utils/preload.ts
4
+ afterAll(removeTempDirs);
5
+ export {};
6
+
7
+ //# sourceMappingURL=preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.js","names":[],"sources":["../../src/test-utils/preload.ts"],"sourcesContent":["import { afterAll } from \"bun:test\"\n\nimport { removeTempDirs } from \"#test-utils/temp-dir.ts\"\n\nafterAll(removeTempDirs)\n"],"mappings":";;;AAIA,SAAS,cAAc"}
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+ // src/test-utils/shell/bin-dirs.ts
3
+ /** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */
4
+ const getBinDirs = (dir) => {
5
+ const binDir = path.join(dir, "node_modules", ".bin");
6
+ const parent = path.dirname(dir);
7
+ return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)];
8
+ };
9
+ /** Puts `node_modules/.bin` of `cwd` and each of its parents first on `PATH`. */
10
+ const addBinDirs = (cwd, env) => {
11
+ const PATH = [...getBinDirs(cwd), env["PATH"]].filter(Boolean).join(path.delimiter);
12
+ return {
13
+ ...env,
14
+ PATH
15
+ };
16
+ };
17
+ export { addBinDirs };
18
+
19
+ //# sourceMappingURL=bin-dirs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin-dirs.js","names":[],"sources":["../../../src/test-utils/shell/bin-dirs.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\n/** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */\nconst getBinDirs = (dir: string): string[] => {\n const binDir = path.join(dir, \"node_modules\", \".bin\")\n const parent = path.dirname(dir)\n return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)]\n}\n\n/** Puts `node_modules/.bin` of `cwd` and each of its parents first on `PATH`. */\nexport const addBinDirs = (cwd: string, env: ShellEnv): ShellEnv => {\n // Drop an empty `PATH` because the shell reads a trailing empty entry as the cwd.\n const PATH = [...getBinDirs(cwd), env[\"PATH\"]].filter(Boolean).join(path.delimiter)\n\n return { ...env, PATH }\n}\n"],"mappings":";;;AAKA,MAAM,cAAc,QAA0B;CAC5C,MAAM,SAAS,KAAK,KAAK,KAAK,gBAAgB,MAAM;CACpD,MAAM,SAAS,KAAK,QAAQ,GAAG;CAC/B,OAAO,WAAW,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,GAAG,WAAW,MAAM,CAAC;AACnE;;AAGA,MAAa,cAAc,KAAa,QAA4B;CAElE,MAAM,OAAO,CAAC,GAAG,WAAW,GAAG,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS;CAElF,OAAO;EAAE,GAAG;EAAK;CAAK;AACxB"}
@@ -0,0 +1,18 @@
1
+ import { ShellEnv, ShellOptions, ShellResult } from "./shell.js";
2
+ import { $ } from "bun";
3
+ /** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */
4
+ export declare class ShellCommand implements PromiseLike<ShellResult> {
5
+ #private;
6
+ /** Starts from the shell's settings, which the command's own methods can then override. */
7
+ constructor(shellPromise: $.ShellPromise, settings: Required<ShellOptions>);
8
+ /** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */
9
+ cwd(newCwd: string): this;
10
+ /** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */
11
+ env(newEnv: ShellEnv): this;
12
+ /** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */
13
+ localBins(useLocalBins: boolean): this;
14
+ /** Configure the command to not throw an exception on a non-zero exit code. */
15
+ nothrow(): this;
16
+ then<TResult1 = ShellResult, TResult2 = never>(onfulfilled?: ((value: ShellResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
17
+ }
18
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","names":["BunShell"],"sources":["../../../src/test-utils/shell/command.ts"],"mappings":";;;qBAca,wBAAwB,YAAY;;;EAM/C,YAAmB,cAAcA,EAAS,cAAc,UAAU,SAAS;;EAOpE,IAAI;;EAMJ,IAAI,QAAQ;;EAMZ,UAAU;;EAMV;EAMM,KAAK,WAAW,aAAa,kBACxC,gBAAgB,OAAO,gBAAgB,WAAW,YAAY,mBAC9D,eAAe,oBAAoB,WAAW,YAAY,oBAAiB,QAAA,WAAA"}
@@ -0,0 +1,63 @@
1
+ import { addBinDirs } from "./bin-dirs.js";
2
+ import { removeNodeShims } from "./node-shim.js";
3
+ import path from "node:path";
4
+ import bun from "bun";
5
+ // src/test-utils/shell/command.ts
6
+ const FINAL_NEWLINE = /\r?\n$/v;
7
+ const stripFinalNewline = (output) => output.toString().replace(FINAL_NEWLINE, "");
8
+ /** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */
9
+ var ShellCommand = class {
10
+ #shellPromise;
11
+ #settings;
12
+ #result;
13
+ /** Starts from the shell's settings, which the command's own methods can then override. */
14
+ constructor(shellPromise, settings) {
15
+ this.#shellPromise = shellPromise;
16
+ this.#settings = { ...settings };
17
+ }
18
+ /** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */
19
+ cwd(newCwd) {
20
+ this.#settings.cwd = newCwd;
21
+ return this;
22
+ }
23
+ /** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */
24
+ env(newEnv) {
25
+ this.#settings.env = {
26
+ ...this.#settings.env,
27
+ ...newEnv
28
+ };
29
+ return this;
30
+ }
31
+ /** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */
32
+ localBins(useLocalBins) {
33
+ this.#settings.localBins = useLocalBins;
34
+ return this;
35
+ }
36
+ /** Configure the command to not throw an exception on a non-zero exit code. */
37
+ nothrow() {
38
+ this.#settings.throws = false;
39
+ return this;
40
+ }
41
+ async then(onfulfilled, onrejected) {
42
+ this.#result ??= this.#run();
43
+ return this.#result.then(onfulfilled, onrejected);
44
+ }
45
+ async #run() {
46
+ const { env, localBins, throws } = this.#settings;
47
+ const cwd = path.resolve(this.#settings.cwd);
48
+ const envWithBins = localBins ? addBinDirs(cwd, env) : env;
49
+ const finalEnv = removeNodeShims(envWithBins);
50
+ const output = await this.#shellPromise.cwd(cwd).env(finalEnv).quiet().throws(throws).catch((error) => {
51
+ if (error instanceof bun.$.ShellError) throw error;
52
+ throw new Error(`Command failed to start (cwd: ${cwd})`, { cause: error });
53
+ });
54
+ return {
55
+ stdout: stripFinalNewline(output.stdout),
56
+ stderr: stripFinalNewline(output.stderr),
57
+ exitCode: output.exitCode
58
+ };
59
+ }
60
+ };
61
+ export { ShellCommand };
62
+
63
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","names":[],"sources":["../../../src/test-utils/shell/command.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport bun from \"bun\"\nimport type { $ as BunShell } from \"bun\"\n\nimport { addBinDirs } from \"#test-utils/shell/bin-dirs.ts\"\nimport { removeNodeShims } from \"#test-utils/shell/node-shim.ts\"\nimport type { ShellEnv, ShellOptions, ShellResult } from \"#test-utils/shell/shell.ts\"\n\nconst FINAL_NEWLINE = /\\r?\\n$/v\n\nconst stripFinalNewline = (output: Buffer) => output.toString().replace(FINAL_NEWLINE, \"\")\n\n/** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */\nexport class ShellCommand implements PromiseLike<ShellResult> {\n readonly #shellPromise: BunShell.ShellPromise\n readonly #settings: Required<ShellOptions>\n #result: Promise<ShellResult> | undefined\n\n /** Starts from the shell's settings, which the command's own methods can then override. */\n public constructor(shellPromise: BunShell.ShellPromise, settings: Required<ShellOptions>) {\n this.#shellPromise = shellPromise\n // Copy `settings` so this command's changes don't reach the shell.\n this.#settings = { ...settings }\n }\n\n /** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */\n public cwd(newCwd: string) {\n this.#settings.cwd = newCwd\n return this\n }\n\n /** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */\n public env(newEnv: ShellEnv) {\n this.#settings.env = { ...this.#settings.env, ...newEnv }\n return this\n }\n\n /** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */\n public localBins(useLocalBins: boolean) {\n this.#settings.localBins = useLocalBins\n return this\n }\n\n /** Configure the command to not throw an exception on a non-zero exit code. */\n public nothrow() {\n this.#settings.throws = false\n return this\n }\n\n // oxlint-disable-next-line unicorn/no-thenable - awaiting a command runs it, like Bun's `ShellPromise`\n public async then<TResult1 = ShellResult, TResult2 = never>(\n onfulfilled?: ((value: ShellResult) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,\n ) {\n // Keep the first run because Bun rejects settings on a command that already started.\n this.#result ??= this.#run()\n return this.#result.then(onfulfilled, onrejected)\n }\n\n async #run(): Promise<ShellResult> {\n const { env, localBins, throws } = this.#settings\n const cwd = path.resolve(this.#settings.cwd)\n const envWithBins = localBins ? addBinDirs(cwd, env) : env\n const finalEnv = removeNodeShims(envWithBins)\n\n const output = await this.#shellPromise\n .cwd(cwd)\n .env(finalEnv)\n .quiet()\n .throws(throws)\n .catch((error: unknown) => {\n if (error instanceof bun.$.ShellError) throw error\n // Name the cwd because Bun's start errors (like a missing cwd) don't.\n throw new Error(`Command failed to start (cwd: ${cwd})`, { cause: error })\n })\n\n return {\n stdout: stripFinalNewline(output.stdout),\n stderr: stripFinalNewline(output.stderr),\n exitCode: output.exitCode,\n }\n }\n}\n"],"mappings":";;;;;AASA,MAAM,gBAAgB;AAEtB,MAAM,qBAAqB,WAAmB,OAAO,SAAS,CAAC,CAAC,QAAQ,eAAe,EAAE;;AAGzF,IAAa,eAAb,MAA8D;CAC5D;CACA;CACA;;CAGA,YAAmB,cAAqC,UAAkC;EACxF,KAAK,gBAAgB;EAErB,KAAK,YAAY,EAAE,GAAG,SAAS;CACjC;;CAGA,IAAW,QAAgB;EACzB,KAAK,UAAU,MAAM;EACrB,OAAO;CACT;;CAGA,IAAW,QAAkB;EAC3B,KAAK,UAAU,MAAM;GAAE,GAAG,KAAK,UAAU;GAAK,GAAG;EAAO;EACxD,OAAO;CACT;;CAGA,UAAiB,cAAuB;EACtC,KAAK,UAAU,YAAY;EAC3B,OAAO;CACT;;CAGA,UAAiB;EACf,KAAK,UAAU,SAAS;EACxB,OAAO;CACT;CAGA,MAAa,KACX,aACA,YACA;EAEA,KAAK,YAAY,KAAK,KAAK;EAC3B,OAAO,KAAK,QAAQ,KAAK,aAAa,UAAU;CAClD;CAEA,MAAM,OAA6B;EACjC,MAAM,EAAE,KAAK,WAAW,WAAW,KAAK;EACxC,MAAM,MAAM,KAAK,QAAQ,KAAK,UAAU,GAAG;EAC3C,MAAM,cAAc,YAAY,WAAW,KAAK,GAAG,IAAI;EACvD,MAAM,WAAW,gBAAgB,WAAW;EAE5C,MAAM,SAAS,MAAM,KAAK,cACvB,IAAI,GAAG,CAAC,CACR,IAAI,QAAQ,CAAC,CACb,MAAM,CAAC,CACP,OAAO,MAAM,CAAC,CACd,OAAO,UAAmB;GACzB,IAAI,iBAAiB,IAAI,EAAE,YAAY,MAAM;GAE7C,MAAM,IAAI,MAAM,iCAAiC,IAAI,IAAI,EAAE,OAAO,MAAM,CAAC;EAC3E,CAAC;EAEH,OAAO;GACL,QAAQ,kBAAkB,OAAO,MAAM;GACvC,QAAQ,kBAAkB,OAAO,MAAM;GACvC,UAAU,OAAO;EACnB;CACF;AACF"}
@@ -0,0 +1,4 @@
1
+ import { ShellEnv } from "./shell.js";
2
+ /** Returns `PATH` and `HOME` from `process.env`, merged with `extra`. */
3
+ export declare const minimalEnv: (extra?: ShellEnv) => ShellEnv;
4
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/test-utils/shell/env.ts"],"mappings":";;qBAKa,aAAU,QAAW,aAAgB"}
@@ -0,0 +1,11 @@
1
+ import process from "node:process";
2
+ // src/test-utils/shell/env.ts
3
+ /** Returns `PATH` and `HOME` from `process.env`, merged with `extra`. */
4
+ const minimalEnv = (extra = {}) => ({
5
+ PATH: process.env["PATH"],
6
+ HOME: process.env["HOME"],
7
+ ...extra
8
+ });
9
+ export { minimalEnv };
10
+
11
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","names":[],"sources":["../../../src/test-utils/shell/env.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\n/** Returns `PATH` and `HOME` from `process.env`, merged with `extra`. */\nexport const minimalEnv = (extra: ShellEnv = {}): ShellEnv => ({\n PATH: process.env[\"PATH\"],\n HOME: process.env[\"HOME\"],\n ...extra,\n})\n"],"mappings":";;;AAKA,MAAa,cAAc,QAAkB,CAAC,OAAiB;CAC7D,MAAM,QAAQ,IAAI;CAClB,MAAM,QAAQ,IAAI;CAClB,GAAG;AACL"}
@@ -0,0 +1,18 @@
1
+ import path from "node:path";
2
+ // src/test-utils/shell/node-shim.ts
3
+ const NODE_SHIM_DIR = /^(?:bask|bun)-node-/v;
4
+ /** Checks for a folder that `bask` or `bun run --bun` puts on `PATH` so `node` runs Bun. */
5
+ const isNodeShimDir = (dir) => NODE_SHIM_DIR.test(path.basename(dir));
6
+ /** Takes every `node` shim off `PATH` so `node` is the real Node however the tests started. */
7
+ const removeNodeShims = (env) => {
8
+ const currentPath = env["PATH"];
9
+ if (currentPath === void 0) return env;
10
+ const PATH = currentPath.split(path.delimiter).filter((dir) => !isNodeShimDir(dir)).join(path.delimiter);
11
+ return {
12
+ ...env,
13
+ PATH
14
+ };
15
+ };
16
+ export { removeNodeShims };
17
+
18
+ //# sourceMappingURL=node-shim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-shim.js","names":[],"sources":["../../../src/test-utils/shell/node-shim.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\nconst NODE_SHIM_DIR = /^(?:bask|bun)-node-/v\n\n/** Checks for a folder that `bask` or `bun run --bun` puts on `PATH` so `node` runs Bun. */\nconst isNodeShimDir = (dir: string) => NODE_SHIM_DIR.test(path.basename(dir))\n\n/** Takes every `node` shim off `PATH` so `node` is the real Node however the tests started. */\nexport const removeNodeShims = (env: ShellEnv): ShellEnv => {\n const currentPath = env[\"PATH\"]\n if (currentPath === undefined) return env\n\n const pathDirs = currentPath.split(path.delimiter)\n const PATH = pathDirs.filter((dir) => !isNodeShimDir(dir)).join(path.delimiter)\n\n return { ...env, PATH }\n}\n"],"mappings":";;AAIA,MAAM,gBAAgB;;AAGtB,MAAM,iBAAiB,QAAgB,cAAc,KAAK,KAAK,SAAS,GAAG,CAAC;;AAG5E,MAAa,mBAAmB,QAA4B;CAC1D,MAAM,cAAc,IAAI;CACxB,IAAI,gBAAgB,KAAA,GAAW,OAAO;CAGtC,MAAM,OADW,YAAY,MAAM,KAAK,SACpB,CAAC,CAAC,QAAQ,QAAQ,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS;CAE9E,OAAO;EAAE,GAAG;EAAK;CAAK;AACxB"}
@@ -0,0 +1,42 @@
1
+ import { ShellCommand } from "./command.js";
2
+ import { ShellExpression } from "bun";
3
+ export type ShellEnv = Record<string, string | undefined>;
4
+ export interface ShellOptions {
5
+ /**
6
+ * The working directory for commands. Relative paths resolve against `process.cwd()`.
7
+ *
8
+ * @default process.cwd()
9
+ */
10
+ cwd?: string;
11
+ /**
12
+ * The environment for commands. Replaces `process.env`.
13
+ *
14
+ * @default process.env without `FORCE_COLOR`
15
+ */
16
+ env?: ShellEnv;
17
+ /**
18
+ * Put `node_modules/.bin` of the cwd and each of its parents first on `PATH`.
19
+ *
20
+ * @default true
21
+ */
22
+ localBins?: boolean;
23
+ /**
24
+ * Throw Bun's `ShellError` on a non-zero exit code.
25
+ *
26
+ * @default true
27
+ */
28
+ throws?: boolean;
29
+ }
30
+ export interface ShellResult {
31
+ stdout: string;
32
+ stderr: string;
33
+ exitCode: number;
34
+ }
35
+ /** Runs commands like Bun's `$`, quietly, starting from the shell's options. */
36
+ export type Shell = (strings: TemplateStringsArray, ...expressions: ShellExpression[]) => ShellCommand;
37
+ /**
38
+ * Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands
39
+ * read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
40
+ */
41
+ export declare const createShell: (options?: ShellOptions) => Shell;
42
+ //# sourceMappingURL=shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.d.ts","names":[],"sources":["../../../src/test-utils/shell/shell.ts"],"mappings":";;YAOY,WAAW;iBAEN;;;;;;EAMf;;;;;;EAMA,MAAM;;;;;;EAMN;;;;;;EAMA;;iBAGe;EACf;EACA;EACA;;;YAIU,SAAS,SAAS,yBAAyB,aAAa,sBAAsB;;;;;qBAM7E,cAAW,UAAa,iBAAoB"}
@@ -0,0 +1,24 @@
1
+ import { ShellCommand } from "./command.js";
2
+ import process from "node:process";
3
+ import bun from "bun";
4
+ // src/test-utils/shell/shell.ts
5
+ /**
6
+ * Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands
7
+ * read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
8
+ */
9
+ const createShell = (options = {}) => {
10
+ const bunShell = new bun.$.Shell();
11
+ const settings = {
12
+ cwd: options.cwd ?? process.cwd(),
13
+ env: options.env ?? {
14
+ ...process.env,
15
+ FORCE_COLOR: void 0
16
+ },
17
+ localBins: options.localBins ?? true,
18
+ throws: options.throws ?? true
19
+ };
20
+ return (strings, ...expressions) => new ShellCommand(bunShell(strings, ...expressions), settings);
21
+ };
22
+ export { createShell };
23
+
24
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","names":[],"sources":["../../../src/test-utils/shell/shell.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport bun from \"bun\"\nimport type { ShellExpression } from \"bun\"\n\nimport { ShellCommand } from \"#test-utils/shell/command.ts\"\n\nexport type ShellEnv = Record<string, string | undefined>\n\nexport interface ShellOptions {\n /**\n * The working directory for commands. Relative paths resolve against `process.cwd()`.\n *\n * @default process.cwd()\n */\n cwd?: string\n /**\n * The environment for commands. Replaces `process.env`.\n *\n * @default process.env without `FORCE_COLOR`\n */\n env?: ShellEnv\n /**\n * Put `node_modules/.bin` of the cwd and each of its parents first on `PATH`.\n *\n * @default true\n */\n localBins?: boolean\n /**\n * Throw Bun's `ShellError` on a non-zero exit code.\n *\n * @default true\n */\n throws?: boolean\n}\n\nexport interface ShellResult {\n stdout: string\n stderr: string\n exitCode: number\n}\n\n/** Runs commands like Bun's `$`, quietly, starting from the shell's options. */\nexport type Shell = (strings: TemplateStringsArray, ...expressions: ShellExpression[]) => ShellCommand\n\n/**\n * Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands\n * read the test runner's stdin, so add `< /dev/null` to a command that might prompt.\n */\nexport const createShell = (options: ShellOptions = {}): Shell => {\n // Use a separate instance so settings on Bun's global `$` don't apply here.\n const bunShell = new bun.$.Shell()\n const settings: Required<ShellOptions> = {\n cwd: options.cwd ?? process.cwd(),\n // Drop `FORCE_COLOR` because `bask` sets it when the tests run in a terminal and CI does not.\n env: options.env ?? { ...process.env, FORCE_COLOR: undefined },\n localBins: options.localBins ?? true,\n throws: options.throws ?? true,\n }\n\n return (strings, ...expressions) => new ShellCommand(bunShell(strings, ...expressions), settings)\n}\n"],"mappings":";;;;;;;;AAiDA,MAAa,eAAe,UAAwB,CAAC,MAAa;CAEhE,MAAM,WAAW,IAAI,IAAI,EAAE,MAAM;CACjC,MAAM,WAAmC;EACvC,KAAK,QAAQ,OAAO,QAAQ,IAAI;EAEhC,KAAK,QAAQ,OAAO;GAAE,GAAG,QAAQ;GAAK,aAAa,KAAA;EAAU;EAC7D,WAAW,QAAQ,aAAa;EAChC,QAAQ,QAAQ,UAAU;CAC5B;CAEA,QAAQ,SAAS,GAAG,gBAAgB,IAAI,aAAa,SAAS,SAAS,GAAG,WAAW,GAAG,QAAQ;AAClG"}
@@ -0,0 +1,3 @@
1
+ /** Makes a temp dir whose name starts with `prefix`, and records it for `removeTempDirs`. */
2
+ export declare const makeTempDir: (prefix: string) => Promise<string>;
3
+ //# sourceMappingURL=temp-dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temp-dir.d.ts","names":[],"sources":["../../src/test-utils/temp-dir.ts"],"mappings":";qBAOa,cAAW,mBAAwB"}
@@ -0,0 +1,21 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+ // src/test-utils/temp-dir.ts
5
+ const tempDirs = [];
6
+ /** Makes a temp dir whose name starts with `prefix`, and records it for `removeTempDirs`. */
7
+ const makeTempDir = async (prefix) => {
8
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
9
+ tempDirs.push(dir);
10
+ return dir;
11
+ };
12
+ /** Removes every dir made by `makeTempDir`. */
13
+ const removeTempDirs = async () => {
14
+ await Promise.all(tempDirs.map(async (dir) => fs.rm(dir, {
15
+ recursive: true,
16
+ force: true
17
+ })));
18
+ };
19
+ export { makeTempDir, removeTempDirs };
20
+
21
+ //# sourceMappingURL=temp-dir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temp-dir.js","names":[],"sources":["../../src/test-utils/temp-dir.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\nconst tempDirs: string[] = []\n\n/** Makes a temp dir whose name starts with `prefix`, and records it for `removeTempDirs`. */\nexport const makeTempDir = async (prefix: string) => {\n const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix))\n tempDirs.push(dir)\n return dir\n}\n\n/** Removes every dir made by `makeTempDir`. */\nexport const removeTempDirs = async () => {\n await Promise.all(tempDirs.map(async (dir) => fs.rm(dir, { recursive: true, force: true })))\n}\n"],"mappings":";;;;AAIA,MAAM,WAAqB,CAAC;;AAG5B,MAAa,cAAc,OAAO,WAAmB;CACnD,MAAM,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;CAC3D,SAAS,KAAK,GAAG;CACjB,OAAO;AACT;;AAGA,MAAa,iBAAiB,YAAY;CACxC,MAAM,QAAQ,IAAI,SAAS,IAAI,OAAO,QAAQ,GAAG,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC,CAAC,CAAC;AAC7F"}
package/dist/utils.js CHANGED
@@ -2,7 +2,7 @@ import { existsSync, globSync, readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { isPlainObject } from "es-toolkit/predicate";
5
- //#region src/utils.ts
5
+ // src/utils.ts
6
6
  const CONFIG_DIRS = ["./configs/", "../configs/"];
7
7
  /** Returns the absolute path of a file in this package's `configs` folder. */
8
8
  const configFilePath = (name) => {
@@ -40,7 +40,6 @@ const resolveProjectTailwind = () => {
40
40
  if (!dependencies.has("tailwindcss")) return false;
41
41
  return globSync("**/*.{css,scss,sass,less,pcss}", { exclude: (filePath) => ["node_modules", ".git"].includes(path.basename(filePath)) }).toSorted().find((file) => TAILWIND_IMPORT.test(readFileSync(file, "utf8"))) ?? false;
42
42
  };
43
- //#endregion
44
43
  export { configFilePath, readProjectPackageJson, resolvePackagePath, resolveProjectTailwind };
45
44
 
46
45
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamhl8/configs",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "My shared configs for TS projects",
5
5
  "homepage": "https://github.com/adamhl8/configs",
6
6
  "bugs": {
@@ -40,13 +40,21 @@
40
40
  "./bask": {
41
41
  "types": "./dist/configs/bask.base.d.ts",
42
42
  "import": "./dist/configs/bask.base.js"
43
+ },
44
+ "./test": {
45
+ "types": "./dist/test-utils/index.d.ts",
46
+ "import": "./dist/test-utils/index.js"
47
+ },
48
+ "./test/preload": {
49
+ "types": "./dist/test-utils/preload.d.ts",
50
+ "import": "./dist/test-utils/preload.js"
43
51
  }
44
52
  },
45
53
  "publishConfig": {
46
54
  "access": "public"
47
55
  },
48
56
  "scripts": {
49
- "prepare": "bunx bask prepare"
57
+ "prepare": "bask prepare"
50
58
  },
51
59
  "dependencies": {
52
60
  "@adamhl8/eslint-plugin-clean-modules": "^0.1.5",
@@ -55,10 +63,10 @@
55
63
  "@e18e/eslint-plugin": "^0.8.1",
56
64
  "arkenv": "^0.12.3",
57
65
  "arktype": "^2.2.9",
58
- "es-toolkit": "^1.52.0",
66
+ "es-toolkit": "^1.53.0",
59
67
  "eslint-plugin-bunisms": "^0.11.0",
60
68
  "eslint-plugin-hono": "^1.1.0",
61
- "eslint-plugin-react-web-api": "^5.28.7",
69
+ "eslint-plugin-react-web-api": "^5.28.8",
62
70
  "eslint-plugin-react-you-might-not-need-an-effect": "^1.0.2",
63
71
  "eslint-plugin-regexp": "^3.3.1",
64
72
  "oxlint-plugin-directive-comments": "^0.1.0",
@@ -71,35 +79,35 @@
71
79
  "@adamhl8/configs": "file:.",
72
80
  "@arethetypeswrong/core": "^0.18.5",
73
81
  "@commitlint/cli": "^21.2.4",
74
- "@types/bun": "^1.4.3",
75
- "knip": "^6.42.1",
82
+ "@types/bun": "^1.4.4",
83
+ "knip": "^6.43.0",
76
84
  "markdown-toc": "^1.2.0",
77
85
  "oxfmt": "^0.74.0",
78
86
  "oxlint": "^1.89.0",
79
- "oxlint-tsgolint": "^7.0.2004",
87
+ "oxlint-tsgolint": "^7.0.2005",
80
88
  "publint": "^0.3.25",
81
89
  "release-it": "^21.1.1",
82
90
  "release-it-git-cliff": "^0.2.0",
83
- "tsdown": "^0.23.1",
84
- "typescript": "^7.0.2"
91
+ "tsdown": "^0.23.2",
92
+ "typescript": "7.1.0-beta"
85
93
  },
86
94
  "peerDependencies": {
87
- "@adamhl8/bask": ">=0.3",
88
- "@arethetypeswrong/core": ">=0.18.1",
89
- "@commitlint/cli": ">=21",
90
- "@commitlint/config-conventional": ">=21",
91
- "@tailwindcss/language-server": ">=0.14",
92
- "knip": ">=6",
93
- "markdown-toc": ">=1",
94
- "oxfmt": ">=0.73",
95
- "oxlint": ">=1.79",
96
- "oxlint-tsgolint": ">=7.0.2004",
97
- "publint": ">=0.3.8",
95
+ "@adamhl8/bask": ">=0.5",
96
+ "@arethetypeswrong/core": ">=0.18",
97
+ "@commitlint/cli": ">=21.2",
98
+ "@commitlint/config-conventional": ">=21.2",
99
+ "@tailwindcss/language-server": ">=0.16",
100
+ "knip": ">=6.43",
101
+ "markdown-toc": ">=1.2",
102
+ "oxfmt": ">=0.74",
103
+ "oxlint": ">=1.89",
104
+ "oxlint-tsgolint": ">=7.0.2005",
105
+ "publint": ">=0.3",
98
106
  "release-it": ">=21.1",
99
- "release-it-git-cliff": ">=0.1",
107
+ "release-it-git-cliff": ">=0.2",
100
108
  "tailwint": ">=1.1",
101
- "tsdown": ">=0.22.7",
102
- "typescript": "^7.0.0"
109
+ "tsdown": ">=0.23.2",
110
+ "typescript": "^7.1.0-beta"
103
111
  },
104
112
  "peerDependenciesMeta": {
105
113
  "@arethetypeswrong/core": {