@venizia/dev-configs 0.4.7-4 → 0.4.7

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/README.md CHANGED
@@ -105,10 +105,10 @@ Every IGNIS package and example does.
105
105
  | `@venizia/dev-configs` | Everything below, re-exported |
106
106
  | `@venizia/dev-configs/compilers` | `BunCompiler` |
107
107
  | `@venizia/dev-configs/testing` | `RejectionHelper` (`rejectionOf`, `expectRejection`), `SpawnHelper` (`spawnSyncBounded`), `RepoTmp` (`findRoot`, `apply`) - test helpers (imports `bun:test`; tests only) |
108
- | `@venizia/dev-configs/linters` | `oxlintConfigs`, `OxlintConfigs`, `BrowserOxlintConfigs`, `ReactOxlintConfigs`, `LintIgnore`, `namingConventionConfigs`, `reactNamingConventionConfigs`, `houseConfigs`, `reactHouseConfigs`, `eslintConfigs`, `ReactEslintConfigs`, the rule classes and their types |
108
+ | `@venizia/dev-configs/linters` | `oxlintConfigs`, `OxlintConfigs`, `BrowserOxlintConfigs`, `ReactOxlintConfigs`, `LintIgnore`, `namingConventionConfigs`, `reactNamingConventionConfigs`, `houseConfigs`, `reactHouseConfigs`, `eslintConfigs`, the rule classes and their types |
109
109
  | `@venizia/dev-configs/linters/oxlint` | `oxlintConfigs`, `OxlintConfigs`, `IOxlintPresetOptions`, `BrowserOxlintConfigs`, `ReactOxlintConfigs`, `LintIgnore`, the rule classes and their types: everything an oxlint config needs, and nothing that loads ESLint. Loads in milliseconds: `/linters` also loads ESLint and its plugins, which an oxlint config never uses |
110
110
  | `@venizia/dev-configs/tsconfig.base.json` | Target and lib ES2025, `module` Node16, strict mode (`noImplicitAny` and `useUnknownInCatchVariables` on) with `strictPropertyInitialization` off (DI-injected properties have no initializer), `noEmitOnError`, tests excluded |
111
- | `@venizia/dev-configs/tsconfig.common.json` | Extends the base and switches `module` and `moduleResolution` to `nodenext` |
111
+ | `@venizia/dev-configs/tsconfig.common.json` | Extends the base and restates `module` as `esnext` and `moduleResolution` as `bundler` |
112
112
  | `@venizia/dev-configs/tsconfig.browser.json` | Extends the base for a browser library built with a bundler: `module` ESNext, `moduleResolution` bundler, lib ES2025 + `DOM` + `DOM.Iterable`, `types: []` so no Bun types reach `dist` |
113
113
  | `@venizia/dev-configs/tsconfig.react.json` | Extends `tsconfig.browser.json` and sets `jsx: react-jsx` |
114
114
 
@@ -250,44 +250,6 @@ conventions, `curly`, `eslint-plugin-n`, plus these IGNIS rules:
250
250
  | `@typescript-eslint/no-namespace` | `error` |
251
251
  | `unicorn/switch-case-braces` | `['error', 'always']` |
252
252
 
253
- ### ReactEslintConfigs
254
-
255
- `ReactEslintConfigs.create({ plugins })` is `eslintConfigs` plus what a React frontend needs. The
256
- plugins come in as options, so a backend installs none of them:
257
-
258
- ```js
259
- // eslint.config.mjs
260
- import { ReactEslintConfigs } from '@venizia/dev-configs';
261
- import react from 'eslint-plugin-react';
262
- import reactHooks from 'eslint-plugin-react-hooks';
263
- import jsxA11y from 'eslint-plugin-jsx-a11y';
264
-
265
- export default [
266
- { ignores: ['dist/'] },
267
- ...ReactEslintConfigs.create({ plugins: { react, reactHooks, jsxA11y } }),
268
- ];
269
- ```
270
-
271
- | Adds | Setting |
272
- | :--- | :--- |
273
- | React correctness (`jsx-key`, `no-children-prop`, `no-deprecated`, ... - 14 rules) | `error`, `.jsx`/`.tsx` |
274
- | `jsx-a11y` (`alt-text`, `aria-props`, `aria-role`, `click-events-have-key-events`, `label-has-associated-control`, ... - 15 rules) | `error`, `.jsx`/`.tsx` |
275
- | `react-hooks/rules-of-hooks` / `exhaustive-deps` | `error`, every source file |
276
- | `@typescript-eslint/consistent-type-imports` | `['error', { prefer: 'type-imports', fixStyle: 'inline-type-imports', disallowTypeAnnotations: false }]` |
277
- | `naming-convention` | the base rule, plus PascalCase functions (`function App()`), `.jsx`/`.tsx` |
278
- | `no-restricted-properties` | `NoRestrictedPropertiesRule.build()` - bans `crypto.randomUUID` |
279
-
280
- Nothing in the base is relaxed: frontend code meets the backend's standard, so a floating promise, a
281
- `void`, a use before declaration or a shadowed name fails the lint as it does in a service.
282
-
283
- Rules the automatic JSX runtime or `tsc` already enforce (`react-in-jsx-scope`, `prop-types`,
284
- `jsx-no-undef`, ...) are left out.
285
-
286
- - `reactVersion` defaults to `'detect'`. Under ESLint 10, eslint-plugin-react 7 cannot detect it and
287
- aborts - pass the version: `create({ plugins, reactVersion: '19.2' })`.
288
- - In an `eslint.config.ts`, `eslint-plugin-jsx-a11y` needs `@types/eslint-plugin-jsx-a11y`.
289
- - `consistent-type-imports` uses `fixStyle: inline-type-imports`, the same as the base preset.
290
-
291
253
  ### BrowserOxlintConfigs
292
254
 
293
255
  `BrowserOxlintConfigs.create()` is `oxlintConfigs` plus `NoRestrictedPropertiesRule.build()`. That
@@ -0,0 +1,43 @@
1
+ /** The removed `@venizia/ignis/<sub-path>` specifiers and the `@venizia/ignis-connectors/<sub-path>` they became. */
2
+ export declare class ConnectorSpecifiers {
3
+ static readonly SUBPATHS: ReadonlyArray<string>;
4
+ static readonly MOVES: ReadonlyMap<string, string>;
5
+ }
6
+ export interface IConnectorImportsResult {
7
+ output: string;
8
+ changed: boolean;
9
+ /** How many specifiers were moved. */
10
+ rewritten: number;
11
+ }
12
+ /** Rewrites the module specifiers of the removed connector sub-paths. */
13
+ export declare class ConnectorImports {
14
+ static rewrite(opts: {
15
+ typescript: typeof import('typescript');
16
+ fileName: string;
17
+ source: string;
18
+ }): IConnectorImportsResult;
19
+ /**
20
+ * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when
21
+ * there is none to read.
22
+ */
23
+ static findManifest(opts: {
24
+ file: string;
25
+ root: string;
26
+ }): {
27
+ path: string;
28
+ hasConnectors: boolean;
29
+ } | undefined;
30
+ }
31
+ /**
32
+ * `devz codemod connector-imports [paths...] [--write | --check]`: moves the removed
33
+ * `@venizia/ignis/<connector sub-path>` specifiers to `@venizia/ignis-connectors`. It is a dry run unless `--write`
34
+ * is given. `--check` is the same dry run, and exits 1 while a file would change.
35
+ */
36
+ export declare class ConnectorImportsCommand {
37
+ static readonly USAGE = "Usage: devz codemod connector-imports [paths...] [--write | --check]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (for CI)\n --help print this text and exit\n\nWith no flag it lists what would change and writes nothing. Inside a git repository it reads the\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed, staged or untracked): commit or stash it first, so git can undo the codemod.";
38
+ static run(opts: {
39
+ root: string;
40
+ args: string[];
41
+ }): Promise<number>;
42
+ }
43
+ //# sourceMappingURL=connector-imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-imports.d.ts","sourceRoot":"","sources":["../../../src/cli/codemod/connector-imports.ts"],"names":[],"mappings":"AA8DA,qHAAqH;AACrH,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAc7C;IAEF,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAKhD;CACH;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,yEAAyE;AACzE,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;QACnB,UAAU,EAAE,cAAc,YAAY,CAAC,CAAC;QACxC,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,uBAAuB;IAkF3B;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS;CAoCzD;AAED;;;;GAIG;AACH,qBAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,KAAK,4hDAAS;WAEjB,GAAG,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAwH1E"}
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectorImportsCommand = exports.ConnectorImports = exports.ConnectorSpecifiers = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const files_1 = require("./files");
7
+ const USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check]
8
+
9
+ Moves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths
10
+ @venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,
11
+ /postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,
12
+ /typesense and /typesense/controllers are removed; each one is the same name under
13
+ @venizia/ignis-connectors, so the rewrite changes only the specifier.
14
+
15
+ It reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import("..."),
16
+ require("..."), require.resolve("...") and import.meta.resolve("..."), import("...") types, declare module
17
+ "..." and the module name of mock.module("...") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,
18
+ testing, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a
19
+ direct dependency: it reports each package.json that does not.
20
+
21
+ --write write the changed files (without it, nothing is written)
22
+ --check dry run that exits 1 while a file would change (for CI)
23
+ --help print this text and exit
24
+
25
+ With no flag it lists what would change and writes nothing. Inside a git repository it reads the
26
+ files git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes
27
+ (changed, staged or untracked): commit or stash it first, so git can undo the codemod.`;
28
+ /** A usage error: nothing was read or written. */
29
+ const USAGE_ERROR_CODE = 2;
30
+ const CONNECTORS_PACKAGE = '@venizia/ignis-connectors';
31
+ const OLD_PREFIX = '@venizia/ignis/';
32
+ /** The call names that take a module name as their first argument besides `require` and `import()`. */
33
+ const MODULE_NAME_CALLS = new Set([
34
+ 'module',
35
+ 'mock',
36
+ 'doMock',
37
+ 'unmock',
38
+ 'importActual',
39
+ 'requireActual',
40
+ 'importMock',
41
+ 'requireMock',
42
+ ]);
43
+ class ConnectorImportsFlags {
44
+ static { this.WRITE = '--write'; }
45
+ static { this.CHECK = '--check'; }
46
+ static { this.HELP = '--help'; }
47
+ static { this.HELP_SHORT = '-h'; }
48
+ static { this.SCHEME_SET = new Set([
49
+ this.WRITE,
50
+ this.CHECK,
51
+ this.HELP,
52
+ this.HELP_SHORT,
53
+ ]); }
54
+ static isValid(value) {
55
+ return this.SCHEME_SET.has(value);
56
+ }
57
+ }
58
+ /** The removed `@venizia/ignis/<sub-path>` specifiers and the `@venizia/ignis-connectors/<sub-path>` they became. */
59
+ class ConnectorSpecifiers {
60
+ static { this.SUBPATHS = [
61
+ 'postgres',
62
+ 'postgres/node-postgres',
63
+ 'postgres/postgres-js',
64
+ 'postgres/pglite',
65
+ 'postgres/supabase',
66
+ 'relational',
67
+ 'sqlite',
68
+ 'sqlite/libsql',
69
+ 'search',
70
+ 'search/controllers',
71
+ 'meilisearch',
72
+ 'typesense',
73
+ 'typesense/controllers',
74
+ ]; }
75
+ static { this.MOVES = new Map(ConnectorSpecifiers.SUBPATHS.map((subpath) => [
76
+ `${OLD_PREFIX}${subpath}`,
77
+ `${CONNECTORS_PACKAGE}/${subpath}`,
78
+ ])); }
79
+ }
80
+ exports.ConnectorSpecifiers = ConnectorSpecifiers;
81
+ /** Rewrites the module specifiers of the removed connector sub-paths. */
82
+ class ConnectorImports {
83
+ static rewrite(opts) {
84
+ const { typescript: ts, fileName, source } = opts;
85
+ const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
86
+ const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);
87
+ const edits = [];
88
+ const consider = (literal) => {
89
+ if (!literal || !ts.isStringLiteralLike(literal)) {
90
+ return;
91
+ }
92
+ const moved = ConnectorSpecifiers.MOVES.get(literal.text);
93
+ if (moved === undefined) {
94
+ return;
95
+ }
96
+ const start = literal.getStart(file);
97
+ const quote = source[start];
98
+ edits.push({ start, end: literal.getEnd(), text: `${quote}${moved}${quote}` });
99
+ };
100
+ const isModuleNameCall = (call) => {
101
+ const callee = call.expression;
102
+ if (callee.kind === ts.SyntaxKind.ImportKeyword) {
103
+ return true;
104
+ }
105
+ if (ts.isIdentifier(callee)) {
106
+ return callee.text === 'require';
107
+ }
108
+ if (!ts.isPropertyAccessExpression(callee)) {
109
+ return false;
110
+ }
111
+ if (callee.name.text === 'resolve') {
112
+ return ((ts.isIdentifier(callee.expression) && callee.expression.text === 'require') ||
113
+ ts.isMetaProperty(callee.expression));
114
+ }
115
+ return MODULE_NAME_CALLS.has(callee.name.text);
116
+ };
117
+ const visit = (node) => {
118
+ if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
119
+ consider(node.moduleSpecifier);
120
+ }
121
+ else if (ts.isImportEqualsDeclaration(node)) {
122
+ if (ts.isExternalModuleReference(node.moduleReference)) {
123
+ consider(node.moduleReference.expression);
124
+ }
125
+ }
126
+ else if (ts.isCallExpression(node)) {
127
+ if (isModuleNameCall(node)) {
128
+ consider(node.arguments[0]);
129
+ }
130
+ }
131
+ else if (ts.isModuleDeclaration(node)) {
132
+ consider(node.name);
133
+ }
134
+ else if (ts.isImportTypeNode(node)) {
135
+ if (ts.isLiteralTypeNode(node.argument)) {
136
+ consider(node.argument.literal);
137
+ }
138
+ }
139
+ ts.forEachChild(node, visit);
140
+ };
141
+ visit(file);
142
+ if (edits.length === 0) {
143
+ return { output: source, changed: false, rewritten: 0 };
144
+ }
145
+ let output = source;
146
+ for (const edit of edits.sort((a, b) => b.start - a.start)) {
147
+ output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
148
+ }
149
+ return { output, changed: true, rewritten: edits.length };
150
+ }
151
+ /**
152
+ * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when
153
+ * there is none to read.
154
+ */
155
+ static findManifest(opts) {
156
+ const { file, root } = opts;
157
+ let directory = (0, node_path_1.dirname)(file);
158
+ for (;;) {
159
+ const candidate = (0, node_path_1.join)(directory, 'package.json');
160
+ if ((0, node_fs_1.existsSync)(candidate)) {
161
+ let manifest;
162
+ try {
163
+ manifest = JSON.parse((0, node_fs_1.readFileSync)(candidate, 'utf8'));
164
+ }
165
+ catch (error) {
166
+ console.warn(`${candidate} is not valid JSON, so its dependencies were not checked | ${error instanceof Error ? error.message : String(error)}`);
167
+ return undefined;
168
+ }
169
+ const listed = typeof manifest === 'object' &&
170
+ manifest !== null &&
171
+ ['dependencies', 'devDependencies', 'peerDependencies'].some((field) => {
172
+ const group = Reflect.get(manifest, field);
173
+ return typeof group === 'object' && group !== null && CONNECTORS_PACKAGE in group;
174
+ });
175
+ return { path: candidate, hasConnectors: listed };
176
+ }
177
+ if (directory === root || (0, node_path_1.dirname)(directory) === directory) {
178
+ return undefined;
179
+ }
180
+ directory = (0, node_path_1.dirname)(directory);
181
+ }
182
+ }
183
+ }
184
+ exports.ConnectorImports = ConnectorImports;
185
+ /**
186
+ * `devz codemod connector-imports [paths...] [--write | --check]`: moves the removed
187
+ * `@venizia/ignis/<connector sub-path>` specifiers to `@venizia/ignis-connectors`. It is a dry run unless `--write`
188
+ * is given. `--check` is the same dry run, and exits 1 while a file would change.
189
+ */
190
+ class ConnectorImportsCommand {
191
+ static { this.USAGE = USAGE; }
192
+ static async run(opts) {
193
+ const { root, args } = opts;
194
+ if (args.includes(ConnectorImportsFlags.HELP) ||
195
+ args.includes(ConnectorImportsFlags.HELP_SHORT)) {
196
+ console.log(USAGE);
197
+ return 0;
198
+ }
199
+ const flags = args.filter((argument) => argument.startsWith('-'));
200
+ const paths = args.filter((argument) => !argument.startsWith('-'));
201
+ const unknown = flags.filter((flag) => !ConnectorImportsFlags.isValid(flag));
202
+ if (unknown.length > 0) {
203
+ console.error(`devz codemod: unknown option ${unknown.map((flag) => `"${flag}"`).join(', ')}\n${USAGE}`);
204
+ return USAGE_ERROR_CODE;
205
+ }
206
+ const isWrite = flags.includes(ConnectorImportsFlags.WRITE);
207
+ const isCheck = flags.includes(ConnectorImportsFlags.CHECK);
208
+ if (isWrite && isCheck) {
209
+ console.error(`devz codemod: ${ConnectorImportsFlags.WRITE} and ${ConnectorImportsFlags.CHECK} contradict each other\n${USAGE}`);
210
+ return USAGE_ERROR_CODE;
211
+ }
212
+ let typescript;
213
+ try {
214
+ const loaded = await import('typescript');
215
+ typescript = loaded.default;
216
+ }
217
+ catch {
218
+ console.error('devz codemod: the "typescript" package is required to read your sources');
219
+ return 1;
220
+ }
221
+ const targets = (paths.length > 0 ? paths : ['.']).map((path) => (0, node_path_1.resolve)(root, path));
222
+ const missing = new Set();
223
+ let changedCount = 0;
224
+ let specifierCount = 0;
225
+ let refusedCount = 0;
226
+ for (const target of targets) {
227
+ const files = files_1.CodemodFiles.collect({ target });
228
+ const dirty = isWrite ? files_1.CodemodFiles.dirty({ target }) : undefined;
229
+ if (files.length === 0 && paths.length > 0) {
230
+ console.warn(`devz codemod: no source files under "${(0, node_path_1.relative)(root, target) || target}" (git ignores the path, or it holds none): nothing was read`);
231
+ }
232
+ for (const file of files) {
233
+ const source = (0, node_fs_1.readFileSync)(file, 'utf8');
234
+ if (!source.includes(OLD_PREFIX)) {
235
+ continue;
236
+ }
237
+ const result = ConnectorImports.rewrite({ typescript, fileName: file, source });
238
+ if (!result.changed) {
239
+ continue;
240
+ }
241
+ const shown = (0, node_path_1.relative)(root, file).split('\\').join('/') || file;
242
+ if (dirty?.has(file)) {
243
+ refusedCount += 1;
244
+ console.warn(`refused ${shown} has local changes (commit or stash them, then run again)`);
245
+ continue;
246
+ }
247
+ changedCount += 1;
248
+ specifierCount += result.rewritten;
249
+ console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} specifier(s))`);
250
+ const manifest = ConnectorImports.findManifest({ file, root });
251
+ if (manifest && !manifest.hasConnectors) {
252
+ missing.add((0, node_path_1.relative)(root, manifest.path).split('\\').join('/') || manifest.path);
253
+ }
254
+ if (isWrite) {
255
+ (0, node_fs_1.writeFileSync)(file, result.output);
256
+ }
257
+ }
258
+ }
259
+ console.log(`devz codemod connector-imports: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${specifierCount} specifier(s) ${isWrite ? 'moved' : 'would be moved'}` +
260
+ (refusedCount > 0 ? `, ${refusedCount} refused` : ''));
261
+ for (const manifestPath of [...missing].sort()) {
262
+ console.warn(`${manifestPath} does not list ${CONNECTORS_PACKAGE}: add it as a dependency, because the imports now come from it`);
263
+ }
264
+ if (!isWrite && changedCount > 0) {
265
+ console.log(`Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then add the dependency and run your typecheck.`);
266
+ }
267
+ if (isWrite && refusedCount > 0) {
268
+ return 1;
269
+ }
270
+ return isCheck && changedCount > 0 ? 1 : 0;
271
+ }
272
+ }
273
+ exports.ConnectorImportsCommand = ConnectorImportsCommand;
274
+ //# sourceMappingURL=connector-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-imports.js","sourceRoot":"","sources":["../../../src/cli/codemod/connector-imports.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,yCAA6D;AAC7D,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;uFAoByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,eAAe;IACf,YAAY;IACZ,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,qBAAqB;aACT,UAAK,GAAG,SAAS,CAAC;aAClB,UAAK,GAAG,SAAS,CAAC;aAClB,SAAI,GAAG,QAAQ,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,UAAU;KAChB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAGH,qHAAqH;AACrH,MAAa,mBAAmB;aACd,aAAQ,GAA0B;QAChD,UAAU;QACV,wBAAwB;QACxB,sBAAsB;QACtB,iBAAiB;QACjB,mBAAmB;QACnB,YAAY;QACZ,QAAQ;QACR,eAAe;QACf,QAAQ;QACR,oBAAoB;QACpB,aAAa;QACb,WAAW;QACX,uBAAuB;KACxB,CAAC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,OAAO,CAAC,GAAG,CACT,uCAAuC,qBAAqB,CAAC,KAAK,4DAA4D,CAC/H,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;;AA1HH,0DA2HC","sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (for CI)\n --help print this text and exit\n\nWith no flag it lists what would change and writes nothing. Inside a git repository it reads the\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed, staged or untracked): commit or stash it first, so git can undo the codemod.`;\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\nconst CONNECTORS_PACKAGE = '@venizia/ignis-connectors';\nconst OLD_PREFIX = '@venizia/ignis/';\n\n/** The call names that take a module name as their first argument besides `require` and `import()`. */\nconst MODULE_NAME_CALLS = new Set([\n 'module',\n 'mock',\n 'doMock',\n 'unmock',\n 'importActual',\n 'requireActual',\n 'importMock',\n 'requireMock',\n]);\n\nclass ConnectorImportsFlags {\n static readonly WRITE = '--write';\n static readonly CHECK = '--check';\n static readonly HELP = '--help';\n static readonly HELP_SHORT = '-h';\n\n static readonly SCHEME_SET = new Set<string>([\n this.WRITE,\n this.CHECK,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** The removed `@venizia/ignis/<sub-path>` specifiers and the `@venizia/ignis-connectors/<sub-path>` they became. */\nexport class ConnectorSpecifiers {\n static readonly SUBPATHS: ReadonlyArray<string> = [\n 'postgres',\n 'postgres/node-postgres',\n 'postgres/postgres-js',\n 'postgres/pglite',\n 'postgres/supabase',\n 'relational',\n 'sqlite',\n 'sqlite/libsql',\n 'search',\n 'search/controllers',\n 'meilisearch',\n 'typesense',\n 'typesense/controllers',\n ];\n\n static readonly MOVES: ReadonlyMap<string, string> = new Map(\n ConnectorSpecifiers.SUBPATHS.map((subpath) => [\n `${OLD_PREFIX}${subpath}`,\n `${CONNECTORS_PACKAGE}/${subpath}`,\n ]),\n );\n}\n\nexport interface IConnectorImportsResult {\n output: string;\n changed: boolean;\n /** How many specifiers were moved. */\n rewritten: number;\n}\n\n/** Rewrites the module specifiers of the removed connector sub-paths. */\nexport class ConnectorImports {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n }): IConnectorImportsResult {\n const { typescript: ts, fileName, source } = opts;\n const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n\n const consider = (literal: import('typescript').Node | undefined) => {\n if (!literal || !ts.isStringLiteralLike(literal)) {\n return;\n }\n\n const moved = ConnectorSpecifiers.MOVES.get(literal.text);\n if (moved === undefined) {\n return;\n }\n\n const start = literal.getStart(file);\n const quote = source[start];\n edits.push({ start, end: literal.getEnd(), text: `${quote}${moved}${quote}` });\n };\n\n const isModuleNameCall = (call: import('typescript').CallExpression): boolean => {\n const callee = call.expression;\n\n if (callee.kind === ts.SyntaxKind.ImportKeyword) {\n return true;\n }\n\n if (ts.isIdentifier(callee)) {\n return callee.text === 'require';\n }\n\n if (!ts.isPropertyAccessExpression(callee)) {\n return false;\n }\n\n if (callee.name.text === 'resolve') {\n return (\n (ts.isIdentifier(callee.expression) && callee.expression.text === 'require') ||\n ts.isMetaProperty(callee.expression)\n );\n }\n\n return MODULE_NAME_CALLS.has(callee.name.text);\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {\n consider(node.moduleSpecifier);\n } else if (ts.isImportEqualsDeclaration(node)) {\n if (ts.isExternalModuleReference(node.moduleReference)) {\n consider(node.moduleReference.expression);\n }\n } else if (ts.isCallExpression(node)) {\n if (isModuleNameCall(node)) {\n consider(node.arguments[0]);\n }\n } else if (ts.isModuleDeclaration(node)) {\n consider(node.name);\n } else if (ts.isImportTypeNode(node)) {\n if (ts.isLiteralTypeNode(node.argument)) {\n consider(node.argument.literal);\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(file);\n\n if (edits.length === 0) {\n return { output: source, changed: false, rewritten: 0 };\n }\n\n let output = source;\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: true, rewritten: edits.length };\n }\n\n /**\n * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when\n * there is none to read.\n */\n static findManifest(opts: {\n file: string;\n root: string;\n }): { path: string; hasConnectors: boolean } | undefined {\n const { file, root } = opts;\n let directory = dirname(file);\n\n for (;;) {\n const candidate = join(directory, 'package.json');\n\n if (existsSync(candidate)) {\n let manifest: unknown;\n try {\n manifest = JSON.parse(readFileSync(candidate, 'utf8'));\n } catch (error) {\n console.warn(\n `${candidate} is not valid JSON, so its dependencies were not checked | ${error instanceof Error ? error.message : String(error)}`,\n );\n return undefined;\n }\n\n const listed =\n typeof manifest === 'object' &&\n manifest !== null &&\n ['dependencies', 'devDependencies', 'peerDependencies'].some((field) => {\n const group: unknown = Reflect.get(manifest, field);\n return typeof group === 'object' && group !== null && CONNECTORS_PACKAGE in group;\n });\n\n return { path: candidate, hasConnectors: listed };\n }\n\n if (directory === root || dirname(directory) === directory) {\n return undefined;\n }\n\n directory = dirname(directory);\n }\n }\n}\n\n/**\n * `devz codemod connector-imports [paths...] [--write | --check]`: moves the removed\n * `@venizia/ignis/<connector sub-path>` specifiers to `@venizia/ignis-connectors`. It is a dry run unless `--write`\n * is given. `--check` is the same dry run, and exits 1 while a file would change.\n */\nexport class ConnectorImportsCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (\n args.includes(ConnectorImportsFlags.HELP) ||\n args.includes(ConnectorImportsFlags.HELP_SHORT)\n ) {\n console.log(USAGE);\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n\n const unknown = flags.filter((flag) => !ConnectorImportsFlags.isValid(flag));\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(ConnectorImportsFlags.WRITE);\n const isCheck = flags.includes(ConnectorImportsFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${ConnectorImportsFlags.WRITE} and ${ConnectorImportsFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n return USAGE_ERROR_CODE;\n }\n\n let typescript: typeof import('typescript');\n try {\n const loaded = await import('typescript');\n typescript = loaded.default;\n } catch {\n console.error('devz codemod: the \"typescript\" package is required to read your sources');\n return 1;\n }\n\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n const missing = new Set<string>();\n let changedCount = 0;\n let specifierCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!source.includes(OLD_PREFIX)) {\n continue;\n }\n\n const result = ConnectorImports.rewrite({ typescript, fileName: file, source });\n\n if (!result.changed) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n if (dirty?.has(file)) {\n refusedCount += 1;\n console.warn(\n `refused ${shown} has local changes (commit or stash them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n specifierCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} specifier(s))`,\n );\n\n const manifest = ConnectorImports.findManifest({ file, root });\n if (manifest && !manifest.hasConnectors) {\n missing.add(relative(root, manifest.path).split('\\\\').join('/') || manifest.path);\n }\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod connector-imports: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${specifierCount} specifier(s) ${isWrite ? 'moved' : 'would be moved'}` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n for (const manifestPath of [...missing].sort()) {\n console.warn(\n `${manifestPath} does not list ${CONNECTORS_PACKAGE}: add it as a dependency, because the imports now come from it`,\n );\n }\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then add the dependency and run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && changedCount > 0 ? 1 : 0;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"const-classes.d.ts","sourceRoot":"","sources":["../../../src/cli/codemod/const-classes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,KAAK,WAAW,GAAG,OAAO,EAAE,CAAC;AAU7B,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,sBAAsB;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,oCAAoC;IACpC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,qGAAqG;IACrG,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,uDAAuD;IACvD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,mBAAmB,EAAE,CAAC;IAC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AAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,iBAAiB;IA4KrB,OAAO,CAAC,MAAM,CAAC,WAAW;IA8C1B,yDAAyD;IACzD,OAAO,CAAC,MAAM,CAAC,aAAa;IAoD5B,OAAO,CAAC,MAAM,CAAC,UAAU;IAQzB,iIAAiI;IACjI,OAAO,CAAC,MAAM,CAAC,SAAS;IA+BxB,gFAAgF;IAChF,OAAO,CAAC,MAAM,CAAC,YAAY;IAuB3B,OAAO,CAAC,MAAM,CAAC,SAAS;IAqCxB,OAAO,CAAC,MAAM,CAAC,WAAW;IAsB1B,sHAAsH;IACtH,OAAO,CAAC,MAAM,CAAC,UAAU;IAkCzB,OAAO,CAAC,MAAM,CAAC,QAAQ;IA2BvB,wJAAwJ;IACxJ,OAAO,CAAC,MAAM,CAAC,UAAU;CAqD1B;AA4DD,mEAAmE;AACnE,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,KAAK,yxDAAS;WAEjB,GAAG,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAuL1E"}
@@ -323,7 +323,6 @@ class ConstClasses {
323
323
  const { className, typeName, members } = opts;
324
324
  const quote = (value) => `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
325
325
  const lines = [
326
- `/** The values of \`${typeName}\`. */`,
327
326
  `export class ${className} {`,
328
327
  ...members.map(({ value, key }) => ` static readonly ${key} = ${quote(value)};`),
329
328
  '',