-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert to flag infra dont ship flag code to production
- Loading branch information
Showing
11 changed files
with
146 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
module.exports = { name: require('./package').name }; | ||
function getApp(addon) { | ||
while (addon && !addon.app) { | ||
addon = addon.parent; | ||
} | ||
if (!addon) { | ||
throw new Error(`Unable to find the parent application`); | ||
} | ||
return addon.app; | ||
} | ||
|
||
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 !== null) { | ||
return this.__isEnabled; | ||
} | ||
const env = getApp(this).env; | ||
|
||
this.__isEnabled = env !== 'production'; | ||
|
||
return this.__isEnabled; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
@module @ember-data/private-build-infra | ||
*/ | ||
|
||
import { has } from 'require'; | ||
import POSSIBLE_PACKAGES from './available-packages'; | ||
|
||
type PackageSettings = Record<keyof typeof POSSIBLE_PACKAGES, boolean>; | ||
|
||
const PACKAGES = Object.keys(POSSIBLE_PACKAGES).reduce((obj, name) => { | ||
const NAME = POSSIBLE_PACKAGES[name]; | ||
obj[NAME] = has(name) || false; | ||
return obj; | ||
}, {}) as PackageSettings; | ||
|
||
export const HAS_EMBER_DATA_PACKAGE = PACKAGES.HAS_EMBER_DATA_PACKAGE; | ||
export const HAS_STORE_PACKAGE = PACKAGES.HAS_STORE_PACKAGE; | ||
export const HAS_MODEL_PACKAGE = PACKAGES.HAS_MODEL_PACKAGE; | ||
export const HAS_ADAPTER_PACKAGE = PACKAGES.HAS_ADAPTER_PACKAGE; | ||
export const HAS_SERIALIZER_PACKAGE = PACKAGES.HAS_SERIALIZER_PACKAGE; | ||
export const HAS_DEBUG_PACKAGE = PACKAGES.HAS_DEBUG_PACKAGE; | ||
export const HAS_RECORD_DATA_PACKAGE = PACKAGES.HAS_RECORD_DATA_PACKAGE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function getApp(addon) { | ||
while (addon && !addon.app) { | ||
addon = addon.parent; | ||
} | ||
if (!addon) { | ||
throw new Error(`Unable to find the parent application`); | ||
} | ||
return addon.app; | ||
} | ||
|
||
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 !== null) { | ||
return this.__isEnabled; | ||
} | ||
const env = getApp(this).env; | ||
|
||
this.__isEnabled = env !== 'production'; | ||
|
||
return this.__isEnabled; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const requireEsm = require('esm')(module); | ||
|
||
function getPackages() { | ||
const { default: POSSIBLE_PACKAGES } = requireEsm('@ember-data/private-build-infra/addon/available-packages.ts'); | ||
const flags = {}; | ||
|
||
Object.keys(POSSIBLE_PACKAGES).forEach(flag => { | ||
const packageName = POSSIBLE_PACKAGES[flag]; | ||
let hasPackage = false; | ||
try { | ||
require.resolve(packageName); | ||
hasPackage = true; | ||
} catch (e) { | ||
hasPackage = false; | ||
} | ||
|
||
flags[flag] = hasPackage; | ||
}); | ||
|
||
return flags; | ||
} | ||
|
||
module.exports = getPackages(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters