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

V2.0.0 #206

Merged
merged 16 commits into from Oct 5, 2018
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
- checkout
- run:
name: Update npm
command: 'sudo npm install -g npm@latest'
command: 'sudo npm install -g npm@6'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc
Expand Up @@ -53,7 +53,9 @@
],
"function-paren-newline": ["error", "consistent"],
"no-sequences": "off",
"global-require": "off",
"prefer-promise-reject-errors": "off",
"import/no-dynamic-require": "off",
"import/no-extraneous-dependencies": [
2,
{
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,7 @@ env:
before_install:
- nvm install $NODE_VERSION
- nvm use --delete-prefix $NODE_VERSION || echo
- if [[ $(npm -v) != 5* ]]; then npm i -g npm@5; fi;
- if [[ $(npm -v) != 6* ]]; then npm i -g npm@6; fi;
- npm install
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$TEST" == "integration" ]]; then
export DISPLAY=:99.0;
Expand Down
31 changes: 31 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,34 @@
## v2.0.0 <sup>02.10.2018</sup>

The main aim of this version is to decouple `electron`, `electron-builder` and `electron-packager` from this package.
Until now every `meteor-desktop` release came with specific versions of those pinned to it.
Now you are free to use any version with your meteor project. Just add them to your `devDependencies`.
If you will not, `meteor-desktop` will add the recommended versions automatically when needed.

From now every `meteor-desktop` release will provide a recommended versions numbers of these dependencies.
By default I will try to make `meteor-desktop` compatible within the compatibility version of the recommended version i.e. if the recommended electron version is `2.0.10` you should still be able to use any `2.x.x` version without problems.

**Recommended versions:**
* [`electron`](https://github.com/electron/electron) -> `2.0.10`
* [`electron-builder`](https://github.com/electron-userland/electron-builder) -> `20.28.4`


**BREAKING:**
* support for Squirrel autoupdate mechanism ended, if you wish to continue with add the `electron-builder-squirrel-windows` dependency to your `devDependencies` and move it's settings to `squirell` section in settings i.e.:
```
"squirell": {
"autoUpdateFeedUrl": "http://127.0.0.1/update/:platform/:version",
"autoUpdateFeedHeaders": {},
"autoUpdateCheckOnStart": true
},
```

## v1.7.0 <sup>28.09.2018</sup>
wojtkowiak marked this conversation as resolved.
Show resolved Hide resolved
* [`electron`](https://github.com/electron/electron) was updated to `2.0.10`
* [`electron-builder`](https://github.com/electron-userland/electron-builder) was updated to `20.28.4`
* `electron-builder-squirrel-windows` was updated to `20.28.3`
* new functionality/cli setting `--prod-debug` which forces devTools to be included in a production build, if you want this to be preserved after desktopHCP you need to run Meteor server with `METEOR_DESKTOP_PROD_DEBUG=1`

## v1.7.0 <sup>28.09.2018</sup>
* [`electron`](https://github.com/electron/electron) was updated to `2.0.10`
* [`electron-builder`](https://github.com/electron-userland/electron-builder) was updated to `20.28.4`
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -238,9 +238,9 @@ field|description
`desktopHCP`|whether to use `.desktop` hot code push module - [more](#desktophcp---desktop-hot-code-push)
<sup>`desktopHCPIgnoreCompatibilityVersion`</sup>|ignore the `.desktop` compatibility version and install new versions even if they can be incompatible
`desktopHCPCompatibilityVersion`|allows to override `.desktop` compatibility version
`autoUpdateFeedUrl`|url passed to [`autoUpdater.setFeedUrl`](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#autoupdatersetfeedurlurl-requestheaders), [more](#squirrel-autoupdate-support)
`autoUpdateFeedHeaders`|http headers passed to [`autoUpdater.setFeedUrl`](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#autoupdatersetfeedurlurl-requestheaders)
`autoUpdateCheckOnStart`|whether to check for updates on app start
`squirell.autoUpdateFeedUrl`| <sup>DEPRECATED</sup> url passed to [`autoUpdater.setFeedUrl`](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#autoupdatersetfeedurlurl-requestheaders), [more](#squirrel-autoupdate-support)
`squirell.autoUpdateFeedHeaders`| <sup>DEPRECATED</sup> http headers passed to [`autoUpdater.setFeedUrl`](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#autoupdatersetfeedurlurl-requestheaders)
`squirell.autoUpdateCheckOnStart`| <sup>DEPRECATED</sup> whether to check for updates on app start
`rebuildNativeNodeModules`|turn on or off recompiling native modules, [more](#native-modules-support)
`webAppStartupTimeout`|amount of time after which the downloaded version is considered faulty if Meteor app did not start - [more](#hot-code-push-support)
`exposeLocalFilesystem`|turns on or off local filesystem exposure over url alias, [more](#accessing-local-filesystem-in-meteor)
Expand Down
9 changes: 5 additions & 4 deletions appveyor.yml
Expand Up @@ -8,15 +8,16 @@ environment:
matrix:
- nodejs_version: "8"
test: "normal"
platform: x64
- nodejs_version: "8"
test: "integration"
platform: x64
- nodejs_version: "9"
test: "integration"
platform: x64
- nodejs_version: "9"
test: "normal"

platform:
- x64
platform: x64

cache:
- node_modules -> appveyor.yml
Expand All @@ -29,7 +30,7 @@ cache:

install:
- ps: Install-Product node $env:nodejs_version
- npm install -g npm@5
- npm install -g npm@6
- npm prune
- npm install
- ps: >-
Expand Down
6 changes: 6 additions & 0 deletions lib/defaultDependencies.js
@@ -0,0 +1,6 @@
module.exports = {
electron: '2.0.10',
'electron-builder': '20.28.4',
'electron-packager': '12.1.2'
};

2 changes: 1 addition & 1 deletion lib/dependenciesManager.js
Expand Up @@ -55,7 +55,7 @@ export default class DependenciesManager {
version: {
type: 'regex',
// Matches all the semver ranges operators, empty strings and `*`.
regex: /[|><= ~-]|\.x|$^|^\*$/,
regex: /[\^|><= ~-]|\.x|^$|^\*$/,
test: 'do not match',
message: 'semver ranges are forbidden, please specify exact version'
}
Expand Down
7 changes: 4 additions & 3 deletions lib/desktop.js
Expand Up @@ -227,9 +227,10 @@ export default class Desktop {
* @property {boolean} devTools
* @property {boolean} devtron
* @property {boolean} desktopHCP
* @property {string} autoUpdateFeedUrl
* @property {Object} autoUpdateFeedHeaders
* @property {Object} autoUpdateManualCheck
* @property {Object} squirell
* @property {string} squirell.autoUpdateFeedUrl
* @property {Object} squirell.autoUpdateFeedHeaders
* @property {Object} squirell.autoUpdateManualCheck

Choose a reason for hiding this comment

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

It's correct property name?

* @property {Object} desktopHCPSettings
* @property {boolean} desktopHCPSettings.ignoreCompatibilityVersion
* @property {boolean} desktopHCPSettings.blockAppUpdateOnDesktopIncompatibility
Expand Down
9 changes: 7 additions & 2 deletions lib/electron.js
@@ -1,7 +1,8 @@
import regeneratorRuntime from 'regenerator-runtime/runtime';
import spawn from 'cross-spawn';
import pathToElectron from 'electron';

import Log from './log';
import defaultDependencies from './defaultDependencies';

/**
* Simple Electron runner. Runs the project with the bin provided by the 'electron' package.
Expand All @@ -13,6 +14,10 @@ export default class Electron {
this.$ = $;
}

async init() {
this.electron = await this.$.getDependency('electron', defaultDependencies.electron);
}

run() {
// Until: https://github.com/electron-userland/electron-prebuilt/pull/118
const { env } = process;
Expand All @@ -26,7 +31,7 @@ export default class Electron {

cmd.push('.');

const child = spawn(pathToElectron, cmd, {
const child = spawn(this.electron.dependency, cmd, {
cwd: this.$.env.paths.electronApp.root,
env
});
Expand Down
64 changes: 22 additions & 42 deletions lib/electronApp.js
Expand Up @@ -11,12 +11,9 @@ import presetEnv from '@babel/preset-env';
import fs from 'fs';
import path from 'path';
import shell from 'shelljs';
import spawn from 'cross-spawn';
import semver from 'semver';
import uglify from 'terser';

import { getGypEnv } from 'app-builder-lib/out/util/yarn';

import Log from './log';
import ElectronAppScaffold from './electronAppScaffold';
import DependenciesManager from './dependenciesManager';
Expand Down Expand Up @@ -268,6 +265,16 @@ export default class ElectronApp {
this.compatibilityVersion = md5.digest('hex');
}

async init() {
try {
await this.$.electron.init();
await this.$.electronBuilder.init();
} catch (e) {
this.log.warn('error occurred while initialising electron and electron-builder integration', e);
process.exit(1);
}
}

/**
* Runs all necessary tasks to build the desktopified app.
*/
Expand All @@ -287,6 +294,9 @@ export default class ElectronApp {
}
}

await this.init();


try {
this.$.meteorApp.updateGitIgnore();
} catch (e) {
Expand Down Expand Up @@ -582,43 +592,6 @@ export default class ElectronApp {
}
}

/**
* NOT IN USE RIGHT NOW // DEPRECATED
*
* Wrapper for spawning npm.
* @param {Array} commands - commands for spawn
* @param {string} stdio
* @return {Promise}
*/
runNpm(commands, stdio = 'ignore') {
return new Promise((resolve, reject) => {
// TODO: find a way to run npm without depending on it cause it's a huge dependency.
let npm = path.join(
this.$.env.paths.meteorApp.root, 'node_modules', '.bin', 'npm'
);

if (!this.$.utils.exists(npm)) {
npm = path.join(
this.$.env.paths.meteorApp.root, 'node_modules', 'meteor-desktop', 'node_modules', '.bin', 'npm'
);
}

if (!this.$.utils.exists(npm)) {
npm = shell.which('npm');
}

this.log.verbose(`executing npm ${commands.join(' ')}`);

spawn(npm, commands, {
cwd: this.$.env.paths.electronApp.root,
stdio
}).on('exit', code => (
(code === 0) ? resolve() : reject(new Error(`npm exit code was ${code}`))
));
});
}


/**
* Runs npm link for every package specified in settings.json->linkPackages.
*/
Expand All @@ -631,7 +604,14 @@ export default class ElectronApp {
if ('linkPackages' in this.$.desktop.getSettings()) {
if (Array.isArray(settings.linkPackages)) {
settings.linkPackages.forEach(packageName =>
promises.push(this.runNpm(['link', packageName])));
promises.push(
this.$.meteorApp.runNpm(
['link', packageName],
undefined,
this.$.env.paths.electronApp.root
)
)
);
}
}
await Promise.all(promises);
Expand Down Expand Up @@ -728,7 +708,7 @@ export default class ElectronApp {
}
this.log.info('installing local node modules');
const lastRebuild = this.$.electronBuilder.prepareLastRebuildObject(arch);
const env = getGypEnv(lastRebuild.frameworkInfo, lastRebuild.platform, lastRebuild.arch);
const env = this.$.electronBuilder.getGypEnv(lastRebuild.frameworkInfo, lastRebuild.platform, lastRebuild.arch);
const installer = new LocalInstaller(
{ [this.$.env.paths.electronApp.root]: localDependencies },
{ npmEnv: env }
Expand Down
33 changes: 20 additions & 13 deletions lib/electronBuilder.js
@@ -1,14 +1,12 @@
// eslint-disable-next-line no-unused-vars
import regeneratorRuntime from 'regenerator-runtime/runtime';
import { build, Platform, createTargets } from 'electron-builder';
import { installOrRebuild } from 'app-builder-lib/out/util/yarn';
import { createLazyProductionDeps } from 'app-builder-lib/out/util/packageDependencies';
import shell from 'shelljs';
import path from 'path';
import fs from 'fs';
import rimraf from 'rimraf';
import spawn from 'cross-spawn';
import Log from './log';
import defaultDependencies from './defaultDependencies';

/**
* Promisfied rimraf.
Expand Down Expand Up @@ -51,6 +49,15 @@ export default class InstallerBuilder {
this.installerDir = path.join(this.$.env.options.output, this.$.env.paths.installerDir);
}

async init() {
this.builder = await this.$.getDependency('electron-builder', defaultDependencies['electron-builder']);
const appBuilder = await this.$.getDependency('app-builder-lib', defaultDependencies['electron-builder'], false);

this.yarn = require(path.join(appBuilder.path, 'out', 'util', 'yarn'));
this.getGypEnv = this.yarn.getGypEnv;
this.packageDependencies = require(path.join(appBuilder.path, 'out', 'util', 'packageDependencies'));
}

/**
* Prepares the last rebuild object for electron-builder.
*
Expand All @@ -59,7 +66,7 @@ export default class InstallerBuilder {
* @returns {Object}
*/
prepareLastRebuildObject(arch, platform = process.platform) {
const productionDeps = createLazyProductionDeps(this.$.env.paths.electronApp.root);
const productionDeps = this.packageDependencies.createLazyProductionDeps(this.$.env.paths.electronApp.root);
this.lastRebuild = {
frameworkInfo: { version: this.$.getElectronVersion(), useCustomDist: true },
platform,
Expand All @@ -79,7 +86,7 @@ export default class InstallerBuilder {
async installOrRebuild(arch, platform = process.platform, install = false) {
this.log.debug(`calling installOrRebuild from electron-builder for arch ${arch}`);
this.prepareLastRebuildObject(arch, platform);
await installOrRebuild(this.$.desktop.getSettings().builderOptions || {},
await this.yarn.installOrRebuild(this.$.desktop.getSettings().builderOptions || {},
this.$.env.paths.electronApp.root, this.lastRebuild, install);
}

Expand Down Expand Up @@ -278,25 +285,25 @@ export default class InstallerBuilder {
const targets = [];

if (this.$.env.options.win) {
targets.push(Platform.WINDOWS);
targets.push(this.builder.dependency.Platform.WINDOWS);
}
if (this.$.env.options.linux) {
targets.push(Platform.LINUX);
targets.push(this.builder.dependency.Platform.LINUX);
}
if (this.$.env.options.mac) {
targets.push(Platform.MAC);
targets.push(this.builder.dependency.Platform.MAC);
}

if (targets.length === 0) {
if (this.$.env.os.isWindows) {
targets.push(Platform.WINDOWS);
targets.push(this.builder.dependency.Platform.WINDOWS);
} else if (this.$.env.os.isLinux) {
targets.push(Platform.LINUX);
targets.push(this.builder.dependency.Platform.LINUX);
} else {
targets.push(Platform.MAC);
targets.push(this.builder.dependency.Platform.MAC);
}
}
return createTargets(targets, null, arch);
return this.builder.dependency.createTargets(targets, null, arch);
}

async build() {
Expand Down Expand Up @@ -324,7 +331,7 @@ export default class InstallerBuilder {

try {
this.log.debug('calling build from electron-builder');
await build(Object.assign({
await this.builder.dependency.build(Object.assign({
targets: this.prepareTargets(),
config: builderOptions
}, settings.builderCliOptions));
Expand Down