Skip to content

Commit

Permalink
Expand (and export) globals
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Apr 18, 2024
1 parent 251837d commit 4301c25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,7 +18,7 @@ const s = '@stylistic/js/'
const config = {
plugins: {
recommended,
arc,
arc: arcRules,
'@stylistic/js': stylistic,
fp,
// importPlugin,
Expand Down Expand Up @@ -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,
Expand All @@ -89,9 +89,12 @@ module.exports = [
files: [ '**/*.mjs' ],
languageOptions: {
ecmaVersion,
globals,
globals: node,
sourceType: 'module',
},
...config,
},
]
arc.globals = globals

module.exports = arc
8 changes: 4 additions & 4 deletions scripts/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4301c25

Please sign in to comment.