From 4301c2536b6762f061537800cd8131e0f2dc4e9c Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Thu, 18 Apr 2024 14:04:22 -0700 Subject: [PATCH] Expand (and export) globals --- eslint.config.js | 17 ++++++++++------- scripts/vendor.js | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 5cc6d60..d4fb003 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,13 +1,14 @@ const eslint = require('@eslint/js') const recommended = eslint.configs.recommended.rules const stylistic = require('@stylistic/eslint-plugin-js') -const arc = require('./src/rules') +const arcRules = require('./src/rules') const fp = require('eslint-plugin-fp') // TODO: re-enable eslint-plugin-import once eslint-plugin-import#2948 is fixed // const importPlugin = require('eslint-plugin-import') // TODO: export browser globals in an easily consumable way for Arc projects? -const { node: globals } = require('./globals.json') +const globals = require('./globals.json') +const { node } = globals const ecmaVersion = 13 // 2022 const off = 'off' @@ -17,7 +18,7 @@ const s = '@stylistic/js/' const config = { plugins: { recommended, - arc, + arc: arcRules, '@stylistic/js': stylistic, fp, // importPlugin, @@ -73,14 +74,13 @@ const config = { }, } - -module.exports = [ +const arc = [ // As of ESLint v9 flat config, *.js is assumed to be ESM, so undo that: { files: [ '**/*.js', '**/*.cjs' ], languageOptions: { ecmaVersion, - globals, + globals: node, sourceType: 'commonjs', }, ...config, @@ -89,9 +89,12 @@ module.exports = [ files: [ '**/*.mjs' ], languageOptions: { ecmaVersion, - globals, + globals: node, sourceType: 'module', }, ...config, }, ] +arc.globals = globals + +module.exports = arc diff --git a/scripts/vendor.js b/scripts/vendor.js index 87993de..320e1e5 100755 --- a/scripts/vendor.js +++ b/scripts/vendor.js @@ -15,17 +15,17 @@ async function main () { return a } - /* // Core JS + // Core JS const { builtin, es5, es2015, es2017, es2020, es2021 } = allGlobals - const common = [builtin, es5, es2015, es2017, es2020, es2021].reduce(aggregate, {}) */ + const common = [ builtin, es5, es2015, es2017, es2020, es2021 ].reduce(aggregate, {}) // Browser const { browser, worker, serviceworker } = allGlobals - const browserGlobals = [ browser, worker, serviceworker ].reduce(aggregate, {}) + const browserGlobals = [ common, browser, worker, serviceworker ].reduce(aggregate, {}) // Node const { node, nodeBuiltin, commonjs } = allGlobals - const nodeGlobals = [ node, nodeBuiltin, commonjs ].reduce(aggregate, {}) + const nodeGlobals = [ common, node, nodeBuiltin, commonjs ].reduce(aggregate, {}) const json = JSON.stringify({ node: nodeGlobals, browser: browserGlobals }, null, 2) + '\n' const dest = join(cwd, 'globals.json')