mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
38
test/esm-helpers.mjs
Normal file
38
test/esm-helpers.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// @ts-check
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
/**
|
||||
* Gets the file name of the current module.
|
||||
* Shims import.meta.filename for Node 18.
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @returns {string} File name.
|
||||
*/
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
export const __filename = (meta) => fileURLToPath(meta.url);
|
||||
|
||||
/**
|
||||
* Gets the directory name of the current module.
|
||||
* Shims import.meta.dirname for Node 18.
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @returns {string} Directory name.
|
||||
*/
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
export const __dirname = (meta) => path.dirname(__filename(meta));
|
||||
|
||||
/**
|
||||
* Imports a file as JSON.
|
||||
* Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time".
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @param {string} file JSON file to import.
|
||||
* @returns {Promise<Object>} JSON object.
|
||||
*/
|
||||
export const importWithTypeJson = async(meta, file) => (
|
||||
// @ts-ignore
|
||||
JSON.parse(await fs.readFile(path.resolve(__dirname(meta), file)))
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue