From 59bf5cb06d229c4b6e83a28332102162e85140c9 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 1 Aug 2017 10:25:17 -0400 Subject: [PATCH 1/4] [BUGFIX beta] Implement `cacheKeyForTree` hook. This hook was added in [ember-cli/rfcs#90](https://github.com/ember-cli/rfcs/blob/master/complete/0090-addon-tree-caching.md), and essentially guarantees that a given tree returned by an addon is considered stable (or not). In the case of Ember Data, we do not have different tree output based on our parent (project or addon). Specifically, this implementation allows both an app _and_ a lazy engine to depend on `ember-data` without duplicating the `ember-data` assets in both the `assets/vendor.js` and `engine-dist//assets/engine-vendor.js`. --- index.js | 6 +++++- package.json | 1 + yarn.lock | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index de266d8599d..533c4c1c69b 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ const merge = require('broccoli-merge-trees'); const semver = require('semver'); const version = require('./lib/version'); const BroccoliDebug = require('broccoli-debug'); +const calculateCacheKeyForTree = require('calculate-cache-key-for-tree'); // allow toggling of heimdall instrumentation let INSTRUMENT_HEIMDALL = false; @@ -213,6 +214,9 @@ module.exports = { production: app.bowerDirectory + '/ember-data/ember-data.prod.js' }); } + }, + + cacheKeyForTree(treeType) { + return calculateCacheKeyForTree(treeType, this); } }; - diff --git a/package.json b/package.json index 7150226bca7..5d40e736268 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "broccoli-funnel": "^1.2.0", "broccoli-merge-trees": "^2.0.0", "broccoli-rollup": "^1.2.0", + "calculate-cache-key-for-tree": "^1.1.0", "chalk": "^1.1.1", "ember-cli-babel": "^6.4.1", "ember-cli-path-utils": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index aebf82223c6..7a7783e870c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1490,6 +1490,12 @@ calculate-cache-key-for-tree@^1.0.0: dependencies: json-stable-stringify "^1.0.1" +calculate-cache-key-for-tree@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/calculate-cache-key-for-tree/-/calculate-cache-key-for-tree-1.1.0.tgz#0c3e42c9c134f3c9de5358c0f16793627ea976d6" + dependencies: + json-stable-stringify "^1.0.1" + caller-path@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" From 49a66fe3b10bdddb5b53ff7912b209eecb808e03 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sun, 13 Aug 2017 09:44:47 -0400 Subject: [PATCH 2/4] Ensure CI has latest yarn. The bizarre failures on CI are related to the super old Yarn version in use on the Trusty arch (0.17.5), and seem to randomly fail based on which CI image a build runs on (super frustratingly :P ). This updates our Travis config to ensure the latest yarn is installed (and also updates the mechansim we use to get phantom so that it works across both Trusty and Precise images). --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6beab2f203..eae503cb0af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ --- language: node_js sudo: false +dist: trusty node_js: - "7" @@ -8,14 +9,13 @@ cache: yarn: true before_install: - - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH" - - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi" - - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi" - - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi" - - "phantomjs --version" + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH=$HOME/.yarn/bin:$PATH + - yarn global add phantomjs-prebuilt + - phantomjs --version install: - - yarn + - yarn install --no-lockfile --no-interactive - ./node_modules/.bin/bower install script: From 968cdf56acb1b57e7604b77abcead6f55344a1f1 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sun, 13 Aug 2017 09:54:06 -0400 Subject: [PATCH 3/4] Remove Bower dependency and related files. --- .bowerrc | 4 ---- .travis.yml | 1 - appveyor.yml | 2 -- bower.json | 5 ----- package.json | 2 -- 5 files changed, 14 deletions(-) delete mode 100644 .bowerrc delete mode 100644 bower.json diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 869443b22d5..00000000000 --- a/.bowerrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "directory": "bower_components", - "interactive": false -} diff --git a/.travis.yml b/.travis.yml index d6beab2f203..cf8981d4851 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ before_install: install: - yarn - - ./node_modules/.bin/bower install script: - ./bin/lint-features diff --git a/appveyor.yml b/appveyor.yml index 913d6ace70b..63705cde3e1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,8 +19,6 @@ install: # Typical npm stuff. - md C:\nc - appveyor-retry yarn install - # Workaround https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows - - yarn run bower # Post-install test scripts. test_script: # Output useful info for debugging. diff --git a/bower.json b/bower.json deleted file mode 100644 index c55b4668708..00000000000 --- a/bower.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "ember-data", - "license": "MIT", - "dependencies": {} -} diff --git a/package.json b/package.json index 7150226bca7..dda7942c095 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "node-tests": "node node-tests/nodetest-runner.js", "test:optional-features": "ember test --environment=test-optional-features", "test:production": "ember test --environment=production", - "bower": "bower install", "production": "ember build --environment=production" }, "author": "", @@ -61,7 +60,6 @@ "babel-plugin-transform-es2015-shorthand-properties": "^6.22.0", "babel-plugin-transform-es2015-spread": "^6.22.0", "babel-plugin-transform-es2015-template-literals": "^6.22.0", - "bower": "^1.6.5", "broccoli-asset-rev": "^2.4.5", "broccoli-concat": "^3.2.2", "broccoli-stew": "^1.4.2", From 8ab2a59d54ebcf25493792db0d1b185ae76e4f0b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 14 Aug 2017 10:19:07 -0400 Subject: [PATCH 4/4] Avoid MODEL_FACTORY_INJECTION deprecations in tests on Ember >= 2.14. --- tests/dummy/app/app.js | 5 ++++- tests/helpers/model-factory-injection.js | 14 ++++++++++++++ tests/integration/injection-test.js | 9 ++++++--- .../integration/relationships/belongs-to-test.js | 2 -- tests/integration/relationships/has-many-test.js | 9 ++++++--- .../polymorphic-mixins-belongs-to-test.js | 15 +++++++++------ .../polymorphic-mixins-has-many-test.js | 16 +++++++++------- 7 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 tests/helpers/model-factory-injection.js diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 831ad6106dd..394ec74d45e 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -2,10 +2,13 @@ import Ember from 'ember'; import Resolver from './resolver'; import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; +import { + setup as setupModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; let App; -Ember.MODEL_FACTORY_INJECTIONS = true; +setupModelFactoryInjections(); App = Ember.Application.extend({ modulePrefix: config.modulePrefix, diff --git a/tests/helpers/model-factory-injection.js b/tests/helpers/model-factory-injection.js new file mode 100644 index 00000000000..aad65f95ade --- /dev/null +++ b/tests/helpers/model-factory-injection.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import hasEmberVersion from 'ember-test-helpers/has-ember-version'; + +let ORIGINAL_MODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; + +export function setup(value = true) { + if (!hasEmberVersion(2, 14)) { + Ember.MODEL_FACTORY_INJECTIONS = value; + } +} + +export function reset() { + setup(ORIGINAL_MODEL_FACTORY_INJECTIONS); +} diff --git a/tests/integration/injection-test.js b/tests/integration/injection-test.js index c24c4bdacbe..dfbc603ff05 100644 --- a/tests/integration/injection-test.js +++ b/tests/integration/injection-test.js @@ -1,10 +1,13 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import DS from 'ember-data'; import { module, test } from 'qunit'; let env, hasFactoryFor, originalLookupFactory, originalOwnerLookupFactory, originalFactoryFor; -let originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; const { run } = Ember; const model = { @@ -79,7 +82,7 @@ test('modelFor', function(assert) { module('integration/injection eager injections', { setup() { - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); env = setupStore(); env.registry.injection('model:foo', 'apple', 'service:apple'); @@ -90,7 +93,7 @@ module('integration/injection eager injections', { teardown() { // can be removed once we no longer support ember versions without lookupFactory - Ember.MODEL_FACTORY_INJECTIONS = originalMODEL_FACTORY_INJECTIONS; + resetModelFactoryInjections(); run(env.store, 'destroy'); } diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 88fa6b08f0e..9eb75ce1f09 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -11,7 +11,6 @@ const { attr, hasMany, belongsTo } = DS; const { hash } = RSVP; let env, store, User, Message, Post, Comment, Book, Chapter, Author, NewMessage; -const injectionValue = Ember.MODEL_FACTORY_INJECTIONS; module("integration/relationship/belongs_to Belongs-To Relationships", { beforeEach() { @@ -83,7 +82,6 @@ module("integration/relationship/belongs_to Belongs-To Relationships", { }, afterEach() { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index e359df81d27..0db8908dd08 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -1,5 +1,9 @@ /*eslint no-unused-vars: ["error", { "args": "none", "varsIgnorePattern": "(page)" }]*/ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -1338,8 +1342,7 @@ test("When a polymorphic hasMany relationship is accessed, the store can call mu test("polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_INJECTIONS is enabled", function(assert) { assert.expect(1); - let injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { run(function () { @@ -1351,7 +1354,7 @@ test("polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_IN assert.equal(igor.get('messages.firstObject.body'), "Well I thought the title was fine"); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 9439b60d168..f62f41e22d1 100644 --- a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -1,3 +1,8 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; + import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -155,8 +160,7 @@ testInDebug("Setting the polymorphic belongsTo with an object that does not impl test("Setting the polymorphic belongsTo gets propagated to the inverse side - model injections true", function(assert) { assert.expect(2); - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -190,13 +194,12 @@ test("Setting the polymorphic belongsTo gets propagated to the inverse side - mo }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); testInDebug("Setting the polymorphic belongsTo with an object that does not implement the mixin errors out - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -226,6 +229,6 @@ testInDebug("Setting the polymorphic belongsTo with an object that does not impl }, /You cannot add a record of modelClass 'not-message' to the 'user.bestMessage' relationship \(only 'message' allowed\)/); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js index 9141b088522..8993ad3f8c4 100644 --- a/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -1,3 +1,8 @@ +import { + setup as setupModelFactoryInjections, + reset as resetModelFactoryInjections +} from 'dummy/tests/helpers/model-factory-injection'; + import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; @@ -170,8 +175,7 @@ testInDebug("Pushing a an object that does not implement the mixin to the mixin }); test("Pushing to the hasMany reflects the change on the belongsTo side - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user, video; @@ -209,7 +213,7 @@ test("Pushing to the hasMany reflects the change on the belongsTo side - model i }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); @@ -217,8 +221,7 @@ test("Pushing to the hasMany reflects the change on the belongsTo side - model i Local edits */ testInDebug("Pushing a an object that does not implement the mixin to the mixin accepting array errors out - model injections true", function(assert) { - var injectionValue = Ember.MODEL_FACTORY_INJECTIONS; - Ember.MODEL_FACTORY_INJECTIONS = true; + setupModelFactoryInjections(); try { var user,notMessage; @@ -255,7 +258,6 @@ testInDebug("Pushing a an object that does not implement the mixin to the mixin }); }); } finally { - Ember.MODEL_FACTORY_INJECTIONS = injectionValue; + resetModelFactoryInjections(); } }); -