diff --git a/data/es2015.mjs b/data/es2015.mjs index a068a7b..98a934d 100644 --- a/data/es2015.mjs +++ b/data/es2015.mjs @@ -1,60 +1,25 @@ -export default { - Array: false, +import {mergeGlobals} from '../utilities.mjs'; +import es5Globals from './es5.mjs'; + +export default mergeGlobals(es5Globals, { ArrayBuffer: false, - Boolean: false, - constructor: false, DataView: false, - Date: false, - decodeURI: false, - decodeURIComponent: false, - encodeURI: false, - encodeURIComponent: false, - Error: false, - escape: false, - eval: false, - EvalError: false, Float32Array: false, Float64Array: false, - Function: false, - hasOwnProperty: false, - Infinity: false, Int16Array: false, Int32Array: false, Int8Array: false, Intl: false, - isFinite: false, - isNaN: false, - isPrototypeOf: false, - JSON: false, Map: false, - Math: false, - NaN: false, - Number: false, - Object: false, - parseFloat: false, - parseInt: false, Promise: false, - propertyIsEnumerable: false, Proxy: false, - RangeError: false, - ReferenceError: false, Reflect: false, - RegExp: false, Set: false, - String: false, Symbol: false, - SyntaxError: false, - toLocaleString: false, - toString: false, - TypeError: false, Uint16Array: false, Uint32Array: false, Uint8Array: false, Uint8ClampedArray: false, - undefined: false, - unescape: false, - URIError: false, - valueOf: false, WeakMap: false, WeakSet: false, -}; +}); diff --git a/data/es2017.mjs b/data/es2017.mjs index 04fb9f6..40a0214 100644 --- a/data/es2017.mjs +++ b/data/es2017.mjs @@ -1,62 +1,7 @@ -export default { - Array: false, - ArrayBuffer: false, +import {mergeGlobals} from '../utilities.mjs'; +import es2015Globals from './es2015.mjs'; + +export default mergeGlobals(es2015Globals, { Atomics: false, - Boolean: false, - constructor: false, - DataView: false, - Date: false, - decodeURI: false, - decodeURIComponent: false, - encodeURI: false, - encodeURIComponent: false, - Error: false, - escape: false, - eval: false, - EvalError: false, - Float32Array: false, - Float64Array: false, - Function: false, - hasOwnProperty: false, - Infinity: false, - Int16Array: false, - Int32Array: false, - Int8Array: false, - Intl: false, - isFinite: false, - isNaN: false, - isPrototypeOf: false, - JSON: false, - Map: false, - Math: false, - NaN: false, - Number: false, - Object: false, - parseFloat: false, - parseInt: false, - Promise: false, - propertyIsEnumerable: false, - Proxy: false, - RangeError: false, - ReferenceError: false, - Reflect: false, - RegExp: false, - Set: false, SharedArrayBuffer: false, - String: false, - Symbol: false, - SyntaxError: false, - toLocaleString: false, - toString: false, - TypeError: false, - Uint16Array: false, - Uint32Array: false, - Uint8Array: false, - Uint8ClampedArray: false, - undefined: false, - unescape: false, - URIError: false, - valueOf: false, - WeakMap: false, - WeakSet: false, -}; +}); diff --git a/data/es2020.mjs b/data/es2020.mjs index 1101e99..2ff8fa5 100644 --- a/data/es2020.mjs +++ b/data/es2020.mjs @@ -1,66 +1,9 @@ -export default { - Array: false, - ArrayBuffer: false, - Atomics: false, +import {mergeGlobals} from '../utilities.mjs'; +import es2017Globals from './es2017.mjs'; + +export default mergeGlobals(es2017Globals, { BigInt: false, BigInt64Array: false, BigUint64Array: false, - Boolean: false, - constructor: false, - DataView: false, - Date: false, - decodeURI: false, - decodeURIComponent: false, - encodeURI: false, - encodeURIComponent: false, - Error: false, - escape: false, - eval: false, - EvalError: false, - Float32Array: false, - Float64Array: false, - Function: false, globalThis: false, - hasOwnProperty: false, - Infinity: false, - Int16Array: false, - Int32Array: false, - Int8Array: false, - Intl: false, - isFinite: false, - isNaN: false, - isPrototypeOf: false, - JSON: false, - Map: false, - Math: false, - NaN: false, - Number: false, - Object: false, - parseFloat: false, - parseInt: false, - Promise: false, - propertyIsEnumerable: false, - Proxy: false, - RangeError: false, - ReferenceError: false, - Reflect: false, - RegExp: false, - Set: false, - SharedArrayBuffer: false, - String: false, - Symbol: false, - SyntaxError: false, - toLocaleString: false, - toString: false, - TypeError: false, - Uint16Array: false, - Uint32Array: false, - Uint8Array: false, - Uint8ClampedArray: false, - undefined: false, - unescape: false, - URIError: false, - valueOf: false, - WeakMap: false, - WeakSet: false, -}; +}); diff --git a/data/es2021.mjs b/data/es2021.mjs index 3bceb3a..1963ffd 100644 --- a/data/es2021.mjs +++ b/data/es2021.mjs @@ -1,69 +1,8 @@ -export default { +import {mergeGlobals} from '../utilities.mjs'; +import es2020Globals from './es2020.mjs'; + +export default mergeGlobals(es2020Globals, { AggregateError: false, - Array: false, - ArrayBuffer: false, - Atomics: false, - BigInt: false, - BigInt64Array: false, - BigUint64Array: false, - Boolean: false, - constructor: false, - DataView: false, - Date: false, - decodeURI: false, - decodeURIComponent: false, - encodeURI: false, - encodeURIComponent: false, - Error: false, - escape: false, - eval: false, - EvalError: false, FinalizationRegistry: false, - Float32Array: false, - Float64Array: false, - Function: false, - globalThis: false, - hasOwnProperty: false, - Infinity: false, - Int16Array: false, - Int32Array: false, - Int8Array: false, - Intl: false, - isFinite: false, - isNaN: false, - isPrototypeOf: false, - JSON: false, - Map: false, - Math: false, - NaN: false, - Number: false, - Object: false, - parseFloat: false, - parseInt: false, - Promise: false, - propertyIsEnumerable: false, - Proxy: false, - RangeError: false, - ReferenceError: false, - Reflect: false, - RegExp: false, - Set: false, - SharedArrayBuffer: false, - String: false, - Symbol: false, - SyntaxError: false, - toLocaleString: false, - toString: false, - TypeError: false, - Uint16Array: false, - Uint32Array: false, - Uint8Array: false, - Uint8ClampedArray: false, - undefined: false, - unescape: false, - URIError: false, - valueOf: false, - WeakMap: false, WeakRef: false, - WeakSet: false, -}; +}); diff --git a/data/node.mjs b/data/node.mjs index 375aa5d..a143b9c 100644 --- a/data/node.mjs +++ b/data/node.mjs @@ -1,75 +1,11 @@ -// This file is autogenerated by scripts -// Do NOT modify this file manually +import {sortObject} from '../utilities.mjs'; +import commonjsGlobals from './commonjs.mjs'; +import nodeBuiltinGlobals from './nodeBuiltin.mjs'; -export default { +export default sortObject({ + ...nodeBuiltinGlobals, + ...commonjsGlobals, __dirname: false, __filename: false, - AbortController: false, - AbortSignal: false, - atob: false, - Blob: false, - BroadcastChannel: false, - btoa: false, - Buffer: false, - ByteLengthQueuingStrategy: false, - clearImmediate: false, - clearInterval: false, - clearTimeout: false, - CompressionStream: false, - console: false, - CountQueuingStrategy: false, - crypto: false, - Crypto: false, - CryptoKey: false, - CustomEvent: false, - DecompressionStream: false, - DOMException: false, - Event: false, - EventTarget: false, - exports: true, - fetch: false, - File: false, - FormData: false, - global: false, - Headers: false, - MessageChannel: false, - MessageEvent: false, - MessagePort: false, - module: false, - performance: false, - Performance: false, - PerformanceEntry: false, - PerformanceMark: false, - PerformanceMeasure: false, - PerformanceObserver: false, - PerformanceObserverEntryList: false, - PerformanceResourceTiming: false, - process: false, - queueMicrotask: false, - ReadableByteStreamController: false, - ReadableStream: false, - ReadableStreamBYOBReader: false, - ReadableStreamBYOBRequest: false, - ReadableStreamDefaultController: false, - ReadableStreamDefaultReader: false, - Request: false, - require: false, - Response: false, - setImmediate: false, - setInterval: false, - setTimeout: false, - structuredClone: false, - SubtleCrypto: false, - TextDecoder: false, - TextDecoderStream: false, - TextEncoder: false, - TextEncoderStream: false, - TransformStream: false, - TransformStreamDefaultController: false, - URL: false, - URLSearchParams: false, - WebAssembly: false, - WritableStream: false, - WritableStreamDefaultController: false, - WritableStreamDefaultWriter: false, -}; +}); + diff --git a/data/shared-node-browser.mjs b/data/shared-node-browser.mjs index 5bdfef7..e1af6a7 100644 --- a/data/shared-node-browser.mjs +++ b/data/shared-node-browser.mjs @@ -1,61 +1,5 @@ -export default { - AbortController: false, - AbortSignal: false, - atob: false, - Blob: false, - BroadcastChannel: false, - btoa: false, - ByteLengthQueuingStrategy: false, - clearInterval: false, - clearTimeout: false, - CompressionStream: false, - console: false, - CountQueuingStrategy: false, - crypto: false, - Crypto: false, - CryptoKey: false, - CustomEvent: false, - DecompressionStream: false, - DOMException: false, - Event: false, - EventTarget: false, - fetch: false, - File: false, - FormData: false, - Headers: false, - MessageChannel: false, - MessageEvent: false, - MessagePort: false, - performance: false, - PerformanceEntry: false, - PerformanceMark: false, - PerformanceMeasure: false, - PerformanceObserver: false, - PerformanceObserverEntryList: false, - PerformanceResourceTiming: false, - queueMicrotask: false, - ReadableByteStreamController: false, - ReadableStream: false, - ReadableStreamBYOBReader: false, - ReadableStreamBYOBRequest: false, - ReadableStreamDefaultController: false, - ReadableStreamDefaultReader: false, - Request: false, - Response: false, - setInterval: false, - setTimeout: false, - structuredClone: false, - SubtleCrypto: false, - TextDecoder: false, - TextDecoderStream: false, - TextEncoder: false, - TextEncoderStream: false, - TransformStream: false, - TransformStreamDefaultController: false, - URL: false, - URLSearchParams: false, - WebAssembly: false, - WritableStream: false, - WritableStreamDefaultController: false, - WritableStreamDefaultWriter: false, -}; +import {getIntersectionGlobals} from '../utilities.mjs'; +import browserGlobals from './browser.mjs'; +import nodeBuiltinGlobals from './nodeBuiltin.mjs'; + +export default getIntersectionGlobals(browserGlobals, nodeBuiltinGlobals); diff --git a/globals.json b/globals.json index 3e5a490..ab0895b 100644 --- a/globals.json +++ b/globals.json @@ -2229,6 +2229,7 @@ "MessageEvent": false, "MessagePort": false, "performance": false, + "Performance": false, "PerformanceEntry": false, "PerformanceMark": false, "PerformanceMeasure": false, diff --git a/scripts/get-node-globals.mjs b/scripts/get-node-globals.mjs index da1f2c3..f71d1c9 100644 --- a/scripts/get-node-globals.mjs +++ b/scripts/get-node-globals.mjs @@ -4,22 +4,7 @@ const ignore = [ /^__/, ]; -const commonjsGlobals = { - exports: true, - global: false, - module: false, - require: false, -}; - const properties = getGlobalThisProperties(); const nodeBuiltinGlobals = await createGlobals(properties, {ignore}); await updateGlobals('nodeBuiltin', nodeBuiltinGlobals); - -const nodejsGlobals = { - ...nodeBuiltinGlobals, - ...commonjsGlobals, - __dirname: false, - __filename: false, -}; -await updateGlobals('node', nodejsGlobals); diff --git a/scripts/utilities.mjs b/scripts/utilities.mjs index fafcb65..c6b9022 100644 --- a/scripts/utilities.mjs +++ b/scripts/utilities.mjs @@ -1,15 +1,9 @@ import fs from 'node:fs/promises'; import {outdent} from 'outdent'; +import {unique, sortObject} from '../utilities.mjs'; const DATA_DIRECTORY = new URL('../data/', import.meta.url); -const sortObject = object => - Object.fromEntries( - Object.entries(object).sort(([propertyA], [propertyB]) => - propertyA.localeCompare(propertyB), - ), - ); - const readGlobals = async (environment, {ignoreNonExits} = {}) => { const file = new URL(`${environment}.mjs`, DATA_DIRECTORY); file.searchParams.set('ts', Date.now()); @@ -73,10 +67,6 @@ function getGlobalThisProperties() { return keys; } -function unique(array) { - return [...new Set(array)]; -} - async function createGlobals(globals, { ignore = [], writeable, diff --git a/utilities.mjs b/utilities.mjs new file mode 100644 index 0000000..c46c805 --- /dev/null +++ b/utilities.mjs @@ -0,0 +1,40 @@ +const sortObject = object => + Object.fromEntries( + Object.entries(object).sort(([propertyA], [propertyB]) => + propertyA.localeCompare(propertyB), + ), + ); + +function unique(array) { + return [...new Set(array)]; +} + +function mergeGlobals(globalsA, globalsB) { + const existsInA = Object.keys(globalsB).filter(name => Object.hasOwn(globalsA, name)); + if (existsInA.length > 0) { + throw new Error(`Already exits:\n${existsInA.map(name => ` - ${name}`).join('\n')}`); + } + + const existsInB = Object.keys(globalsA).filter(name => Object.hasOwn(globalsB, name)); + if (existsInB.length > 0) { + throw new Error(`Already exits:\n${existsInB.map(name => ` - ${name}`).join('\n')}`); + } + + return sortObject({...globalsA, ...globalsB}); +} + +function getIntersectionGlobals(globalsA, globalsB) { + return sortObject( + Object.fromEntries([ + ...Object.entries(globalsA).filter(([name]) => Object.hasOwn(globalsB, name)), + ...Object.entries(globalsB).filter(([name]) => Object.hasOwn(globalsA, name)), + ]), + ); +} + +export { + unique, + sortObject, + mergeGlobals, + getIntersectionGlobals, +};