diff --git a/markdownlint-cli2.js b/markdownlint-cli2.js index 18060a8d..ded56451 100755 --- a/markdownlint-cli2.js +++ b/markdownlint-cli2.js @@ -98,10 +98,12 @@ const importOrRequireResolve = async (dirOrDirs, id, noRequire) => { errors.push(error); } try { - const fileUrlString = - pathToFileURL(pathDefault.resolve(dirs[0], expandId)).toString(); + const isURL = !pathDefault.isAbsolute(expandId) && URL.canParse(expandId); + const urlString = ( + isURL ? new URL(expandId) : pathToFileURL(pathDefault.resolve(dirs[0], expandId)) + ).toString(); // eslint-disable-next-line no-inline-comments - const module = await import(/* webpackIgnore: true */ fileUrlString); + const module = await import(/* webpackIgnore: true */ urlString); return module.default; } catch (error) { errors.push(error); diff --git a/test/customRules/dir4/.markdownlint-cli2.mjs b/test/customRules/dir4/.markdownlint-cli2.mjs new file mode 100644 index 00000000..524f8fef --- /dev/null +++ b/test/customRules/dir4/.markdownlint-cli2.mjs @@ -0,0 +1,15 @@ +// @ts-check + +import { sep as sepDefault } from "node:path"; +import { sep as sepPosix } from "node:path/posix"; + +const options = { + "customRules": [ + (new URL( + "../node_modules/markdownlint-rule-sample-module/sample-rule.mjs", + import.meta.url + )).toString() + ] +}; + +export default options; diff --git a/test/customRules/dir4/hr.md b/test/customRules/dir4/hr.md new file mode 100644 index 00000000..7a141621 --- /dev/null +++ b/test/customRules/dir4/hr.md @@ -0,0 +1,3 @@ +# hr + +--- diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.md b/test/snapshots/markdownlint-cli2-test-exec.js.md index 6113a23d..c24fe0f1 100644 --- a/test/snapshots/markdownlint-cli2-test-exec.js.md +++ b/test/snapshots/markdownlint-cli2-test-exec.js.md @@ -2835,6 +2835,7 @@ Generated by [AVA](https://avajs.dev). dir3/hr.md:3 every-n-lines Rule that reports an error every N lines [Line number 3]␊ dir3/hr.md:3 sample-rule-commonjs Sample rule (commonjs) [Sample error for hr]␊ dir3/hr.md:3 sample-rule-module Sample rule (module) [Sample error for hr]␊ + dir4/hr.md:3 sample-rule-module Sample rule (module) [Sample error for hr]␊ viewme.md:1 first-line Rule that reports an error for the first line␊ viewme.md:3 any-blockquote Rule that reports an error for any blockquote [Blockquote spans 1 line(s).] [Context: "> Tagli"]␊ viewme.md:3 every-n-lines Rule that reports an error every N lines [Line number 3]␊ @@ -2849,8 +2850,8 @@ Generated by [AVA](https://avajs.dev). `, stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ Finding: **/*.md␊ - Linting: 8 file(s)␊ - Summary: 46 error(s)␊ + Linting: 9 file(s)␊ + Summary: 47 error(s)␊ `, } diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.snap b/test/snapshots/markdownlint-cli2-test-exec.js.snap index 4a21066b..ad3f1d97 100644 Binary files a/test/snapshots/markdownlint-cli2-test-exec.js.snap and b/test/snapshots/markdownlint-cli2-test-exec.js.snap differ diff --git a/test/snapshots/markdownlint-cli2-test-fs.js.md b/test/snapshots/markdownlint-cli2-test-fs.js.md index 346a002c..ef0733a2 100644 --- a/test/snapshots/markdownlint-cli2-test-fs.js.md +++ b/test/snapshots/markdownlint-cli2-test-fs.js.md @@ -2245,7 +2245,7 @@ Generated by [AVA](https://avajs.dev). `, stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ Finding: **/*.md␊ - Linting: 8 file(s)␊ + Linting: 9 file(s)␊ Summary: 23 error(s)␊ `, } diff --git a/test/snapshots/markdownlint-cli2-test-fs.js.snap b/test/snapshots/markdownlint-cli2-test-fs.js.snap index 8152d7ca..91932d1b 100644 Binary files a/test/snapshots/markdownlint-cli2-test-fs.js.snap and b/test/snapshots/markdownlint-cli2-test-fs.js.snap differ diff --git a/test/snapshots/markdownlint-cli2-test-main.js.md b/test/snapshots/markdownlint-cli2-test-main.js.md index 22cb9587..9dd484b5 100644 --- a/test/snapshots/markdownlint-cli2-test-main.js.md +++ b/test/snapshots/markdownlint-cli2-test-main.js.md @@ -2835,6 +2835,7 @@ Generated by [AVA](https://avajs.dev). dir3/hr.md:3 every-n-lines Rule that reports an error every N lines [Line number 3]␊ dir3/hr.md:3 sample-rule-commonjs Sample rule (commonjs) [Sample error for hr]␊ dir3/hr.md:3 sample-rule-module Sample rule (module) [Sample error for hr]␊ + dir4/hr.md:3 sample-rule-module Sample rule (module) [Sample error for hr]␊ viewme.md:1 first-line Rule that reports an error for the first line␊ viewme.md:3 any-blockquote Rule that reports an error for any blockquote [Blockquote spans 1 line(s).] [Context: "> Tagli"]␊ viewme.md:3 every-n-lines Rule that reports an error every N lines [Line number 3]␊ @@ -2849,8 +2850,8 @@ Generated by [AVA](https://avajs.dev). `, stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ Finding: **/*.md␊ - Linting: 8 file(s)␊ - Summary: 46 error(s)␊ + Linting: 9 file(s)␊ + Summary: 47 error(s)␊ `, } @@ -5224,7 +5225,7 @@ Generated by [AVA](https://avajs.dev). `, stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ Finding: **/*.md␊ - Linting: 8 file(s)␊ + Linting: 9 file(s)␊ Summary: 23 error(s)␊ `, } diff --git a/test/snapshots/markdownlint-cli2-test-main.js.snap b/test/snapshots/markdownlint-cli2-test-main.js.snap index e88fcf08..8352f63e 100644 Binary files a/test/snapshots/markdownlint-cli2-test-main.js.snap and b/test/snapshots/markdownlint-cli2-test-main.js.snap differ