build: stop pre-compiling `lint-md`

PR-URL: https://github.com/nodejs/node/pull/55266
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Aviv Keller 2024-11-01 19:45:02 -04:00 committed by GitHub
parent 413975a580
commit 5ce3d1078d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 229 additions and 24600 deletions

View File

@ -22,3 +22,16 @@ updates:
applies-to: version-updates
patterns:
- '*'
- package-ecosystem: npm
directory: /tools/lint-md
schedule:
interval: monthly
commit-message:
prefix: tools
open-pull-requests-limit: 10
groups:
lint-md:
applies-to: version-updates
patterns:
- '*'

View File

@ -28,7 +28,6 @@ on:
- histogram
- icu
# - libuv
- lint-md-dependencies
- llhttp
- minimatch
- nbytes
@ -187,24 +186,6 @@ jobs:
# cat temp-output
# tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
# rm temp-output
- id: lint-md-dependencies
subsystem: tools
label: tools
run: |
cd tools/lint-md
npm ci
NEW_VERSION=$(npm outdated --parseable | cut -d: -f4 | xargs)
if [ "$NEW_VERSION" != "" ]; then
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
rm -rf package-lock.json node_modules
# Include $NEW_VERSION to explicitly update the package.json
# entry for the dependency and also so that semver-major updates
# are not skipped.
npm install --ignore-scripts $NEW_VERSION
npm install --ignore-scripts
cd ../..
make lint-md-rollup
fi
- id: llhttp
subsystem: deps
label: dependencies

1
.gitignore vendored
View File

@ -114,6 +114,7 @@ tools/*/*.i.tmp
/tools/doc/node_modules
/tools/clang-format/node_modules
/tools/eslint/node_modules
/tools/lint-md/node_modules
# === Rules for test artifacts ===
/*.tap

View File

@ -1335,21 +1335,6 @@ bench-addons-clean:
$(RM) -r benchmark/napi/*/build
$(RM) benchmark/napi/.buildstamp
.PHONY: lint-md-rollup
lint-md-rollup:
$(RM) tools/.*mdlintstamp
cd tools/lint-md && npm ci && npm run build
.PHONY: lint-md-clean
.NOTPARALLEL: lint-md-clean
lint-md-clean:
$(RM) -r tools/lint-md/node_modules
$(RM) tools/.*mdlintstamp
.PHONY: lint-md-build
lint-md-build:
$(warning Deprecated no-op target 'lint-md-build')
ifeq ("$(wildcard tools/.mdlintstamp)","")
LINT_MD_NEWER =
else
@ -1361,8 +1346,13 @@ LINT_MD_FILES = $(shell $(FIND) $(LINT_MD_TARGETS) -type f \
! -path '*node_modules*' ! -path 'test/fixtures/*' -name '*.md' \
$(LINT_MD_NEWER))
run-lint-md = tools/lint-md/lint-md.mjs $(LINT_MD_FILES)
# Check for a specific file, as (empty) directories are persisted in git.
tools/lint-md/node_modules/remark-parse/package.json:
-cd tools/lint-md && $(call available-node,$(run-npm-ci))
# Lint all changed markdown files maintained by us
tools/.mdlintstamp: $(LINT_MD_FILES)
tools/.mdlintstamp: tools/lint-md/node_modules/remark-parse/package.json $(LINT_MD_FILES)
$(info Running Markdown linter...)
@$(call available-node,$(run-lint-md))
@touch $@
@ -1372,7 +1362,7 @@ lint-md: lint-js-doc | tools/.mdlintstamp ## Lint the markdown documents maintai
run-format-md = tools/lint-md/lint-md.mjs --format $(LINT_MD_FILES)
.PHONY: format-md
format-md: ## Format the markdown documents maintained by us in the codebase.
format-md: tools/lint-md/node_modules/remark-parse/package.json ## Format the markdown documents maintained by us in the codebase.
@$(call available-node,$(run-format-md))
@ -1601,6 +1591,7 @@ lint-clean: ## Remove linting artifacts.
$(RM) tools/.*lintstamp
$(RM) .eslintcache
$(RM) -r tools/eslint/node_modules
$(RM) -r tools/lint-md/node_modules
$(RM) tools/pip/site_packages
HAS_DOCKER ?= $(shell command -v docker > /dev/null 2>&1; [ $$? -eq 0 ] && echo 1 || echo 0)

View File

@ -54,7 +54,6 @@ export default [
'test/message/esm_display_syntax_error.mjs',
'tools/github_reporter/**',
'tools/icu/**',
'tools/lint-md/lint-md.mjs',
],
},
// #endregion

View File

@ -1 +0,0 @@
node_modules

File diff suppressed because one or more lines are too long

View File

@ -1,53 +0,0 @@
import fs from 'fs';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import presetLintNode from 'remark-preset-lint-node';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
const paths = process.argv.slice(2);
if (!paths.length) {
console.error('Usage: lint-md.mjs <path> [<path> ...]');
process.exit(1);
}
let format = false;
if (paths[0] === '--format') {
paths.shift();
format = true;
}
const linter = unified()
.use(remarkParse)
.use(presetLintNode)
.use(remarkStringify);
paths.forEach(async (path) => {
const file = await read(path);
// We need to calculate `fileContents` before running `linter.process(files)`
// because `linter.process(files)` mutates `file` and returns it as `result`.
// So we won't be able to use `file` after that to see if its contents have
// changed as they will have been altered to the changed version.
const fileContents = file.toString();
const result = await linter.process(file);
const isDifferent = fileContents !== result.toString();
if (format) {
if (isDifferent) {
fs.writeFileSync(path, result.toString());
}
} else {
if (isDifferent) {
process.exitCode = 1;
const cmd = process.platform === 'win32' ? 'vcbuild' : 'make';
console.error(`${path} is not formatted. Please run '${cmd} format-md'.`);
}
if (result.messages.length) {
process.exitCode = 1;
console.error(reporter(result));
}
}
});

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,6 @@
"name": "lint-md",
"description": "markdown linting",
"version": "1.0.0",
"scripts": {
"build": "rollup -f es -p '@rollup/plugin-node-resolve={exportConditions: [\"node\"]}' -p @rollup/plugin-commonjs -p rollup-plugin-cleanup lint-md.src.mjs --file lint-md.mjs"
},
"dependencies": {
"remark-parse": "^11.0.0",
"remark-preset-lint-node": "^5.1.2",
@ -12,11 +9,5 @@
"to-vfile": "^8.0.0",
"unified": "^11.0.5",
"vfile-reporter": "^8.1.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"rollup": "^4.24.0",
"rollup-plugin-cleanup": "^3.2.1"
}
}

View File

@ -122,7 +122,6 @@ if /i "%1"=="lint-js-build" set lint_js_build=1&goto arg-ok
if /i "%1"=="lint-js-fix" set lint_js_fix=1&goto arg-ok
if /i "%1"=="jslint" set lint_js=1&echo Please use lint-js instead of jslint&goto arg-ok
if /i "%1"=="lint-md" set lint_md=1&goto arg-ok
if /i "%1"=="lint-md-build" set lint_md_build=1&goto arg-ok
if /i "%1"=="lint" set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok
if /i "%1"=="lint-ci" set lint_cpp=1&set lint_js_ci=1&goto arg-ok
if /i "%1"=="format-md" set format_md=1&goto arg-ok
@ -750,24 +749,21 @@ echo running lint-js
goto lint-js-fix
:lint-js-fix
if not defined lint_js_fix goto lint-md-build
if not defined lint_js_fix goto lint-md
if not exist tools\eslint\node_modules\eslint goto no-lint
echo running lint-js-fix
%node_exe% tools\eslint\node_modules\eslint\bin\eslint.js --cache --max-warnings=0 --report-unused-disable-directives --rule "@stylistic/js/linebreak-style: 0" eslint.config.mjs benchmark doc lib test tools --fix
goto lint-md-build
:no-lint
echo Linting is not available through the source tarball.
echo Use the git repo instead: $ git clone https://github.com/nodejs/node.git
goto lint-md-build
:lint-md-build
if not defined lint_md_build goto lint-md
echo "Deprecated no-op target 'lint_md_build'"
goto lint-md
if not defined lint_md if not defined format_md goto lint-md
cd tools\lint-md
%npm_exe% ci
cd ..\..
:lint-md
if not defined lint_md goto format-md
if not exist tools\lint-md\node_modules goto no-lint
echo Running Markdown linter on docs...
SETLOCAL ENABLEDELAYEDEXPANSION
set lint_md_files=
@ -782,6 +778,7 @@ goto format-md
:format-md
if not defined format_md goto exit
if not exist tools\lint-md\node_modules goto no-lint
echo Running Markdown formatter on docs...
SETLOCAL ENABLEDELAYEDEXPANSION
set lint_md_files=
@ -792,6 +789,10 @@ for /D %%D IN (doc\*) do (
)
%node_exe% tools\lint-md\lint-md.mjs --format %lint_md_files%
ENDLOCAL
:no-lint
echo Linting is not available through the source tarball.
echo Use the git repo instead: $ git clone https://github.com/nodejs/node.git
goto exit
:create-msvs-files-failed