-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: compute list of expected globals from ESLint config file #42056
base: main
Are you sure you want to change the base?
Changes from 7 commits
fbb89f2
9a5ec5f
48e859d
afdec40
5f9d376
76b5491
f1cb9bf
ef7dd44
8d54abb
d85d9b8
0446006
c11b45d
642a1ad
945c835
9f4470d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ testclean: | |
# Next one is legacy remove this at some point | ||
$(RM) -r test/tmp* | ||
$(RM) -r test/.tmp* | ||
$(RM) -d test/common/knownGlobals.json | ||
|
||
.PHONY: distclean | ||
.NOTPARALLEL: distclean | ||
|
@@ -280,8 +281,11 @@ v8: | |
export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ | ||
tools/make-v8.sh $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS) | ||
|
||
test/common/knownGlobals.json: test/common/parseEslintConfigForKnownGlobals.js lib/.eslintrc.yaml | ||
$(NODE) $< > $@ | ||
|
||
.PHONY: jstest | ||
jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addon tests and JS tests | ||
jstest: build-addons build-js-native-api-tests build-node-api-tests test/common/knownGlobals.json ## Runs addon tests and JS tests | ||
$(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ | ||
$(TEST_CI_ARGS) \ | ||
--skip-tests=$(CI_SKIP_TESTS) \ | ||
|
@@ -606,7 +610,7 @@ test-doc: doc-only lint-md ## Builds, lints, and verifies the docs. | |
fi | ||
|
||
.PHONY: test-doc-ci | ||
test-doc-ci: doc-only | ||
test-doc-ci: doc-only test/common/knownGlobals.json | ||
$(PYTHON) tools/test.py --shell $(NODE) $(TEST_CI_ARGS) $(PARALLEL_ARGS) doctool | ||
|
||
.PHONY: test-known-issues | ||
|
@@ -1136,7 +1140,7 @@ pkg-upload: pkg | |
scp -p $(TARNAME).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg | ||
ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg.done" | ||
|
||
$(TARBALL): release-only doc-only | ||
$(TARBALL): release-only doc-only test/common/knownGlobals.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This target will also probably need to copy in the generated |
||
git checkout-index -a -f --prefix=$(TARNAME)/ | ||
mkdir -p $(TARNAME)/doc/api | ||
cp doc/node.1 $(TARNAME)/doc/node.1 | ||
|
@@ -1155,6 +1159,7 @@ $(TARBALL): release-only doc-only | |
$(RM) -r $(TARNAME)/deps/v8/tools/run-tests.py | ||
$(RM) -r $(TARNAME)/doc/images # too big | ||
$(RM) -r $(TARNAME)/test*.tap | ||
$(RM) -r $(TARNAME)/test/common/parseEslintConfigForKnownGlobals.js | ||
$(RM) -r $(TARNAME)/tools/cpplint.py | ||
$(RM) -r $(TARNAME)/tools/eslint-rules | ||
$(RM) -r $(TARNAME)/tools/license-builder.sh | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const readline = require('readline'); | ||
|
||
const searchLines = [ | ||
' no-restricted-globals:', | ||
' node-core/prefer-primordials:', | ||
]; | ||
|
||
const restrictedGlobalLine = /^\s{4}- name:\s?([^#\s]+)/; | ||
const closingLine = /^\s{0,3}[^#\s]/; | ||
|
||
const jsonFile = fs.openSync(path.join(__dirname, 'knownGlobals.json'), 'w'); | ||
|
||
fs.writeSync(jsonFile, '["process"'); | ||
|
||
const eslintConfig = readline.createInterface({ | ||
input: fs.createReadStream( | ||
path.join(__dirname, '..', '..', 'lib', '.eslintrc.yaml') | ||
), | ||
crlfDelay: Infinity, | ||
}); | ||
|
||
let isReadingGlobals = false; | ||
eslintConfig.on('line', (line) => { | ||
if (isReadingGlobals) { | ||
const match = restrictedGlobalLine.exec(line); | ||
if (match != null) { | ||
fs.writeSync(jsonFile, ',' + JSON.stringify(match[1])); | ||
} else if (closingLine.test(line)) { | ||
isReadingGlobals = false; | ||
} | ||
} else if (line === searchLines[0]) { | ||
searchLines.shift(); | ||
isReadingGlobals = true; | ||
} | ||
}); | ||
|
||
eslintConfig.once('close', () => { | ||
fs.writeSync(jsonFile, ']'); | ||
fs.closeSync(jsonFile); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ common.skipIfDumbTerminal(); | |
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
common.allowGlobals('require', '_', '_error', ...require('module').builtinModules); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add |
||
|
||
process.throwDeprecation = true; | ||
|
||
const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to break
jstest
(and targets such astest-only
) for builds from the source tar ball as we strip out anything related to linting (e.g.lib/.eslintrc.yaml
) from those: #5618node/Makefile
Line 1167 in aa97c9d