diff --git a/.evergreen/compass_package.sh b/.evergreen/compass_package.sh index 078d9946cda..f8ca1996b38 100755 --- a/.evergreen/compass_package.sh +++ b/.evergreen/compass_package.sh @@ -8,7 +8,7 @@ if [[ "$OSTYPE" == "cygwin" ]]; then fi echo "Creating signed release build..." -npm run package-compass-nocompile $COMPASS_DISTRIBUTION +npm run package-compass-nocompile npm run generate-first-party-deps-json ls -la packages/compass/dist diff --git a/.evergreen/functions.yml b/.evergreen/functions.yml index 6971bbc7afd..91116e10c5e 100644 --- a/.evergreen/functions.yml +++ b/.evergreen/functions.yml @@ -301,12 +301,13 @@ functions: shell: bash env: <<: *compass-env + HADRON_DISTRIBUTION: ${compass_distribution} script: | set -e # Load environment variables eval $(.evergreen/print-compass-env.sh) # Generates and expansion file with build target metadata in packages/compass/expansions.yml - npm run --workspace mongodb-compass build-info -- ${target_platform} ${target_arch} --format=yaml --flatten ${compass_distribution} --out expansions.raw.yml + npm run --workspace mongodb-compass build-info -- ${target_platform} ${target_arch} --format=yaml --flatten --out expansions.raw.yml # the 'author' key conflicts with evergreen's own expansion grep -v '^author:' < packages/compass/expansions.raw.yml > packages/compass/expansions.yml - command: expansions.update @@ -405,7 +406,7 @@ functions: <<: *compass-env DEBUG: ${debug} npm_config_loglevel: ${npm_loglevel} - COMPASS_DISTRIBUTION: ${compass_distribution} + HADRON_DISTRIBUTION: ${compass_distribution} script: | set -e @@ -443,7 +444,7 @@ functions: <<: *compass-env DEBUG: ${debug} npm_config_loglevel: ${npm_loglevel} - COMPASS_DISTRIBUTION: ${compass_distribution} + HADRON_DISTRIBUTION: ${compass_distribution} SIGNING_SERVER_HOSTNAME: ${SIGNING_SERVER_HOSTNAME} SIGNING_SERVER_PRIVATE_KEY: ${SIGNING_SERVER_PRIVATE_KEY} SIGNING_SERVER_PRIVATE_KEY_CYGPATH: ${SIGNING_SERVER_PRIVATE_KEY_CYGPATH} @@ -586,6 +587,7 @@ functions: E2E_TEST_GROUPS: ${e2e_test_groups} E2E_TEST_GROUP: ${e2e_test_group} ATLAS_LOCAL_VERSION: latest + HADRON_DISTRIBUTION: compass script: | set -e # Load environment variables @@ -614,6 +616,7 @@ functions: MONGODB_RUNNER_VERSION: ${mongodb_version|} E2E_TEST_GROUPS: ${e2e_test_groups} E2E_TEST_GROUP: ${e2e_test_group} + HADRON_DISTRIBUTION: compass script: | set -e # Load environment variables @@ -623,7 +626,6 @@ functions: npm run --unsafe-perm --workspace compass-e2e-tests test-ci -- -- --test-multiple-connections - test-packaged-app: - command: shell.exec # Fail the task if it's idle for 10 mins @@ -946,6 +948,7 @@ functions: DEBUG: ${debug} SNYK_TOKEN: ${snyk_token} JIRA_API_TOKEN: ${jira_api_token} + HADRON_DISTRIBUTION: compass script: | set -e # Load environment variables diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 078a1b7df3b..f2fba00eb3d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,10 +56,10 @@ In addition to running lerna commands directly, there are a few convenient npm s To build compass you can run `package-compass` script: ```sh -npm run package-compass +HADRON_DISTRIBUTION='compass' npm run package-compass ``` -You can change the type of distribution you are building with `HADRON_DISTRIBUTION` environmental variable: +It is required to provide `HADRON_DISTRIBUTION` env variable explicitly. You can change the type of distribution you are building by setting a different `HADRON_DISTRIBUTION` value: ```sh HADRON_DISTRIBUTION='compass-readonly' npm run package-compass diff --git a/package-lock.json b/package-lock.json index be5dc2bad19..28c00caf426 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,6 @@ "configs/*", "scripts" ], - "dependencies": { - "electron": "^30.4.0" - }, "devDependencies": { "@babel/core": "7.16.0", "@babel/parser": "7.16.0", diff --git a/package.json b/package.json index 062a594b3af..865ab3d3f97 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "release": "npm run release --workspace mongodb-compass --", "reformat": "lerna run reformat --stream --no-bail", "package-compass": "npm run package-compass --workspace=mongodb-compass --", + "package-compass-debug": "npm run package-compass-debug --workspace=mongodb-compass --", "package-compass-nocompile": "npm run package-compass-nocompile --workspace=mongodb-compass --", "prestart": "npm run compile --workspace=@mongodb-js/webpack-config-compass", "prestart-web": "npm run prestart", diff --git a/packages/compass/package.json b/packages/compass/package.json index 7c431023f6e..88b341dda9c 100644 --- a/packages/compass/package.json +++ b/packages/compass/package.json @@ -31,7 +31,6 @@ } ], "distributions": { - "default": "compass", "compass": { "name": "mongodb-compass", "productName": "MongoDB Compass", @@ -143,7 +142,7 @@ "install": "node scripts/download-fonts.js && node scripts/download-csfle.js", "electron-rebuild": "electron-rebuild --only kerberos,keytar,interruptor,os-dns-native,win-export-certificate-and-key,macos-export-certificate-and-key --prebuild-tag-prefix not-real-prefix-to-force-rebuild", "prestart": "npm run electron-rebuild", - "start": "npm run webpack serve -- --mode development", + "start": "HADRON_DISTRIBUTION=${HADRON_DISTRIBUTION:-compass} npm run webpack serve -- --mode development", "test-electron": "npm run test-main && npm run test-renderer", "test-main": "xvfb-maybe electron-mocha --no-sandbox \"./src/main/**/*.spec.*\" \"./src/main/**/*.test.*\"", "test-renderer": "xvfb-maybe electron-mocha --no-sandbox --config ./.mocharc.renderer.js \"./src/app/**/*.spec.*\"", @@ -158,7 +157,7 @@ "package-compass-nocompile": "hadron-build release", "prepackage-compass": "npm run compile", "package-compass": "npm run package-compass-nocompile", - "package-compass-debug": "DEBUG='*' HADRON_SKIP_INSTALLER=true NO_ASAR=true npm run package-compass", + "package-compass-debug": "DEBUG='hadron*,compass*' HADRON_SKIP_INSTALLER=true NO_ASAR=true npm run package-compass", "upload": "hadron-build upload", "download": "hadron-build download", "evergreen-expansions": "hadron-build info --format=yaml --flatten > expansions.yml", diff --git a/packages/hadron-build/cli.js b/packages/hadron-build/cli.js index f05b8f627b7..b2018ad4cbc 100755 --- a/packages/hadron-build/cli.js +++ b/packages/hadron-build/cli.js @@ -11,7 +11,6 @@ const yargs = require('yargs') .command(require('./commands/info')) .command(require('./commands/upload')) .command(require('./commands/download')) - .command(require('./commands/verify')) .demand(1, 'Please specify a command.') .strict() .env() diff --git a/packages/hadron-build/commands/info.js b/packages/hadron-build/commands/info.js index 3ff2109e25d..7465ca13519 100644 --- a/packages/hadron-build/commands/info.js +++ b/packages/hadron-build/commands/info.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); const Target = require('../lib/target'); -const verifyDistro = require('../lib/distro'); const Table = require('cli-table'); const yaml = require('js-yaml'); const inspect = require('util').inspect; @@ -74,8 +73,6 @@ const toTable = (target) => { }; exports.handler = (argv) => { - verifyDistro(argv); - let target = new Target(argv.dir, { version: argv.version, platform: argv.platform, diff --git a/packages/hadron-build/commands/release.js b/packages/hadron-build/commands/release.js index 2a317b0991f..97233bde742 100644 --- a/packages/hadron-build/commands/release.js +++ b/packages/hadron-build/commands/release.js @@ -15,7 +15,6 @@ */ const Target = require('../lib/target'); -const verifyDistro = require('../lib/distro'); const cli = require('mongodb-js-cli')('hadron-build:release'); const util = require('util'); const format = util.format; @@ -30,8 +29,6 @@ const run = require('./../lib/run'); const rebuild = require('@electron/rebuild').rebuild; const { signArchive } = require('./../lib/signtool'); -const verify = require('./verify'); - exports.command = 'release'; exports.describe = ':shipit:'; @@ -514,8 +511,6 @@ exports.builder = { } }; -_.assign(exports.builder, verify.builder); - /** * @param {any} argv Parsed command arguments @@ -525,8 +520,6 @@ _.assign(exports.builder, verify.builder); exports.run = async (argv, done) => { cli.argv = argv; - verifyDistro(argv); - const target = new Target(argv.dir); cli.debug(`Building distribution: ${target.distribution}`); @@ -551,7 +544,6 @@ exports.run = async (argv, done) => { const noAsar = process.env.NO_ASAR === 'true' || argv.no_asar; const tasks = _.flatten([ - () => verify.tasks(argv), task('copy npmrc from root', ({ dir }, done) => { fs.cp( path.resolve(dir, '..', '..', '.npmrc'), diff --git a/packages/hadron-build/commands/verify.js b/packages/hadron-build/commands/verify.js deleted file mode 100644 index 476569ea98f..00000000000 --- a/packages/hadron-build/commands/verify.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; -/** - * Wouldn't it be great if you or a CI system were notified properly - * that you aren't using the right version of node.js or npm? - * - * @see https://github.com/atom/atom/blob/master/script/utils/verify-requirements.js - */ - -const semver = require('semver'); -const cli = require('mongodb-js-cli')('hadron-build:verify'); -const { promisify } = require('util'); -const run = require('./../lib/run'); -const runAsync = promisify(run); - -exports.command = 'verify [options]'; -exports.describe = 'Verify the current environment meets the app\'s requirements.'; - -exports.builder = { - nodejs_version: { - describe: 'What version of node.js is required for this app?', - default: '^7.4.0' - }, - npm_version: { - describe: 'What version of npm is required for this app?', - default: '^4.0.0' - } -}; - -exports.tasks = (argv) => { - return exports.checkNpmAndNodejsVersions(argv); -}; - -exports.handler = (argv) => { - exports.tasks(argv).catch((err) => cli.abortIfError(err)); -}; - -exports.checkNpmAndNodejsVersions = async(opts) => { - const expectNodeVersion = opts.nodejs_version; - const expectNpmVersion = opts.npm_version; - const args = ['version', '--json', '--loglevel', 'error']; - const stdout = await runAsync('npm', args, {env: process.env, shell: true}); - const versions = JSON.parse(stdout); - - if (!semver.satisfies(versions.node, expectNodeVersion)) { - return new Error(`Your current node.js (v${versions.node}) ` + - `does not satisfy the version required by this project (v${expectNodeVersion}).`); - } else if (!semver.satisfies(versions.npm, expectNpmVersion)) { - return new Error(`Your current npm (v${versions.npm}) ` + - `does not meet the requirement ${expectNpmVersion}.`); - } - - return versions; -}; diff --git a/packages/hadron-build/index.js b/packages/hadron-build/index.js index d811147af8d..e76cf08e3d4 100644 --- a/packages/hadron-build/index.js +++ b/packages/hadron-build/index.js @@ -4,6 +4,5 @@ exports = function() {}; exports.release = require('./commands/release'); exports.upload = require('./commands/upload'); exports.download = require('./commands/download'); -exports.verify = require('./commands/verify'); module.exports = exports; diff --git a/packages/hadron-build/lib/distro.js b/packages/hadron-build/lib/distro.js deleted file mode 100644 index e5196ccf89b..00000000000 --- a/packages/hadron-build/lib/distro.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; -/** - * Verify the distribution is passed as an argument. - * - * @param {Object} argv - The arguments. - */ -const verifyDistribution = (argv) => { - if (argv._ && argv._[1]) { - process.env.HADRON_DISTRIBUTION = argv._[1]; - } -}; - -module.exports = verifyDistribution; diff --git a/packages/hadron-build/lib/target.js b/packages/hadron-build/lib/target.js index 77ccd01074c..e716adc35b8 100644 --- a/packages/hadron-build/lib/target.js +++ b/packages/hadron-build/lib/target.js @@ -101,12 +101,27 @@ class Target { this.pkg = pkg; const distributions = pkg.config.hadron.distributions; + const distribution = opts.distribution ?? process.env.HADRON_DISTRIBUTION; + + if (!distribution) { + throw new Error( + 'You need to explicitly set HADRON_DISTRIBUTION or pass `distribution` option to Target constructor before building Compass' + ); + } + + if (!supportedDistributions.includes(distribution)) { + throw new Error( + `Unknown distribution "${distribution}". Available distributions: ${supportedDistributions.join( + ', ' + )}` + ); + } _.defaults(opts, { version: process.env.HADRON_APP_VERSION }, pkg, { platform: process.platform, arch: process.arch, sign: true, - distribution: process.env.HADRON_DISTRIBUTION || distributions.default + distribution, }); this.distribution = opts.distribution; diff --git a/packages/hadron-build/test/fixtures/hadron-app/package.json b/packages/hadron-build/test/fixtures/hadron-app/package.json index 2ebf3eda63c..ae56155f2c6 100644 --- a/packages/hadron-build/test/fixtures/hadron-app/package.json +++ b/packages/hadron-build/test/fixtures/hadron-app/package.json @@ -42,6 +42,9 @@ "productName": "MongoDB Compass Enterprise super long test name", "plugins": [], "styles": [ "index" ] + }, + "foo-bar": { + "name": "foo-bar" } }, "endpoint": "https://hadron-app.herokuapp.com", diff --git a/packages/hadron-build/test/index.test.js b/packages/hadron-build/test/index.test.js index 714d24f7928..14af4320d14 100644 --- a/packages/hadron-build/test/index.test.js +++ b/packages/hadron-build/test/index.test.js @@ -14,13 +14,6 @@ describe('hadron-build', () => { expect(hadronBuild).to.be.a('function'); }); - describe('::release', () => { - it('should include options from commands::verify', () => { - expect(commands.release.builder).to.have.property('nodejs_version'); - expect(commands.release.builder).to.have.property('npm_version'); - }); - }); - describe('::test', () => { const DEFAULT_ARGS = { _: [], @@ -84,23 +77,4 @@ describe('hadron-build', () => { it('should spawn electron-mocha'); }); }); - - describe('::verify', () => { - it('should have a `nodejs_version` option', () => { - expect(commands.verify.builder).to.have.property('nodejs_version'); - }); - - it('should have a `npm_version` option', () => { - expect(commands.verify.builder).to.have.property('npm_version'); - }); - - it('should use `engines.node` for the default `nodejs_version` option'); - - it('should use `engines.npm` for the default `npm_version` option'); - - describe('::handler', () => { - it('should check the environment\'s npm installation'); - it('should check the environment\'s node.js installation'); - }); - }); }); diff --git a/packages/hadron-build/test/target.test.js b/packages/hadron-build/test/target.test.js index 740c77f14d8..666d4cd0086 100644 --- a/packages/hadron-build/test/target.test.js +++ b/packages/hadron-build/test/target.test.js @@ -39,7 +39,7 @@ describe('target', () => { it('allows to override distribution config with env vars', () => { Object.assign(process.env, { - HADRON_DISTRIBUTION: 'my-custom-distribution', + HADRON_DISTRIBUTION: 'compass-isolated', HADRON_PRODUCT: 'compass-compass', HADRON_PRODUCT_NAME: 'MongoDB Compass My Awesome Edition', HADRON_READONLY: 'true', @@ -49,7 +49,7 @@ describe('target', () => { const target = new Target(path.join(__dirname, 'fixtures', 'hadron-app')); - expect(target).to.have.property('distribution', 'my-custom-distribution'); + expect(target).to.have.property('distribution', 'compass-isolated'); expect(target).to.have.property('name', 'compass-compass'); expect(target).to.have.property( 'productName',