Skip to content

Commit

Permalink
Update CLI dependencies and features including React17 (#238)
Browse files Browse the repository at this point in the history
* 9037 Fix dotenv file loading order

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Upgrade to React 17

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Update dependencies

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Revert react-refresh-webpack-plugin version

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Replace inquirer with prompts

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Replace inquirer with prompts in eject

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* 9374 Fix: use default modules option from preset-env

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* PLAT-129601: Upgrade react-refresh-webpack-plugin 0.3.3 to 0.4.3 (#231)

* PLAT-129601: Upgrade @pmmmwh/react-refresh-webpack-plugin module from 0.3.3 to 0.4.1

* Update CHANGELOG.md

* Update package-lock.json

* Update commands/eject.js (for fixing lint error)

* Update package.json 2

* 9964 Add TypeScript 4.x as peerDependency

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* PLAT-129600: Replace deprecated eslint-loader by eslint-webpack-plugin (#235)

* PLAT-129600: Replace eslint-loader to eslint-webpack-plugin

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* fix lint

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* PLAT-121645: Add support for new JSX Transform (#236)

* PLAT-121645: Add support for new JSX Transform

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* fix lint error

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* fix lint

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Added a guard

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* update dependecies

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* Update @enact/moonstone-template dependency

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

* added changelog

Enact-DCO-1.0-Signed-off-by: Mikyung Kim (mikyung27.kim@lge.com)

Co-authored-by: taeyoung.hong <35059065+hong6316@users.noreply.github.com>
  • Loading branch information
MikyungKim and hong6316 authored Feb 26, 2021
1 parent df2e202 commit 6472be7
Show file tree
Hide file tree
Showing 9 changed files with 2,729 additions and 2,502 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## unreleased

### create

* Updated moonstone template for Enact 4.0.0-alpha.1 release.

### eject, template

* Replaced `inquirer` with `prompts`.

### pack

* Updated CLI dependency of `react` and `react-dom` to 17.0.1.
* Added `typescript` 4.x as peerDependency.
* Replaced deprecated `eslint-loader` by `eslint-webpack-plugin`.
* Added support for new JSX Transform.

### serve

* Updated CLI dependency of `@pmmmwh/react-refresh-webpack-plugin` to 0.4.3.

### test

* Updated CLI dependency of `react-test-renderer` to 17.0.1.

### lint

* Added support for new JSX Transform.

## 3.0.5 (February 3, 2021)

### serve
Expand Down
62 changes: 30 additions & 32 deletions commands/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const os = require('os');
const path = require('path');
const chalk = require('chalk');
const fs = require('fs-extra');
const inquirer = require('react-dev-utils/inquirer');
const prompts = require('prompts');
const minimist = require('minimist');
const {packageRoot} = require('@enact/dev-utils');
const spawn = require('cross-spawn');
Expand Down Expand Up @@ -68,38 +68,36 @@ function displayHelp() {
}

function validateEject() {
return inquirer
.prompt({
type: 'confirm',
name: 'shouldEject',
message: 'Are you sure you want to eject? This action is permanent.',
default: false
})
.then(answer => {
if (!answer.shouldEject) {
console.log(chalk.cyan('Close one! Eject aborted.'));
return {abort: true};
} else {
checkGitStatus();
return prompts({
type: 'confirm',
name: 'shouldEject',
message: 'Are you sure you want to eject? This action is permanent.',
default: false
}).then(answer => {
if (!answer.shouldEject) {
console.log(chalk.cyan('Close one! Eject aborted.'));
return {abort: true};
} else {
checkGitStatus();

// Make shallow array of files paths
const files = assets.reduce((list, dir) => {
return list.concat(
fs
.readdirSync(dir.src)
// set full relative path
.map(file => ({
src: path.join(dir.src, file),
dest: path.join(dir.dest, file)
}))
// omit dirs from file list
.filter(file => fs.lstatSync(file.src).isFile())
);
}, []);
files.forEach(verifyAbsent);
return {files};
}
});
// Make shallow array of files paths
const files = assets.reduce((list, dir) => {
return list.concat(
fs
.readdirSync(dir.src)
// set full relative path
.map(file => ({
src: path.join(dir.src, file),
dest: path.join(dir.dest, file)
}))
// omit dirs from file list
.filter(file => fs.lstatSync(file.src).isFile())
);
}, []);
files.forEach(verifyAbsent);
return {files};
}
});
}

function checkGitStatus() {
Expand Down
4 changes: 2 additions & 2 deletions commands/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chalk = require('chalk');
const spawn = require('cross-spawn');
const fs = require('fs-extra');
const minimist = require('minimist');
const inquirer = require('react-dev-utils/inquirer');
const prompts = require('prompts');
const tar = require('tar');

const TEMPLATE_DIR = path.join(process.env.APPDATA || os.homedir(), '.enact');
Expand Down Expand Up @@ -218,7 +218,7 @@ function doDefault(name) {
choice = Promise.resolve({template: name});
} else {
const i = all.find(t => fs.realpathSync(path.join(TEMPLATE_DIR, t)) === fs.realpathSync(DEFAULT_LINK));
choice = inquirer.prompt([
choice = prompts([
{
name: 'template',
type: 'list',
Expand Down
19 changes: 16 additions & 3 deletions config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
*/
const path = require('path');

// Check if JSX transform is able
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();

module.exports = function (api) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const es5Standalone = process.env.ES5 && process.env.ES5 !== 'false';
Expand Down Expand Up @@ -36,8 +50,7 @@ module.exports = function (api) {
],
forceAllTransforms: es5Standalone,
useBuiltIns: 'entry',
corejs: 3,
modules: false
corejs: 3
}
],
[
Expand All @@ -48,7 +61,7 @@ module.exports = function (api) {
development: env !== 'production' && !es5Standalone,
// Will use the native built-in instead of trying to polyfill
// behavior for any plugins that require one.
useBuiltIns: true
...(!hasJsxRuntime ? {useBuiltIns: true} : {runtime: 'automatic'})
}
],
['@babel/preset-typescript']
Expand Down
2 changes: 1 addition & 1 deletion config/dotenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module.exports = {
const mode = process.env.NODE_ENV || 'development';
[
`.env.${mode}.local`,
`.env.${mode}`,
// Similar to create-react app, don't include `.env.local` for
// `test` environment for test result consistency.
mode !== 'test' && `.env.local`,
`.env.${mode}`,
'.env'
]
.filter(Boolean)
Expand Down
2 changes: 1 addition & 1 deletion config/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');
const enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
const {packageRoot} = require('@enact/dev-utils');

const filters = [
Expand Down
59 changes: 37 additions & 22 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const fs = require('fs');
const path = require('path');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
Expand Down Expand Up @@ -46,6 +47,20 @@ module.exports = function (env) {
// Sets the browserslist default fallback set of browsers to the Enact default browser support list.
app.setEnactTargetsAsDefault();

// Check if JSX transform is able
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();

// Check if TypeScript is setup
const useTypeScript = fs.existsSync('tsconfig.json');

Expand Down Expand Up @@ -213,27 +228,6 @@ module.exports = function (env) {
// @remove-on-eject-end
module: {
rules: [
// First, run the linter.
// It's important to do this before Babel processes the JS.
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
enforce: 'pre',
exclude: /node_modules/,
loader: require.resolve('eslint-loader'),
// Point ESLint to our predefined config.
options: {
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
resolvePluginsRelativeTo: __dirname,
// @remove-on-eject-begin
baseConfig: {
extends: [require.resolve('eslint-config-enact')]
},
useEslintrc: false,
// @remove-on-eject-end
cache: true
}
},
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
Expand Down Expand Up @@ -473,7 +467,28 @@ module.exports = function (env) {
silent: true,
// The formatter is invoked directly in WebpackDevServerUtils during development
formatter: !process.env.DISABLE_TSFORMATTER ? typescriptFormatter : undefined
})
}),
new ESLintPlugin({
// Plugin options
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
// ESLint class options
resolvePluginsRelativeTo: __dirname,
// @remove-on-eject-begin
baseConfig: {
extends: [require.resolve('eslint-config-enact')],
rules: {
...(!hasJsxRuntime && {
'react/jsx-uses-react': 'warn',
'react/react-in-jsx-scope': 'warn'
})
}
},
useEslintrc: false,
// @remove-on-eject-end
cache: true
})
].filter(Boolean)
};
};
Loading

0 comments on commit 6472be7

Please sign in to comment.