Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESLint] Disable on prod instances #8229

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.PHONY: clean dev all check checkstatic unittests test phpdev javascript testdata
.PHONY: clean dev all check checkstatic unittests phpdev jslatest testdata

all: VERSION jsdev
all: VERSION
composer install --no-dev
npm ci
npm run build

# If anything changes, re-generate the VERSION file
VERSION: .
Expand All @@ -10,7 +12,7 @@ VERSION: .
phpdev:
composer install

jsdev:
dev: VERSION phpdev
npm ci
npm run compile

Expand All @@ -20,8 +22,6 @@ jslatest: clean
npm install
npm run compile

dev: VERSION phpdev jsdev

clean:
rm -f smarty/templates_c/*
rm -f VERSION
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"tests:unit:debug": "DEBUG=true ./test/dockerized-unit-tests.sh",
"tests:integration": "./test/dockerized-integration-tests.sh",
"tests:integration:debug": "DEBUG=true ./test/dockerized-integration-tests.sh",
"compile": "webpack",
"compile": "webpack --node-env=development",
"build": "webpack --node-env=production",
"watch": "webpack --watch",
"postinstall": "node npm-postinstall.js"
},
Expand Down
120 changes: 51 additions & 69 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const ESLintPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const cp = require('child_process');
Expand Down Expand Up @@ -134,19 +133,6 @@ mod.rules.push(
},
);

let mode = 'production';
try {
const configFile = fs.readFileSync('project/config.xml', 'latin1');
const res = /<[\s]*?sandbox[\s]*?>(.*)<\/[\s]*?sandbox[\s]*?>/
.exec(configFile);
if (res && parseInt(res[1]) == 1) mode = 'development';
} catch (error) {
console.error(
'Error - Can\'t read config.xml file. '
+ 'Webpack mode set to production.'
);
}

/**
* Creates a webpack config entry for a LORIS module named
* mname.
Expand Down Expand Up @@ -181,24 +167,66 @@ function lorisModule(mname, entries) {
'react-dom': 'ReactDOM',
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${mode}"`,
}),
...modulePlugins,
],
plugins: modulePlugins,
optimization: optimization,
resolve: resolve,
module: mod,
mode: 'none',
stats: 'errors-only',
};
}

const plugins = [
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'node_modules/react/umd'),
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
force: true,
globOptions: {
ignore: ['react.profiling.min.js'],
},
filter: async (path) => {
const file = path.split('\\').pop().split('/').pop();
const keep = [
'react.development.js',
'react.production.min.js',
];
return keep.includes(file);
},
},
{
from: path.resolve(__dirname, 'node_modules/react-dom/umd'),
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
force: true,
filter: async (path) => {
const file = path.split('\\').pop().split('/').pop();
const keep = [
'react-dom.development.js',
'react-dom.production.min.js',
];
return keep.includes(file);
},
},
],
}),
];

process.env.NODE_ENV == 'development' && plugins.push(new ESLintPlugin({
extensions: ['ts', 'tsx', 'js', 'jsx'],
files: [
'modules/',
'jsx/',
'jslib/',
'htdocs/js/',
'webpack.config.js',
'npm-postinstall.js',
],
cache: true,
}));

let config = [
// Core components
{
mode: mode,
entry: {
DynamicDataTable: './jsx/DynamicDataTable.js',
PaginationLinks: './jsx/PaginationLinks.js',
Expand All @@ -220,53 +248,7 @@ let config = [
'react-dom': 'ReactDOM',
},
devtool: 'source-map',
plugins: [
new ESLintPlugin({
extensions: ['ts', 'tsx', 'js', 'jsx'],
files: [
'modules/',
'jsx/',
'jslib/',
'htdocs/js/',
'webpack.config.js',
'npm-postinstall.js',
],
cache: true,
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'node_modules/react/umd'),
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
force: true,
globOptions: {
ignore: ['react.profiling.min.js'],
},
filter: async (path) => {
const file = path.split('\\').pop().split('/').pop();
const keep = [
'react.development.js',
'react.production.min.js',
];
return keep.includes(file);
},
},
{
from: path.resolve(__dirname, 'node_modules/react-dom/umd'),
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
force: true,
filter: async (path) => {
const file = path.split('\\').pop().split('/').pop();
const keep = [
'react-dom.development.js',
'react-dom.production.min.js',
];
return keep.includes(file);
},
},
],
}),
],
plugins: plugins,
optimization: optimization,
resolve: resolve,
module: mod,
Expand Down