@apso/cli 0.41.0 → 0.41.2

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.
@@ -10,6 +10,7 @@ const interactive_1 = require("../lib/utils/interactive");
10
10
  const perf_hooks_1 = require("perf_hooks");
11
11
  const file_system_1 = require("../lib/utils/file-system");
12
12
  const git_hooks_1 = require("../lib/utils/git-hooks");
13
+ const crud_deps_1 = require("../lib/utils/crud-deps");
13
14
  class Generate extends base_command_1.default {
14
15
  async run() {
15
16
  var _a, _b;
@@ -240,6 +241,15 @@ class Generate extends base_command_1.default {
240
241
  else if (generatedFileCount === 0) {
241
242
  console.log("[apso] Skipping formatting (no files were generated)");
242
243
  }
244
+ // Generated TS code imports @apso/crud*. Projects from the v1 template
245
+ // (@nestjsx/crud) don't declare those, and every entity then fails to
246
+ // compile with TS2307. Declare them so the next install picks them up.
247
+ if (language === "typescript" && generatedFileCount > 0) {
248
+ const added = (0, crud_deps_1.ensureCrudDeps)(process.cwd());
249
+ if (added.length > 0) {
250
+ console.log(`[apso] Added ${added.join(", ")} to package.json (the generated code imports them). Run npm install before building.`);
251
+ }
252
+ }
243
253
  const totalBuildTime = perf_hooks_1.performance.now() - totalBuildStart;
244
254
  console.log(`[apso] Finished building all entities in ${totalBuildTime.toFixed(2)} ms`);
245
255
  // Best-effort: install the commit co-author hook so commits that include
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runtime packages the generated TypeScript code imports (entities, services,
3
+ * controllers, guards). Versions match the pinned service-template-ts tag
4
+ * (see TEMPLATE_REFS in ./template.ts); bump both together.
5
+ */
6
+ export declare const APSO_CRUD_DEPS: Record<string, string>;
7
+ /**
8
+ * Add any missing @apso/crud runtime packages to the project's package.json.
9
+ *
10
+ * Projects created from the v1 template (@nestjsx/crud) don't declare them, so
11
+ * freshly generated code fails `nest build` with TS2307 "Cannot find module
12
+ * '@apso/crud'" on every entity. Existing @nestjsx deps are left alone because
13
+ * hand-written code may still import them.
14
+ *
15
+ * @param {string} projectDir - Directory holding the project's package.json.
16
+ * @returns {string[]} Names added (empty when nothing changed or no package.json).
17
+ */
18
+ export declare function ensureCrudDeps(projectDir: string): string[];
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureCrudDeps = exports.APSO_CRUD_DEPS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ /**
8
+ * Runtime packages the generated TypeScript code imports (entities, services,
9
+ * controllers, guards). Versions match the pinned service-template-ts tag
10
+ * (see TEMPLATE_REFS in ./template.ts); bump both together.
11
+ */
12
+ exports.APSO_CRUD_DEPS = {
13
+ "@apso/crud": "^1.0.1",
14
+ "@apso/crud-core": "^1.0.1",
15
+ "@apso/crud-request": "^1.0.1",
16
+ "@apso/crud-typeorm": "^1.0.1",
17
+ };
18
+ /**
19
+ * Add any missing @apso/crud runtime packages to the project's package.json.
20
+ *
21
+ * Projects created from the v1 template (@nestjsx/crud) don't declare them, so
22
+ * freshly generated code fails `nest build` with TS2307 "Cannot find module
23
+ * '@apso/crud'" on every entity. Existing @nestjsx deps are left alone because
24
+ * hand-written code may still import them.
25
+ *
26
+ * @param {string} projectDir - Directory holding the project's package.json.
27
+ * @returns {string[]} Names added (empty when nothing changed or no package.json).
28
+ */
29
+ function ensureCrudDeps(projectDir) {
30
+ var _a;
31
+ const pkgPath = path.join(projectDir, "package.json");
32
+ if (!fs.existsSync(pkgPath))
33
+ return [];
34
+ const raw = fs.readFileSync(pkgPath, "utf8");
35
+ const pkg = JSON.parse(raw);
36
+ const declared = { ...pkg.devDependencies, ...pkg.dependencies };
37
+ const missing = Object.keys(exports.APSO_CRUD_DEPS).filter((name) => !declared[name]);
38
+ if (missing.length === 0)
39
+ return [];
40
+ pkg.dependencies = (_a = pkg.dependencies) !== null && _a !== void 0 ? _a : {};
41
+ for (const name of missing)
42
+ pkg.dependencies[name] = exports.APSO_CRUD_DEPS[name];
43
+ pkg.dependencies = Object.fromEntries(Object.entries(pkg.dependencies).sort(([a], [b]) => a.localeCompare(b)));
44
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + (raw.endsWith("\n") ? "\n" : ""));
45
+ return missing;
46
+ }
47
+ exports.ensureCrudDeps = ensureCrudDeps;
@@ -42,6 +42,7 @@ export interface CheckResult {
42
42
  ok: boolean;
43
43
  steps: Step[];
44
44
  }
45
+ export declare function supportsPglite(projectDir: string): boolean;
45
46
  /**
46
47
  * Run a migration on a fresh copy of the deployed schema, then check that the
47
48
  * database matches the project's entities (a second generate finds nothing).
@@ -6,7 +6,7 @@
6
6
  * the CLI in a WebContainer) share these steps.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.report = exports.cliBinPath = exports.smokeTest = exports.verifyMigration = exports.generateMigration = exports.buildBaseline = exports.pgliteEnv = exports.run = void 0;
9
+ exports.report = exports.cliBinPath = exports.smokeTest = exports.verifyMigration = exports.supportsPglite = exports.generateMigration = exports.buildBaseline = exports.pgliteEnv = exports.run = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const child_process_1 = require("child_process");
12
12
  const fs = tslib_1.__importStar(require("fs"));
@@ -133,11 +133,37 @@ ds.initialize()
133
133
  .then((ran) => { console.log("ran " + ran.map((m) => m.name).join(", ")); return ds.destroy(); })
134
134
  .catch((e) => { console.error(e && e.message ? e.message : e); process.exit(1); });
135
135
  `;
136
+ /**
137
+ * Projects from the v1 template have no PGlite support in src/orm.config.ts,
138
+ * so the checks cannot run locally. They pass as skipped rather than block a
139
+ * deploy they cannot judge.
140
+ */
141
+ const NO_PGLITE = {
142
+ ok: true,
143
+ steps: [
144
+ {
145
+ name: "skipped",
146
+ ok: true,
147
+ output: "This project's database config (src/orm.config.ts) can't use a local PGlite database, so this check was skipped. Projects created from the current template support it.",
148
+ },
149
+ ],
150
+ };
151
+ function supportsPglite(projectDir) {
152
+ try {
153
+ return /typeorm-pglite|PGliteDriver/.test(fs.readFileSync(path.join(projectDir, "src", "orm.config.ts"), "utf8"));
154
+ }
155
+ catch {
156
+ return false;
157
+ }
158
+ }
159
+ exports.supportsPglite = supportsPglite;
136
160
  /**
137
161
  * Run a migration on a fresh copy of the deployed schema, then check that the
138
162
  * database matches the project's entities (a second generate finds nothing).
139
163
  */
140
164
  async function verifyMigration(projectDir, baselineApsorc, migrationFile, cliBin, skipBuild = false) {
165
+ if (!supportsPglite(projectDir))
166
+ return NO_PGLITE;
141
167
  const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "apso-pglite-"));
142
168
  const steps = [];
143
169
  const done = (s) => {
@@ -193,6 +219,8 @@ const get = (url) => new Promise((resolve) => {
193
219
  */
194
220
  async function smokeTest(projectDir, entityNames, { skipBuild = false, timeoutMs = 60000 } = {}) {
195
221
  var _a, _b;
222
+ if (!supportsPglite(projectDir))
223
+ return NO_PGLITE;
196
224
  const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "apso-pglite-"));
197
225
  const steps = [];
198
226
  const done = (s) => {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.41.0",
3
+ "version": "0.41.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@apso/cli",
9
- "version": "0.41.0",
9
+ "version": "0.41.2",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@apso/schema-tools": "^0.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.41.0",
2
+ "version": "0.41.2",
3
3
  "commands": {
4
4
  "config": {
5
5
  "id": "config",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.41.0",
3
+ "version": "0.41.2",
4
4
  "mcpName": "io.github.apsoai/apso",
5
5
  "description": "Apso CLI",
6
6
  "author": "Apso by Mavric - @mavric",