Skip to content

Commit c2428f7

Browse files
authored
Merge pull request #2106 from docsifyjs/es-modules
conversion to ESM, and deletion of CommonJS
2 parents a69c22a + 376c92d commit c2428f7

Some content is hidden

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

91 files changed

+1152
-961
lines changed

Diff for: .eslintrc.js renamed to .eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const prettierConfig = require('./.prettierrc');
1+
const prettierConfig = require('./.prettierrc.json');
22

33
module.exports = {
44
root: true,

Diff for: .github/workflows/test.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Build & Test
22

3-
on:
4-
push:
5-
branches: [master, develop]
6-
pull_request:
7-
branches: [master, develop]
3+
on: [push]
84

95
jobs:
106
lint:

Diff for: .npmignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.eslintignore
2-
.eslintrc
2+
.eslintrc.cjs
33
.github
44
.gitignore
5-
.travis.yml

Diff for: .prettierrc.js

-4
This file was deleted.

Diff for: .prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"arrowParens": "avoid",
3+
"singleQuote": true
4+
}

Diff for: .vscode/launch.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Run tests",
10+
"name": "Run unit tests",
1111
"runtimeExecutable": "npm",
12-
"runtimeArgs": ["run-script", "test"],
12+
"runtimeArgs": ["test"],
1313
"console": "integratedTerminal"
1414
},
1515
{
1616
"type": "node",
1717
"request": "launch",
1818
"name": "Run current test file",
19-
"runtimeExecutable": "npm",
20-
"runtimeArgs": ["run-script", "test"],
21-
"args": ["--", "-i", "${relativeFile}", "--testPathIgnorePatterns"],
19+
"runtimeExecutable": "npx",
20+
"runtimeArgs": ["jest"],
21+
"args": ["-i", "${relativeFile}", "--testPathIgnorePatterns"],
2222
"console": "integratedTerminal"
2323
},
2424
{
@@ -41,10 +41,9 @@
4141
"type": "node",
4242
"request": "launch",
4343
"name": "Update current test file snapshot(s)",
44-
"runtimeExecutable": "npm",
45-
"runtimeArgs": ["run-script", "test"],
44+
"runtimeExecutable": "npx",
45+
"runtimeArgs": ["jest"],
4646
"args": [
47-
"--",
4847
"-i",
4948
"${relativeFile}",
5049
"--updateSnapshot",
@@ -56,8 +55,8 @@
5655
"type": "node",
5756
"request": "launch",
5857
"name": "Update selected test name snapshot(s)",
59-
"runtimeExecutable": "npm",
60-
"runtimeArgs": ["run-script", "test"],
58+
"runtimeExecutable": "npx",
59+
"runtimeArgs": ["jest"],
6160
"args": [
6261
"--",
6362
"-i",

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
- [`develop` branch preview](https://docsify-preview.vercel.app/)
3333
- [Documentation](https://docsify.js.org)
3434
- [CLI](https://github.com/docsifyjs/docsify-cli)
35-
- CDN: [UNPKG](https://unpkg.com/docsify/) | [jsDelivr](https://cdn.jsdelivr.net/npm/docsify/) | [cdnjs](https://cdnjs.com/libraries/docsify)
35+
- CDN:
36+
- [UNPKG](https://unpkg.com/docsify/)
37+
- [jsDelivr](https://cdn.jsdelivr.net/npm/docsify/)
38+
- [cdnjs](https://cdnjs.com/libraries/docsify)
3639
- [Awesome docsify](https://github.com/docsifyjs/awesome-docsify)
3740
- [Community chat](https://discord.gg/3NwKFyR)
3841

Diff for: babel.config.js

-12
This file was deleted.

Diff for: babel.config.json

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

Diff for: build/build.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
const rollup = require('rollup')
2-
const buble = require('rollup-plugin-buble')
3-
const commonjs = require('rollup-plugin-commonjs')
4-
const nodeResolve = require('rollup-plugin-node-resolve')
5-
const { uglify } = require('rollup-plugin-uglify')
6-
const replace = require('rollup-plugin-replace')
7-
const isProd = process.env.NODE_ENV === 'production'
8-
const version = process.env.VERSION || require('../package.json').version
9-
const chokidar = require('chokidar')
10-
const path = require('path')
1+
import rollup from 'rollup';
2+
import buble from 'rollup-plugin-buble';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import nodeResolve from 'rollup-plugin-node-resolve';
5+
import { uglify } from 'rollup-plugin-uglify';
6+
import replace from 'rollup-plugin-replace';
7+
import chokidar from 'chokidar';
8+
import path from 'path';
9+
import { relative } from './util.js';
10+
import { promises as fs } from 'fs';
11+
12+
const pkgPath = relative(import.meta, '..', 'package.json');
13+
const pkgString = (await fs.readFile(pkgPath)).toString();
14+
const pkg = JSON.parse(pkgString);
15+
const isProd = process.env.NODE_ENV === 'production';
16+
const version = process.env.VERSION || pkg.version;
1117

1218
/**
1319
* @param {{

Diff for: build/cover.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
var fs = require('fs')
2-
var read = fs.readFileSync
3-
var write = fs.writeFileSync
4-
var version = process.env.VERSION || require('../package.json').version
1+
import fs from 'fs';
2+
import { relative } from './util.js';
3+
var read = fs.readFileSync;
4+
var write = fs.writeFileSync;
5+
const pkgPath = relative(import.meta, '..', 'package.json');
6+
const pkg = JSON.parse(read(pkgPath).toString());
7+
var version = process.env.VERSION || pkg.version;
58

6-
var file = __dirname + '/../docs/_coverpage.md'
7-
var cover = read(file, 'utf8').toString()
9+
var file = relative(import.meta, '..', 'docs', '_coverpage.md');
10+
var cover = read(file, 'utf8').toString();
811

9-
console.log('Replace version number in cover page...')
12+
console.log('Replace version number in cover page...');
1013
cover = cover.replace(
1114
/<small>(\S+)?<\/small>/g,
1215
'<small>' + version + '</small>'
13-
)
14-
write(file, cover)
16+
);
17+
write(file, cover);

Diff for: build/css.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const {spawn} = require('child_process')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import {spawn} from 'child_process'
44

5+
const relative = path => new URL(path, import.meta.url);
56
const args = process.argv.slice(2)
6-
fs.readdir(path.join(__dirname, '../src/themes'), (err, files) => {
7+
fs.readdir(relative('../src/themes'), (err, files) => {
78
if (err) {
89
console.error('err', err)
910
process.exit(1)

Diff for: build/emoji.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const axios = require('axios');
2-
const fs = require('fs');
3-
const path = require('path');
1+
import axios from 'axios';
2+
import fs from 'fs';
3+
import path from 'path';
44

55
const filePaths = {
66
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'),

Diff for: build/mincss.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const cssnano = require('cssnano').process
2-
const path = require('path')
3-
const fs = require('fs')
1+
import cssnano from 'cssnano';
2+
import path from 'path'
3+
import fs from 'fs'
44

5-
files = fs.readdirSync(path.resolve('lib/themes'))
5+
const files = fs.readdirSync(path.resolve('lib/themes'))
66

77
files.forEach(file => {
88
file = path.resolve('lib/themes', file)
9-
cssnano(fs.readFileSync(file)).then(result => {
9+
cssnano.process(fs.readFileSync(file)).then(result => {
1010
fs.writeFileSync(file, result.css)
1111
}).catch(e => {
1212
console.error(e)

Diff for: build/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import url from 'url';
2+
import path from 'path';
3+
4+
/** Get a new path relative to the current module (pass import.meta). */
5+
export const relative = (meta, ...to) =>
6+
path.resolve(path.dirname(url.fileURLToPath(meta.url)), ...to);

Diff for: jest.config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { TEST_HOST } = require('./test/config/server.js');
1+
import { TEST_HOST } from './test/config/server.js';
22

33
const sharedConfig = {
44
errorOnDeprecated: true,
@@ -11,7 +11,8 @@ const sharedConfig = {
1111
testURL: `${TEST_HOST}/_blank.html`,
1212
};
1313

14-
module.exports = {
14+
export default {
15+
transform: {},
1516
projects: [
1617
// Unit Tests
1718
{

0 commit comments

Comments
 (0)