Skip to content

Commit 47e9c5c

Browse files
authored
[ESLint] Disable on prod instances (#8229)
Resolves #5186
1 parent 0114075 commit 47e9c5c

File tree

3 files changed

+58
-75
lines changed

3 files changed

+58
-75
lines changed

Makefile

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
.PHONY: clean dev all check checkstatic unittests test phpdev javascript testdata
1+
.PHONY: clean dev all check checkstatic unittests phpdev jslatest testdata
22

3-
all: VERSION jsdev
3+
all: VERSION
44
composer install --no-dev
5+
npm ci
6+
npm run build
57

68
# If anything changes, re-generate the VERSION file
79
VERSION: .
@@ -10,7 +12,7 @@ VERSION: .
1012
phpdev:
1113
composer install
1214

13-
jsdev:
15+
dev: VERSION phpdev
1416
npm ci
1517
npm run compile
1618

@@ -20,8 +22,6 @@ jslatest: clean
2022
npm install
2123
npm run compile
2224

23-
dev: VERSION phpdev jsdev
24-
2525
clean:
2626
rm -f smarty/templates_c/*
2727
rm -f VERSION

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"tests:unit:debug": "DEBUG=true ./test/dockerized-unit-tests.sh",
6565
"tests:integration": "./test/dockerized-integration-tests.sh",
6666
"tests:integration:debug": "DEBUG=true ./test/dockerized-integration-tests.sh",
67-
"compile": "webpack",
67+
"compile": "webpack --node-env=development",
68+
"build": "webpack --node-env=production",
6869
"watch": "webpack --watch",
6970
"postinstall": "node npm-postinstall.js"
7071
},

webpack.config.js

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const ESLintPlugin = require('eslint-webpack-plugin');
22
const TerserPlugin = require('terser-webpack-plugin');
33
const CopyPlugin = require('copy-webpack-plugin');
4-
const webpack = require('webpack');
54
const path = require('path');
65
const fs = require('fs');
76
const cp = require('child_process');
@@ -134,19 +133,6 @@ mod.rules.push(
134133
},
135134
);
136135

137-
let mode = 'production';
138-
try {
139-
const configFile = fs.readFileSync('project/config.xml', 'latin1');
140-
const res = /<[\s]*?sandbox[\s]*?>(.*)<\/[\s]*?sandbox[\s]*?>/
141-
.exec(configFile);
142-
if (res && parseInt(res[1]) == 1) mode = 'development';
143-
} catch (error) {
144-
console.error(
145-
'Error - Can\'t read config.xml file. '
146-
+ 'Webpack mode set to production.'
147-
);
148-
}
149-
150136
/**
151137
* Creates a webpack config entry for a LORIS module named
152138
* mname.
@@ -181,24 +167,66 @@ function lorisModule(mname, entries) {
181167
'react-dom': 'ReactDOM',
182168
},
183169
devtool: 'source-map',
184-
plugins: [
185-
new webpack.DefinePlugin({
186-
'process.env.NODE_ENV': `"${mode}"`,
187-
}),
188-
...modulePlugins,
189-
],
170+
plugins: modulePlugins,
190171
optimization: optimization,
191172
resolve: resolve,
192173
module: mod,
193-
mode: 'none',
194174
stats: 'errors-only',
195175
};
196176
}
197177

178+
const plugins = [
179+
new CopyPlugin({
180+
patterns: [
181+
{
182+
from: path.resolve(__dirname, 'node_modules/react/umd'),
183+
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
184+
force: true,
185+
globOptions: {
186+
ignore: ['react.profiling.min.js'],
187+
},
188+
filter: async (path) => {
189+
const file = path.split('\\').pop().split('/').pop();
190+
const keep = [
191+
'react.development.js',
192+
'react.production.min.js',
193+
];
194+
return keep.includes(file);
195+
},
196+
},
197+
{
198+
from: path.resolve(__dirname, 'node_modules/react-dom/umd'),
199+
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
200+
force: true,
201+
filter: async (path) => {
202+
const file = path.split('\\').pop().split('/').pop();
203+
const keep = [
204+
'react-dom.development.js',
205+
'react-dom.production.min.js',
206+
];
207+
return keep.includes(file);
208+
},
209+
},
210+
],
211+
}),
212+
];
213+
214+
process.env.NODE_ENV == 'development' && plugins.push(new ESLintPlugin({
215+
extensions: ['ts', 'tsx', 'js', 'jsx'],
216+
files: [
217+
'modules/',
218+
'jsx/',
219+
'jslib/',
220+
'htdocs/js/',
221+
'webpack.config.js',
222+
'npm-postinstall.js',
223+
],
224+
cache: true,
225+
}));
226+
198227
let config = [
199228
// Core components
200229
{
201-
mode: mode,
202230
entry: {
203231
DynamicDataTable: './jsx/DynamicDataTable.js',
204232
PaginationLinks: './jsx/PaginationLinks.js',
@@ -220,53 +248,7 @@ let config = [
220248
'react-dom': 'ReactDOM',
221249
},
222250
devtool: 'source-map',
223-
plugins: [
224-
new ESLintPlugin({
225-
extensions: ['ts', 'tsx', 'js', 'jsx'],
226-
files: [
227-
'modules/',
228-
'jsx/',
229-
'jslib/',
230-
'htdocs/js/',
231-
'webpack.config.js',
232-
'npm-postinstall.js',
233-
],
234-
cache: true,
235-
}),
236-
new CopyPlugin({
237-
patterns: [
238-
{
239-
from: path.resolve(__dirname, 'node_modules/react/umd'),
240-
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
241-
force: true,
242-
globOptions: {
243-
ignore: ['react.profiling.min.js'],
244-
},
245-
filter: async (path) => {
246-
const file = path.split('\\').pop().split('/').pop();
247-
const keep = [
248-
'react.development.js',
249-
'react.production.min.js',
250-
];
251-
return keep.includes(file);
252-
},
253-
},
254-
{
255-
from: path.resolve(__dirname, 'node_modules/react-dom/umd'),
256-
to: path.resolve(__dirname, 'htdocs/vendor/js/react'),
257-
force: true,
258-
filter: async (path) => {
259-
const file = path.split('\\').pop().split('/').pop();
260-
const keep = [
261-
'react-dom.development.js',
262-
'react-dom.production.min.js',
263-
];
264-
return keep.includes(file);
265-
},
266-
},
267-
],
268-
}),
269-
],
251+
plugins: plugins,
270252
optimization: optimization,
271253
resolve: resolve,
272254
module: mod,

0 commit comments

Comments
 (0)