Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 3, 2021
1 parent 16baa4f commit b7afd25
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 129 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"type": "module",
"devDependencies": {
"c8": "^7.0.0",
"camelcase": "^6.0.0",
Expand All @@ -29,8 +30,7 @@
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
"format": "./packages/remark-cli/cli.js . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "tape \"packages/*/test.js\" \"test/index.js\"",
"test-api": "node --conditions development test/index.js",
"test-api": "node --conditions development test/index.js && lerna run test",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run format && npm run test-coverage"
},
Expand All @@ -44,8 +44,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {},
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
},
"ignores": [
"**/types"
]
Expand Down
29 changes: 21 additions & 8 deletions packages/remark-cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#!/usr/bin/env node
'use strict'
import {createRequire} from 'node:module'
import start from 'unified-args'
import {remark} from 'remark'

var start = require('unified-args')
var extensions = require('markdown-extensions')
var processor = require('remark')
var proc = require('remark/package.json')
var cli = require('./package.json')
const require = createRequire(import.meta.url)

const proc = require('remark/package.json')
const cli = require('./package.json')

// To do: enable `markdown-extensions` once it supports ESM.
const extensions = [
'md',
'markdown',
'mdown',
'mkdn',
'mkd',
'mdwn',
'mkdown',
'ron'
]

start({
processor: processor,
processor: remark,
name: proc.name,
description: cli.description,
version: [
Expand All @@ -20,5 +33,5 @@ start({
packageField: proc.name + 'Config',
rcName: '.' + proc.name + 'rc',
ignoreName: '.' + proc.name + 'ignore',
extensions: extensions
extensions
})
5 changes: 3 additions & 2 deletions packages/remark-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"type": "module",
"main": "index.js",
"bin": {
"remark": "cli.js"
},
"files": [
"cli.js"
],
"dependencies": {
"markdown-extensions": "^1.1.0",
"remark": "^13.0.0",
"unified-args": "^8.0.0"
},
"scripts": {
"test": "tape test.js"
"test": "node --conditions development test.js"
},
"xo": false
}
14 changes: 5 additions & 9 deletions packages/remark-cli/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use strict'

var path = require('path')
var execa = require('execa')
var test = require('tape')

var join = path.join
import url from 'url'
import execa from 'execa'
import test from 'tape'

test('remark-cli', function (t) {
t.plan(2)

t.test('should show help on `--help`', function (st) {
var bin = join('packages', 'remark-cli', 'cli.js')
const bin = url.fileURLToPath(new URL('./cli.js', import.meta.url))

st.plan(1)

Expand Down Expand Up @@ -67,7 +63,7 @@ test('remark-cli', function (t) {
})

t.test('should show version on `--version`', function (st) {
var bin = join('packages', 'remark-cli', 'cli.js')
const bin = url.fileURLToPath(new URL('./cli.js', import.meta.url))

st.plan(2)

Expand Down
8 changes: 2 additions & 6 deletions packages/remark-parse/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import fromMarkdown from 'mdast-util-from-markdown'

module.exports = parse

var fromMarkdown = require('mdast-util-from-markdown')

function parse(options) {
export default function remarkParse(options) {
var self = this

this.Parser = parse
Expand Down
9 changes: 5 additions & 4 deletions packages/remark-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"ast",
"parse"
],
"types": "types/index.d.ts",
"homepage": "https://remark.js.org",
"repository": "https://github.com/remarkjs/remark/tree/main/packages/remark-parse",
"bugs": "https://github.com/remarkjs/remark/issues",
Expand All @@ -32,15 +31,17 @@
"Elijah Hamovitz <elijahhamovitz@gmail.com>",
"Ika <ikatyang@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js",
"types/index.d.ts"
"index.js"
],
"dependencies": {
"mdast-util-from-markdown": "^0.8.0"
},
"scripts": {
"test": "tape test.js"
"test": "node --conditions development test.js"
},
"xo": false
}
21 changes: 9 additions & 12 deletions packages/remark-parse/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
'use strict'
import test from 'tape'
import unified from 'unified'
import gfmSyntax from 'micromark-extension-gfm'
import gfm from 'mdast-util-gfm/from-markdown.js'
import remove from 'unist-util-remove-position'
import remarkParse from './index.js'

var test = require('tape')
var unified = require('unified')
var gfmSyntax = require('micromark-extension-gfm')
var gfm = require('mdast-util-gfm/from-markdown')
var remove = require('unist-util-remove-position')

var parse = require('.')

test('remark().parse(file)', function (t) {
test('remarkParse', function (t) {
t.equal(
unified().use(parse).parse('Alfred').children.length,
unified().use(remarkParse).parse('Alfred').children.length,
1,
'should accept a `string`'
)
Expand All @@ -19,7 +16,7 @@ test('remark().parse(file)', function (t) {
var tree = unified()
.data('micromarkExtensions', [gfmSyntax()])
.data('fromMarkdownExtensions', [gfm])
.use(parse)
.use(remarkParse)
.parse('* [x] contact@example.com ~~strikethrough~~')

remove(tree, true)
Expand Down
8 changes: 2 additions & 6 deletions packages/remark-stringify/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import toMarkdown from 'mdast-util-to-markdown'

module.exports = stringify

var toMarkdown = require('mdast-util-to-markdown')

function stringify(options) {
export default function remarkStringify(options) {
var self = this

this.Compiler = compile
Expand Down
9 changes: 5 additions & 4 deletions packages/remark-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Eugene Sharygin <eush77@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js",
"types/index.d.ts"
"index.js"
],
"types": "types/index.d.ts",
"dependencies": {
"mdast-util-to-markdown": "^0.6.0"
},
"scripts": {
"test": "tape test.js"
"test": "node --conditions development test.js"
},
"xo": false
}
Loading

0 comments on commit b7afd25

Please sign in to comment.