Skip to content

Commit

Permalink
[FEAT packages] introduce build-infra package
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 10, 2019
1 parent 1794b06 commit 00df008
Show file tree
Hide file tree
Showing 58 changed files with 457 additions and 531 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -76,7 +77,7 @@ module.exports = {

// node tests
{
files: ['packages/*/node-tests/**'],
files: ['packages/*/node-tests/**', 'node-tests/**'],

env: {
mocha: true,
Expand Down
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
73 changes: 54 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 13 additions & 15 deletions bin/lint-features
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions packages/-build-infra/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# compiled output
/dist/
/tmp/

# misc
/.bowerrc
/.editorconfig
/.env*
/.gitignore
/.watchmanconfig
/CONTRIBUTING.md
/testem.js
/tests/
/yarn.lock
.gitkeep
3 changes: 3 additions & 0 deletions packages/-build-infra/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
}
9 changes: 9 additions & 0 deletions packages/-build-infra/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions packages/-build-infra/README.md
Original file line number Diff line number Diff line change
@@ -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).
41 changes: 30 additions & 11 deletions .../-ember-data/lib/scripts/test-external.js → ...nfra/bin/test-external-partner-project.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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';
Expand All @@ -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}'`
);
}

Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
File renamed without changes.
Loading

0 comments on commit 00df008

Please sign in to comment.