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

Adjusts to upgrade on files conflicts. #17095

Merged
merged 3 commits into from
Nov 23, 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
1 change: 1 addition & 0 deletions cli/import-jdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function runGenerator(command, { cwd, fork, env }, generatorOptions = {}) {
forceNoFiltering: undefined,
unidirectionalRelationships: undefined,
localConfigOnly: undefined,
commandName: undefined,
fromJdl: true,
};

Expand Down
1 change: 1 addition & 0 deletions cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
const options = {
...program.opts(),
...cmdOptions,
commandName: cmdName,
};
if (options.installPath) {
// eslint-disable-next-line no-console
Expand Down
3 changes: 2 additions & 1 deletion generators/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ module.exports = class extends BaseGenerator {
if (!skipPrettier) {
const prettierOptions = { packageJson: true, java: !this.skipServer && !this.jhipsterConfig.skipServer };
// Prettier is clever, it uses correct rules and correct parser according to file extension.
transformStreams.push(prettierTransform(prettierOptions, this, this.options.ignoreErrors));
const ignoreErrors = this.options.commandName === 'upgrade' || this.options.ignoreErrors;
transformStreams.push(prettierTransform(prettierOptions, this, ignoreErrors));
}

transformStreams.push(createConflicterCheckTransform(this.env.conflicter, conflicterStatus), createConflicterStatusTransform());
Expand Down
16 changes: 12 additions & 4 deletions generators/generator-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const prettierTransform = function (options, generator, transformOptions = {}) {
if (isFileStateDeleted(file)) {
return file;
}
if (!file.contents) {
throw new Error(`File content doesn't exist for ${file.relative}`);
}
/* resolve from the projects config */
let fileContent;
try {
Expand All @@ -58,12 +61,17 @@ const prettierTransform = function (options, generator, transformOptions = {}) {
file.contents = Buffer.from(data);
return file;
} catch (error) {
const errorMessage = `Error parsing file ${file.relative}: ${error}
let errorMessage;
if (fileContent) {
errorMessage = `Error parsing file ${file.relative}: ${error}

At: ${fileContent
.split('\n')
.map((value, idx) => `${idx + 1}: ${value}`)
.join('\n')}`;
.split('\n')
.map((value, idx) => `${idx + 1}: ${value}`)
.join('\n')}`;
} else {
errorMessage = `Unknown prettier error: ${error}`;
}
if (ignoreErrors) {
generator.warning(errorMessage);
return file;
Expand Down
2 changes: 1 addition & 1 deletion generators/upgrade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = class extends BaseGenerator {
generatorCommand = `"${generatorDir.replace('\n', '')}/jhipster"`;
}
const skipChecksOption = this.skipChecks ? '--skip-checks' : '';
const regenerateCmd = `${generatorCommand} --with-entities --force --skip-install --skip-git --no-insight ${skipChecksOption}`;
const regenerateCmd = `${generatorCommand} --with-entities --force --skip-install --skip-git --ignore-errors --no-insight ${skipChecksOption}`;
this.info(regenerateCmd);
try {
childProcess.execSync(regenerateCmd, { stdio: 'inherit' });
Expand Down