@vvedantb/config 0.1.0 → 0.3.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 +33 -0
- package/README.md +183 -13
- 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/expo.d.ts +49 -0
- package/dist/expo.js +38 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/vite.d.ts +136 -0
- package/dist/vite.js +97 -0
- package/package.json +18 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- New Vite and Vitest presets: `defineWebViteConfig`, `defineWebVitestConfig`, `reactPlugins`, `vendorChunkBuild`, `srcAlias` and `REACT_DEDUPE`. The app passes its plugin factories in; the root does not import Vite or any plugin, and needs no new peer.
|
|
6
|
+
- New Expo presets: `expoBabelConfig` (Babel with NativeWind) and `defineExpoMetroConfig` (Metro with NativeWind, monorepo folders and package exports).
|
|
7
|
+
- Each preset reproduces each app's current config object exactly. Tests compare it per app with a copy of that config.
|
|
8
|
+
- The root export uses the `default` condition instead of `import`, so CommonJS files can `require()` it (Node 20.19+ or 22.12+). It is still one ES module, not a dual build.
|
|
9
|
+
- README: `npx @vvedantb/config sync` cannot pick between the two bins. The docs now use the `vvedantb-config` bin (`pnpm exec vvedantb-config sync --check`) or `npx -p @vvedantb/config vvedantb-config`.
|
|
10
|
+
- The oxlint base is unchanged: no rule is set the same way by every app.
|
|
11
|
+
|
|
12
|
+
## 0.2.0
|
|
13
|
+
|
|
14
|
+
- Publishable again: `"private"` removed, `publishConfig.access: public`, and `repository.url` now points at github.com/vvedantb/packages.
|
|
15
|
+
- 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.
|
|
16
|
+
- New bin `vvedantb-check-asar` checks a packaged Electron `app.asar` for missing runtime modules. It has two modes:
|
|
17
|
+
- `list` reads the archive with `@electron/asar`.
|
|
18
|
+
- `resolve` re-runs itself inside the packaged binary with `ELECTRON_RUN_AS_NODE=1`, and can run an app `--hook`.
|
|
19
|
+
- The root also exports `runCheckAsar`, `packageName`, `findSpecifiers`, `findBareImports`, `CHECK_ASAR_CHILD_ENV` and the types `CheckAsarIo`, `AsarCheckHook` and `AsarCheckHookContext`.
|
|
20
|
+
- `@electron/asar` (`^3.2.0 || ^4.0.0`) is an optional peer. Only `list` mode loads it.
|
|
21
|
+
- `vvedantb-config sync` is unchanged.
|
|
22
|
+
|
|
23
|
+
## 0.1.1
|
|
24
|
+
|
|
25
|
+
- Not published to npm (npm latest stays 0.1.0).
|
|
26
|
+
- Marked `"private": true`.
|
|
27
|
+
- Docs no longer name consuming apps.
|
|
28
|
+
- The build compiles with `module`/`moduleResolution: NodeNext`, so the emitted ESM runs under plain Node.
|
|
29
|
+
- No change to the sync behaviour, the tsconfig bases or the oxlint base.
|
|
30
|
+
|
|
31
|
+
## 0.1.0
|
|
32
|
+
|
|
33
|
+
- 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, Vite, Vitest, Babel and Metro presets, 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`). It is an ES module exported under the `default` condition, so both `import` and `require()` reach it. `require()` of an ES module needs Node 20.19+ or 22.12+, which every Expo SDK from 54 needs anyway. 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,90 @@ 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.
|
|
52
|
+
|
|
53
|
+
## Vite and Vitest presets
|
|
54
|
+
|
|
55
|
+
The root never imports Vite or a plugin. The app imports its plugins and passes the factories in, so the versions stay the app's own. The functions return plain objects; spread them into Vite's `defineConfig` and add `server`, `base` or `root` there.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { defineConfig } from "vite";
|
|
59
|
+
import react from "@vitejs/plugin-react";
|
|
60
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
61
|
+
import tanstackRouter from "@tanstack/router-plugin/vite";
|
|
62
|
+
import { REACT_DEDUPE, defineWebViteConfig, srcAlias } from "@vvedantb/config";
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
...defineWebViteConfig({
|
|
66
|
+
tailwindcss,
|
|
67
|
+
router: { plugin: tanstackRouter, options: { routesDirectory: "./src/routes" } },
|
|
68
|
+
react: { plugin: react, compiler: true },
|
|
69
|
+
alias: srcAlias(import.meta.dirname),
|
|
70
|
+
dedupe: REACT_DEDUPE,
|
|
71
|
+
vendorChunks: true,
|
|
72
|
+
}),
|
|
73
|
+
server: { port: 5173 },
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`defineWebViteConfig` options:
|
|
78
|
+
|
|
79
|
+
| Option | Result |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `tailwindcss` | `tailwindcss()`, first plugin. |
|
|
82
|
+
| `router: { plugin, options? }` | `plugin({ ...options, autoCodeSplitting: true })`, after Tailwind. Options: `target`, `routesDirectory`, `generatedRouteTree`, `routeFileIgnorePattern`. |
|
|
83
|
+
| `react: { plugin, compiler? }` | After the router. `compiler: true` calls `react({ compiler: true })` (plugin-react 6.1+). `compiler: { babel, preset }` calls `react()` then `babel({ presets: [preset()] })`, for `@rolldown/plugin-babel` with `reactCompilerPreset`. No `compiler` calls `react()`. |
|
|
84
|
+
| `plugins` | App plugins, last. Falsy entries are dropped, so `flag && plugin()` works. |
|
|
85
|
+
| `tsconfigPaths` | `resolve.tsconfigPaths: true`. |
|
|
86
|
+
| `alias` | `resolve.alias` as given (object or `{ find, replacement }` list). `srcAlias(dir)` is `{ "@": "<dir>/src" }`. |
|
|
87
|
+
| `dedupe` | `resolve.dedupe` as given. `REACT_DEDUPE` is `react`, `react-dom`, `convex`, `@tanstack/react-router`, `@clerk/clerk-react`. |
|
|
88
|
+
| `vendorChunks` | `build`: `outDir: "dist"`, `chunkSizeWarningLimit: 1000` and rolldown chunk groups `vendor-radix`, `vendor-convex`, `vendor-clerk`, `vendor-motion` (priority 15). An object keyed by group (`radix`, `convex`, `clerk`, `motion`) replaces that group's `test` RegExp. |
|
|
89
|
+
|
|
90
|
+
Keys that are not asked for are left out, so `resolve` and `build` appear only when set. `reactPlugins(setup)` and `vendorChunkBuild(tests?)` are exported on their own.
|
|
91
|
+
|
|
92
|
+
`defineWebVitestConfig` takes `plugins`, `tsconfigPaths`, `alias`, `automaticJsx` (`esbuild: { jsx: "automatic" }`), `include` (default `["src/**/*.test.ts"]`) and `inline` (`test.server.deps.inline`). It always sets `test.environment: "node"`. Pass the result to `defineConfig` from `vitest/config`.
|
|
93
|
+
|
|
94
|
+
## Expo presets
|
|
95
|
+
|
|
96
|
+
`babel.config.js` and `metro.config.js` are CommonJS, loaded by Expo:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
// babel.config.js
|
|
100
|
+
module.exports = require("@vvedantb/config").expoBabelConfig;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`expoBabelConfig(api)` calls `api.cache(true)` and returns `babel-preset-expo` with `jsxImportSource: "nativewind"`, then `nativewind/babel`. Babel resolves both from the app.
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
// metro.config.js
|
|
107
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
|
108
|
+
const { withNativeWind } = require("nativewind/metro");
|
|
109
|
+
const { defineExpoMetroConfig } = require("@vvedantb/config");
|
|
110
|
+
|
|
111
|
+
module.exports = defineExpoMetroConfig({
|
|
112
|
+
projectRoot: __dirname,
|
|
113
|
+
getDefaultConfig,
|
|
114
|
+
withNativeWind,
|
|
115
|
+
inlineRem: 16,
|
|
116
|
+
monorepoRoot: "../..",
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`defineExpoMetroConfig` calls `withNativeWind(getDefaultConfig(projectRoot), { input, inlineRem })`. `input` defaults to `"./global.css"`; `inlineRem` is passed only when set. Then, on a new object:
|
|
121
|
+
|
|
122
|
+
- `monorepoRoot` sets `watchFolders: [<root>]` and `resolver.nodeModulesPaths` to the app's and the root's `node_modules`.
|
|
123
|
+
- `packageExports: true` sets `resolver.unstable_enablePackageExports: true`.
|
|
124
|
+
|
|
125
|
+
`withNativeWind` copies the config and its resolver and reads neither setting, so the order matches setting them before it.
|
|
43
126
|
|
|
44
127
|
## Versions
|
|
45
128
|
|
|
46
129
|
```ts
|
|
47
|
-
import { versions } from "@vvedantb/config
|
|
130
|
+
import { versions } from "@vvedantb/config";
|
|
48
131
|
```
|
|
49
132
|
|
|
133
|
+
The `./versions` subpath was removed in 0.2.0; import from the root.
|
|
134
|
+
|
|
50
135
|
| Tool | Range |
|
|
51
136
|
| --- | --- |
|
|
52
137
|
| typescript | `^5.9.0` |
|
|
@@ -57,13 +142,15 @@ import { versions } from "@vvedantb/config/versions";
|
|
|
57
142
|
|
|
58
143
|
## sync
|
|
59
144
|
|
|
145
|
+
Install the package as a devDependency and run its `vvedantb-config` bin from the repo root:
|
|
146
|
+
|
|
60
147
|
```sh
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
148
|
+
pnpm exec vvedantb-config sync # write
|
|
149
|
+
pnpm exec vvedantb-config sync --check # CI: exit 1 if anything would change
|
|
150
|
+
pnpm exec vvedantb-config sync --cwd ../app
|
|
64
151
|
```
|
|
65
152
|
|
|
66
|
-
|
|
153
|
+
In `package.json` scripts, call `vvedantb-config sync --check` directly. Without installing, use `npx -p @vvedantb/config vvedantb-config sync`. Plain `npx @vvedantb/config` does not work: the package has two bins and neither is named `config`, so npx cannot choose one. A bin named `config` was not added, because that generic name would land in every app's `node_modules/.bin`.
|
|
67
154
|
|
|
68
155
|
| Target | Behaviour |
|
|
69
156
|
| --- | --- |
|
|
@@ -77,18 +164,101 @@ Exit codes: 0 in sync (or written), 1 drift under `--check`, 2 bad arguments or
|
|
|
77
164
|
CI example:
|
|
78
165
|
|
|
79
166
|
```yaml
|
|
80
|
-
- run:
|
|
167
|
+
- run: pnpm exec vvedantb-config sync --check
|
|
81
168
|
```
|
|
82
169
|
|
|
83
|
-
##
|
|
170
|
+
## check-asar
|
|
171
|
+
|
|
172
|
+
`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
173
|
|
|
85
174
|
```sh
|
|
86
|
-
|
|
87
|
-
|
|
175
|
+
vvedantb-check-asar list [app.asar] [--default-asar <path>]... [--scan <dir>]... [--require <package>]... [--root <dir>]
|
|
176
|
+
vvedantb-check-asar resolve [binary] [app.asar] [--default-binary <path>] [--scan <dir>]... [--skip-dir <name>]... [--hook <module>] [--root <dir>]
|
|
88
177
|
```
|
|
89
178
|
|
|
90
|
-
|
|
179
|
+
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.
|
|
180
|
+
|
|
181
|
+
### list
|
|
182
|
+
|
|
183
|
+
1. Finds `app.asar`: the argument, then `$ASAR`, then the first `--default-asar` that exists.
|
|
184
|
+
2. Lists the archive with `@electron/asar` `listPackage`.
|
|
185
|
+
3. Scans every `.js`, `.cjs` and `.mjs` file under each `--scan` directory on disk. A missing directory is skipped.
|
|
186
|
+
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.
|
|
187
|
+
5. Adds each `--require` package. Use it for optional peers that a dependency loads but the bundles never name.
|
|
188
|
+
6. Requires `node_modules/<package>/package.json` in the archive for each package.
|
|
189
|
+
|
|
190
|
+
Output:
|
|
191
|
+
|
|
192
|
+
| Case | Stream | Message | Exit |
|
|
193
|
+
| --- | --- | --- | --- |
|
|
194
|
+
| Every package found | stdout | `Checked <n> packages in <asar>: <names>`, then `check-asar-modules: OK` | 0 |
|
|
195
|
+
| Packages missing | stdout, then stderr | The `Checked` line, then `Missing from app.asar: <names>` | 1 |
|
|
196
|
+
| No asar found | stderr | `app.asar not found (tried <path or defaults>). Pass a path or set ASAR.` | 1 |
|
|
197
|
+
|
|
198
|
+
### resolve
|
|
199
|
+
|
|
200
|
+
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`.
|
|
201
|
+
|
|
202
|
+
Inside the binary:
|
|
203
|
+
|
|
204
|
+
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.
|
|
205
|
+
2. Collects bare specifiers with subpaths kept (`dep/sub`). Relative paths, `node:`, `electron` and Node built-ins are dropped.
|
|
206
|
+
3. Resolves each specifier with `require.resolve` from `app.asar/package.json`, then prints `checked <files> JS files, <imports> unbundled imports`.
|
|
207
|
+
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.
|
|
208
|
+
5. Prints each problem as `FAIL <problem>` to stderr and exits 1. Otherwise it prints `CHECK_ASAR_OK`.
|
|
209
|
+
|
|
210
|
+
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.
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
// scripts/check-asar-hook.mjs: runs inside the packaged binary
|
|
214
|
+
import { existsSync } from "node:fs";
|
|
215
|
+
import { join } from "node:path";
|
|
216
|
+
import { pathToFileURL } from "node:url";
|
|
217
|
+
|
|
218
|
+
/** @type {import("@vvedantb/config").AsarCheckHook} */
|
|
219
|
+
export default async function ({ asar }) {
|
|
220
|
+
const problems = [];
|
|
221
|
+
const native = join(`${asar}.unpacked`, "dist", "native", "addon.node");
|
|
222
|
+
if (process.platform === "darwin" && !existsSync(native)) problems.push(`missing native file: ${native}`);
|
|
223
|
+
try {
|
|
224
|
+
const { boot } = await import(pathToFileURL(join(asar, "dist", "boot.js")).href);
|
|
225
|
+
console.info(`boot ok: ${(await boot()) === null ? "null" : "value"}`);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
problems.push(`bundled boot path failed: ${error.stack ?? error}`);
|
|
228
|
+
}
|
|
229
|
+
return problems;
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Per-app invocation
|
|
234
|
+
|
|
235
|
+
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.
|
|
236
|
+
|
|
237
|
+
- An app built with electron-vite that ships macOS builds:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
vvedantb-check-asar list \
|
|
241
|
+
--default-asar "release/mac-arm64/<Product>.app/Contents/Resources/app.asar" \
|
|
242
|
+
--default-asar "release/mac/<Product>.app/Contents/Resources/app.asar" \
|
|
243
|
+
--scan out/main --scan out/preload --require electron-store
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- An app bundled with esbuild into `dist`, packaged as a Linux dir build by default, with native files and a bundled module to boot:
|
|
247
|
+
|
|
248
|
+
```sh
|
|
249
|
+
vvedantb-check-asar resolve --default-binary "release/linux-unpacked/<binary>" \
|
|
250
|
+
--scan dist --skip-dir renderer --hook scripts/check-asar-hook.mjs
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The app's native-file and boot checks, and their messages, move into the hook unchanged.
|
|
254
|
+
|
|
255
|
+
Exit codes for both modes: 0 passed, 1 failed, 2 bad arguments.
|
|
256
|
+
|
|
257
|
+
## Develop
|
|
91
258
|
|
|
92
259
|
```sh
|
|
93
|
-
pnpm --filter @vvedantb/config
|
|
260
|
+
pnpm --filter @vvedantb/config build
|
|
261
|
+
pnpm --filter @vvedantb/config test
|
|
94
262
|
```
|
|
263
|
+
|
|
264
|
+
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/expo.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The part of Babel's config API the preset uses. */
|
|
2
|
+
export interface BabelApi {
|
|
3
|
+
cache: (forever: boolean) => void;
|
|
4
|
+
}
|
|
5
|
+
export interface ExpoBabelConfig {
|
|
6
|
+
presets: (string | [string, {
|
|
7
|
+
jsxImportSource: string;
|
|
8
|
+
}])[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* `babel.config.js` for Expo with NativeWind: caches forever, then
|
|
12
|
+
* `babel-preset-expo` with `jsxImportSource: "nativewind"` and `nativewind/babel`.
|
|
13
|
+
* Babel resolves the preset names from the app, as before.
|
|
14
|
+
*/
|
|
15
|
+
export declare function expoBabelConfig(api: BabelApi): ExpoBabelConfig;
|
|
16
|
+
/** The part of Metro's config the preset sets. */
|
|
17
|
+
export interface MetroConfigLike {
|
|
18
|
+
watchFolders?: readonly string[];
|
|
19
|
+
resolver?: {
|
|
20
|
+
nodeModulesPaths?: readonly string[];
|
|
21
|
+
unstable_enablePackageExports?: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface NativeWindMetroOptions {
|
|
25
|
+
input: string;
|
|
26
|
+
inlineRem?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ExpoMetroOptions<Config extends MetroConfigLike> {
|
|
29
|
+
/** The app folder: `__dirname`. */
|
|
30
|
+
projectRoot: string;
|
|
31
|
+
/** `getDefaultConfig` from `expo/metro-config`. */
|
|
32
|
+
getDefaultConfig: (projectRoot: string) => Config;
|
|
33
|
+
/** `withNativeWind` from `nativewind/metro`. */
|
|
34
|
+
withNativeWind: (config: Config, options: NativeWindMetroOptions) => Config;
|
|
35
|
+
/** NativeWind CSS entry. Default `"./global.css"`. */
|
|
36
|
+
input?: string;
|
|
37
|
+
/** NativeWind `inlineRem`. Not passed when unset, so NativeWind keeps its default. */
|
|
38
|
+
inlineRem?: number;
|
|
39
|
+
/** Monorepo root relative to `projectRoot`, such as `"../.."`. Watches it and resolves from both node_modules folders. */
|
|
40
|
+
monorepoRoot?: string;
|
|
41
|
+
/** Sets `resolver.unstable_enablePackageExports: true`. */
|
|
42
|
+
packageExports?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `metro.config.js` for Expo with NativeWind: the Expo default config wrapped
|
|
46
|
+
* by `withNativeWind`, then the monorepo and package-exports resolver settings.
|
|
47
|
+
* Returns a new object; the result of `withNativeWind` is not changed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function defineExpoMetroConfig<Config extends MetroConfigLike>(options: ExpoMetroOptions<Config>): Config;
|
package/dist/expo.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* `babel.config.js` for Expo with NativeWind: caches forever, then
|
|
4
|
+
* `babel-preset-expo` with `jsxImportSource: "nativewind"` and `nativewind/babel`.
|
|
5
|
+
* Babel resolves the preset names from the app, as before.
|
|
6
|
+
*/
|
|
7
|
+
export function expoBabelConfig(api) {
|
|
8
|
+
api.cache(true);
|
|
9
|
+
return {
|
|
10
|
+
presets: [["babel-preset-expo", { jsxImportSource: "nativewind" }], "nativewind/babel"],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `metro.config.js` for Expo with NativeWind: the Expo default config wrapped
|
|
15
|
+
* by `withNativeWind`, then the monorepo and package-exports resolver settings.
|
|
16
|
+
* Returns a new object; the result of `withNativeWind` is not changed.
|
|
17
|
+
*/
|
|
18
|
+
export function defineExpoMetroConfig(options) {
|
|
19
|
+
const nativeWind = { input: options.input ?? "./global.css" };
|
|
20
|
+
if (options.inlineRem !== undefined)
|
|
21
|
+
nativeWind.inlineRem = options.inlineRem;
|
|
22
|
+
const config = options.withNativeWind(options.getDefaultConfig(options.projectRoot), nativeWind);
|
|
23
|
+
if (options.monorepoRoot === undefined && !options.packageExports)
|
|
24
|
+
return config;
|
|
25
|
+
const resolver = { ...config.resolver };
|
|
26
|
+
const result = { ...config, resolver };
|
|
27
|
+
if (options.monorepoRoot !== undefined) {
|
|
28
|
+
const root = resolve(options.projectRoot, options.monorepoRoot);
|
|
29
|
+
result.watchFolders = [root];
|
|
30
|
+
resolver.nodeModulesPaths = [
|
|
31
|
+
resolve(options.projectRoot, "node_modules"),
|
|
32
|
+
resolve(root, "node_modules"),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
if (options.packageExports)
|
|
36
|
+
resolver.unstable_enablePackageExports = true;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
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";
|
|
5
|
+
export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, type AliasOptions, type BabelReactCompiler, type PathOptions, type ReactSetup, type ResolveConfig, type RouterPluginOptions, type VendorChunk, type VendorChunkGroup, type VitePlugin, type VitePluginOption, type WebBuildConfig, type WebViteConfig, type WebViteOptions, type WebVitestConfig, type WebVitestOptions, } from "./vite.js";
|
|
6
|
+
export { defineExpoMetroConfig, expoBabelConfig, type BabelApi, type ExpoBabelConfig, type ExpoMetroOptions, type MetroConfigLike, type NativeWindMetroOptions, } from "./expo.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
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";
|
|
5
|
+
export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, } from "./vite.js";
|
|
6
|
+
export { defineExpoMetroConfig, expoBabelConfig, } from "./expo.js";
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** A Vite plugin: Vite's `Plugin` needs only `name`. */
|
|
2
|
+
export interface VitePlugin {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
type VitePluginOptionValue = VitePlugin | false | null | undefined | VitePluginOption[];
|
|
6
|
+
/** Mirrors Vite's `PluginOption`: falsy entries are dropped by Vite. */
|
|
7
|
+
export type VitePluginOption = VitePluginOptionValue | Promise<VitePluginOptionValue>;
|
|
8
|
+
/** The `@tanstack/router-plugin/vite` options the presets pass through. */
|
|
9
|
+
export interface RouterPluginOptions {
|
|
10
|
+
target?: "react";
|
|
11
|
+
routesDirectory?: string;
|
|
12
|
+
generatedRouteTree?: string;
|
|
13
|
+
routeFileIgnorePattern?: string;
|
|
14
|
+
autoCodeSplitting: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The React Compiler through `@rolldown/plugin-babel` and `reactCompilerPreset` (plugin-react before 6.1). */
|
|
17
|
+
export interface BabelReactCompiler<Preset> {
|
|
18
|
+
babel: (options: {
|
|
19
|
+
presets: Preset[];
|
|
20
|
+
}) => VitePluginOption;
|
|
21
|
+
preset: () => Preset;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `@vitejs/plugin-react`, with or without the React Compiler.
|
|
25
|
+
* - `compiler: true` calls `react({ compiler: true })` (plugin-react 6.1+).
|
|
26
|
+
* - `compiler: { babel, preset }` calls `react()` then `babel({ presets: [preset()] })`.
|
|
27
|
+
* - No `compiler` calls `react()`.
|
|
28
|
+
*/
|
|
29
|
+
export type ReactSetup<Preset> = {
|
|
30
|
+
plugin: (options: {
|
|
31
|
+
compiler: true;
|
|
32
|
+
}) => VitePluginOption;
|
|
33
|
+
compiler: true;
|
|
34
|
+
} | {
|
|
35
|
+
plugin: () => VitePluginOption;
|
|
36
|
+
compiler: BabelReactCompiler<Preset>;
|
|
37
|
+
} | {
|
|
38
|
+
plugin: () => VitePluginOption;
|
|
39
|
+
compiler?: false;
|
|
40
|
+
};
|
|
41
|
+
/** Vite's `resolve.alias`: an object, or a list of `{ find, replacement }`. */
|
|
42
|
+
export type AliasOptions = Record<string, string> | {
|
|
43
|
+
find: string | RegExp;
|
|
44
|
+
replacement: string;
|
|
45
|
+
}[];
|
|
46
|
+
export interface PathOptions {
|
|
47
|
+
/** Sets `resolve.tsconfigPaths: true` (Vite 8). */
|
|
48
|
+
tsconfigPaths?: boolean;
|
|
49
|
+
/** `resolve.alias`, as given. See `srcAlias`. */
|
|
50
|
+
alias?: AliasOptions;
|
|
51
|
+
}
|
|
52
|
+
export interface ResolveConfig {
|
|
53
|
+
tsconfigPaths?: boolean;
|
|
54
|
+
alias?: AliasOptions;
|
|
55
|
+
dedupe?: string[];
|
|
56
|
+
}
|
|
57
|
+
export type VendorChunk = "radix" | "convex" | "clerk" | "motion";
|
|
58
|
+
export interface VendorChunkGroup {
|
|
59
|
+
name: string;
|
|
60
|
+
test: RegExp;
|
|
61
|
+
priority: number;
|
|
62
|
+
}
|
|
63
|
+
export interface WebBuildConfig {
|
|
64
|
+
outDir: string;
|
|
65
|
+
chunkSizeWarningLimit: number;
|
|
66
|
+
rolldownOptions: {
|
|
67
|
+
output: {
|
|
68
|
+
codeSplitting: {
|
|
69
|
+
groups: VendorChunkGroup[];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface WebViteOptions<Preset> extends PathOptions {
|
|
75
|
+
/** `@tailwindcss/vite`. Added first. */
|
|
76
|
+
tailwindcss?: () => VitePluginOption;
|
|
77
|
+
/** `@tanstack/router-plugin/vite`. Added after Tailwind; `autoCodeSplitting: true` is always set. */
|
|
78
|
+
router?: {
|
|
79
|
+
plugin: (options: RouterPluginOptions) => VitePluginOption;
|
|
80
|
+
options?: Omit<RouterPluginOptions, "autoCodeSplitting">;
|
|
81
|
+
};
|
|
82
|
+
/** `@vitejs/plugin-react`. Added after the router. */
|
|
83
|
+
react: ReactSetup<Preset>;
|
|
84
|
+
/** App plugins, added last. Falsy entries are dropped. */
|
|
85
|
+
plugins?: VitePluginOption[];
|
|
86
|
+
/** `resolve.dedupe`, as given. See `REACT_DEDUPE`. */
|
|
87
|
+
dedupe?: readonly string[];
|
|
88
|
+
/** Splits vendor chunks with rolldown. `true` uses the default tests; an object replaces some of them. */
|
|
89
|
+
vendorChunks?: boolean | Partial<Record<VendorChunk, RegExp>>;
|
|
90
|
+
}
|
|
91
|
+
export interface WebViteConfig {
|
|
92
|
+
plugins: VitePluginOption[];
|
|
93
|
+
resolve?: ResolveConfig;
|
|
94
|
+
build?: WebBuildConfig;
|
|
95
|
+
}
|
|
96
|
+
export interface WebVitestOptions extends PathOptions {
|
|
97
|
+
plugins?: VitePluginOption[];
|
|
98
|
+
/** Sets `esbuild: { jsx: "automatic" }`, so `.tsx` tests need no React import. */
|
|
99
|
+
automaticJsx?: boolean;
|
|
100
|
+
/** Test globs. Default `["src/**\/*.test.ts"]`. */
|
|
101
|
+
include?: string[];
|
|
102
|
+
/** Packages Vitest transforms instead of loading from node_modules (`test.server.deps.inline`). */
|
|
103
|
+
inline?: string[];
|
|
104
|
+
}
|
|
105
|
+
export interface WebVitestConfig {
|
|
106
|
+
plugins?: VitePluginOption[];
|
|
107
|
+
esbuild?: {
|
|
108
|
+
jsx: "automatic";
|
|
109
|
+
};
|
|
110
|
+
resolve?: ResolveConfig;
|
|
111
|
+
test: {
|
|
112
|
+
environment: "node";
|
|
113
|
+
include: string[];
|
|
114
|
+
server?: {
|
|
115
|
+
deps: {
|
|
116
|
+
inline: string[];
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Packages that hold React context. pnpm can install two copies; dedupe keeps one. */
|
|
122
|
+
export declare const REACT_DEDUPE: readonly ["react", "react-dom", "convex", "@tanstack/react-router", "@clerk/clerk-react"];
|
|
123
|
+
/** `{ "@": "<dirname>/src" }`. Pass `import.meta.dirname`. */
|
|
124
|
+
export declare function srcAlias(dirname: string): Record<string, string>;
|
|
125
|
+
/** The plugin-react plugins for a `ReactSetup`, in order. */
|
|
126
|
+
export declare function reactPlugins<Preset>(setup: ReactSetup<Preset>): VitePluginOption[];
|
|
127
|
+
/** `outDir: "dist"`, a 1000 kB chunk warning and vendor chunks for Radix, Convex, Clerk and Motion. */
|
|
128
|
+
export declare function vendorChunkBuild(tests?: Partial<Record<VendorChunk, RegExp>>): WebBuildConfig;
|
|
129
|
+
/**
|
|
130
|
+
* The shared part of a web app's `vite.config.ts`: plugins, `resolve` and `build`.
|
|
131
|
+
* Spread it into Vite's `defineConfig` and add `server`, `base` or `root` there.
|
|
132
|
+
*/
|
|
133
|
+
export declare function defineWebViteConfig<Preset>(options: WebViteOptions<Preset>): WebViteConfig;
|
|
134
|
+
/** A web app's `vitest.config.ts`: Node environment, test globs and inlined packages. */
|
|
135
|
+
export declare function defineWebVitestConfig(options?: WebVitestOptions): WebVitestConfig;
|
|
136
|
+
export {};
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
/** Packages that hold React context. pnpm can install two copies; dedupe keeps one. */
|
|
3
|
+
export const REACT_DEDUPE = [
|
|
4
|
+
"react",
|
|
5
|
+
"react-dom",
|
|
6
|
+
"convex",
|
|
7
|
+
"@tanstack/react-router",
|
|
8
|
+
"@clerk/clerk-react",
|
|
9
|
+
];
|
|
10
|
+
const VENDOR_TESTS = {
|
|
11
|
+
radix: /node_modules[\\/]@radix-ui/,
|
|
12
|
+
convex: /node_modules[\\/]convex/,
|
|
13
|
+
clerk: /node_modules[\\/]@clerk/,
|
|
14
|
+
motion: /node_modules[\\/](motion|framer-motion)/,
|
|
15
|
+
};
|
|
16
|
+
const VENDOR_ORDER = ["radix", "convex", "clerk", "motion"];
|
|
17
|
+
/** `{ "@": "<dirname>/src" }`. Pass `import.meta.dirname`. */
|
|
18
|
+
export function srcAlias(dirname) {
|
|
19
|
+
return { "@": resolve(dirname, "src") };
|
|
20
|
+
}
|
|
21
|
+
/** The plugin-react plugins for a `ReactSetup`, in order. */
|
|
22
|
+
export function reactPlugins(setup) {
|
|
23
|
+
if (setup.compiler === true)
|
|
24
|
+
return [setup.plugin({ compiler: true })];
|
|
25
|
+
if (setup.compiler) {
|
|
26
|
+
return [setup.plugin(), setup.compiler.babel({ presets: [setup.compiler.preset()] })];
|
|
27
|
+
}
|
|
28
|
+
return [setup.plugin()];
|
|
29
|
+
}
|
|
30
|
+
/** `outDir: "dist"`, a 1000 kB chunk warning and vendor chunks for Radix, Convex, Clerk and Motion. */
|
|
31
|
+
export function vendorChunkBuild(tests = {}) {
|
|
32
|
+
return {
|
|
33
|
+
outDir: "dist",
|
|
34
|
+
chunkSizeWarningLimit: 1000,
|
|
35
|
+
rolldownOptions: {
|
|
36
|
+
output: {
|
|
37
|
+
codeSplitting: {
|
|
38
|
+
groups: VENDOR_ORDER.map((chunk) => ({
|
|
39
|
+
name: `vendor-${chunk}`,
|
|
40
|
+
test: tests[chunk] ?? VENDOR_TESTS[chunk],
|
|
41
|
+
priority: 15,
|
|
42
|
+
})),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function resolveConfig(options) {
|
|
49
|
+
const config = {};
|
|
50
|
+
if (options.tsconfigPaths)
|
|
51
|
+
config.tsconfigPaths = true;
|
|
52
|
+
if (options.alias)
|
|
53
|
+
config.alias = options.alias;
|
|
54
|
+
if (options.dedupe)
|
|
55
|
+
config.dedupe = [...options.dedupe];
|
|
56
|
+
return Object.keys(config).length > 0 ? config : undefined;
|
|
57
|
+
}
|
|
58
|
+
function isPlugin(plugin) {
|
|
59
|
+
return Boolean(plugin);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The shared part of a web app's `vite.config.ts`: plugins, `resolve` and `build`.
|
|
63
|
+
* Spread it into Vite's `defineConfig` and add `server`, `base` or `root` there.
|
|
64
|
+
*/
|
|
65
|
+
export function defineWebViteConfig(options) {
|
|
66
|
+
const plugins = [];
|
|
67
|
+
if (options.tailwindcss)
|
|
68
|
+
plugins.push(options.tailwindcss());
|
|
69
|
+
if (options.router) {
|
|
70
|
+
plugins.push(options.router.plugin({ ...options.router.options, autoCodeSplitting: true }));
|
|
71
|
+
}
|
|
72
|
+
plugins.push(...reactPlugins(options.react), ...(options.plugins ?? []).filter(isPlugin));
|
|
73
|
+
const config = { plugins };
|
|
74
|
+
const resolved = resolveConfig(options);
|
|
75
|
+
if (resolved)
|
|
76
|
+
config.resolve = resolved;
|
|
77
|
+
if (options.vendorChunks) {
|
|
78
|
+
config.build = vendorChunkBuild(options.vendorChunks === true ? {} : options.vendorChunks);
|
|
79
|
+
}
|
|
80
|
+
return config;
|
|
81
|
+
}
|
|
82
|
+
/** A web app's `vitest.config.ts`: Node environment, test globs and inlined packages. */
|
|
83
|
+
export function defineWebVitestConfig(options = {}) {
|
|
84
|
+
const config = {
|
|
85
|
+
test: { environment: "node", include: options.include ?? ["src/**/*.test.ts"] },
|
|
86
|
+
};
|
|
87
|
+
if (options.plugins)
|
|
88
|
+
config.plugins = options.plugins;
|
|
89
|
+
if (options.automaticJsx)
|
|
90
|
+
config.esbuild = { jsx: "automatic" };
|
|
91
|
+
const resolved = resolveConfig(options);
|
|
92
|
+
if (resolved)
|
|
93
|
+
config.resolve = resolved;
|
|
94
|
+
if (options.inline)
|
|
95
|
+
config.test.server = { deps: { inline: options.inline } };
|
|
96
|
+
return config;
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "Shared tsconfig bases, oxlint base, pinned tool versions
|
|
5
|
+
"description": "Shared tsconfig bases, oxlint base, Vite, Vitest, Babel and Metro presets, 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
|
-
},
|
|
23
|
-
"./versions": {
|
|
24
|
-
"types": "./dist/versions.d.ts",
|
|
25
|
-
"import": "./dist/versions.js"
|
|
22
|
+
"default": "./dist/index.js"
|
|
26
23
|
},
|
|
27
24
|
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
28
25
|
"./tsconfig/web.json": "./tsconfig/web.json",
|
|
@@ -37,6 +34,7 @@
|
|
|
37
34
|
"files",
|
|
38
35
|
"tsconfig",
|
|
39
36
|
"oxlint",
|
|
37
|
+
"CHANGELOG.md",
|
|
40
38
|
"LICENSE"
|
|
41
39
|
],
|
|
42
40
|
"scripts": {
|
|
@@ -45,9 +43,20 @@
|
|
|
45
43
|
"test": "vitest run",
|
|
46
44
|
"prepack": "tsc -p tsconfig.json"
|
|
47
45
|
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@electron/asar": "^3.2.0 || ^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@electron/asar": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
48
54
|
"devDependencies": {
|
|
55
|
+
"@electron/asar": "^4.3.1",
|
|
49
56
|
"@types/node": "^22.0.0",
|
|
57
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
50
58
|
"typescript": "^5.9.0",
|
|
59
|
+
"vite": "^8.3.4",
|
|
51
60
|
"vitest": "^3.2.0"
|
|
52
61
|
}
|
|
53
62
|
}
|