Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion to ESM, and deletion of CommonJS #2106

Merged
merged 5 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const prettierConfig = require('./.prettierrc');
const prettierConfig = require('./.prettierrc.json');

module.exports = {
root: true,
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Build & Test

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
on: [push]

jobs:
lint:
Expand Down
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.eslintignore
.eslintrc
.eslintrc.cjs
.github
.gitignore
.travis.yml
4 changes: 0 additions & 4 deletions .prettierrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"arrowParens": "avoid",
"singleQuote": true
}
19 changes: 9 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
{
"type": "node",
"request": "launch",
"name": "Run tests",
"name": "Run unit tests",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "test"],
"runtimeArgs": ["test"],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Run current test file",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "test"],
"args": ["--", "-i", "${relativeFile}", "--testPathIgnorePatterns"],
"runtimeExecutable": "npx",
"runtimeArgs": ["jest"],
"args": ["-i", "${relativeFile}", "--testPathIgnorePatterns"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scripts were out of date. Now you can run them in VS Code! Give it a try!

"console": "integratedTerminal"
},
{
Expand All @@ -41,10 +41,9 @@
"type": "node",
"request": "launch",
"name": "Update current test file snapshot(s)",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "test"],
"runtimeExecutable": "npx",
"runtimeArgs": ["jest"],
"args": [
"--",
"-i",
"${relativeFile}",
"--updateSnapshot",
Expand All @@ -56,8 +55,8 @@
"type": "node",
"request": "launch",
"name": "Update selected test name snapshot(s)",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "test"],
"runtimeExecutable": "npx",
"runtimeArgs": ["jest"],
"args": [
"--",
"-i",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
- [`develop` branch preview](https://docsify-preview.vercel.app/)
- [Documentation](https://docsify.js.org)
- [CLI](https://github.com/docsifyjs/docsify-cli)
- CDN: [UNPKG](https://unpkg.com/docsify/) | [jsDelivr](https://cdn.jsdelivr.net/npm/docsify/) | [cdnjs](https://cdnjs.com/libraries/docsify)
- CDN:
- [UNPKG](https://unpkg.com/docsify/)
- [jsDelivr](https://cdn.jsdelivr.net/npm/docsify/)
- [cdnjs](https://cdnjs.com/libraries/docsify)
- [Awesome docsify](https://github.com/docsifyjs/awesome-docsify)
- [Community chat](https://discord.gg/3NwKFyR)

Expand Down
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
26 changes: 16 additions & 10 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const rollup = require('rollup')
const buble = require('rollup-plugin-buble')
const commonjs = require('rollup-plugin-commonjs')
const nodeResolve = require('rollup-plugin-node-resolve')
const { uglify } = require('rollup-plugin-uglify')
const replace = require('rollup-plugin-replace')
const isProd = process.env.NODE_ENV === 'production'
const version = process.env.VERSION || require('../package.json').version
const chokidar = require('chokidar')
const path = require('path')
import rollup from 'rollup';
import buble from 'rollup-plugin-buble';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';
import replace from 'rollup-plugin-replace';
import chokidar from 'chokidar';
import path from 'path';
import { relative } from './util.js';
import { promises as fs } from 'fs';

const pkgPath = relative(import.meta, '..', 'package.json');
const pkgString = (await fs.readFile(pkgPath)).toString();
const pkg = JSON.parse(pkgString);
const isProd = process.env.NODE_ENV === 'production';
const version = process.env.VERSION || pkg.version;

/**
* @param {{
Expand Down
21 changes: 12 additions & 9 deletions build/cover.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
var fs = require('fs')
var read = fs.readFileSync
var write = fs.writeFileSync
var version = process.env.VERSION || require('../package.json').version
import fs from 'fs';
import { relative } from './util.js';
var read = fs.readFileSync;
var write = fs.writeFileSync;
const pkgPath = relative(import.meta, '..', 'package.json');
const pkg = JSON.parse(read(pkgPath).toString());
var version = process.env.VERSION || pkg.version;

var file = __dirname + '/../docs/_coverpage.md'
var cover = read(file, 'utf8').toString()
var file = relative(import.meta, '..', 'docs', '_coverpage.md');
var cover = read(file, 'utf8').toString();

console.log('Replace version number in cover page...')
console.log('Replace version number in cover page...');
cover = cover.replace(
/<small>(\S+)?<\/small>/g,
'<small>' + version + '</small>'
)
write(file, cover)
);
write(file, cover);
9 changes: 5 additions & 4 deletions build/css.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const fs = require('fs')
const path = require('path')
const {spawn} = require('child_process')
import fs from 'fs'
import path from 'path'
import {spawn} from 'child_process'

const relative = path => new URL(path, import.meta.url);
const args = process.argv.slice(2)
fs.readdir(path.join(__dirname, '../src/themes'), (err, files) => {
fs.readdir(relative('../src/themes'), (err, files) => {
if (err) {
console.error('err', err)
process.exit(1)
Expand Down
6 changes: 3 additions & 3 deletions build/emoji.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const axios = require('axios');
const fs = require('fs');
const path = require('path');
import axios from 'axios';
import fs from 'fs';
import path from 'path';

const filePaths = {
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'),
Expand Down
10 changes: 5 additions & 5 deletions build/mincss.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const cssnano = require('cssnano').process
const path = require('path')
const fs = require('fs')
import cssnano from 'cssnano';
import path from 'path'
import fs from 'fs'

files = fs.readdirSync(path.resolve('lib/themes'))
const files = fs.readdirSync(path.resolve('lib/themes'))

files.forEach(file => {
file = path.resolve('lib/themes', file)
cssnano(fs.readFileSync(file)).then(result => {
cssnano.process(fs.readFileSync(file)).then(result => {
fs.writeFileSync(file, result.css)
}).catch(e => {
console.error(e)
Expand Down
6 changes: 6 additions & 0 deletions build/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import url from 'url';
import path from 'path';

/** Get a new path relative to the current module (pass import.meta). */
export const relative = (meta, ...to) =>
path.resolve(path.dirname(url.fileURLToPath(meta.url)), ...to);
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { TEST_HOST } = require('./test/config/server.js');
import { TEST_HOST } from './test/config/server.js';

const sharedConfig = {
errorOnDeprecated: true,
Expand All @@ -11,7 +11,8 @@ const sharedConfig = {
testURL: `${TEST_HOST}/_blank.html`,
};

module.exports = {
export default {
transform: {},
projects: [
// Unit Tests
{
Expand Down
Loading