Skip to content

Commit c61cc23

Browse files
committed
Tweaks
1 parent 7abfb5d commit c61cc23

14 files changed

Lines changed: 173 additions & 163 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
node-version:
18-
- 20
19-
- 18
18+
- 26
19+
- 22
2020
steps:
2121
- uses: actions/checkout@v7
22-
- uses: actions/setup-node@v6
22+
- uses: actions/setup-node@v7
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
- run: npm install
@@ -38,7 +38,7 @@ jobs:
3838
- uses: actions/checkout@v7
3939
- uses: oven-sh/setup-bun@v2
4040
- uses: denoland/setup-deno@v2
41-
- uses: actions/setup-node@v6
41+
- uses: actions/setup-node@v7
4242
with:
4343
check-latest: true
4444
node-version: latest

‎.github/workflows/update.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v7
1919
- uses: oven-sh/setup-bun@v2
2020
- uses: denoland/setup-deno@v2
21-
- uses: actions/setup-node@v6
21+
- uses: actions/setup-node@v7
2222
with:
2323
check-latest: true
2424
node-version: latest
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v7
4141
- uses: oven-sh/setup-bun@v2
4242
- uses: denoland/setup-deno@v2
43-
- uses: actions/setup-node@v6
43+
- uses: actions/setup-node@v7
4444
with:
4545
check-latest: true
4646
node-version: latest
@@ -67,7 +67,7 @@ jobs:
6767
- uses: actions/checkout@v7
6868
- uses: oven-sh/setup-bun@v2
6969
- uses: denoland/setup-deno@v2
70-
- uses: actions/setup-node@v6
70+
- uses: actions/setup-node@v7
7171
with:
7272
check-latest: true
7373
node-version: latest

‎index.test-d.ts‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎package.json‎

Lines changed: 78 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
"license": "MIT",
66
"repository": "sindresorhus/globals",
77
"funding": "https://github.com/sponsors/sindresorhus",
8-
"author": {
9-
"name": "Sindre Sorhus",
10-
"email": "[email protected]",
11-
"url": "https://sindresorhus.com"
12-
},
8+
"author": "Sindre Sorhus <[email protected]> (https://sindresorhus.com)",
139
"sideEffects": false,
1410
"engines": {
1511
"node": ">=18"
1612
},
1713
"scripts": {
18-
"test": "npm run build && xo && ava && tsd",
14+
"test": "npm run build && xo && node --test",
1915
"prepare": "npm run build",
2016
"update": "node scripts/update.mjs",
2117
"update:browser": "node scripts/update.mjs --job=browser",
@@ -36,12 +32,11 @@
3632
"build:types": "node scripts/generate-types.mjs"
3733
},
3834
"files": [
35+
"globals.json",
3936
"index.js",
40-
"index.d.ts",
41-
"globals.json"
37+
"index.d.ts"
4238
],
4339
"keywords": [
44-
"globals",
4540
"global",
4641
"identifiers",
4742
"variables",
@@ -51,71 +46,87 @@
5146
"environments"
5247
],
5348
"devDependencies": {
54-
"@vitest/eslint-plugin": "^1.1.44",
55-
"ava": "^6.3.0",
56-
"cheerio": "^1.0.0",
57-
"eslint-plugin-jest": "^28.11.0",
58-
"get-port": "^7.1.0",
59-
"is-identifier": "^1.0.1",
60-
"nano-spawn": "^0.2.0",
61-
"npm-run-all2": "^8.0.1",
49+
"@vitest/eslint-plugin": "^1.6.27",
50+
"cheerio": "^1.2.0",
51+
"eslint-plugin-jest": "^29.16.6",
52+
"get-port": "^7.2.0",
53+
"is-identifier": "^1.1.0",
54+
"nano-spawn": "^2.1.0",
55+
"npm-run-all2": "^9.0.3",
6256
"outdent": "^0.8.0",
6357
"puppeteer": "^25.16.0",
64-
"shelljs": "^0.9.2",
65-
"tsd": "^0.32.0",
66-
"type-fest": "^4.41.0",
67-
"xo": "^0.60.0"
58+
"shelljs": "^0.10.0",
59+
"type-fest": "^5.10.0",
60+
"xo": "^5.0.1"
6861
},
69-
"xo": {
70-
"rules": {
71-
"unicorn/prefer-module": "off"
62+
"xo": [
63+
{
64+
"ignores": [
65+
"scripts/browser/index.html"
66+
]
67+
},
68+
{
69+
"rules": {
70+
"unicorn/prefer-module": "off"
71+
}
7272
},
73-
"overrides": [
74-
{
75-
"files": [
76-
"data/*.mjs"
77-
],
78-
"rules": {
79-
"import/no-anonymous-default-export": "off",
80-
"camelcase": "off",
81-
"unicorn/filename-case": [
82-
"error",
83-
{
84-
"cases": {
85-
"camelCase": true,
86-
"kebabCase": true
87-
}
73+
{
74+
"files": [
75+
"**/package.json"
76+
],
77+
"rules": {
78+
"package-json/prefer-type-module": "off",
79+
"package-json/require-entry-point": "off"
80+
}
81+
},
82+
{
83+
"files": [
84+
"data/*.mjs"
85+
],
86+
"rules": {
87+
"import-x/no-anonymous-default-export": "off",
88+
"camelcase": "off",
89+
"unicorn/filename-case": [
90+
"error",
91+
{
92+
"cases": {
93+
"camelCase": true,
94+
"kebabCase": true
8895
}
89-
]
90-
}
91-
},
92-
{
93-
"files": [
94-
"scripts/*.mjs"
95-
],
96-
"rules": {
97-
"n/no-unsupported-features/node-builtins": "off"
96+
}
97+
]
98+
}
99+
},
100+
{
101+
"files": [
102+
"scripts/*.mjs"
103+
],
104+
"rules": {
105+
"n/no-unsupported-features/node-builtins": "off"
106+
}
107+
},
108+
{
109+
"files": [
110+
"scripts/browser/assets/**/*.mjs"
111+
],
112+
"languageOptions": {
113+
"globals": {
114+
"AudioContext": "readonly",
115+
"AudioWorkletNode": "readonly",
116+
"AudioWorkletProcessor": "readonly",
117+
"CSS": "readonly",
118+
"alert": "readonly",
119+
"document": "readonly",
120+
"registerProcessor": "readonly",
121+
"SharedWorker": "readonly",
122+
"Worker": "readonly"
98123
}
99124
},
100-
{
101-
"files": [
102-
"scripts/browser/assets/**/*.mjs"
103-
],
104-
"envs": [
105-
"browser",
106-
"worker",
107-
"serviceworker"
108-
],
109-
"rules": {
110-
"n/no-unsupported-features/node-builtins": "off",
111-
"unicorn/prefer-add-event-listener": "off"
112-
}
125+
"rules": {
126+
"n/no-unsupported-features/node-builtins": "off",
127+
"unicorn/prefer-add-event-listener": "off",
128+
"unicorn/no-global-object-property-assignment": "off"
113129
}
114-
]
115-
},
116-
"tsd": {
117-
"compilerOptions": {
118-
"resolveJsonModule": true
119130
}
120-
}
131+
]
121132
}

‎readme.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ For Node.js this package provides two sets of globals:
4040
See: https://nodejs.org/api/modules.html#modules_the_module_scope
4141

4242
When analyzing code that is known to run outside of a CommonJS wrapper, for example, JavaScript modules, `nodeBuiltin` can find accidental CommonJS references.
43+
44+
> [!NOTE]
45+
> The data is a snapshot committed to the repository, not something read from the runtime at install time. `nodeBuiltin` is regenerated monthly by the `Update` workflow against the *latest* Node.js release, so it describes the newest Node.js rather than the oldest version this package supports. `engines.node` is the support floor and does not describe the data.

‎scripts/browser/assets/main.mjs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function getGlobalThisProperties({expectSecureContext = true} = {}) {
2828
}
2929

3030
function sendResult({
31-
port = globalThis,
31+
port,
3232
receivePort = port,
3333
sendPort = receivePort,
3434
getGlobals = getGlobalThisProperties,
@@ -45,8 +45,8 @@ function sendResult({
4545
message.error = error;
4646
throw error;
4747
} finally {
48-
const port = typeof sendPort === 'function' ? sendPort(receivedMessage) : sendPort;
49-
port.postMessage(message);
48+
const messagePort = typeof sendPort === 'function' ? sendPort(receivedMessage) : sendPort;
49+
messagePort.postMessage(message);
5050
}
5151
};
5252
}
@@ -76,7 +76,7 @@ function getWebWorkerGlobals() {
7676
}
7777

7878
function initWebWorker() {
79-
sendResult();
79+
sendResult({port: globalThis});
8080
}
8181

8282
const SERVICE_WORK_URL = './assets/service-worker.mjs';
@@ -100,6 +100,7 @@ async function getServiceWorkerGlobals() {
100100

101101
function initServiceWorker() {
102102
sendResult({
103+
port: globalThis,
103104
sendPort: message => message.source,
104105
});
105106
}
@@ -111,8 +112,8 @@ function getSharedWorkerGlobals() {
111112
}
112113

113114
function initSharedWorker() {
114-
globalThis.onconnect = ({ports: [port]}) => {
115-
sendResult({port});
115+
globalThis.onconnect = event => {
116+
sendResult({port: event.ports[0]});
116117
};
117118
}
118119

‎scripts/browser/server.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function startServer({silent = false, port: preferredPort} = {}) {
1717
}
1818

1919
// Only allow `.mjs` and `.html`
20-
if (!/\.(?:html|mjs)$/.test(url)) {
20+
if (!/\.(?:html|mjs)$/v.test(url)) {
2121
response.statusCode = 404;
2222
response.end();
2323
return;

‎scripts/es-builtin.mjs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ function * getGlobalObjects($) {
5959
let text = $(element).text().trim();
6060

6161
// Function shape `Array ( . . . )`
62-
text = text.match(/^(?<functionName>\w+?)\s*\(.*?\)$/)?.groups.functionName ?? text;
62+
text = text.match(/^(?<functionName>\w+)\s*\(.*?\)$/v)?.groups.functionName ?? text;
6363

64-
if (!/^\w+$/.test(text)) {
64+
if (!/^\w+$/v.test(text)) {
6565
continue;
6666
}
6767

@@ -73,7 +73,7 @@ async function parseSpecification() {
7373
const specification = await getSpecification();
7474
const $ = cheerio.load(specification);
7575
const meta = $('pre.metadata').text();
76-
const {year} = meta.match(/title: ECMAScript® (?<year>\d{4})/).groups;
76+
const {year} = meta.match(/title: ECMAScript® (?<year>\d{4})/v).groups;
7777

7878
return {
7979
year,
@@ -110,7 +110,7 @@ async function buildYearlyBuiltinGlobals(job, options) {
110110
${content};
111111
`;
112112

113-
if (!options.dryRun) {
113+
if (!options.dry) {
114114
await fs.writeFile(file, code + '\n');
115115
}
116116

‎scripts/generate-data.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const DATA_DIRECTORY = new URL('../data/', import.meta.url);
88
async function getData() {
99
const files = await fs.readdir(DATA_DIRECTORY);
1010
const environments = files.map(file => path.basename(file, '.mjs'))
11-
.sort((a, b) => a.localeCompare(b));
11+
.toSorted((a, b) => a.localeCompare(b));
1212
const data = await Promise.all(
1313
environments.map(async environment => ({environment, globals: await readGlobals(environment)})),
1414
);

‎scripts/generate-types.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const output = [
99
'// Do NOT modify this file manually\n',
1010
];
1111

12-
for (const group of Object.keys(globals)) {
12+
for (const [group, environmentGlobals] of Object.entries(globals)) {
1313
const groupType = getGroupTypeName(group);
1414
groups[group] = groupType;
1515

16-
output.push(`type ${getGroupTypeName(group)} = {`);
16+
output.push(`type ${groupType} = {`);
1717

18-
for (const [rule, status] of Object.entries(globals[group])) {
18+
for (const [rule, status] of Object.entries(environmentGlobals)) {
1919
output.push(` readonly '${rule}': ${status};`);
2020
}
2121

0 commit comments

Comments
 (0)