@lipemat/js-boilerplate 10.3.1 → 10.4.0-beta.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.
@@ -22,13 +22,24 @@ switch ( script ) {
22
22
  case 'lint':
23
23
  case 'start':
24
24
  case 'test': {
25
+ // If the ts-node command is not available install it globally.
26
+ if ( spawn.sync( 'ts-node', [ '-v' ] ).error ) {
27
+ console.log( 'Installing ts-node globally.' );
28
+ spawn.sync( 'npm', [ 'install', '-g', 'ts-node' ] );
29
+ }
30
+
31
+ // Run the script.
25
32
  const result = spawn.sync(
26
- 'node',
33
+ 'ts-node',
27
34
  nodeArgs
28
35
  .concat( require.resolve( '../scripts/' + script ) )
29
36
  .concat( args.slice( scriptIndex + 1 ) ),
30
- {stdio: 'inherit'},
37
+ {stdio: 'inherit'}
31
38
  );
39
+ if ( result.error ) {
40
+ console.log( result.error );
41
+ process.exit( 1 );
42
+ }
32
43
  if ( result.signal ) {
33
44
  if ( 'SIGKILL' === result.signal ) {
34
45
  console.log(
@@ -4,29 +4,37 @@ const postcssPresetEnv = require( 'postcss-preset-env' );
4
4
  const {getBrowsersList} = require( '../helpers/config' );
5
5
  const packageConfig = require( '../helpers/package-config' );
6
6
 
7
+ /**
8
+ * Base postcss-presets-env config.
9
+ *
10
+ */
7
11
  const presetEnv = {
8
12
  browsers: getBrowsersList(),
9
- features: {
13
+ features: {},
14
+ };
15
+
16
+ // Get a list of included postcss plugins based no the browsers list.
17
+ const includedPlugins = postcssPresetEnv( presetEnv )
18
+ .plugins
19
+ .map( plugin => plugin.postcssPlugin );
20
+
21
+
22
+ if ( includedPlugins.includes( 'postcss-focus-visible' ) ) {
23
+ presetEnv.features[ 'focus-visible-pseudo-class' ] = {
10
24
  /**
11
- * Fixes `focus-visible` feature for CSS modules (included by preset-env anywhere
12
- * Safari is supported).
13
- *
14
- * Requires `focus-visible` polyfill to be loaded externally to support Safari.
15
- *
16
- * @link https://caniuse.com/css-focus-visible
25
+ * Fixes `focus-visible` feature for CSS modules.
17
26
  *
18
- * May be imported directly into the index.js for sites, which loads JS app
19
- * on every page.
20
- * @link https://github.com/WICG/focus-visible
27
+ * Only needed if our browsers list includes non-supported browsers
28
+ * such as Safari 15.3 and below.
21
29
  *
30
+ * Requires `focus-visible` polyfill to be loaded externally.
22
31
  * Most will often need it site wide on pages, which do and don't use the JS app.
32
+ *
23
33
  * @link https://unpkg.com/focus-visible@5.2.0/dist/focus-visible.min.js
24
34
  */
25
- 'focus-visible-pseudo-class': {
26
- replaceWith: ':global(.focus-visible)',
27
- },
28
- },
29
- };
35
+ replaceWith: ':global(.focus-visible)',
36
+ };
37
+ }
30
38
 
31
39
  /**
32
40
  * Provide CSS properties and media queries to all postcss plugins.
@@ -78,6 +86,7 @@ if ( 'production' === process.env.NODE_ENV ) {
78
86
  level: 2,
79
87
  } ) );
80
88
  } else {
89
+ config.plugins.push( require( '../lib/postcss-pretty' ) );
81
90
  config.sourceMap = true;
82
91
  }
83
92
 
@@ -5,6 +5,7 @@
5
5
  "display": "JS Boilerplate",
6
6
  "compilerOptions": {
7
7
  "allowSyntheticDefaultImports": true,
8
+ "forceConsistentCasingInFileNames": true,
8
9
  "jsx": "preserve",
9
10
  "lib": [
10
11
  "dom",
@@ -6,8 +6,8 @@ const {CleanWebpackPlugin} = require( 'clean-webpack-plugin' );
6
6
  const WebpackAssetsManifest = require( 'webpack-assets-manifest' );
7
7
  const {SubresourceIntegrityPlugin} = require( 'webpack-subresource-integrity' );
8
8
  const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' );
9
-
10
9
  const WebpackAssetsHash = require( '../helpers/WebpackAssetsHash' );
10
+
11
11
  const {getConfig, getTsConfigFile, getBrowsersList} = require( '../helpers/config' );
12
12
  const moduleHelpers = require( '../helpers/modules' );
13
13
  const config = require( '../helpers/package-config' );
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Custom PostCSS plugin to format CSS output.
5
+ *
6
+ * - Fix indentation.
7
+ *
8
+ * Inspired by postcss-prettify.
9
+ */
10
+
11
+
12
+ import {Container, Root} from 'postcss';
13
+ import {ChildNode} from 'postcss/lib/node';
14
+ import {AtRuleRaws} from 'postcss/lib/at-rule';
15
+
16
+ /**
17
+ * Get the depth of the current node.
18
+ */
19
+ function getDepth( node: ChildNode ): number {
20
+ let depth = 0;
21
+ let parent = node.parent;
22
+ if ( 'undefined' === typeof parent ) {
23
+ return 0;
24
+ }
25
+ while ( parent && parent.type !== 'root' ) {
26
+ depth += 1;
27
+ parent = parent.parent as Container<ChildNode> | undefined;
28
+ }
29
+ return depth;
30
+ }
31
+
32
+ function indent( node: ChildNode, depth: number, position: keyof AtRuleRaws = 'before' ) {
33
+ if ( node.raws[ position ] === undefined ) {
34
+ return;
35
+ }
36
+ const indentStr = '\t'.repeat( depth );
37
+ if ( 'string' === typeof node.raws[ position ] ) {
38
+ const content = node.raws[ position ] as string;
39
+ node.raws[ position ] = content.trim().concat( `\n${indentStr}` );
40
+ }
41
+ }
42
+
43
+ function processCss( node: ChildNode ) {
44
+ const nodeDepth = getDepth( node );
45
+ indent( node, nodeDepth, 'before' );
46
+ indent( node, nodeDepth, 'after' );
47
+
48
+ if ( 0 === nodeDepth ) {
49
+ node.raws.before += '\n';
50
+ }
51
+ }
52
+
53
+ module.exports = () => {
54
+ return {
55
+ postcssPlugin: 'js-boilerplate/postcss-pretty',
56
+ OnceExit( css: Root ) {
57
+ css.walk( processCss );
58
+ if ( css.first !== undefined && css.first.raws !== undefined ) {
59
+ css.first.raws.before = '';
60
+ }
61
+ },
62
+ };
63
+ };
64
+
65
+ module.exports.postcss = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate",
3
- "version": "10.3.1",
3
+ "version": "10.4.0-beta.1",
4
4
  "description": "Dependencies and scripts for a no config JavaScript app",
5
5
  "author": "Mat Lipe",
6
6
  "license": "MIT",
@@ -44,8 +44,9 @@
44
44
  "@babel/preset-typescript": "^7.12.7",
45
45
  "@csstools/postcss-global-data": "2.0.0",
46
46
  "@lipemat/css-mqpacker": "^9.0.0",
47
- "@lipemat/eslint-config": "^3.0.1",
47
+ "@lipemat/eslint-config": "^3.1.3",
48
48
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
49
+ "@types/node": "^16",
49
50
  "@wordpress/browserslist-config": "^5.19.0",
50
51
  "are-you-es5": "^2.1.1",
51
52
  "babel-jest": "^29.0.0",
@@ -85,7 +86,11 @@
85
86
  "webpack-subresource-integrity": "^5.1.0"
86
87
  },
87
88
  "devDependencies": {
88
- "@types/jest": "^29.5.3"
89
+ "@types/jest": "^29.5.3",
90
+ "eslint": "^8",
91
+ "glob": "^10.3.3",
92
+ "memfs": "^3.5.3",
93
+ "setimmediate": "^1.0.5"
89
94
  },
90
- "packageManager": "yarn@3.6.0"
95
+ "packageManager": "yarn@3.6.1"
91
96
  }
@@ -2,17 +2,21 @@
2
2
 
3
3
  /**
4
4
  * When using PNP loose mode, we get warnings for every module
5
- * we access which is not strictly declared.
5
+ * we access, not strictly declared.
6
6
  *
7
- * There is no built in way in Yarn to disable the warnings.
8
- * This script modifies the generate .pnp.js file to suppress
7
+ * No built-in way in Yarn to disable the warnings.
8
+ * This script modifies to generate .pnp.js file to suppress
9
9
  * all loose module warnings unless the environmental variable
10
10
  * it set to display all warnings.
11
11
  *
12
- * @example "scripts": {
13
- "postinstall": "lipemat-js-boilerplate fix-pnp"
14
- },
15
- *
12
+ * @example
13
+ * ```json
14
+ * {
15
+ * "scripts": {
16
+ * "postinstall": "lipemat-js-boilerplate fix-pnp"
17
+ * }
18
+ * }
19
+ * ```
16
20
  */
17
21
 
18
22
  const fs = require( 'fs' );
@@ -20,6 +24,7 @@ const fs = require( 'fs' );
20
24
  const PNP_FILES = [
21
25
  './.pnp.js',
22
26
  './.pnp.cjs',
27
+ './.pnp.mjs',
23
28
  ];
24
29
 
25
30
  PNP_FILES.forEach( PNP_FILE => {