@vvedantb/config 0.0.0-stage → 0.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.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +187 -2
- package/dist/check-asar-cli.d.ts +2 -0
- package/dist/check-asar-cli.js +13 -0
- package/dist/check-asar.d.ts +27 -0
- package/dist/check-asar.js +278 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/run.d.ts +7 -0
- package/dist/run.js +64 -0
- package/dist/sync.d.ts +26 -0
- package/dist/sync.js +202 -0
- package/dist/versions.d.ts +18 -0
- package/dist/versions.js +17 -0
- package/files/claude/commands/changelog.md +16 -0
- package/files/claude/commands/push.md +17 -0
- package/files/claude/commands/ship.md +13 -0
- package/files/claude/commands/stage.md +10 -0
- package/oxlint/base.json +38 -0
- package/package.json +56 -3
- package/tsconfig/base.json +12 -0
- package/tsconfig/convex.json +14 -0
- package/tsconfig/react-native.json +15 -0
- package/tsconfig/web.json +12 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Publishable again: `"private"` removed, `publishConfig.access: public`, and `repository.url` now points at github.com/vvedantb/packages.
|
|
6
|
+
- Breaking: the `./versions` subpath is gone. Import `versions` and `Versions` from the root (`@vvedantb/config`), which already exported them. The JSON subpaths (`./tsconfig/*.json`, `./oxlint/base.json`) stay, because tools resolve them by path.
|
|
7
|
+
- New bin `vvedantb-check-asar` checks a packaged Electron `app.asar` for missing runtime modules. It has two modes:
|
|
8
|
+
- `list` reads the archive with `@electron/asar`.
|
|
9
|
+
- `resolve` re-runs itself inside the packaged binary with `ELECTRON_RUN_AS_NODE=1`, and can run an app `--hook`.
|
|
10
|
+
- The root also exports `runCheckAsar`, `packageName`, `findSpecifiers`, `findBareImports`, `CHECK_ASAR_CHILD_ENV` and the types `CheckAsarIo`, `AsarCheckHook` and `AsarCheckHookContext`.
|
|
11
|
+
- `@electron/asar` (`^3.2.0 || ^4.0.0`) is an optional peer. Only `list` mode loads it.
|
|
12
|
+
- `vvedantb-config sync` is unchanged.
|
|
13
|
+
|
|
14
|
+
## 0.1.1
|
|
15
|
+
|
|
16
|
+
- Not published to npm (npm latest stays 0.1.0).
|
|
17
|
+
- Marked `"private": true`.
|
|
18
|
+
- Docs no longer name consuming apps.
|
|
19
|
+
- The build compiles with `module`/`moduleResolution: NodeNext`, so the emitted ESM runs under plain Node.
|
|
20
|
+
- No change to the sync behaviour, the tsconfig bases or the oxlint base.
|
|
21
|
+
|
|
22
|
+
## 0.1.0
|
|
23
|
+
|
|
24
|
+
- First release: tsconfig bases, an oxlint base, pinned tool versions (`./versions`) and the `vvedantb-config sync [--check]` CLI.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vvedantb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,188 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vvedantb/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared tooling for vvedantb apps: tsconfig bases, an oxlint base, pinned tool versions, a `sync` CLI and a packaged Electron `app.asar` module check (`vvedantb-check-asar`).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -D @vvedantb/config
|
|
9
|
+
npm install -D @electron/asar # only for vvedantb-check-asar list
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Exports
|
|
13
|
+
|
|
14
|
+
The only JS entry is the root (`@vvedantb/config`). The JSON files below are also exported by path, because TypeScript (`extends`) and oxlint resolve them as files, not as modules:
|
|
15
|
+
|
|
16
|
+
- `@vvedantb/config/tsconfig/base.json`, `web.json`, `convex.json` and `react-native.json`
|
|
17
|
+
- `@vvedantb/config/oxlint/base.json`
|
|
18
|
+
- `@vvedantb/config/package.json`
|
|
19
|
+
|
|
20
|
+
## tsconfig bases
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{ "extends": "@vvedantb/config/tsconfig/web.json", "include": ["src"] }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
| File | Use |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `tsconfig/base.json` | Strict flags: `strict`, `skipLibCheck`, `isolatedModules`, `moduleDetection: force`, `noFallthroughCasesInSwitch`, `noImplicitOverride`, `forceConsistentCasingInFileNames`, `noUncheckedIndexedAccess`. |
|
|
29
|
+
| `tsconfig/web.json` | Extends base. DOM libs, `jsx: react-jsx`, bundler resolution, `noEmit`. Add `paths` and `types` (for example `vite/client`) in the app. |
|
|
30
|
+
| `tsconfig/convex.json` | Extends base. The settings Convex requires: bundler resolution, `jsx: react-jsx`, `target: ESNext`, `lib: [ES2022, dom]`, `module: ESNext`, `noEmit`, `types: [node]`. |
|
|
31
|
+
| `tsconfig/react-native.json` | Extends base. Expo and React Native: `jsx: react-jsx`, bundler resolution, `lib: [ES2022]`, `noEmit`. |
|
|
32
|
+
|
|
33
|
+
Convex: `convex/tsconfig.json` (or `packages/backend/convex/tsconfig.json`)
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"extends": "@vvedantb/config/tsconfig/convex.json",
|
|
38
|
+
"include": ["./**/*"],
|
|
39
|
+
"exclude": ["./_generated"]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## oxlint base
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{ "extends": ["./node_modules/@vvedantb/config/oxlint/base.json"] }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Generic rules only: plugins `typescript`, `import`, `unicorn`, `react`; `suspicious` as error; ignore patterns for build output and generated files; `no-explicit-any`, `no-non-null-assertion`, `consistent-type-imports`, `no-floating-promises`, `import/no-cycle`, `react/rules-of-hooks`, `react/exhaustive-deps`, `no-console` (allows `warn`, `error`, `info`) and `no-unused-vars` (ignores `^_`). It has no app plugins and no path overrides. Apps add their own `jsPlugins`, `rules` and `overrides`. `no-floating-promises` needs type-aware linting (`oxlint-tsgolint`).
|
|
50
|
+
|
|
51
|
+
The severity of `no-console` and `no-unused-vars` is set to `error` here. It was not copied from the source app file, which was not in the extract. Check it against the app.
|
|
52
|
+
|
|
53
|
+
## Versions
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { versions } from "@vvedantb/config";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The `./versions` subpath was removed in 0.2.0; import from the root.
|
|
60
|
+
|
|
61
|
+
| Tool | Range |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| typescript | `^5.9.0` |
|
|
64
|
+
| vitest | `^3.2.0` |
|
|
65
|
+
| pnpm | `>=10 <11` |
|
|
66
|
+
| convex | `^1.0.0` (guidance only; apps pin an exact version) |
|
|
67
|
+
| node | `>=22` for the ui monorepo, `>=20` for apps |
|
|
68
|
+
|
|
69
|
+
## sync
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
npx @vvedantb/config sync # write
|
|
73
|
+
npx @vvedantb/config sync --check # CI: exit 1 if anything would change
|
|
74
|
+
npx @vvedantb/config sync --cwd ../app
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The `vvedantb-config` bin is the same command. Run from the repo root.
|
|
78
|
+
|
|
79
|
+
| Target | Behaviour |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `.claude/commands/{stage,changelog,push,ship}.md` | Managed. Overwritten on every sync. |
|
|
82
|
+
| `CLAUDE.md` | Created from a skeleton if missing. If present, the four headings (`## Git / ship`, `## Always`, `## Domain docs (read when relevant)`, `## Product facts`) are appended when absent. Existing bodies, including Product facts, are never changed. Drift means a missing heading only. |
|
|
83
|
+
| `.cursor/environment.json` | Created if missing. If present, other keys are kept. `install` gains the Claude Code CLI step (sudo, then `~/.local` fallback) and `pnpm install` when either is absent. |
|
|
84
|
+
| `convex/tsconfig.json` or `packages/backend/convex/tsconfig.json` | Only when that folder exists. Created if missing. If present, `extends` is set to `@vvedantb/config/tsconfig/convex.json`; other keys are kept. Comments in an existing file are lost on rewrite. |
|
|
85
|
+
|
|
86
|
+
Exit codes: 0 in sync (or written), 1 drift under `--check`, 2 bad arguments or an unparsable JSON file. A second `sync` changes nothing.
|
|
87
|
+
|
|
88
|
+
CI example:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
- run: npx @vvedantb/config sync --check
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## check-asar
|
|
95
|
+
|
|
96
|
+
`vvedantb-check-asar` fails a packaged Electron app when the build left a runtime module out of `app.asar`. Run it after packaging, from the app root.
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
vvedantb-check-asar list [app.asar] [--default-asar <path>]... [--scan <dir>]... [--require <package>]... [--root <dir>]
|
|
100
|
+
vvedantb-check-asar resolve [binary] [app.asar] [--default-binary <path>] [--scan <dir>]... [--skip-dir <name>]... [--hook <module>] [--root <dir>]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Relative `--default-asar`, `--default-binary`, `--hook` and (in `list`) `--scan` paths are read from `--root` (default: the current directory). Positional paths are read from the current directory.
|
|
104
|
+
|
|
105
|
+
### list
|
|
106
|
+
|
|
107
|
+
1. Finds `app.asar`: the argument, then `$ASAR`, then the first `--default-asar` that exists.
|
|
108
|
+
2. Lists the archive with `@electron/asar` `listPackage`.
|
|
109
|
+
3. Scans every `.js`, `.cjs` and `.mjs` file under each `--scan` directory on disk. A missing directory is skipped.
|
|
110
|
+
4. Maps each import specifier to a package name. Relative paths, `node:`, `electron` and Node built-ins are dropped. A specifier has no spaces or commas, so a word list such as `["the", "from"]` is not read as an import.
|
|
111
|
+
5. Adds each `--require` package. Use it for optional peers that a dependency loads but the bundles never name.
|
|
112
|
+
6. Requires `node_modules/<package>/package.json` in the archive for each package.
|
|
113
|
+
|
|
114
|
+
Output:
|
|
115
|
+
|
|
116
|
+
| Case | Stream | Message | Exit |
|
|
117
|
+
| --- | --- | --- | --- |
|
|
118
|
+
| Every package found | stdout | `Checked <n> packages in <asar>: <names>`, then `check-asar-modules: OK` | 0 |
|
|
119
|
+
| Packages missing | stdout, then stderr | The `Checked` line, then `Missing from app.asar: <names>` | 1 |
|
|
120
|
+
| No asar found | stderr | `app.asar not found (tried <path or defaults>). Pass a path or set ASAR.` | 1 |
|
|
121
|
+
|
|
122
|
+
### resolve
|
|
123
|
+
|
|
124
|
+
Plain Node cannot read an asar. The CLI starts the packaged binary with `ELECTRON_RUN_AS_NODE=1` and runs itself inside it, where Electron's asar support is active. The binary is the argument or `--default-binary`. `app.asar` is the argument or `<binary dir>/resources/app.asar`.
|
|
125
|
+
|
|
126
|
+
Inside the binary:
|
|
127
|
+
|
|
128
|
+
1. Scans the JS under each `--scan` directory inside `app.asar`. Directories named by `--skip-dir` are skipped at any depth. A missing `--scan` directory throws.
|
|
129
|
+
2. Collects bare specifiers with subpaths kept (`dep/sub`). Relative paths, `node:`, `electron` and Node built-ins are dropped.
|
|
130
|
+
3. Resolves each specifier with `require.resolve` from `app.asar/package.json`, then prints `checked <files> JS files, <imports> unbundled imports`.
|
|
131
|
+
4. Imports the `--hook` module and calls its default export with `{ asar }`. The hook returns a list of problems (nothing means it passed). Use it for checks that belong to the app, such as native files in `app.asar.unpacked` or booting a bundled module.
|
|
132
|
+
5. Prints each problem as `FAIL <problem>` to stderr and exits 1. Otherwise it prints `CHECK_ASAR_OK`.
|
|
133
|
+
|
|
134
|
+
An unresolved import is reported as `unresolved import "<spec>": <error message>`. Without the asar, the CLI prints `No asar at <path>. Package the app first.` and exits 1. If the binary cannot start, it exits 1. Otherwise the binary's exit code is passed through.
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
// scripts/check-asar-hook.mjs: runs inside the packaged binary
|
|
138
|
+
import { existsSync } from "node:fs";
|
|
139
|
+
import { join } from "node:path";
|
|
140
|
+
import { pathToFileURL } from "node:url";
|
|
141
|
+
|
|
142
|
+
/** @type {import("@vvedantb/config").AsarCheckHook} */
|
|
143
|
+
export default async function ({ asar }) {
|
|
144
|
+
const problems = [];
|
|
145
|
+
const native = join(`${asar}.unpacked`, "dist", "native", "addon.node");
|
|
146
|
+
if (process.platform === "darwin" && !existsSync(native)) problems.push(`missing native file: ${native}`);
|
|
147
|
+
try {
|
|
148
|
+
const { boot } = await import(pathToFileURL(join(asar, "dist", "boot.js")).href);
|
|
149
|
+
console.info(`boot ok: ${(await boot()) === null ? "null" : "value"}`);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
problems.push(`bundled boot path failed: ${error.stack ?? error}`);
|
|
152
|
+
}
|
|
153
|
+
return problems;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Per-app invocation
|
|
158
|
+
|
|
159
|
+
Each line reproduces one app's earlier `scripts/check-asar-modules.mjs`: the same inputs, messages and exit codes. Put it in the app's `check:asar` script.
|
|
160
|
+
|
|
161
|
+
- An app built with electron-vite that ships macOS builds:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
vvedantb-check-asar list \
|
|
165
|
+
--default-asar "release/mac-arm64/<Product>.app/Contents/Resources/app.asar" \
|
|
166
|
+
--default-asar "release/mac/<Product>.app/Contents/Resources/app.asar" \
|
|
167
|
+
--scan out/main --scan out/preload --require electron-store
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- An app bundled with esbuild into `dist`, packaged as a Linux dir build by default, with native files and a bundled module to boot:
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
vvedantb-check-asar resolve --default-binary "release/linux-unpacked/<binary>" \
|
|
174
|
+
--scan dist --skip-dir renderer --hook scripts/check-asar-hook.mjs
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The app's native-file and boot checks, and their messages, move into the hook unchanged.
|
|
178
|
+
|
|
179
|
+
Exit codes for both modes: 0 passed, 1 failed, 2 bad arguments.
|
|
180
|
+
|
|
181
|
+
## Develop
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
pnpm --filter @vvedantb/config build
|
|
185
|
+
pnpm --filter @vvedantb/config test
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Publish from a logged-in npm machine after a version bump: `pnpm --filter @vvedantb/config exec npm publish`. `prepack` builds `dist`.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { runCheckAsar } from "./check-asar.js";
|
|
4
|
+
const code = await runCheckAsar(process.argv.slice(2), {
|
|
5
|
+
log: (message) => console.info(message),
|
|
6
|
+
error: (message) => console.error(message),
|
|
7
|
+
cwd: () => process.cwd(),
|
|
8
|
+
env: process.env,
|
|
9
|
+
selfPath: fileURLToPath(import.meta.url),
|
|
10
|
+
});
|
|
11
|
+
// Exit at once on failure; on success let the process end by itself, as the original scripts did.
|
|
12
|
+
if (code !== 0)
|
|
13
|
+
process.exit(code);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type CheckAsarIo = {
|
|
2
|
+
log: (message: string) => void;
|
|
3
|
+
error: (message: string) => void;
|
|
4
|
+
cwd: () => string;
|
|
5
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
6
|
+
/** This CLI's own file, which `resolve` runs again inside the Electron binary. */
|
|
7
|
+
selfPath: string;
|
|
8
|
+
};
|
|
9
|
+
export type AsarCheckHookContext = {
|
|
10
|
+
/** Absolute path of app.asar (readable as a directory inside the Electron binary). */
|
|
11
|
+
asar: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Default export of a `--hook` module, run inside the Electron binary after the import check (`resolve` mode).
|
|
15
|
+
* Returns problems, each printed as `FAIL <problem>`; nothing or an empty list means it passed.
|
|
16
|
+
*/
|
|
17
|
+
export type AsarCheckHook = (context: AsarCheckHookContext) => readonly string[] | void | Promise<readonly string[] | void>;
|
|
18
|
+
/** Set in the environment of the run inside the Electron binary. */
|
|
19
|
+
export declare const CHECK_ASAR_CHILD_ENV = "VVEDANTB_CHECK_ASAR_CHILD";
|
|
20
|
+
/** Maps an import specifier to its package name, or null if the runtime provides it (`list` mode). */
|
|
21
|
+
export declare function packageName(specifier: string): string | null;
|
|
22
|
+
/** Finds import and require specifiers in built JavaScript (`list` mode). */
|
|
23
|
+
export declare function findSpecifiers(source: string): Set<string>;
|
|
24
|
+
/** Finds bare import and require specifiers (not electron, not a Node built-in), subpaths kept (`resolve` mode). */
|
|
25
|
+
export declare function findBareImports(source: string): Set<string>;
|
|
26
|
+
/** Run the CLI. Resolves to the process exit code: 0 passed, 1 failed (or no asar), 2 bad arguments. */
|
|
27
|
+
export declare function runCheckAsar(argv: readonly string[], io: CheckAsarIo): Promise<number>;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { builtinModules, createRequire } from "node:module";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
/** Set in the environment of the run inside the Electron binary. */
|
|
7
|
+
export const CHECK_ASAR_CHILD_ENV = "VVEDANTB_CHECK_ASAR_CHILD";
|
|
8
|
+
const USAGE = `Usage:
|
|
9
|
+
vvedantb-check-asar list [app.asar] [--default-asar <path>]... [--scan <dir>]... [--require <package>]... [--root <dir>]
|
|
10
|
+
vvedantb-check-asar resolve [binary] [app.asar] [--default-binary <path>] [--scan <dir>]... [--skip-dir <name>]... [--hook <module>] [--root <dir>]
|
|
11
|
+
|
|
12
|
+
list Read app.asar with @electron/asar. Every package imported by the JS under each
|
|
13
|
+
--scan dir (relative to --root) and every --require package needs
|
|
14
|
+
node_modules/<package>/package.json in the archive.
|
|
15
|
+
app.asar: the argument, else $ASAR, else the first --default-asar that exists.
|
|
16
|
+
resolve Run inside the packaged binary (ELECTRON_RUN_AS_NODE=1). Every bare import of the
|
|
17
|
+
JS under each --scan dir (relative to app.asar; --skip-dir names are skipped at any
|
|
18
|
+
depth) must resolve from app.asar. Then the --hook module's default export runs.
|
|
19
|
+
binary: the argument, else --default-binary. app.asar: the argument, else
|
|
20
|
+
<binary dir>/resources/app.asar.
|
|
21
|
+
--root Base for relative --default-asar, --default-binary, --scan (list) and --hook. Default: cwd.`;
|
|
22
|
+
const LIST_FLAGS = new Set(["--default-asar", "--scan", "--require", "--root"]);
|
|
23
|
+
const RESOLVE_FLAGS = new Set(["--default-binary", "--scan", "--skip-dir", "--hook", "--root"]);
|
|
24
|
+
function parseFlags(argv, known) {
|
|
25
|
+
const positional = [];
|
|
26
|
+
const flags = new Map();
|
|
27
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
28
|
+
const arg = argv[i] ?? "";
|
|
29
|
+
if (!arg.startsWith("--")) {
|
|
30
|
+
positional.push(arg);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!known.has(arg))
|
|
34
|
+
return { ok: false, message: `Unknown option: ${arg}` };
|
|
35
|
+
const value = argv[i + 1];
|
|
36
|
+
if (value === undefined)
|
|
37
|
+
return { ok: false, message: `${arg} needs a value` };
|
|
38
|
+
flags.set(arg, [...(flags.get(arg) ?? []), value]);
|
|
39
|
+
i += 1;
|
|
40
|
+
}
|
|
41
|
+
return { ok: true, options: { positional, flags } };
|
|
42
|
+
}
|
|
43
|
+
function single(flags, name) {
|
|
44
|
+
const values = flags.get(name) ?? [];
|
|
45
|
+
if (values.length > 1)
|
|
46
|
+
return { ok: false, message: `${name} can be given once` };
|
|
47
|
+
return { ok: true, options: values[0] };
|
|
48
|
+
}
|
|
49
|
+
/** Maps an import specifier to its package name, or null if the runtime provides it (`list` mode). */
|
|
50
|
+
export function packageName(specifier) {
|
|
51
|
+
if (specifier.startsWith("node:") || specifier.startsWith(".") || specifier.startsWith("/"))
|
|
52
|
+
return null;
|
|
53
|
+
const parts = specifier.split("/");
|
|
54
|
+
const name = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : (parts[0] ?? specifier);
|
|
55
|
+
return PROVIDED.has(name) || PROVIDED.has(specifier) ? null : name;
|
|
56
|
+
}
|
|
57
|
+
const PROVIDED = new Set(["electron", ...builtinModules]);
|
|
58
|
+
/** Finds import and require specifiers in built JavaScript (`list` mode). */
|
|
59
|
+
export function findSpecifiers(source) {
|
|
60
|
+
const found = new Set();
|
|
61
|
+
// A specifier never holds spaces or commas, so text such as ["the", "from", "will"] in a bundled word list is not an import.
|
|
62
|
+
const patterns = [/\bfrom\s*["']([^"'\s,]+)["']/g, /\bimport\s*["']([^"'\s,]+)["']/g, /\b(?:require|import)\(\s*["']([^"'\s,]+)["']\s*\)/g];
|
|
63
|
+
for (const pattern of patterns) {
|
|
64
|
+
for (const match of source.matchAll(pattern))
|
|
65
|
+
if (match[1] !== undefined)
|
|
66
|
+
found.add(match[1]);
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
const IMPORT_SPECIFIER = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)["']([^"']+)["']/g;
|
|
71
|
+
/** Finds bare import and require specifiers (not electron, not a Node built-in), subpaths kept (`resolve` mode). */
|
|
72
|
+
export function findBareImports(source) {
|
|
73
|
+
const found = new Set();
|
|
74
|
+
for (const match of source.matchAll(IMPORT_SPECIFIER)) {
|
|
75
|
+
const spec = match[1];
|
|
76
|
+
if (spec === undefined || spec.startsWith(".") || spec.startsWith("/"))
|
|
77
|
+
continue;
|
|
78
|
+
if (spec.startsWith("node:") || spec === "electron")
|
|
79
|
+
continue;
|
|
80
|
+
if (builtinModules.includes(spec.split("/")[0] ?? spec))
|
|
81
|
+
continue;
|
|
82
|
+
found.add(spec);
|
|
83
|
+
}
|
|
84
|
+
return found;
|
|
85
|
+
}
|
|
86
|
+
const JS_FILE = /\.(c|m)?js$/;
|
|
87
|
+
/** JS files under `dir`, recursively. A missing dir has none. */
|
|
88
|
+
function listJsFiles(dir) {
|
|
89
|
+
if (!existsSync(dir))
|
|
90
|
+
return [];
|
|
91
|
+
return readdirSync(dir, { withFileTypes: true, recursive: true })
|
|
92
|
+
.filter((entry) => entry.isFile() && JS_FILE.test(entry.name))
|
|
93
|
+
.map((entry) => join(entry.parentPath, entry.name));
|
|
94
|
+
}
|
|
95
|
+
/** JS files under `dir`, skipping directories named in `skip` at any depth. Throws if `dir` is missing. */
|
|
96
|
+
function resolveJsFiles(dir, skip) {
|
|
97
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
98
|
+
const path = join(dir, entry.name);
|
|
99
|
+
if (entry.isDirectory())
|
|
100
|
+
return skip.has(entry.name) ? [] : resolveJsFiles(path, skip);
|
|
101
|
+
return JS_FILE.test(entry.name) ? [path] : [];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function parseList(argv, io) {
|
|
105
|
+
const parsed = parseFlags(argv, LIST_FLAGS);
|
|
106
|
+
if (!parsed.ok)
|
|
107
|
+
return parsed;
|
|
108
|
+
const { positional, flags } = parsed.options;
|
|
109
|
+
if (positional.length > 1)
|
|
110
|
+
return { ok: false, message: `Unexpected argument: ${positional[1] ?? ""}` };
|
|
111
|
+
const root = single(flags, "--root");
|
|
112
|
+
if (!root.ok)
|
|
113
|
+
return root;
|
|
114
|
+
return {
|
|
115
|
+
ok: true,
|
|
116
|
+
options: {
|
|
117
|
+
asar: positional[0],
|
|
118
|
+
defaultAsars: flags.get("--default-asar") ?? [],
|
|
119
|
+
scans: flags.get("--scan") ?? [],
|
|
120
|
+
requires: flags.get("--require") ?? [],
|
|
121
|
+
root: resolve(io.cwd(), root.options ?? "."),
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parseResolve(argv, io) {
|
|
126
|
+
const parsed = parseFlags(argv, RESOLVE_FLAGS);
|
|
127
|
+
if (!parsed.ok)
|
|
128
|
+
return parsed;
|
|
129
|
+
const { positional, flags } = parsed.options;
|
|
130
|
+
if (positional.length > 2)
|
|
131
|
+
return { ok: false, message: `Unexpected argument: ${positional[2] ?? ""}` };
|
|
132
|
+
const root = single(flags, "--root");
|
|
133
|
+
if (!root.ok)
|
|
134
|
+
return root;
|
|
135
|
+
const defaultBinary = single(flags, "--default-binary");
|
|
136
|
+
if (!defaultBinary.ok)
|
|
137
|
+
return defaultBinary;
|
|
138
|
+
const hook = single(flags, "--hook");
|
|
139
|
+
if (!hook.ok)
|
|
140
|
+
return hook;
|
|
141
|
+
const scans = flags.get("--scan") ?? [];
|
|
142
|
+
if (scans.length === 0)
|
|
143
|
+
return { ok: false, message: "resolve needs at least one --scan" };
|
|
144
|
+
return {
|
|
145
|
+
ok: true,
|
|
146
|
+
options: {
|
|
147
|
+
positional,
|
|
148
|
+
defaultBinary: defaultBinary.options,
|
|
149
|
+
scans,
|
|
150
|
+
skipDirs: flags.get("--skip-dir") ?? [],
|
|
151
|
+
hook: hook.options,
|
|
152
|
+
root: resolve(io.cwd(), root.options ?? "."),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function runList(options, io) {
|
|
157
|
+
const asar = options.asar || io.env["ASAR"] || options.defaultAsars.map((path) => join(options.root, path)).find(existsSync);
|
|
158
|
+
if (!asar || !existsSync(resolve(io.cwd(), asar))) {
|
|
159
|
+
io.error(`app.asar not found (tried ${asar ?? options.defaultAsars.join(", ")}). Pass a path or set ASAR.`);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
const { listPackage } = await import("@electron/asar");
|
|
163
|
+
const entries = new Set(listPackage(resolve(io.cwd(), asar), { isPack: false }).map((entry) => entry.replaceAll("\\", "/").replace(/^\//, "")));
|
|
164
|
+
const required = new Set(options.requires);
|
|
165
|
+
for (const dir of options.scans) {
|
|
166
|
+
for (const file of listJsFiles(join(options.root, dir))) {
|
|
167
|
+
for (const specifier of findSpecifiers(readFileSync(file, "utf8"))) {
|
|
168
|
+
const name = packageName(specifier);
|
|
169
|
+
if (name)
|
|
170
|
+
required.add(name);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const sorted = [...required].sort();
|
|
175
|
+
const missing = sorted.filter((name) => !entries.has(`node_modules/${name}/package.json`));
|
|
176
|
+
io.log(`Checked ${sorted.length} packages in ${asar}: ${sorted.join(", ")}`);
|
|
177
|
+
if (missing.length > 0) {
|
|
178
|
+
io.error(`Missing from app.asar: ${missing.join(", ")}`);
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
io.log("check-asar-modules: OK");
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
function runResolveParent(options, io) {
|
|
185
|
+
const given = options.positional[0] ?? (options.defaultBinary === undefined ? undefined : resolve(options.root, options.defaultBinary));
|
|
186
|
+
if (given === undefined) {
|
|
187
|
+
io.error(`resolve needs a binary or --default-binary\n${USAGE}`);
|
|
188
|
+
return 2;
|
|
189
|
+
}
|
|
190
|
+
const binary = resolve(io.cwd(), given);
|
|
191
|
+
const asar = resolve(io.cwd(), options.positional[1] ?? join(dirname(binary), "resources", "app.asar"));
|
|
192
|
+
if (!existsSync(asar)) {
|
|
193
|
+
io.error(`No asar at ${asar}. Package the app first.`);
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
const forwarded = [
|
|
197
|
+
...options.scans.flatMap((dir) => ["--scan", dir]),
|
|
198
|
+
...options.skipDirs.flatMap((name) => ["--skip-dir", name]),
|
|
199
|
+
...(options.hook === undefined ? [] : ["--hook", resolve(options.root, options.hook)]),
|
|
200
|
+
];
|
|
201
|
+
const result = spawnSync(binary, [io.selfPath, "resolve", asar, ...forwarded], {
|
|
202
|
+
stdio: "inherit",
|
|
203
|
+
env: { ...io.env, ELECTRON_RUN_AS_NODE: "1", [CHECK_ASAR_CHILD_ENV]: "1" },
|
|
204
|
+
});
|
|
205
|
+
return result.status ?? 1;
|
|
206
|
+
}
|
|
207
|
+
async function runHook(file, context) {
|
|
208
|
+
// The module is the app's; the checks below stand in for its declared type.
|
|
209
|
+
const mod = await import(pathToFileURL(file).href);
|
|
210
|
+
const hook = mod.default;
|
|
211
|
+
if (typeof hook !== "function")
|
|
212
|
+
return [`hook ${file} has no default export function`];
|
|
213
|
+
const result = await hook(context);
|
|
214
|
+
if (result === undefined)
|
|
215
|
+
return [];
|
|
216
|
+
if (!Array.isArray(result))
|
|
217
|
+
return [`hook ${file} must return a list of problems`];
|
|
218
|
+
return result.map(String);
|
|
219
|
+
}
|
|
220
|
+
/** The run inside the Electron binary: argv is `[app.asar, ...flags]` with an absolute asar and hook. */
|
|
221
|
+
async function runResolveChild(options, io) {
|
|
222
|
+
const asar = options.positional[0] ?? "";
|
|
223
|
+
const problems = [];
|
|
224
|
+
const requireFromAsar = createRequire(join(asar, "package.json"));
|
|
225
|
+
const skip = new Set(options.skipDirs);
|
|
226
|
+
// 1. Every unbundled JS import must resolve from inside the asar.
|
|
227
|
+
const files = options.scans.flatMap((dir) => resolveJsFiles(join(asar, dir), skip));
|
|
228
|
+
const specs = new Set();
|
|
229
|
+
for (const file of files) {
|
|
230
|
+
for (const spec of findBareImports(readFileSync(file, "utf8")))
|
|
231
|
+
specs.add(spec);
|
|
232
|
+
}
|
|
233
|
+
for (const spec of specs) {
|
|
234
|
+
try {
|
|
235
|
+
requireFromAsar.resolve(spec);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
problems.push(`unresolved import "${spec}": ${error instanceof Error ? error.message : String(error)}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
io.log(`checked ${files.length} JS files, ${specs.size} unbundled imports`);
|
|
242
|
+
// 2. The app's own checks (native files, booting a bundled path, ...).
|
|
243
|
+
if (options.hook !== undefined)
|
|
244
|
+
problems.push(...(await runHook(options.hook, { asar })));
|
|
245
|
+
if (problems.length > 0) {
|
|
246
|
+
for (const problem of problems)
|
|
247
|
+
io.error(`FAIL ${problem}`);
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
io.log("CHECK_ASAR_OK");
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
/** Run the CLI. Resolves to the process exit code: 0 passed, 1 failed (or no asar), 2 bad arguments. */
|
|
254
|
+
export async function runCheckAsar(argv, io) {
|
|
255
|
+
const [mode, ...rest] = argv;
|
|
256
|
+
if (mode === undefined || mode === "--help" || mode === "-h") {
|
|
257
|
+
io.log(USAGE);
|
|
258
|
+
return mode === undefined ? 2 : 0;
|
|
259
|
+
}
|
|
260
|
+
if (mode !== "list" && mode !== "resolve") {
|
|
261
|
+
io.error(`Unknown mode: ${mode}\n${USAGE}`);
|
|
262
|
+
return 2;
|
|
263
|
+
}
|
|
264
|
+
if (mode === "list") {
|
|
265
|
+
const parsed = parseList(rest, io);
|
|
266
|
+
if (!parsed.ok) {
|
|
267
|
+
io.error(`${parsed.message}\n${USAGE}`);
|
|
268
|
+
return 2;
|
|
269
|
+
}
|
|
270
|
+
return runList(parsed.options, io);
|
|
271
|
+
}
|
|
272
|
+
const parsed = parseResolve(rest, io);
|
|
273
|
+
if (!parsed.ok) {
|
|
274
|
+
io.error(`${parsed.message}\n${USAGE}`);
|
|
275
|
+
return 2;
|
|
276
|
+
}
|
|
277
|
+
return io.env[CHECK_ASAR_CHILD_ENV] === "1" ? runResolveChild(parsed.options, io) : runResolveParent(parsed.options, io);
|
|
278
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { versions, type Versions } from "./versions.js";
|
|
2
|
+
export { CLAUDE_INSTALL_SNIPPET, ENVIRONMENT_INSTALL, parseJsonc, planSync, runSync, type PlannedChange, type SyncOptions, type SyncResult, } from "./sync.js";
|
|
3
|
+
export { runCli, type CliIo } from "./run.js";
|
|
4
|
+
export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, runCheckAsar, type AsarCheckHook, type AsarCheckHookContext, type CheckAsarIo, } from "./check-asar.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { versions } from "./versions.js";
|
|
2
|
+
export { CLAUDE_INSTALL_SNIPPET, ENVIRONMENT_INSTALL, parseJsonc, planSync, runSync, } from "./sync.js";
|
|
3
|
+
export { runCli } from "./run.js";
|
|
4
|
+
export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, runCheckAsar, } from "./check-asar.js";
|
package/dist/run.d.ts
ADDED
package/dist/run.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { runSync } from "./sync.js";
|
|
3
|
+
const USAGE = `Usage: vvedantb-config sync [--check] [--cwd <dir>]
|
|
4
|
+
|
|
5
|
+
sync Write shared Claude commands, CLAUDE.md headings,
|
|
6
|
+
.cursor/environment.json and the Convex tsconfig.
|
|
7
|
+
--check Write nothing. Exit 1 if any managed file would change.
|
|
8
|
+
--cwd <dir> Target repo. Default: current directory.`;
|
|
9
|
+
/** Run the CLI. Returns the process exit code. */
|
|
10
|
+
export function runCli(argv, io) {
|
|
11
|
+
const [command, ...rest] = argv;
|
|
12
|
+
if (command === undefined || command === "--help" || command === "-h") {
|
|
13
|
+
io.log(USAGE);
|
|
14
|
+
return command === undefined ? 2 : 0;
|
|
15
|
+
}
|
|
16
|
+
if (command !== "sync") {
|
|
17
|
+
io.error(`Unknown command: ${command}\n${USAGE}`);
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
let check = false;
|
|
21
|
+
let cwd = io.cwd();
|
|
22
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
23
|
+
const arg = rest[i];
|
|
24
|
+
if (arg === "--check") {
|
|
25
|
+
check = true;
|
|
26
|
+
}
|
|
27
|
+
else if (arg === "--cwd") {
|
|
28
|
+
const value = rest[i + 1];
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
io.error(`--cwd needs a directory\n${USAGE}`);
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
cwd = resolve(io.cwd(), value);
|
|
34
|
+
i += 1;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
io.error(`Unknown option: ${arg}\n${USAGE}`);
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const { changes, errors } = runSync({ cwd, check });
|
|
42
|
+
for (const message of errors)
|
|
43
|
+
io.error(`error: ${message}`);
|
|
44
|
+
if (errors.length > 0)
|
|
45
|
+
return 2;
|
|
46
|
+
if (check) {
|
|
47
|
+
if (changes.length === 0) {
|
|
48
|
+
io.log("In sync.");
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
io.error("Out of sync. Run `vvedantb-config sync` to update:");
|
|
52
|
+
for (const change of changes)
|
|
53
|
+
io.error(` ${change.path}`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
if (changes.length === 0) {
|
|
57
|
+
io.log("Already in sync.");
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
for (const change of changes) {
|
|
61
|
+
io.log(`${change.action === "create" ? "created" : "updated"} ${change.path}`);
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type PlannedChange = {
|
|
2
|
+
/** Path relative to the consumer repo root, with forward slashes. */
|
|
3
|
+
path: string;
|
|
4
|
+
content: string;
|
|
5
|
+
action: "create" | "update";
|
|
6
|
+
};
|
|
7
|
+
export type SyncOptions = {
|
|
8
|
+
cwd: string;
|
|
9
|
+
/** Report drift without writing. */
|
|
10
|
+
check?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type SyncResult = {
|
|
13
|
+
changes: PlannedChange[];
|
|
14
|
+
/** Problems that stopped a file from being planned (for example bad JSON). */
|
|
15
|
+
errors: string[];
|
|
16
|
+
};
|
|
17
|
+
/** Installs the Claude Code CLI when missing. Sudo first, then a `~/.local` prefix. */
|
|
18
|
+
export declare const CLAUDE_INSTALL_SNIPPET = "if ! command -v claude >/dev/null 2>&1; then (sudo npm install -g @anthropic-ai/claude-code) || (mkdir -p \"$HOME/.local\" && npm install -g --prefix \"$HOME/.local\" @anthropic-ai/claude-code && export PATH=\"$HOME/.local/bin:$PATH\"); fi";
|
|
19
|
+
/** Recommended `install` for `.cursor/environment.json`. */
|
|
20
|
+
export declare const ENVIRONMENT_INSTALL = "if ! command -v claude >/dev/null 2>&1; then (sudo npm install -g @anthropic-ai/claude-code) || (mkdir -p \"$HOME/.local\" && npm install -g --prefix \"$HOME/.local\" @anthropic-ai/claude-code && export PATH=\"$HOME/.local/bin:$PATH\"); fi; pnpm install";
|
|
21
|
+
/** Parse JSON with comments and trailing commas (tsconfig style). */
|
|
22
|
+
export declare function parseJsonc(text: string): unknown;
|
|
23
|
+
/** Compute every change a sync would make in `cwd`, without writing. */
|
|
24
|
+
export declare function planSync(cwd: string): SyncResult;
|
|
25
|
+
/** Plan, then write unless `check` is set. */
|
|
26
|
+
export declare function runSync(options: SyncOptions): SyncResult;
|
package/dist/sync.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
const TEMPLATE_DIR = new URL("../files/claude/commands/", import.meta.url);
|
|
4
|
+
const COMMAND_FILES = ["stage.md", "changelog.md", "push.md", "ship.md"];
|
|
5
|
+
/** Installs the Claude Code CLI when missing. Sudo first, then a `~/.local` prefix. */
|
|
6
|
+
export const CLAUDE_INSTALL_SNIPPET = 'if ! command -v claude >/dev/null 2>&1; then (sudo npm install -g @anthropic-ai/claude-code) || (mkdir -p "$HOME/.local" && npm install -g --prefix "$HOME/.local" @anthropic-ai/claude-code && export PATH="$HOME/.local/bin:$PATH"); fi';
|
|
7
|
+
/** Recommended `install` for `.cursor/environment.json`. */
|
|
8
|
+
export const ENVIRONMENT_INSTALL = `${CLAUDE_INSTALL_SNIPPET}; pnpm install`;
|
|
9
|
+
const CONVEX_EXTENDS = "@vvedantb/config/tsconfig/convex.json";
|
|
10
|
+
const CLAUDE_SECTIONS = [
|
|
11
|
+
{
|
|
12
|
+
heading: "## Git / ship",
|
|
13
|
+
body: [
|
|
14
|
+
"- NEVER create a new branch, push, or open a PR unless the user asks.",
|
|
15
|
+
"- If already on main and the user asks to ship: commit and push directly to main.",
|
|
16
|
+
].join("\n"),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
heading: "## Always",
|
|
20
|
+
body: [
|
|
21
|
+
"- Think first; simplest solution wins.",
|
|
22
|
+
"- Prefer simplicity. No premature abstractions.",
|
|
23
|
+
].join("\n"),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
heading: "## Domain docs (read when relevant)",
|
|
27
|
+
body: "- (add pointers to this app's docs)",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
heading: "## Product facts",
|
|
31
|
+
body: "- (app-specific; @vvedantb/config sync will not overwrite this section)",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
const CLAUDE_TITLE = "FOLLOW ALL OF THESE RULES";
|
|
35
|
+
function readIfExists(file) {
|
|
36
|
+
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
37
|
+
}
|
|
38
|
+
function isDirectory(dir) {
|
|
39
|
+
return existsSync(dir) && statSync(dir).isDirectory();
|
|
40
|
+
}
|
|
41
|
+
function toChange(rel, existing, content) {
|
|
42
|
+
if (existing === content)
|
|
43
|
+
return null;
|
|
44
|
+
return { path: rel, content, action: existing === null ? "create" : "update" };
|
|
45
|
+
}
|
|
46
|
+
function planCommands(cwd) {
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const name of COMMAND_FILES) {
|
|
49
|
+
const template = readFileSync(new URL(name, TEMPLATE_DIR), "utf8");
|
|
50
|
+
const rel = `.claude/commands/${name}`;
|
|
51
|
+
const change = toChange(rel, readIfExists(join(cwd, rel)), template);
|
|
52
|
+
if (change)
|
|
53
|
+
out.push(change);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function buildClaudeSkeleton() {
|
|
58
|
+
const sections = CLAUDE_SECTIONS.map((s) => `${s.heading}\n${s.body}`);
|
|
59
|
+
return `${CLAUDE_TITLE}\n\n${sections.join("\n\n")}\n`;
|
|
60
|
+
}
|
|
61
|
+
function planClaudeMd(cwd) {
|
|
62
|
+
const rel = "CLAUDE.md";
|
|
63
|
+
const existing = readIfExists(join(cwd, rel));
|
|
64
|
+
if (existing === null)
|
|
65
|
+
return toChange(rel, null, buildClaudeSkeleton());
|
|
66
|
+
const lines = new Set(existing.split(/\r?\n/).map((line) => line.trim()));
|
|
67
|
+
const missing = CLAUDE_SECTIONS.filter((s) => !lines.has(s.heading));
|
|
68
|
+
if (missing.length === 0)
|
|
69
|
+
return null;
|
|
70
|
+
const base = existing.endsWith("\n") ? existing : `${existing}\n`;
|
|
71
|
+
const appended = missing.map((s) => `${s.heading}\n${s.body}\n`).join("\n");
|
|
72
|
+
return toChange(rel, existing, `${base}\n${appended}`);
|
|
73
|
+
}
|
|
74
|
+
function formatJson(value) {
|
|
75
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
76
|
+
}
|
|
77
|
+
function isRecord(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
79
|
+
}
|
|
80
|
+
/** Parse JSON with comments and trailing commas (tsconfig style). */
|
|
81
|
+
export function parseJsonc(text) {
|
|
82
|
+
let out = "";
|
|
83
|
+
let i = 0;
|
|
84
|
+
while (i < text.length) {
|
|
85
|
+
const ch = text[i] ?? "";
|
|
86
|
+
const next = text[i + 1];
|
|
87
|
+
if (ch === '"') {
|
|
88
|
+
let j = i + 1;
|
|
89
|
+
while (j < text.length && text[j] !== '"')
|
|
90
|
+
j += text[j] === "\\" ? 2 : 1;
|
|
91
|
+
out += text.slice(i, j + 1);
|
|
92
|
+
i = j + 1;
|
|
93
|
+
}
|
|
94
|
+
else if (ch === "/" && next === "/") {
|
|
95
|
+
while (i < text.length && text[i] !== "\n")
|
|
96
|
+
i += 1;
|
|
97
|
+
}
|
|
98
|
+
else if (ch === "/" && next === "*") {
|
|
99
|
+
const end = text.indexOf("*/", i + 2);
|
|
100
|
+
i = end === -1 ? text.length : end + 2;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
out += ch;
|
|
104
|
+
i += 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
108
|
+
}
|
|
109
|
+
function planEnvironment(cwd, errors) {
|
|
110
|
+
const rel = ".cursor/environment.json";
|
|
111
|
+
const existing = readIfExists(join(cwd, rel));
|
|
112
|
+
if (existing === null) {
|
|
113
|
+
return toChange(rel, null, formatJson({ name: "app", install: ENVIRONMENT_INSTALL }));
|
|
114
|
+
}
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = JSON.parse(existing);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
errors.push(`${rel}: invalid JSON (${error instanceof Error ? error.message : "unknown"})`);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
if (!isRecord(parsed)) {
|
|
124
|
+
errors.push(`${rel}: expected a JSON object`);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const current = typeof parsed["install"] === "string" ? parsed["install"] : null;
|
|
128
|
+
const hasClaude = current !== null &&
|
|
129
|
+
current.includes("@anthropic-ai/claude-code") &&
|
|
130
|
+
current.includes("sudo npm install") &&
|
|
131
|
+
current.includes("$HOME/.local");
|
|
132
|
+
const hasPnpm = current !== null && current.includes("pnpm install");
|
|
133
|
+
if (hasClaude && hasPnpm)
|
|
134
|
+
return null;
|
|
135
|
+
const install = current === null
|
|
136
|
+
? ENVIRONMENT_INSTALL
|
|
137
|
+
: [hasClaude ? null : CLAUDE_INSTALL_SNIPPET, current, hasPnpm ? null : "pnpm install"]
|
|
138
|
+
.filter((part) => part !== null)
|
|
139
|
+
.join("; ");
|
|
140
|
+
return toChange(rel, existing, formatJson({ ...parsed, install }));
|
|
141
|
+
}
|
|
142
|
+
function convexTsconfigContent() {
|
|
143
|
+
return formatJson({
|
|
144
|
+
extends: CONVEX_EXTENDS,
|
|
145
|
+
include: ["./**/*"],
|
|
146
|
+
exclude: ["./_generated"],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function planConvexTsconfig(cwd, dir, errors) {
|
|
150
|
+
const rel = `${dir}/tsconfig.json`;
|
|
151
|
+
const existing = readIfExists(join(cwd, rel));
|
|
152
|
+
if (existing === null)
|
|
153
|
+
return toChange(rel, null, convexTsconfigContent());
|
|
154
|
+
let parsed;
|
|
155
|
+
try {
|
|
156
|
+
parsed = parseJsonc(existing);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
errors.push(`${rel}: cannot parse (${error instanceof Error ? error.message : "unknown"})`);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
if (!isRecord(parsed)) {
|
|
163
|
+
errors.push(`${rel}: expected a JSON object`);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const current = parsed["extends"];
|
|
167
|
+
const list = Array.isArray(current) ? current : [current];
|
|
168
|
+
if (list.includes(CONVEX_EXTENDS))
|
|
169
|
+
return null;
|
|
170
|
+
const nextExtends = Array.isArray(current) ? [CONVEX_EXTENDS, ...current] : CONVEX_EXTENDS;
|
|
171
|
+
const { extends: _old, ...rest } = parsed;
|
|
172
|
+
return toChange(rel, existing, formatJson({ extends: nextExtends, ...rest }));
|
|
173
|
+
}
|
|
174
|
+
/** Compute every change a sync would make in `cwd`, without writing. */
|
|
175
|
+
export function planSync(cwd) {
|
|
176
|
+
const changes = [];
|
|
177
|
+
const errors = [];
|
|
178
|
+
const push = (change) => {
|
|
179
|
+
if (change)
|
|
180
|
+
changes.push(change);
|
|
181
|
+
};
|
|
182
|
+
changes.push(...planCommands(cwd));
|
|
183
|
+
push(planClaudeMd(cwd));
|
|
184
|
+
push(planEnvironment(cwd, errors));
|
|
185
|
+
for (const dir of ["packages/backend/convex", "convex"]) {
|
|
186
|
+
if (isDirectory(join(cwd, dir)))
|
|
187
|
+
push(planConvexTsconfig(cwd, dir, errors));
|
|
188
|
+
}
|
|
189
|
+
return { changes, errors };
|
|
190
|
+
}
|
|
191
|
+
/** Plan, then write unless `check` is set. */
|
|
192
|
+
export function runSync(options) {
|
|
193
|
+
const result = planSync(options.cwd);
|
|
194
|
+
if (options.check)
|
|
195
|
+
return result;
|
|
196
|
+
for (const change of result.changes) {
|
|
197
|
+
const file = join(options.cwd, change.path);
|
|
198
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
199
|
+
writeFileSync(file, change.content);
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinned tool versions shared across vvedantb repos. These are ranges for
|
|
3
|
+
* guidance. Apps pin exact versions in their own lockfiles; `convex` in
|
|
4
|
+
* particular should be pinned exactly by each app.
|
|
5
|
+
*/
|
|
6
|
+
export declare const versions: {
|
|
7
|
+
readonly typescript: "^5.9.0";
|
|
8
|
+
readonly vitest: "^3.2.0";
|
|
9
|
+
readonly pnpm: ">=10 <11";
|
|
10
|
+
readonly convex: "^1.0.0";
|
|
11
|
+
readonly node: {
|
|
12
|
+
/** This ui monorepo. */
|
|
13
|
+
readonly uiMonorepo: ">=22";
|
|
14
|
+
/** Apps that consume the packages. */
|
|
15
|
+
readonly apps: ">=20";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type Versions = typeof versions;
|
package/dist/versions.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinned tool versions shared across vvedantb repos. These are ranges for
|
|
3
|
+
* guidance. Apps pin exact versions in their own lockfiles; `convex` in
|
|
4
|
+
* particular should be pinned exactly by each app.
|
|
5
|
+
*/
|
|
6
|
+
export const versions = {
|
|
7
|
+
typescript: "^5.9.0",
|
|
8
|
+
vitest: "^3.2.0",
|
|
9
|
+
pnpm: ">=10 <11",
|
|
10
|
+
convex: "^1.0.0",
|
|
11
|
+
node: {
|
|
12
|
+
/** This ui monorepo. */
|
|
13
|
+
uiMonorepo: ">=22",
|
|
14
|
+
/** Apps that consume the packages. */
|
|
15
|
+
apps: ">=20",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: haiku
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Review all changes made in this conversation and add a new entry to `internal/changelog/<YYYY-MM>.md` — the file for today's month. If that file does not exist yet, create it with a `# Changelog — <Month YYYY>` heading (e.g. `# Changelog — September 2026`) followed by a blank line.
|
|
6
|
+
|
|
7
|
+
Format: `## <Title> - <YYYY-MM-DD>` followed by bullet points describing each change.
|
|
8
|
+
|
|
9
|
+
Rules:
|
|
10
|
+
|
|
11
|
+
- Only add entries for medium-to-large changes/features, not quick fixes or bug fixes
|
|
12
|
+
- Each bullet should describe what changed and why, not implementation details
|
|
13
|
+
- Keep bullets concise (one line each)
|
|
14
|
+
- Add the new entry at the top of the month file, right after the `# Changelog — <Month YYYY>` heading
|
|
15
|
+
- Use today's date
|
|
16
|
+
- If multiple features were implemented, group them under one entry if related, or create separate entries if unrelated
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: haiku
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Commit ONLY already-staged changes and push to the remote.
|
|
6
|
+
|
|
7
|
+
CRITICAL: Do NOT run `git add`, `git add -A`, `git add .`, or stage any files. Only commit what is already in the staging area.
|
|
8
|
+
|
|
9
|
+
Steps:
|
|
10
|
+
|
|
11
|
+
1. Run `git diff --cached --stat` to review what's staged
|
|
12
|
+
2. If nothing is staged, stop and tell the user — do NOT stage files yourself
|
|
13
|
+
3. Run `git log --oneline -5` to see recent commit message style
|
|
14
|
+
4. Write a commit message following the repo's convention (lowercase prefix like `feat:`, `fix:`, `refactor:`, etc.) — short title summarizing the WHY, not the WHAT
|
|
15
|
+
5. Commit using a HEREDOC for the message (do NOT use `git add` before committing)
|
|
16
|
+
6. Push to the remote with `git push`
|
|
17
|
+
7. Print the resulting commit hash
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: haiku
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Stage relevant files, commit, and push to remote.
|
|
6
|
+
|
|
7
|
+
1. Run the `/changelog` step first: review this session's changes and, only if they amount to a medium-to-large change or feature (skip quick fixes and bug fixes), add an entry to the top of `internal/changelog/<YYYY-MM>.md` (the current month's file) per the `/changelog` rules. Stage this edit with the code in step 4.
|
|
8
|
+
2. Run `git status -u` and `git log --oneline -5` in parallel
|
|
9
|
+
3. Identify session-related files, excluding pre-existing dirty files
|
|
10
|
+
4. Stage with `git add` using specific paths (never `git add -A` or `.`)
|
|
11
|
+
5. Write commit message following repo convention (lowercase prefix: feat/fix/refactor) — summarize WHY, not WHAT
|
|
12
|
+
6. Commit with HEREDOC, then `git push`
|
|
13
|
+
7. Print commit hash and summary
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
model: haiku
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Stage files relevant to changes made in this session.
|
|
6
|
+
|
|
7
|
+
1. Run `git status -u`
|
|
8
|
+
2. Identify session-related files, excluding pre-existing dirty files
|
|
9
|
+
3. Stage with `git add` using specific paths (never `git add -A` or `.`)
|
|
10
|
+
4. Print summary of staged files and reason
|
package/oxlint/base.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
|
|
3
|
+
"plugins": ["typescript", "import", "unicorn", "react"],
|
|
4
|
+
"categories": {
|
|
5
|
+
"suspicious": "error"
|
|
6
|
+
},
|
|
7
|
+
"ignorePatterns": [
|
|
8
|
+
"**/node_modules/**",
|
|
9
|
+
"**/_generated/**",
|
|
10
|
+
"**/dist/**",
|
|
11
|
+
"**/build/**",
|
|
12
|
+
"**/.next/**",
|
|
13
|
+
"**/.expo/**",
|
|
14
|
+
"**/.vercel/**",
|
|
15
|
+
"**/android/**",
|
|
16
|
+
"**/ios/**",
|
|
17
|
+
"**/routeTree.gen.ts",
|
|
18
|
+
"**/*.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"rules": {
|
|
21
|
+
"typescript/no-explicit-any": "error",
|
|
22
|
+
"typescript/no-non-null-assertion": "error",
|
|
23
|
+
"typescript/consistent-type-imports": "error",
|
|
24
|
+
"typescript/no-floating-promises": "error",
|
|
25
|
+
"import/no-cycle": "error",
|
|
26
|
+
"react/rules-of-hooks": "error",
|
|
27
|
+
"react/exhaustive-deps": "error",
|
|
28
|
+
"no-console": ["error", { "allow": ["warn", "error", "info"] }],
|
|
29
|
+
"no-unused-vars": [
|
|
30
|
+
"error",
|
|
31
|
+
{
|
|
32
|
+
"argsIgnorePattern": "^_",
|
|
33
|
+
"varsIgnorePattern": "^_",
|
|
34
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Shared tsconfig bases, oxlint base, pinned tool versions, a sync CLI for Claude commands, CLAUDE.md, Cursor environment and Convex tsconfig, and a packaged Electron app.asar module check.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vvedantb/packages.git",
|
|
13
|
+
"directory": "packages/config"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"vvedantb-config": "./dist/cli.js",
|
|
17
|
+
"vvedantb-check-asar": "./dist/check-asar-cli.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
25
|
+
"./tsconfig/web.json": "./tsconfig/web.json",
|
|
26
|
+
"./tsconfig/convex.json": "./tsconfig/convex.json",
|
|
27
|
+
"./tsconfig/react-native.json": "./tsconfig/react-native.json",
|
|
28
|
+
"./oxlint/base.json": "./oxlint/base.json",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"files",
|
|
35
|
+
"tsconfig",
|
|
36
|
+
"oxlint",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@electron/asar": "^3.2.0 || ^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@electron/asar": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@electron/asar": "^4.3.1",
|
|
50
|
+
"@types/node": "^22.0.0",
|
|
51
|
+
"typescript": "^5.9.0",
|
|
52
|
+
"vitest": "^3.2.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p tsconfig.json",
|
|
56
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
57
|
+
"test": "vitest run"
|
|
58
|
+
}
|
|
6
59
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"skipLibCheck": true,
|
|
5
|
+
"isolatedModules": true,
|
|
6
|
+
"moduleDetection": "force",
|
|
7
|
+
"noFallthroughCasesInSwitch": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"allowSyntheticDefaultImports": true,
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"target": "ESNext",
|
|
9
|
+
"lib": ["ES2022", "dom"],
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"types": ["node"]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"jsx": "react-jsx"
|
|
11
|
+
}
|
|
12
|
+
}
|