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 14, 2025
1 parent 5e1fbe9 commit 44c19e8
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 135 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
5 changes: 2 additions & 3 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 All @@ -77,7 +76,7 @@
"globby": "14.0.2",
"js-yaml": "4.1.0",
"jsonc-parser": "3.3.1",
"markdownlint": "0.37.3",
"markdownlint": "DavidAnson/markdownlint#vsc",
"markdownlint-cli2-formatter-default": "0.0.5",
"micromatch": "4.0.8"
},
Expand Down
16 changes: 0 additions & 16 deletions resolve-module.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion test/markdownlint-cli2-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test("validateMarkdownlintConfigSchema", async (t) => {
const validateConfigSchema = ajv.compile(markdownlintConfigSchemaDefinition);
t.is(
markdownlintConfigSchemaDefinition.$id.replace(schemaIdVersionRe, "$<version>"),
packageJson.dependencies.markdownlint
"0.37.3"
);
t.is(
markdownlintConfigSchemaDefinition.$id,
Expand Down
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 44c19e8

Please sign in to comment.