Skip to content

Commit 9e4ee43

Browse files
committed
[ESLint] Disable on prod instances
1 parent 13b3f8a commit 9e4ee43

File tree

3 files changed

+58
-75
lines changed

3 files changed

+58
-75
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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
4+
npm ci
5+
npm run build
46
composer install --no-dev
57

68
# If anything changes, re-generate the VERSION file
@@ -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');
@@ -125,19 +124,6 @@ mod.rules.push(
125124
},
126125
);
127126

128-
let mode = 'production';
129-
try {
130-
const configFile = fs.readFileSync('project/config.xml', 'latin1');
131-
const res = /<[\s]*?sandbox[\s]*?>(.*)<\/[\s]*?sandbox[\s]*?>/
132-
.exec(configFile);
133-
if (res && parseInt(res[1]) == 1) mode = 'development';
134-
} catch (error) {
135-
console.error(
136-
'Error - Can\'t read config.xml file. '
137-
+ 'Webpack mode set to production.'
138-
);
139-
}
140-
141127
/**
142128
* Creates a webpack config entry for a LORIS module named
143129
* mname.
@@ -172,24 +158,66 @@ function lorisModule(mname, entries) {
172158
'react-dom': 'ReactDOM',
173159
},
174160
devtool: 'source-map',
175-
plugins: [
176-
new webpack.DefinePlugin({
177-
'process.env.NODE_ENV': `"${mode}"`,
178-
}),
179-
...modulePlugins,
180-
],
161+
plugins: modulePlugins,
181162
optimization: optimization,
182163
resolve: resolve,
183164
module: mod,
184-
mode: 'none',
185165
stats: 'errors-only',
186166
};
187167
}
188168

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

0 commit comments

Comments
 (0)