Skip to content

Commit b7afd25

Browse files
committedAug 3, 2021
Use ESM
1 parent 16baa4f commit b7afd25

File tree

16 files changed

+122
-129
lines changed

16 files changed

+122
-129
lines changed
 

‎package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"type": "opencollective",
1010
"url": "https://opencollective.com/unified"
1111
},
12+
"type": "module",
1213
"devDependencies": {
1314
"c8": "^7.0.0",
1415
"camelcase": "^6.0.0",
@@ -29,8 +30,7 @@
2930
"scripts": {
3031
"postinstall": "lerna bootstrap --no-ci",
3132
"format": "./packages/remark-cli/cli.js . -qfo && prettier . -w --loglevel warn && xo --fix",
32-
"test-api": "tape \"packages/*/test.js\" \"test/index.js\"",
33-
"test-api": "node --conditions development test/index.js",
33+
"test-api": "node --conditions development test/index.js && lerna run test",
3434
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
3535
"test": "npm run format && npm run test-coverage"
3636
},
@@ -44,8 +44,10 @@
4444
},
4545
"xo": {
4646
"prettier": true,
47-
"esnext": false,
48-
"rules": {},
47+
"rules": {
48+
"no-var": "off",
49+
"prefer-arrow-callback": "off"
50+
},
4951
"ignores": [
5052
"**/types"
5153
]

‎packages/remark-cli/cli.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
#!/usr/bin/env node
2-
'use strict'
2+
import {createRequire} from 'node:module'
3+
import start from 'unified-args'
4+
import {remark} from 'remark'
35

4-
var start = require('unified-args')
5-
var extensions = require('markdown-extensions')
6-
var processor = require('remark')
7-
var proc = require('remark/package.json')
8-
var cli = require('./package.json')
6+
const require = createRequire(import.meta.url)
7+
8+
const proc = require('remark/package.json')
9+
const cli = require('./package.json')
10+
11+
// To do: enable `markdown-extensions` once it supports ESM.
12+
const extensions = [
13+
'md',
14+
'markdown',
15+
'mdown',
16+
'mkdn',
17+
'mkd',
18+
'mdwn',
19+
'mkdown',
20+
'ron'
21+
]
922

1023
start({
11-
processor: processor,
24+
processor: remark,
1225
name: proc.name,
1326
description: cli.description,
1427
version: [
@@ -20,5 +33,5 @@ start({
2033
packageField: proc.name + 'Config',
2134
rcName: '.' + proc.name + 'rc',
2235
ignoreName: '.' + proc.name + 'ignore',
23-
extensions: extensions
36+
extensions
2437
})

‎packages/remark-cli/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222
"contributors": [
2323
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2424
],
25+
"type": "module",
26+
"main": "index.js",
2527
"bin": {
2628
"remark": "cli.js"
2729
},
2830
"files": [
2931
"cli.js"
3032
],
3133
"dependencies": {
32-
"markdown-extensions": "^1.1.0",
3334
"remark": "^13.0.0",
3435
"unified-args": "^8.0.0"
3536
},
3637
"scripts": {
37-
"test": "tape test.js"
38+
"test": "node --conditions development test.js"
3839
},
3940
"xo": false
4041
}

‎packages/remark-cli/test.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
'use strict'
2-
3-
var path = require('path')
4-
var execa = require('execa')
5-
var test = require('tape')
6-
7-
var join = path.join
1+
import url from 'url'
2+
import execa from 'execa'
3+
import test from 'tape'
84

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

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

1511
st.plan(1)
1612

@@ -67,7 +63,7 @@ test('remark-cli', function (t) {
6763
})
6864

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

7268
st.plan(2)
7369

‎packages/remark-parse/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
'use strict'
1+
import fromMarkdown from 'mdast-util-from-markdown'
22

3-
module.exports = parse
4-
5-
var fromMarkdown = require('mdast-util-from-markdown')
6-
7-
function parse(options) {
3+
export default function remarkParse(options) {
84
var self = this
95

106
this.Parser = parse

‎packages/remark-parse/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"ast",
1717
"parse"
1818
],
19-
"types": "types/index.d.ts",
2019
"homepage": "https://remark.js.org",
2120
"repository": "https://github.com/remarkjs/remark/tree/main/packages/remark-parse",
2221
"bugs": "https://github.com/remarkjs/remark/issues",
@@ -32,15 +31,17 @@
3231
"Elijah Hamovitz <elijahhamovitz@gmail.com>",
3332
"Ika <ikatyang@gmail.com>"
3433
],
34+
"sideEffects": false,
35+
"type": "module",
36+
"main": "index.js",
3537
"files": [
36-
"index.js",
37-
"types/index.d.ts"
38+
"index.js"
3839
],
3940
"dependencies": {
4041
"mdast-util-from-markdown": "^0.8.0"
4142
},
4243
"scripts": {
43-
"test": "tape test.js"
44+
"test": "node --conditions development test.js"
4445
},
4546
"xo": false
4647
}

‎packages/remark-parse/test.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
'use strict'
1+
import test from 'tape'
2+
import unified from 'unified'
3+
import gfmSyntax from 'micromark-extension-gfm'
4+
import gfm from 'mdast-util-gfm/from-markdown.js'
5+
import remove from 'unist-util-remove-position'
6+
import remarkParse from './index.js'
27

3-
var test = require('tape')
4-
var unified = require('unified')
5-
var gfmSyntax = require('micromark-extension-gfm')
6-
var gfm = require('mdast-util-gfm/from-markdown')
7-
var remove = require('unist-util-remove-position')
8-
9-
var parse = require('.')
10-
11-
test('remark().parse(file)', function (t) {
8+
test('remarkParse', function (t) {
129
t.equal(
13-
unified().use(parse).parse('Alfred').children.length,
10+
unified().use(remarkParse).parse('Alfred').children.length,
1411
1,
1512
'should accept a `string`'
1613
)
@@ -19,7 +16,7 @@ test('remark().parse(file)', function (t) {
1916
var tree = unified()
2017
.data('micromarkExtensions', [gfmSyntax()])
2118
.data('fromMarkdownExtensions', [gfm])
22-
.use(parse)
19+
.use(remarkParse)
2320
.parse('* [x] contact@example.com ~~strikethrough~~')
2421

2522
remove(tree, true)

‎packages/remark-stringify/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
'use strict'
1+
import toMarkdown from 'mdast-util-to-markdown'
22

3-
module.exports = stringify
4-
5-
var toMarkdown = require('mdast-util-to-markdown')
6-
7-
function stringify(options) {
3+
export default function remarkStringify(options) {
84
var self = this
95

106
this.Compiler = compile

‎packages/remark-stringify/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
3232
"Eugene Sharygin <eush77@gmail.com>"
3333
],
34+
"sideEffects": false,
35+
"type": "module",
36+
"main": "index.js",
3437
"files": [
35-
"index.js",
36-
"types/index.d.ts"
38+
"index.js"
3739
],
38-
"types": "types/index.d.ts",
3940
"dependencies": {
4041
"mdast-util-to-markdown": "^0.6.0"
4142
},
4243
"scripts": {
43-
"test": "tape test.js"
44+
"test": "node --conditions development test.js"
4445
},
4546
"xo": false
4647
}

‎packages/remark-stringify/test.js

+31-34
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
'use strict'
1+
import test from 'tape'
2+
import unified from 'unified'
3+
import parse from '../remark-parse/index.js'
4+
import gfm from 'mdast-util-gfm/to-markdown.js'
5+
import remarkStringify from './index.js'
26

3-
var test = require('tape')
4-
var unified = require('unified')
5-
var parse = require('../remark-parse/index.js')
6-
var gfm = require('mdast-util-gfm/to-markdown')
7-
8-
var stringify = require('.')
9-
10-
test('remark().stringify(ast, file)', function (t) {
7+
test('remarkStringify', function (t) {
118
t.equal(
129
unified()
13-
.use(stringify)
10+
.use(remarkStringify)
1411
.stringify({
1512
type: 'root',
1613
children: [{type: 'html', value: '<!-- last line\n'}]
@@ -22,15 +19,15 @@ test('remark().stringify(ast, file)', function (t) {
2219

2320
t.throws(
2421
function () {
25-
unified().use(stringify).stringify(false)
22+
unified().use(remarkStringify).stringify(false)
2623
},
2724
/false/,
2825
'should throw when `ast` is not an object'
2926
)
3027

3128
t.throws(
3229
function () {
33-
unified().use(stringify).stringify({type: 'unicorn'})
30+
unified().use(remarkStringify).stringify({type: 'unicorn'})
3431
},
3532
/unicorn/,
3633
'should throw when `ast` is not a valid node'
@@ -39,7 +36,7 @@ test('remark().stringify(ast, file)', function (t) {
3936
t.throws(
4037
function () {
4138
unified()
42-
.use(stringify)
39+
.use(remarkStringify)
4340
.data('settings', {bullet: true})
4441
.stringify({type: 'listItem'})
4542
},
@@ -50,7 +47,7 @@ test('remark().stringify(ast, file)', function (t) {
5047
t.throws(
5148
function () {
5249
unified()
53-
.use(stringify)
50+
.use(remarkStringify)
5451
.data('settings', {listItemIndent: 'foo'})
5552
.stringify({type: 'listItem'})
5653
},
@@ -61,7 +58,7 @@ test('remark().stringify(ast, file)', function (t) {
6158
t.throws(
6259
function () {
6360
unified()
64-
.use(stringify)
61+
.use(remarkStringify)
6562
.data('settings', {rule: true})
6663
.stringify({type: 'thematicBreak'})
6764
},
@@ -72,7 +69,7 @@ test('remark().stringify(ast, file)', function (t) {
7269
t.throws(
7370
function () {
7471
unified()
75-
.use(stringify)
72+
.use(remarkStringify)
7673
.data('settings', {ruleRepetition: 1})
7774
.stringify({type: 'thematicBreak'})
7875
},
@@ -83,7 +80,7 @@ test('remark().stringify(ast, file)', function (t) {
8380
t.throws(
8481
function () {
8582
unified()
86-
.use(stringify)
83+
.use(remarkStringify)
8784
.data('settings', {ruleRepetition: true})
8885
.stringify({type: 'thematicBreak'})
8986
},
@@ -94,7 +91,7 @@ test('remark().stringify(ast, file)', function (t) {
9491
t.throws(
9592
function () {
9693
unified()
97-
.use(stringify)
94+
.use(remarkStringify)
9895
.data('settings', {emphasis: '-'})
9996
.stringify({type: 'emphasis'})
10097
},
@@ -105,7 +102,7 @@ test('remark().stringify(ast, file)', function (t) {
105102
t.throws(
106103
function () {
107104
unified()
108-
.use(stringify)
105+
.use(remarkStringify)
109106
.data('settings', {strong: '-'})
110107
.stringify({type: 'strong'})
111108
},
@@ -116,7 +113,7 @@ test('remark().stringify(ast, file)', function (t) {
116113
t.throws(
117114
function () {
118115
unified()
119-
.use(stringify)
116+
.use(remarkStringify)
120117
.data('settings', {fence: '-'})
121118
.stringify({type: 'code'})
122119
},
@@ -253,7 +250,7 @@ test('remark().stringify(ast, file)', function (t) {
253250
st.end()
254251

255252
function toString(value) {
256-
return String(unified().use(stringify).stringify(value))
253+
return String(unified().use(remarkStringify).stringify(value))
257254
}
258255
})
259256

@@ -269,27 +266,27 @@ test('remark().stringify(ast, file)', function (t) {
269266
]
270267

271268
st.equal(
272-
toString({type: 'listItem', children: children}),
269+
toString({type: 'listItem', children}),
273270
'* alpha\n\n > bravo\n',
274271
'no spread'
275272
)
276273

277274
st.equal(
278-
toString({type: 'listItem', spread: true, children: children}),
275+
toString({type: 'listItem', spread: true, children}),
279276
'* alpha\n\n > bravo\n',
280277
'spread: true'
281278
)
282279

283280
st.equal(
284-
toString({type: 'listItem', spread: false, children: children}),
281+
toString({type: 'listItem', spread: false, children}),
285282
'* alpha\n > bravo\n',
286283
'spread: false'
287284
)
288285

289286
st.end()
290287

291288
function toString(value) {
292-
return String(unified().use(stringify).stringify(value))
289+
return String(unified().use(remarkStringify).stringify(value))
293290
}
294291
})
295292

@@ -299,7 +296,7 @@ test('remark().stringify(ast, file)', function (t) {
299296
st.end()
300297

301298
function toString(value) {
302-
return String(unified().use(stringify).stringify(value))
299+
return String(unified().use(remarkStringify).stringify(value))
303300
}
304301
})
305302

@@ -318,7 +315,7 @@ test('remark().stringify(ast, file)', function (t) {
318315
st.equal(
319316
unified()
320317
.use(parse)
321-
.use(stringify)
318+
.use(remarkStringify)
322319
.processSync(test[1] + '\n\n[bravo]: #\n')
323320
.toString(),
324321
test[1] + '\n\n[bravo]: #\n',
@@ -355,7 +352,7 @@ test('remark().stringify(ast, file)', function (t) {
355352
st.end()
356353

357354
function toString(value) {
358-
return String(unified().use(stringify).stringify(value))
355+
return String(unified().use(remarkStringify).stringify(value))
359356
}
360357
})
361358

@@ -364,21 +361,21 @@ test('remark().stringify(ast, file)', function (t) {
364361

365362
var example = '[example@foo.com](mailto:example@foo.com)'
366363
st.equal(
367-
unified().use(parse).use(stringify).processSync(example).toString(),
364+
unified().use(parse).use(remarkStringify).processSync(example).toString(),
368365
'<example@foo.com>\n',
369366
'url is `mailto:` plus link text'
370367
)
371368

372369
example = '[mailto:example@foo.com](mailto:example@foo.com)'
373370
st.equal(
374-
unified().use(parse).use(stringify).processSync(example).toString(),
371+
unified().use(parse).use(remarkStringify).processSync(example).toString(),
375372
'<mailto:example@foo.com>\n',
376373
'url is link text'
377374
)
378375

379376
example = '[example](mailto:example@foo.com)\n'
380377
st.equal(
381-
unified().use(parse).use(stringify).processSync(example).toString(),
378+
unified().use(parse).use(remarkStringify).processSync(example).toString(),
382379
example,
383380
'url is not link text'
384381
)
@@ -460,7 +457,7 @@ test('stringify escapes', function (t) {
460457
test('extensions', function (t) {
461458
var doc = unified()
462459
.data('toMarkdownExtensions', [gfm()])
463-
.use(stringify)
460+
.use(remarkStringify)
464461
.stringify({
465462
type: 'root',
466463
children: [
@@ -596,8 +593,8 @@ test('extensions', function (t) {
596593
function toString(value, options) {
597594
var tree =
598595
typeof value === 'string'
599-
? {type: 'paragraph', children: [{type: 'text', value: value}]}
596+
? {type: 'paragraph', children: [{type: 'text', value}]}
600597
: value
601598

602-
return unified().use(stringify, options).stringify(tree)
599+
return unified().use(remarkStringify, options).stringify(tree)
603600
}

‎packages/remark/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict'
1+
import unified from 'unified'
2+
import remarkParse from 'remark-parse'
3+
import remarkStringify from 'remark-stringify'
24

3-
var unified = require('unified')
4-
var parse = require('remark-parse')
5-
var stringify = require('remark-stringify')
6-
7-
module.exports = unified().use(parse).use(stringify).freeze()
5+
export const remark = unified().use(remarkParse).use(remarkStringify).freeze()

‎packages/remark/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
"contributors": [
3030
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
3131
],
32+
"sideEffects": false,
33+
"type": "module",
34+
"main": "index.js",
3235
"files": [
33-
"index.js",
34-
"types/index.d.ts"
36+
"index.js"
3537
],
36-
"types": "types/index.d.ts",
3738
"dependencies": {
3839
"remark-parse": "^9.0.0",
3940
"remark-stringify": "^9.0.0",
4041
"unified": "^9.1.0"
4142
},
4243
"scripts": {
43-
"test": "tape test.js"
44+
"test": "node --conditions development test.js"
4445
},
4546
"xo": false
4647
}

‎packages/remark/test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
1+
import test from 'tape'
2+
import {remark} from './index.js'
23

3-
var test = require('tape')
4-
var remark = require('.')
5-
6-
test('remark().processSync(value)', function (t) {
4+
test('remark', function (t) {
75
t.equal(
86
remark().processSync('*foo*').toString(),
97
'*foo*\n',

‎script/regenerate-fixtures.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
var fs = require('fs')
4-
var path = require('path')
5-
var remark = require('../packages/remark/index.js')
6-
var fixtures = require('../test/fixtures/index.js')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import remark from '../packages/remark/index.js'
4+
import fixtures from '../test/fixtures/index.js'
75

86
var base = path.join('test', 'fixtures', 'tree')
97
var generated = []

‎test/fixtures/index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
var fs = require('fs')
4-
var path = require('path')
5-
var camelcase = require('camelcase')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import camelcase from 'camelcase'
64

75
// See <https://github.com/syntax-tree/mdast-util-to-markdown#formatting-options>
86
var defaults = {
@@ -22,16 +20,18 @@ var defaults = {
2220
tightDefinitions: false
2321
}
2422

25-
module.exports = fs
26-
.readdirSync(path.join(__dirname, 'input'))
23+
export const fixtures = fs
24+
.readdirSync(path.join('test', 'fixtures', 'input'))
2725
.filter(function (filepath) {
2826
return filepath.indexOf('.') !== 0
2927
})
3028
.map(function (basename) {
3129
var stem = path.basename(basename, path.extname(basename))
3230
var settings = parseOptions(stem.replace(/-asterisk-/g, '*'))
33-
var input = String(fs.readFileSync(path.join(__dirname, 'input', basename)))
34-
var treePath = path.join(__dirname, 'tree', stem + '.json')
31+
var input = String(
32+
fs.readFileSync(path.join('test', 'fixtures', 'input', basename))
33+
)
34+
var treePath = path.join('test', 'fixtures', 'tree', stem + '.json')
3535
var tree
3636

3737
if (fs.existsSync(treePath)) {
@@ -40,8 +40,8 @@ module.exports = fs
4040

4141
return {
4242
name: basename,
43-
input: input,
44-
tree: tree,
43+
input,
44+
tree,
4545
stringify: settings.stringify,
4646
output: settings.output
4747
}
@@ -90,5 +90,5 @@ function augment(key, value) {
9090
value = Number(value)
9191
}
9292

93-
return {key: key, value: value}
93+
return {key, value}
9494
}

‎test/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var remove = require('unist-util-remove-position')
5-
var mdast = require('mdast-util-assert')
6-
var remark = require('../packages/remark/index.js')
7-
var fixtures = require('./fixtures/index.js')
1+
import test from 'tape'
2+
import remove from 'unist-util-remove-position'
3+
import mdast from 'mdast-util-assert'
4+
import {remark} from '../packages/remark/index.js'
5+
import {fixtures} from './fixtures/index.js'
86

97
test('fixtures', function (t) {
108
var index = -1

0 commit comments

Comments
 (0)
Please sign in to comment.