@lipemat/js-boilerplate 10.4.0-beta.1 → 10.4.0-beta.3
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/bin/lipemat-js-boilerplate.js +5 -1
- package/config/jest.config.js +16 -5
- package/config/jest.config.ts +51 -0
- package/helpers/{config.js → config.ts} +9 -8
- package/helpers/{package-config.js → package-config.ts} +9 -7
- package/package.json +4 -1
- package/scripts/test.ts +24 -0
- package/tsconfig.json +16 -0
- package/scripts/test.js +0 -12
|
@@ -15,6 +15,10 @@ 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
|
+
|
|
18
22
|
switch ( script ) {
|
|
19
23
|
case 'browserslist':
|
|
20
24
|
case 'dist':
|
|
@@ -32,7 +36,7 @@ switch ( script ) {
|
|
|
32
36
|
const result = spawn.sync(
|
|
33
37
|
'ts-node',
|
|
34
38
|
nodeArgs
|
|
35
|
-
.concat( require.resolve( '../scripts/' + script ) )
|
|
39
|
+
.concat( require.resolve( '../scripts/' + script + ( TS_CONVERTED.includes( script ) ? '.ts' : '.js' ) ) )
|
|
36
40
|
.concat( args.slice( scriptIndex + 1 ) ),
|
|
37
41
|
{stdio: 'inherit'}
|
|
38
42
|
);
|
package/config/jest.config.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Kept here for backward compatibility.
|
|
3
|
+
*
|
|
4
|
+
* @deprecated
|
|
5
|
+
*
|
|
6
|
+
* @todo Remove on next major release.
|
|
7
|
+
*
|
|
8
|
+
* @see jest.config.ts
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Necessary because some of the boilerplate code is written in TypeScript.
|
|
12
|
+
require( 'ts-node/register' );
|
|
3
13
|
|
|
4
14
|
const path = require( 'path' );
|
|
5
|
-
const packageConfig = require( '../helpers/package-config' );
|
|
15
|
+
const packageConfig = require( '../helpers/package-config.ts' );
|
|
6
16
|
const fs = require( 'fs' );
|
|
7
17
|
|
|
8
|
-
const babelConfig = require( '../helpers/config' ).getConfig( 'babel.config' );
|
|
18
|
+
const babelConfig = require( '../helpers/config.ts' ).getConfig( 'babel.config' );
|
|
9
19
|
delete babelConfig.cacheDirectory;
|
|
10
20
|
|
|
11
21
|
let jestConfig = {
|
|
@@ -30,12 +40,13 @@ let jestConfig = {
|
|
|
30
40
|
setupFilesAfterEnv: [
|
|
31
41
|
path.resolve( packageConfig.workingDirectory, 'tests/setup.js' ),
|
|
32
42
|
path.resolve( packageConfig.workingDirectory, 'tests/setup.ts' ),
|
|
43
|
+
path.resolve( packageConfig.workingDirectory, 'jest/setup.ts' ),
|
|
33
44
|
].filter( fs.existsSync ),
|
|
34
45
|
};
|
|
35
46
|
|
|
36
47
|
/**
|
|
37
48
|
* Allows overriding configurations in the project `/config/jest.config.js` file.
|
|
38
|
-
* We don't actually need to do this because `jest.config.
|
|
49
|
+
* We don't actually need to do this because `jest.config.[tj]s` in the project root
|
|
39
50
|
* is already an override of this file, but we support it anyway to keep things consistent.
|
|
40
51
|
*/
|
|
41
52
|
try {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {Config} from 'jest';
|
|
2
|
+
import {resolve} from 'path';
|
|
3
|
+
const {getPackageConfig} = require( '../helpers/package-config' );
|
|
4
|
+
const {existsSync} = require( 'fs' );
|
|
5
|
+
const {getConfig} = require( '../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.js' ) );
|
|
47
|
+
jestConfig = {...jestConfig, ...localConfig};
|
|
48
|
+
} catch ( e ) {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = jestConfig;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {getPackageConfig} from './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' );
|
|
6
5
|
|
|
7
6
|
const extensions = [
|
|
8
|
-
...Object.keys(
|
|
9
|
-
...Object.keys(
|
|
7
|
+
...Object.keys( getPackageConfig().dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
8
|
+
...Object.keys( getPackageConfig().devDependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
10
9
|
];
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -19,6 +18,7 @@ const extensions = [
|
|
|
19
18
|
*/
|
|
20
19
|
function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
21
20
|
let hasLocal = false;
|
|
21
|
+
const packageConfig = getPackageConfig();
|
|
22
22
|
try {
|
|
23
23
|
if ( inWorkingDirectory ) {
|
|
24
24
|
require( path.resolve( packageConfig.workingDirectory, fileName ) );
|
|
@@ -62,6 +62,7 @@ function hasLocalOverride( fileName, inWorkingDirectory = false, ) {
|
|
|
62
62
|
* @return {Object}
|
|
63
63
|
*/
|
|
64
64
|
function getConfig( fileName ) {
|
|
65
|
+
const packageConfig = getPackageConfig();
|
|
65
66
|
let mergedConfig = require( '../config/' + fileName );
|
|
66
67
|
mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
|
|
67
68
|
try {
|
|
@@ -117,14 +118,15 @@ function getExtensionsConfig( fileName, defaultConfig ) {
|
|
|
117
118
|
* @return {string}
|
|
118
119
|
*/
|
|
119
120
|
function getTsConfigFile() {
|
|
121
|
+
const packageConfig = getPackageConfig();
|
|
120
122
|
const possibles = [
|
|
121
123
|
// Backward compatible for before @lipemat/eslint-config version 3.
|
|
122
|
-
path.resolve(
|
|
123
|
-
path.resolve(
|
|
124
|
+
path.resolve( packageConfig.workingDirectory + '/tsconfig.json' ),
|
|
125
|
+
path.resolve( packageConfig.packageDirectory + '/tsconfig.json' ),
|
|
124
126
|
];
|
|
125
127
|
let tsConfig = '';
|
|
126
128
|
possibles.forEach( filePath => {
|
|
127
|
-
if ( fs.existsSync( filePath ) ) {
|
|
129
|
+
if ( Boolean( fs.existsSync( filePath ) ) ) {
|
|
128
130
|
tsConfig = filePath;
|
|
129
131
|
}
|
|
130
132
|
} );
|
|
@@ -171,7 +173,6 @@ const getDefaultBrowsersList = () => {
|
|
|
171
173
|
return false;
|
|
172
174
|
};
|
|
173
175
|
|
|
174
|
-
|
|
175
176
|
module.exports = {
|
|
176
177
|
getBrowsersList,
|
|
177
178
|
getConfig,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {resolve} from 'path';
|
|
2
|
+
import {realpathSync} from 'fs';
|
|
3
3
|
|
|
4
|
-
const workingDirectory =
|
|
5
|
-
let packageConfig = require(
|
|
4
|
+
const workingDirectory = realpathSync( process.cwd() );
|
|
5
|
+
let packageConfig = require( 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 !== '' ?
|
|
13
|
+
packageConfig.workingDirectory = packageConfig.jsPath !== '' ? resolve( packageConfig.jsPath ) : workingDirectory;
|
|
14
14
|
packageConfig.shortCssClasses ||= false;
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
|
-
const localConfig = require(
|
|
17
|
+
const localConfig = require( resolve( workingDirectory, './local-config.json' ) );
|
|
18
18
|
packageConfig = {...packageConfig, ...localConfig};
|
|
19
19
|
} catch ( e ) {
|
|
20
20
|
}
|
|
@@ -27,9 +27,11 @@ try {
|
|
|
27
27
|
*
|
|
28
28
|
* @since 10.3.0
|
|
29
29
|
*/
|
|
30
|
-
function getPackageConfig() {
|
|
30
|
+
export function getPackageConfig() {
|
|
31
31
|
return packageConfig;
|
|
32
32
|
}
|
|
33
33
|
packageConfig.getPackageConfig = getPackageConfig;
|
|
34
34
|
|
|
35
|
+
// Leaving old export structure for backwards compatibility.
|
|
36
|
+
// @todo Remove in favor of default export in version 11.
|
|
35
37
|
module.exports = packageConfig;
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "10.4.0-beta.
|
|
3
|
+
"version": "10.4.0-beta.3",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"author": "Mat Lipe",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "commonjs",
|
|
7
8
|
"engines": {
|
|
8
9
|
"node": ">=16.14.2"
|
|
9
10
|
},
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"no-config"
|
|
24
25
|
],
|
|
25
26
|
"files": [
|
|
27
|
+
"tsconfig.json",
|
|
26
28
|
"bin/",
|
|
27
29
|
"config/",
|
|
28
30
|
"helpers/",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"react-dom": "^18.2.0",
|
|
78
80
|
"react-refresh": "^0.14.0",
|
|
79
81
|
"style-loader": "^3.3.1",
|
|
82
|
+
"ts-node": "^10.9.1",
|
|
80
83
|
"typescript": "^5.1.3",
|
|
81
84
|
"update-notifier": "^4.1.3",
|
|
82
85
|
"webpack": "^5.72.1",
|
package/scripts/test.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
const packageConfig = require( '../helpers/package-config' );
|
|
5
|
+
|
|
6
|
+
const possibleConfig = [
|
|
7
|
+
// @todo Remove pulling from the root on next major release.
|
|
8
|
+
path.resolve( packageConfig.workingDirectory + '/jest.config.js' ),
|
|
9
|
+
|
|
10
|
+
// New location.
|
|
11
|
+
path.resolve( packageConfig.workingDirectory + '/jest/jest.config.js' ),
|
|
12
|
+
path.resolve( packageConfig.workingDirectory + '/jest/jest.config.ts' ),
|
|
13
|
+
].filter( fs.existsSync );
|
|
14
|
+
|
|
15
|
+
if ( possibleConfig.length < 1 ) {
|
|
16
|
+
throw new Error( 'You must have a `jest.config.[tj]s` file in the root of your project or in the `jest` folder.' );
|
|
17
|
+
} else {
|
|
18
|
+
const file = possibleConfig.shift();
|
|
19
|
+
if ( undefined !== file ) {
|
|
20
|
+
process.argv.push( '--config', file );
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
require( 'jest-cli/bin/jest' );
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./config/tsconfig.json",
|
|
3
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
4
|
+
"display": "JS Boilerplate",
|
|
5
|
+
"include": [
|
|
6
|
+
"bin/**/*",
|
|
7
|
+
"config/**/*",
|
|
8
|
+
"helpers/**/*",
|
|
9
|
+
"lib/**/*",
|
|
10
|
+
"scripts/**/*"
|
|
11
|
+
],
|
|
12
|
+
"compilerOptions": {
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"module": "CommonJS"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/scripts/test.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runs `jest` with any arguments passed via the terminal or yarn.
|
|
3
|
-
*
|
|
4
|
-
* @notice you must add `/templates/jest.config.js` to the `jsPath` of your project.
|
|
5
|
-
*
|
|
6
|
-
* @example `lipemat-js-boilerplate test`
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const packageConfig = require( '../helpers/package-config' );
|
|
10
|
-
process.argv.push( '--config', packageConfig.workingDirectory + '/jest.config.js' );
|
|
11
|
-
|
|
12
|
-
require( 'jest-cli/bin/jest' );
|