Skip to content

Commit 3981d90

Browse files
mokagiocodexgithub-advanced-security[bot]
authored
Lint scripts from the root config (#3310)
Co-authored-by: Codex GPT-5 <noreply@openai.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 6340abd commit 3981d90

10 files changed

Lines changed: 55 additions & 31 deletions

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ export default defineConfig(
125125
'@typescript-eslint/no-require-imports': 'off',
126126
},
127127
},
128+
{
129+
files: [ 'scripts/**/*.js', 'scripts/**/*.cjs' ],
130+
rules: {
131+
'@typescript-eslint/no-require-imports': 'off',
132+
},
133+
},
128134
{
129135
files: [ 'apps/cli/**/*.{ts,tsx}' ],
130136
ignores: [ 'apps/cli/vite.config*.ts', 'apps/cli/vitest.config.ts' ],
@@ -141,5 +147,21 @@ export default defineConfig(
141147
},
142148
],
143149
},
150+
},
151+
{
152+
files: [ 'scripts/**/*.mjs' ],
153+
rules: {
154+
'no-restricted-globals': [
155+
'error',
156+
{
157+
name: '__dirname',
158+
message: 'Use import.meta.dirname in ESM modules.',
159+
},
160+
{
161+
name: '__filename',
162+
message: 'Use import.meta.filename in ESM modules.',
163+
},
164+
],
165+
},
144166
}
145167
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"cli:watch": "npm -w wp-studio run watch",
4848
"app:install:bundle": "npm -w studio-app run install:bundle",
4949
"compare:perf": "npm -w compare-perf run compare",
50-
"lint": "eslint {apps/cli,apps/studio/src,apps/studio/e2e,apps/ui/src,tools/common}",
50+
"lint": "eslint {apps/cli,apps/studio/src,apps/studio/e2e,apps/ui/src,tools/common,scripts}",
5151
"typecheck": "npm run typecheck --workspaces --if-present && tsc -p scripts/tsconfig.json --noEmit",
5252
"format": "npm run lint -- --fix",
5353
"test": "vitest run",

scripts/azure-sign-hook.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// (sha1 + sha256) fails because there's no local cert for sha1.
44
// This hook calls signtool directly with SHA256-only parameters.
55

6-
/* eslint-disable @typescript-eslint/no-require-imports */
7-
86
const { execFileSync } = require( 'child_process' );
97
const path = require( 'path' );
108
const {

scripts/download-available-site-translations.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import fs from 'fs';
22
import https from 'https';
33
import path from 'path';
4-
import { fileURLToPath } from 'url';
5-
6-
const __dirname = path.dirname( fileURLToPath( import.meta.url ) );
74

85
console.log(
96
'[available-site-translations] Downloading information of available translations for latest WordPress version ...'
107
);
118

129
const jsonFilePath = path.join(
13-
__dirname,
10+
import.meta.dirname,
1411
'..',
1512
'wp-files',
1613
'latest',

scripts/download-node-binary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
import fs from 'fs';
9-
import path from 'path';
109
import os from 'os';
10+
import path from 'path';
1111
import { extract } from 'tar';
1212
import { extractZip } from '../tools/common/lib/extract-zip';
1313

@@ -172,4 +172,4 @@ async function main(): Promise< void > {
172172
}
173173
}
174174

175-
main();
175+
void main();

scripts/make-dmg.mjs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import child_process from 'child_process';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import { fileURLToPath } from 'url';
54
import packageJson from '../apps/studio/package.json' with { type: 'json' };
65

7-
const __dirname = path.dirname( fileURLToPath( import.meta.url ) );
86
const fileArchitecture = process.env.FILE_ARCHITECTURE;
97

108
if ( ! fileArchitecture ) {
@@ -13,7 +11,7 @@ if ( ! fileArchitecture ) {
1311
);
1412
}
1513

16-
const outDir = path.resolve( __dirname, '../apps/studio/out' );
14+
const outDir = path.resolve( import.meta.dirname, '../apps/studio/out' );
1715

1816
const appPath = path.resolve(
1917
outDir,
@@ -26,8 +24,14 @@ const dmgPath = path.resolve(
2624
`${ packageJson.productName }-darwin-${ fileArchitecture }.dmg`
2725
);
2826

29-
const volumeIconPath = path.resolve( __dirname, '../apps/studio/assets/studio-app-icon.icns' );
30-
const backgroundPath = path.resolve( __dirname, '../apps/studio/assets/dmg-background.png' );
27+
const volumeIconPath = path.resolve(
28+
import.meta.dirname,
29+
'../apps/studio/assets/studio-app-icon.icns'
30+
);
31+
const backgroundPath = path.resolve(
32+
import.meta.dirname,
33+
'../apps/studio/assets/dmg-background.png'
34+
);
3135

3236
const dmgSpecs = {
3337
title: packageJson.productName,
@@ -50,9 +54,13 @@ if ( fs.existsSync( dmgPath ) ) {
5054
}
5155
fs.mkdirSync( path.dirname( dmgPath ), { recursive: true } );
5256

53-
const specsFile = path.resolve( __dirname, '..', 'appdmg-specs.json' );
57+
const specsFile = path.resolve( import.meta.dirname, '..', 'appdmg-specs.json' );
5458
fs.writeFileSync( specsFile, JSON.stringify( dmgSpecs ) );
55-
child_process.execSync(
56-
[ path.join( __dirname, '..', 'node_modules', '.bin', `appdmg` ), specsFile, dmgPath ].join( ' ' )
57-
);
58-
fs.unlinkSync( specsFile );
59+
const appdmgBin = path.join( import.meta.dirname, '..', 'node_modules', '.bin', 'appdmg' );
60+
try {
61+
child_process.execFileSync( appdmgBin, [ specsFile, dmgPath ] );
62+
} finally {
63+
if ( fs.existsSync( specsFile ) ) {
64+
fs.unlinkSync( specsFile );
65+
}
66+
}

scripts/package-appx.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { execFileSync } from 'child_process';
22
import fs from 'fs/promises';
33
import path from 'path';
4-
import { fileURLToPath } from 'url';
54
import convertToWindowsStore from 'electron2appx';
65
import packageJson from '../apps/studio/package.json' with { type: 'json' };
76

@@ -29,16 +28,18 @@ if ( useAzureSigning ) {
2928
}
3029
}
3130

32-
const __dirname = path.dirname( fileURLToPath( import.meta.url ) );
33-
3431
// Get architecture from environment variable, default to x64 for backward compatibility
3532
const architecture = process.env.FILE_ARCHITECTURE || 'x64';
3633
if ( architecture !== 'x64' && architecture !== 'arm64' ) {
3734
console.error( `Invalid architecture: ${ architecture }. Must be 'x64' or 'arm64'.` );
3835
process.exit( 1 );
3936
}
4037

41-
const windows10SDKVersionPath = path.resolve( __dirname, '..', '.windows-10-sdk-version' );
38+
const windows10SDKVersionPath = path.resolve(
39+
import.meta.dirname,
40+
'..',
41+
'.windows-10-sdk-version'
42+
);
4243
try {
4344
await fs.access( windows10SDKVersionPath );
4445
} catch {
@@ -62,8 +63,8 @@ try {
6263
process.exit( 1 );
6364
}
6465

65-
const outPath = path.join( __dirname, '..', 'apps', 'studio', 'out' );
66-
const assetsPath = path.join( __dirname, '..', 'apps', 'studio', 'assets', 'appx' );
66+
const outPath = path.join( import.meta.dirname, '..', 'apps', 'studio', 'out' );
67+
const assetsPath = path.join( import.meta.dirname, '..', 'apps', 'studio', 'assets', 'appx' );
6768

6869
console.log( `~~~ Packaging AppX for architecture: ${ architecture }` );
6970

scripts/package-in-isolation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function main() {
9090
const studioAppScripts = getStudioAppScripts();
9191
const scriptName = process.argv[ 2 ];
9292

93-
if ( ! studioAppScripts.hasOwnProperty( scriptName ) ) {
93+
if ( ! Object.prototype.hasOwnProperty.call( studioAppScripts, scriptName ) ) {
9494
throw new Error(
9595
`Unsupported script "${ scriptName }". Supported studio-app packaging scripts: ${ Object.keys(
9696
studioAppScripts

scripts/prepare-dev-build-version.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import fs from 'fs/promises';
44
import path from 'path';
55
import semver from 'semver';
6-
import { getLatestTag, getCommitCount } from './lib/git-utils.mjs';
76
import packageJson from '../apps/studio/package.json' with { type: 'json' };
7+
import { getCommitCount, getLatestTag } from './lib/git-utils.mjs';
88

99
const latestTag = getLatestTag();
1010
const commitCount = getCommitCount( latestTag );

scripts/start-new-ui.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
*/
1010

1111
import { spawn } from 'child_process';
12-
import { dirname, resolve } from 'path';
13-
import { fileURLToPath } from 'url';
12+
import { resolve } from 'path';
1413

15-
const scriptDir = dirname( fileURLToPath( import.meta.url ) );
16-
const root = resolve( scriptDir, '..' );
14+
const root = resolve( import.meta.dirname, '..' );
1715

1816
const UI_DEV_PORT = 5200;
1917

0 commit comments

Comments
 (0)