diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0096d6..5423c45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: ['ubuntu-latest', 'windows-latest'] - node: ['12.0'] + node: ['12.17.0'] name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -43,7 +43,7 @@ jobs: strategy: matrix: os: ['ubuntu-latest', 'windows-latest'] - node: ['12.0', '14.0', '16.0'] + node: ['12.17.0', '14.0', '16.0'] name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index a353a36..08cddfa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ npm-debug.log* .nyc_output coverage.info test/fixtures/*/build +lib node_modules \ No newline at end of file diff --git a/README.md b/README.md index 1bdd0b7..2a24d81 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ yarn add @metalsmith/markdown ## Usage ```js -const markdown = require('@metalsmith/markdown') +import markdown from '@metalsmith/markdown' metalsmith.use( markdown({ @@ -111,8 +111,8 @@ would be transformed into: You can use a custom renderer by using `marked.Renderer()` ```js -const markdown = require('@metalsmith/markdown') -const marked = require('marked') +import markdown from '@metalsmith/markdown' +import { marked } from 'marked' const markdownRenderer = new marked.Renderer() markdownRenderer.image = function (href, title, text) { diff --git a/package.json b/package.json index 89244cc..025c9bd 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,14 @@ "maintainers": [ "Kevin Van Lierde (https://webketje.com)" ], - "main": "lib/index.js", + "source": "src/index.js", + "main": "lib/index.cjs", + "module": "lib/index.js", + "exports": { + "import": "./lib/index.js", + "require": "./lib/index.cjs" + }, + "type": "module", "files": [ "lib/*.js" ], @@ -36,8 +43,10 @@ "format:check": "prettier --list-different \"**/*.{yml,md,js,json}\"", "lint": "eslint --fix .", "lint:check": "eslint --fix-dry-run .", - "release": "release-it .", - "test": "nyc mocha" + "release": "npm run build && release-it .", + "build": "microbundle --target node --no-sourcemap -f cjs,esm", + "test": "nyc mocha", + "pretest": "npm run build" }, "dependencies": { "dlv": "^1.1.3", @@ -52,6 +61,7 @@ "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", "metalsmith": "^2.5.0", + "microbundle": "^0.15.1", "mocha": "^9.2.2", "nyc": "^15.1.0", "prettier": "^2.7.1", @@ -64,6 +74,6 @@ "access": "public" }, "engines": { - "node": ">=12" + "node": ">=12.17.0 <13.0.0-0||>=13.2.0" } } diff --git a/lib/expand-wildcard-keypath.js b/src/expand-wildcard-keypath.js similarity index 96% rename from lib/expand-wildcard-keypath.js rename to src/expand-wildcard-keypath.js index 7a5d84b..1f7bc18 100644 --- a/lib/expand-wildcard-keypath.js +++ b/src/expand-wildcard-keypath.js @@ -1,4 +1,4 @@ -const get = require('dlv') +import get from 'dlv' function error(name, msg) { const err = new Error(msg) @@ -63,4 +63,4 @@ function expandWildcardKeypath(root, keypaths, char) { return expanded } -module.exports = expandWildcardKeypath +export default expandWildcardKeypath diff --git a/lib/index.js b/src/index.js similarity index 87% rename from lib/index.js rename to src/index.js index 24c4c6d..0ca0772 100644 --- a/lib/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ -const { basename, dirname, extname, join } = require('path') -const get = require('dlv') -const set = require('dset').dset -const { marked } = require('marked') -const expandWildcardKeypaths = require('./expand-wildcard-keypath') +import { basename, dirname, extname, join } from 'path' +import get from 'dlv' +import { dset as set } from 'dset' +import { marked } from 'marked' +import expandWildcardKeypaths from './expand-wildcard-keypath.js' function render(data, key, options) { const value = get(data, key) @@ -72,4 +72,4 @@ function initMarkdown(options = defaultOptions) { } } -module.exports = initMarkdown +export default initMarkdown diff --git a/test/index.js b/test/index.cjs similarity index 96% rename from test/index.js rename to test/index.cjs index f35b145..2552636 100644 --- a/test/index.js +++ b/test/index.cjs @@ -5,7 +5,7 @@ const equal = require('assert-dir-equal') const Metalsmith = require('metalsmith') const { name } = require('../package.json') const markdown = require('..') -const expandWildcardKeypath = require('../lib/expand-wildcard-keypath') +let expandWildcardKeypath const path = require('path') function msCommon(dir) { @@ -13,6 +13,12 @@ function msCommon(dir) { } describe('@metalsmith/markdown', function () { + before(function (done) { + import('../src/expand-wildcard-keypath.js').then(imported => { + expandWildcardKeypath = imported + done() + }) + }) it('should export a named plugin function matching package.json name', function () { const namechars = name.split('/')[1] const camelCased = namechars.split('').reduce((str, char, i) => {