@carbon/feature-flags 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,7 +60,7 @@ import { enable, disable, merge } from '@carbon/feature-flags';
60
60
  enable('feature-flag-a');
61
61
 
62
62
  // Disable `feature-flag-a`
63
- disable('feature-flag-a);
63
+ disable('feature-flag-a');
64
64
 
65
65
  // Set a variety of feature flags to a specific value
66
66
  merge({
package/es/index.js CHANGED
@@ -5,82 +5,189 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ const enabled$1 = {};
9
+
10
+ try {
11
+ if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES) {
12
+ if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES === 'true') {
13
+ enabled$1.enableCssCustomProperties = true;
14
+ } else {
15
+ enabled$1.enableCssCustomProperties = false;
16
+ }
17
+ } else {
18
+ enabled$1.enableCssCustomProperties = false;
19
+ }
20
+
21
+ if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE) {
22
+ if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE === 'true') {
23
+ enabled$1.enableUseControlledStateWithValue = true;
24
+ } else {
25
+ enabled$1.enableUseControlledStateWithValue = false;
26
+ }
27
+ } else {
28
+ enabled$1.enableUseControlledStateWithValue = false;
29
+ }
30
+
31
+ if (process.env.CARBON_ENABLE_CSS_GRID) {
32
+ if (process.env.CARBON_ENABLE_CSS_GRID === 'true') {
33
+ enabled$1.enableCssGrid = true;
34
+ } else {
35
+ enabled$1.enableCssGrid = false;
36
+ }
37
+ } else {
38
+ enabled$1.enableCssGrid = false;
39
+ }
40
+
41
+ if (process.env.CARBON_ENABLE_2021_RELEASE) {
42
+ if (process.env.CARBON_ENABLE_2021_RELEASE === 'true') {
43
+ enabled$1.enable_2021Release = true;
44
+ } else {
45
+ enabled$1.enable_2021Release = false;
46
+ }
47
+ } else {
48
+ enabled$1.enable_2021Release = false;
49
+ }
50
+ } catch (error) {
51
+ enabled$1.enableCssCustomProperties = false;
52
+ enabled$1.enableUseControlledStateWithValue = false;
53
+ enabled$1.enableCssGrid = false;
54
+ enabled$1.enable_2021Release = false;
55
+ }
56
+
8
57
  const featureFlagInfo = [{
9
58
  name: "enable-css-custom-properties",
10
59
  description: "Describe what the flag does",
11
- enabled: process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES || false
60
+ enabled: enabled$1.enableCssCustomProperties
12
61
  }, {
13
62
  name: "enable-use-controlled-state-with-value",
14
63
  description: "Enable components to be created in either a controlled or uncontrolled mode\n",
15
- enabled: process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE || false
64
+ enabled: enabled$1.enableUseControlledStateWithValue
65
+ }, {
66
+ name: "enable-css-grid",
67
+ description: "Enable CSS Grid Layout in the Grid and Column React components\n",
68
+ enabled: enabled$1.enableCssGrid
69
+ }, {
70
+ name: "enable-2021-release",
71
+ description: "Enable the features and functionality for the 2021 Release\n",
72
+ enabled: enabled$1.enable_2021Release
16
73
  }];
17
74
 
18
- const featureFlags = new Map();
75
+ class FeatureFlagScope {
76
+ constructor(flags) {
77
+ this.flags = new Map();
78
+
79
+ if (flags) {
80
+ Object.keys(flags).forEach((key) => {
81
+ this.flags.set(key, flags[key]);
82
+ });
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Check to see if a flag exists
88
+ * @param {string} name
89
+ */
90
+ checkForFlag(name) {
91
+ if (!this.flags.has(name)) {
92
+ throw new Error(
93
+ `Unable to find a feature flag with the name: \`${name}\``
94
+ );
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Add a feature flag
100
+ * @param {string} name
101
+ * @param {boolean} enabled
102
+ */
103
+ add(name, enabled) {
104
+ if (this.flags.has(name)) {
105
+ throw new Error(`The feature flag: ${name} already exists`);
106
+ }
107
+ this.flags.set(name, enabled);
108
+ }
109
+
110
+ /**
111
+ * Enable a feature flag
112
+ * @param {string} name
113
+ */
114
+ enable(name) {
115
+ this.checkForFlag(name);
116
+ this.flags.set(name, true);
117
+ }
118
+
119
+ /**
120
+ * Disable a feature flag
121
+ * @param {string} name
122
+ */
123
+ disable(name) {
124
+ this.checkForFlag(name);
125
+ this.flags.set(name, false);
126
+ }
127
+
128
+ /**
129
+ * Merge the given feature flags with the current set of feature flags.
130
+ * Duplicate keys will be set to the value in the given feature flags.
131
+ * @param {object} flags
132
+ */
133
+ merge(flags) {
134
+ Object.keys(flags).forEach((key) => {
135
+ this.flags.set(key, flags[key]);
136
+ });
137
+ }
138
+
139
+ /**
140
+ * @param {FeatureFlagScope} scope
141
+ */
142
+ mergeWithScope(scope) {
143
+ for (const [key, value] of scope.flags) {
144
+ if (this.flags.has(key)) {
145
+ continue;
146
+ }
147
+ this.flags.set(key, value);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Check if a feature flag is enabled
153
+ * @param {string} name
154
+ * @returns {boolean}
155
+ */
156
+ enabled(name) {
157
+ this.checkForFlag(name);
158
+ return this.flags.get(name);
159
+ }
160
+ }
161
+
162
+ const FeatureFlags = createScope();
19
163
 
20
164
  for (let i = 0; i < featureFlagInfo.length; i++) {
21
165
  const featureFlag = featureFlagInfo[i];
22
- featureFlags.set(featureFlag.name, featureFlag.enabled);
166
+ FeatureFlags.add(featureFlag.name, featureFlag.enabled);
23
167
  }
24
168
 
25
- /**
26
- * Check to see if a flag exists
27
- * @param {string} name
28
- */
29
- function checkForFlag(name) {
30
- if (!featureFlags.has(name)) {
31
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
32
- }
169
+ function createScope(flags) {
170
+ return new FeatureFlagScope(flags);
33
171
  }
34
172
 
35
- /**
36
- * Add a feature flag
37
- * @param {string} name
38
- * @param {boolean} enabled
39
- */
40
- function add(name, enabled) {
41
- if (featureFlags.has(name)) {
42
- throw new Error(`The feature flag: ${name} already exists`);
43
- }
44
- featureFlags.set(name, enabled);
173
+ function add(...args) {
174
+ return FeatureFlags.add(...args);
45
175
  }
46
176
 
47
- /**
48
- * Enable a feature flag
49
- * @param {string} name
50
- */
51
- function enable(name) {
52
- checkForFlag(name);
53
- featureFlags.set(name, true);
177
+ function enable(...args) {
178
+ return FeatureFlags.enable(...args);
54
179
  }
55
180
 
56
- /**
57
- * Disable a feature flag
58
- * @param {string} name
59
- */
60
- function disable(name) {
61
- checkForFlag(name);
62
- featureFlags.set(name, false);
181
+ function disable(...args) {
182
+ return FeatureFlags.disable(...args);
63
183
  }
64
184
 
65
- /**
66
- * Merge the given feature flags with the current set of feature flags.
67
- * Duplicate keys will be set to the value in the given feature flags.
68
- * @param {object} flags
69
- */
70
- function merge(flags) {
71
- Object.keys(flags).forEach((key) => {
72
- featureFlags.set(key, flags[key]);
73
- });
185
+ function enabled(...args) {
186
+ return FeatureFlags.enabled(...args);
74
187
  }
75
188
 
76
- /**
77
- * Check if a feature flag is enabled
78
- * @param {string} name
79
- * @returns {boolean}
80
- */
81
- function enabled(name) {
82
- checkForFlag(name);
83
- return featureFlags.get(name);
189
+ function merge(...args) {
190
+ return FeatureFlags.merge(...args);
84
191
  }
85
192
 
86
- export { add, disable, enable, enabled, merge, featureFlagInfo as unstable_featureFlagInfo };
193
+ export { FeatureFlags, add, createScope, disable, enable, enabled, merge };
package/lib/index.js CHANGED
@@ -9,87 +9,195 @@
9
9
 
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
+ const enabled$1 = {};
13
+
14
+ try {
15
+ if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES) {
16
+ if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES === 'true') {
17
+ enabled$1.enableCssCustomProperties = true;
18
+ } else {
19
+ enabled$1.enableCssCustomProperties = false;
20
+ }
21
+ } else {
22
+ enabled$1.enableCssCustomProperties = false;
23
+ }
24
+
25
+ if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE) {
26
+ if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE === 'true') {
27
+ enabled$1.enableUseControlledStateWithValue = true;
28
+ } else {
29
+ enabled$1.enableUseControlledStateWithValue = false;
30
+ }
31
+ } else {
32
+ enabled$1.enableUseControlledStateWithValue = false;
33
+ }
34
+
35
+ if (process.env.CARBON_ENABLE_CSS_GRID) {
36
+ if (process.env.CARBON_ENABLE_CSS_GRID === 'true') {
37
+ enabled$1.enableCssGrid = true;
38
+ } else {
39
+ enabled$1.enableCssGrid = false;
40
+ }
41
+ } else {
42
+ enabled$1.enableCssGrid = false;
43
+ }
44
+
45
+ if (process.env.CARBON_ENABLE_2021_RELEASE) {
46
+ if (process.env.CARBON_ENABLE_2021_RELEASE === 'true') {
47
+ enabled$1.enable_2021Release = true;
48
+ } else {
49
+ enabled$1.enable_2021Release = false;
50
+ }
51
+ } else {
52
+ enabled$1.enable_2021Release = false;
53
+ }
54
+ } catch (error) {
55
+ enabled$1.enableCssCustomProperties = false;
56
+ enabled$1.enableUseControlledStateWithValue = false;
57
+ enabled$1.enableCssGrid = false;
58
+ enabled$1.enable_2021Release = false;
59
+ }
60
+
12
61
  const featureFlagInfo = [{
13
62
  name: "enable-css-custom-properties",
14
63
  description: "Describe what the flag does",
15
- enabled: process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES || false
64
+ enabled: enabled$1.enableCssCustomProperties
16
65
  }, {
17
66
  name: "enable-use-controlled-state-with-value",
18
67
  description: "Enable components to be created in either a controlled or uncontrolled mode\n",
19
- enabled: process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE || false
68
+ enabled: enabled$1.enableUseControlledStateWithValue
69
+ }, {
70
+ name: "enable-css-grid",
71
+ description: "Enable CSS Grid Layout in the Grid and Column React components\n",
72
+ enabled: enabled$1.enableCssGrid
73
+ }, {
74
+ name: "enable-2021-release",
75
+ description: "Enable the features and functionality for the 2021 Release\n",
76
+ enabled: enabled$1.enable_2021Release
20
77
  }];
21
78
 
22
- const featureFlags = new Map();
79
+ class FeatureFlagScope {
80
+ constructor(flags) {
81
+ this.flags = new Map();
82
+
83
+ if (flags) {
84
+ Object.keys(flags).forEach((key) => {
85
+ this.flags.set(key, flags[key]);
86
+ });
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Check to see if a flag exists
92
+ * @param {string} name
93
+ */
94
+ checkForFlag(name) {
95
+ if (!this.flags.has(name)) {
96
+ throw new Error(
97
+ `Unable to find a feature flag with the name: \`${name}\``
98
+ );
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Add a feature flag
104
+ * @param {string} name
105
+ * @param {boolean} enabled
106
+ */
107
+ add(name, enabled) {
108
+ if (this.flags.has(name)) {
109
+ throw new Error(`The feature flag: ${name} already exists`);
110
+ }
111
+ this.flags.set(name, enabled);
112
+ }
113
+
114
+ /**
115
+ * Enable a feature flag
116
+ * @param {string} name
117
+ */
118
+ enable(name) {
119
+ this.checkForFlag(name);
120
+ this.flags.set(name, true);
121
+ }
122
+
123
+ /**
124
+ * Disable a feature flag
125
+ * @param {string} name
126
+ */
127
+ disable(name) {
128
+ this.checkForFlag(name);
129
+ this.flags.set(name, false);
130
+ }
131
+
132
+ /**
133
+ * Merge the given feature flags with the current set of feature flags.
134
+ * Duplicate keys will be set to the value in the given feature flags.
135
+ * @param {object} flags
136
+ */
137
+ merge(flags) {
138
+ Object.keys(flags).forEach((key) => {
139
+ this.flags.set(key, flags[key]);
140
+ });
141
+ }
142
+
143
+ /**
144
+ * @param {FeatureFlagScope} scope
145
+ */
146
+ mergeWithScope(scope) {
147
+ for (const [key, value] of scope.flags) {
148
+ if (this.flags.has(key)) {
149
+ continue;
150
+ }
151
+ this.flags.set(key, value);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Check if a feature flag is enabled
157
+ * @param {string} name
158
+ * @returns {boolean}
159
+ */
160
+ enabled(name) {
161
+ this.checkForFlag(name);
162
+ return this.flags.get(name);
163
+ }
164
+ }
165
+
166
+ const FeatureFlags = createScope();
23
167
 
24
168
  for (let i = 0; i < featureFlagInfo.length; i++) {
25
169
  const featureFlag = featureFlagInfo[i];
26
- featureFlags.set(featureFlag.name, featureFlag.enabled);
170
+ FeatureFlags.add(featureFlag.name, featureFlag.enabled);
27
171
  }
28
172
 
29
- /**
30
- * Check to see if a flag exists
31
- * @param {string} name
32
- */
33
- function checkForFlag(name) {
34
- if (!featureFlags.has(name)) {
35
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
36
- }
173
+ function createScope(flags) {
174
+ return new FeatureFlagScope(flags);
37
175
  }
38
176
 
39
- /**
40
- * Add a feature flag
41
- * @param {string} name
42
- * @param {boolean} enabled
43
- */
44
- function add(name, enabled) {
45
- if (featureFlags.has(name)) {
46
- throw new Error(`The feature flag: ${name} already exists`);
47
- }
48
- featureFlags.set(name, enabled);
177
+ function add(...args) {
178
+ return FeatureFlags.add(...args);
49
179
  }
50
180
 
51
- /**
52
- * Enable a feature flag
53
- * @param {string} name
54
- */
55
- function enable(name) {
56
- checkForFlag(name);
57
- featureFlags.set(name, true);
181
+ function enable(...args) {
182
+ return FeatureFlags.enable(...args);
58
183
  }
59
184
 
60
- /**
61
- * Disable a feature flag
62
- * @param {string} name
63
- */
64
- function disable(name) {
65
- checkForFlag(name);
66
- featureFlags.set(name, false);
185
+ function disable(...args) {
186
+ return FeatureFlags.disable(...args);
67
187
  }
68
188
 
69
- /**
70
- * Merge the given feature flags with the current set of feature flags.
71
- * Duplicate keys will be set to the value in the given feature flags.
72
- * @param {object} flags
73
- */
74
- function merge(flags) {
75
- Object.keys(flags).forEach((key) => {
76
- featureFlags.set(key, flags[key]);
77
- });
189
+ function enabled(...args) {
190
+ return FeatureFlags.enabled(...args);
78
191
  }
79
192
 
80
- /**
81
- * Check if a feature flag is enabled
82
- * @param {string} name
83
- * @returns {boolean}
84
- */
85
- function enabled(name) {
86
- checkForFlag(name);
87
- return featureFlags.get(name);
193
+ function merge(...args) {
194
+ return FeatureFlags.merge(...args);
88
195
  }
89
196
 
197
+ exports.FeatureFlags = FeatureFlags;
90
198
  exports.add = add;
199
+ exports.createScope = createScope;
91
200
  exports.disable = disable;
92
201
  exports.enable = enable;
93
202
  exports.enabled = enabled;
94
203
  exports.merge = merge;
95
- exports.unstable_featureFlagInfo = featureFlagInfo;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/feature-flags",
3
3
  "description": "Build with feature flags in Carbon",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -11,6 +11,12 @@
11
11
  "directory": "packages/feature-flags"
12
12
  },
13
13
  "bugs": "https://github.com/carbon-design-system/carbon/issues",
14
+ "files": [
15
+ "es",
16
+ "lib",
17
+ "scss",
18
+ "index.scss"
19
+ ],
14
20
  "keywords": [
15
21
  "ibm",
16
22
  "carbon",
@@ -28,6 +34,7 @@
28
34
  },
29
35
  "devDependencies": {
30
36
  "@babel/generator": "^7.10.2",
37
+ "@babel/template": "^7.12.13",
31
38
  "@babel/types": "^7.10.2",
32
39
  "@carbon/scss-generator": "^10.13.0",
33
40
  "change-case": "^4.1.2",
@@ -38,5 +45,5 @@
38
45
  "rollup-plugin-strip-banner": "^2.0.0"
39
46
  },
40
47
  "sideEffects": false,
41
- "gitHead": "d3dc7ca3254a97d52d39ef8d26b9afdbc1235390"
48
+ "gitHead": "05909da32a2ee6aa2fb1965eb57871ea77c81c0e"
42
49
  }
@@ -9,4 +9,6 @@
9
9
  $generated-feature-flags: (
10
10
  'enable-css-custom-properties': false,
11
11
  'enable-use-controlled-state-with-value': false,
12
+ 'enable-css-grid': false,
13
+ 'enable-2021-release': false,
12
14
  );
package/feature-flags.yml DELETED
@@ -1,16 +0,0 @@
1
- #
2
- # Copyright IBM Corp. 2015, 2020
3
- #
4
- # This source code is licensed under the Apache-2.0 license found in the
5
- # LICENSE file in the root directory of this source tree.
6
- #
7
-
8
- feature-flags:
9
- - name: enable-css-custom-properties
10
- description: Describe what the flag does
11
- enabled: false
12
- - name: enable-use-controlled-state-with-value
13
- description: >
14
- Enable components to be created in either a controlled or uncontrolled
15
- mode
16
- enabled: false
package/rollup.config.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2015, 2020
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import path from 'path';
9
- import stripBanner from 'rollup-plugin-strip-banner';
10
-
11
- const BANNER = `/**
12
- * Copyright IBM Corp. 2015, 2020
13
- *
14
- * This source code is licensed under the Apache-2.0 license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- */
17
- `;
18
-
19
- const baseConfig = {
20
- external: [],
21
- plugins: [
22
- stripBanner(),
23
- {
24
- renderChunk(code) {
25
- return `${BANNER}\n${code}`;
26
- },
27
- },
28
- ],
29
- };
30
-
31
- export default [
32
- {
33
- ...baseConfig,
34
- input: path.join(__dirname, './src/index.js'),
35
- output: {
36
- file: 'es/index.js',
37
- format: 'esm',
38
- },
39
- },
40
- {
41
- ...baseConfig,
42
- input: path.join(__dirname, './src/index.js'),
43
- output: {
44
- file: 'lib/index.js',
45
- format: 'commonjs',
46
- },
47
- },
48
- ];
@@ -1,17 +0,0 @@
1
- /**
2
- * Code generated by @carbon/feature-flags. DO NOT EDIT.
3
- *
4
- * Copyright IBM Corp. 2015, 2020
5
- *
6
- * This source code is licensed under the Apache-2.0 license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
- export const featureFlagInfo = [{
10
- name: "enable-css-custom-properties",
11
- description: "Describe what the flag does",
12
- enabled: process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES || false
13
- }, {
14
- name: "enable-use-controlled-state-with-value",
15
- description: "Enable components to be created in either a controlled or uncontrolled mode\n",
16
- enabled: process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE || false
17
- }];
package/src/index.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2015, 2020
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import { featureFlagInfo } from './generated/feature-flags';
9
-
10
- const featureFlags = new Map();
11
-
12
- for (let i = 0; i < featureFlagInfo.length; i++) {
13
- const featureFlag = featureFlagInfo[i];
14
- featureFlags.set(featureFlag.name, featureFlag.enabled);
15
- }
16
-
17
- /**
18
- * Check to see if a flag exists
19
- * @param {string} name
20
- */
21
- function checkForFlag(name) {
22
- if (!featureFlags.has(name)) {
23
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
24
- }
25
- }
26
-
27
- /**
28
- * Add a feature flag
29
- * @param {string} name
30
- * @param {boolean} enabled
31
- */
32
- export function add(name, enabled) {
33
- if (featureFlags.has(name)) {
34
- throw new Error(`The feature flag: ${name} already exists`);
35
- }
36
- featureFlags.set(name, enabled);
37
- }
38
-
39
- /**
40
- * Enable a feature flag
41
- * @param {string} name
42
- */
43
- export function enable(name) {
44
- checkForFlag(name);
45
- featureFlags.set(name, true);
46
- }
47
-
48
- /**
49
- * Disable a feature flag
50
- * @param {string} name
51
- */
52
- export function disable(name) {
53
- checkForFlag(name);
54
- featureFlags.set(name, false);
55
- }
56
-
57
- /**
58
- * Merge the given feature flags with the current set of feature flags.
59
- * Duplicate keys will be set to the value in the given feature flags.
60
- * @param {object} flags
61
- */
62
- export function merge(flags) {
63
- Object.keys(flags).forEach((key) => {
64
- featureFlags.set(key, flags[key]);
65
- });
66
- }
67
-
68
- /**
69
- * Check if a feature flag is enabled
70
- * @param {string} name
71
- * @returns {boolean}
72
- */
73
- export function enabled(name) {
74
- checkForFlag(name);
75
- return featureFlags.get(name);
76
- }
77
-
78
- export { featureFlagInfo as unstable_featureFlagInfo };