@lipemat/js-boilerplate 10.4.0-beta.4 → 10.4.0-beta.6

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
@@ -88,7 +88,7 @@ This is useful when you have often reused overrides to support a particular libr
88
88
 
89
89
  ### Testing
90
90
  To use the built in testing, copy the following items from `templates` into your project root:
91
- 1. `jest.config.ts`
91
+ 1. `jest.config.js`
92
92
  2. `tests`
93
93
 
94
94
  Now you may write `jest` tests as desired and run them via `yarn run test`
@@ -96,7 +96,7 @@ Now you may write `jest` tests as desired and run them via `yarn run test`
96
96
 
97
97
  **Alternatively you may create a [run configuration](https://www.jetbrains.com/help/phpstorm/running-unit-tests-on-jest.html#createRunConfigJest) in PHPStorm for an interactive testing experience.**
98
98
  1. __Jest package__: `<project root>/node_modules/jest-cli`
99
- 2. __Working directory__: root of your app which contains the `jest.config.ts`.
99
+ 2. __Working directory__: root of your app which contains the `jest.config.js`.
100
100
  3. "All tests" to run an entire directory of tests.
101
101
  4. "Suite" to run a particular file of tests.
102
102
 
@@ -15,10 +15,6 @@ const scriptIndex = args.findIndex(
15
15
  const script = -1 === scriptIndex ? args[ 0 ] : args[ scriptIndex ];
16
16
  const nodeArgs = scriptIndex > 0 ? args.slice( 0, scriptIndex ) : [];
17
17
 
18
- const TS_CONVERTED = [
19
- 'test',
20
- ];
21
-
22
18
  switch ( script ) {
23
19
  case 'browserslist':
24
20
  case 'dist':
@@ -36,7 +32,7 @@ switch ( script ) {
36
32
  const result = spawn.sync(
37
33
  'ts-node',
38
34
  nodeArgs
39
- .concat( require.resolve( '../scripts/' + script + ( TS_CONVERTED.includes( script ) ? '.ts' : '.js' ) ) )
35
+ .concat( require.resolve( '../scripts/' + script ) )
40
36
  .concat( args.slice( scriptIndex + 1 ) ),
41
37
  {stdio: 'inherit'}
42
38
  );
@@ -0,0 +1,51 @@
1
+ // So we have something to check against for adjusting things like babel.config.js.
2
+ global.__TEST__ = true;
3
+
4
+ const path = require( 'path' );
5
+ const packageConfig = require( '../helpers/package-config' );
6
+ const fs = require( 'fs' );
7
+
8
+ const babelConfig = require( '../helpers/config' ).getConfig( 'babel.config' );
9
+ delete babelConfig.cacheDirectory;
10
+
11
+ let jestConfig = {
12
+ globals: {
13
+ __TEST__: true,
14
+ },
15
+ moduleNameMapper: {
16
+ '\\.(pcss|less|css)$': 'identity-obj-proxy',
17
+ 'is-plain-obj': 'identity-obj-proxy',
18
+ uuid: 'identity-obj-proxy',
19
+ },
20
+ roots: [
21
+ './tests',
22
+ ],
23
+ testEnvironment: 'jsdom',
24
+ testEnvironmentOptions: {
25
+ url: packageConfig.url,
26
+ },
27
+ transform: {
28
+ '^.+\\.[tj]sx?$': [ 'babel-jest', babelConfig ],
29
+ },
30
+ setupFilesAfterEnv: [
31
+ // @todo Remove old "tests" directory on next major release.
32
+ path.resolve( packageConfig.workingDirectory, 'tests/setup.js' ),
33
+ path.resolve( packageConfig.workingDirectory, 'tests/setup.ts' ),
34
+
35
+ // New location.
36
+ path.resolve( packageConfig.workingDirectory, 'jest/setup.ts' ),
37
+ ].filter( fs.existsSync ),
38
+ };
39
+
40
+ /**
41
+ * Allows overriding configurations in the project `/config/jest.config.js` file.
42
+ * We don't actually need to do this because `jest.config.js` in the project root
43
+ * is already an override of this file, but we support it anyway to keep things consistent.
44
+ */
45
+ try {
46
+ const localConfig = require( path.resolve( packageConfig.workingDirectory + '/config', 'jest.config.js' ) );
47
+ jestConfig = {...jestConfig, ...localConfig};
48
+ } catch ( e ) {
49
+ }
50
+
51
+ module.exports = jestConfig;
@@ -5,20 +5,18 @@
5
5
  "display": "JS Boilerplate",
6
6
  "compilerOptions": {
7
7
  "allowSyntheticDefaultImports": true,
8
- "esModuleInterop": true,
9
8
  "forceConsistentCasingInFileNames": true,
10
9
  "jsx": "preserve",
11
10
  "lib": [
12
11
  "dom",
13
12
  "es2018"
14
13
  ],
15
- "module": "Node16",
14
+ "module": "ESNext",
16
15
  "moduleResolution": "Node",
17
16
  "noFallthroughCasesInSwitch": true,
18
17
  "noImplicitReturns": true,
19
18
  "noImplicitThis": true,
20
19
  "sourceMap": true,
21
- "strict": false,
22
20
  "strictBindCallApply": true,
23
21
  "strictNullChecks": true,
24
22
  "target": "es6",
@@ -36,12 +36,6 @@ const plugins = [
36
36
  // Remove all files except the `.running` file created by "Start".
37
37
  cleanOnceBeforeBuildPatterns: [ '**/*', '!.running' ],
38
38
  } ),
39
- new ForkTsCheckerWebpackPlugin( {
40
- formatter: 'basic',
41
- typescript: {
42
- configFile: getTsConfigFile(),
43
- },
44
- } ),
45
39
  new SubresourceIntegrityPlugin( {
46
40
  hashFuncNames: [ 'sha384' ],
47
41
  } ),
@@ -49,6 +43,16 @@ const plugins = [
49
43
  ManifestPlugin,
50
44
  ];
51
45
 
46
+ // Loads a thread, which verifies any TypeScripts if project has a "tsconfig.json" file.
47
+ if ( '' !== getTsConfigFile() ) {
48
+ plugins.push( new ForkTsCheckerWebpackPlugin( {
49
+ formatter: 'basic',
50
+ typescript: {
51
+ configFile: getTsConfigFile(),
52
+ },
53
+ } ) );
54
+ }
55
+
52
56
  /**
53
57
  * Generate .br files if enabled.
54
58
  *
@@ -1,11 +1,12 @@
1
- import {getPackageConfig} from './package-config';
1
+ const packageConfig = require( './package-config' );
2
2
  const path = require( 'path' );
3
3
  const browserslist = require( 'browserslist' );
4
4
  const fs = require( 'fs' );
5
+ const config = require( './package-config' );
5
6
 
6
7
  const extensions = [
7
- ...Object.keys( getPackageConfig().dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
8
- ...Object.keys( getPackageConfig().devDependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
8
+ ...Object.keys( packageConfig.dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
9
+ ...Object.keys( packageConfig.devDependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
9
10
  ];
10
11
 
11
12
  /**
@@ -16,9 +17,8 @@ const extensions = [
16
17
  *
17
18
  * @return {boolean}
18
19
  */
19
- function hasLocalOverride( fileName: string, inWorkingDirectory = false, ) {
20
- let hasLocal: boolean = false;
21
- const packageConfig = getPackageConfig();
20
+ function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
21
+ let hasLocal = false;
22
22
  try {
23
23
  if ( inWorkingDirectory ) {
24
24
  require( path.resolve( packageConfig.workingDirectory, fileName ) );
@@ -61,8 +61,7 @@ function hasLocalOverride( fileName: string, inWorkingDirectory = false, ) {
61
61
  *
62
62
  * @return {Object}
63
63
  */
64
- export function getConfig( fileName: string ) {
65
- const packageConfig = getPackageConfig();
64
+ function getConfig( fileName ) {
66
65
  let mergedConfig = require( '../config/' + fileName );
67
66
  mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
68
67
  try {
@@ -89,8 +88,8 @@ export function getConfig( fileName: string ) {
89
88
  *
90
89
  * @return {Object}
91
90
  */
92
- function getExtensionsConfig( fileName: string, defaultConfig: Record<string, any> ) {
93
- let mergedConfig: Record<string, any> = {};
91
+ function getExtensionsConfig( fileName, defaultConfig ) {
92
+ let mergedConfig = {};
94
93
  extensions.forEach( extension => {
95
94
  try {
96
95
  const extensionConfig = require( extension + '/config/' + fileName );
@@ -118,15 +117,14 @@ function getExtensionsConfig( fileName: string, defaultConfig: Record<string, an
118
117
  * @return {string}
119
118
  */
120
119
  function getTsConfigFile() {
121
- const packageConfig = getPackageConfig();
122
120
  const possibles = [
123
121
  // Backward compatible for before @lipemat/eslint-config version 3.
124
- path.resolve( packageConfig.workingDirectory + '/tsconfig.json' ),
125
- path.resolve( packageConfig.packageDirectory + '/tsconfig.json' ),
122
+ path.resolve( config.workingDirectory + '/tsconfig.json' ),
123
+ path.resolve( config.packageDirectory + '/tsconfig.json' ),
126
124
  ];
127
125
  let tsConfig = '';
128
126
  possibles.forEach( filePath => {
129
- if ( Boolean( fs.existsSync( filePath ) ) ) {
127
+ if ( fs.existsSync( filePath ) ) {
130
128
  tsConfig = filePath;
131
129
  }
132
130
  } );
@@ -173,10 +171,7 @@ const getDefaultBrowsersList = () => {
173
171
  return false;
174
172
  };
175
173
 
176
- /**
177
- * @notice This module must remain CommonJS for use with Jest.
178
- * It is loaded before TS is loaded by Jest.
179
- */
174
+
180
175
  module.exports = {
181
176
  getBrowsersList,
182
177
  getConfig,
@@ -1,5 +1,5 @@
1
- import {checkModules} from 'are-you-es5';
2
- import {getBabelLoaderIgnoreRegex} from 'are-you-es5/dist/babel-loader-regex-builder';
1
+ const areYouES5 = require( 'are-you-es5' );
2
+ const regexBuilder = require( 'are-you-es5/dist/babel-loader-regex-builder' );
3
3
  const config = require( './package-config' );
4
4
 
5
5
  /**
@@ -13,11 +13,15 @@ const config = require( './package-config' );
13
13
  *
14
14
  * @return {RegExp}
15
15
  */
16
- export function getBabelExcludeRegex() {
17
- const nonES5 = checkModules( {} );
16
+ function getBabelExcludeRegex() {
17
+ const nonES5 = areYouES5.checkModules( {} );
18
18
  // Support specifying additional es5Modules in package.json.
19
- const regex = getBabelLoaderIgnoreRegex( [ ...nonES5.es6Modules, ...config.es6Modules ] );
19
+ const regex = regexBuilder.getBabelLoaderIgnoreRegex( [ ...nonES5.es6Modules, ...config.es6Modules ] );
20
20
 
21
21
  // We must strip off the leading and trailing '/'.
22
22
  return new RegExp( regex.replace( /^\/|\/$/g, '' ) );
23
23
  }
24
+
25
+ module.exports = {
26
+ getBabelExcludeRegex,
27
+ };
@@ -1,8 +1,8 @@
1
- const {resolve} = require( 'path' );
2
- import {realpathSync} from 'fs';
1
+ const path = require( 'path' );
2
+ const fs = require( 'fs' );
3
3
 
4
- const workingDirectory = realpathSync( process.cwd() );
5
- let packageConfig = require( resolve( workingDirectory, 'package.json' ) );
4
+ const workingDirectory = fs.realpathSync( process.cwd() );
5
+ let packageConfig = require( path.resolve( workingDirectory, 'package.json' ) );
6
6
  packageConfig.brotliFiles ||= false;
7
7
  packageConfig.es6Modules ||= [];
8
8
  packageConfig.jsPath ||= '';
@@ -10,11 +10,11 @@ packageConfig.jsPath ||= '';
10
10
  packageConfig.packageDirectory = workingDirectory;
11
11
  packageConfig.url ||= 'http://localhost';
12
12
  // Path of JS application files.
13
- packageConfig.workingDirectory = packageConfig.jsPath !== '' ? resolve( packageConfig.jsPath ) : workingDirectory;
13
+ packageConfig.workingDirectory = packageConfig.jsPath !== '' ? path.resolve( packageConfig.jsPath ) : workingDirectory;
14
14
  packageConfig.shortCssClasses ||= false;
15
15
 
16
16
  try {
17
- const localConfig = require( resolve( workingDirectory, './local-config.json' ) );
17
+ const localConfig = require( path.resolve( workingDirectory, './local-config.json' ) );
18
18
  packageConfig = {...packageConfig, ...localConfig};
19
19
  } catch ( e ) {
20
20
  }
@@ -27,10 +27,9 @@ try {
27
27
  *
28
28
  * @since 10.3.0
29
29
  */
30
- export function getPackageConfig() {
30
+ function getPackageConfig() {
31
31
  return packageConfig;
32
32
  }
33
-
34
33
  packageConfig.getPackageConfig = getPackageConfig;
35
34
 
36
35
  module.exports = packageConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate",
3
- "version": "10.4.0-beta.4",
3
+ "version": "10.4.0-beta.6",
4
4
  "description": "Dependencies and scripts for a no config JavaScript app",
5
5
  "author": "Mat Lipe",
6
6
  "license": "MIT",
@@ -78,7 +78,6 @@
78
78
  "react-dom": "^18.2.0",
79
79
  "react-refresh": "^0.14.0",
80
80
  "style-loader": "^3.3.1",
81
- "ts-node": "^10.9.1",
82
81
  "typescript": "^5.1.3",
83
82
  "update-notifier": "^4.1.3",
84
83
  "webpack": "^5.72.1",
@@ -1,7 +1,7 @@
1
1
  const {resolve: pathResolve} = require( 'path' );
2
2
  const {existsSync} = require( 'fs' );
3
3
 
4
- import {getPackageConfig} from '../helpers/package-config';
4
+ const {getPackageConfig} = require( '../helpers/package-config' );
5
5
 
6
6
  const packageConfig = getPackageConfig();
7
7
 
package/tsconfig.json CHANGED
@@ -2,14 +2,15 @@
2
2
  "extends": "./config/tsconfig.json",
3
3
  "$schema": "https://json.schemastore.org/tsconfig",
4
4
  "display": "JS Boilerplate",
5
+ "compilerOptions": {
6
+ "module": "CommonJS"
7
+ },
5
8
  "include": [
6
- "jest.config.js",
7
- "jest.config.ts",
8
9
  "bin/**/*",
9
10
  "config/**/*",
10
11
  "helpers/**/*",
11
12
  "lib/**/*",
12
- "scripts/**/*",
13
- "tests/**/*",
13
+ "jest/**/*",
14
+ "scripts/**/*"
14
15
  ]
15
16
  }
@@ -1,51 +0,0 @@
1
- import type {Config} from 'jest';
2
- import {resolve} from 'path';
3
- const {getPackageConfig} = require( '../helpers/package-config' );
4
- const {existsSync} = require( 'fs' );
5
- import {getConfig} from '../helpers/config';
6
-
7
- const packageConfig = getPackageConfig();
8
- const babelConfig = getConfig( 'babel.config' );
9
- delete babelConfig.cacheDirectory;
10
-
11
- let jestConfig: Config = {
12
- globals: {
13
- __TEST__: true,
14
- },
15
- moduleNameMapper: {
16
- '\\.(pcss|less|css)$': 'identity-obj-proxy',
17
- 'is-plain-obj': 'identity-obj-proxy',
18
- uuid: 'identity-obj-proxy',
19
- },
20
- roots: [
21
- './tests',
22
- ],
23
- testEnvironment: 'jsdom',
24
- testEnvironmentOptions: {
25
- url: packageConfig.url,
26
- },
27
- transform: {
28
- '^.+\\.[tj]sx?$': [ 'babel-jest', babelConfig ],
29
- },
30
- setupFilesAfterEnv: [
31
- // @todo Remove old "tests" directory on next major release.
32
- resolve( packageConfig.workingDirectory, 'tests/setup.js' ),
33
- resolve( packageConfig.workingDirectory, 'tests/setup.ts' ),
34
-
35
- // New location.
36
- resolve( packageConfig.workingDirectory, 'jest/setup.ts' ),
37
- ].filter( existsSync ),
38
- };
39
-
40
- /**
41
- * Never ended up using this.
42
- *
43
- * @todo Remove in version 11.
44
- */
45
- try {
46
- const localConfig = require( resolve( packageConfig.workingDirectory + '/config', 'jest.config.ts' ) );
47
- jestConfig = {...jestConfig, ...localConfig};
48
- } catch ( e ) {
49
- }
50
-
51
- export default jestConfig;