Skip to content

Commit

Permalink
[ESLint] Disable on prod instances
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Dec 20, 2022
1 parent 93e473c commit df4d320
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 75 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.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
npm ci
npm run build
composer install --no-dev

# If anything changes, re-generate the VERSION file
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

0 comments on commit df4d320

Please sign in to comment.