Skip to content

Commit

Permalink
Merge pull request #289 from kongregate/improved-yarn-support
Browse files Browse the repository at this point in the history
Improved yarn support
  • Loading branch information
felixrieseberg authored Aug 25, 2017
2 parents 46ad304 + 9d7e9b8 commit 5c867a7
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 9,428 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
npm-debug.log*
testem.log
browse.VC.db
yarn.lock
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
bower.json
ember-cli-build.js
testem.js
yarn.lock
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ cache:
yarn: true

before_install:
# We need at least 0.23.3 for the optional dependencies fix, otherwise
# electron-forge fails to install. This can be removed when travis updates
# their build image to a new enough yarn version.
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.27.5
- export PATH=$HOME/.yarn/bin:$PATH
- yarn config set no-progress
Expand Down
26 changes: 17 additions & 9 deletions lib/tasks/assemble.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const chalk = require('chalk');
const install = require('rsvp').denodeify(require('npmi'));
const execa = require('execa');
const { hasYarn } = require('yarn-or-npm');
const Task = require('ember-cli/lib/models/task');
const BuildTask = require('./build');
const Assembler = require('../models/assembler');
Expand Down Expand Up @@ -62,17 +63,24 @@ class AssembleTask extends Task {
});
}

pruneCommand() {
if (hasYarn()) {
return 'yarn install --production --no-bin-links';
} else {
return 'npm prune --production';
}
}

installDependencies(ui, path) {
ui.startProgress('installing production dependencies');

return install({
path,
npmLoad: {
production: true,
progress: false,
logLevel: 'error',
},
}).finally(() => {
let [command, ...args] = this.pruneCommand().split(' ');

return execa(
command,
args,
{ cwd: path }
).catch().then(() => {
ui.stopProgress();
});
}
Expand Down
10 changes: 9 additions & 1 deletion lib/utils/assemble-tree.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const { existsSync } = require('fs');
const Logger = require('./logger');
const { UnwatchedDir } = require('broccoli-source');

function hasEmberWelcomePage(pkg) {
return pkg && pkg.devDependencies && pkg.devDependencies['ember-welcome-page'];
Expand Down Expand Up @@ -64,6 +65,13 @@ this addon once you removed the {{welcome-page}} template tag.
let trees = [
writeFile('package.json', JSON.stringify(packageJson, null, ' ')),

new Funnel(new UnwatchedDir('.'), {
include: [
'npm-shrinkwrap.json',
'yarn.lock',
],
}),

new Funnel('ember-electron', {
files: ['.compilerc'],
}),
Expand Down Expand Up @@ -97,7 +105,7 @@ this addon once you removed the {{welcome-page}} template tag.

if (process.env.EMBER_ENV === 'test') {
// Overwrite main.js with test main.js
trees.push(new Funnel('.', {
trees.push(new Funnel(new UnwatchedDir('.'), {
destDir: 'ember-electron',
include: [
'tests/ember-electron/main.js',
Expand Down
2 changes: 1 addition & 1 deletion node-tests/acceptance/end-to-end-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('end-to-end', function() {
}).then(() => {
process.chdir('ee-test-app');

return ember('install', 'ember-electron@file:../package');
return ember('install', `ember-electron@file:${tmpDir}/package`);
}).then(() => {
// yarn has some kind of bug that causes it to hoist the wrong version of
// npmlog during one of the operations performed by the ember-electron
Expand Down
34 changes: 11 additions & 23 deletions node-tests/unit/tasks/assemble-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('AssembleTask', () => {
let assemblerFail;

let installOptions;
let installFail;

let task;

Expand Down Expand Up @@ -55,11 +54,11 @@ describe('AssembleTask', () => {
}
}

function mockInstall(options, cb) {
operations.push('install');
installOptions = clone(options);
function mockInstall(command, args, opts) {
operations.push('install-dependencies');
installOptions = opts;

return cb(installFail ? new Error('Failed to install') : undefined);
return resolve();
}

before(() => {
Expand All @@ -81,11 +80,10 @@ describe('AssembleTask', () => {
assemblerOptions = null;
assemblerFail = false;
installOptions = null;
installFail = false;

mockery.registerMock('./build', MockBuildTask);
mockery.registerMock('../models/assembler', MockAssembler);
mockery.registerMock('npmi', mockInstall);
mockery.registerMock('execa', mockInstall);

const AssembleTask = require('../../../lib/tasks/assemble');
task = new AssembleTask({
Expand All @@ -106,7 +104,7 @@ describe('AssembleTask', () => {
};

return task.run(options).then(() => {
expect(operations).to.deep.equal(['build', 'install']);
expect(operations).to.deep.equal(['build', 'install-dependencies']);

expect(buildTaskOptions.ui).to.equal(task.ui);
expect(buildTaskOptions.analytics).to.equal(task.analytics);
Expand All @@ -118,12 +116,7 @@ describe('AssembleTask', () => {
expect(buildRunOptions.platform).to.not.be.ok;

expect(installOptions).to.deep.equal({
path: 'output',
npmLoad: {
production: true,
progress: false,
logLevel: 'error',
},
cwd: 'output',
});
});
});
Expand All @@ -136,7 +129,7 @@ describe('AssembleTask', () => {
};

return task.run(options).then(() => {
expect(operations).to.deep.equal(['build', 'install']);
expect(operations).to.deep.equal(['build', 'install-dependencies']);

expect(buildRunOptions.environment).to.equal('test');
expect(buildRunOptions.platform).to.equal('linux');
Expand All @@ -161,7 +154,7 @@ describe('AssembleTask', () => {
};

return task.run(options).then(() => {
expect(operations).to.deep.equal(['assemble', 'cleanup', 'install']);
expect(operations).to.deep.equal(['assemble', 'cleanup', 'install-dependencies']);

expect(assemblerOptions.ui).to.equal(task.ui);
expect(assemblerOptions.platform).to.not.be.ok;
Expand All @@ -170,12 +163,7 @@ describe('AssembleTask', () => {
expect(assemblerOptions.project).to.equal(task.project);

expect(installOptions).to.deep.equal({
path: 'output',
npmLoad: {
production: true,
progress: false,
logLevel: 'error',
},
cwd: 'output',
});
});
});
Expand All @@ -188,7 +176,7 @@ describe('AssembleTask', () => {
};

return task.run(options).then(() => {
expect(operations).to.deep.equal(['assemble', 'cleanup', 'install']);
expect(operations).to.deep.equal(['assemble', 'cleanup', 'install-dependencies']);

expect(assemblerOptions.platform).to.equal('linux');
});
Expand Down
4 changes: 2 additions & 2 deletions node-tests/unit/tasks/build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('BuildTask', () => {
build() {
operations.push('build');

return failBuild ? reject() : resolve();
return failBuild ? reject('build rejection') : resolve('build resolution');
}

cleanup() {
operations.push('cleanup');

return resolve;
return resolve('cleanup resolve');
}
}

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@
"url": "https://github.com/felixrieseberg/ember-electron/issues"
},
"scripts": {
"test": "npm run test-node-all && npm run lint",
"test-fast": "npm run test-node && npm run lint",
"test": "yarn-or-npm run test-node-all && yarn-or-npm run lint",
"test-fast": "yarn-or-npm run test-node && yarn-or-npm run lint",
"test-node": "mocha node-tests/unit/**/*.js ./node-tests/integration/**/*.js",
"test-node-slow": "mocha ./node-tests/acceptance/**/*.js",
"test-node-all": "npm run test-node && npm run test-node-slow",
"test-node-all": "yarn-or-npm run test-node && yarn-or-npm run test-node-slow",
"lint": "eslint ./*.js app lib node-tests"
},
"dependencies": {
"broccoli-file-creator": "^1.1.1",
"broccoli-funnel": "^1.0.1",
"broccoli-merge-trees": "^2.0.0",
"broccoli-source": "^1.1.0",
"broccoli-string-replace": "^0.1.1",
"capture-exit": "^1.2.0",
"chalk": "^1.1.0",
"core-object": "^3.1.0",
"electron-forge": "3.0.0",
"electron-forge": "~3.1.1",
"electron-protocol-serve": "^1.3.0",
"ember-cli-babel": "^6.0.0",
"ember-cli-version-checker": "^1.1.6",
Expand All @@ -65,17 +66,17 @@
"globby": "^6.0.0",
"loader.js": "^4.2.3",
"lodash": "^4.15.0",
"npmi": "^2.0.1",
"quick-temp": "^0.1.5",
"rimraf": "^2.6.1",
"rsvp": "^3.2.1",
"rsvp": "^4.0.1",
"silent-error": "^1.0.1",
"socket.io": "^1.4.8",
"symlink-or-copy": "^1.1.8",
"testem": "^1.15.0",
"tmp": "0.0.31",
"tree-kill": "^1.1.0",
"tree-sync": "^1.2.2"
"tree-sync": "^1.2.2",
"yarn-or-npm": "^2.0.4"
},
"devDependencies": {
"babel-plugin-transform-async-to-generator": "^6.22.0",
Expand Down Expand Up @@ -112,8 +113,7 @@
"ncp": "^2.0.0",
"sinon": "^1.17.2",
"testdouble": "^2.1.2",
"walk-sync": "^0.3.1",
"yarn": "^0.23.2"
"walk-sync": "^0.3.1"
},
"engines": {
"node": ">= 6.0.0"
Expand Down
Loading

0 comments on commit 5c867a7

Please sign in to comment.