Skip to content

Commit 27b2e32

Browse files
committed
WIP: update use native Node ESM for server code, update config files to specifically use .cjs (those tools don't support Node ESM files yet), use a single eslintrc file, all test code uses ESM import/export syntax instead of require (WIP)
1 parent c354bce commit 27b2e32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3571
-821
lines changed

.eslintrc.js renamed to .eslintrc.cjs

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
const deasync = require('deasync'); // powerful magic
2+
3+
const promiseSync = deasync((promise, cb) => {
4+
promise.then(result => cb(null, result)).catch(error => cb(error));
5+
});
6+
7+
const importSync = name => promiseSync(import(name));
8+
9+
// Look, no await needed here!
10+
const jestConfig = importSync('./jest.config.js').default;
11+
const testGlobals = {};
12+
13+
for (const key of Object.keys(jestConfig.globals)) {
14+
testGlobals[key] = 'readonly';
15+
}
16+
117
module.exports = {
218
root: true,
319
parser: 'babel-eslint',
@@ -39,6 +55,7 @@ module.exports = {
3955
'no-var': ['error'],
4056
'no-void': ['error'],
4157
'no-with': ['error'],
58+
'no-prototype-builtins': 'off',
4259
radix: ['error'],
4360
'spaced-comment': ['error', 'always'],
4461
strict: ['error', 'global'],
@@ -60,4 +77,16 @@ module.exports = {
6077
$docsify: 'writable',
6178
dom: 'writable',
6279
},
80+
81+
overrides: [
82+
{
83+
files: ['test/**/*.js', '**/*.test.js'],
84+
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
85+
globals: testGlobals,
86+
},
87+
{
88+
files: ['test/e2e/**/*.test.js'],
89+
extends: ['plugin:jest-playwright/recommended'],
90+
},
91+
],
6392
};
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
22
singleQuote: true,
33
trailingComma: 'es5',
4+
useTabs: false,
5+
tabWidth: 2,
6+
arrowParens: 'avoid',
47
};

babel.config.cjs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
// presets: [
3+
// [
4+
// '@babel/preset-env',
5+
// {
6+
// targets: {
7+
// node: 'current',
8+
// },
9+
// },
10+
// ],
11+
// ],
12+
};

babel.config.js

-12
This file was deleted.

docs/ssr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ module.exports = {
106106
You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`.
107107

108108
```js
109-
var Renderer = require('docsify-server-renderer')
110-
var readFileSync = require('fs').readFileSync
109+
import Renderer from 'docsify-server-renderer'
110+
import {readFileSync} from 'fs'
111111

112112
// init
113113
var renderer = new Renderer({

jest.config.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1-
const path = require('path');
2-
const { globals: serverGlobals } = require('./test/config/server.js');
1+
import path from 'path';
2+
import server from './test/config/server.js';
3+
4+
const { globals: serverGlobals } = server;
5+
const dirname = path.dirname(import.meta.url.replace('file://', ''));
36

47
const sharedConfig = {
58
errorOnDeprecated: true,
69
globals: {
710
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST
8-
DOCS_PATH: path.resolve(__dirname, 'docs'),
9-
LIB_PATH: path.resolve(__dirname, 'lib'),
10-
SRC_PATH: path.resolve(__dirname, 'src'),
11+
DOCS_PATH: path.resolve(dirname, 'docs'),
12+
LIB_PATH: path.resolve(dirname, 'lib'),
13+
SRC_PATH: path.resolve(dirname, 'src'),
1114
},
12-
globalSetup: './test/config/jest.setup.js',
13-
globalTeardown: './test/config/jest.teardown.js',
15+
globalSetup: './test/config/jest.setup.cjs',
16+
globalTeardown: './test/config/jest.teardown.cjs',
1417
resetModules: true,
1518
restoreMocks: true,
1619
};
1720

18-
module.exports = {
19-
// Adding globals to config root for easier importing into .eslint.js, but
21+
// Jest configuration: https://jestjs.io/docs/en/configuration
22+
23+
// Jest is configured for us to write our code as native ES Modules. See
24+
// https://github.com/facebook/jest/issues/9430 and
25+
// https://jestjs.io/docs/en/ecmascript-modules.
26+
27+
export default {
28+
// Disable transforms, we'll write plain JS. This is needed for native
29+
// ESM
30+
transform: {},
31+
32+
// Adding globals to config root for easier importing into .eslint.cjs, but
2033
// as of Jest 26.4.2 these globals need to be added to each project config
2134
// as well.
2235
globals: sharedConfig.globals,

0 commit comments

Comments
 (0)