Use webpack to create a CommonJS module from micromark's ESM implementation, convert to using that.

This commit is contained in:
David Anson 2023-01-14 15:05:04 -08:00
parent 5038f6e154
commit bb0aa012b5
6 changed files with 57 additions and 5 deletions

View file

@ -15,6 +15,8 @@
"demo/markdownlint-browser.js",
"demo/markdownlint-browser.min.js",
"example/typescript/type-check.js",
"micromark/micromark.js",
"micromark/micromark.dev.js",
"test-repos/"
],
"overrides": [

View file

@ -1,8 +1,12 @@
// @ts-check
/* eslint-disable n/no-unpublished-import */
import assert from "node:assert/strict";
// eslint-disable-next-line n/no-unpublished-import
import { parse, postprocess, preprocess } from "../micromark/exports.mjs";
// @ts-ignore
import micromark from "../micromark/micromark.js";
// @ts-ignore
const { parse, postprocess, preprocess } = micromark;
/**
* Markdown token.

3
micromark/.npmignore Normal file
View file

@ -0,0 +1,3 @@
exports.mjs
micromark.dev.js
webpack.config.js

View file

@ -2,7 +2,8 @@
"name": "markdownlint-micromark",
"version": "0.1.0",
"description": "A trivial package that re-exports some micromark functionality as a CommonJS module",
"exports": "./exports.mjs",
"type": "commonjs",
"exports": "./micromark.js",
"author": "David Anson (https://dlaa.me/)",
"license": "MIT",
"homepage": "https://github.com/DavidAnson/markdownlint",
@ -11,10 +12,17 @@
"url": "https://github.com/DavidAnson/markdownlint.git"
},
"bugs": "https://github.com/DavidAnson/markdownlint/issues",
"scripts": {
"build": "webpack --no-stats"
},
"engines": {
"node": ">=14.18.0"
},
"dependencies": {
"micromark": "3.1.0"
},
"devDependencies": {
"webpack": "5.75.0",
"webpack-cli": "5.0.1"
}
}

View file

@ -0,0 +1,34 @@
// @ts-check
"use strict";
const shared = {
"entry": "./exports.mjs",
"output": {
"library": {
"type": "commonjs"
},
"path": __dirname
},
"target": "node"
};
module.exports = [
{
...shared,
"mode": "production",
"output": {
...shared.output,
"filename": "micromark.js"
}
},
{
...shared,
"devtool": false,
"mode": "development",
"output": {
...shared.output,
"filename": "micromark.dev.js"
}
}
];

View file

@ -29,7 +29,8 @@
"build-demo": "node scripts copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && cd demo && webpack --no-stats",
"build-docs": "node doc-build/build-rules.mjs",
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
"ci": "npm-run-all --continue-on-error --parallel lint serial-config-docs serial-declaration-demo test-cover && git diff --exit-code",
"build-micromark": "cd micromark && npm run build",
"ci": "npm run build-micromark && npm-run-all --continue-on-error --parallel lint serial-config-docs serial-declaration-demo test-cover && git diff --exit-code",
"clone-test-repos-apache-airflow": "cd test-repos && git clone https://github.com/apache/airflow apache-airflow --depth 1 --no-tags --quiet",
"clone-test-repos-dotnet-docs": "cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet",
"clone-test-repos-electron-electron": "cd test-repos && git clone https://github.com/electron/electron electron-electron --depth 1 --no-tags --quiet",
@ -52,7 +53,7 @@
"serial-config-docs": "npm run build-config && npm run build-docs",
"serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration",
"test": "ava test/markdownlint-test.js test/markdownlint-test-config.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-micromark.mjs test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js",
"test-cover": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test",
"test-cover": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --exclude 'test/**' --exclude 'micromark/**' npm test",
"test-declaration": "cd example/typescript && tsc && node type-check.js",
"test-extra": "ava --timeout=5m test/markdownlint-test-extra-parse.js test/markdownlint-test-extra-type.js",
"update-snapshots": "ava --update-snapshots test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.js",