@harnessed-ts/config 0.3.0 → 0.6.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.
- package/CHANGELOG.md +23 -0
- package/dist/index.cjs +23 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @harnessed-ts/config
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e324e94]
|
|
8
|
+
- @harnessed-ts/core@0.6.0
|
|
9
|
+
|
|
10
|
+
## 0.5.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @harnessed-ts/core@0.5.0
|
|
15
|
+
|
|
16
|
+
## 0.4.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 9666a3d: `loadConfigFor` no longer walks to the filesystem root: it stops at the project root — the nearest git checkout or workspace root (`.git`, `pnpm-workspace.yaml`, or a `package.json` with `workspaces`), else the nearest `package.json` — so a `harnessed.config.ts` above the project is never executed. A config at a monorepo's root still governs its nested packages. `npx @harnessed-ts/claude install` now escapes the values it writes into `harnessed.config.ts`, so a path containing a quote or backslash no longer produces a broken file.
|
|
21
|
+
- Updated dependencies [9666a3d]
|
|
22
|
+
- Updated dependencies [9666a3d]
|
|
23
|
+
- Updated dependencies [1823546]
|
|
24
|
+
- @harnessed-ts/core@0.4.0
|
|
25
|
+
|
|
3
26
|
## 0.3.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -27,16 +27,32 @@ function loadConfig(root = process.cwd()) {
|
|
|
27
27
|
cache.set(root, config);
|
|
28
28
|
return config;
|
|
29
29
|
}
|
|
30
|
+
function ancestors(dir) {
|
|
31
|
+
const dirs = [dir];
|
|
32
|
+
for (let parent = path.dirname(dir); parent !== dirs.at(-1); parent = path.dirname(parent)) {
|
|
33
|
+
dirs.push(parent);
|
|
34
|
+
}
|
|
35
|
+
return dirs;
|
|
36
|
+
}
|
|
37
|
+
var hasManifest = (dir) => fs.existsSync(path.join(dir, "package.json"));
|
|
38
|
+
function isRepoRoot(dir) {
|
|
39
|
+
if (fs.existsSync(path.join(dir, ".git")) || fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return true;
|
|
40
|
+
if (!hasManifest(dir)) return false;
|
|
41
|
+
try {
|
|
42
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
43
|
+
return typeof manifest === "object" && manifest !== null && "workspaces" in manifest;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
30
48
|
function loadConfigFor(filename) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
const dirs = ancestors(path.dirname(filename));
|
|
50
|
+
const root = dirs.find(isRepoRoot) ?? dirs.find(hasManifest);
|
|
51
|
+
if (root === void 0) return void 0;
|
|
52
|
+
for (const dir of dirs.slice(0, dirs.indexOf(root) + 1)) {
|
|
34
53
|
if (findConfig(dir) !== void 0) return loadConfig(dir);
|
|
35
|
-
if (dir === root) return void 0;
|
|
36
|
-
const parent = path.dirname(dir);
|
|
37
|
-
if (parent === dir) return void 0;
|
|
38
|
-
dir = parent;
|
|
39
54
|
}
|
|
55
|
+
return void 0;
|
|
40
56
|
}
|
|
41
57
|
function clearConfigCache() {
|
|
42
58
|
cache.clear();
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["join","existsSync","jiti","createJiti","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["join","existsSync","jiti","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A,CAAM,KAAA,EAAM;AACd","file":"index.cjs","sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport type { HarnessedConfig } from '@harnessed-ts/core'\nimport { createJiti } from 'jiti'\n\nexport type { HarnessedConfig }\n\n/** Tried in order; the first that exists wins. */\nconst FILENAMES = [\n 'harnessed.config.ts',\n 'harnessed.config.mts',\n 'harnessed.config.js',\n 'harnessed.config.mjs',\n]\n\nconst cache = new Map<string, HarnessedConfig | undefined>()\n\n/** The config file's path, if a repo has one. */\nexport function findConfig(root: string = process.cwd()): string | undefined {\n return FILENAMES.map(name => join(root, name)).find(existsSync)\n}\n\n/**\n * Reads `harnessed.config.ts` from disk.\n *\n * Synchronous and TypeScript-capable, because the callers are an ESLint rule and\n * a CLI — neither of which runs inside a bundler that would transform the file\n * for them. That is what `jiti` is for, and why this is a separate package:\n * `@harnessed-ts/core` stays dependency-free and usable in a browser.\n *\n * Cached per root: an ESLint run asks once per file, and the answer cannot change\n * within a run.\n */\nexport function loadConfig(root: string = process.cwd()): HarnessedConfig | undefined {\n if (cache.has(root)) return cache.get(root)\n\n const file = findConfig(root)\n let config: HarnessedConfig | undefined\n if (file !== undefined) {\n const jiti = createJiti(root, { interopDefault: true })\n const loaded = jiti(file) as HarnessedConfig | { default?: HarnessedConfig }\n config =\n 'default' in loaded && loaded.default !== undefined\n ? loaded.default\n : (loaded as HarnessedConfig)\n }\n\n cache.set(root, config)\n return config\n}\n\n/** `dir` and every directory above it, nearest first. */\nfunction ancestors(dir: string): string[] {\n const dirs = [dir]\n for (let parent = dirname(dir); parent !== dirs.at(-1); parent = dirname(parent)) {\n dirs.push(parent)\n }\n return dirs\n}\n\nconst hasManifest = (dir: string): boolean => existsSync(join(dir, 'package.json'))\n\n/** A git checkout's root, or the root of a pnpm, npm or yarn workspace. */\nfunction isRepoRoot(dir: string): boolean {\n if (existsSync(join(dir, '.git')) || existsSync(join(dir, 'pnpm-workspace.yaml'))) return true\n if (!hasManifest(dir)) return false\n try {\n const manifest: unknown = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))\n return typeof manifest === 'object' && manifest !== null && 'workspaces' in manifest\n } catch {\n return false\n }\n}\n\n/**\n * The config governing a particular file, found by walking up from it.\n *\n * Resolving from the file rather than the process's working directory is what\n * makes this correct for a monorepo, and for an editor or a lint run started from\n * anywhere other than the repo root — `cwd` says where the tool was invoked,\n * which is not a fact about the code being checked.\n *\n * The walk stops at the project root, checking that directory itself last.\n * Loading a config executes it, so a `harnessed.config.ts` above the project — in\n * a home directory, a shared parent, `/tmp` — must never be picked up. The root is\n * the nearest git checkout or workspace root (`.git`, `pnpm-workspace.yaml`, or a\n * `package.json` with `workspaces`), not the nearest `package.json`: in a monorepo\n * the file's own package has a `package.json`, and the config usually sits at the\n * workspace root above it. Outside any checkout or workspace, the nearest\n * `package.json` is the root. With neither, there is no project, and no config.\n */\nexport function loadConfigFor(filename: string): HarnessedConfig | undefined {\n const dirs = ancestors(dirname(filename))\n const root = dirs.find(isRepoRoot) ?? dirs.find(hasManifest)\n if (root === undefined) return undefined\n for (const dir of dirs.slice(0, dirs.indexOf(root) + 1)) {\n if (findConfig(dir) !== undefined) return loadConfig(dir)\n }\n return undefined\n}\n\n/** Forgets what was loaded. For tests, and for a long-lived editor process. */\nexport function clearConfigCache(): void {\n cache.clear()\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,15 @@ export declare function loadConfig(root?: string): HarnessedConfig | undefined;
|
|
|
21
21
|
* makes this correct for a monorepo, and for an editor or a lint run started from
|
|
22
22
|
* anywhere other than the repo root — `cwd` says where the tool was invoked,
|
|
23
23
|
* which is not a fact about the code being checked.
|
|
24
|
+
*
|
|
25
|
+
* The walk stops at the project root, checking that directory itself last.
|
|
26
|
+
* Loading a config executes it, so a `harnessed.config.ts` above the project — in
|
|
27
|
+
* a home directory, a shared parent, `/tmp` — must never be picked up. The root is
|
|
28
|
+
* the nearest git checkout or workspace root (`.git`, `pnpm-workspace.yaml`, or a
|
|
29
|
+
* `package.json` with `workspaces`), not the nearest `package.json`: in a monorepo
|
|
30
|
+
* the file's own package has a `package.json`, and the config usually sits at the
|
|
31
|
+
* workspace root above it. Outside any checkout or workspace, the nearest
|
|
32
|
+
* `package.json` is the root. With neither, there is no project, and no config.
|
|
24
33
|
*/
|
|
25
34
|
export declare function loadConfigFor(filename: string): HarnessedConfig | undefined;
|
|
26
35
|
/** Forgets what was loaded. For tests, and for a long-lived editor process. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGzD,YAAY,EAAE,eAAe,EAAE,CAAA;AAY/B,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAsB,GAAG,eAAe,GAAG,SAAS,CAgBpF;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGzD,YAAY,EAAE,eAAe,EAAE,CAAA;AAY/B,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAsB,GAAG,eAAe,GAAG,SAAS,CAgBpF;AAyBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAQ3E;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync } from 'fs';
|
|
2
|
-
import { join,
|
|
1
|
+
import { existsSync, readFileSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
3
|
import { createJiti } from 'jiti';
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
@@ -25,16 +25,32 @@ function loadConfig(root = process.cwd()) {
|
|
|
25
25
|
cache.set(root, config);
|
|
26
26
|
return config;
|
|
27
27
|
}
|
|
28
|
+
function ancestors(dir) {
|
|
29
|
+
const dirs = [dir];
|
|
30
|
+
for (let parent = dirname(dir); parent !== dirs.at(-1); parent = dirname(parent)) {
|
|
31
|
+
dirs.push(parent);
|
|
32
|
+
}
|
|
33
|
+
return dirs;
|
|
34
|
+
}
|
|
35
|
+
var hasManifest = (dir) => existsSync(join(dir, "package.json"));
|
|
36
|
+
function isRepoRoot(dir) {
|
|
37
|
+
if (existsSync(join(dir, ".git")) || existsSync(join(dir, "pnpm-workspace.yaml"))) return true;
|
|
38
|
+
if (!hasManifest(dir)) return false;
|
|
39
|
+
try {
|
|
40
|
+
const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
41
|
+
return typeof manifest === "object" && manifest !== null && "workspaces" in manifest;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
28
46
|
function loadConfigFor(filename) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
const dirs = ancestors(dirname(filename));
|
|
48
|
+
const root = dirs.find(isRepoRoot) ?? dirs.find(hasManifest);
|
|
49
|
+
if (root === void 0) return void 0;
|
|
50
|
+
for (const dir of dirs.slice(0, dirs.indexOf(root) + 1)) {
|
|
32
51
|
if (findConfig(dir) !== void 0) return loadConfig(dir);
|
|
33
|
-
if (dir === root) return void 0;
|
|
34
|
-
const parent = dirname(dir);
|
|
35
|
-
if (parent === dir) return void 0;
|
|
36
|
-
dir = parent;
|
|
37
52
|
}
|
|
53
|
+
return void 0;
|
|
38
54
|
}
|
|
39
55
|
function clearConfigCache() {
|
|
40
56
|
cache.clear();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAQA,IAAM,SAAA,GAAY;AAAA,EAChB,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,KAAA,uBAAY,GAAA,EAAyC;AAGpD,SAAS,UAAA,CAAW,IAAA,GAAe,OAAA,CAAQ,GAAA,EAAI,EAAuB;AAC3E,EAAA,OAAO,SAAA,CAAU,IAAI,CAAA,IAAA,KAAQ,IAAA,CAAK,MAAM,IAAI,CAAC,CAAA,CAAE,IAAA,CAAK,UAAU,CAAA;AAChE;AAaO,SAAS,UAAA,CAAW,IAAA,GAAe,OAAA,CAAQ,GAAA,EAAI,EAAgC;AACpF,EAAA,IAAI,MAAM,GAAA,CAAI,IAAI,GAAG,OAAO,KAAA,CAAM,IAAI,IAAI,CAAA;AAE1C,EAAA,MAAM,IAAA,GAAO,WAAW,IAAI,CAAA;AAC5B,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,MAAM,OAAO,UAAA,CAAW,IAAA,EAAM,EAAE,cAAA,EAAgB,MAAM,CAAA;AACtD,IAAA,MAAM,MAAA,GAAS,KAAK,IAAI,CAAA;AACxB,IAAA,MAAA,GACE,aAAa,MAAA,IAAU,MAAA,CAAO,OAAA,KAAY,MAAA,GACtC,OAAO,OAAA,GACN,MAAA;AAAA,EACT;AAEA,EAAA,KAAA,CAAM,GAAA,CAAI,MAAM,MAAM,CAAA;AACtB,EAAA,OAAO,MAAA;AACT;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAQA,IAAM,SAAA,GAAY;AAAA,EAChB,qBAAA;AAA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type { HarnessedConfig } from '@harnessed-ts/core'\nimport { createJiti } from 'jiti'\n\nexport type { HarnessedConfig }\n\n/** Tried in order; the first that exists wins. */\nconst FILENAMES = [\n 'harnessed.config.ts',\n 'harnessed.config.mts',\n 'harnessed.config.js',\n 'harnessed.config.mjs',\n]\n\nconst cache = new Map<string, HarnessedConfig | undefined>()\n\n/** The config file's path, if a repo has one. */\nexport function findConfig(root: string = process.cwd()): string | undefined {\n return FILENAMES.map(name => join(root, name)).find(existsSync)\n}\n\n/**\n * Reads `harnessed.config.ts` from disk.\n *\n * Synchronous and TypeScript-capable, because the callers are an ESLint rule and\n * a CLI — neither of which runs inside a bundler that would transform the file\n * for them. That is what `jiti` is for, and why this is a separate package:\n * `@harnessed-ts/core` stays dependency-free and usable in a browser.\n *\n * Cached per root: an ESLint run asks once per file, and the answer cannot change\n * within a run.\n */\nexport function loadConfig(root: string = process.cwd()): HarnessedConfig | undefined {\n if (cache.has(root)) return cache.get(root)\n\n const file = findConfig(root)\n let config: HarnessedConfig | undefined\n if (file !== undefined) {\n const jiti = createJiti(root, { interopDefault: true })\n const loaded = jiti(file) as HarnessedConfig | { default?: HarnessedConfig }\n config =\n 'default' in loaded && loaded.default !== undefined\n ? loaded.default\n : (loaded as HarnessedConfig)\n }\n\n cache.set(root, config)\n return config\n}\n\n/** `dir` and every directory above it, nearest first. */\nfunction ancestors(dir: string): string[] {\n const dirs = [dir]\n for (let parent = dirname(dir); parent !== dirs.at(-1); parent = dirname(parent)) {\n dirs.push(parent)\n }\n return dirs\n}\n\nconst hasManifest = (dir: string): boolean => existsSync(join(dir, 'package.json'))\n\n/** A git checkout's root, or the root of a pnpm, npm or yarn workspace. */\nfunction isRepoRoot(dir: string): boolean {\n if (existsSync(join(dir, '.git')) || existsSync(join(dir, 'pnpm-workspace.yaml'))) return true\n if (!hasManifest(dir)) return false\n try {\n const manifest: unknown = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))\n return typeof manifest === 'object' && manifest !== null && 'workspaces' in manifest\n } catch {\n return false\n }\n}\n\n/**\n * The config governing a particular file, found by walking up from it.\n *\n * Resolving from the file rather than the process's working directory is what\n * makes this correct for a monorepo, and for an editor or a lint run started from\n * anywhere other than the repo root — `cwd` says where the tool was invoked,\n * which is not a fact about the code being checked.\n *\n * The walk stops at the project root, checking that directory itself last.\n * Loading a config executes it, so a `harnessed.config.ts` above the project — in\n * a home directory, a shared parent, `/tmp` — must never be picked up. The root is\n * the nearest git checkout or workspace root (`.git`, `pnpm-workspace.yaml`, or a\n * `package.json` with `workspaces`), not the nearest `package.json`: in a monorepo\n * the file's own package has a `package.json`, and the config usually sits at the\n * workspace root above it. Outside any checkout or workspace, the nearest\n * `package.json` is the root. With neither, there is no project, and no config.\n */\nexport function loadConfigFor(filename: string): HarnessedConfig | undefined {\n const dirs = ancestors(dirname(filename))\n const root = dirs.find(isRepoRoot) ?? dirs.find(hasManifest)\n if (root === undefined) return undefined\n for (const dir of dirs.slice(0, dirs.indexOf(root) + 1)) {\n if (findConfig(dir) !== undefined) return loadConfig(dir)\n }\n return undefined\n}\n\n/** Forgets what was loaded. For tests, and for a long-lived editor process. */\nexport function clearConfigCache(): void {\n cache.clear()\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harnessed-ts/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Loads harnessed.config.ts, so the runtime, the linter, and the docs generator read one file.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testing",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"node": ">=22.12.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@harnessed-ts/core": "^0.
|
|
50
|
+
"@harnessed-ts/core": "^0.6.0",
|
|
51
51
|
"jiti": "^2.4.2"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|