@lipemat/js-boilerplate 10.6.0 → 10.7.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/README.md CHANGED
@@ -22,6 +22,7 @@ Add the following to your package.json. (this may also be found in the `template
22
22
  {
23
23
  "jsPath": "./js",
24
24
  "scripts": {
25
+ "analyze": "lipemat-js-boilerplate analyze",
25
26
  "browserslist": "lipemat-js-boilerplate browserslist",
26
27
  "dist": "lipemat-js-boilerplate dist",
27
28
  "lint": "lipemat-js-boilerplate lint",
@@ -17,12 +17,14 @@ const nodeArgs = scriptIndex > 0 ? args.slice( 0, scriptIndex ) : [];
17
17
 
18
18
 
19
19
  const TS_CONVERTED_SCRIPTS = [
20
+ 'analyze',
20
21
  'test',
21
22
  'lint',
22
23
  'validate-css-modules',
23
24
  ];
24
25
 
25
26
  switch ( script ) {
27
+ case 'analyze':
26
28
  case 'browserslist':
27
29
  case 'dist':
28
30
  case 'fix-pnp':
@@ -1,5 +1,10 @@
1
1
  const {getBrowsersList} = require( '../helpers/config' );
2
2
 
3
+ /**
4
+ * @notice This file must NOT be a TS file because it is used
5
+ * as part of the JEST configuration.
6
+ */
7
+
3
8
  /**
4
9
  * Use Babel's preset-env to add support for target browsers.
5
10
  *
@@ -12,6 +17,7 @@ const presetEnv = {
12
17
  corejs: {
13
18
  // Use the core-js version currently installed in the project.
14
19
  version: require( 'core-js/package.json' ).version,
20
+ proposals: false,
15
21
  },
16
22
  // Enable the `debug` option to debug the included polyfills and plugins.
17
23
  debug: false,
@@ -6,10 +6,10 @@ const {getPackageConfig} = require( '../helpers/package-config' );
6
6
  const {getEntries} = require( '../helpers/entries' );
7
7
  const {getConfig, getTsConfigFile, getBrowsersList} = require( '../helpers/config' );
8
8
 
9
- const postcssOptions = getConfig( 'postcss.config.js' );
10
- const babelOptions = getConfig( 'babel.config.js' );
11
- const cssLoaderOptions = getConfig( 'css-loader.config.js' );
12
- const devServerOptions = getConfig( 'dev-server.config.js' );
9
+ const postcssOptions = getConfig( 'postcss.config' );
10
+ const babelOptions = getConfig( 'babel.config' );
11
+ const cssLoaderOptions = getConfig( 'css-loader.config' );
12
+ const devServerOptions = getConfig( 'dev-server.config' );
13
13
 
14
14
  // To allow line numbers to show up in console errors. @see React Error Boundaries.
15
15
  babelOptions.plugins.unshift( '@babel/plugin-transform-react-jsx-source' );
@@ -14,9 +14,9 @@ const config = require( '../helpers/package-config' );
14
14
  const {getEntries} = require( '../helpers/entries' );
15
15
  const {getPackageConfig} = require( '../helpers/package-config' );
16
16
 
17
- const postcssOptions = getConfig( 'postcss.config.js' );
18
- const babelOptions = getConfig( 'babel.config.js' );
19
- const cssLoaderOptions = getConfig( 'css-loader.config.js' );
17
+ const postcssOptions = getConfig( 'postcss.config' );
18
+ const babelOptions = getConfig( 'babel.config' );
19
+ const cssLoaderOptions = getConfig( 'css-loader.config' );
20
20
 
21
21
  const ManifestPlugin = new WebpackAssetsManifest( {
22
22
  integrity: true,
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @todo convert the source to TS.
3
+ */
4
+
5
+ export function getBrowsersList(): readonly string[];
6
+
7
+ export function getConfig<T extends object>( fileName: string ): T;
@@ -3,7 +3,7 @@ const fs = require( 'fs' );
3
3
  const path = require( 'path' );
4
4
  const {getConfig} = require( './config' );
5
5
 
6
- const entries = getConfig( 'entries.config.js' );
6
+ const entries = getConfig( 'entries.config' );
7
7
 
8
8
 
9
9
  /**
@@ -10,8 +10,8 @@
10
10
 
11
11
 
12
12
  import {Container, Root} from 'postcss';
13
- import {ChildNode} from 'postcss/lib/node';
14
- import {AtRuleRaws} from 'postcss/lib/at-rule';
13
+ import type {ChildNode} from 'postcss/lib/node';
14
+ import type {AtRuleRaws} from 'postcss/lib/at-rule';
15
15
 
16
16
  /**
17
17
  * Get the depth of the current node.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate",
3
- "version": "10.6.0",
3
+ "version": "10.7.1",
4
4
  "description": "Dependencies and scripts for a no config JavaScript app",
5
5
  "author": "Mat Lipe",
6
6
  "license": "MIT",
@@ -48,13 +48,16 @@
48
48
  "@lipemat/css-mqpacker": "^9.0.0",
49
49
  "@lipemat/eslint-config": "^3.1.3",
50
50
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
51
+ "@statoscope/webpack-plugin": "^5.28.2",
51
52
  "@teamsupercell/typings-for-css-modules-loader": "^2.5.2",
53
+ "@types/babel__preset-env": "^7.9.6",
52
54
  "@types/node": "^16",
53
55
  "@wordpress/browserslist-config": "^5.19.0",
54
56
  "are-you-es5": "^2.1.1",
55
57
  "babel-jest": "^29.0.0",
56
58
  "babel-loader": "9.1.2",
57
59
  "browserslist": "^4.21.9",
60
+ "chalk": "^4.0",
58
61
  "clean-css": "^5.3.0",
59
62
  "clean-webpack-plugin": "^4.0.0",
60
63
  "compression-webpack-plugin": "^10.0.0",
@@ -0,0 +1,53 @@
1
+ import {getConfig} from '../helpers/config';
2
+ import webpack from 'webpack';
3
+ import StatoscopeWebpackPlugin from '@statoscope/webpack-plugin';
4
+ import fs from 'fs';
5
+ import minimist from 'minimist';
6
+
7
+ const help = `
8
+ Uses Statoscope to visualize the size of the project's output files.
9
+
10
+ Usage: lipemat-js-boilerplate analyze [--stats-only|--help]
11
+
12
+ --help, -h Show help menu.
13
+ --stats-only Generate stats.json file for use with https://statoscope.tech for comparing diffs between builds.
14
+
15
+ `;
16
+
17
+
18
+ // Command line arguments.
19
+ const flags = minimist( process.argv.slice( 2 ) );
20
+ const workingDirectory = fs.realpathSync( process.cwd() );
21
+ const statsDir = workingDirectory + '/node_modules/.cache/statoscope';
22
+ const webpackConfig = getConfig<webpack.Configuration>( 'webpack.dist' );
23
+
24
+ if ( true === flags.h || true === flags.help ) {
25
+ console.log( help );
26
+ process.exit( 0 );
27
+ }
28
+
29
+
30
+ function analyze() {
31
+ webpackConfig.plugins?.push( new StatoscopeWebpackPlugin( {
32
+ saveOnlyStats: true === ( flags[ 'stats-only' ] ?? false ),
33
+ saveStatsTo: statsDir + '/stats-[hash].json',
34
+ saveReportTo: statsDir + '/stats-[hash].html',
35
+ } ) );
36
+
37
+ // Use the default webpack stats configuration.
38
+ delete webpackConfig.stats;
39
+
40
+ webpack( webpackConfig ).run( ( err, stats ) => {
41
+ if ( err ) {
42
+ throw err;
43
+ }
44
+ if ( 'undefined' === typeof stats ) {
45
+ return;
46
+ }
47
+ if ( stats.hasErrors() ) {
48
+ process.exit( 1 );
49
+ }
50
+ } );
51
+ }
52
+
53
+ analyze();
package/scripts/dist.js CHANGED
@@ -2,7 +2,7 @@ process.env.BABEL_ENV = 'production';
2
2
  process.env.NODE_ENV = 'production';
3
3
 
4
4
  const webpack = require( 'webpack' );
5
- const webpackConfig = require( '../helpers/config' ).getConfig( 'webpack.dist.js' );
5
+ const webpackConfig = require( '../helpers/config' ).getConfig( 'webpack.dist' );
6
6
 
7
7
  async function build( config ) {
8
8
  // Compiler Instance.
package/scripts/lint.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {ESLint} from 'eslint';
2
2
  import minimist from 'minimist';
3
+ import chalk from 'chalk';
3
4
 
4
5
  import packageConfig from '../helpers/package-config';
5
6
 
@@ -30,6 +31,8 @@ function errorOccurred( results: ESLint.LintResult[] ): boolean {
30
31
  cacheStrategy: 'content',
31
32
  } );
32
33
 
34
+ console.log( chalk.underline( 'Running "js-boilerplate:lint" (eslint) task' ) );
35
+
33
36
  // 2. Lint files. This doesn't modify target files.
34
37
  const results: ESLint.LintResult[] = await eslint.lintFiles( [
35
38
  packageConfig.workingDirectory + '/src/**/*.{js,jsx,ts,tsx}',
@@ -43,13 +46,15 @@ function errorOccurred( results: ESLint.LintResult[] ): boolean {
43
46
  const resultText = formatter.format( results );
44
47
 
45
48
  // 5. Output it.
46
- console.log( resultText );
47
49
  if ( '' === resultText ) {
48
- console.log( '>> Linted JS files without errors.' );
49
- console.log( '-----------------------------------' );
50
- } else if ( errorOccurred( results ) ) {
51
- process.exitCode = 1;
50
+ console.log( `>> Linted ${results.length} files without errors` );
51
+ } else {
52
+ console.log( resultText );
53
+ if ( errorOccurred( results ) ) {
54
+ process.exitCode = 1;
55
+ }
52
56
  }
57
+ console.log( '' );
53
58
  }() ).catch( error => {
54
59
  process.exitCode = 1;
55
60
  console.error( error );
package/scripts/start.js CHANGED
@@ -7,8 +7,8 @@ const {unlinkSync, writeFile} = require( 'fs' );
7
7
  const WebpackDevServer = require( 'webpack-dev-server' );
8
8
  const configHelper = require( '../helpers/config' );
9
9
  const path = require( 'path' );
10
- const webpackConfig = configHelper.getConfig( 'webpack.dev.js' );
11
- const devServerConfig = configHelper.getConfig( 'dev-server.config.js' );
10
+ const webpackConfig = configHelper.getConfig( 'webpack.dev' );
11
+ const devServerConfig = configHelper.getConfig( 'dev-server.config' );
12
12
 
13
13
  const server = new WebpackDevServer( devServerConfig, webpack( webpackConfig ) );
14
14
 
@@ -14,7 +14,7 @@ Validate CSS modules using .d.ts definition files for each CSS module.
14
14
 
15
15
  Usage: lipemat-js-boilerplate validate-css-modules
16
16
 
17
- --help, -h Show help menu.`;
17
+ --help, -h Show help menu.`;
18
18
 
19
19
  const args = process.argv.slice( 3 );
20
20
  if ( '-h' === args[ 0 ] || '--help' === args[ 0 ] ) {
@@ -23,7 +23,7 @@ if ( '-h' === args[ 0 ] || '--help' === args[ 0 ] ) {
23
23
  }
24
24
 
25
25
  async function validate() {
26
- let webpackConfig: webpack.Configuration = getConfig( 'webpack.dist.js' );
26
+ let webpackConfig = getConfig<webpack.Configuration>( 'webpack.dist' );
27
27
  webpackConfig.stats = 'errors-warnings';
28
28
 
29
29
  // Add CSS module typings generation to webpack config.