diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa5be1b..97b6e53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,6 +40,9 @@ jobs: - name: Install run: npm install + - name: Vendor + run: npm run vendor + - name: Test run: npm test env: diff --git a/.gitignore b/.gitignore index 504afef..006433d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ package-lock.json +globals.json diff --git a/eslint.config.js b/eslint.config.js index 3315c1a..5cc6d60 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -6,6 +6,9 @@ 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 ecmaVersion = 13 // 2022 const off = 'off' const err = 'error' @@ -77,6 +80,7 @@ module.exports = [ files: [ '**/*.js', '**/*.cjs' ], languageOptions: { ecmaVersion, + globals, sourceType: 'commonjs', }, ...config, @@ -85,6 +89,7 @@ module.exports = [ files: [ '**/*.mjs' ], languageOptions: { ecmaVersion, + globals, sourceType: 'module', }, ...config, diff --git a/index.js b/index.js deleted file mode 120000 index 3241e7a..0000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -eslint.config.js \ No newline at end of file diff --git a/package.json b/package.json index 5510434..2926ac0 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,12 @@ "name": "@architect/eslint-config", "version": "3.0.0-RC.1", "description": "Architect standard ESLint configuration", - "main": "index.js", + "main": "eslint.config.js", "scripts": { "lint": "eslint . --fix", "test": "npm run lint", - "rc": "npm version prerelease --preid RC" + "rc": "npm version prerelease --preid RC", + "vendor": "scripts/vendor.js" }, "repository": { "type": "git", @@ -20,13 +21,19 @@ "eslint-plugin-fp": "^2.3.0" }, "devDependencies": { - "eslint": "^9.0.0" + "eslint": "^9.0.0", + "globals": "^15.0.0" }, "peerDependencies": { "eslint": ">= 9" }, "author": "Ryan Block", "license": "Apache-2.0", + "files": [ + "eslint.config.js", + "globals.js*", + "src" + ], "keywords": [ "amazon", "api gateway", diff --git a/scripts/vendor.js b/scripts/vendor.js new file mode 100755 index 0000000..87993de --- /dev/null +++ b/scripts/vendor.js @@ -0,0 +1,34 @@ +#! /usr/bin/env node + +const { readFileSync, writeFileSync } = require('node:fs') +const { join } = require('node:path') +const cwd = process.cwd() + +async function main () { + const allGlobalsFile = join(cwd, 'node_modules', 'globals', 'globals.json') + const allGlobals = JSON.parse(readFileSync(allGlobalsFile)) + + function aggregate (a, b) { + Object.keys(b).forEach(k => { + if (a[k] === undefined) a[k] = b[k] + }) + return a + } + + /* // Core JS + const { builtin, es5, es2015, es2017, es2020, es2021 } = allGlobals + const common = [builtin, es5, es2015, es2017, es2020, es2021].reduce(aggregate, {}) */ + + // Browser + const { browser, worker, serviceworker } = allGlobals + const browserGlobals = [ browser, worker, serviceworker ].reduce(aggregate, {}) + + // Node + const { node, nodeBuiltin, commonjs } = allGlobals + const nodeGlobals = [ node, nodeBuiltin, commonjs ].reduce(aggregate, {}) + + const json = JSON.stringify({ node: nodeGlobals, browser: browserGlobals }, null, 2) + '\n' + const dest = join(cwd, 'globals.json') + writeFileSync(dest, json) +} +main()