@machtwatch/react-script 1.2.11-alpha.29 → 1.2.11-alpha.31

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.
@@ -4,7 +4,7 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const merge = require('deepmerge');
6
6
 
7
- module.exports = (resolve, rootDir, srcRoots) => {
7
+ module.exports = (resolve, rootDir, srcRoots, appConfig) => {
8
8
  const toRelRootDir = f => '<rootDir>/' + path.relative(rootDir || '', f);
9
9
  const extendedPath = path.join(process.cwd(), 'extended-jest.config.js');
10
10
 
@@ -26,6 +26,9 @@ module.exports = (resolve, rootDir, srcRoots) => {
26
26
  }
27
27
 
28
28
  const config = {
29
+ globals: {
30
+ CONFIG: appConfig && (appConfig.globals || appConfig),
31
+ },
29
32
  setupFiles: [resolve('scripts/utils/polyfills.js')],
30
33
  testMatch: [
31
34
  "<rootDir>/src/shared/**/*.(spec|test).{js,jsx,mjs}"
@@ -1,4 +1 @@
1
1
  import "@testing-library/jest-dom";
2
- import config from 'config';
3
-
4
- global.CONFIG = config.globals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machtwatch/react-script",
3
- "version": "1.2.11-alpha.29",
3
+ "version": "1.2.11-alpha.31",
4
4
  "description": "Machtwatch React script",
5
5
  "author": "Danny Reza Miloen <danny@machtwatch.co.id>",
6
6
  "contributors": [],
@@ -80,8 +80,6 @@
80
80
  "imagemin-webp-webpack-plugin": "^3.3.6",
81
81
  "intersection-observer": "^0.5.1",
82
82
  "jest": "^26.4.2",
83
- "less": "^4.2.1",
84
- "less-loader": "^12.2.0",
85
83
  "mini-css-extract-plugin": "^2.6.1",
86
84
  "mkdirp": "^0.5.1",
87
85
  "null-loader": "^4.0.1",
@@ -107,7 +105,7 @@
107
105
  "speed-measure-webpack-plugin": "^1.5.0",
108
106
  "style-loader": "^4.0.0",
109
107
  "stylelint": "^16.10.0",
110
- "stylelint-config-recommended-less": "^3.0.1",
108
+ "stylelint-config-recommended": "^14.0.1",
111
109
  "stylelint-webpack-plugin": "^5.0.1",
112
110
  "tailwindcss": "^3.4.17",
113
111
  "terser": "^5.14.1",
package/scripts/test.js CHANGED
@@ -9,32 +9,43 @@ process.on('unhandledRejection', err => {
9
9
 
10
10
  const jest = require('jest');
11
11
  const path = require('path');
12
+ const { createRequire } = require('module');
12
13
 
13
14
  const createJestConfig = require('../config/jest/createJestConfig');
14
15
  const paths = require('../config/paths');
15
16
 
17
+ const requireApp = createRequire(`${paths.appPath}/package.json`);
18
+ const { loadConfig } = requireApp('c12');
19
+
16
20
  require('../config/env');
17
21
 
18
- let argv = process.argv.slice(2);
22
+ async function start() {
23
+ const { config } = await loadConfig({ cwd: paths.appPath });
19
24
 
20
- if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
21
- argv.push('--watchAll');
22
- }
25
+ let argv = process.argv.slice(2);
26
+
27
+ if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
28
+ argv.push('--watchAll');
29
+ }
23
30
 
24
- const jestConfig = createJestConfig(
25
- relativePath => path.resolve(__dirname, '..', relativePath),
26
- path.resolve(paths.appSrc, '..'),
27
- paths.srcPaths
28
- );
31
+ const jestConfig = createJestConfig(
32
+ relativePath => path.resolve(__dirname, '..', relativePath),
33
+ path.resolve(paths.appSrc, '..'),
34
+ paths.srcPaths,
35
+ config
36
+ );
29
37
 
30
- argv.push(
31
- '--config',
32
- JSON.stringify(
33
- jestConfig
34
- )
35
- );
38
+ argv.push(
39
+ '--config',
40
+ JSON.stringify(
41
+ jestConfig
42
+ )
43
+ );
36
44
 
37
- const testEnvironment = 'jsdom';
38
- argv.push('--coverage', '--env', testEnvironment);
45
+ const testEnvironment = 'jsdom';
46
+ argv.push('--coverage', '--env', testEnvironment);
47
+
48
+ jest.run(argv);
49
+ }
39
50
 
40
- jest.run(argv);
51
+ start();
@@ -285,64 +285,52 @@ const webpackConfig = ({ isClient }) => ({
285
285
  stats: 'minimal'
286
286
  });
287
287
 
288
- const styleLoaders = ({ isClient }) => [
289
- {
290
- loader: 'css-loader',
291
- options: {
292
- modules: {
293
- exportOnlyLocals: !isClient,
294
- localIdentName: '[local]',
288
+ const styleLoaders = ({ isClient }) => [
289
+ {
290
+ loader: 'css-loader',
291
+ options: {
292
+ modules: {
293
+ exportOnlyLocals: !isClient,
294
+ localIdentName: '[local]',
295
+ },
296
+ importLoaders: 2,
295
297
  },
296
- importLoaders: 2,
297
298
  },
298
- },
299
- {
300
- loader: require.resolve('postcss-loader'),
301
- options: {
302
- postcssOptions: {
303
- ident: 'postcss',
304
- config: false,
305
- plugins: [
306
- [
307
- 'postcss-import',
308
- {
309
- addModulesDirectories: [
310
- path.resolve(__dirname, '../node_modules'),
311
- `${paths.appPath}/node_modules`
312
- ],
313
- root: `${paths.appSrc}/styles/`
314
- }
315
- ],
316
- [
317
- 'postcss-preset-env',
318
- {
319
- autoprefixer: {
320
- flexbox: 'no-2009',
321
- },
322
- stage: 3,
323
- browsers: pkg.browserslist
324
- }
299
+ {
300
+ loader: require.resolve('postcss-loader'),
301
+ options: {
302
+ postcssOptions: {
303
+ ident: 'postcss',
304
+ config: false,
305
+ plugins: [
306
+ [
307
+ 'postcss-import',
308
+ {
309
+ addModulesDirectories: [
310
+ path.resolve(__dirname, '../node_modules'),
311
+ `${paths.appPath}/node_modules`
312
+ ],
313
+ root: `${paths.appSrc}/styles/`
314
+ }
315
+ ],
316
+ [
317
+ 'postcss-preset-env',
318
+ {
319
+ autoprefixer: {
320
+ flexbox: 'no-2009',
321
+ },
322
+ stage: 3,
323
+ browsers: pkg.browserslist
324
+ }
325
+ ],
326
+ 'tailwindcss',
327
+ 'postcss-modules-values',
328
+ 'postcss-flexbugs-fixes'
325
329
  ],
326
- 'tailwindcss',
327
- 'postcss-modules-values',
328
- 'postcss-flexbugs-fixes'
329
- ],
330
+ },
330
331
  },
331
332
  },
332
- },
333
- {
334
- loader: 'less-loader',
335
- options: {
336
- lessOptions: {
337
- javascriptEnabled: true,
338
- paths: [
339
- `${paths.appSrc}/styles`,
340
- `${paths.appPath}/node_modules/@machtwatch/react-ui`,
341
- ],
342
- }
343
- },
344
- },
345
- ];
333
+ ];
346
334
 
347
335
  //
348
336
  // Configuration for the client-side bundle (client.js)
@@ -537,55 +525,37 @@ const clientConfig = {
537
525
  },
538
526
  ],
539
527
  },
540
- {
541
- test: /\.less$/,
542
- use: [
543
- MiniCssExtractPlugin.loader,
544
- ...styleLoaders({ isClient: true }).filter(
545
- (loader) => loader.loader !== 'less-loader'
546
- ),
547
- {
548
- loader: 'less-loader',
549
- options: {
550
- lessOptions: {
551
- javascriptEnabled: true,
552
- paths: [`${paths.appSrc}/styles`],
553
- },
554
- },
555
- },
556
- ],
557
- }
558
- ]
559
- },
560
- plugins: [
561
- ...baseClientConfig.plugins,
562
- new StyleLintPlugin({
563
- configFile: `${paths.appPath}/.stylelintrc.json`,
564
- extensions: ['less'],
565
- exclude: ['node_modules', 'coverage'],
566
- }),
567
- isRuntimeDev && new ReactRefreshWebpackPlugin({
568
- overlay: false,
569
- }),
570
- new webpack.HotModuleReplacementPlugin(),
571
- new SubresourceIntegrityPlugin(),
572
- new LoadablePlugin({
573
- writeToDisk: {
574
- filename: paths.appBuild
575
- },
576
- outputAsset: false
577
- }),
578
- // Define free variables
579
- // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
580
- new webpack.DefinePlugin({
581
- 'process.env.DEV_SERVER': isRuntimeDev,
582
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
583
- 'process.env.BROWSER': true,
584
- __DEVTOOLS__: isVerbose // <-------- DISABLE redux-devtools HERE
585
- }),
586
- new webpack.ProvidePlugin({
587
- process: 'process/browser.js',
588
- }),
528
+ ]
529
+ },
530
+ plugins: [
531
+ ...baseClientConfig.plugins,
532
+ new StyleLintPlugin({
533
+ configFile: `${paths.appPath}/.stylelintrc.json`,
534
+ extensions: ['css'],
535
+ exclude: ['node_modules', 'coverage'],
536
+ }),
537
+ isRuntimeDev && new ReactRefreshWebpackPlugin({
538
+ overlay: false,
539
+ }),
540
+ new webpack.HotModuleReplacementPlugin(),
541
+ new SubresourceIntegrityPlugin(),
542
+ new LoadablePlugin({
543
+ writeToDisk: {
544
+ filename: paths.appBuild
545
+ },
546
+ outputAsset: false
547
+ }),
548
+ // Define free variables
549
+ // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
550
+ new webpack.DefinePlugin({
551
+ 'process.env.DEV_SERVER': isRuntimeDev,
552
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
553
+ 'process.env.BROWSER': true,
554
+ __DEVTOOLS__: isVerbose // <-------- DISABLE redux-devtools HERE
555
+ }),
556
+ new webpack.ProvidePlugin({
557
+ process: 'process/browser.js',
558
+ }),
589
559
 
590
560
  new MiniCssExtractPlugin({
591
561
  // Options similar to the same options in webpackOptions.output
@@ -692,82 +662,76 @@ const clientConfig = {
692
662
  devtool: isDevEnv && useSourceMap ? 'eval' : false,
693
663
  };
694
664
 
695
- //
696
- // Configuration for the server-side bundle (server.js)
697
- // -----------------------------------------------------------------------------
698
- const baseServerConfig = webpackConfig({ isClient: false });
699
- const serverConfig = {
700
- ...baseServerConfig,
701
- name: 'server',
702
- target: 'node',
703
- devtool: isDevEnv && useSourceMap ? 'eval' : false,
704
- performance: false,
705
- optimization: {
706
- nodeEnv: false,
707
- splitChunks: {
708
- name: false,
709
- cacheGroups: {
710
- vendor: {
711
- test: /[\\/]node_modules[\\/]/,
712
- chunks: 'all',
713
- enforce: true
665
+ //
666
+ // Configuration for the server-side bundle (server.js)
667
+ // -----------------------------------------------------------------------------
668
+ const baseServerConfig = webpackConfig({ isClient: false });
669
+ const serverConfig = {
670
+ ...baseServerConfig,
671
+ name: 'server',
672
+ target: 'node',
673
+ devtool: isDevEnv && useSourceMap ? 'eval' : false,
674
+ performance: false,
675
+ optimization: {
676
+ nodeEnv: false,
677
+ splitChunks: {
678
+ name: false,
679
+ cacheGroups: {
680
+ vendor: {
681
+ test: /[\\/]node_modules[\\/]/,
682
+ chunks: 'all',
683
+ enforce: true
684
+ }
714
685
  }
715
- }
716
- },
717
- minimize: isProdEnv,
718
- minimizer: [
719
- new TerserPlugin(),
720
- new CssMinimizerPlugin()
721
- ]
722
- },
723
- entry: {
724
- server: [
725
- path.resolve(__dirname, './utils/polyfills.js'),
726
- `${paths.appSrc}/server.js`
727
- ]
728
- },
729
- output: {
730
- ...baseServerConfig.output,
731
- path: paths.appBuild,
732
- filename: '[name].js',
733
- libraryTarget: 'commonjs2',
734
- },
735
- module: {
736
- ...baseServerConfig.module,
737
- rules: [
738
- ...baseServerConfig.module.rules,
739
- {
740
- test: /\.css$/,
741
- use: styleLoaders({ isClient: false }).filter(
742
- (loader) => loader.loader !== 'less-loader'
743
- ),
744
- },
745
- {
746
- test: /\.less$/,
747
- use: styleLoaders({ isClient: false }),
748
686
  },
687
+ minimize: isProdEnv,
688
+ minimizer: [
689
+ new TerserPlugin(),
690
+ new CssMinimizerPlugin()
691
+ ]
692
+ },
693
+ entry: {
694
+ server: [
695
+ path.resolve(__dirname, './utils/polyfills.js'),
696
+ `${paths.appSrc}/server.js`
697
+ ]
698
+ },
699
+ output: {
700
+ ...baseServerConfig.output,
701
+ path: paths.appBuild,
702
+ filename: '[name].js',
703
+ libraryTarget: 'commonjs2',
704
+ },
705
+ module: {
706
+ ...baseServerConfig.module,
707
+ rules: [
708
+ ...baseServerConfig.module.rules,
709
+ {
710
+ test: /\.css$/,
711
+ use: styleLoaders({ isClient: false }),
712
+ },
713
+ ],
714
+ },
715
+ externalsPresets: { node: true },
716
+ externals: [
717
+ nodeExternals({
718
+ allowlist: [/^driver\.js/],
719
+ }),
720
+ /^\.\/assets\.json$/,
749
721
  ],
750
- },
751
- externalsPresets: { node: true },
752
- externals: [
753
- nodeExternals({
754
- allowlist: [/^driver\.js/],
755
- }),
756
- /^\.\/assets\.json$/,
757
- ],
758
- plugins: [
759
- ...baseServerConfig.plugins,
760
- // Define free variables
761
- // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
762
- new webpack.DefinePlugin({
763
- 'process.env.DEV_SERVER': isRuntimeDev,
764
- 'process.env.BROWSER': false,
765
- __DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
766
- }),
767
- // Do not create separate chunks of the server bundle
768
- // https://webpack.github.io/docs/list-of-plugins.html#limitchunkcountplugin
769
- new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
770
- ].filter(Boolean),
722
+ plugins: [
723
+ ...baseServerConfig.plugins,
724
+ // Define free variables
725
+ // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
726
+ new webpack.DefinePlugin({
727
+ 'process.env.DEV_SERVER': isRuntimeDev,
728
+ 'process.env.BROWSER': false,
729
+ __DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
730
+ }),
731
+ // Do not create separate chunks of the server bundle
732
+ // https://webpack.github.io/docs/list-of-plugins.html#limitchunkcountplugin
733
+ new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
734
+ ].filter(Boolean),
771
735
 
772
736
  node: {
773
737
  global: false,