@lenne.tech/cli 1.11.0 → 1.12.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.
@@ -46,6 +46,7 @@ exports.Server = void 0;
46
46
  const crypto = __importStar(require("crypto"));
47
47
  const path_1 = require("path");
48
48
  const ts = __importStar(require("typescript"));
49
+ const markdown_table_1 = require("../lib/markdown-table");
49
50
  /**
50
51
  * Server helper functions
51
52
  */
@@ -749,6 +750,13 @@ class Server {
749
750
  catch (err) {
750
751
  return { method: result.method, path: dest, success: false };
751
752
  }
753
+ // Post-install format pass. processApiMode may have left whitespace
754
+ // artifacts (multi-line arrays/imports) that the formatter flags in
755
+ // format:check; oxfmt is only available after install, so we run it
756
+ // here.
757
+ if (apiMode) {
758
+ yield apiModeHelper.formatProject(dest);
759
+ }
752
760
  }
753
761
  return { method: result.method, path: dest, success: true };
754
762
  });
@@ -890,9 +898,11 @@ class Server {
890
898
  *
891
899
  * In vendor mode we additionally clone `@lenne.tech/nest-server` to
892
900
  * /tmp, copy its framework kernel (`src/core/`, `src/index.ts`,
893
- * `src/core.module.ts`, `src/test/`, `src/templates/`, `src/types/`,
894
- * `LICENSE`, `bin/migrate.js`) into the project at `src/core/`
895
- * applying the flatten-fix, remove `@lenne.tech/nest-server` from the
901
+ * `src/core.module.ts`, `src/test/`, `src/types/`, `LICENSE`,
902
+ * `bin/migrate.js`) into the project at `src/core/` applying the
903
+ * flatten-fix, place upstream `src/templates/` at `<project>/src/templates/`
904
+ * (outside core/ so the runtime resolver finds it at the same relative
905
+ * path as in npm mode), remove `@lenne.tech/nest-server` from the
896
906
  * project's `package.json`, merge the framework's transitive deps into
897
907
  * the project's own deps, and run an AST-based codemod that rewrites
898
908
  * every `from '@lenne.tech/nest-server'` import in consumer code
@@ -994,7 +1004,10 @@ class Server {
994
1004
  //
995
1005
  // Upstream layout: src/core/ (framework sub-dir) + src/index.ts +
996
1006
  // src/core.module.ts + src/test/ + src/templates/ + src/types/.
997
- // Target layout: everything flat under <project>/src/core/.
1007
+ // Target layout: most things flat under <project>/src/core/, with
1008
+ // one exception: src/templates/ stays at the same upstream location
1009
+ // (<project>/src/templates/) because the runtime email-template
1010
+ // resolver uses __dirname-relative lookup that must match npm mode.
998
1011
  //
999
1012
  // We WIPE the starter's (non-existent in npm mode) src/core/ first
1000
1013
  // just to guarantee idempotency when users run this twice.
@@ -1006,7 +1019,15 @@ class Server {
1006
1019
  [`${tmpClone}/src/index.ts`, `${coreDir}/index.ts`],
1007
1020
  [`${tmpClone}/src/core.module.ts`, `${coreDir}/core.module.ts`],
1008
1021
  [`${tmpClone}/src/test`, `${coreDir}/test`],
1009
- [`${tmpClone}/src/templates`, `${coreDir}/templates`],
1022
+ // src/templates/ stays OUTSIDE src/core/ at its upstream location so
1023
+ // the runtime template resolver (which computes
1024
+ // `__dirname + '../../../templates'` from within
1025
+ // src/core/modules/better-auth/) finds E-Mail templates at the same
1026
+ // relative path as in npm mode (node_modules/@lenne.tech/nest-server/
1027
+ // src/templates/). Keeping templates as first-class project files
1028
+ // outside core/ also lets projects customize them without touching
1029
+ // the vendored framework tree.
1030
+ [`${tmpClone}/src/templates`, `${dest}/src/templates`],
1010
1031
  [`${tmpClone}/src/types`, `${coreDir}/types`],
1011
1032
  [`${tmpClone}/LICENSE`, `${coreDir}/LICENSE`],
1012
1033
  ];
@@ -1395,14 +1416,14 @@ class Server {
1395
1416
  "var f=require('fs'),h=require('https');",
1396
1417
  "try{var c=f.readFileSync('src/core/VENDOR.md','utf8')}catch(e){process.exit(0)}",
1397
1418
  'var m=c.match(/Baseline-Version[^0-9]*(\\d+\\.\\d+\\.\\d+)/);',
1398
- 'if(!m){process.stderr.write(String.fromCharCode(9888)+\' vendor-freshness: no baseline\\n\');process.exit(0)}',
1419
+ "if(!m){process.stderr.write(String.fromCharCode(9888)+' vendor-freshness: no baseline\\n');process.exit(0)}",
1399
1420
  'var v=m[1];',
1400
1421
  "h.get('https://registry.npmjs.org/@lenne.tech/nest-server/latest',function(r){",
1401
1422
  "var d='';r.on('data',function(c){d+=c});r.on('end',function(){",
1402
- "try{var l=JSON.parse(d).version;",
1423
+ 'try{var l=JSON.parse(d).version;',
1403
1424
  "if(v===l)console.log('vendor core up-to-date (v'+v+')');",
1404
1425
  "else process.stderr.write('vendor core v'+v+', latest v'+l+'\\n')",
1405
- '}catch(e){}})}).on(\'error\',function(){});',
1426
+ "}catch(e){}})}).on('error',function(){});",
1406
1427
  'setTimeout(function(){process.exit(0)},5000)',
1407
1428
  '"',
1408
1429
  ].join('');
@@ -1417,7 +1438,8 @@ class Server {
1417
1438
  return;
1418
1439
  const installPrefix = 'pnpm install && ';
1419
1440
  if (existing.startsWith(installPrefix)) {
1420
- scripts[scriptName] = `${installPrefix}pnpm run check:vendor-freshness && ${existing.slice(installPrefix.length)}`;
1441
+ scripts[scriptName] =
1442
+ `${installPrefix}pnpm run check:vendor-freshness && ${existing.slice(installPrefix.length)}`;
1421
1443
  }
1422
1444
  else {
1423
1445
  scripts[scriptName] = `pnpm run check:vendor-freshness && ${existing}`;
@@ -1485,7 +1507,7 @@ class Server {
1485
1507
  ' * Vendor-mode stub for extras/sync-packages.mjs.',
1486
1508
  ' *',
1487
1509
  ' * The original script is designed for npm-mode projects where',
1488
- " * `@lenne.tech/nest-server` is an installed dependency and",
1510
+ ' * `@lenne.tech/nest-server` is an installed dependency and',
1489
1511
  ' * `pnpm run update` pulls the latest upstream deps into the',
1490
1512
  ' * project package.json.',
1491
1513
  ' *',
@@ -1547,7 +1569,7 @@ class Server {
1547
1569
  '',
1548
1570
  '- **Read framework code from `src/core/**`** — not from `node_modules/`.',
1549
1571
  '- **Generated imports use relative paths** to `src/core`, e.g.',
1550
- ' `import { CrudService } from \'../../../core\';`',
1572
+ " `import { CrudService } from '../../../core';`",
1551
1573
  ' The exact depth depends on the file location. `lt server module`',
1552
1574
  ' computes it automatically.',
1553
1575
  '- **Baseline + patch log** live in `src/core/VENDOR.md`. Log any',
@@ -1615,17 +1637,48 @@ class Server {
1615
1637
  '',
1616
1638
  'This directory is a curated vendor copy of the `core/` tree from',
1617
1639
  '@lenne.tech/nest-server. It is first-class project code, not a',
1618
- 'node_modules shadow copy. Edit freely; log substantial changes in',
1619
- 'the "Local changes" table below so the `nest-server-core-updater`',
1620
- 'agent can classify them at sync time.',
1640
+ 'node_modules shadow copy but it is **not a fork**. The copy',
1641
+ 'exists so Claude Code (and humans) can read framework internals',
1642
+ 'directly. Log substantial local changes in the "Local changes"',
1643
+ 'table below so the `nest-server-core-updater` agent can classify',
1644
+ 'them at sync time.',
1621
1645
  '',
1622
1646
  'The flatten-fix was applied during `lt fullstack init`: the',
1623
1647
  'upstream `src/index.ts`, `src/core.module.ts`, `src/test/`,',
1624
- '`src/templates/`, `src/types/`, and `LICENSE` were moved under',
1625
- '`src/core/` and their relative `./core/…` specifiers were',
1626
- 'stripped. See the init code in',
1648
+ '`src/types/`, and `LICENSE` were moved under `src/core/` and',
1649
+ 'their relative `./core/…` specifiers were stripped. The upstream',
1650
+ '`src/templates/` tree (E-Mail templates) was placed at the',
1651
+ 'project root `src/templates/` (outside `src/core/`) so the',
1652
+ 'runtime template resolver finds them at the same relative path',
1653
+ 'as in npm mode. See the init code in',
1627
1654
  '`lenneTech/cli/src/extensions/server.ts#convertCloneToVendored`.',
1628
1655
  '',
1656
+ '## Modification Policy',
1657
+ '',
1658
+ 'Edit `src/core/` **only** when the change is generally useful to every',
1659
+ '@lenne.tech/nest-server consumer:',
1660
+ '',
1661
+ '- Bugfixes that apply to every consumer',
1662
+ '- Broad framework enhancements',
1663
+ '- Security vulnerability fixes',
1664
+ '- Build/TypeScript compatibility fixes every consumer would hit',
1665
+ '',
1666
+ 'Everything else stays **outside** `src/core/`. Project-specific',
1667
+ 'business rules, customer enums, and proprietary integrations',
1668
+ 'belong in project code via modification, inheritance, extension,',
1669
+ 'or `ICoreModuleOverrides`.',
1670
+ '',
1671
+ 'Generally-useful changes **MUST** be submitted as an upstream PR',
1672
+ 'to https://github.com/lenneTech/nest-server. Run',
1673
+ '`/lt-dev:backend:contribute-nest-server-core` to prepare it — the',
1674
+ 'agent filters cosmetic commits, categorizes local changes as',
1675
+ 'upstream-candidate vs. project-specific, and writes PR drafts for',
1676
+ "human review. Letting useful fixes rot in one project's vendor",
1677
+ 'tree is an anti-pattern: they belong upstream so every consumer',
1678
+ 'benefits and the local patch disappears on the next sync.',
1679
+ '',
1680
+ 'When in doubt, ask before editing `src/core/`.',
1681
+ '',
1629
1682
  '## Baseline',
1630
1683
  '',
1631
1684
  '- **Upstream-Repo:** https://github.com/lenneTech/nest-server',
@@ -1636,22 +1689,15 @@ class Server {
1636
1689
  '',
1637
1690
  '## Sync history',
1638
1691
  '',
1639
- '| Date | From | To | Notes |',
1640
- '| ---- | ---- | -- | ----- |',
1641
- `| ${today} | — | ${syncHistoryTo} | scaffolded by lt CLI |`,
1692
+ ...(0, markdown_table_1.formatMarkdownTable)(['Date', 'From', 'To', 'Notes'], [[today, '—', syncHistoryTo, 'scaffolded by lt CLI']]),
1642
1693
  '',
1643
1694
  '## Local changes',
1644
1695
  '',
1645
- '| Date | Commit | Scope | Reason | Status |',
1646
- '| ---- | ------ | ----- | ------ | ------ |',
1647
- '| — | — | (none, pristine) | initial vendor | — |',
1696
+ ...(0, markdown_table_1.formatMarkdownTable)(['Date', 'Commit', 'Scope', 'Reason', 'Status'], [['—', '—', '(none, pristine)', 'initial vendor', '—']]),
1648
1697
  '',
1649
1698
  '## Upstream PRs',
1650
1699
  '',
1651
- '| PR | Title | Commits | Status |',
1652
- '| -- | ----- | ------- | ------ |',
1653
- '| — | (none yet) | — | — |',
1654
- '',
1700
+ ...(0, markdown_table_1.formatMarkdownTable)(['PR', 'Title', 'Commits', 'Status'], [['—', '(none yet)', '—', '—']]),
1655
1701
  ].join('\n'));
1656
1702
  }
1657
1703
  // ── Post-conversion verification ──────────────────────────────────────
@@ -1842,10 +1888,7 @@ class Server {
1842
1888
  if (!this.filesystem.exists(tsconfigPath)) {
1843
1889
  return;
1844
1890
  }
1845
- const EXCLUDE_ENTRIES = [
1846
- 'src/core/modules/migrate/templates/**/*.template.ts',
1847
- 'src/core/test/**/*.ts',
1848
- ];
1891
+ const EXCLUDE_ENTRIES = ['src/core/modules/migrate/templates/**/*.template.ts', 'src/core/test/**/*.ts'];
1849
1892
  try {
1850
1893
  // The upstream tsconfig files may contain comments — standard JSON parse
1851
1894
  // breaks on them. Use a regex-based patch as a fallback.
@@ -2080,9 +2123,7 @@ class Server {
2080
2123
  print.warning('');
2081
2124
  print.warning('⚠ VENDOR.md documents local patches in src/core/ that will be LOST:');
2082
2125
  // Extract non-header table rows
2083
- const rows = localChangesSection[0]
2084
- .split('\n')
2085
- .filter((l) => /^\|\s*\d{4}-/.test(l));
2126
+ const rows = localChangesSection[0].split('\n').filter((l) => /^\|\s*\d{4}-/.test(l));
2086
2127
  for (const row of rows.slice(0, 5)) {
2087
2128
  print.info(` ${row.trim()}`);
2088
2129
  }
@@ -2112,10 +2153,7 @@ class Server {
2112
2153
  for (const sourceFile of project.getSourceFiles()) {
2113
2154
  let modified = false;
2114
2155
  // Static imports + re-exports
2115
- for (const decl of [
2116
- ...sourceFile.getImportDeclarations(),
2117
- ...sourceFile.getExportDeclarations(),
2118
- ]) {
2156
+ for (const decl of [...sourceFile.getImportDeclarations(), ...sourceFile.getExportDeclarations()]) {
2119
2157
  const spec = decl.getModuleSpecifierValue();
2120
2158
  if (!spec)
2121
2159
  continue;
@@ -2182,7 +2220,8 @@ class Server {
2182
2220
  const migrateCompiler = 'ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js';
2183
2221
  const migrateStore = '--store ./migrations-utils/migrate.js --migrations-dir ./migrations';
2184
2222
  const migrateTemplate = './node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/templates/migration-project.template.ts';
2185
- scripts['migrate:create'] = `f() { migrate create "$1" --template-file ${migrateTemplate} --migrations-dir ./migrations --compiler ${migrateCompiler}; }; f`;
2223
+ scripts['migrate:create'] =
2224
+ `f() { migrate create "$1" --template-file ${migrateTemplate} --migrations-dir ./migrations --compiler ${migrateCompiler}; }; f`;
2186
2225
  scripts['migrate:up'] = `migrate up ${migrateStore} --compiler ${migrateCompiler}`;
2187
2226
  scripts['migrate:down'] = `migrate down ${migrateStore} --compiler ${migrateCompiler}`;
2188
2227
  scripts['migrate:list'] = `migrate list ${migrateStore} --compiler ${migrateCompiler}`;
@@ -2262,8 +2301,7 @@ class Server {
2262
2301
  let content = filesystem.read(gitignorePath) || '';
2263
2302
  content = content
2264
2303
  .split('\n')
2265
- .filter((line) => !line.includes('scripts/vendor/sync-results') &&
2266
- !line.includes('scripts/vendor/upstream-candidates'))
2304
+ .filter((line) => !line.includes('scripts/vendor/sync-results') && !line.includes('scripts/vendor/upstream-candidates'))
2267
2305
  .join('\n');
2268
2306
  filesystem.write(gitignorePath, content);
2269
2307
  }
@@ -2279,7 +2317,7 @@ class Server {
2279
2317
  for (const f of staleRelativeImports.slice(0, 10)) {
2280
2318
  print.info(` ${f}`);
2281
2319
  }
2282
- print.info('These imports must be manually rewritten to \'@lenne.tech/nest-server\'.');
2320
+ print.info("These imports must be manually rewritten to '@lenne.tech/nest-server'.");
2283
2321
  }
2284
2322
  });
2285
2323
  }
@@ -81,8 +81,7 @@ function findAppDir(startDir) {
81
81
  let current = path.resolve(startDir);
82
82
  const root = path.parse(current).root;
83
83
  while (current !== root) {
84
- if ((0, node_fs_1.existsSync)(path.join(current, 'nuxt.config.ts')) ||
85
- (0, node_fs_1.existsSync)(path.join(current, 'nuxt.config.js'))) {
84
+ if ((0, node_fs_1.existsSync)(path.join(current, 'nuxt.config.ts')) || (0, node_fs_1.existsSync)(path.join(current, 'nuxt.config.js'))) {
86
85
  return current;
87
86
  }
88
87
  current = path.dirname(current);
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hoistWorkspacePnpmConfig = hoistWorkspacePnpmConfig;
4
+ /**
5
+ * pnpm workspace-scoped fields that must live at the workspace root.
6
+ * When present in sub-project package.json files, pnpm emits:
7
+ *
8
+ * WARN The field "<field>" was found in <path>. This will not take
9
+ * effect. You should configure "<field>" at the root of the workspace
10
+ * instead.
11
+ *
12
+ * Crucially, the WARN also means the values are silently ignored — CVE
13
+ * overrides defined only in projects/api/package.json never reach the
14
+ * install resolver. Hoisting them to the root fixes both the warning
15
+ * and the actual dependency-resolution behavior.
16
+ */
17
+ const WORKSPACE_SCOPED_PNPM_FIELDS = ['overrides', 'onlyBuiltDependencies', 'ignoredOptionalDependencies'];
18
+ /**
19
+ * Hoist workspace-scoped pnpm config from sub-projects into the root
20
+ * package.json. After this runs, sub-project package.json files no
21
+ * longer have `overrides`, `onlyBuiltDependencies`, or
22
+ * `ignoredOptionalDependencies`, and the root package.json contains
23
+ * the merged union.
24
+ *
25
+ * Idempotent: running twice has the same effect as running once.
26
+ *
27
+ * @param options.filesystem Gluegun filesystem tool
28
+ * @param options.projectDir Workspace root (contains pnpm-workspace.yaml)
29
+ * @param options.subProjects Sub-project dirs relative to projectDir
30
+ */
31
+ function hoistWorkspacePnpmConfig(options) {
32
+ var _a;
33
+ const { filesystem, projectDir, subProjects } = options;
34
+ const rootPkgPath = `${projectDir}/package.json`;
35
+ if (!filesystem.exists(rootPkgPath))
36
+ return;
37
+ const rootPkg = filesystem.read(rootPkgPath, 'json');
38
+ if (!rootPkg)
39
+ return;
40
+ (_a = rootPkg.pnpm) !== null && _a !== void 0 ? _a : (rootPkg.pnpm = {});
41
+ let rootChanged = false;
42
+ for (const subDir of subProjects) {
43
+ const subPkgPath = `${projectDir}/${subDir}/package.json`;
44
+ if (!filesystem.exists(subPkgPath))
45
+ continue;
46
+ const subPkg = filesystem.read(subPkgPath, 'json');
47
+ if (!(subPkg === null || subPkg === void 0 ? void 0 : subPkg.pnpm))
48
+ continue;
49
+ let subChanged = false;
50
+ for (const field of WORKSPACE_SCOPED_PNPM_FIELDS) {
51
+ const subValue = subPkg.pnpm[field];
52
+ if (subValue === undefined)
53
+ continue;
54
+ rootPkg.pnpm[field] = mergePnpmFieldValue(field, rootPkg.pnpm[field], subValue);
55
+ rootChanged = true;
56
+ delete subPkg.pnpm[field];
57
+ subChanged = true;
58
+ }
59
+ if (subChanged) {
60
+ // If the sub-project's pnpm section is now empty, drop it entirely.
61
+ if (subPkg.pnpm && Object.keys(subPkg.pnpm).length === 0) {
62
+ delete subPkg.pnpm;
63
+ }
64
+ filesystem.write(subPkgPath, `${JSON.stringify(subPkg, null, 2)}\n`);
65
+ }
66
+ }
67
+ if (rootChanged) {
68
+ filesystem.write(rootPkgPath, `${JSON.stringify(rootPkg, null, 2)}\n`);
69
+ }
70
+ }
71
+ /**
72
+ * Merge two values for a pnpm workspace-scoped field.
73
+ *
74
+ * pnpm expects:
75
+ * - `overrides` → object ({pkg: version})
76
+ * - `onlyBuiltDependencies` → array of strings
77
+ * - `ignoredOptionalDependencies` → array of strings
78
+ *
79
+ * Arrays: deduplicated, alphabetically sorted union.
80
+ * Objects: sub-project values take precedence over root (sub-projects
81
+ * like nest-server-starter own the authoritative CVE override list for
82
+ * their transitive deps; the root usually only seeds cross-cutting
83
+ * handlebars/minimatch patches).
84
+ */
85
+ function mergePnpmFieldValue(field, rootValue, subValue) {
86
+ if (field === 'onlyBuiltDependencies' || field === 'ignoredOptionalDependencies') {
87
+ const rootArr = Array.isArray(rootValue) ? rootValue : [];
88
+ const subArr = Array.isArray(subValue) ? subValue : [];
89
+ return Array.from(new Set([...rootArr, ...subArr])).sort((a, b) => a.localeCompare(b));
90
+ }
91
+ const rootObj = rootValue && typeof rootValue === 'object' && !Array.isArray(rootValue)
92
+ ? rootValue
93
+ : {};
94
+ const subObj = subValue && typeof subValue === 'object' && !Array.isArray(subValue) ? subValue : {};
95
+ const merged = Object.assign(Object.assign({}, rootObj), subObj);
96
+ return Object.fromEntries(Object.entries(merged).sort(([a], [b]) => a.localeCompare(b)));
97
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMarkdownTable = formatMarkdownTable;
4
+ /**
5
+ * Build an oxfmt-compatible Markdown table with padded columns so that the
6
+ * generated file passes `oxfmt --check` without a reformat pass.
7
+ *
8
+ * Column width = max(header length, longest cell length, 3). Cells are
9
+ * padded with trailing spaces; the separator row uses `-` characters of
10
+ * the same width.
11
+ *
12
+ * Character width note: uses JavaScript `.length` (UTF-16 code units),
13
+ * which matches oxfmt's own accounting for typical BMP characters used
14
+ * in VENDOR.md generation (em-dash `—`, backticks, version strings).
15
+ *
16
+ * @param headers Column headers (top row)
17
+ * @param rows Data rows; each row must have `headers.length` cells
18
+ * @returns Lines ready to concatenate with `\n`
19
+ */
20
+ function formatMarkdownTable(headers, rows) {
21
+ const columnCount = headers.length;
22
+ const widths = headers.map((h, i) => {
23
+ const cellMax = rows.reduce((max, row) => { var _a; return Math.max(max, ((_a = row[i]) !== null && _a !== void 0 ? _a : '').length); }, 0);
24
+ return Math.max(h.length, cellMax, 3);
25
+ });
26
+ const formatRow = (cells) => `| ${cells.map((cell, i) => cell.padEnd(widths[i])).join(' | ')} |`;
27
+ const lines = [formatRow(headers), `| ${widths.map((w) => '-'.repeat(w)).join(' | ')} |`];
28
+ for (const row of rows) {
29
+ const padded = Array.from({ length: columnCount }, (_, i) => { var _a; return (_a = row[i]) !== null && _a !== void 0 ? _a : ''; });
30
+ lines.push(formatRow(padded));
31
+ }
32
+ return lines;
33
+ }