Skip to content

Commit 5122732

Browse files
committed
Merge branch 'rollback/esm-settings' into develop
2 parents 72e4a8d + 855d79e commit 5122732

File tree

13 files changed

+32
-17
lines changed

13 files changed

+32
-17
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ const specialConfig = {
8989
files: [
9090
'**/*.config.js',
9191
'**/*.config.cjs',
92+
'**/*.config.mjs',
9293
'**/*.config.*.js',
9394
'**/*.config.*.cjs',
95+
'**/*.config.*.mjs',
9496
],
9597
rules: {
9698
...baseConfig.rules,

CHANGELOG_V4+.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- File extension of Jest & Webpack config files to `mjs`.
10+
- NPM `test` script:
11+
- Removed `jest --clearCache` at the beginning as the updated Jest & ts-jest
12+
settings execute the dynamic import lines with no issue.
13+
- Disabled Node experimental warning message by setting `NODE_NO_WARNINGS=1`.
14+
- Rolled back the value of `moduleResolution` in `tsconfig` to `Node` (means
15+
`.js` file extension on relative imports is now __OPTIONAL__).
16+
- Enhanced function `pathsToESModuleNameMapper` in `jest.config.js` to return a
17+
less clumsy mapping object.
818

919
## [v4.1.2] - 2022-08-15
1020
### Added

jest.config.js renamed to jest.config.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ function pathsToESModuleNameMapper() {
2121
const [key, val] = entry;
2222

2323
if (/.*\(\.\*\)\$$/.test(key)) {
24-
const convertedKey = `${key.substring(0, key.length - 1)}\\.js$`;
24+
// eslint-disable-next-line prefer-template
25+
const convertedKey = key.substring(0, key.length - 2)
26+
+ '[^\\.js])(\\.js)?$';
2527
esmMap[convertedKey] = val;
2628
}
27-
28-
esmMap[key] = val;
2929
});
3030

31+
// Append the mapping for relative paths without path alias.
32+
esmMap['^(\\.{1,2}/.*)\\.js$'] = '$1';
33+
3134
return esmMap;
3235
}
3336

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
"name": "electron-react-typescript-webpack-boilerplate",
33
"version": "4.1.2",
44
"description": "Pre-configured boilerplate for Electron + React + TypeScript",
5-
"type": "module",
65
"main": "./dist/main.bundle.js",
76
"scripts": {
87
"start": "electron ./dist/main.bundle.js",
98
"dev": "rimraf dist && cross-env NODE_ENV=development webpack --watch --progress --color",
109
"prod": "rimraf dist && cross-env NODE_ENV=production webpack --progress --color",
11-
"test": "jest --clearCache && cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest",
10+
"test": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
1211
"watch-test": "npm run test -- --watchAll",
1312
"next-rc": "npm --no-git-tag-version version prerelease --preid=rc",
1413
"next-patch": "npm --no-git-tag-version version patch",

src/main/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as path from 'path';
55
// eslint-disable-next-line import/no-extraneous-dependencies
66
import { BrowserWindow, app, ipcMain } from 'electron';
7-
import * as nodeEnv from '_utils/node-env.js';
7+
import * as nodeEnv from '_utils/node-env';
88

99
let mainWindow: Electron.BrowserWindow | undefined;
1010

src/preload/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import { contextBridge } from 'electron';
3-
import ipcAPI from '_preload/ipc-api.js';
3+
import ipcAPI from '_preload/ipc-api';
44

55
contextBridge.exposeInMainWorld('ipcAPI', ipcAPI);

src/renderer/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// Import the styles here to process them with webpack
55
import '_public/style.css';
66

7-
import App from '_renderer/App.js';
87
import * as React from 'react';
98
import { createRoot } from 'react-dom/client';
9+
import App from '_renderer/App';
1010

1111
const container = document.getElementById('app');
1212
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

src/types/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare global {
22
interface Window {
33
/** APIs for Electron IPC */
4-
ipcAPI?: typeof import('_preload/ipc-api.js').default
4+
ipcAPI?: typeof import('_preload/ipc-api').default
55
}
66
}
77

tests/main/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals';
22
import { BrowserWindow } from 'electron';
3-
import { exportedForTests } from '_main/main.js';
3+
import { exportedForTests } from '_main/main';
44

55
jest.mock('electron', () => ({
66
app: {

tests/utils/node-env.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test('NODE_ENV=test', async () => {
44
process.env.NODE_ENV = 'test';
55
jest.resetModules();
66

7-
const nodeEnv = await import('_utils/node-env.js');
7+
const nodeEnv = await import('_utils/node-env');
88

99
expect(nodeEnv.test).toBeTruthy();
1010
expect(nodeEnv.dev).toBeFalsy();
@@ -15,7 +15,7 @@ test('NODE_ENV=development', async () => {
1515
process.env.NODE_ENV = 'development';
1616
jest.resetModules();
1717

18-
const nodeEnv = await import('_utils/node-env.js');
18+
const nodeEnv = await import('_utils/node-env');
1919

2020
expect(nodeEnv.dev).toBeTruthy();
2121
expect(nodeEnv.prod).toBeFalsy();
@@ -26,7 +26,7 @@ test('NODE_ENV=production', async () => {
2626
process.env.NODE_ENV = 'production';
2727
jest.resetModules();
2828

29-
const nodeEnv = await import('_utils/node-env.js');
29+
const nodeEnv = await import('_utils/node-env');
3030

3131
expect(nodeEnv.prod).toBeTruthy();
3232
expect(nodeEnv.dev).toBeFalsy();

tsconfig.eslint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
".eslintrc.cjs",
1010
"**/*.config.js",
1111
"**/*.config.cjs",
12+
"**/*.config.mjs",
1213
"**/*.config.*.js",
13-
"**/*.config.*.cjs"
14+
"**/*.config.*.cjs",
15+
"**/*.config.*.mjs"
1416
]
1517
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"strict": true,
44
"baseUrl": ".",
55
"module": "ES2020",
6-
"moduleResolution": "Node16",
6+
"moduleResolution": "Node",
77
"paths": {
88
"_/*": ["src/*"],
99
"_public/*": ["public/*"],

webpack.config.js renamed to webpack.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const commonConfig = {
2020
output: { path: path.join(__dirname, 'dist') },
2121
node: { __dirname: false, __filename: false },
2222
plugins: [
23-
new webpack.NormalModuleReplacementPlugin(/.*\/+.+\.js$/, (resource) => {
23+
new webpack.NormalModuleReplacementPlugin(/^\S+\/\S+\.js$/, (resource) => {
2424
// eslint-disable-next-line no-param-reassign
2525
resource.request = resource.request.replace(/\.js$/, '');
2626
}),
@@ -68,7 +68,6 @@ const mainConfig = merge(commonConfig, {
6868
const jsonContent = JSON.parse(content);
6969
const electronVersion = jsonContent.devDependencies.electron;
7070

71-
delete jsonContent.type;
7271
delete jsonContent.devDependencies;
7372
delete jsonContent.optionalDependencies;
7473
delete jsonContent.scripts;

0 commit comments

Comments
 (0)