Skip to content

Commit

Permalink
WIP (this commit will be re-written): update use native Node ESM for …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
trusktr committed Nov 17, 2020
1 parent c354bce commit 607ccc6
Show file tree
Hide file tree
Showing 63 changed files with 3,567 additions and 821 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
const deasync = require('deasync'); // powerful magic

const promiseSync = deasync((promise, cb) => {
promise.then(result => cb(null, result)).catch(error => cb(error));
});

const importSync = name => promiseSync(import(name));

// Look, no await needed here!
const jestConfig = importSync('./jest.config.js').default;
const testGlobals = {};

for (const key of Object.keys(jestConfig.globals)) {
testGlobals[key] = 'readonly';
}

module.exports = {
root: true,
parser: 'babel-eslint',
Expand Down Expand Up @@ -39,6 +55,7 @@ module.exports = {
'no-var': ['error'],
'no-void': ['error'],
'no-with': ['error'],
'no-prototype-builtins': 'off',
radix: ['error'],
'spaced-comment': ['error', 'always'],
strict: ['error', 'global'],
Expand All @@ -60,4 +77,16 @@ module.exports = {
$docsify: 'writable',
dom: 'writable',
},

overrides: [
{
files: ['test/**/*.js', '**/*.test.js'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
globals: testGlobals,
},
{
files: ['test/e2e/**/*.test.js'],
extends: ['plugin:jest-playwright/recommended'],
},
],
};
3 changes: 3 additions & 0 deletions .prettierrc.js → .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
useTabs: false,
tabWidth: 2,
arrowParens: 'avoid',
};
12 changes: 12 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
// presets: [
// [
// '@babel/preset-env',
// {
// targets: {
// node: 'current',
// },
// },
// ],
// ],
};
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ module.exports = {
You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`.

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

// init
var renderer = new Renderer({
Expand Down
31 changes: 22 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
const path = require('path');
const { globals: serverGlobals } = require('./test/config/server.js');
import path from 'path';
import server from './test/config/server.js';

const { globals: serverGlobals } = server;
const dirname = path.dirname(import.meta.url.replace('file://', ''));

const sharedConfig = {
errorOnDeprecated: true,
globals: {
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST
DOCS_PATH: path.resolve(__dirname, 'docs'),
LIB_PATH: path.resolve(__dirname, 'lib'),
SRC_PATH: path.resolve(__dirname, 'src'),
DOCS_PATH: path.resolve(dirname, 'docs'),
LIB_PATH: path.resolve(dirname, 'lib'),
SRC_PATH: path.resolve(dirname, 'src'),
},
globalSetup: './test/config/jest.setup.js',
globalTeardown: './test/config/jest.teardown.js',
globalSetup: './test/config/jest.setup.cjs',
globalTeardown: './test/config/jest.teardown.cjs',
resetModules: true,
restoreMocks: true,
};

module.exports = {
// Adding globals to config root for easier importing into .eslint.js, but
// Jest configuration: https://jestjs.io/docs/en/configuration

// Jest is configured for us to write our code as native ES Modules. See
// https://github.com/facebook/jest/issues/9430 and
// https://jestjs.io/docs/en/ecmascript-modules.

export default {
// Disable transforms, we'll write plain JS. This is needed for native
// ESM
transform: {},

// Adding globals to config root for easier importing into .eslint.cjs, but
// as of Jest 26.4.2 these globals need to be added to each project config
// as well.
globals: sharedConfig.globals,
Expand Down
Loading

0 comments on commit 607ccc6

Please sign in to comment.