-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
features.js
199 lines (188 loc) · 5.84 KB
/
features.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
const packageHelper = require('./package-helper');
/**
* An object that holds internal configuration about different
* "loaders"/"plugins" that can be enabled/used.
*
* @type {{[key: string]: {
* method: string,
* packages: Array<{ name: string, enforce_version?: boolean } | Array<{ name: string }>>,
* description: string,
* }}}
*/
const features = {
sass: {
method: 'enableSassLoader()',
packages: [
{ name: 'sass-loader', enforce_version: true },
[{ name: 'sass' }, { name: 'sass-embedded' }, { name: 'node-sass' }]
],
description: 'load Sass files'
},
less: {
method: 'enableLessLoader()',
packages: [
{ name: 'less-loader', enforce_version: true },
],
description: 'load LESS files'
},
stylus: {
method: 'enableStylusLoader()',
packages: [
{ name: 'stylus-loader', enforce_version: true },
],
description: 'load Stylus files'
},
postcss: {
method: 'enablePostCssLoader()',
packages: [
{ name: 'postcss-loader', enforce_version: true }
],
description: 'process through PostCSS'
},
react: {
method: 'enableReactPreset()',
packages: [
{ name: '@babel/preset-react', enforce_version: true }
],
description: 'process React JS files'
},
preact: {
method: 'enablePreactPreset()',
packages: [
{ name: '@babel/plugin-transform-react-jsx', enforce_version: true }
],
description: 'process Preact JS files'
},
typescript: {
method: 'enableTypeScriptLoader()',
packages: [
{ name: 'typescript' },
{ name: 'ts-loader', enforce_version: true },
],
description: 'process TypeScript files'
},
forkedtypecheck: {
method: 'enableForkedTypeScriptTypesChecking()',
packages: [
{ name: 'typescript' },
{ name: 'ts-loader', enforce_version: true },
{ name: 'fork-ts-checker-webpack-plugin', enforce_version: true },
],
description: 'check TypeScript types in a separate process'
},
'typescript-babel': {
method: 'enableBabelTypeScriptPreset',
packages: [
{ name: 'typescript' },
{ name: '@babel/preset-typescript', enforce_version: true },
],
description: 'process TypeScript files with Babel'
},
vue3: {
method: 'enableVueLoader()',
// vue is needed so the end-user can do things
// @vue/compiler-sfc is an optional peer dep of vue-loader
packages: [
{ name: 'vue', enforce_version: true },
{ name: 'vue-loader', enforce_version: true },
{ name: '@vue/compiler-sfc' }
],
description: 'load Vue files'
},
'vue-jsx': {
method: 'enableVueLoader()',
packages: [
{ name: '@vue/babel-preset-jsx' },
{ name: '@vue/babel-helper-vue-jsx-merge-props' }
],
description: 'use Vue with JSX support'
},
'vue3-jsx': {
method: 'enableVueLoader()',
packages: [
{ name: '@vue/babel-plugin-jsx' },
],
description: 'use Vue with JSX support'
},
copy_files: {
method: 'copyFiles()',
packages: [
{ name: 'file-loader', enforce_version: true },
],
description: 'Copy files'
},
notifier: {
method: 'enableBuildNotifications()',
packages: [
{ name: 'webpack-notifier', enforce_version: true },
],
description: 'display build notifications'
},
handlebars: {
method: 'enableHandlebarsLoader()',
packages: [
{ name: 'handlebars' },
{ name: 'handlebars-loader', enforce_version: true }
],
description: 'load Handlebars files'
},
stimulus: {
method: 'enableStimulusBridge()',
packages: [
{ name: '@symfony/stimulus-bridge', enforce_version: true }
],
description: 'enable Stimulus bridge'
},
svelte: {
method: 'enableSvelte()',
packages: [
{ name: 'svelte', enforce_version: true },
{ name: 'svelte-loader', enforce_version: true }
],
description: 'process Svelte JS files'
},
'webpack-dev-server': {
method: 'configureDevServerOptions()',
packages: [
{ name: 'webpack-dev-server' }
],
description: 'run the Webpack development server'
},
};
function getFeatureConfig(featureName) {
if (!features[featureName]) {
throw new Error(`Unknown feature ${featureName}`);
}
return features[featureName];
}
module.exports = {
ensurePackagesExistAndAreCorrectVersion: function(featureName, method = null) {
const config = getFeatureConfig(featureName);
packageHelper.ensurePackagesExist(
packageHelper.addPackagesVersionConstraint(config.packages),
method || config.method
);
},
getMissingPackageRecommendations: function(featureName) {
const config = getFeatureConfig(featureName);
return packageHelper.getMissingPackageRecommendations(
packageHelper.addPackagesVersionConstraint(config.packages),
config.method
);
},
getFeatureMethod: function(featureName) {
return getFeatureConfig(featureName).method;
},
getFeatureDescription: function(featureName) {
return getFeatureConfig(featureName).description;
},
};