@kabran-tecnologia/kabran-config 2.1.0 → 2.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabran-tecnologia/kabran-config",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Shared quality configurations, enforcement scripts, and CI/CD tooling for Kabran projects",
5
5
  "author": "Kabran",
6
6
  "license": "MIT",
@@ -5,8 +5,9 @@
5
5
  * Enables projects to customize validator behavior without modifying kabran-config.
6
6
  *
7
7
  * Features:
8
- * - Smart detection of tools (ESLint, TypeScript, Prettier, Vitest, Playwright)
8
+ * - Smart detection of tools (ESLint, TypeScript, Prettier, Vitest, Playwright, Turbo)
9
9
  * - Automatic Doppler integration for secrets injection in tests
10
+ * - Native support for Turbo monorepos (auto-detects turbo.json)
10
11
  * - Convention over configuration - works out of the box
11
12
  *
12
13
  * @module config-loader
@@ -45,6 +46,7 @@ const TOOL_CONFIGS = {
45
46
  prettier: ['prettier.config.mjs', 'prettier.config.js', '.prettierrc', '.prettierrc.json', '.prettierrc.js'],
46
47
  vitest: ['vitest.config.ts', 'vitest.config.mts', 'vitest.config.js', 'vitest.config.mjs'],
47
48
  playwright: ['playwright.config.ts', 'playwright.config.js'],
49
+ turbo: ['turbo.json'],
48
50
  };
49
51
 
50
52
  /**
@@ -59,10 +61,27 @@ function hasToolConfig(cwd, configFiles) {
59
61
 
60
62
  /**
61
63
  * Check if Doppler is configured for the current directory.
64
+ *
65
+ * Detection methods (in order of reliability):
66
+ * 1. DOPPLER_TOKEN environment variable is set
67
+ * 2. doppler.yaml exists in the project
68
+ * 3. doppler configure get token returns a value (CLI-level config)
69
+ *
62
70
  * @param {string} cwd - Working directory
63
- * @returns {boolean} True if Doppler token is configured
71
+ * @returns {boolean} True if Doppler is available
64
72
  */
65
73
  function hasDopplerConfigured(cwd) {
74
+ // Method 1: Environment variable (most common in CI/CD and scoped setups)
75
+ if (process.env.DOPPLER_TOKEN) {
76
+ return true;
77
+ }
78
+
79
+ // Method 2: doppler.yaml in project (common for project-level config)
80
+ if (existsSync(join(cwd, 'doppler.yaml'))) {
81
+ return true;
82
+ }
83
+
84
+ // Method 3: CLI-level configuration (doppler setup was run)
66
85
  try {
67
86
  const result = execSync('doppler configure get token', {
68
87
  cwd,
@@ -72,7 +91,18 @@ function hasDopplerConfigured(cwd) {
72
91
  });
73
92
  return result.trim().length > 0;
74
93
  } catch {
75
- return false;
94
+ // Method 4: Try doppler secrets as last resort (validates full setup)
95
+ try {
96
+ execSync('doppler secrets --only-names', {
97
+ cwd,
98
+ stdio: 'pipe',
99
+ encoding: 'utf-8',
100
+ timeout: 10000,
101
+ });
102
+ return true;
103
+ } catch {
104
+ return false;
105
+ }
76
106
  }
77
107
  }
78
108
 
@@ -89,6 +119,15 @@ export function wrapWithDoppler(cmd, useDoppler) {
89
119
  /**
90
120
  * Detect available tools and generate smart defaults.
91
121
  * Only configures commands for tools that are actually set up in the project.
122
+ *
123
+ * Turbo monorepo support:
124
+ * - When turbo.json is detected, commands delegate to `turbo run` for:
125
+ * - Lint: `turbo run lint`
126
+ * - Types: `turbo run type-check`
127
+ * - Tests: `turbo run test`
128
+ * - Build: `turbo run build`
129
+ * - This ensures proper monorepo handling with caching and workspace orchestration.
130
+ *
92
131
  * @param {string} cwd - Working directory
93
132
  * @returns {object} Detected defaults for CLI commands
94
133
  */
@@ -98,10 +137,76 @@ export function detectToolDefaults(cwd) {
98
137
  test: {},
99
138
  build: {},
100
139
  ci: { steps: [] },
140
+ turbo: false,
101
141
  };
102
142
 
103
143
  const hasDoppler = hasDopplerConfigured(cwd);
144
+ const hasTurbo = hasToolConfig(cwd, TOOL_CONFIGS.turbo);
145
+
146
+ // Store turbo detection result for consumers
147
+ defaults.turbo = hasTurbo;
148
+
149
+ // Turbo monorepo mode: delegate to turbo run commands
150
+ if (hasTurbo) {
151
+ return detectTurboDefaults(defaults, hasDoppler);
152
+ }
153
+
154
+ // Standard single-package mode: use direct tool commands
155
+ return detectStandardDefaults(cwd, defaults, hasDoppler);
156
+ }
104
157
 
158
+ /**
159
+ * Generate defaults for Turbo monorepo projects.
160
+ * Uses `turbo run` commands for all operations.
161
+ * @param {object} defaults - Base defaults object
162
+ * @param {boolean} hasDoppler - Whether Doppler is configured
163
+ * @returns {object} Turbo-specific defaults
164
+ */
165
+ function detectTurboDefaults(defaults, hasDoppler) {
166
+ // L1: Static Analysis via Turbo
167
+ defaults.check.lint = 'turbo run lint';
168
+ defaults.check.types = 'turbo run type-check';
169
+ defaults.check.format = 'turbo run format:check';
170
+
171
+ // L2: Unit Tests via Turbo (with Doppler support)
172
+ const testCmd = 'turbo run test';
173
+ defaults.test.unit = {
174
+ command: wrapWithDoppler(testCmd, hasDoppler),
175
+ doppler: hasDoppler,
176
+ };
177
+
178
+ // L3: Integration Tests via Turbo (with Doppler support)
179
+ const integrationCmd = 'turbo run test:integration';
180
+ defaults.test.integration = {
181
+ command: wrapWithDoppler(integrationCmd, hasDoppler),
182
+ doppler: hasDoppler,
183
+ };
184
+
185
+ // L4: E2E Tests via Turbo (with Doppler support)
186
+ const e2eCmd = 'turbo run test:e2e';
187
+ defaults.test.e2e = {
188
+ command: wrapWithDoppler(e2eCmd, hasDoppler),
189
+ doppler: hasDoppler,
190
+ };
191
+
192
+ // Build via Turbo
193
+ defaults.build.command = 'turbo run build';
194
+
195
+ // CI steps for Turbo projects
196
+ defaults.ci.steps = ['check', 'test:unit', 'build'];
197
+
198
+ return defaults;
199
+ }
200
+
201
+ /**
202
+ * Generate defaults for standard single-package projects.
203
+ * Uses direct tool commands (npx eslint, npx tsc, etc).
204
+ * @param {string} cwd - Working directory
205
+ * @param {object} defaults - Base defaults object
206
+ * @param {boolean} hasDoppler - Whether Doppler is configured
207
+ * @returns {object} Standard project defaults
208
+ */
209
+ function detectStandardDefaults(cwd, defaults, hasDoppler) {
105
210
  // L1: Static Analysis
106
211
  if (hasToolConfig(cwd, TOOL_CONFIGS.eslint)) {
107
212
  defaults.check.lint = 'npx eslint .';