From 00df008f874c2719c1253c217ecd10243d5fdb21 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Tue, 9 Apr 2019 13:48:51 -0700 Subject: [PATCH] [FEAT packages] introduce build-infra package --- .eslintrc.js | 3 +- .travis.yml | 7 +- CONTRIBUTING.md | 73 +++++++++--- appveyor.yml | 2 +- bin/lint-features | 28 +++-- package.json | 27 ++--- packages/-build-infra/.npmignore | 15 +++ packages/-build-infra/.watchmanconfig | 3 + packages/-build-infra/LICENSE.md | 9 ++ packages/-build-infra/README.md | 11 ++ .../bin/test-external-partner-project.js} | 41 +++++-- .../config/in-progress-features.json} | 0 packages/-build-infra/package.json | 36 ++++++ .../addon-build-config-for-data-package.js | 55 +++++++++ packages/-build-infra/src/cli-flags.js | 33 ++++++ .../src/create-version-module.js} | 7 +- .../src/stripped-build-plugins.js | 109 ++++++++++++++++++ .../transforms/babel-plugin-remove-imports.js | 0 .../src}/transforms/package.json | 0 .../extend-from-application-entity.js | 0 .../src}/utilities/module-unification.js | 0 packages/-ember-data/.npmignore | 1 - packages/-ember-data/FEATURES.md | 14 --- .../blueprints/adapter-test/index.js | 2 +- .../-ember-data/blueprints/adapter/index.js | 4 +- .../blueprints/model-test/index.js | 2 +- .../-ember-data/blueprints/model/index.js | 2 +- .../blueprints/serializer-test/index.js | 2 +- .../blueprints/serializer/index.js | 4 +- .../blueprints/transform-test/index.js | 2 +- .../-ember-data/blueprints/transform/index.js | 2 +- packages/-ember-data/index.js | 48 +------- packages/-ember-data/lib/cli-flags.js | 9 -- .../-ember-data/lib/stripped-build-plugins.js | 67 ----------- packages/-ember-data/lib/version-replace.js | 13 --- packages/-ember-data/lib/version.js | 6 - .../unit/babel-plugin-remove-imports-test.js | 2 +- packages/-ember-data/package.json | 28 +---- .../tests/dummy/config/environment.js | 11 -- packages/adapter/ember-cli-build.js | 4 +- packages/adapter/index.js | 7 +- packages/adapter/package.json | 4 +- packages/model/ember-cli-build.js | 4 +- packages/model/index.js | 7 +- packages/model/package.json | 5 +- packages/serializer/ember-cli-build.js | 4 +- packages/serializer/index.js | 7 +- packages/serializer/package.json | 4 +- packages/store/ember-cli-build.js | 4 +- packages/store/index.js | 37 +----- packages/store/lib/cli-flags.js | 9 -- packages/store/lib/stripped-build-plugins.js | 67 ----------- .../transforms/babel-plugin-remove-imports.js | 60 ---------- packages/store/lib/transforms/package.json | 3 - .../extend-from-application-entity.js | 63 ---------- .../store/lib/utilities/module-unification.js | 7 -- packages/store/package.json | 5 +- yarn.lock | 9 +- 58 files changed, 457 insertions(+), 531 deletions(-) create mode 100644 packages/-build-infra/.npmignore create mode 100644 packages/-build-infra/.watchmanconfig create mode 100644 packages/-build-infra/LICENSE.md create mode 100644 packages/-build-infra/README.md rename packages/{-ember-data/lib/scripts/test-external.js => -build-infra/bin/test-external-partner-project.js} (76%) mode change 100644 => 100755 rename packages/{-ember-data/config/features.json => -build-infra/config/in-progress-features.json} (100%) create mode 100644 packages/-build-infra/package.json create mode 100644 packages/-build-infra/src/addon-build-config-for-data-package.js create mode 100644 packages/-build-infra/src/cli-flags.js rename packages/{-ember-data/lib/calculate-version.js => -build-infra/src/create-version-module.js} (80%) create mode 100644 packages/-build-infra/src/stripped-build-plugins.js rename packages/{-ember-data/lib => -build-infra/src}/transforms/babel-plugin-remove-imports.js (100%) rename packages/{-ember-data/lib => -build-infra/src}/transforms/package.json (100%) rename packages/{-ember-data/lib => -build-infra/src}/utilities/extend-from-application-entity.js (100%) rename packages/{-ember-data/lib => -build-infra/src}/utilities/module-unification.js (100%) delete mode 100644 packages/-ember-data/FEATURES.md delete mode 100644 packages/-ember-data/lib/cli-flags.js delete mode 100644 packages/-ember-data/lib/stripped-build-plugins.js delete mode 100644 packages/-ember-data/lib/version-replace.js delete mode 100644 packages/-ember-data/lib/version.js delete mode 100644 packages/store/lib/cli-flags.js delete mode 100644 packages/store/lib/stripped-build-plugins.js delete mode 100644 packages/store/lib/transforms/babel-plugin-remove-imports.js delete mode 100644 packages/store/lib/transforms/package.json delete mode 100644 packages/store/lib/utilities/extend-from-application-entity.js delete mode 100644 packages/store/lib/utilities/module-unification.js diff --git a/.eslintrc.js b/.eslintrc.js index 3b57edf568f..521071dd93a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,6 +46,7 @@ module.exports = { files: [ '.eslintrc.js', '.prettierrc.js', + 'packages/-build-infra/src/**/*.js', 'packages/*/ember-cli-build.js', 'packages/*/index.js', 'packages/*/testem.js', @@ -76,7 +77,7 @@ module.exports = { // node tests { - files: ['packages/*/node-tests/**'], + files: ['packages/*/node-tests/**', 'node-tests/**'], env: { mocha: true, diff --git a/.travis.yml b/.travis.yml index 95eb32823a0..14bb48ffe85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ stages: jobs: fail_fast: true allow_failures: - - name: "emberaddons.com" + - name: 'Ember Data Factory Guy' include: # runs tests with current locked deps and linting @@ -46,10 +46,11 @@ jobs: script: yarn test - stage: additional tests - name: 'Optional Features' + + name: 'Enabled In-Progress Features' if: NOT (branch ~= /^(release|lts).*/) install: yarn install - script: yarn test:optional-features + script: yarn test:enabled-in-progress-features - name: 'Floating Dependencies' install: yarn install --no-lockfile --non-interactive diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb6496570af..4b7ba2e3a77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,23 +106,65 @@ All commits should be tagged. Tags are denoted by square brackets (`[]`) and com In general almost all commits should fall into one of the above categories. In the cases where they don't please submit your PR untagged. -#### Developing a New Feature with Feature Flags +#### Developing a New Feature with in-progress-feature Flags -Sometimes a new feature will require use of a feature flag. +Sometimes a new feature can't be completed all at once, but portions +of it can be landed to help parallelize the effort and make the review +process simpler. -Feature flags allow new features to be tested in dev builds, but -the features are stripped out of production builds automatically. +`in-progress-feature` flags allow for code to be present on the `master` +branch but stripped from any build that isn't. -1. Add your new feature flag to the [config/features.json](https://github.com/emberjs/data/blob/master/config/features.json) file. +These flags have three states. Locally here means that a developer is +working within the `addon` itself. Locally linking `ember-data` to +another project or using a `master` build will not make code behind +the flags available unless `isDevelopingAddon` in `index.js` is modified +to return `true`. + +- `false`: the feature is only available locally and the code behind the + flag is stripped at all times and never included in test runs. To develop + on this feature use `--enable-in-progress-flag="desired-flag-name,another-flag-name"` + when running a command. This flag will never be active in `CI` jobs + meaning that both tests and code wrapped in a check for this flag will + not run. + +- `null`: The same as `false` except the `Enabled In-Progress Features` + job in `CI` will activate the flag to ensure it passes tests. + Use this for features that are nearing delivery and need protection + against regressions but are not quite polished off yet. + + Other test runs and `CI` will still default the flag to `false` to ensure + that what we would release (were we to release master) works as + expected. + + The `--enable-in-progress` flag and the Travis Job `Enabled In-Progress Features` + will run the tests with any flags set to `null` enabled to prevent + regressions. + +- `true`: Indicates that this feature is "complete". Features set to + `true` will be included in any `release` published while the flag + is in that state, any build from `master` and all `CI` jobs. + + This is a sign that the feature has entered a final testing phase + and the in-progress flags for the feature should be removed + before a stable release is published. + + Sometimes a nearly releasable feature may encounter problems late + in the release cycle. For such problems, the flag should be moved + back to the `null` state prior to doing a release. + + Versions published with a flag set to `true` will include that + feature. + +1. Add your new feature flag to the [config/in-progress-features.json](https://github.com/emberjs/data/blob/master/config/in-progress-features.json) file with the `ds-` prefix. ```js { - "ds-boolean-transform-allow-null": null, - "ds-mynew-feature": null + "ds-mynew-feature": false } ``` -Give it a default of `null` so it will not be used in production builds. +Give it a default of `false` so it will not be used in production builds. 2. Import `isEnabled` from `ember-data/-private`, wrapping any new code with your feature: @@ -152,19 +194,12 @@ if (isEnabled('ds-mynew-feature')) { This will ensure these feature tests are only run when then feature is included in the build for `ember-data`. -4. Running tests with all feature flags enabled is possible via - `ember test --environment=test-optional-features` This is also possible while - running tests in the browser via the `Enable Opt Feature` checkbox. - -5. Add your feature to the [Features](https://github.com/emberjs/data/blob/master/FEATURES.md) file. - Be sure to leave a description of the feature and possible example of how to - use it (if necessary). - -For more information about commit prefixes see [Commit Tagging](#commit-tagging). +4. Commit your work. For more information about commit prefixes see [Commit Tagging](#commit-tagging). -6. Push to your fork and submit a pull request. Please provide us with some +5. Push to your fork and submit a pull request. Please provide us with some explanation of why you made the changes you made. For new features make sure to - explain a standard use case to us. + explain a standard use case to us. Use the commit tagging guidelines for the PR + title. ## Notes diff --git a/appveyor.yml b/appveyor.yml index e9c2b5b7759..c55a0e5eba4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,7 +19,7 @@ install: test_script: # Output useful info for debugging. - cmd: yarn test - - cmd: yarn test:optional-features + - cmd: yarn test:enabled-in-progress-features - cmd: yarn test:production - cmd: yarn test:node diff --git a/bin/lint-features b/bin/lint-features index 7c0eda5d7ea..adbd634940c 100755 --- a/bin/lint-features +++ b/bin/lint-features @@ -2,27 +2,25 @@ const fs = require('fs'); const path = require('path'); -const PKG_ROOT = path.join(__dirname, '../packages'); -const PATH_TO_CONFIG = 'config/features.json'; -const packages = fs.readdirSync(PKG_ROOT); +const configPath = path.join( + __dirname, + '../packages/-build-infra/config/in-progress-features.json' +); const beginsWithDS = /^ds-/; const violations = []; -packages.forEach(function(package) { - const configPath = path.join(PKG_ROOT, package, PATH_TO_CONFIG); - if (fs.existsSync(configPath)) { - const features = require(configPath); - Object.keys(features).forEach(function(feature) { - if (!beginsWithDS.exec(feature)) { - violations.push('"' + feature + '" in @ember-data/' + package); - } - }); - } -}); +if (fs.existsSync(configPath)) { + const features = require(configPath); + Object.keys(features).forEach(function(feature) { + if (!beginsWithDS.exec(feature)) { + violations.push(feature); + } + }); +} if (violations.length) { console.log( - 'Features in features.json MUST begin with `ds-`! These features do not:\n\t', + 'Features in in-progress-features.json MUST begin with `ds-`! These features do not:\n\t', violations.join('\n\t') ); process.exit(1); diff --git a/package.json b/package.json index c54e9891c91..be679ef98cd 100644 --- a/package.json +++ b/package.json @@ -15,21 +15,20 @@ "test:node": "yarn workspace ember-data node node-tests/nodetest-runner.js", "test:production": "yarn workspace ember-data test:production", "test:try-one": "yarn workspace ember-data test:try-one", - "test:optional-features": "yarn workspace ember-data test:optional-features", - "test-external:ember-m3": "yarn workspace ember-data test-external:ember-m3", - "test-external:ember-data-change-tracker": "yarn workspace ember-data test-external:ember-data-change-tracker", - "test-external:emberaddons.com": "yarn workspace ember-data test-external:emberaddons.com", - "test-external:model-fragments": "yarn workspace ember-data test-external:model-fragments", - "test-external:ember-observer": "yarn workspace ember-data test-external:ember-observer", - "test-external:travis-web": "yarn workspace ember-data test-external:travis-web", - "test-external:storefront": "yarn workspace ember-data test-external:storefront", - "test-external:factory-guy": "yarn workspace ember-data test-external:factory-guy", - "test-external:ilios-frontend": "yarn workspace ember-data test-external:ilios-frontend", - "test-external:ember-resource-metadata": "yarn workspace ember-data test-external:ember-resource-metadata", - "test-external:ember-data-relationship-tracker": "yarn workspace ember-data test-external:ember-data-relationship-tracker" + "test:enabled-in-progress-features": "yarn workspace ember-data test --enable-in-progress", + "test-external:ember-m3": "test-external-partner ember-m3 https://github.com/hjdivad/ember-m3.git", + "test-external:ember-data-change-tracker": "test-external-partner ember-data-change-tracker https://github.com/danielspaniel/ember-data-change-tracker.git", + "test-external:emberaddons.com": "test-external-partner ember-cli-addon-search https://github.com/gcollazo/ember-cli-addon-search.git", + "test-external:model-fragments": "test-external-partner ember-data-model-fragments https://github.com/lytics/ember-data-model-fragments.git", + "test-external:ember-observer": "test-external-partner ember-observer https://github.com/emberobserver/client.git", + "test-external:travis-web": "test-external-partner travis-web https://github.com/travis-ci/travis-web.git", + "test-external:storefront": "test-external-partner storefront https://github.com/embermap/ember-data-storefront.git", + "test-external:factory-guy": "test-external-partner factory-guy https://github.com/danielspaniel/ember-data-factory-guy.git", + "test-external:ilios-frontend": "test-external-partner ilios-frontend https://github.com/ilios/frontend.git --skip-smoke-test", + "test-external:ember-resource-metadata": "test-external-partner ember-resource-metadata https://github.com/ef4/ember-resource-metadata.git", + "test-external:ember-data-relationship-tracker": "test-external-partner ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git" }, "devDependencies": { - "lerna": "^3.13.2", "@babel/plugin-transform-typescript": "^7.2.0", "@ember-decorators/babel-transforms": "^5.2.0", "@ember-decorators/data": "^5.1.4", @@ -61,6 +60,7 @@ "ember-cli-pretender": "^3.1.1", "ember-cli-shims": "^1.2.0", "ember-cli-sri": "^2.1.1", + "ember-cli-string-utils": "^1.1.0", "ember-cli-test-loader": "^2.2.0", "ember-cli-typescript-blueprints": "^2.0.0-beta.1", "ember-cli-uglify": "2.1.0", @@ -84,6 +84,7 @@ "github": "^1.1.1", "glob": "^7.1.3", "json-typescript": "^1.1.0", + "lerna": "^3.13.2", "loader.js": "^4.7.0", "mocha": "^6.1.2", "mocha-only-detector": "1.0.0", diff --git a/packages/-build-infra/.npmignore b/packages/-build-infra/.npmignore new file mode 100644 index 00000000000..aec6952e146 --- /dev/null +++ b/packages/-build-infra/.npmignore @@ -0,0 +1,15 @@ +# compiled output +/dist/ +/tmp/ + +# misc +/.bowerrc +/.editorconfig +/.env* +/.gitignore +/.watchmanconfig +/CONTRIBUTING.md +/testem.js +/tests/ +/yarn.lock +.gitkeep diff --git a/packages/-build-infra/.watchmanconfig b/packages/-build-infra/.watchmanconfig new file mode 100644 index 00000000000..e7834e3e4f3 --- /dev/null +++ b/packages/-build-infra/.watchmanconfig @@ -0,0 +1,3 @@ +{ + "ignore_dirs": ["tmp", "dist"] +} diff --git a/packages/-build-infra/LICENSE.md b/packages/-build-infra/LICENSE.md new file mode 100644 index 00000000000..f8d1edb3b7d --- /dev/null +++ b/packages/-build-infra/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2019 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/-build-infra/README.md b/packages/-build-infra/README.md new file mode 100644 index 00000000000..6b5e98b4260 --- /dev/null +++ b/packages/-build-infra/README.md @@ -0,0 +1,11 @@ +# @ember-data/-build-infra + +!! This is an internal package for use by `@ember-data` only. !! + +This package provides utilities for configuring addon-build setup +for `@ember-data/` packages. It is directly depended upon by those +packages and should not be installed for use in an app directly. + +## License + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/packages/-ember-data/lib/scripts/test-external.js b/packages/-build-infra/bin/test-external-partner-project.js old mode 100644 new mode 100755 similarity index 76% rename from packages/-ember-data/lib/scripts/test-external.js rename to packages/-build-infra/bin/test-external-partner-project.js index ae15cfbc03a..1498a05b5f7 --- a/packages/-ember-data/lib/scripts/test-external.js +++ b/packages/-build-infra/bin/test-external-partner-project.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + 'use strict'; /* eslint-disable no-console, node/no-extraneous-require, node/no-unpublished-require */ const fs = require('fs'); @@ -7,7 +9,7 @@ const { shellSync } = require('execa'); const debug = require('debug')('test-external'); const rimraf = require('rimraf'); -const projectRoot = path.resolve(__dirname, '../../'); +const projectRoot = path.resolve(__dirname, '../'); const externalProjectName = process.argv[2]; const gitUrl = process.argv[3]; const skipSmokeTest = process.argv[4] && process.argv[4] === '--skip-smoke-test'; @@ -17,11 +19,11 @@ const projectTempDir = path.join(tempDir, externalProjectName); if (!gitUrl) { throw new Error( - 'No git url provided to `node ./lib/scripts/test-external`. An https git url should be the first argument.' + 'No git url provided to `test-external-partner`. An https git url should be the first argument.' ); } else if (gitUrl.indexOf('https') !== 0) { throw new Error( - `The git url provided to \`node ./lib/scripts/test-external\` should use https. Received '${gitUrl}'` + `The git url provided to \`node test-external-partner\` should use https. Received '${gitUrl}'` ); } @@ -43,10 +45,12 @@ function execWithLog(command, force) { } if (!fs.existsSync(tempDir)) { + debug(`Ensuring Cache Root at: ${tempDir}`); fs.mkdirSync(tempDir); } if (fs.existsSync(projectTempDir)) { + debug(`Cleaning Cache at: ${projectTempDir}`); rimraf.sync(projectTempDir); } @@ -56,25 +60,40 @@ try { } catch (e) { debug(e); throw new Error( - `Install of ${gitUrl} for external project ${externalProjectName} testing failed.` + `Install of ${gitUrl} in ${projectTempDir} for external project ${externalProjectName} testing failed.` ); } const useYarn = fs.existsSync(path.join(projectTempDir, 'yarn.lock')); -const npmInstall = ` -cd ../adapter; npm link; -cd ../store; npm link @ember-data/adapter; npm link; -cd ../serializer; npm link @ember-data/store; npm link; -cd ../model; npm link @ember-data/store; npm link; +const npmLink = ` +npm link; +cd ../adapter; +npm link @ember-data/-build-infra; +npm link; +cd ../store; +npm link @ember-data/-build-infra; +npm link @ember-data/adapter; +npm link; +cd ../serializer; +npm link @ember-data/-build-infra; +npm link @ember-data/store; +npm link; +cd ../model; +npm link @ember-data/-build-infra; +npm link @ember-data/store; +npm link; cd ../-ember-data; -npm link @ember-data/adapter; npm link @ember-data/store;npm link @ember-data/serializer; +npm link @ember-data/-build-infra; +npm link @ember-data/adapter; +npm link @ember-data/store; +npm link @ember-data/serializer; npm link @ember-data/model; npm link; `; // install project dependencies and link our local version of ember-data try { - execWithLog(`${useYarn ? 'yarn link' : npmInstall}`); + execWithLog(`${useYarn ? 'yarn link' : npmLink}`); execExternal(`${useYarn ? 'yarn' : 'npm install'}`); } catch (e) { debug(e); diff --git a/packages/-ember-data/config/features.json b/packages/-build-infra/config/in-progress-features.json similarity index 100% rename from packages/-ember-data/config/features.json rename to packages/-build-infra/config/in-progress-features.json diff --git a/packages/-build-infra/package.json b/packages/-build-infra/package.json new file mode 100644 index 00000000000..d0d25c8b1d2 --- /dev/null +++ b/packages/-build-infra/package.json @@ -0,0 +1,36 @@ +{ + "name": "@ember-data/-build-infra", + "version": "0.0.0", + "description": "The default blueprint for ember-data private packages.", + "keywords": [], + "repository": "", + "license": "MIT", + "author": "", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "prepublishOnly": "ember ts:precompile", + "postpublish": "ember ts:clean" + }, + "dependencies": { + "babel-plugin-feature-flags": "^0.3.1", + "babel-plugin-filter-imports": "^2.0.4", + "babel6-plugin-strip-class-callcheck": "^6.0.0", + "broccoli-file-creator": "^2.1.1", + "git-repo-info": "^2.0.0", + "npm-git-info": "^1.0.3", + "ember-cli-string-utils": "^1.1.0", + "calculate-cache-key-for-tree": "^1.1.0", + "silent-error": "^1.1.1", + "ember-cli-path-utils": "^1.0.0" + }, + "bin": { + "test-external-partner": "./bin/test-external-partner-project.js" + }, + "devDependencies": {}, + "engines": { + "node": ">= 6.0.0" + } +} diff --git a/packages/-build-infra/src/addon-build-config-for-data-package.js b/packages/-build-infra/src/addon-build-config-for-data-package.js new file mode 100644 index 00000000000..14c428ca69b --- /dev/null +++ b/packages/-build-infra/src/addon-build-config-for-data-package.js @@ -0,0 +1,55 @@ +const calculateCacheKeyForTree = require('calculate-cache-key-for-tree'); + +function addonBuildConfigForDataPackage(name) { + return { + name, + + isLocalBuild() { + let appName = this.parent.pkg.name; + + return this.isDevelopingAddon() && appName === 'ember-data'; + }, + + buildBabelOptions() { + let babelOptions = this.options.babel || {}; + let existingPlugins = babelOptions.plugins || []; + let customPlugins = require('./stripped-build-plugins')( + process.env.EMBER_ENV, + this.isLocalBuild() + ); + let plugins = existingPlugins.map(plugin => { + return Array.isArray(plugin) ? plugin : [plugin]; + }); + plugins = plugins.concat(customPlugins.plugins); + + return { + loose: true, + plugins, + postTransformPlugins: customPlugins.postTransformPlugins, + exclude: ['transform-block-scoping', 'transform-typeof-symbol'], + }; + }, + + _setupBabelOptions() { + if (this._hasSetupBabelOptions) { + return; + } + + this.options.babel = this.buildBabelOptions(); + + this._hasSetupBabelOptions = true; + }, + + included(app) { + this._super.included.apply(this, arguments); + + this._setupBabelOptions(); + }, + + cacheKeyForTree(treeType) { + return calculateCacheKeyForTree(treeType, this); + }, + }; +} + +module.exports = addonBuildConfigForDataPackage; diff --git a/packages/-build-infra/src/cli-flags.js b/packages/-build-infra/src/cli-flags.js new file mode 100644 index 00000000000..b949f2e53fe --- /dev/null +++ b/packages/-build-infra/src/cli-flags.js @@ -0,0 +1,33 @@ +'use strict'; + +function isInstrumentedBuild() { + return process.argv.includes('--instrument'); +} + +function wantsEnabledFeatures() { + return process.argv.includes('--enable-in-progress'); +} + +function getManuallyEnabledFeatures() { + let args = process.argv; + let enabled = {}; + let ARG = '--enable-in-progress-flag'; + + for (let i = 0; i < args.length; i++) { + if (args[i].indexOf(ARG) === 0) { + let toEnable = args[i].substr(ARG.length + 1).split(','); + toEnable.forEach(function(flag) { + enabled[flag] = true; + }); + break; + } + } + + return enabled; +} + +module.exports = { + isInstrumentedBuild, + wantsEnabledFeatures, + getManuallyEnabledFeatures, +}; diff --git a/packages/-ember-data/lib/calculate-version.js b/packages/-build-infra/src/create-version-module.js similarity index 80% rename from packages/-ember-data/lib/calculate-version.js rename to packages/-build-infra/src/create-version-module.js index 4aab74ba2ed..1dd15792a3e 100644 --- a/packages/-ember-data/lib/calculate-version.js +++ b/packages/-build-infra/src/create-version-module.js @@ -1,9 +1,10 @@ +var createFile = require('broccoli-file-creator'); var path = require('path'); var fs = require('fs'); var gitRepoInfo = require('git-repo-info'); var npmGitInfo = require('npm-git-info'); -module.exports = function() { +function calculateVersion() { var gitPath = path.join(__dirname, '..', '.git'); var pkg = require('../package.json'); var packageVersion = pkg.version; @@ -25,4 +26,8 @@ module.exports = function() { } return packageVersion + suffix; +} + +module.exports = function() { + return createFile('version.js', 'export default "' + calculateVersion() + '";'); }; diff --git a/packages/-build-infra/src/stripped-build-plugins.js b/packages/-build-infra/src/stripped-build-plugins.js new file mode 100644 index 00000000000..f642ca501bf --- /dev/null +++ b/packages/-build-infra/src/stripped-build-plugins.js @@ -0,0 +1,109 @@ +'use strict'; + +const fs = require('fs'); + +const FilterImports = require.resolve('babel-plugin-filter-imports'); +const FeatureFlags = require.resolve('babel-plugin-feature-flags'); +const StripClassCallCheck = require.resolve('babel6-plugin-strip-class-callcheck'); +const StripFilteredImports = require.resolve('./transforms/babel-plugin-remove-imports'); +const TransformBlockScoping = require.resolve('@babel/plugin-transform-block-scoping'); +const { + isInstrumentedBuild, + wantsEnabledFeatures, + getManuallyEnabledFeatures, +} = require('./cli-flags'); + +function uniqueAdd(obj, key, values) { + const a = (obj[key] = obj[key] || []); + + for (let i = 0; i < values.length; i++) { + if (a.indexOf(values[i]) === -1) { + a.push(values[i]); + } + } +} + +function isProduction(environment) { + return /production/.test(environment); +} + +module.exports = function(environment, isLocalBuild) { + let flagsJsonPath = __dirname + '/../config/in-progress-features.json'; + let flagsJson = fs.readFileSync(flagsJsonPath, { encoding: 'utf8' }); + let inProgressFlags = JSON.parse(flagsJson); + let filteredImports = {}; + let allowInProgressFeatures = isLocalBuild === true && wantsEnabledFeatures(); + let manuallyEnabled = isLocalBuild ? getManuallyEnabledFeatures() : {}; + let enabledFlags = []; + let allFlags = Object.assign({}, inProgressFlags, manuallyEnabled); + + for (let flag in allFlags) { + let state = inProgressFlags[flag]; + /* + Default anything not `true` (e.g. `null`) feature to `false` + unless this is a local build and we've set the flags + to enable something. + */ + if (manuallyEnabled[flag]) { + if (state === true) { + // eslint-disable-next-line no-console + console.warn( + 'You specified the in-progress-feature "' + flag + '" but it was already active' + ); + } else if (state === undefined) { + throw new Error( + 'You specified the in-progress-feature "' + flag + '" but no such flag exists!' + ); + } else { + // eslint-disable-next-line no-console + console.warn('Manually Actived in-progress-feature: ' + flag); + } + inProgressFlags[flag] = true; + } else if (allowInProgressFeatures && state === null) { + enabledFlags.push(flag); + inProgressFlags[flag] = true; + } else if (state !== true) { + inProgressFlags[flag] = false; + } + } + + if (allowInProgressFeatures) { + if (enabledFlags.length) { + // eslint-disable-next-line no-console + console.warn( + 'Enabled the following in-progress-features that specified `null` as their state for this build: ["' + + enabledFlags.join(', ') + + '"]' + ); + } else { + // eslint-disable-next-line no-console + console.warn( + 'Attempted to enable all in-progress-features that specify `null` as their state for this build, but there were none.' + ); + } + } + + let postTransformPlugins = []; + let plugins = [ + [ + FeatureFlags, + { + import: { module: 'ember-data/-private/features' }, + features: inProgressFlags, + }, + ], + ]; + + if (isProduction(environment) || isInstrumentedBuild()) { + postTransformPlugins.push([StripClassCallCheck]); + uniqueAdd(filteredImports, 'ember-data/-debug', ['assertPolymorphicType']); + } + + plugins.push( + [FilterImports, { imports: filteredImports }], + [StripFilteredImports, filteredImports], + [TransformBlockScoping, { throwIfClosureRequired: true }] + ); + + return { plugins, postTransformPlugins }; +}; diff --git a/packages/-ember-data/lib/transforms/babel-plugin-remove-imports.js b/packages/-build-infra/src/transforms/babel-plugin-remove-imports.js similarity index 100% rename from packages/-ember-data/lib/transforms/babel-plugin-remove-imports.js rename to packages/-build-infra/src/transforms/babel-plugin-remove-imports.js diff --git a/packages/-ember-data/lib/transforms/package.json b/packages/-build-infra/src/transforms/package.json similarity index 100% rename from packages/-ember-data/lib/transforms/package.json rename to packages/-build-infra/src/transforms/package.json diff --git a/packages/-ember-data/lib/utilities/extend-from-application-entity.js b/packages/-build-infra/src/utilities/extend-from-application-entity.js similarity index 100% rename from packages/-ember-data/lib/utilities/extend-from-application-entity.js rename to packages/-build-infra/src/utilities/extend-from-application-entity.js diff --git a/packages/-ember-data/lib/utilities/module-unification.js b/packages/-build-infra/src/utilities/module-unification.js similarity index 100% rename from packages/-ember-data/lib/utilities/module-unification.js rename to packages/-build-infra/src/utilities/module-unification.js diff --git a/packages/-ember-data/.npmignore b/packages/-ember-data/.npmignore index 7a8ea4a1b77..fdeced3439a 100644 --- a/packages/-ember-data/.npmignore +++ b/packages/-ember-data/.npmignore @@ -37,4 +37,3 @@ !/dist/docs # ignore all assets except /dist/docs folder .appveyor.yml lib/scripts -lib/version-replace.js diff --git a/packages/-ember-data/FEATURES.md b/packages/-ember-data/FEATURES.md deleted file mode 100644 index fd945910b0e..00000000000 --- a/packages/-ember-data/FEATURES.md +++ /dev/null @@ -1,14 +0,0 @@ -## About Features - -Please read the [Feature Flag Guide](https://emberjs.com/guides/configuring-ember/feature-flags/) -for a detailed explanation. - -To add a new feature flag or change an existing one, you can add an -entry in `config/features.json`. - -**Ember Data features flags must begin with `ds-`, such as -`ds-new-coalescing`.** - -## Feature Flags - -- None currently. diff --git a/packages/-ember-data/blueprints/adapter-test/index.js b/packages/-ember-data/blueprints/adapter-test/index.js index cc4511cc854..a7f7a95664f 100644 --- a/packages/-ember-data/blueprints/adapter-test/index.js +++ b/packages/-ember-data/blueprints/adapter-test/index.js @@ -1,6 +1,6 @@ const testInfo = require('ember-cli-test-info'); const useTestFrameworkDetector = require('../test-framework-detector'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); diff --git a/packages/-ember-data/blueprints/adapter/index.js b/packages/-ember-data/blueprints/adapter/index.js index 3da434cfb09..7e4a067fae9 100644 --- a/packages/-ember-data/blueprints/adapter/index.js +++ b/packages/-ember-data/blueprints/adapter/index.js @@ -1,5 +1,5 @@ -const extendFromApplicationEntity = require('../../lib/utilities/extend-from-application-entity'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const extendFromApplicationEntity = require('@ember-data/-build-infra/src/utilities/extend-from-application-entity'); +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); const useEditionDetector = require('../edition-detector'); diff --git a/packages/-ember-data/blueprints/model-test/index.js b/packages/-ember-data/blueprints/model-test/index.js index 2956ab7bb19..d259aa392d0 100644 --- a/packages/-ember-data/blueprints/model-test/index.js +++ b/packages/-ember-data/blueprints/model-test/index.js @@ -1,7 +1,7 @@ const ModelBlueprint = require('../model'); const testInfo = require('ember-cli-test-info'); const useTestFrameworkDetector = require('../test-framework-detector'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); diff --git a/packages/-ember-data/blueprints/model/index.js b/packages/-ember-data/blueprints/model/index.js index 7fed2c30d57..7ae4a946fa9 100644 --- a/packages/-ember-data/blueprints/model/index.js +++ b/packages/-ember-data/blueprints/model/index.js @@ -1,7 +1,7 @@ const inflection = require('inflection'); const stringUtils = require('ember-cli-string-utils'); const EOL = require('os').EOL; -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); const useEditionDetector = require('../edition-detector'); diff --git a/packages/-ember-data/blueprints/serializer-test/index.js b/packages/-ember-data/blueprints/serializer-test/index.js index c38c753d07b..d8fe9827d8f 100644 --- a/packages/-ember-data/blueprints/serializer-test/index.js +++ b/packages/-ember-data/blueprints/serializer-test/index.js @@ -1,6 +1,6 @@ const testInfo = require('ember-cli-test-info'); const useTestFrameworkDetector = require('../test-framework-detector'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); diff --git a/packages/-ember-data/blueprints/serializer/index.js b/packages/-ember-data/blueprints/serializer/index.js index 7388b042031..4318a3d1c37 100644 --- a/packages/-ember-data/blueprints/serializer/index.js +++ b/packages/-ember-data/blueprints/serializer/index.js @@ -1,5 +1,5 @@ -const extendFromApplicationEntity = require('../../lib/utilities/extend-from-application-entity'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const extendFromApplicationEntity = require('@ember-data/-build-infra/src/utilities/extend-from-application-entity'); +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); const useEditionDetector = require('../edition-detector'); diff --git a/packages/-ember-data/blueprints/transform-test/index.js b/packages/-ember-data/blueprints/transform-test/index.js index 4b6c993309f..85c61ce1073 100644 --- a/packages/-ember-data/blueprints/transform-test/index.js +++ b/packages/-ember-data/blueprints/transform-test/index.js @@ -1,6 +1,6 @@ const testInfo = require('ember-cli-test-info'); const useTestFrameworkDetector = require('../test-framework-detector'); -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); diff --git a/packages/-ember-data/blueprints/transform/index.js b/packages/-ember-data/blueprints/transform/index.js index 6eec410b89d..3420a49c77d 100644 --- a/packages/-ember-data/blueprints/transform/index.js +++ b/packages/-ember-data/blueprints/transform/index.js @@ -1,4 +1,4 @@ -const isModuleUnificationProject = require('../../lib/utilities/module-unification') +const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification') .isModuleUnificationProject; const path = require('path'); const useEditionDetector = require('../edition-detector'); diff --git a/packages/-ember-data/index.js b/packages/-ember-data/index.js index 0be826f8378..d2870f2782f 100644 --- a/packages/-ember-data/index.js +++ b/packages/-ember-data/index.js @@ -4,10 +4,9 @@ const path = require('path'); const Funnel = require('broccoli-funnel'); const Rollup = require('broccoli-rollup'); const merge = require('broccoli-merge-trees'); -const version = require('./lib/version'); -const { isInstrumentedBuild } = require('./lib/cli-flags'); +const version = require('@ember-data/-build-infra/src/create-version-module'); +const { isInstrumentedBuild } = require('@ember-data/-build-infra/src/cli-flags'); const BroccoliDebug = require('broccoli-debug'); -const calculateCacheKeyForTree = require('calculate-cache-key-for-tree'); function isProductionEnv() { let isProd = /production/.test(process.env.EMBER_ENV); @@ -16,9 +15,10 @@ function isProductionEnv() { return isProd && !isTest; } -module.exports = { - name: 'ember-data', +const addonBuildConfigForDataPackage = require('@ember-data/-build-infra/src/addon-build-config-for-data-package'); +const addonBaseConfig = addonBuildConfigForDataPackage('ember-data'); +module.exports = Object.assign(addonBaseConfig, { _prodLikeWarning() { let emberEnv = process.env.EMBER_ENV; if (emberEnv !== 'production' && /production/.test(emberEnv)) { @@ -141,40 +141,4 @@ module.exports = { return this.debugTree(merge([publicTree, privateTree]), 'final'); }, - - buildBabelOptions() { - let existing = this.options.babel; - let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV); - let plugins = existing.plugins.map(plugin => { - return Array.isArray(plugin) ? plugin : [plugin]; - }); - plugins = plugins.concat(customPlugins.plugins); - - return { - loose: true, - plugins, - postTransformPlugins: customPlugins.postTransformPlugins, - exclude: ['transform-block-scoping', 'transform-typeof-symbol'], - }; - }, - - _setupBabelOptions() { - if (this._hasSetupBabelOptions) { - return; - } - - this.options.babel = this.buildBabelOptions(); - - this._hasSetupBabelOptions = true; - }, - - included(app) { - this._super.included.apply(this, arguments); - - this._setupBabelOptions(); - }, - - cacheKeyForTree(treeType) { - return calculateCacheKeyForTree(treeType, this); - }, -}; +}); diff --git a/packages/-ember-data/lib/cli-flags.js b/packages/-ember-data/lib/cli-flags.js deleted file mode 100644 index aaa8be2e8e0..00000000000 --- a/packages/-ember-data/lib/cli-flags.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -function isInstrumentedBuild() { - return process.argv.includes('--instrument'); -} - -module.exports = { - isInstrumentedBuild, -}; diff --git a/packages/-ember-data/lib/stripped-build-plugins.js b/packages/-ember-data/lib/stripped-build-plugins.js deleted file mode 100644 index bd942e2cb4a..00000000000 --- a/packages/-ember-data/lib/stripped-build-plugins.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -const fs = require('fs'); - -const FilterImports = requireBabelPlugin('babel-plugin-filter-imports'); -const FeatureFlags = requireBabelPlugin('babel-plugin-feature-flags'); -const StripClassCallCheck = requireBabelPlugin('babel6-plugin-strip-class-callcheck'); -const StripFilteredImports = requireBabelPlugin('./transforms/babel-plugin-remove-imports'); -const TransformBlockScoping = requireBabelPlugin('@babel/plugin-transform-block-scoping'); -const { isInstrumentedBuild } = require('./cli-flags'); - -function uniqueAdd(obj, key, values) { - const a = (obj[key] = obj[key] || []); - - for (let i = 0; i < values.length; i++) { - if (a.indexOf(values[i]) === -1) { - a.push(values[i]); - } - } -} - -// ensures that a `baseDir` property is present on the babel plugins -// that we will be using, this prevents ember-cli-babel/broccoli-babel-transpiler -// from opting out of caching (and printing a giant warning) -function requireBabelPlugin(packageName) { - return require.resolve(packageName); -} - -module.exports = function(environment) { - let featuresJsonPath = __dirname + '/../config/features.json'; - let featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' }); - let features = JSON.parse(featuresJson); - let filteredImports = {}; - - // TODO explicitly set all features which are not enabled to `false`, so - // they are stripped --> make this configurable or pass features - // - // for (let feature in features) { - // if (features[feature] !== true) { - // features[feature] = false; - // } - // } - - let postTransformPlugins = []; - let plugins = [ - [ - FeatureFlags, - { - import: { module: 'ember-data/-private/features' }, - features: features, - }, - ], - ]; - - if (/production/.test(environment) || isInstrumentedBuild()) { - postTransformPlugins.push([StripClassCallCheck]); - uniqueAdd(filteredImports, 'ember-data/-debug', ['assertPolymorphicType']); - } - - plugins.push( - [FilterImports, { imports: filteredImports }], - [StripFilteredImports, filteredImports], - [TransformBlockScoping, { throwIfClosureRequired: true }] - ); - - return { plugins, postTransformPlugins }; -}; diff --git a/packages/-ember-data/lib/version-replace.js b/packages/-ember-data/lib/version-replace.js deleted file mode 100644 index d8d694855e3..00000000000 --- a/packages/-ember-data/lib/version-replace.js +++ /dev/null @@ -1,13 +0,0 @@ -var calculateVersion = require('./calculate-version'); -var version = calculateVersion(); -var replace = require('broccoli-string-replace'); - -module.exports = function configFiles(tree) { - return replace(tree, { - files: ['*.{json,js}'], - pattern: { - match: /VERSION_STRING_PLACEHOLDER/g, - replacement: version, - }, - }); -}; diff --git a/packages/-ember-data/lib/version.js b/packages/-ember-data/lib/version.js deleted file mode 100644 index dd80c315bd2..00000000000 --- a/packages/-ember-data/lib/version.js +++ /dev/null @@ -1,6 +0,0 @@ -var calculateVersion = require('./calculate-version'); -var createFile = require('broccoli-file-creator'); - -module.exports = function() { - return createFile('version.js', 'export default "' + calculateVersion() + '";'); -}; diff --git a/packages/-ember-data/node-tests/unit/babel-plugin-remove-imports-test.js b/packages/-ember-data/node-tests/unit/babel-plugin-remove-imports-test.js index b01980d9b4c..15202805c83 100644 --- a/packages/-ember-data/node-tests/unit/babel-plugin-remove-imports-test.js +++ b/packages/-ember-data/node-tests/unit/babel-plugin-remove-imports-test.js @@ -5,7 +5,7 @@ const co = require('co'); const Babel = require('broccoli-babel-transpiler'); const chai = require('ember-cli-blueprint-test-helpers/chai'); const stripIndent = require('common-tags').stripIndent; -const StripFilteredImports = require('../../lib/transforms/babel-plugin-remove-imports'); +const StripFilteredImports = require('@ember-data/-build-infra/src/transforms/babel-plugin-remove-imports'); const expect = chai.expect; const createTempDir = BroccoliTestHelper.createTempDir; diff --git a/packages/-ember-data/package.json b/packages/-ember-data/package.json index e548b3efc84..d7848104a02 100644 --- a/packages/-ember-data/package.json +++ b/packages/-ember-data/package.json @@ -17,17 +17,6 @@ "test:production": "ember test -e production", "test:optional-features": "ember test -e test-optional-features", "test:try-one": "ember try:one", - "test-external:ember-m3": "node ./lib/scripts/test-external ember-m3 https://github.com/hjdivad/ember-m3.git", - "test-external:ember-data-change-tracker": "node ./lib/scripts/test-external ember-data-change-tracker https://github.com/danielspaniel/ember-data-change-tracker.git", - "test-external:emberaddons.com": "node ./lib/scripts/test-external ember-cli-addon-search https://github.com/gcollazo/ember-cli-addon-search.git", - "test-external:model-fragments": "node ./lib/scripts/test-external ember-data-model-fragments https://github.com/lytics/ember-data-model-fragments.git", - "test-external:ember-observer": "node ./lib/scripts/test-external ember-observer https://github.com/emberobserver/client.git", - "test-external:travis-web": "node ./lib/scripts/test-external travis-web https://github.com/travis-ci/travis-web.git", - "test-external:storefront": "node ./lib/scripts/test-external storefront https://github.com/embermap/ember-data-storefront.git", - "test-external:factory-guy": "node ./lib/scripts/test-external factory-guy https://github.com/danielspaniel/ember-data-factory-guy.git", - "test-external:ilios-frontend": "node ./lib/scripts/test-external ilios-frontend https://github.com/ilios/frontend.git --skip-smoke-test", - "test-external:ember-resource-metadata": "node ./lib/scripts/test-external ember-resource-metadata https://github.com/ef4/ember-resource-metadata.git", - "test-external:ember-data-relationship-tracker": "node ./lib/scripts/test-external ember-data-relationship-tracker https://github.com/ef4/ember-data-relationship-tracker.git", "prepublishOnly": "ember ts:precompile", "postpublish": "ember ts:clean" }, @@ -38,32 +27,25 @@ "@ember-data/model": "^0.0.0", "@ember-data/serializer": "^0.0.0", "@ember-data/store": "^0.0.0", + "@ember-data/-build-infra": "^0.0.0", "@ember/ordered-set": "^2.0.3", "@glimmer/env": "^0.1.7", - "babel-plugin-feature-flags": "^0.3.1", - "babel-plugin-filter-imports": "^2.0.4", - "babel6-plugin-strip-class-callcheck": "^6.0.0", "broccoli-debug": "^0.6.5", - "broccoli-file-creator": "^2.1.1", "broccoli-funnel": "^2.0.1", "broccoli-merge-trees": "^3.0.2", "broccoli-rollup": "^2.1.1", - "calculate-cache-key-for-tree": "^1.1.0", "chalk": "^2.4.1", - "ember-cli-babel": "^7.1.4", - "ember-cli-path-utils": "^1.0.0", - "ember-cli-string-utils": "^1.1.0", + "ember-cli-babel": "^7.7.3", "ember-cli-test-info": "^1.0.0", - "ember-cli-typescript": "^2.0.0-beta.2", + "ember-cli-typescript": "^2.0.0-rc.2", "ember-cli-version-checker": "^3.1.2", "ember-fetch": "^6.5.0", "ember-inflector": "^3.0.0", - "git-repo-info": "^2.0.0", "inflection": "^1.12.0", - "npm-git-info": "^1.0.3", "resolve": "^1.8.1", "semver": "^5.6.0", - "silent-error": "^1.1.1" + "silent-error": "^1.1.1", + "ember-cli-string-utils": "^1.1.0" }, "devDependencies": { "@babel/plugin-transform-typescript": "*", diff --git a/packages/-ember-data/tests/dummy/config/environment.js b/packages/-ember-data/tests/dummy/config/environment.js index 8f6ea148349..4834376ad2d 100644 --- a/packages/-ember-data/tests/dummy/config/environment.js +++ b/packages/-ember-data/tests/dummy/config/environment.js @@ -1,11 +1,5 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var featuresJsonPath = path.join(__dirname, '../../../config/features.json'); -var featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' }); -var featureFlags = JSON.parse(featuresJson); - module.exports = function(environment) { var ENV = { modulePrefix: 'dummy', @@ -14,7 +8,6 @@ module.exports = function(environment) { rootURL: '/', locationType: 'auto', EmberENV: { - FEATURES: featureFlags, RAISE_ON_DEPRECATION: false, }, @@ -24,10 +17,6 @@ module.exports = function(environment) { }, }; - if (environment === 'test-optional-features') { - ENV.EmberENV.ENABLE_OPTIONAL_FEATURES = true; - } - if (environment === 'development') { // ENV.APP.LOG_RESOLVER = true; // ENV.APP.LOG_ACTIVE_GENERATION = true; diff --git a/packages/adapter/ember-cli-build.js b/packages/adapter/ember-cli-build.js index dc5a39e1b79..aa2951398b8 100644 --- a/packages/adapter/ember-cli-build.js +++ b/packages/adapter/ember-cli-build.js @@ -4,7 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { let app = new EmberAddon(defaults, { - // Add options here + 'ember-cli-babel': { + throwUnlessParallelizable: true, + }, }); /* diff --git a/packages/adapter/index.js b/packages/adapter/index.js index 0ca063d427d..091c2912bef 100644 --- a/packages/adapter/index.js +++ b/packages/adapter/index.js @@ -1,5 +1,6 @@ 'use strict'; -module.exports = { - name: require('./package').name, -}; +const name = require('./package').name; +const addonBuildConfigForDataPackage = require('@ember-data/-build-infra/src/addon-build-config-for-data-package'); + +module.exports = addonBuildConfigForDataPackage(name); diff --git a/packages/adapter/package.json b/packages/adapter/package.json index 836f0261673..218d4d59b82 100644 --- a/packages/adapter/package.json +++ b/packages/adapter/package.json @@ -19,7 +19,9 @@ "test:all": "ember try:each" }, "dependencies": { - "ember-cli-babel": "^7.1.4" + "@ember-data/-build-infra": "^0.0.0", + "ember-cli-babel": "^7.7.3", + "ember-cli-typescript": "^2.0.0-rc.2" }, "devDependencies": { "@ember/optional-features": "*", diff --git a/packages/model/ember-cli-build.js b/packages/model/ember-cli-build.js index dc5a39e1b79..aa2951398b8 100644 --- a/packages/model/ember-cli-build.js +++ b/packages/model/ember-cli-build.js @@ -4,7 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { let app = new EmberAddon(defaults, { - // Add options here + 'ember-cli-babel': { + throwUnlessParallelizable: true, + }, }); /* diff --git a/packages/model/index.js b/packages/model/index.js index 0ca063d427d..091c2912bef 100644 --- a/packages/model/index.js +++ b/packages/model/index.js @@ -1,5 +1,6 @@ 'use strict'; -module.exports = { - name: require('./package').name, -}; +const name = require('./package').name; +const addonBuildConfigForDataPackage = require('@ember-data/-build-infra/src/addon-build-config-for-data-package'); + +module.exports = addonBuildConfigForDataPackage(name); diff --git a/packages/model/package.json b/packages/model/package.json index 40a2a807e1b..7fce93e408c 100644 --- a/packages/model/package.json +++ b/packages/model/package.json @@ -21,8 +21,9 @@ }, "dependencies": { "@ember-data/store": "^0.0.0", - "ember-cli-babel": "^7.1.2", - "ember-cli-typescript": "^2.0.0-beta.2" + "@ember-data/-build-infra": "^0.0.0", + "ember-cli-babel": "^7.7.3", + "ember-cli-typescript": "^2.0.0-rc.2" }, "devDependencies": { "@ember/optional-features": "*", diff --git a/packages/serializer/ember-cli-build.js b/packages/serializer/ember-cli-build.js index dc5a39e1b79..aa2951398b8 100644 --- a/packages/serializer/ember-cli-build.js +++ b/packages/serializer/ember-cli-build.js @@ -4,7 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { let app = new EmberAddon(defaults, { - // Add options here + 'ember-cli-babel': { + throwUnlessParallelizable: true, + }, }); /* diff --git a/packages/serializer/index.js b/packages/serializer/index.js index 0ca063d427d..091c2912bef 100644 --- a/packages/serializer/index.js +++ b/packages/serializer/index.js @@ -1,5 +1,6 @@ 'use strict'; -module.exports = { - name: require('./package').name, -}; +const name = require('./package').name; +const addonBuildConfigForDataPackage = require('@ember-data/-build-infra/src/addon-build-config-for-data-package'); + +module.exports = addonBuildConfigForDataPackage(name); diff --git a/packages/serializer/package.json b/packages/serializer/package.json index b5eecd170e8..13dc7636d0a 100644 --- a/packages/serializer/package.json +++ b/packages/serializer/package.json @@ -21,7 +21,9 @@ }, "dependencies": { "@ember-data/store": "^0.0.0", - "ember-cli-babel": "^7.1.2" + "@ember-data/-build-infra": "^0.0.0", + "ember-cli-babel": "^7.7.3", + "ember-cli-typescript": "^2.0.0-rc.2" }, "devDependencies": { "@ember/optional-features": "*", diff --git a/packages/store/ember-cli-build.js b/packages/store/ember-cli-build.js index dc5a39e1b79..aa2951398b8 100644 --- a/packages/store/ember-cli-build.js +++ b/packages/store/ember-cli-build.js @@ -4,7 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { let app = new EmberAddon(defaults, { - // Add options here + 'ember-cli-babel': { + throwUnlessParallelizable: true, + }, }); /* diff --git a/packages/store/index.js b/packages/store/index.js index 5a1ae7c1c9c..091c2912bef 100644 --- a/packages/store/index.js +++ b/packages/store/index.js @@ -1,37 +1,6 @@ 'use strict'; -module.exports = { - name: require('./package').name, +const name = require('./package').name; +const addonBuildConfigForDataPackage = require('@ember-data/-build-infra/src/addon-build-config-for-data-package'); - buildBabelOptions() { - let existing = this.options.babel; - let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV); - let plugins = existing.plugins.map(plugin => { - return Array.isArray(plugin) ? plugin : [plugin]; - }); - plugins = plugins.concat(customPlugins.plugins); - - return { - loose: true, - plugins, - postTransformPlugins: customPlugins.postTransformPlugins, - exclude: ['transform-block-scoping', 'transform-typeof-symbol'], - }; - }, - - _setupBabelOptions() { - if (this._hasSetupBabelOptions) { - return; - } - - this.options.babel = this.buildBabelOptions(); - - this._hasSetupBabelOptions = true; - }, - - included(app) { - this._super.included.apply(this, arguments); - - this._setupBabelOptions(); - }, -}; +module.exports = addonBuildConfigForDataPackage(name); diff --git a/packages/store/lib/cli-flags.js b/packages/store/lib/cli-flags.js deleted file mode 100644 index aaa8be2e8e0..00000000000 --- a/packages/store/lib/cli-flags.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -function isInstrumentedBuild() { - return process.argv.includes('--instrument'); -} - -module.exports = { - isInstrumentedBuild, -}; diff --git a/packages/store/lib/stripped-build-plugins.js b/packages/store/lib/stripped-build-plugins.js deleted file mode 100644 index 33bad587840..00000000000 --- a/packages/store/lib/stripped-build-plugins.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -const fs = require('fs'); - -const FilterImports = requireBabelPlugin('babel-plugin-filter-imports'); -const FeatureFlags = requireBabelPlugin('babel-plugin-feature-flags'); -const StripClassCallCheck = requireBabelPlugin('babel6-plugin-strip-class-callcheck'); -const StripFilteredImports = requireBabelPlugin('./transforms/babel-plugin-remove-imports'); -const TransformBlockScoping = requireBabelPlugin('@babel/plugin-transform-block-scoping'); -const { isInstrumentedBuild } = require('./cli-flags'); - -function uniqueAdd(obj, key, values) { - const a = (obj[key] = obj[key] || []); - - for (let i = 0; i < values.length; i++) { - if (a.indexOf(values[i]) === -1) { - a.push(values[i]); - } - } -} - -// ensures that a `baseDir` property is present on the babel plugins -// that we will be using, this prevents ember-cli-babel/broccoli-babel-transpiler -// from opting out of caching (and printing a giant warning) -function requireBabelPlugin(packageName) { - return require.resolve(packageName); -} - -module.exports = function(environment) { - let featuresJsonPath = __dirname + '/../../-ember-data/config/features.json'; - let featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' }); - let features = JSON.parse(featuresJson); - let filteredImports = {}; - - // TODO explicitly set all features which are not enabled to `false`, so - // they are stripped --> make this configurable or pass features - // - // for (let feature in features) { - // if (features[feature] !== true) { - // features[feature] = false; - // } - // } - - let postTransformPlugins = []; - let plugins = [ - [ - FeatureFlags, - { - import: { module: 'ember-data/-private/features' }, - features: features, - }, - ], - ]; - - if (/production/.test(environment) || isInstrumentedBuild()) { - postTransformPlugins.push([StripClassCallCheck]); - uniqueAdd(filteredImports, 'ember-data/-debug', ['assertPolymorphicType']); - } - - plugins.push( - [FilterImports, { imports: filteredImports }], - [StripFilteredImports, filteredImports], - [TransformBlockScoping, { throwIfClosureRequired: true }] - ); - - return { plugins, postTransformPlugins }; -}; diff --git a/packages/store/lib/transforms/babel-plugin-remove-imports.js b/packages/store/lib/transforms/babel-plugin-remove-imports.js deleted file mode 100644 index 480a2f1abaf..00000000000 --- a/packages/store/lib/transforms/babel-plugin-remove-imports.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -module.exports = function PluginRemoveFilteredImports() { - let importDeclarationsToRemove; - let filteredImports; - let filteredImportNames; - - return { - name: 'remove-filtered-imports', - visitor: { - Program: { - enter(_, state) { - filteredImports = state.opts || {}; - filteredImportNames = Object.keys(filteredImports); - importDeclarationsToRemove = []; - }, - exit() { - importDeclarationsToRemove.forEach(declaration => declaration.remove()); - - importDeclarationsToRemove = undefined; - }, - }, - - ImportDeclaration(path) { - let name = path.node.source.value; - - if (filteredImportNames.indexOf(name) !== -1) { - if (filteredImports[name] === true || filteredImports[name] === '*') { - importDeclarationsToRemove.push(path); - } else { - let removables = []; - let imports = path.node.specifiers; - const hasSpecifiers = imports.length > 0; - - for (let i = 0; i < imports.length; i++) { - if (imports[i].type === 'ImportNamespaceSpecifier') { - continue; - } - - let specifier = imports[i].imported; - - if (filteredImports[name].indexOf(specifier.name) !== -1) { - removables.push(imports[i]); - } - } - - if (hasSpecifiers && removables.length === imports.length) { - importDeclarationsToRemove.push(path); - } else { - for (let i = 0; i < removables.length; i++) { - let index = imports.indexOf(removables[i]); - imports.splice(index, 1); - } - } - } - } - }, - }, - }; -}; diff --git a/packages/store/lib/transforms/package.json b/packages/store/lib/transforms/package.json deleted file mode 100644 index 1f9b1fe9050..00000000000 --- a/packages/store/lib/transforms/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "babel-plugin-remove-imports" -} diff --git a/packages/store/lib/utilities/extend-from-application-entity.js b/packages/store/lib/utilities/extend-from-application-entity.js deleted file mode 100644 index 589229a5ff5..00000000000 --- a/packages/store/lib/utilities/extend-from-application-entity.js +++ /dev/null @@ -1,63 +0,0 @@ -const stringUtil = require('ember-cli-string-utils'); -const SilentError = require('silent-error'); -const pathUtil = require('ember-cli-path-utils'); -const fs = require('fs'); -const path = require('path'); -const isModuleUnificationProject = require('./module-unification').isModuleUnificationProject; - -module.exports = function(type, baseClass, options) { - let isAddon = options.inRepoAddon || options.project.isEmberCLIAddon(); - let isModuleUnification = isModuleUnificationProject(options.project); - - let entityName = options.entity.name; - let relativePath = pathUtil.getRelativePath(options.entity.name); - - if (options.pod && options.podPath) { - relativePath = pathUtil.getRelativePath(options.podPath + options.entity.name); - } - - let applicationEntityPath; - if (isModuleUnification) { - applicationEntityPath = path.join( - options.project.root, - 'src', - 'data', - 'models', - 'application', - `${type}.js` - ); - } else { - applicationEntityPath = path.join(options.project.root, 'app', `${type}s`, 'application.js'); - } - - let hasApplicationEntity = fs.existsSync(applicationEntityPath); - if (!isAddon && !options.baseClass && entityName !== 'application' && hasApplicationEntity) { - options.baseClass = 'application'; - } - - if (options.baseClass === entityName) { - throw new SilentError( - stringUtil.classify(type) + - 's cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.' - ); - } - let importStatement = "import DS from 'ember-data';"; - - if (options.baseClass) { - let baseClassPath = options.baseClass; - baseClass = stringUtil.classify(baseClassPath.replace('/', '-')); - baseClass = baseClass + stringUtil.classify(type); - - if (isModuleUnification) { - relativePath = `../${options.baseClass}/`; - baseClassPath = type; - } - - importStatement = `import ${baseClass} from '${relativePath}${baseClassPath}';`; - } - - return { - importStatement: importStatement, - baseClass: baseClass, - }; -}; diff --git a/packages/store/lib/utilities/module-unification.js b/packages/store/lib/utilities/module-unification.js deleted file mode 100644 index aa7f4683ae7..00000000000 --- a/packages/store/lib/utilities/module-unification.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports = { - isModuleUnificationProject(project) { - return project && project.isModuleUnification && project.isModuleUnification(); - }, -}; diff --git a/packages/store/package.json b/packages/store/package.json index bd614e83ae3..578db787434 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -23,10 +23,9 @@ }, "dependencies": { "@ember-data/adapter": "^0.0.0", - "babel6-plugin-strip-heimdall": "^6.0.1", - "ember-cli-babel": "^7.1.2", + "@ember-data/-build-infra": "^0.0.0", + "ember-cli-babel": "^7.7.3", "ember-cli-path-utils": "^1.0.0", - "ember-cli-string-utils": "^1.1.0", "ember-cli-typescript": "^2.0.0-rc.2", "heimdalljs": "^0.3.0", "silent-error": "^1.1.1" diff --git a/yarn.lock b/yarn.lock index 3fb3fe2cfab..97b9a07e4c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2735,11 +2735,6 @@ babel6-plugin-strip-class-callcheck@^6.0.0: resolved "https://registry.npmjs.org/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf" integrity sha1-3oQcGr6705943gr/ssmlLuIo/d8= -babel6-plugin-strip-heimdall@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/babel6-plugin-strip-heimdall/-/babel6-plugin-strip-heimdall-6.0.1.tgz#35f80eddec1f7fffdc009811dfbd46d9965072b6" - integrity sha1-NfgO3ewff//cAJgR371G2ZZQcrY= - babylon@^6.18.0: version "6.18.0" resolved "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" @@ -4679,7 +4674,7 @@ ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.0.0-beta.7, ember-cli-babel@^6 ember-cli-version-checker "^2.1.2" semver "^5.5.0" -ember-cli-babel@^7.0.0, ember-cli-babel@^7.1.2, ember-cli-babel@^7.1.3, ember-cli-babel@^7.1.4, ember-cli-babel@^7.4.2, ember-cli-babel@^7.4.3, ember-cli-babel@^7.5.0: +ember-cli-babel@^7.0.0, ember-cli-babel@^7.1.3, ember-cli-babel@^7.4.2, ember-cli-babel@^7.4.3, ember-cli-babel@^7.5.0, ember-cli-babel@^7.7.3: version "7.7.3" resolved "https://registry.npmjs.org/ember-cli-babel/-/ember-cli-babel-7.7.3.tgz#f94709f6727583d18685ca6773a995877b87b8a0" integrity sha512-/LWwyKIoSlZQ7k52P+6agC7AhcOBqPJ5C2u27qXHVVxKvCtg6ahNuRk/KmfZmV4zkuw4EjTZxfJE1PzpFyHkXg== @@ -4898,7 +4893,7 @@ ember-cli-typescript-blueprints@*, ember-cli-typescript-blueprints@^2.0.0-beta.1 inflection "^1.12.0" silent-error "^1.1.0" -ember-cli-typescript@^2.0.0-beta.2, ember-cli-typescript@^2.0.0-rc.2: +ember-cli-typescript@^2.0.0-rc.2: version "2.0.0" resolved "https://registry.npmjs.org/ember-cli-typescript/-/ember-cli-typescript-2.0.0.tgz#c31f7b649892ff8f7bb518539ccfa336d0613965" integrity sha512-UUm/uMI1ToBQMmr5aiArEhHiCTyARXNxzbQxU+Yf1cBKuIXbDFTa/jdS55wt2o8qCPNay8v90m2C0Nvk3KuAEQ==