Skip to content

Commit

Permalink
add --generate-types to the watch command (#9314)
Browse files Browse the repository at this point in the history
The heavy lifting was done in #9308 . This PR is about adding the same
functionality for `bit watch`.
  • Loading branch information
davidfirst authored Nov 20, 2024
1 parent 04d5d56 commit 696501b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scopes/compilation/compiler/compiler.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CompileCmd implements Command {
['v', 'verbose', 'show more data, such as, dist paths'],
['j', 'json', 'return the compile results in json format'],
['d', 'delete-dist-dir', 'delete existing dist folder before writing new compiled files'],
['', 'generate-types', 'generate d.ts files for typescript components (hurts performance)'],
['', 'generate-types', 'EXPERIMENTAL. generate d.ts files for typescript components (hurts performance)'],
] as CommandOptions;

constructor(
Expand Down
8 changes: 6 additions & 2 deletions scopes/compilation/compiler/workspace-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ export class WorkspaceCompiler {
}
const buildResults = await this.compileComponents(
[component.id.toString()],
{ initiator: watchOpts.initiator || CompilationInitiator.ComponentChanged, deleteDistDir },
{
initiator: watchOpts.initiator || CompilationInitiator.ComponentChanged,
deleteDistDir,
generateTypes: watchOpts.generateTypes,
},
true
);
return {
Expand All @@ -361,7 +365,7 @@ export class WorkspaceCompiler {
this.logger.console(`compiling ${componentIds.length} components`);
await this.compileComponents(
componentIds.map((id) => id),
{ initiator: CompilationInitiator.PreWatch }
{ initiator: CompilationInitiator.PreWatch, generateTypes: watchOpts.generateTypes }
);
const end = Date.now() - start;
this.logger.consoleSuccess(`compiled ${componentIds.length} components successfully (${end / 1000} sec)`);
Expand Down
3 changes: 3 additions & 0 deletions scopes/workspace/watcher/watch.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type WatchCmdOpts = {
checkTypes?: string | boolean;
import?: boolean;
skipImport?: boolean;
generateTypes?: boolean;
trigger?: string;
};

Expand All @@ -42,6 +43,7 @@ if this doesn't work well for you, run "bit config set watch_use_polling true" t
'DEPRECATED. it is now the default. helpful when using git. import component objects if .bitmap changed not by bit',
],
['', 'skip-import', 'do not import component objects if .bitmap changed not by bit'],
['', 'generate-types', 'EXPERIMENTAL. generate d.ts files for typescript components (hurts performance)'],
[
'',
'trigger <comp-id>',
Expand Down Expand Up @@ -109,6 +111,7 @@ if this doesn't work well for you, run "bit config set watch_use_polling true" t
checkTypes: getCheckTypesEnum(),
import: !skipImport,
trigger: trigger ? ComponentID.fromString(trigger) : undefined,
generateTypes: watchCmdOpts.generateTypes,
};
await this.watcher.watch(watchOpts);
return 'watcher terminated';
Expand Down
1 change: 1 addition & 0 deletions scopes/workspace/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type WatchOptions = {
preCompile?: boolean; // whether compile all components before start watching
compile?: boolean; // whether compile modified/added components during watch process
import?: boolean; // whether import objects when .bitmap got version changes
generateTypes?: boolean; // whether generate d.ts files for typescript files during watch process (hurts performance)
trigger?: ComponentID; // trigger onComponentChange for the specified component-id. helpful when this comp must be a bundle, and needs to be recompile on any dep change.
};

Expand Down

0 comments on commit 696501b

Please sign in to comment.