@specdest/devkit 0.4.15 → 0.4.16

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/dist/npm/cli.js CHANGED
@@ -5,7 +5,9 @@ import { runSupabaseLocal } from "./supabase-local.js";
5
5
  import { sendSlackFiles } from "./slack.js";
6
6
  import { runHostAutomation } from "./host-automation.js";
7
7
  import { runSnapshot } from "./snapshot-cli.js";
8
+ import { assertStandaloneDevkit } from "./project-install-guard.js";
8
9
  try {
10
+ assertStandaloneDevkit();
9
11
  const exitCode = await runCli(process.argv.slice(2), process, {
10
12
  ...createCanonicalCommandHandlers(),
11
13
  flow: createFlowCommandHandler(),
@@ -0,0 +1,2 @@
1
+ /** Reject project dependency declarations without blocking standalone CLI use. */
2
+ export declare function assertStandaloneDevkit(cwd?: string): void;
@@ -0,0 +1,51 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join, parse, resolve } from 'node:path';
3
+ const PACKAGE = '@specdest/devkit';
4
+ const DEPENDENCY_FIELDS = [
5
+ 'dependencies',
6
+ 'devDependencies',
7
+ 'optionalDependencies',
8
+ 'peerDependencies',
9
+ ];
10
+ /** Reject project dependency declarations without blocking standalone CLI use. */
11
+ export function assertStandaloneDevkit(cwd = process.cwd()) {
12
+ let current = resolve(cwd);
13
+ while (true) {
14
+ const manifest = join(current, 'package.json');
15
+ let source;
16
+ try {
17
+ source = readFileSync(manifest, 'utf8');
18
+ }
19
+ catch (error) {
20
+ if (error.code !== 'ENOENT')
21
+ throw error;
22
+ source = '';
23
+ }
24
+ if (source) {
25
+ const packageJson = JSON.parse(source);
26
+ if (packageJson && typeof packageJson === 'object') {
27
+ const fields = packageJson;
28
+ // Devkit's own checkout is not a consuming project.
29
+ if (fields.name === PACKAGE)
30
+ return;
31
+ if (DEPENDENCY_FIELDS.some((field) => {
32
+ const dependencies = fields[field];
33
+ return (dependencies &&
34
+ typeof dependencies === 'object' &&
35
+ Object.hasOwn(dependencies, PACKAGE));
36
+ })) {
37
+ throw new Error(`ERROR: ${PACKAGE} must not be installed as a project dependency.\n\n` +
38
+ `Remove it: pnpm remove -D ${PACKAGE}\n` +
39
+ `Install globally: pnpm add -g ${PACKAGE}\n` +
40
+ `Then run: specdest <command>\n` +
41
+ `(Project: ${manifest})`);
42
+ }
43
+ }
44
+ // The closest package manifest defines the current project boundary.
45
+ return;
46
+ }
47
+ if (current === parse(current).root)
48
+ return;
49
+ current = dirname(current);
50
+ }
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.4.15",
3
+ "version": "0.4.16",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "dist/npm/cli.js"