@vvedantb/config 0.1.0 → 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/README.md +102 -8
- 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.js +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +20 -14
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/README.md
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
# @vvedantb/config
|
|
2
2
|
|
|
3
|
-
Shared tooling for vvedantb apps: tsconfig bases, an oxlint base, pinned tool versions
|
|
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
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
npm install -D @vvedantb/config
|
|
9
|
+
npm install -D @electron/asar # only for vvedantb-check-asar list
|
|
9
10
|
```
|
|
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
|
+
|
|
11
20
|
## tsconfig bases
|
|
12
21
|
|
|
13
22
|
```json
|
|
@@ -39,14 +48,16 @@ Convex: `convex/tsconfig.json` (or `packages/backend/convex/tsconfig.json`)
|
|
|
39
48
|
|
|
40
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`).
|
|
41
50
|
|
|
42
|
-
The severity of `no-console` and `no-unused-vars` is set to `error` here. It was not copied from the
|
|
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.
|
|
43
52
|
|
|
44
53
|
## Versions
|
|
45
54
|
|
|
46
55
|
```ts
|
|
47
|
-
import { versions } from "@vvedantb/config
|
|
56
|
+
import { versions } from "@vvedantb/config";
|
|
48
57
|
```
|
|
49
58
|
|
|
59
|
+
The `./versions` subpath was removed in 0.2.0; import from the root.
|
|
60
|
+
|
|
50
61
|
| Tool | Range |
|
|
51
62
|
| --- | --- |
|
|
52
63
|
| typescript | `^5.9.0` |
|
|
@@ -80,15 +91,98 @@ CI example:
|
|
|
80
91
|
- run: npx @vvedantb/config sync --check
|
|
81
92
|
```
|
|
82
93
|
|
|
83
|
-
##
|
|
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.
|
|
84
97
|
|
|
85
98
|
```sh
|
|
86
|
-
|
|
87
|
-
|
|
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>]
|
|
88
101
|
```
|
|
89
102
|
|
|
90
|
-
|
|
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
|
|
91
182
|
|
|
92
183
|
```sh
|
|
93
|
-
pnpm --filter @vvedantb/config
|
|
184
|
+
pnpm --filter @vvedantb/config build
|
|
185
|
+
pnpm --filter @vvedantb/config test
|
|
94
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.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { versions, type Versions } from "./versions.js";
|
|
2
2
|
export { CLAUDE_INSTALL_SNIPPET, ENVIRONMENT_INSTALL, parseJsonc, planSync, runSync, type PlannedChange, type SyncOptions, type SyncResult, } from "./sync.js";
|
|
3
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
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { versions } from "./versions.js";
|
|
2
2
|
export { CLAUDE_INSTALL_SNIPPET, ENVIRONMENT_INSTALL, parseJsonc, planSync, runSync, } from "./sync.js";
|
|
3
3
|
export { runCli } from "./run.js";
|
|
4
|
+
export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, runCheckAsar, } from "./check-asar.js";
|
package/package.json
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "Shared tsconfig bases, oxlint base, pinned tool versions
|
|
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
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/vvedantb/
|
|
12
|
+
"url": "git+https://github.com/vvedantb/packages.git",
|
|
13
13
|
"directory": "packages/config"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"vvedantb-config": "./dist/cli.js"
|
|
16
|
+
"vvedantb-config": "./dist/cli.js",
|
|
17
|
+
"vvedantb-check-asar": "./dist/check-asar-cli.js"
|
|
17
18
|
},
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
21
|
"types": "./dist/index.d.ts",
|
|
21
22
|
"import": "./dist/index.js"
|
|
22
23
|
},
|
|
23
|
-
"./versions": {
|
|
24
|
-
"types": "./dist/versions.d.ts",
|
|
25
|
-
"import": "./dist/versions.js"
|
|
26
|
-
},
|
|
27
24
|
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
28
25
|
"./tsconfig/web.json": "./tsconfig/web.json",
|
|
29
26
|
"./tsconfig/convex.json": "./tsconfig/convex.json",
|
|
@@ -37,17 +34,26 @@
|
|
|
37
34
|
"files",
|
|
38
35
|
"tsconfig",
|
|
39
36
|
"oxlint",
|
|
37
|
+
"CHANGELOG.md",
|
|
40
38
|
"LICENSE"
|
|
41
39
|
],
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@electron/asar": "^3.2.0 || ^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@electron/asar": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@electron/asar": "^4.3.1",
|
|
49
50
|
"@types/node": "^22.0.0",
|
|
50
51
|
"typescript": "^5.9.0",
|
|
51
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"
|
|
52
58
|
}
|
|
53
|
-
}
|
|
59
|
+
}
|