-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathtest-supported-webpack-versions.js
executable file
·135 lines (115 loc) · 3.76 KB
/
test-supported-webpack-versions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env node
/* eslint-disable arrow-body-style,no-param-reassign,promise/always-return */
'use strict';
const execa = require('execa');
const Listr = require('listr');
const del = require('del');
const readPkgUp = require('read-pkg-up');
const getWebpackVersion = require('./get-webpack-version');
const ciEnabled = process.argv[process.argv.length - 1] === '--ci';
const supported = [
//
'3',
'4',
'next',
];
const webpackTestTasks = supported.map((version) => {
const skip = () => {
/**
* Webpack version 5 (currently @next) removed support for node 6.
*/
// if (
// (version === 'next' || version === '5') &&
// semver.lte(process.version, '8.0.0') === true
// ) {
// return `node ${
// process.version
// } is not supported by webpack@${version}...node >=8 required`;
// }
return false;
};
const npmCommandArgs = ['install', '--no-save', `webpack@${version}`];
const npmInstallTaskTitle = `npm ${npmCommandArgs.join(' ')}`;
const npmInstallTask = {
title: npmInstallTaskTitle,
task: (ctx, task) =>
execa('npm', npmCommandArgs).then(() => {
task.title = `${npmInstallTaskTitle} (${getWebpackVersion()})`;
}),
};
const jestCommandArgs =
ciEnabled === true
? ['--ci', '--no-cache', '--coverage', '--max-workers', '2']
: [];
const runJestTask = {
title: `jest ${jestCommandArgs.join(' ')}`,
task: () => {
if (ciEnabled === true) {
del.sync('coverage/**/*', { dot: true });
}
return execa('jest', jestCommandArgs, {
env: { FORCE_COLOR: true },
});
},
};
const testWebpackVersionTask = [npmInstallTask, runJestTask];
if (ciEnabled === true) {
const codecovTask = {
title: 'codecov',
task: () =>
execa('codecov', [], {
env: { FORCE_COLOR: true },
}).then(({ stdout }) => {
// eslint-disable-next-line no-console
console.log(stdout);
}),
};
testWebpackVersionTask.push(codecovTask);
}
return {
title: `webpack@${version}`,
task: () => new Listr(testWebpackVersionTask),
skip,
};
});
const listrOptions =
ciEnabled === false
? { collapse: false, clearOutput: false }
: { renderer: 'verbose' };
const tasks = new Listr(webpackTestTasks, listrOptions);
tasks
.run()
.then(() => {
/**
* Install original webpack devDependency listed in package.json
*/
const packageJsonWebpackVersion = readPkgUp.sync({
cwd: process.cwd(),
normalize: false,
}).package.devDependencies.webpack;
return new Listr(
[
{
title: `npm install --no-save webpack@${packageJsonWebpackVersion}`,
task: () =>
execa(
'npm',
[
'install',
'--no-save',
`webpack@${packageJsonWebpackVersion}`,
],
{ env: { FORCE_COLOR: true } },
),
skip: () => ciEnabled === true,
},
],
listrOptions,
).run();
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error.message);
// eslint-disable-next-line no-process-exit
process.exit(error.code);
});