Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commit of files written after first commit was done. #14481

Merged
merged 2 commits into from
Mar 27, 2021
Merged
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
2 changes: 1 addition & 1 deletion cli/jhipster.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let preferLocal = true;

// Don't use commander for parsing command line to avoid polluting it in cli.js
// --prefer-local: Always resolve node modules locally (useful when using linked module)
if (process.argv.includes('upgrade') && !process.argv.includes('--prefer-local')) {
if ((process.argv.includes('upgrade') && !process.argv.includes('--prefer-local')) || process.argv.includes('--prefer-global')) {
// Prefer global version for `jhipster upgrade` to get most recent code
preferLocal = false;
}
Expand Down
2 changes: 2 additions & 0 deletions cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const createProgram = () => {
.option('--skip-regenerate', "Don't regenerate identical files", false)
.option('--skip-yo-resolve', 'Ignore .yo-resolve files', false)
.addOption(new Option('--from-jdl', 'Allow every option jdl forwards').default(false).hideHelp())
.addOption(new Option('--prefer-global', 'Run jhipster installed globally').hideHelp())
.addOption(new Option('--prefer-local', 'Run jhipster installed locally').hideHelp())
);
};

Expand Down
21 changes: 13 additions & 8 deletions generators/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ module.exports = class extends BaseGenerator {
return;
}
await this._commitSharedFs();
this.env.sharedFs.once('change', () => this._queueCommit());
this.env.sharedFs.once('change', () => {
this._queueCommit();
});
},
};
}
Expand All @@ -115,15 +117,18 @@ module.exports = class extends BaseGenerator {
*/
_queueCommit() {
this.debug('Queueing conflicts task');
this.runLoop.add(
'conflicts',
(done, stop) =>
this._commitSharedFs().then(() => {
this.queueTask(
{
method: async () => {
await this._commitSharedFs();
this.debug('Adding queueCommit event listener');
this.sharedFs.once('change', () => this.queueCommit);
done();
}, stop),
this.env.sharedFs.once('change', () => {
this._queueCommit();
});
},
},
{
priorityName: 'conflicts',
once: 'write memory fs to disk',
}
);
Expand Down
14 changes: 4 additions & 10 deletions generators/entity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,17 +808,11 @@ class EntityGenerator extends BaseBlueprintGenerator {
// form the data to be passed to modules
const context = this.context;

const done = this.async();
// run through all post entity creation module hooks
this.callHooks(
'entity',
'post',
{
entityConfig: context,
force: this.options.force,
},
done
);
this.callHooks('entity', 'post', {
entityConfig: context,
force: this.options.force,
});
}
} catch (err) {
this.log(`\n${chalk.bold.red('Running post run module hooks failed. No modification done to the generated entity.')}`);
Expand Down
37 changes: 37 additions & 0 deletions test/bootstrap/bootstrap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { dryRunHelpers: helpers } = require('../utils/utils');
const GeneratorBase = require('../../generators/generator-base');

const MockedGenerator = class extends GeneratorBase {
get install() {
return {
writeInstallFile() {
this.writeDestination('installPriority.txt', 'success');
},
};
}

get end() {
return {
writeEndFile() {
this.writeDestination('endPriority.txt', 'success');
},
};
}
};

describe('Bootstrap generator', () => {
context('Default configuration with', () => {
let runResult;
before(async () => {
runResult = await helpers
.create('mocked-generator')
.withGenerators([[MockedGenerator, 'mocked-generator']])
.withOptions({ defaults: true })
.run();
});
it('should generate files from every priority', () => {
runResult.assertFileContent('installPriority.txt', 'success');
runResult.assertFileContent('endPriority.txt', 'success');
});
});
});
2 changes: 1 addition & 1 deletion test/cli/jdl-fork.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sinon = require('sinon');
const { prepareTempDir } = require('../utils/utils');
const { runJHipster } = require('../../cli/program');

describe('jhipster program', () => {
describe('jhipster cli with jdl fork', () => {
let cleanup;
beforeEach(() => {
cleanup = prepareTempDir();
Expand Down