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

Commit f200efc

Browse files
flyingrobotsclaude
andcommitted
feat(esm): Complete P1.T005 - Migrate core commands to ESM JavaScript
✅ Successfully migrated 13 core files (~800 LoC) from CommonJS to ESM: - src/index.js - Main CLI entry with dynamic imports - src/lib/Command.js - Base command class - src/lib/DatabaseCommand.js - Database base class - src/lib/SupabaseCommand.js - Supabase base class - src/lib/TestCommand.js - Test base class - src/commands/db/CompileCommand.js - Compilation command - src/commands/db/MigrateCommand.js - Migration command - src/commands/test/RunCommand.js - Test execution command - src/reporters/CliReporter.js - CLI reporter - src/ui/logo.js - Logo utility - Command index files for db, test, functions Migration patterns established: - require() → import statements - module.exports → export default/named exports - Added .js extensions to relative imports - Dynamic imports for runtime loading - import.meta.url for module detection CLI fully functional with ESM modules! Next: P1.T009 and P1.T010 can run in parallel 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 19e655b commit f200efc

File tree

13 files changed

+292
-245
lines changed

13 files changed

+292
-245
lines changed

src/commands/db/CompileCommand.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Database Migration Compile Command
33
*/
44

5-
const path = require('path');
6-
const BuildCommand = require('../../lib/BuildCommand');
5+
import { join } from 'path';
6+
import BuildCommand from '../../lib/BuildCommand.js';
77

88
/**
99
* Compile SQL sources into migration file
@@ -39,7 +39,7 @@ class CompileCommand extends BuildCommand {
3939
}
4040

4141
// Load the native migration compiler
42-
const MigrationCompiler = require('../../lib/migration/MigrationCompiler');
42+
const { default: MigrationCompiler } = await import('../../lib/migration/MigrationCompiler.js');
4343

4444
// Create compiler instance
4545
const compiler = new MigrationCompiler({
@@ -80,12 +80,12 @@ class CompileCommand extends BuildCommand {
8080

8181
try {
8282
// Import the DeployCommand
83-
const { DeployCommand } = require('../functions');
83+
const { DeployCommand } = await import('../functions/index.js');
8484

8585
// Create a functions deployment command
8686
// Note: This will need to be refactored when functions are separated
8787
const deployCommand = new DeployCommand(
88-
path.join(this.inputDir, '../functions'),
88+
join(this.inputDir, '../functions'),
8989
this.logger,
9090
this.isProd
9191
);
@@ -158,4 +158,5 @@ class CompileCommand extends BuildCommand {
158158
}
159159
}
160160

161-
module.exports = CompileCommand;
161+
export { CompileCommand };
162+
export default CompileCommand;

src/commands/db/MigrateCommand.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Database Migration Management Command
33
*/
44

5-
const Command = require('../../lib/Command');
6-
const CommandRouter = require('../../lib/CommandRouter');
7-
const { z } = require('zod');
5+
import Command from '../../lib/Command.js';
6+
import CommandRouter from '../../lib/CommandRouter.js';
7+
import { z } from 'zod';
88

99
/**
1010
* Migration command that uses router pattern for subcommands
@@ -56,7 +56,10 @@ class MigrateCommand extends Command {
5656
'data db migrate generate --name add-users-table',
5757
'data db migrate generate --dry-run'
5858
)
59-
.handler(require('./migrate/generate'));
59+
.handler(async (...args) => {
60+
const { default: handler } = await import('./migrate/generate.js');
61+
return handler(...args);
62+
});
6063

6164
// Register test command
6265
router
@@ -74,7 +77,10 @@ class MigrateCommand extends Command {
7477
'data db migrate test --migration latest',
7578
'data db migrate test --migration 20250829_001 --coverage'
7679
)
77-
.handler(require('./migrate/test-v2'));
80+
.handler(async (...args) => {
81+
const { default: handler } = await import('./migrate/test-v2.js');
82+
return handler(...args);
83+
});
7884

7985
// Register promote command
8086
router
@@ -91,7 +97,10 @@ class MigrateCommand extends Command {
9197
'data db migrate promote --migration 20250829_001',
9298
'data db migrate promote --prod --force'
9399
)
94-
.handler(require('./migrate/promote'));
100+
.handler(async (...args) => {
101+
const { default: handler } = await import('./migrate/promote.js');
102+
return handler(...args);
103+
});
95104

96105
// Register status command
97106
router
@@ -108,7 +117,10 @@ class MigrateCommand extends Command {
108117
'data db migrate status --detailed',
109118
'data db migrate status --prod --format json'
110119
)
111-
.handler(require('./migrate/status'));
120+
.handler(async (...args) => {
121+
const { default: handler } = await import('./migrate/status.js');
122+
return handler(...args);
123+
});
112124

113125
// Register rollback command
114126
router
@@ -127,7 +139,10 @@ class MigrateCommand extends Command {
127139
'data db migrate rollback --to 20250828_003',
128140
'data db migrate rollback --prod --force'
129141
)
130-
.handler(require('./migrate/rollback'));
142+
.handler(async (...args) => {
143+
const { default: handler } = await import('./migrate/rollback.js');
144+
return handler(...args);
145+
});
131146

132147
// Register clean command
133148
router
@@ -145,7 +160,10 @@ class MigrateCommand extends Command {
145160
'data db migrate clean --all',
146161
'data db migrate clean --older 30 --dry-run'
147162
)
148-
.handler(require('./migrate/clean'));
163+
.handler(async (...args) => {
164+
const { default: handler } = await import('./migrate/clean.js');
165+
return handler(...args);
166+
});
149167

150168
// Register history command
151169
router
@@ -164,7 +182,10 @@ class MigrateCommand extends Command {
164182
'data db migrate history --limit 20',
165183
'data db migrate history --from 2025-01-01 --format timeline'
166184
)
167-
.handler(require('./migrate/history'));
185+
.handler(async (...args) => {
186+
const { default: handler } = await import('./migrate/history.js');
187+
return handler(...args);
188+
});
168189

169190
// Register verify command
170191
router
@@ -182,7 +203,10 @@ class MigrateCommand extends Command {
182203
'data db migrate verify --migration 20250829_001',
183204
'data db migrate verify --all --prod'
184205
)
185-
.handler(require('./migrate/verify'));
206+
.handler(async (...args) => {
207+
const { default: handler } = await import('./migrate/verify.js');
208+
return handler(...args);
209+
});
186210

187211
// Register squash command
188212
router
@@ -201,7 +225,10 @@ class MigrateCommand extends Command {
201225
'data db migrate squash --name initial-schema',
202226
'data db migrate squash --dry-run'
203227
)
204-
.handler(require('./migrate/squash'));
228+
.handler(async (...args) => {
229+
const { default: handler } = await import('./migrate/squash.js');
230+
return handler(...args);
231+
});
205232

206233
return router;
207234
}
@@ -295,4 +322,5 @@ class MigrateCommand extends Command {
295322
}
296323
}
297324

298-
module.exports = MigrateCommand;
325+
export { MigrateCommand };
326+
export default MigrateCommand;

src/commands/db/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* Database Commands for data CLI
33
*/
44

5-
const ResetCommand = require('./ResetCommand');
6-
const QueryCommand = require('./QueryCommand');
7-
const CompileCommand = require('./CompileCommand');
8-
const MigrateCommand = require('./MigrateCommand');
5+
import ResetCommand from './ResetCommand.js';
6+
import QueryCommand from './QueryCommand.js';
7+
import CompileCommand from './CompileCommand.js';
8+
import MigrateCommand from './MigrateCommand.js';
99

10-
module.exports = {
10+
export {
1111
ResetCommand,
1212
QueryCommand,
1313
CompileCommand,

src/commands/functions/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Functions Commands Index
33
*/
44

5-
const DeployCommand = require('./DeployCommand');
6-
const ValidateCommand = require('./ValidateCommand');
7-
const StatusCommand = require('./StatusCommand');
5+
import DeployCommand from './DeployCommand.js';
6+
import ValidateCommand from './ValidateCommand.js';
7+
import StatusCommand from './StatusCommand.js';
88

9-
module.exports = {
9+
export {
1010
DeployCommand,
1111
ValidateCommand,
1212
StatusCommand

src/commands/test/RunCommand.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Test Run Command
33
*/
44

5-
const { Client } = require('pg');
6-
const chalk = require('chalk').default || require('chalk');
7-
const fs = require('fs').promises;
8-
const path = require('path');
9-
const TestCommand = require('../../lib/TestCommand');
10-
const ResultParser = require('../../lib/test/ResultParser');
11-
const { JUnitFormatter, JSONFormatter } = require('../../lib/test/formatters');
12-
const TestCache = require('../../lib/test/TestCache');
13-
const Config = require('../../lib/config');
5+
import { Client } from 'pg';
6+
import chalk from 'chalk';
7+
import { promises as fs } from 'fs';
8+
import { extname, dirname, join } from 'path';
9+
import TestCommand from '../../lib/TestCommand.js';
10+
import ResultParser from '../../lib/test/ResultParser.js';
11+
import { JUnitFormatter, JSONFormatter } from '../../lib/test/formatters/index.js';
12+
import TestCache from '../../lib/test/TestCache.js';
13+
import Config from '../../lib/config.js';
1414

1515
/**
1616
* Run compiled tests using pgTAP
@@ -527,12 +527,12 @@ class RunCommand extends TestCommand {
527527
let fullPath = filePath;
528528

529529
// Add default extension if not present
530-
if (!path.extname(filePath)) {
530+
if (!extname(filePath)) {
531531
fullPath = filePath + defaultExtension;
532532
}
533533

534534
// Ensure directory exists
535-
const dir = path.dirname(fullPath);
535+
const dir = dirname(fullPath);
536536
await fs.mkdir(dir, { recursive: true });
537537

538538
// Write file
@@ -663,4 +663,5 @@ class RunCommand extends TestCommand {
663663
}
664664
}
665665

666-
module.exports = RunCommand;
666+
export { RunCommand };
667+
export default RunCommand;

src/commands/test/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
* Test Commands for data CLI
33
*/
44

5-
const CompileCommand = require('./CompileCommand');
6-
const RunCommand = require('./RunCommand');
7-
const DevCycleCommand = require('./DevCycleCommand');
8-
const CoverageCommand = require('./CoverageCommand');
9-
const WatchCommand = require('./WatchCommand');
10-
const ValidateCommand = require('./ValidateCommand');
11-
const GenerateCommand = require('./GenerateCommand');
12-
const GenerateTemplateCommand = require('./GenerateTemplateCommand');
13-
const CacheCommand = require('./CacheCommand');
5+
import CompileCommand from './CompileCommand.js';
6+
import RunCommand from './RunCommand.js';
7+
import DevCycleCommand from './DevCycleCommand.js';
8+
import CoverageCommand from './CoverageCommand.js';
9+
import WatchCommand from './WatchCommand.js';
10+
import ValidateCommand from './ValidateCommand.js';
11+
import GenerateCommand from './GenerateCommand.js';
12+
import GenerateTemplateCommand from './GenerateTemplateCommand.js';
13+
import CacheCommand from './CacheCommand.js';
1414

1515
// CI Commands for automated testing
16-
const CIValidateCommand = require('./ci/CIValidateCommand');
17-
const CIRunCommand = require('./ci/CIRunCommand');
18-
const CICoverageCommand = require('./ci/CICoverageCommand');
16+
import CIValidateCommand from './ci/CIValidateCommand.js';
17+
import CIRunCommand from './ci/CIRunCommand.js';
18+
import CICoverageCommand from './ci/CICoverageCommand.js';
1919

20-
module.exports = {
20+
export {
2121
CompileCommand,
2222
RunCommand,
2323
DevCycleCommand,

0 commit comments

Comments
 (0)