Skip to content

Commit 3990aa4

Browse files
committed
refactor(cli): remove unnecessary lazy loading
Replace dynamic imports with normal top-level imports across the codebase since everything is bundled into build/cli.js. Lazy loading adds complexity without providing benefits in a bundled environment. Changes: - provider-factory.mts: Change createPrProvider to synchronous with top-level imports (fixes Node 20 syntax errors) - analytics-app-cli.mts: Import React/Ink at top level instead of dynamic imports - audit-log-app-cli.mts: Import React/Ink at top level instead of dynamic imports - threat-feed-app-cli.mts: Import React/Ink at top level instead of dynamic imports - with-subcommands.mts: Import interactive help at top level instead of dynamic imports - downloads.mts: Import fs.promises at top level instead of dynamic import This fixes Node 20 test failures in providers.test.mts where require() with destructuring caused syntax errors.
1 parent c329d1f commit 3990aa4

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

packages/cli/src/commands/analytics/analytics-app-cli.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
import { pathToFileURL } from 'node:url'
55

6+
import { render } from 'ink'
7+
import React from 'react'
8+
69
/**
710
* Run the Ink AnalyticsApp with data from stdin.
811
*/
@@ -15,9 +18,7 @@ async function main() {
1518
const input = Buffer.concat(chunks).toString('utf8')
1619
const data = JSON.parse(input)
1720

18-
// Dynamically import ESM modules.
19-
const React = await import('react')
20-
const { render } = await import('ink')
21+
// Dynamic import is needed here because AnalyticsApp.tsx gets compiled to .js at build time.
2122
const { AnalyticsApp } = await import(
2223
pathToFileURL(new URL('./AnalyticsApp.js', import.meta.url).pathname).href
2324
)

packages/cli/src/commands/audit-log/audit-log-app-cli.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
import { pathToFileURL } from 'node:url'
55

6+
import { render } from 'ink'
7+
import React from 'react'
8+
69
/**
710
* Run the Ink AuditLogApp with data from stdin.
811
*/
@@ -15,9 +18,7 @@ async function main() {
1518
const input = Buffer.concat(chunks).toString('utf8')
1619
const data = JSON.parse(input)
1720

18-
// Dynamically import ESM modules.
19-
const React = await import('react')
20-
const { render } = await import('ink')
21+
// Dynamic import is needed here because AuditLogApp.tsx gets compiled to .js at build time.
2122
const { AuditLogApp } = await import(
2223
pathToFileURL(new URL('./AuditLogApp.js', import.meta.url).pathname).href
2324
)

packages/cli/src/commands/threat-feed/threat-feed-app-cli.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
import { pathToFileURL } from 'node:url'
55

6+
import { render } from 'ink'
7+
import React from 'react'
8+
69
/**
710
* Run the Ink ThreatFeedApp with data from stdin.
811
*/
@@ -15,9 +18,7 @@ async function main() {
1518
const input = Buffer.concat(chunks).toString('utf8')
1619
const data = JSON.parse(input)
1720

18-
// Dynamically import ESM modules.
19-
const React = await import('react')
20-
const { render } = await import('ink')
21+
// Dynamic import is needed here because ThreatFeedApp.tsx gets compiled to .js at build time.
2122
const { ThreatFeedApp } = await import(
2223
pathToFileURL(new URL('./ThreatFeedApp.js', import.meta.url).pathname).href
2324
)

packages/cli/src/utils/cli/with-subcommands.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from '../config.mts'
3535
import { isDebug } from '../debug.mts'
3636
import { tildify } from '../fs/home-path.mts'
37+
import { showCategoryHelp, showInteractiveHelp } from './interactive-help.mts'
3738
import { getFlagListOutput, getHelpListOutput } from '../output/formatting.mts'
3839
import { spawnSocketPython } from '../python/standalone.mts'
3940
import { getVisibleTokenPrefix } from '../socket/sdk.mjs'
@@ -881,14 +882,12 @@ export async function meowWithSubcommands(
881882
process.env['CI'] !== 'true'
882883

883884
if (shouldShowInteractive) {
884-
// Show interactive help for root --help command
885-
const { showInteractiveHelp } = await import('./interactive-help.mts')
885+
// Show interactive help for root --help command.
886886
await showInteractiveHelp()
887887
// eslint-disable-next-line n/no-process-exit
888888
process.exit(0)
889889
} else if (helpCategory) {
890-
// Show specific category help
891-
const { showCategoryHelp } = await import('./interactive-help.mts')
890+
// Show specific category help.
892891
const found = showCategoryHelp(helpCategory)
893892
if (!found) {
894893
logger.error(`Unknown help category: ${helpCategory}`)

packages/cli/src/utils/git/provider-factory.mts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { spawnSync } from '@socketsecurity/lib/spawn'
22

3+
import { GitHubProvider } from './github-provider.mts'
4+
import { GitLabProvider } from './gitlab-provider.mts'
35
import type { PrProvider } from './provider.mts'
46

57
/**
@@ -17,15 +19,10 @@ export function createPrProvider(): PrProvider {
1719
process.env['GITLAB_HOST'] ||
1820
remoteUrl.includes('gitlab')
1921
) {
20-
// Lazy load to avoid importing GitLab dependency if not needed.
21-
22-
const { GitLabProvider } = require('./gitlab-provider.mts')
2322
return new GitLabProvider()
2423
}
2524

2625
// Default to GitHub (backward compatibility).
27-
28-
const { GitHubProvider } = require('./github-provider.mts')
2926
return new GitHubProvider()
3027
}
3128

packages/cli/src/utils/preflight/downloads.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* This runs asynchronously and never blocks the main CLI execution.
88
*/
99

10-
import { existsSync } from 'node:fs'
10+
import { existsSync, promises as fs } from 'node:fs'
1111
import path from 'node:path'
1212

1313
import { spawn } from '@socketsecurity/lib/spawn'
@@ -41,7 +41,6 @@ async function markPackageCached(packageName: string): Promise<void> {
4141
const cacheMarker = path.join(cacheDir, packageName.replace(/[/@]/g, '-'))
4242

4343
try {
44-
const { promises: fs } = await import('node:fs')
4544
await fs.mkdir(cacheDir, { recursive: true })
4645
await fs.writeFile(cacheMarker, new Date().toISOString())
4746
} catch {

0 commit comments

Comments
 (0)