Skip to content

Commit

Permalink
Stop using module.createRequire (problematic under webpack), replace …
Browse files Browse the repository at this point in the history
…resolveModule helper with corresponding (new) export from markdownlint.
  • Loading branch information
DavidAnson committed Jan 15, 2025
1 parent 6a515c0 commit 28198d9
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 133 deletions.
7 changes: 2 additions & 5 deletions markdownlint-cli2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

// Imports
import fsNode from "node:fs";
import { createRequire } from "node:module";
const dynamicRequire = createRequire(import.meta.url);
import os from "node:os";
import pathDefault from "node:path";
const pathPosix = pathDefault.posix;
import { pathToFileURL } from "node:url";
import { globby } from "globby";
import micromatch from "micromatch";
import { applyFixes, getVersion } from "markdownlint";
import { applyFixes, getVersion, resolveModule } from "markdownlint";
import { lint, extendConfig, readConfig } from "markdownlint/promise";
import { expandTildePath } from "markdownlint/helpers";
import appendToArray from "./append-to-array.mjs";
import mergeOptions from "./merge-options.mjs";
import resolveModule from "./resolve-module.mjs";
import parsers from "./parsers/parsers.mjs";
import jsoncParse from "./parsers/jsonc-parse.mjs";
import yamlParse from "./parsers/yaml-parse.mjs";
Expand Down Expand Up @@ -78,7 +75,7 @@ const importModule = async (dirOrDirs, id, noImport) => {
let moduleName = null;
try {
try {
moduleName = pathToFileURL(resolveModule(dynamicRequire, expandId, dirs));
moduleName = pathToFileURL(resolveModule(expandId, dirs));
} catch (error) {
errors.push(error);
moduleName =
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"playwright-test": "playwright test --config ./webworker/playwright.config.mjs",
"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",
"schema": "cpy ./node_modules/markdownlint/schema/markdownlint-config-schema.json ./schema --flat",
"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",
"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-cover": "c8 --100 npm test",
"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\"",
"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\"",
Expand Down Expand Up @@ -68,7 +68,6 @@
"parsers/jsonc-parse.mjs",
"parsers/yaml-parse.mjs",
"README.md",
"resolve-module.mjs",
"schema/markdownlint-cli2-config-schema.json",
"schema/markdownlint-config-schema.json",
"schema/ValidatingConfiguration.md"
Expand Down
16 changes: 0 additions & 16 deletions resolve-module.mjs

This file was deleted.

101 changes: 0 additions & 101 deletions test/resolve-module-test.mjs

This file was deleted.

8 changes: 0 additions & 8 deletions webworker/module-stub.cjs

This file was deleted.

1 change: 0 additions & 1 deletion webworker/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module.exports = {
"fallback": {
"buffer": false,
"fs": false,
"module": require.resolve("./module-stub.cjs"),
"os": require.resolve("./os-stub.cjs"),
"path": require.resolve("path-browserify"),
"process": require.resolve("./process-stub.cjs"),
Expand Down

0 comments on commit 28198d9

Please sign in to comment.