@@ -9,6 +9,13 @@ const getLoadersFromRules = (rules, path, loaderName) =>
99 . reduce ( flatten , [ ] )
1010 . filter ( get ( "loader" ) )
1111 . filter ( ( { loader } ) => loader . includes ( loaderName ) ) ;
12+ const getRulesByTest = ( rules , path , testPart ) =>
13+ rules
14+ . filter ( get ( path ) )
15+ . map ( get ( path ) )
16+ . reduce ( flatten , [ ] )
17+ . filter ( get ( "test" ) )
18+ . filter ( ( { test } ) => test . toString ( ) . includes ( testPart ) ) ;
1219
1320const script = process . argv [ 2 ] || "start" ;
1421process . env . NODE_ENV = script === "build" ? "production" : "development" ;
@@ -21,23 +28,23 @@ const webpackConfig = require(webpackConfigPath)(process.env.NODE_ENV);
2128if ( ! webpackConfig ) {
2229 throw new Error ( `no Webpack config found for: ${ webpackConfigPath } ` ) ;
2330}
31+
32+ webpackConfig . plugins = ( webpackConfig . plugins || [ ] ) . filter (
33+ plugin => ! ( plugin ?. constructor ?. name || "" ) . toLowerCase ( ) . includes ( "react" )
34+ ) ;
2435const { module : { rules = [ ] } = { } } = webpackConfig ;
2536
2637// use for unminified prod builds
2738// webpackConfig.optimization.minimize = false;
2839
29- const eslintLoaders = getLoadersFromRules ( rules , "use" , "eslint" ) ;
30- if ( ! eslintLoaders . length ) {
31- throw new Error (
32- `missing ESLint config in webpack config: ${ webpackConfigPath } `
33- ) ;
40+ const svgRules = getRulesByTest ( rules , "oneOf" , ".svg" ) ;
41+ if ( ! svgRules . length ) {
42+ throw new Error ( `missing SVG rules in webpack config: ${ webpackConfigPath } ` ) ;
3443}
35- const eslintConfig = eslintLoaders [ 0 ] . options . baseConfig ;
36- eslintConfig . settings = { react : { version : "latest" } } ;
37- // override ESLint rules to allow using JSX with Hyperapp
38- eslintConfig . rules = Object . assign ( eslintConfig . rules || { } , {
39- "react/react-in-jsx-scope" : "off"
40- } ) ;
44+ // this rule brings in a copy of react
45+ svgRules [ 0 ] . use = svgRules [ 0 ] . use . filter (
46+ ruleUse => ! ruleUse . loader . includes ( "@svgr" )
47+ ) ;
4148
4249const babelLoaders = getLoadersFromRules ( rules , "oneOf" , "babel" ) ;
4350if ( ! babelLoaders . length ) {
@@ -46,8 +53,12 @@ if (!babelLoaders.length) {
4653 ) ;
4754}
4855const babelOptions = babelLoaders [ 0 ] . options ;
56+
57+ // disable babel caching for testing
58+ // babelOptions.cacheDirectory = false;
59+
4960// configure babel to allow using JSX with Hyperapp
50- babelOptions . plugins = ( babelOptions . plugins || [ ] ) . concat ( [
61+ babelOptions . plugins = [
5162 [
5263 "@babel/transform-react-jsx" ,
5364 {
@@ -56,20 +67,18 @@ babelOptions.plugins = (babelOptions.plugins || []).concat([
5667 }
5768 ] ,
5869 require . resolve ( "./injectHtmlImportPlugin" )
59- ] ) ;
70+ ] ;
6071
6172// override config in cache
6273require . cache [ require . resolve ( webpackConfigPath ) ] . exports = ( ) => webpackConfig ;
6374
6475const createJestConfig = require ( createJestConfigPath ) ;
6576require . cache [ require . resolve ( createJestConfigPath ) ] . exports = ( ...args ) => {
6677 const jestConfig = createJestConfig ( ...args ) ;
67- for ( let key in jestConfig . transform ) {
68- if ( jestConfig . transform [ key ] . includes ( "fileTransform" ) ) {
69- jestConfig . transform [ key ] = require . resolve ( "./dummyTransform" ) ;
70- }
71- }
72- jestConfig . transformIgnorePatterns = [ "node_modules/(?!hyperapp)/" ] ;
78+ jestConfig . transformIgnorePatterns = jestConfig . transformIgnorePatterns . map (
79+ pattern =>
80+ pattern . includes ( "node_modules" ) ? "/node_modules/(?!hyperapp)/" : pattern
81+ ) ;
7382 return jestConfig ;
7483} ;
7584
0 commit comments