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

Fixes for npm 7. #13127

Merged
merged 5 commits into from
Nov 25, 2020
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 generators/client/files-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const files = {
common: [
{
templates: [
'.npmrc',
'package.json',
'tsconfig.json',
'tsconfig.app.json',
Expand Down
1 change: 1 addition & 0 deletions generators/client/files-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const files = {
common: [
{
templates: [
'.npmrc',
'package.json',
'.eslintrc.json',
'tsconfig.json',
Expand Down
1 change: 1 addition & 0 deletions generators/client/files-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const vueFiles = {
common: [
{
templates: [
'.npmrc',
'package.json',
'tsconfig.json',
'.postcssrc.js',
Expand Down
1 change: 1 addition & 0 deletions generators/client/templates/angular/.npmrc.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps = true
1 change: 1 addition & 0 deletions generators/client/templates/react/.npmrc.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps = true
1 change: 1 addition & 0 deletions generators/client/templates/vue/.npmrc.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps = true
10 changes: 5 additions & 5 deletions generators/upgrade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ module.exports = class extends BaseGenerator {
const commandPrefix = 'npm show';
const pkgInfo = shelljs.exec(`${commandPrefix} ${packageName} version`, { silent: this.silent });
if (pkgInfo.stderr) {
this.warning(`Something went wrong fetching the latest ${packageName} version number...\n${pkgInfo.stderr}`);
this.error('Exiting process');
this.warning(pkgInfo.stderr);
throw new Error(`Something went wrong fetching the latest ${packageName} version number...\n${pkgInfo.stderr}`);
}
const msg = pkgInfo.stdout;
return msg.replace('\n', '');
Expand All @@ -211,7 +211,7 @@ module.exports = class extends BaseGenerator {
const commandPrefix = 'npm install';
const devDependencyParam = '--save-dev';
const noPackageLockParam = '--no-package-lock';
const generatorCommand = `${commandPrefix} ${npmPackage}@${version} ${devDependencyParam} ${noPackageLockParam} --ignore-scripts`;
const generatorCommand = `${commandPrefix} ${npmPackage}@${version} ${devDependencyParam} ${noPackageLockParam} --ignore-scripts --legacy-peer-deps`;
this.info(generatorCommand);

const npmIntall = shelljs.exec(generatorCommand, { silent: this.silent });
Expand Down Expand Up @@ -324,8 +324,8 @@ module.exports = class extends BaseGenerator {
const gitStatus = this.gitExec(['status', '--porcelain'], { silent: this.silent });
if (gitStatus.code !== 0) this.error(`Unable to check for local changes:\n${gitStatus.stdout} ${gitStatus.stderr}`);
if (gitStatus.stdout) {
this.warning(' local changes found.\n\tPlease commit/stash them before upgrading');
this.error('Exiting process');
this.warning(gitStatus.stdout);
throw new Error(' local changes found.\n\tPlease commit/stash them before upgrading');
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"main": "cli/index.js",
"bin": {
"jhipster": "./cli/jhipster.js"
"jhipster": "cli/jhipster.js"
},
"files": [
"cli",
Expand Down
97 changes: 39 additions & 58 deletions test/upgrade.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ const expect = require('chai').expect;
const expectedFiles = require('./utils/expected-files');
const packageJson = require('../package.json');
const constants = require('../generators/generator-constants');
const { prepareTempDir } = require('./utils/utils');

const ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;

describe('JHipster upgrade generator', function () {
this.timeout(400000);

describe('default application', () => {
const cwd = process.cwd();
before(done => {
let workingDirectory;
helpers
.run(path.join(__dirname, '../generators/app'))
let cleanup;
before(() => {
cleanup = prepareTempDir();
return helpers
.create(path.join(__dirname, '../generators/app'), { tmpdir: false })
.withOptions({ skipInstall: true, skipChecks: true, fromCli: true })
.inTmpDir(dir => {
/* eslint-disable-next-line no-console */
console.log(`Generating JHipster application in directory: ${dir}`);
// Save directory, in order to run the upgrade generator in the same directory
workingDirectory = dir;
})
.withPrompts({
baseName: 'jhipster',
clientFramework: ANGULAR,
Expand All @@ -47,24 +43,22 @@ describe('JHipster upgrade generator', function () {
serverSideOptions: [],
upgradeConfig: false,
})
.on('end', () => {
helpers
.run(path.join(__dirname, '../generators/upgrade'))
.run()
.then(() => {
return helpers
.create(path.join(__dirname, '../generators/upgrade'), { tmpdir: false })
.withOptions({
fromCli: true,
force: true,
silent: false,
targetVersion: packageJson.version,
})
.inTmpDir(() => {
/* eslint-disable-next-line no-console */
console.log('Upgrading the JHipster application');
process.chdir(workingDirectory);
})
.on('end', done);
.run();
});
});

after(() => cleanup());

it('creates expected files for default configuration', () => {
assert.file(expectedFiles.common);
assert.file(expectedFiles.server);
Expand All @@ -82,36 +76,29 @@ describe('JHipster upgrade generator', function () {
// - master: merge commit of jhipster_upgrade
expect(commitsCount).to.equal('5');
});

after(() => {
process.chdir(cwd);
});
});
describe('blueprint application', () => {
const cwd = process.cwd();
const blueprintName = 'generator-jhipster-sample-blueprint';
const blueprintVersion = '0.1.1';
before(done => {
let workingDirectory;
helpers
.run(path.join(__dirname, '../generators/app'))
let cleanup;
before(() => {
cleanup = prepareTempDir();
const dir = process.cwd();
/* eslint-disable-next-line no-console */
console.log(`Generating JHipster application in directory: ${dir}`);
// Fake the presence of the blueprint in node_modules: we don't install it, but we need its version
const packagejs = {
name: blueprintName,
version: blueprintVersion,
};
const fakeBlueprintModuleDir = path.join(dir, `node_modules/${blueprintName}`);
fse.ensureDirSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake'));
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
// Create an fake generator, otherwise env.lookup doesn't find it.
fse.writeFileSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake', 'index.js'), '');
return helpers
.create(path.join(__dirname, '../generators/app'), { tmpdir: false })
.withOptions({ skipInstall: true, skipChecks: true, fromCli: true, blueprints: blueprintName })
.inTmpDir(dir => {
/* eslint-disable-next-line no-console */
console.log(`Generating JHipster application in directory: ${dir}`);
// Save directory, in order to run the upgrade generator in the same directory
workingDirectory = dir;
// Fake the presence of the blueprint in node_modules: we don't install it, but we need its version
const packagejs = {
name: blueprintName,
version: blueprintVersion,
};
const fakeBlueprintModuleDir = path.join(dir, `node_modules/${blueprintName}`);
fse.ensureDirSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake'));
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
// Create an fake generator, otherwise env.lookup doesn't find it.
fse.writeFileSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake', 'index.js'), '');
})
.withPrompts({
baseName: 'jhipster',
clientFramework: ANGULAR,
Expand All @@ -134,25 +121,23 @@ describe('JHipster upgrade generator', function () {
serverSideOptions: [],
upgradeConfig: false,
})
.on('end', () => {
helpers
.run(path.join(__dirname, '../generators/upgrade'))
.run()
.then(() => {
return helpers
.create(path.join(__dirname, '../generators/upgrade'), { tmpdir: false })
.withOptions({
fromCli: true,
force: true,
silent: false,
skipChecks: true,
targetVersion: packageJson.version,
})
.inTmpDir(() => {
/* eslint-disable-next-line no-console */
console.log('Upgrading the JHipster application');
process.chdir(workingDirectory);
})
.on('end', done);
.run();
});
});

after(() => cleanup());

it('creates expected files for default configuration', () => {
assert.file(expectedFiles.common);
assert.file(expectedFiles.server);
Expand All @@ -177,9 +162,5 @@ describe('JHipster upgrade generator', function () {
});
assert.fileContent('package.json', new RegExp(`"${blueprintName}": "${blueprintVersion}"`));
});

after(() => {
process.chdir(cwd);
});
});
});
1 change: 1 addition & 0 deletions test/utils/expected-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ const expectedFiles = {
'angular.json',
'ngsw-config.json',
'.eslintrc.json',
'.npmrc',
'package.json',
'.browserslistrc',
`${CLIENT_MAIN_SRC_DIR}404.html`,
Expand Down