1- import { cli , type Command } from 'gunshi' ;
1+ import { cli , lazy } from 'gunshi' ;
22import completion from '@gunshi/plugin-completion' ;
33import { gracefulExit } from 'exit-hook' ;
44
@@ -16,75 +16,65 @@ import { checkLocalVersionMismatch } from '../lib/check-local-version';
1616import packageJson from '../../package.json' ;
1717import { enforceProxyContextGuards } from './helpers/proxy-context-guard' ;
1818
19- // we'll import just the spec from each, so the implementations can be lazy loaded
20- import { commandSpec as initCommandSpec } from './commands/init.command' ;
21- import { commandSpec as loadCommandSpec } from './commands/load.command' ;
22- import { commandSpec as runCommandSpec } from './commands/run.command' ;
23- import { commandSpec as printenvCommandSpec } from './commands/printenv.command' ;
24- import { commandSpec as encryptCommandSpec } from './commands/encrypt.command' ;
25- import { commandSpec as lockCommandSpec } from './commands/lock.command' ;
26- import { commandSpec as revealCommandSpec } from './commands/reveal.command' ;
27- // import { commandSpec as doctorCommandSpec } from './commands/doctor.command';
28- import { commandSpec as helpCommandSpec } from './commands/help.command' ;
29- import { commandSpec as telemetryCommandSpec } from './commands/telemetry.command' ;
30- import { commandSpec as explainCommandSpec } from './commands/explain.command' ;
31- import { commandSpec as flattenCommandSpec } from './commands/flatten.command' ;
32- import { commandSpec as scanCommandSpec } from './commands/scan.command' ;
33- import { commandSpec as codegenCommandSpec } from './commands/codegen.command' ;
34- import { commandSpec as typegenCommandSpec } from './commands/typegen.command' ;
35- import { commandSpec as installPluginCommandSpec } from './commands/install-plugin.command' ;
36- import { commandSpec as auditCommandSpec } from './commands/audit.command' ;
37- import { commandSpec as generateKeyCommandSpec } from './commands/generate-key.command' ;
38- import { commandSpec as cacheCommandSpec } from './commands/cache.command' ;
39- import { commandSpec as keychainCommandSpec } from './commands/keychain.command' ;
40- import { commandSpec as proxyCommandSpec } from './commands/proxy.command' ;
41- // import { commandSpec as loginCommandSpec } from './commands/login.command';
42- // import { commandSpec as pluginCommandSpec } from './commands/plugin.command';
19+ // Only the spec (name/description/args/examples) is imported eagerly - each command's
20+ // implementation lives in a sibling `*.command.ts` that is pulled in via a dynamic
21+ // import when that command actually runs. Keeping the two in separate modules is what
22+ // makes the split real: importing anything from `*.command.ts` here would drag the whole
23+ // implementation into the entry chunk and collapse the dynamic import away.
24+ import { commandSpec as initCommandSpec } from './commands/init.command-spec' ;
25+ import { commandSpec as loadCommandSpec } from './commands/load.command-spec' ;
26+ import { commandSpec as runCommandSpec } from './commands/run.command-spec' ;
27+ import { commandSpec as printenvCommandSpec } from './commands/printenv.command-spec' ;
28+ import { commandSpec as encryptCommandSpec } from './commands/encrypt.command-spec' ;
29+ import { commandSpec as lockCommandSpec } from './commands/lock.command-spec' ;
30+ import { commandSpec as revealCommandSpec } from './commands/reveal.command-spec' ;
31+ // import { commandSpec as doctorCommandSpec } from './commands/doctor.command-spec';
32+ import { commandSpec as helpCommandSpec } from './commands/help.command-spec' ;
33+ import { commandSpec as telemetryCommandSpec } from './commands/telemetry.command-spec' ;
34+ import { commandSpec as explainCommandSpec } from './commands/explain.command-spec' ;
35+ import { commandSpec as flattenCommandSpec } from './commands/flatten.command-spec' ;
36+ import { commandSpec as scanCommandSpec } from './commands/scan.command-spec' ;
37+ import { commandSpec as codegenCommandSpec } from './commands/codegen.command-spec' ;
38+ import { commandSpec as typegenCommandSpec } from './commands/typegen.command-spec' ;
39+ import { commandSpec as installPluginCommandSpec } from './commands/install-plugin.command-spec' ;
40+ import { commandSpec as auditCommandSpec } from './commands/audit.command-spec' ;
41+ import { commandSpec as generateKeyCommandSpec } from './commands/generate-key.command-spec' ;
42+ import { commandSpec as cacheCommandSpec } from './commands/cache.command-spec' ;
43+ import { commandSpec as keychainCommandSpec } from './commands/keychain.command-spec' ;
44+ import { commandSpec as proxyCommandSpec } from './commands/proxy.command-spec' ;
45+ // import { commandSpec as loginCommandSpec } from './commands/login.command-spec';
46+ // import { commandSpec as pluginCommandSpec } from './commands/plugin.command-spec';
4347
4448// must happen before anything writes to stdio
4549handleBrokenPipe ( ) ;
4650
4751let versionId = packageJson . version ;
4852if ( __VARLOCK_BUILD_TYPE__ !== 'release' ) versionId += `-${ __VARLOCK_BUILD_TYPE__ } ` ;
4953
50- // TODO: this is not splitting the bundle correctly to actually lazy load the command fns
51- function buildLazyCommand (
52- commandSpec : Command < any > ,
53- loadCommandFn : ( ) => Promise < { commandSpec : Command < any > , commandFn : any } > ,
54- ) {
55- return {
56- ...commandSpec ,
57- run : async ( ...args : Array < any > ) => {
58- const commandSpecAndFn = await loadCommandFn ( ) ;
59- return await commandSpecAndFn . commandFn ( ...args ) ;
60- } ,
61- } ;
62- }
63-
6454const subCommands = new Map ( ) ;
65- subCommands . set ( 'init' , buildLazyCommand ( initCommandSpec , async ( ) => await import ( './commands/init.command' ) ) ) ;
66- subCommands . set ( 'load' , buildLazyCommand ( loadCommandSpec , async ( ) => await import ( './commands/load.command' ) ) ) ;
67- subCommands . set ( 'run' , buildLazyCommand ( runCommandSpec , async ( ) => await import ( './commands/run.command' ) ) ) ;
68- subCommands . set ( 'printenv' , buildLazyCommand ( printenvCommandSpec , async ( ) => await import ( './commands/printenv.command' ) ) ) ;
69- subCommands . set ( 'encrypt' , buildLazyCommand ( encryptCommandSpec , async ( ) => await import ( './commands/encrypt.command' ) ) ) ;
70- subCommands . set ( 'lock' , buildLazyCommand ( lockCommandSpec , async ( ) => await import ( './commands/lock.command' ) ) ) ;
71- subCommands . set ( 'reveal' , buildLazyCommand ( revealCommandSpec , async ( ) => await import ( './commands/reveal.command' ) ) ) ;
72- // subCommands.set('doctor', buildLazyCommand(doctorCommandSpec, async () => await import('./commands/doctor.command')));
73- subCommands . set ( 'explain' , buildLazyCommand ( explainCommandSpec , async ( ) => await import ( './commands/explain.command' ) ) ) ;
74- subCommands . set ( 'flatten' , buildLazyCommand ( flattenCommandSpec , async ( ) => await import ( './commands/flatten.command' ) ) ) ;
75- subCommands . set ( 'help' , buildLazyCommand ( helpCommandSpec , async ( ) => await import ( './commands/help.command' ) ) ) ;
76- subCommands . set ( 'telemetry' , buildLazyCommand ( telemetryCommandSpec , async ( ) => await import ( './commands/telemetry.command' ) ) ) ;
77- subCommands . set ( 'scan' , buildLazyCommand ( scanCommandSpec , async ( ) => await import ( './commands/scan.command' ) ) ) ;
78- subCommands . set ( 'audit' , buildLazyCommand ( auditCommandSpec , async ( ) => await import ( './commands/audit.command' ) ) ) ;
79- subCommands . set ( 'codegen' , buildLazyCommand ( codegenCommandSpec , async ( ) => await import ( './commands/codegen.command' ) ) ) ;
80- subCommands . set ( 'typegen' , buildLazyCommand ( typegenCommandSpec , async ( ) => await import ( './commands/typegen.command' ) ) ) ;
81- subCommands . set ( 'install-plugin' , buildLazyCommand ( installPluginCommandSpec , async ( ) => await import ( './commands/install-plugin.command' ) ) ) ;
82- subCommands . set ( 'generate-key' , buildLazyCommand ( generateKeyCommandSpec , async ( ) => await import ( './commands/generate-key.command' ) ) ) ;
83- subCommands . set ( 'cache' , buildLazyCommand ( cacheCommandSpec , async ( ) => await import ( './commands/cache.command' ) ) ) ;
84- subCommands . set ( 'keychain' , buildLazyCommand ( keychainCommandSpec , async ( ) => await import ( './commands/keychain.command' ) ) ) ;
85- subCommands . set ( 'proxy' , buildLazyCommand ( proxyCommandSpec , async ( ) => await import ( './commands/proxy.command' ) ) ) ;
86- // subCommands.set('login', buildLazyCommand(loginCommandSpec, async () => await import('./commands/login.command')));
87- // subCommands.set('plugin', buildLazyCommand(pluginCommandSpec, async () => await import('./commands/plugin.command')));
55+ subCommands . set ( 'init' , lazy ( async ( ) => ( await import ( './commands/init.command' ) ) . commandFn , initCommandSpec ) ) ;
56+ subCommands . set ( 'load' , lazy ( async ( ) => ( await import ( './commands/load.command' ) ) . commandFn , loadCommandSpec ) ) ;
57+ subCommands . set ( 'run' , lazy ( async ( ) => ( await import ( './commands/run.command' ) ) . commandFn , runCommandSpec ) ) ;
58+ subCommands . set ( 'printenv' , lazy ( async ( ) => ( await import ( './commands/printenv.command' ) ) . commandFn , printenvCommandSpec ) ) ;
59+ subCommands . set ( 'encrypt' , lazy ( async ( ) => ( await import ( './commands/encrypt.command' ) ) . commandFn , encryptCommandSpec ) ) ;
60+ subCommands . set ( 'lock' , lazy ( async ( ) => ( await import ( './commands/lock.command' ) ) . commandFn , lockCommandSpec ) ) ;
61+ subCommands . set ( 'reveal' , lazy ( async ( ) => ( await import ( './commands/reveal.command' ) ) . commandFn , revealCommandSpec ) ) ;
62+ // subCommands.set('doctor', lazy( async () => ( await import('./commands/doctor.command')).commandFn, doctorCommandSpec ));
63+ subCommands . set ( 'explain' , lazy ( async ( ) => ( await import ( './commands/explain.command' ) ) . commandFn , explainCommandSpec ) ) ;
64+ subCommands . set ( 'flatten' , lazy ( async ( ) => ( await import ( './commands/flatten.command' ) ) . commandFn , flattenCommandSpec ) ) ;
65+ subCommands . set ( 'help' , lazy ( async ( ) => ( await import ( './commands/help.command' ) ) . commandFn , helpCommandSpec ) ) ;
66+ subCommands . set ( 'telemetry' , lazy ( async ( ) => ( await import ( './commands/telemetry.command' ) ) . commandFn , telemetryCommandSpec ) ) ;
67+ subCommands . set ( 'scan' , lazy ( async ( ) => ( await import ( './commands/scan.command' ) ) . commandFn , scanCommandSpec ) ) ;
68+ subCommands . set ( 'audit' , lazy ( async ( ) => ( await import ( './commands/audit.command' ) ) . commandFn , auditCommandSpec ) ) ;
69+ subCommands . set ( 'codegen' , lazy ( async ( ) => ( await import ( './commands/codegen.command' ) ) . commandFn , codegenCommandSpec ) ) ;
70+ subCommands . set ( 'typegen' , lazy ( async ( ) => ( await import ( './commands/typegen.command' ) ) . commandFn , typegenCommandSpec ) ) ;
71+ subCommands . set ( 'install-plugin' , lazy ( async ( ) => ( await import ( './commands/install-plugin.command' ) ) . commandFn , installPluginCommandSpec ) ) ;
72+ subCommands . set ( 'generate-key' , lazy ( async ( ) => ( await import ( './commands/generate-key.command' ) ) . commandFn , generateKeyCommandSpec ) ) ;
73+ subCommands . set ( 'cache' , lazy ( async ( ) => ( await import ( './commands/cache.command' ) ) . commandFn , cacheCommandSpec ) ) ;
74+ subCommands . set ( 'keychain' , lazy ( async ( ) => ( await import ( './commands/keychain.command' ) ) . commandFn , keychainCommandSpec ) ) ;
75+ subCommands . set ( 'proxy' , lazy ( async ( ) => ( await import ( './commands/proxy.command' ) ) . commandFn , proxyCommandSpec ) ) ;
76+ // subCommands.set('login', lazy( async () => ( await import('./commands/login.command')).commandFn, loginCommandSpec ));
77+ // subCommands.set('plugin', lazy( async () => ( await import('./commands/plugin.command')).commandFn, pluginCommandSpec ));
8878
8979( async function go ( ) {
9080 try {
0 commit comments