@commercetools-frontend/babel-preset-mc-app 21.0.0-rc.5 → 21.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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @commercetools-frontend/babel-preset-mc-app
2
2
 
3
+ ## 21.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2520](https://github.com/commercetools/merchant-center-application-kit/pull/2520) [`6f3a2083`](https://github.com/commercetools/merchant-center-application-kit/commit/6f3a2083efac387e9a2994fbaaeb18914e739aa8) Thanks [@renovate](https://github.com/apps/renovate)! - Upgrade dependencies
8
+
9
+ ## 21.0.0
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`bb1f7d75`](https://github.com/commercetools/merchant-center-application-kit/commit/bb1f7d75ff54f7fef05c4d2b3328b88e400b4867) Thanks [@emmenko](https://github.com/emmenko)! - ESLint config depends on Babel preset. Add pre-configured entry points for Babel preset for different environments.
14
+
15
+ * [#2450](https://github.com/commercetools/merchant-center-application-kit/pull/2450) [`eb8f5b2c`](https://github.com/commercetools/merchant-center-application-kit/commit/eb8f5b2c885a4c3ffc7857a61e50508b429bf964) Thanks [@emmenko](https://github.com/emmenko)! - Update dependencies
16
+
17
+ - [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`bb1f7d75`](https://github.com/commercetools/merchant-center-application-kit/commit/bb1f7d75ff54f7fef05c4d2b3328b88e400b4867) Thanks [@emmenko](https://github.com/emmenko)! - Use version range for Babel packages.
18
+
19
+ * [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`bb1f7d75`](https://github.com/commercetools/merchant-center-application-kit/commit/bb1f7d75ff54f7fef05c4d2b3328b88e400b4867) Thanks [@emmenko](https://github.com/emmenko)! - Update babel dependencies
20
+
21
+ ## 21.0.0-rc.7
22
+
23
+ ### Patch Changes
24
+
25
+ - [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`71171d65`](https://github.com/commercetools/merchant-center-application-kit/commit/71171d65c276801d499f9b39923674114dff360c) Thanks [@emmenko](https://github.com/emmenko)! - ESLint config depends on Babel preset. Add pre-configured entry points for Babel preset for different environments.
26
+
3
27
  ## 21.0.0-rc.5
4
28
 
5
29
  ### Patch Changes
package/create.js ADDED
@@ -0,0 +1,186 @@
1
+ const defaultOptions = {
2
+ // Enables new JSX runtime `automatic`.
3
+ runtime: 'classic',
4
+ // If prop types should be removed from the bundle or not.
5
+ // Usually when bundling packages we want to keep the prop types
6
+ // but when building the final application we can remove them.
7
+ keepPropTypes: false,
8
+ // plugin-proposal-class-properties, plugin-proposal-private-methods,
9
+ // plugin-proposal-private-property-in-object have a loose option which
10
+ // needs to be synced. At times, for instance for better debuggability
11
+ // the loose option can be disabled at the cost of lowered performance.
12
+ disableLooseMode: false,
13
+ // Some environemnts do not require `core-js` and can hence disable
14
+ // it explicitely. This will disable `core-js` for `preset-env` and the
15
+ // `plugin-transform-runtime`.
16
+ disableCoreJs: false,
17
+ };
18
+
19
+ /* eslint-disable global-require */
20
+ module.exports = function createBabePresetConfigForMcApp(api, opts = {}, env) {
21
+ // Merge with default options
22
+ const options = { ...defaultOptions, ...opts };
23
+
24
+ const isEnvDevelopment = env === 'development';
25
+ const isEnvProduction = env === 'production';
26
+ const isEnvTest = env === 'test';
27
+
28
+ if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
29
+ throw new Error(
30
+ 'Using `babel-preset-mc-app` requires that you specify `NODE_ENV` or ' +
31
+ '`BABEL_ENV` environment variables. Valid values are "development", ' +
32
+ `"test", and "production". Instead, received: ${JSON.stringify(env)}.`
33
+ );
34
+ }
35
+
36
+ return {
37
+ presets: [
38
+ isEnvTest && [
39
+ // ES features necessary for user's Node version
40
+ require('@babel/preset-env').default,
41
+ {
42
+ targets: {
43
+ browsers: ['last 2 versions'],
44
+ node: 'current',
45
+ },
46
+ },
47
+ ],
48
+ (isEnvProduction || isEnvDevelopment) && [
49
+ // Latest stable ECMAScript features
50
+ require('@babel/preset-env').default,
51
+ {
52
+ targets: {
53
+ browsers: ['last 2 versions'],
54
+ },
55
+ ...(options.disableCoreJs
56
+ ? {}
57
+ : { corejs: { version: 3, proposals: true } }),
58
+ // `entry` transforms `@babel/polyfill` into individual requires for
59
+ // the targeted browsers. This is safer than `usage` which performs
60
+ // static code analysis to determine what's required.
61
+ // This is probably a fine default to help trim down bundles when
62
+ // end-users inevitably import '@babel/polyfill'.
63
+ useBuiltIns: !options.disableCoreJs ? 'entry' : false,
64
+ include: ['transform-classes'],
65
+ // Exclude transforms that make all code slower
66
+ exclude: ['transform-typeof-symbol'],
67
+ },
68
+ ],
69
+ [
70
+ require('@babel/preset-react').default,
71
+ {
72
+ // Adds component stack to warning messages
73
+ // Adds __self attribute to JSX which React will use for some warnings
74
+ development: isEnvDevelopment || isEnvTest,
75
+ // Will use the native built-in instead of trying to polyfill
76
+ // behavior for any plugins that require one.
77
+ ...(options.runtime === 'automatic'
78
+ ? // https://emotion.sh/docs/css-prop#babel-preset
79
+ { importSource: '@emotion/react' }
80
+ : { useBuiltIns: true }),
81
+ runtime: options.runtime || 'classic',
82
+ },
83
+ ],
84
+ // Use this preset only with the JSX runtime `classic`, otherwise
85
+ // use the `@emotion/babel-plugin` plugin.
86
+ // https://emotion.sh/docs/@emotion/babel-preset-css-prop
87
+ options.runtime !== 'automatic' && [
88
+ '@emotion/babel-preset-css-prop',
89
+ {
90
+ sourceMap: isEnvDevelopment,
91
+ autoLabel: 'dev-only',
92
+ },
93
+ ],
94
+ require('@babel/preset-typescript').default,
95
+ ].filter(Boolean),
96
+ plugins: [
97
+ // Experimental macros support. Will be documented after it's had some time
98
+ // in the wild.
99
+ require('babel-plugin-macros'),
100
+ require('babel-plugin-preval'),
101
+ // export { default } from './foo'
102
+ require('@babel/plugin-proposal-export-default-from'),
103
+ // export * from './foo'
104
+ require('@babel/plugin-proposal-export-namespace-from'),
105
+ // Necessary to include regardless of the environment because
106
+ // in practice some other transforms (such as object-rest-spread)
107
+ // don't work without it: https://github.com/babel/babel/issues/7215
108
+ require('@babel/plugin-transform-destructuring').default,
109
+ // class { handleClick = () => { } }
110
+ // Enable loose mode to use assignment instead of defineProperty
111
+ // See discussion in https://github.com/facebook/create-react-app/issues/4263
112
+ // Note:
113
+ // 'loose' mode configuration must be the same for
114
+ // * @babel/plugin-proposal-class-properties
115
+ // * @babel/plugin-proposal-private-methods
116
+ // * @babel/plugin-proposal-private-property-in-object
117
+ // (when they are enabled)
118
+ [
119
+ require('@babel/plugin-proposal-class-properties').default,
120
+ {
121
+ loose: !options.disableLooseMode,
122
+ },
123
+ ],
124
+ [
125
+ require('@babel/plugin-proposal-private-methods').default,
126
+ {
127
+ loose: !options.disableLooseMode,
128
+ },
129
+ ],
130
+ [
131
+ require('@babel/plugin-proposal-private-property-in-object').default,
132
+ {
133
+ loose: !options.disableLooseMode,
134
+ },
135
+ ],
136
+ // The following two plugins use Object.assign directly, instead of Babel's
137
+ // extends helper. Note that this assumes `Object.assign` is available.
138
+ // { ...todo, completed: true }
139
+ [
140
+ require('@babel/plugin-proposal-object-rest-spread').default,
141
+ {
142
+ useBuiltIns: true,
143
+ },
144
+ ],
145
+ // Polyfills the runtime needed for async/await, generators, and friends
146
+ // https://babeljs.io/docs/en/babel-plugin-transform-runtime
147
+ [
148
+ require('@babel/plugin-transform-runtime').default,
149
+ {
150
+ // corejs messes with jest@27 in tests, due to some
151
+ // Promise/Date related polyfills it provides.
152
+ corejs: options.disableCoreJs ? false : 3,
153
+ // To be able to use `runtime` in Rollup babel plugin
154
+ helpers: true,
155
+ regenerator: true,
156
+ },
157
+ ],
158
+ isEnvProduction && require('babel-plugin-dev-expression'),
159
+ isEnvProduction && [
160
+ // Remove PropTypes from production build
161
+ require('babel-plugin-transform-react-remove-prop-types').default,
162
+ // In case of rollup bundles, we want to keep the prop types but wrap
163
+ // them into a `process.env.NODE_ENV !== "production"` so that when
164
+ // building the final application bundles, those codes parts can be removed.
165
+ options.keepPropTypes ? { mode: 'wrap' } : { removeImport: true },
166
+ ],
167
+ // function* () { yield 42; yield 43; }
168
+ !isEnvTest && [
169
+ require('@babel/plugin-transform-regenerator').default,
170
+ {
171
+ // Async functions are converted to generators by @babel/preset-env
172
+ async: false,
173
+ },
174
+ ],
175
+ require('@babel/plugin-proposal-do-expressions').default,
176
+ require('@babel/plugin-proposal-logical-assignment-operators').default,
177
+ // Use this plugin only with the JSX runtime `automatic`, otherwise
178
+ // use the `@emotion/babel-preset-css-prop` preset.
179
+ // https://emotion.sh/docs/@emotion/babel-preset-css-prop
180
+ options.runtime === 'automatic' &&
181
+ require('@emotion/babel-plugin').default,
182
+ // Cherry-pick Lodash modules
183
+ require('babel-plugin-lodash').default,
184
+ ].filter(Boolean),
185
+ };
186
+ };
package/development.js ADDED
@@ -0,0 +1,5 @@
1
+ const create = require('./create');
2
+
3
+ module.exports = function getBabePresetConfigForMcAppForDevelopment(api, opts) {
4
+ return create(api, opts, 'development');
5
+ };
package/index.js CHANGED
@@ -1,26 +1,6 @@
1
- const defaultOptions = {
2
- // Enables new JSX runtime `automatic`.
3
- runtime: 'classic',
4
- // If prop types should be removed from the bundle or not.
5
- // Usually when bundling packages we want to keep the prop types
6
- // but when building the final application we can remove them.
7
- keepPropTypes: false,
8
- // plugin-proposal-class-properties, plugin-proposal-private-methods,
9
- // plugin-proposal-private-property-in-object have a loose option which
10
- // needs to be synced. At times, for instance for better debuggability
11
- // the loose option can be disabled at the cost of lowered performance.
12
- disableLooseMode: false,
13
- // Some environemnts do not require `core-js` and can hence disable
14
- // it explicitely. This will disable `core-js` for `preset-env` and the
15
- // `plugin-transform-runtime`.
16
- disableCoreJs: false,
17
- };
18
-
19
- /* eslint-disable global-require */
20
- module.exports = function getBabePresetConfigForMcApp(api, opts = {}) {
21
- // Merge with default options
22
- const options = { ...defaultOptions, ...opts };
1
+ const create = require('./create');
23
2
 
3
+ module.exports = function getBabePresetConfigForMcApp(api, opts) {
24
4
  // This is similar to how `env` works in Babel:
25
5
  // https://babeljs.io/docs/usage/babelrc/#env-option
26
6
  // We are not using `env` because it’s ignored in versions > babel-core@6.10.4:
@@ -28,166 +8,5 @@ module.exports = function getBabePresetConfigForMcApp(api, opts = {}) {
28
8
  // https://github.com/facebook/create-react-app/issues/720
29
9
  // It’s also nice that we can enforce `NODE_ENV` being specified.
30
10
  const env = process.env.BABEL_ENV || process.env.NODE_ENV;
31
- const isEnvDevelopment = env === 'development';
32
- const isEnvProduction = env === 'production';
33
- const isEnvTest = env === 'test';
34
-
35
- if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
36
- throw new Error(
37
- 'Using `babel-preset-mc-app` requires that you specify `NODE_ENV` or ' +
38
- '`BABEL_ENV` environment variables. Valid values are "development", ' +
39
- `"test", and "production". Instead, received: ${JSON.stringify(env)}.`
40
- );
41
- }
42
-
43
- return {
44
- presets: [
45
- isEnvTest && [
46
- // ES features necessary for user's Node version
47
- require('@babel/preset-env').default,
48
- {
49
- targets: {
50
- browsers: ['last 2 versions'],
51
- node: 'current',
52
- },
53
- },
54
- ],
55
- (isEnvProduction || isEnvDevelopment) && [
56
- // Latest stable ECMAScript features
57
- require('@babel/preset-env').default,
58
- {
59
- targets: {
60
- browsers: ['last 2 versions'],
61
- },
62
- ...(options.disableCoreJs
63
- ? {}
64
- : { corejs: { version: 3, proposals: true } }),
65
- // `entry` transforms `@babel/polyfill` into individual requires for
66
- // the targeted browsers. This is safer than `usage` which performs
67
- // static code analysis to determine what's required.
68
- // This is probably a fine default to help trim down bundles when
69
- // end-users inevitably import '@babel/polyfill'.
70
- useBuiltIns: !options.disableCoreJs ? 'entry' : false,
71
- include: ['transform-classes'],
72
- // Exclude transforms that make all code slower
73
- exclude: ['transform-typeof-symbol'],
74
- },
75
- ],
76
- [
77
- require('@babel/preset-react').default,
78
- {
79
- // Adds component stack to warning messages
80
- // Adds __self attribute to JSX which React will use for some warnings
81
- development: isEnvDevelopment || isEnvTest,
82
- // Will use the native built-in instead of trying to polyfill
83
- // behavior for any plugins that require one.
84
- ...(options.runtime === 'automatic'
85
- ? // https://emotion.sh/docs/css-prop#babel-preset
86
- { importSource: '@emotion/react' }
87
- : { useBuiltIns: true }),
88
- runtime: options.runtime || 'classic',
89
- },
90
- ],
91
- // Use this preset only with the JSX runtime `classic`, otherwise
92
- // use the `@emotion/babel-plugin` plugin.
93
- // https://emotion.sh/docs/@emotion/babel-preset-css-prop
94
- options.runtime !== 'automatic' && [
95
- '@emotion/babel-preset-css-prop',
96
- {
97
- sourceMap: isEnvDevelopment,
98
- autoLabel: 'dev-only',
99
- },
100
- ],
101
- require('@babel/preset-typescript').default,
102
- ].filter(Boolean),
103
- plugins: [
104
- // Experimental macros support. Will be documented after it's had some time
105
- // in the wild.
106
- require('babel-plugin-macros'),
107
- require('babel-plugin-preval'),
108
- // export { default } from './foo'
109
- require('@babel/plugin-proposal-export-default-from'),
110
- // export * from './foo'
111
- require('@babel/plugin-proposal-export-namespace-from'),
112
- // Necessary to include regardless of the environment because
113
- // in practice some other transforms (such as object-rest-spread)
114
- // don't work without it: https://github.com/babel/babel/issues/7215
115
- require('@babel/plugin-transform-destructuring').default,
116
- // class { handleClick = () => { } }
117
- // Enable loose mode to use assignment instead of defineProperty
118
- // See discussion in https://github.com/facebook/create-react-app/issues/4263
119
- // Note:
120
- // 'loose' mode configuration must be the same for
121
- // * @babel/plugin-proposal-class-properties
122
- // * @babel/plugin-proposal-private-methods
123
- // * @babel/plugin-proposal-private-property-in-object
124
- // (when they are enabled)
125
- [
126
- require('@babel/plugin-proposal-class-properties').default,
127
- {
128
- loose: !options.disableLooseMode,
129
- },
130
- ],
131
- [
132
- require('@babel/plugin-proposal-private-methods').default,
133
- {
134
- loose: !options.disableLooseMode,
135
- },
136
- ],
137
- [
138
- require('@babel/plugin-proposal-private-property-in-object').default,
139
- {
140
- loose: !options.disableLooseMode,
141
- },
142
- ],
143
- // The following two plugins use Object.assign directly, instead of Babel's
144
- // extends helper. Note that this assumes `Object.assign` is available.
145
- // { ...todo, completed: true }
146
- [
147
- require('@babel/plugin-proposal-object-rest-spread').default,
148
- {
149
- useBuiltIns: true,
150
- },
151
- ],
152
- // Polyfills the runtime needed for async/await, generators, and friends
153
- // https://babeljs.io/docs/en/babel-plugin-transform-runtime
154
- [
155
- require('@babel/plugin-transform-runtime').default,
156
- {
157
- // corejs messes with jest@27 in tests, due to some
158
- // Promise/Date related polyfills it provides.
159
- corejs: options.disableCoreJs ? false : 3,
160
- // To be able to use `runtime` in Rollup babel plugin
161
- helpers: true,
162
- regenerator: true,
163
- },
164
- ],
165
- isEnvProduction && require('babel-plugin-dev-expression'),
166
- isEnvProduction && [
167
- // Remove PropTypes from production build
168
- require('babel-plugin-transform-react-remove-prop-types').default,
169
- // In case of rollup bundles, we want to keep the prop types but wrap
170
- // them into a `process.env.NODE_ENV !== "production"` so that when
171
- // building the final application bundles, those codes parts can be removed.
172
- options.keepPropTypes ? { mode: 'wrap' } : { removeImport: true },
173
- ],
174
- // function* () { yield 42; yield 43; }
175
- !isEnvTest && [
176
- require('@babel/plugin-transform-regenerator').default,
177
- {
178
- // Async functions are converted to generators by @babel/preset-env
179
- async: false,
180
- },
181
- ],
182
- require('@babel/plugin-proposal-do-expressions').default,
183
- require('@babel/plugin-proposal-logical-assignment-operators').default,
184
- // Use this plugin only with the JSX runtime `automatic`, otherwise
185
- // use the `@emotion/babel-preset-css-prop` preset.
186
- // https://emotion.sh/docs/@emotion/babel-preset-css-prop
187
- options.runtime === 'automatic' &&
188
- require('@emotion/babel-plugin').default,
189
- // Cherry-pick Lodash modules
190
- require('babel-plugin-lodash').default,
191
- ].filter(Boolean),
192
- };
11
+ return create(api, opts, env);
193
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/babel-preset-mc-app",
3
- "version": "21.0.0-rc.5",
3
+ "version": "21.3.0",
4
4
  "description": "Babel preset used by a MC application",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -17,31 +17,31 @@
17
17
  "main": "./index.js",
18
18
  "module": "./index.js",
19
19
  "dependencies": {
20
- "@babel/core": "^7.16.10",
20
+ "@babel/core": "^7.17.8",
21
21
  "@babel/plugin-proposal-class-properties": "^7.16.7",
22
22
  "@babel/plugin-proposal-do-expressions": "^7.16.7",
23
23
  "@babel/plugin-proposal-export-default-from": "^7.16.7",
24
24
  "@babel/plugin-proposal-export-namespace-from": "^7.16.7",
25
25
  "@babel/plugin-proposal-logical-assignment-operators": "^7.16.7",
26
- "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
26
+ "@babel/plugin-proposal-object-rest-spread": "^7.17.3",
27
27
  "@babel/plugin-proposal-private-methods": "^7.16.11",
28
28
  "@babel/plugin-proposal-private-property-in-object": "^7.16.7",
29
- "@babel/plugin-transform-destructuring": "^7.16.7",
29
+ "@babel/plugin-transform-destructuring": "^7.17.7",
30
30
  "@babel/plugin-transform-regenerator": "^7.16.7",
31
- "@babel/plugin-transform-runtime": "^7.16.10",
31
+ "@babel/plugin-transform-runtime": "^7.17.0",
32
32
  "@babel/preset-env": "^7.16.11",
33
33
  "@babel/preset-react": "^7.16.7",
34
34
  "@babel/preset-typescript": "^7.16.7",
35
- "@babel/runtime": "^7.16.7",
36
- "@babel/runtime-corejs3": "^7.16.8",
35
+ "@babel/runtime": "^7.17.8",
36
+ "@babel/runtime-corejs3": "^7.17.8",
37
37
  "@emotion/babel-plugin": "^11.7.2",
38
38
  "@emotion/babel-preset-css-prop": "^11.2.0",
39
39
  "babel-plugin-dev-expression": "^0.2.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
41
41
  "babel-plugin-macros": "^3.1.0",
42
- "babel-plugin-preval": "^5.0.0",
42
+ "babel-plugin-preval": "^5.1.0",
43
43
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
44
- "core-js": "^3.20.3"
44
+ "core-js": "^3.21.1"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=14"
package/production.js ADDED
@@ -0,0 +1,5 @@
1
+ const create = require('./create');
2
+
3
+ module.exports = function getBabePresetConfigForMcAppForProduction(api, opts) {
4
+ return create(api, opts, 'production');
5
+ };
package/test.js ADDED
@@ -0,0 +1,5 @@
1
+ const create = require('./create');
2
+
3
+ module.exports = function getBabePresetConfigForMcAppForTest(api, opts) {
4
+ return create(api, opts, 'test');
5
+ };