Skip to content

Commit

Permalink
[CHORE] add package flag infra, strip flag infra (#6737)
Browse files Browse the repository at this point in the history
* [CHORE] add package flag infra

convert to flag infra

dont ship flag code to production

* kickstart cause npm registry blinked

* fix detect

* cleanup reduce

* even simpler

* invoke cnary test

* match new pattern

* use EMBER_ENV and this._findApp

* _findHost not _findApp

* cleanup uniqueAdd
  • Loading branch information
runspired authored Nov 15, 2019
1 parent 8bf2da7 commit ad9f29d
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 229 deletions.
4 changes: 3 additions & 1 deletion bin/-tarball-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/*
This file generates meta information about what packages
are included in the project and the tarballs we would produce
Expand Down Expand Up @@ -136,6 +135,9 @@ packages.forEach(localName => {
} catch (e) {
return;
}
if (pkgInfo.private === true) {
return;
}
const version = `${pkgInfo.version}-sha.${CurrentSha}`;
const tarballName = `${convertPackageNameToTarballName(pkgInfo.name)}-${version}.tgz`;
OurPackages[pkgInfo.name] = {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"babel-plugin-filter-imports": "^3.0.0",
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"broccoli-asset-rev": "^3.0.0",
"broccoli-babel-transpiler": "^7.2.0",
"broccoli-concat": "^3.7.5",
"broccoli-file-creator": "^2.1.1",
"broccoli-stew": "^3.0.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/-ember-data/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = function(defaults) {
babel: {
// this ensures that the same `@ember-data/canary-features` processing that the various
// ember-data addons do is done in the dummy app
plugins: [...require('@ember-data/private-build-infra/src/debug-macros')()],
plugins: [
...require('@ember-data/private-build-infra/src/debug-macros')(null, process.env.EMBER_ENV === 'production'),
],
},
'ember-cli-babel': {
throwUnlessParallelizable: true,
Expand Down
1 change: 0 additions & 1 deletion packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@types/ember__test-helpers": "~0.7.9",
"@types/qunit": "^2.5.3",
"@types/rsvp": "^4.0.3",
"broccoli-babel-transpiler": "^7.2.0",
"broccoli-concat": "^3.7.5",
"broccoli-stew": "^3.0.0",
"broccoli-string-replace": "^0.1.2",
Expand Down
7 changes: 5 additions & 2 deletions packages/canary-features/addon/default-features.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
@module @ember-data/canary-features
*/

/*
This list of features is used both at build time (by `@ember-data/private-build-infra`)
and at runtime (by `@ember-data/canary-features`).
Expand All @@ -11,7 +10,11 @@
- true - The feature is enabled at all times, and cannot be disabled.
- false - The feature is disabled at all times, and cannot be enabled.
- null - The feature is disabled by default, but can be enabled at runtime via `EmberDataENV`.
*/
@module @ember-data/canary-features
@main
@private
*/
export default {
SAMPLE_FEATURE_FLAG: null,
RECORD_DATA_ERRORS: null,
Expand Down
22 changes: 21 additions & 1 deletion packages/canary-features/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
module.exports = { name: require('./package').name };
module.exports = {
name: require('./package').name,
treeFor() {
// Nested addons don't call isEnabled automatically,
// So this ensures that we return empty trees whenever
// we are not enabled.
if (this.isEnabled()) {
return this._super.treeFor.call(this, ...arguments);
}
},
isEnabled() {
if (this.__isEnabled !== undefined) {
return this.__isEnabled;
}
const env = process.env.EMBER_ENV;

this.__isEnabled = env !== 'production';

return this.__isEnabled;
},
};
1 change: 0 additions & 1 deletion packages/canary-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"babel-plugin-debug-macros": "^0.3.3",
"babel-plugin-filter-imports": "^3.0.0",
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"broccoli-babel-transpiler": "^7.2.0",
"broccoli-file-creator": "^2.1.1",
"broccoli-test-helper": "^2.0.0",
"calculate-cache-key-for-tree": "^2.0.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/private-build-infra/addon/available-packages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
HAS_EMBER_DATA_PACKAGE: 'ember-data',
HAS_STORE_PACKAGE: '@ember-data/store',
HAS_MODEL_PACKAGE: '@ember-data/model',
HAS_RECORD_DATA_PACKAGE: '@ember-data/record-data',
HAS_ADAPTER_PACKAGE: '@ember-data/adapter',
HAS_SERIALIZER_PACKAGE: '@ember-data/serializer',
HAS_DEBUG_PACKAGE: '@ember-data/debug',
};
19 changes: 19 additions & 0 deletions packages/private-build-infra/addon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
@module @ember-data/private-build-infra
*/

import { has } from 'require';
import AVAILABLE_PACKAGES from './available-packages';

function flagState(flag: keyof typeof AVAILABLE_PACKAGES): boolean {
const packageName = AVAILABLE_PACKAGES[flag];
return has(packageName) || false;
}

export const HAS_EMBER_DATA_PACKAGE = flagState('HAS_EMBER_DATA_PACKAGE');
export const HAS_STORE_PACKAGE = flagState('HAS_STORE_PACKAGE');
export const HAS_MODEL_PACKAGE = flagState('HAS_MODEL_PACKAGE');
export const HAS_ADAPTER_PACKAGE = flagState('HAS_ADAPTER_PACKAGE');
export const HAS_SERIALIZER_PACKAGE = flagState('HAS_SERIALIZER_PACKAGE');
export const HAS_DEBUG_PACKAGE = flagState('HAS_DEBUG_PACKAGE');
export const HAS_RECORD_DATA_PACKAGE = flagState('HAS_RECORD_DATA_PACKAGE');
21 changes: 21 additions & 0 deletions packages/private-build-infra/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: require('./package').name,
treeFor() {
// Nested addons don't call isEnabled automatically,
// So this ensures that we return empty trees whenever
// we are not enabled.
if (this.isEnabled()) {
return this._super.treeFor.call(this, ...arguments);
}
},
isEnabled() {
if (this.__isEnabled !== undefined) {
return this.__isEnabled;
}
const env = process.env.EMBER_ENV;

this.__isEnabled = env !== 'production';

return this.__isEnabled;
},
};

This file was deleted.

19 changes: 7 additions & 12 deletions packages/private-build-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "@ember-data/private-build-infra",
"version": "3.16.0-alpha.0",
"description": "The default blueprint for ember-data private packages.",
"keywords": [],
"keywords": [
"ember-addon"
],
"repository": "",
"license": "MIT",
"author": "",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"test:node": "mocha"
},
"scripts": {},
"dependencies": {
"ember-cli-babel": "^7.12.0",
"ember-cli-typescript": "^3.1.1",
"@babel/plugin-transform-block-scoping": "^7.6.3",
"@ember-data/canary-features": "3.16.0-alpha.0",
"@ember/edition-utils": "^1.1.1",
Expand All @@ -38,14 +40,7 @@
"rsvp": "^4.8.5",
"silent-error": "^1.1.1"
},
"devDependencies": {
"broccoli-babel-transpiler": "^7.2.0",
"broccoli-test-helper": "^2.0.0",
"co": "^4.6.0",
"common-tags": "^1.8.0",
"ember-cli-blueprint-test-helpers": "^0.19.1",
"mocha": "^6.2.2"
},
"devDependencies": {},
"engines": {
"node": ">= 8.0.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function addonBuildConfigForDataPackage(PackageName) {
buildBabelOptions() {
let babelOptions = this.options.babel || {};
let existingPlugins = babelOptions.plugins || [];
let customPlugins = require('./stripped-build-plugins')(process.env.EMBER_ENV);
let customPlugins = require('./stripped-build-plugins')(process.env.EMBER_ENV, this._findHost());
let plugins = existingPlugins.map(plugin => {
return Array.isArray(plugin) ? plugin : [plugin];
});
Expand Down
21 changes: 17 additions & 4 deletions packages/private-build-infra/src/debug-macros.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const FEATURES = require('./features');

module.exports = function debugMacros(environment) {
module.exports = function debugMacros(app, isProd) {
const PACKAGES = require('./packages')(app);
const FEATURES = require('./features')(isProd);
const debugMacrosPath = require.resolve('babel-plugin-debug-macros');
let plugins = [
[
require.resolve('babel-plugin-debug-macros'),
debugMacrosPath,
{
flags: [
{
Expand All @@ -16,6 +17,18 @@ module.exports = function debugMacros(environment) {
},
'@ember-data/canary-features-stripping',
],
[
debugMacrosPath,
{
flags: [
{
source: '@ember-data/private-build-infra',
flags: PACKAGES,
},
],
},
'@ember-data/optional-packages-stripping',
],
];

return plugins;
Expand Down
17 changes: 15 additions & 2 deletions packages/private-build-infra/src/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const version = require('../package.json').version;
const isCanary = version.includes('alpha');

const requireEsm = require('esm')(module);
function getFeatures() {

function getFeatures(isProd) {
const { default: features } = requireEsm('@ember-data/canary-features/addon/default-features.ts');

if (!isCanary) {
// disable all features with a current value of `null`
for (let feature in features) {
let featureValue = features[feature];

Expand Down Expand Up @@ -39,7 +41,18 @@ function getFeatures() {
}
}

if (isProd) {
// disable all features with a current value of `null`
for (let feature in features) {
let featureValue = features[feature];

if (featureValue === null) {
features[feature] = false;
}
}
}

return features;
}

module.exports = getFeatures();
module.exports = getFeatures;
Loading

0 comments on commit ad9f29d

Please sign in to comment.