@commercetools-frontend/babel-preset-mc-app 20.12.3 → 21.0.0-rc.7

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.0.0-rc.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
9
+ ## 21.0.0-rc.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`8c189ad3`](https://github.com/commercetools/merchant-center-application-kit/commit/8c189ad3233b7bf7846e097539f2c47827c79b2b) Thanks [@emmenko](https://github.com/emmenko)! - Update babel dependencies
14
+
15
+ ## 21.0.0-rc.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#2430](https://github.com/commercetools/merchant-center-application-kit/pull/2430) [`5ea8baf1`](https://github.com/commercetools/merchant-center-application-kit/commit/5ea8baf1b2ca2661aac9a6a572d2c8e596ee0b2c) Thanks [@emmenko](https://github.com/emmenko)! - Use version range for Babel packages.
20
+
21
+ ## 21.0.0-rc.0
22
+
23
+ ### Patch Changes
24
+
25
+ - [#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
26
+
3
27
  ## 20.12.3
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,157 +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
- 'The babel preset of `mc-scripts` 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
- },
73
- ],
74
- [
75
- require('@babel/preset-react').default,
76
- {
77
- // Adds component stack to warning messages
78
- // Adds __self attribute to JSX which React will use for some warnings
79
- development: isEnvDevelopment || isEnvTest,
80
- // Will use the native built-in instead of trying to polyfill
81
- // behavior for any plugins that require one.
82
- ...(options.runtime === 'automatic'
83
- ? // https://emotion.sh/docs/css-prop#babel-preset
84
- { importSource: '@emotion/react' }
85
- : { useBuiltIns: true }),
86
- runtime: options.runtime || 'classic',
87
- },
88
- ],
89
- // Use this preset only with the JSX runtime `classic`, otherwise
90
- // use the `@emotion/babel-plugin` plugin.
91
- // https://emotion.sh/docs/@emotion/babel-preset-css-prop
92
- options.runtime !== 'automatic' && [
93
- '@emotion/babel-preset-css-prop',
94
- {
95
- sourceMap: isEnvDevelopment,
96
- autoLabel: 'dev-only',
97
- },
98
- ],
99
- require('@babel/preset-typescript').default,
100
- ].filter(Boolean),
101
- plugins: [
102
- // Experimental macros support. Will be documented after it's had some time
103
- // in the wild.
104
- require('babel-plugin-macros'),
105
- require('babel-plugin-preval'),
106
- // export { default } from './foo'
107
- require('@babel/plugin-proposal-export-default-from'),
108
- // export * from './foo'
109
- require('@babel/plugin-proposal-export-namespace-from'),
110
- // Necessary to include regardless of the environment because
111
- // in practice some other transforms (such as object-rest-spread)
112
- // don't work without it: https://github.com/babel/babel/issues/7215
113
- require('@babel/plugin-transform-destructuring').default,
114
- // class { handleClick = () => { } }
115
- // Enable loose mode to use assignment instead of defineProperty
116
- // See discussion in https://github.com/facebook/create-react-app/issues/4263
117
- [
118
- require('@babel/plugin-proposal-class-properties').default,
119
- {
120
- loose: !options.disableLooseMode,
121
- },
122
- ],
123
- [
124
- require('@babel/plugin-proposal-private-methods').default,
125
- {
126
- loose: !options.disableLooseMode,
127
- },
128
- ],
129
- [
130
- require('@babel/plugin-proposal-private-property-in-object').default,
131
- {
132
- loose: !options.disableLooseMode,
133
- },
134
- ],
135
- // The following two plugins use Object.assign directly, instead of Babel's
136
- // extends helper. Note that this assumes `Object.assign` is available.
137
- // { ...todo, completed: true }
138
- [
139
- require('@babel/plugin-proposal-object-rest-spread').default,
140
- {
141
- useBuiltIns: true,
142
- },
143
- ],
144
- // Polyfills the runtime needed for async/await and generators
145
- [
146
- require('@babel/plugin-transform-runtime').default,
147
- {
148
- // corejs messes with jest@27 in tests, due to some
149
- // Promise/Date related polyfills it provides.
150
- corejs: options.disableCoreJs ? false : 3,
151
- // To be able to use `runtime` in Rollup babel plugin
152
- helpers: true,
153
- regenerator: true,
154
- },
155
- ],
156
- isEnvProduction && require('babel-plugin-dev-expression'),
157
- isEnvProduction && [
158
- // Remove PropTypes from production build
159
- require('babel-plugin-transform-react-remove-prop-types').default,
160
- // In case of rollup bundles, we want to keep the prop types but wrap
161
- // them into a `process.env.NODE_ENV !== "production"` so that when
162
- // building the final application bundles, those codes parts can be removed.
163
- options.keepPropTypes ? { mode: 'wrap' } : { removeImport: true },
164
- ],
165
- // function* () { yield 42; yield 43; }
166
- !isEnvTest && [
167
- require('@babel/plugin-transform-regenerator').default,
168
- {
169
- // Async functions are converted to generators by @babel/preset-env
170
- async: false,
171
- },
172
- ],
173
- require('@babel/plugin-proposal-do-expressions').default,
174
- require('@babel/plugin-proposal-logical-assignment-operators').default,
175
- // Use this plugin only with the JSX runtime `automatic`, otherwise
176
- // use the `@emotion/babel-preset-css-prop` preset.
177
- // https://emotion.sh/docs/@emotion/babel-preset-css-prop
178
- options.runtime === 'automatic' &&
179
- require('@emotion/babel-plugin').default,
180
- // Cherry-pick Lodash modules
181
- require('babel-plugin-lodash').default,
182
- ].filter(Boolean),
183
- };
11
+ return create(api, opts, env);
184
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/babel-preset-mc-app",
3
- "version": "20.12.3",
3
+ "version": "21.0.0-rc.7",
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,30 +17,33 @@
17
17
  "main": "./index.js",
18
18
  "module": "./index.js",
19
19
  "dependencies": {
20
- "@babel/core": "7.16.5",
21
- "@babel/plugin-proposal-class-properties": "7.16.5",
22
- "@babel/plugin-proposal-do-expressions": "7.16.5",
23
- "@babel/plugin-proposal-export-default-from": "7.16.5",
24
- "@babel/plugin-proposal-export-namespace-from": "7.16.5",
25
- "@babel/plugin-proposal-logical-assignment-operators": "7.16.5",
26
- "@babel/plugin-proposal-object-rest-spread": "7.16.5",
27
- "@babel/plugin-transform-classes": "7.16.5",
28
- "@babel/plugin-transform-destructuring": "7.16.5",
29
- "@babel/plugin-transform-react-display-name": "7.16.5",
30
- "@babel/plugin-transform-regenerator": "7.16.5",
31
- "@babel/plugin-transform-runtime": "7.16.5",
32
- "@babel/preset-env": "7.16.5",
33
- "@babel/preset-react": "7.16.5",
34
- "@babel/preset-typescript": "7.16.5",
35
- "@babel/runtime": "7.16.5",
36
- "@babel/runtime-corejs3": "7.16.5",
37
- "@emotion/babel-plugin": "11.7.1",
38
- "@emotion/babel-preset-css-prop": "11.2.0",
39
- "babel-plugin-dev-expression": "0.2.3",
40
- "babel-plugin-lodash": "3.3.4",
41
- "babel-plugin-macros": "3.1.0",
42
- "babel-plugin-preval": "5.0.0",
43
- "babel-plugin-transform-react-remove-prop-types": "0.4.24",
44
- "core-js": "3.20.0"
20
+ "@babel/core": "^7.16.10",
21
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
22
+ "@babel/plugin-proposal-do-expressions": "^7.16.7",
23
+ "@babel/plugin-proposal-export-default-from": "^7.16.7",
24
+ "@babel/plugin-proposal-export-namespace-from": "^7.16.7",
25
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.16.7",
26
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
27
+ "@babel/plugin-proposal-private-methods": "^7.16.11",
28
+ "@babel/plugin-proposal-private-property-in-object": "^7.16.7",
29
+ "@babel/plugin-transform-destructuring": "^7.16.7",
30
+ "@babel/plugin-transform-regenerator": "^7.16.7",
31
+ "@babel/plugin-transform-runtime": "^7.16.10",
32
+ "@babel/preset-env": "^7.16.11",
33
+ "@babel/preset-react": "^7.16.7",
34
+ "@babel/preset-typescript": "^7.16.7",
35
+ "@babel/runtime": "^7.16.7",
36
+ "@babel/runtime-corejs3": "^7.16.8",
37
+ "@emotion/babel-plugin": "^11.7.2",
38
+ "@emotion/babel-preset-css-prop": "^11.2.0",
39
+ "babel-plugin-dev-expression": "^0.2.3",
40
+ "babel-plugin-lodash": "^3.3.4",
41
+ "babel-plugin-macros": "^3.1.0",
42
+ "babel-plugin-preval": "^5.0.0",
43
+ "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
44
+ "core-js": "^3.20.3"
45
+ },
46
+ "engines": {
47
+ "node": ">=14"
45
48
  }
46
49
  }
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
+ };