@lipemat/js-boilerplate 10.2.0 → 10.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/webpack.dev.js +5 -5
- package/helpers/config.js +40 -10
- package/package.json +1 -1
package/config/webpack.dev.js
CHANGED
|
@@ -4,7 +4,7 @@ const path = require( 'path' );
|
|
|
4
4
|
const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' );
|
|
5
5
|
const config = require( '../helpers/package-config' );
|
|
6
6
|
const {getEntries} = require( '../helpers/entries' );
|
|
7
|
-
const {getConfig,
|
|
7
|
+
const {getConfig, getTsConfigFile} = require( '../helpers/config' );
|
|
8
8
|
|
|
9
9
|
const postcssOptions = getConfig( 'postcss.config.js' );
|
|
10
10
|
const babelOptions = getConfig( 'babel.config.js' );
|
|
@@ -24,14 +24,14 @@ const plugins = [
|
|
|
24
24
|
new ReactRefreshWebpackPlugin(),
|
|
25
25
|
];
|
|
26
26
|
|
|
27
|
-
// Loads a thread, which verifies any TypeScripts on changes
|
|
28
|
-
//
|
|
29
|
-
if (
|
|
27
|
+
// Loads a thread, which verifies any TypeScripts on changes if the
|
|
28
|
+
// project has a "tsconfig.json" file.
|
|
29
|
+
if ( '' !== getTsConfigFile() ) {
|
|
30
30
|
plugins.push( new ForkTsCheckerWebpackPlugin( {
|
|
31
31
|
devServer: false,
|
|
32
32
|
formatter: 'basic',
|
|
33
33
|
typescript: {
|
|
34
|
-
configFile:
|
|
34
|
+
configFile: getTsConfigFile(),
|
|
35
35
|
},
|
|
36
36
|
} ) );
|
|
37
37
|
}
|
package/helpers/config.js
CHANGED
|
@@ -2,6 +2,8 @@ const packageConfig = require( './package-config' );
|
|
|
2
2
|
const path = require( 'path' );
|
|
3
3
|
const once = require( 'lodash/once' );
|
|
4
4
|
const browserslist = require( 'browserslist' );
|
|
5
|
+
const fs = require( 'fs' );
|
|
6
|
+
const config = require( './package-config' );
|
|
5
7
|
|
|
6
8
|
const extensions = [
|
|
7
9
|
...Object.keys( packageConfig.dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
@@ -16,7 +18,7 @@ const extensions = [
|
|
|
16
18
|
*
|
|
17
19
|
* @return {boolean}
|
|
18
20
|
*/
|
|
19
|
-
function hasLocalOverride( fileName, inWorkingDirectory = false ) {
|
|
21
|
+
function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
20
22
|
let hasLocal = false;
|
|
21
23
|
try {
|
|
22
24
|
if ( inWorkingDirectory ) {
|
|
@@ -61,18 +63,18 @@ function hasLocalOverride( fileName, inWorkingDirectory = false ) {
|
|
|
61
63
|
* @return {Object}
|
|
62
64
|
*/
|
|
63
65
|
function getConfig( fileName ) {
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
+
let mergedConfig = require( '../config/' + fileName );
|
|
67
|
+
mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
|
|
66
68
|
try {
|
|
67
69
|
const localConfig = require( path.resolve( packageConfig.packageDirectory + '/config', fileName ) );
|
|
68
70
|
if ( 'function' === typeof localConfig ) {
|
|
69
|
-
|
|
71
|
+
mergedConfig = {...mergedConfig, ...localConfig( mergedConfig )};
|
|
70
72
|
} else {
|
|
71
|
-
|
|
73
|
+
mergedConfig = {...mergedConfig, ...localConfig};
|
|
72
74
|
}
|
|
73
75
|
} catch ( e ) {
|
|
74
76
|
}
|
|
75
|
-
return
|
|
77
|
+
return mergedConfig;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -88,22 +90,49 @@ function getConfig( fileName ) {
|
|
|
88
90
|
* @return {Object}
|
|
89
91
|
*/
|
|
90
92
|
function getExtensionsConfig( fileName, defaultConfig ) {
|
|
91
|
-
let
|
|
93
|
+
let mergedConfig = {};
|
|
92
94
|
extensions.forEach( extension => {
|
|
93
95
|
try {
|
|
94
96
|
const extensionConfig = require( extension + '/config/' + fileName );
|
|
95
97
|
if ( 'function' === typeof extensionConfig ) {
|
|
96
|
-
|
|
98
|
+
mergedConfig = {...mergedConfig, ...extensionConfig( {...defaultConfig, ...mergedConfig} )};
|
|
97
99
|
} else {
|
|
98
|
-
|
|
100
|
+
mergedConfig = {...mergedConfig, ...extensionConfig};
|
|
99
101
|
}
|
|
100
102
|
} catch ( e ) {
|
|
101
103
|
}
|
|
102
104
|
} );
|
|
103
105
|
|
|
104
|
-
return
|
|
106
|
+
return mergedConfig;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Get the path to the "tsconfig.json" file if it exists.
|
|
111
|
+
*
|
|
112
|
+
* 1. The working directory.
|
|
113
|
+
* 2. The package directory.
|
|
114
|
+
*
|
|
115
|
+
* The package directory takes priority over the working directory.
|
|
116
|
+
*
|
|
117
|
+
*
|
|
118
|
+
* @return {string}
|
|
119
|
+
*/
|
|
120
|
+
function getTsConfigFile() {
|
|
121
|
+
const possibles = [
|
|
122
|
+
// Backward compatible for before @lipemat/eslint-config version 3.
|
|
123
|
+
path.resolve( config.workingDirectory + '/tsconfig.json' ),
|
|
124
|
+
path.resolve( config.packageDirectory + '/tsconfig.json' ),
|
|
125
|
+
];
|
|
126
|
+
let tsConfig = '';
|
|
127
|
+
possibles.forEach( filePath => {
|
|
128
|
+
if ( fs.existsSync( filePath ) ) {
|
|
129
|
+
tsConfig = filePath;
|
|
130
|
+
}
|
|
131
|
+
} );
|
|
132
|
+
return tsConfig;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
107
136
|
/**
|
|
108
137
|
* If browserslist is not specified, we fall back to WordPress defaults
|
|
109
138
|
* except for > 1% we don't support by default.
|
|
@@ -134,5 +163,6 @@ module.exports = {
|
|
|
134
163
|
getConfig,
|
|
135
164
|
getDefaultBrowsersList,
|
|
136
165
|
getExtensionsConfig,
|
|
166
|
+
getTsConfigFile,
|
|
137
167
|
hasLocalOverride,
|
|
138
168
|
};
|