Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 2a4d6be

Browse files
flyingrobotsclaude
andcommitted
feat: Complete ESM migration for all CLI commands (P1.T010)
Massive parallel ESM conversion - 28 files transformed from CommonJS to pure ES modules: Database Commands: - Converted QueryCommand, ResetCommand to ESM - Migrated all 10 migrate subcommands (clean, generate, history, promote, rollback, squash, status, test, test-v2, verify) - Added proper handler exports for router integration Function Commands: - DeployCommand, StatusCommand, ValidateCommand converted to ESM - InitCommand migrated with proper imports Test Commands: - 7 test commands converted (Compile, Coverage, DevCycle, Generate, GenerateTemplate, Validate, Watch) - Dynamic imports for conditional loading - Proper .js extensions on all imports Library Classes: - Command.js fixed event imports - SupabaseTestCommand, BuildCommand, CommandRouter converted - All base classes now pure ESM Technical improvements: - All require() → import statements - All module.exports → export default - Added .js extensions to relative imports - Converted to async/await patterns where applicable - Zero CommonJS artifacts remaining in main codebase This completes P1.T010 - the entire CLI is now running on pure ES modules! 🖖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent e86c7ab commit 2a4d6be

28 files changed

+383
-184
lines changed

starfleet/data-cli/src/commands/InitCommand.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const fs = require('fs/promises');
2-
const path = require('path');
3-
const Command = require('../lib/Command.js');
1+
import fs from 'fs/promises';
2+
import path from 'path';
3+
import Command from '../lib/Command.js';
44

55
class InitCommand extends Command {
66
constructor(options = {}) {
@@ -133,4 +133,4 @@ CREATE POLICY "Allow public read" ON public.maintenance_mode
133133
}
134134
}
135135

136-
module.exports = InitCommand;
136+
export default InitCommand;

starfleet/data-cli/src/commands/db/QueryCommand.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
* Database Query Command
33
*/
44

5-
const fs = require('fs').promises;
6-
const { Client } = require('pg');
7-
const DatabaseCommand = require('../../lib/DatabaseCommand');
5+
import { promises as fs } from 'fs';
6+
import { Client } from 'pg';
7+
import DatabaseCommand from '../../lib/DatabaseCommand.js';
88

99
/**
1010
* Execute SQL queries against the database
11+
* @class
1112
*/
1213
class QueryCommand extends DatabaseCommand {
1314
constructor(databaseUrl, serviceRoleKey = null, anonKey = null, logger = null, isProd = false) {
@@ -125,4 +126,5 @@ class QueryCommand extends DatabaseCommand {
125126
}
126127
}
127128

128-
module.exports = QueryCommand;
129+
export { QueryCommand };
130+
export default QueryCommand;

starfleet/data-cli/src/commands/db/ResetCommand.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* Database Reset Command
33
*/
44

5-
const { exec } = require('child_process');
6-
const { promisify } = require('util');
7-
const DatabaseCommand = require('../../lib/DatabaseCommand');
5+
import { exec } from 'child_process';
6+
import { promisify } from 'util';
7+
import DatabaseCommand from '../../lib/DatabaseCommand.js';
88

99
const execAsync = promisify(exec);
1010

1111
/**
1212
* Reset database command
13+
* @class
1314
*/
1415
class ResetCommand extends DatabaseCommand {
1516
constructor(databaseUrl, serviceRoleKey = null, anonKey = null, logger = null, isProd = false) {
@@ -93,4 +94,5 @@ class ResetCommand extends DatabaseCommand {
9394
}
9495
}
9596

96-
module.exports = ResetCommand;
97+
export { ResetCommand };
98+
export default ResetCommand;

starfleet/data-cli/src/commands/db/migrate/clean.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* Migration Clean Command
33
*/
44

5-
const Command = require('../../../lib/Command');
6-
const fs = require('fs').promises;
7-
const path = require('path');
5+
import Command from '../../../lib/Command.js';
6+
import { promises as fs } from 'fs';
7+
import path from 'path';
88

99
/**
1010
* Clean up temporary migration files and staging directories
1111
*/
12+
/**
13+
* @class
14+
*/
1215
class MigrateCleanCommand extends Command {
1316
static description = 'Clean up temporary migration files';
1417

@@ -283,4 +286,17 @@ class MigrateCleanCommand extends Command {
283286
}
284287
}
285288

286-
module.exports = MigrateCleanCommand;
289+
/**
290+
* Migration clean handler
291+
* @param {Object} args - Command arguments
292+
* @param {Object} config - Configuration object
293+
* @param {Object} logger - Logger instance
294+
* @param {boolean} isProd - Production flag
295+
* @returns {Promise<Object>} Clean result
296+
*/
297+
export default async function cleanHandler(args, config, logger, isProd) {
298+
const command = new MigrateCleanCommand(config, logger, isProd);
299+
return await command.performExecute(args);
300+
}
301+
302+
export { MigrateCleanCommand };

starfleet/data-cli/src/commands/db/migrate/generate.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const Command = require('../../../lib/Command');
2-
const MigrationMetadata = require('../../../lib/MigrationMetadata');
3-
const fs = require('fs').promises;
4-
const path = require('path');
1+
import Command from '../../../lib/Command.js';
2+
import MigrationMetadata from '../../../lib/MigrationMetadata.js';
3+
import { promises as fs } from 'fs';
4+
import path from 'path';
55

66
/**
77
* MigrateGenerateCommand - Generate migration from schema diff
@@ -15,6 +15,7 @@ const path = require('path');
1515
* --dry-run Show diff without saving migration
1616
* --current-db <url> Current database URL (defaults to local)
1717
* --desired-db <url> Desired database URL (defaults to compiled SQL)
18+
* @class
1819
*/
1920
class MigrateGenerateCommand extends Command {
2021
static description = 'Generate migration from schema diff';
@@ -359,4 +360,17 @@ INSERT INTO example_table (name) VALUES ('test_data');
359360
}
360361
}
361362

362-
module.exports = MigrateGenerateCommand;
363+
/**
364+
* Generate migration from schema diff handler
365+
* @param {Object} args - Command arguments
366+
* @param {Object} config - Configuration object
367+
* @param {Object} logger - Logger instance
368+
* @param {boolean} isProd - Production flag
369+
* @returns {Promise<Object>} Migration generation result
370+
*/
371+
export default async function generateHandler(args, config, logger, isProd) {
372+
const command = new MigrateGenerateCommand(config, logger, isProd);
373+
return await command.performExecute(args);
374+
}
375+
376+
export { MigrateGenerateCommand };

starfleet/data-cli/src/commands/db/migrate/history.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* Migration History Command
33
*/
44

5-
const Command = require('../../../lib/Command');
6-
const fs = require('fs').promises;
7-
const path = require('path');
5+
import Command from '../../../lib/Command.js';
6+
import { promises as fs } from 'fs';
7+
import path from 'path';
88

99
/**
1010
* Show migration history and timeline
1111
*/
12+
/**
13+
* @class
14+
*/
1215
class MigrateHistoryCommand extends Command {
1316
static description = 'Show migration history';
1417

@@ -219,4 +222,17 @@ class MigrateHistoryCommand extends Command {
219222
}
220223
}
221224

222-
module.exports = MigrateHistoryCommand;
225+
/**
226+
* Migration history handler
227+
* @param {Object} args - Command arguments
228+
* @param {Object} config - Configuration object
229+
* @param {Object} logger - Logger instance
230+
* @param {boolean} isProd - Production flag
231+
* @returns {Promise<Object>} History result
232+
*/
233+
export default async function historyHandler(args, config, logger, isProd) {
234+
const command = new MigrateHistoryCommand(config, logger, isProd);
235+
return await command.performExecute(args);
236+
}
237+
238+
export { MigrateHistoryCommand };

starfleet/data-cli/src/commands/db/migrate/index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@
44
* Exports all migration subcommands for the data CLI
55
*/
66

7-
module.exports = {
8-
MigrateStatusCommand: require('./status'),
9-
MigrateRollbackCommand: require('./rollback'),
10-
MigrateCleanCommand: require('./clean'),
11-
MigrateHistoryCommand: require('./history'),
12-
MigrateVerifyCommand: require('./verify'),
13-
MigrateSquashCommand: require('./squash'),
14-
MigrateGenerateCommand: require('./generate')
7+
import { MigrateStatusCommand } from './status.js';
8+
import { MigrateRollbackCommand } from './rollback.js';
9+
import { MigrateCleanCommand } from './clean.js';
10+
import { MigrateHistoryCommand } from './history.js';
11+
import { MigrateVerifyCommand } from './verify.js';
12+
import { MigrateSquashCommand } from './squash.js';
13+
import { MigrateGenerateCommand } from './generate.js';
14+
import { MigrateTestCommand } from './test.js';
15+
import { MigrateTestCommand as MigrateTestV2Command } from './test-v2.js';
16+
17+
export {
18+
MigrateStatusCommand,
19+
MigrateRollbackCommand,
20+
MigrateCleanCommand,
21+
MigrateHistoryCommand,
22+
MigrateVerifyCommand,
23+
MigrateSquashCommand,
24+
MigrateGenerateCommand,
25+
MigrateTestCommand,
26+
MigrateTestV2Command
1527
};

starfleet/data-cli/src/commands/db/migrate/promote.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Promotes tested migrations from staging to production with safety checks
44
*/
55

6-
const Command = require('../../../lib/Command');
7-
const MigrationMetadata = require('../../../lib/MigrationMetadata');
8-
const fs = require('fs').promises;
9-
const path = require('path');
6+
import Command from '../../../lib/Command.js';
7+
import MigrationMetadata from '../../../lib/MigrationMetadata.js';
8+
import { promises as fs, statSync } from 'fs';
9+
import path from 'path';
10+
import { spawn } from 'child_process';
1011

1112
/**
1213
* Command to promote a tested migration to production
14+
* @class
1315
*/
1416
class MigratePromoteCommand extends Command {
1517
static description = 'Promote tested migration to production';
@@ -245,8 +247,6 @@ class MigratePromoteCommand extends Command {
245247
async stageInGit(productionPath) {
246248
this.progress('Staging migration in Git...');
247249

248-
const { spawn } = require('child_process');
249-
250250
return new Promise((resolve, reject) => {
251251
const git = spawn('git', ['add', productionPath], {
252252
stdio: ['ignore', 'pipe', 'pipe']
@@ -285,7 +285,7 @@ class MigratePromoteCommand extends Command {
285285
while (currentDir !== path.dirname(currentDir)) {
286286
const supabasePath = path.join(currentDir, 'supabase');
287287
try {
288-
require('fs').statSync(supabasePath);
288+
statSync(supabasePath);
289289
return supabasePath;
290290
} catch {
291291
currentDir = path.dirname(currentDir);
@@ -320,4 +320,17 @@ class MigratePromoteCommand extends Command {
320320
}
321321
}
322322

323-
module.exports = MigratePromoteCommand;
323+
/**
324+
* Promote tested migration to production handler
325+
* @param {Object} args - Command arguments
326+
* @param {Object} config - Configuration object
327+
* @param {Object} logger - Logger instance
328+
* @param {boolean} isProd - Production flag
329+
* @returns {Promise<Object>} Promotion result
330+
*/
331+
export default async function promoteHandler(args, config, logger, isProd) {
332+
const command = new MigratePromoteCommand(config, logger, isProd);
333+
return await command.performExecute(args);
334+
}
335+
336+
export { MigratePromoteCommand };

starfleet/data-cli/src/commands/db/migrate/rollback.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* Migration Rollback Command
33
*/
44

5-
const DatabaseCommand = require('../../../lib/DatabaseCommand');
6-
const fs = require('fs').promises;
7-
const path = require('path');
5+
import DatabaseCommand from '../../../lib/DatabaseCommand.js';
6+
import { promises as fs } from 'fs';
7+
import path from 'path';
88

99
/**
1010
* Rollback migration to previous state with confirmation
1111
*/
12+
/**
13+
* @class
14+
*/
1215
class MigrateRollbackCommand extends DatabaseCommand {
1316
static description = 'Rollback migration to previous state';
1417
static requiresConfirmation = true;
@@ -182,4 +185,17 @@ class MigrateRollbackCommand extends DatabaseCommand {
182185
}
183186
}
184187

185-
module.exports = MigrateRollbackCommand;
188+
/**
189+
* Migration rollback handler
190+
* @param {Object} args - Command arguments
191+
* @param {Object} config - Configuration object
192+
* @param {Object} logger - Logger instance
193+
* @param {boolean} isProd - Production flag
194+
* @returns {Promise<Object>} Rollback result
195+
*/
196+
export default async function rollbackHandler(args, config, logger, isProd) {
197+
const command = new MigrateRollbackCommand(config, logger, isProd);
198+
return await command.performExecute(args);
199+
}
200+
201+
export { MigrateRollbackCommand };

starfleet/data-cli/src/commands/db/migrate/squash.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* Migration Squash Command
33
*/
44

5-
const Command = require('../../../lib/Command');
6-
const fs = require('fs').promises;
7-
const path = require('path');
5+
import Command from '../../../lib/Command.js';
6+
import { promises as fs } from 'fs';
7+
import path from 'path';
88

99
/**
1010
* Squash multiple migrations into a single migration file
1111
*/
12+
/**
13+
* @class
14+
*/
1215
class MigrateSquashCommand extends Command {
1316
static description = 'Squash multiple migrations';
1417

@@ -348,4 +351,17 @@ class MigrateSquashCommand extends Command {
348351
}
349352
}
350353

351-
module.exports = MigrateSquashCommand;
354+
/**
355+
* Migration squash handler
356+
* @param {Object} args - Command arguments
357+
* @param {Object} config - Configuration object
358+
* @param {Object} logger - Logger instance
359+
* @param {boolean} isProd - Production flag
360+
* @returns {Promise<Object>} Squash result
361+
*/
362+
export default async function squashHandler(args, config, logger, isProd) {
363+
const command = new MigrateSquashCommand(config, logger, isProd);
364+
return await command.performExecute(args);
365+
}
366+
367+
export { MigrateSquashCommand };

0 commit comments

Comments
 (0)