Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bin/commands/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
assertRunnableOptions,
setConfig,
} from '../../src/utils/configuration/index.mjs';
import createProgressBar from '../../src/utils/progress-bar.mjs';
import { errorWrap } from '../utils.mjs';

const { runGenerators } = createGenerator();
Expand Down Expand Up @@ -67,6 +68,14 @@ export default new Command('generate')
const config = await setConfig(opts);
assertRunnableOptions(config);

await runGenerators(config);
const progressBar = createProgressBar();

progressBar.start(config.target.length);

await runGenerators(config, {
onGeneratorComplete: progressBar.increment,
});

progressBar.stop();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress bar not stopped on failure

Medium Severity

When runGenerators rejects, progressBar.stop() is skipped because it runs only after a successful await. The TTY bar is started with hideCursor: true, so a failed generate can leave the terminal cursor hidden until the user resets the shell.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4d7db68. Configure here.

})
);
113 changes: 68 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@rollup/plugin-virtual": "^3.0.2",
"@swc/html-wasm": "^1.15.43",
"acorn": "^8.17.0",
"cli-progress": "^3.12.0",
"commander": "^14.0.3",
"dedent": "^1.7.2",
"estree-util-to-js": "^2.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/generators.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ describe('createGenerator orchestration', () => {
]);
});

it('calls onGeneratorComplete once per requested target, not per dependency', async () => {
const { runGenerators } = createGenerator();

const completed = [];

await runGenerators(
{ target: ['gen-a', 'gen-b'], threads: 1 },
{ onGeneratorComplete: name => completed.push(name) }
);

assert.deepStrictEqual(completed.sort(), ['gen-a', 'gen-b']);
});

it('does not re-run a target that is also another target dependency', async () => {
const { runGenerators } = createGenerator();

Expand Down
13 changes: 11 additions & 2 deletions src/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ const createGenerator = () => {
* Runs all requested generators with their dependencies.
*
* @param {import('./utils/configuration/types').Configuration} options - Runtime options
* @param {Object} [callbacks] - Optional lifecycle callbacks
* @param {(name: string) => void} [callbacks.onGeneratorComplete] - Called once per
* requested generator (not its dependencies) as soon as its result is ready
* @returns {Promise<unknown[]>} Results of all requested generators
*/
const runGenerators = async configuration => {
const runGenerators = async (configuration, { onGeneratorComplete } = {}) => {
const { target: generators, threads } = configuration;

generatorsLogger.debug(`Starting pipeline`, {
Expand All @@ -118,7 +121,13 @@ const createGenerator = () => {
// Start all collections in parallel (don't await sequentially). Consuming
// through the shared path lets the final read also trigger eviction.
const results = await Promise.all(
generators.map(name => cache.consume(name))
generators.map(name =>
cache.consume(name).then(result => {
onGeneratorComplete?.(name);

return result;
})
)
);

await pool.destroy();
Expand Down
Loading