Skip to content

Commit

Permalink
Export Node.js globals
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Apr 18, 2024
1 parent 294e6fa commit fed2266
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ jobs:
- name: Install
run: npm i

- name: Vendor
run: npm run vendor

- name: Lint
run: npm run lint

# Publish to npm
- name: Publish @RC to npm
if: contains(github.ref, 'RC')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
package-lock.json
globals.json
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -77,6 +80,7 @@ module.exports = [
files: [ '**/*.js', '**/*.cjs' ],
languageOptions: {
ecmaVersion,
globals,
sourceType: 'commonjs',
},
...config,
Expand All @@ -85,6 +89,7 @@ module.exports = [
files: [ '**/*.mjs' ],
languageOptions: {
ecmaVersion,
globals,
sourceType: 'module',
},
...config,
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions scripts/vendor.js
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit fed2266

Please sign in to comment.