Skip to content

Commit 6621036

Browse files
committed
Stop using module.createRequire (problematic under webpack), replace resolveModule helper with corresponding (new) export from markdownlint.
1 parent 0ef65fc commit 6621036

6 files changed

+3
-133
lines changed

markdownlint-cli2.mjs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
// Imports
44
import fsNode from "node:fs";
5-
import { createRequire } from "node:module";
6-
const dynamicRequire = createRequire(import.meta.url);
75
import os from "node:os";
86
import pathDefault from "node:path";
97
const pathPosix = pathDefault.posix;
108
import { pathToFileURL } from "node:url";
119
import { globby } from "globby";
1210
import micromatch from "micromatch";
13-
import { applyFixes, getVersion } from "markdownlint";
11+
import { applyFixes, getVersion, resolveModule } from "markdownlint";
1412
import { lint, extendConfig, readConfig } from "markdownlint/promise";
1513
import { expandTildePath } from "markdownlint/helpers";
1614
import appendToArray from "./append-to-array.mjs";
1715
import mergeOptions from "./merge-options.mjs";
18-
import resolveModule from "./resolve-module.mjs";
1916
import parsers from "./parsers/parsers.mjs";
2017
import jsoncParse from "./parsers/jsonc-parse.mjs";
2118
import yamlParse from "./parsers/yaml-parse.mjs";
@@ -78,7 +75,7 @@ const importModule = async (dirOrDirs, id, noImport) => {
7875
let moduleName = null;
7976
try {
8077
try {
81-
moduleName = pathToFileURL(resolveModule(dynamicRequire, expandId, dirs));
78+
moduleName = pathToFileURL(resolveModule(expandId, dirs));
8279
} catch (error) {
8380
errors.push(error);
8481
moduleName =

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"playwright-test": "playwright test --config ./webworker/playwright.config.mjs",
4040
"playwright-test-docker": "docker run --rm --volume $PWD:/home/workdir --workdir /home/workdir --ipc=host mcr.microsoft.com/playwright:v1.49.1 npm run playwright-test",
4141
"schema": "cpy ./node_modules/markdownlint/schema/markdownlint-config-schema.json ./schema --flat",
42-
"test": "ava --timeout=1m test/append-to-array-test.mjs test/fs-mock-test.mjs test/fs-virtual-test.mjs test/markdownlint-cli2-test.mjs test/markdownlint-cli2-test-exec.mjs test/markdownlint-cli2-test-exports.mjs test/markdownlint-cli2-test-fs.mjs test/markdownlint-cli2-test-main.mjs test/merge-options-test.mjs test/resolve-module-test.mjs",
42+
"test": "ava --timeout=1m test/append-to-array-test.mjs test/fs-mock-test.mjs test/fs-virtual-test.mjs test/markdownlint-cli2-test.mjs test/markdownlint-cli2-test-exec.mjs test/markdownlint-cli2-test-exports.mjs test/markdownlint-cli2-test-fs.mjs test/markdownlint-cli2-test-main.mjs test/merge-options-test.mjs",
4343
"test-cover": "c8 --100 npm test",
4444
"test-docker-hub-image": "VERSION=$(node -e \"process.stdout.write(require('./package.json').version)\") && docker image rm davidanson/markdownlint-cli2:v$VERSION davidanson/markdownlint-cli2:latest || true && docker run --rm -v $PWD:/workdir davidanson/markdownlint-cli2:v$VERSION \"*.md\" && docker run --rm -v $PWD:/workdir davidanson/markdownlint-cli2:latest \"*.md\"",
4545
"test-docker-hub-image-rules": "VERSION=$(node -e \"process.stdout.write(require('./package.json').version)\") && docker image rm davidanson/markdownlint-cli2-rules:v$VERSION davidanson/markdownlint-cli2-rules:latest || true && docker run --rm -v $PWD:/workdir davidanson/markdownlint-cli2-rules:v$VERSION \"*.md\" && docker run --rm -v $PWD:/workdir davidanson/markdownlint-cli2-rules:latest \"*.md\"",
@@ -68,7 +68,6 @@
6868
"parsers/jsonc-parse.mjs",
6969
"parsers/yaml-parse.mjs",
7070
"README.md",
71-
"resolve-module.mjs",
7271
"schema/markdownlint-cli2-config-schema.json",
7372
"schema/markdownlint-config-schema.json",
7473
"schema/ValidatingConfiguration.md"

resolve-module.mjs

-16
This file was deleted.

test/resolve-module-test.mjs

-101
This file was deleted.

webworker/module-stub.cjs

-8
This file was deleted.

webworker/webpack.config.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ module.exports = {
5252
"fallback": {
5353
"buffer": false,
5454
"fs": false,
55-
"module": require.resolve("./module-stub.cjs"),
5655
"os": require.resolve("./os-stub.cjs"),
5756
"path": require.resolve("path-browserify"),
5857
"process": require.resolve("./process-stub.cjs"),

0 commit comments

Comments
 (0)