refactor: use node scheme imports in scripts (#38846)

* refactor: use node scheme imports in script

* refactor: use node scheme imports in build
This commit is contained in:
Milan Burda 2023-06-22 16:21:42 +02:00 committed by GitHub
parent 395b608dd5
commit abec9ead06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 105 additions and 89 deletions

8
build/.eslintrc.json Normal file
View file

@ -0,0 +1,8 @@
{
"plugins": [
"unicorn"
],
"rules": {
"unicorn/prefer-node-protocol": "error"
}
}

View file

@ -1,5 +1,5 @@
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const webpack = require('webpack'); const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin');
const WrapperPlugin = require('wrapper-webpack-plugin'); const WrapperPlugin = require('wrapper-webpack-plugin');

8
script/.eslintrc.json Normal file
View file

@ -0,0 +1,8 @@
{
"plugins": [
"unicorn"
],
"rules": {
"unicorn/prefer-node-protocol": "error"
}
}

View file

@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'; import { spawnSync } from 'node:child_process';
import * as path from 'path'; import * as path from 'node:path';
const srcPath = path.resolve(__dirname, '..', '..', '..'); const srcPath = path.resolve(__dirname, '..', '..', '..');
const patchExportFnPath = path.resolve(__dirname, 'export_all_patches.py'); const patchExportFnPath = path.resolve(__dirname, 'export_all_patches.py');

View file

@ -1,5 +1,5 @@
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const utils = require('./lib/utils'); const utils = require('./lib/utils');
const branding = require('../shell/app/BRANDING.json'); const branding = require('../shell/app/BRANDING.json');

View file

@ -1,6 +1,6 @@
import * as cp from 'child_process'; import * as cp from 'node:child_process';
import * as fs from 'fs'; import * as fs from 'node:fs';
import * as path from 'path'; import * as path from 'node:path';
const certificatePath = process.argv[2]; const certificatePath = process.argv[2];
const outPath = process.argv[3]; const outPath = process.argv[3];

View file

@ -1,6 +1,6 @@
const { parseDocs } = require('@electron/docs-parser'); const { parseDocs } = require('@electron/docs-parser');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const { getElectronVersion } = require('./lib/get-version'); const { getElectronVersion } = require('./lib/get-version');

View file

@ -1,8 +1,8 @@
const args = require('minimist')(process.argv.slice(2)); const args = require('minimist')(process.argv.slice(2));
const fs = require('fs'); const fs = require('node:fs');
const got = require('got'); const got = require('got');
const stream = require('stream'); const stream = require('node:stream');
const { promisify } = require('util'); const { promisify } = require('node:util');
const pipeline = promisify(stream.pipeline); const pipeline = promisify(stream.pipeline);

View file

@ -1,7 +1,7 @@
import * as cp from 'child_process'; import * as cp from 'node:child_process';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import * as os from 'os'; import * as os from 'node:os';
import * as path from 'path'; import * as path from 'node:path';
const rootPath = path.resolve(__dirname, '..'); const rootPath = path.resolve(__dirname, '..');
const gniPath = path.resolve(__dirname, '../filenames.auto.gni'); const gniPath = path.resolve(__dirname, '../filenames.auto.gni');

View file

@ -1,5 +1,5 @@
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const check = process.argv.includes('--check'); const check = process.argv.includes('--check');

View file

@ -1,5 +1,5 @@
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const check = process.argv.includes('--check'); const check = process.argv.includes('--check');

View file

@ -1,6 +1,6 @@
const crypto = require('crypto'); const crypto = require('node:crypto');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
// Fallback to blow away old cache keys // Fallback to blow away old cache keys
const FALLBACK_HASH_VERSION = 3; const FALLBACK_HASH_VERSION = 3;

View file

@ -1,5 +1,5 @@
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const semver = require('semver'); const semver = require('semver');
const outputPath = process.argv[2]; const outputPath = process.argv[2];

View file

@ -1,6 +1,6 @@
const asar = require('@electron/asar'); const asar = require('@electron/asar');
const crypto = require('crypto'); const crypto = require('node:crypto');
const fs = require('fs'); const fs = require('node:fs');
const archive = process.argv[2]; const archive = process.argv[2];
const hashFile = process.argv[3]; const hashFile = process.argv[3];

View file

@ -1,8 +1,8 @@
const asar = require('@electron/asar'); const asar = require('@electron/asar');
const assert = require('assert'); const assert = require('node:assert');
const fs = require('fs-extra'); const fs = require('fs-extra');
const os = require('os'); const os = require('node:os');
const path = require('path'); const path = require('node:path');
const getArgGroup = (name) => { const getArgGroup = (name) => {
const group = []; const group = [];

View file

@ -4,8 +4,8 @@ Usage:
$ node ./script/gn-check.js [--outDir=dirName] $ node ./script/gn-check.js [--outDir=dirName]
*/ */
const cp = require('child_process'); const cp = require('node:child_process');
const path = require('path'); const path = require('node:path');
const args = require('minimist')(process.argv.slice(2), { string: ['outDir'] }); const args = require('minimist')(process.argv.slice(2), { string: ['outDir'] });
const { getOutDir } = require('./lib/utils'); const { getOutDir } = require('./lib/utils');

View file

@ -1,4 +1,4 @@
const fs = require('fs'); const fs = require('node:fs');
const [,, plistPath, outputPath, ...keySet] = process.argv; const [,, plistPath, outputPath, ...keySet] = process.argv;

View file

@ -1,7 +1,7 @@
/* eslint-disable camelcase */ /* eslint-disable camelcase */
const { BlobServiceClient } = require('@azure/storage-blob'); const { BlobServiceClient } = require('@azure/storage-blob');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.ELECTRON_ARTIFACTS_BLOB_STORAGE); const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.ELECTRON_ARTIFACTS_BLOB_STORAGE);

View file

@ -1,5 +1,5 @@
const { spawnSync } = require('child_process'); const { spawnSync } = require('node:child_process');
const path = require('path'); const path = require('node:path');
module.exports.getElectronVersion = () => { module.exports.getElectronVersion = () => {
// Find the nearest tag to the current HEAD // Find the nearest tag to the current HEAD

View file

@ -1,8 +1,8 @@
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const fs = require('fs'); const fs = require('node:fs');
const klaw = require('klaw'); const klaw = require('klaw');
const os = require('os'); const os = require('node:os');
const path = require('path'); const path = require('node:path');
const ELECTRON_DIR = path.resolve(__dirname, '..', '..'); const ELECTRON_DIR = path.resolve(__dirname, '..', '..');
const SRC_DIR = path.resolve(ELECTRON_DIR, '..'); const SRC_DIR = path.resolve(ELECTRON_DIR, '..');

View file

@ -1,12 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
const crypto = require('crypto'); const crypto = require('node:crypto');
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const childProcess = require('child_process'); const childProcess = require('node:child_process');
const { ESLint } = require('eslint'); const { ESLint } = require('eslint');
const fs = require('fs'); const fs = require('node:fs');
const minimist = require('minimist'); const minimist = require('minimist');
const path = require('path'); const path = require('node:path');
const { chunkFilenames, findMatchingFiles } = require('./lib/utils'); const { chunkFilenames, findMatchingFiles } = require('./lib/utils');

View file

@ -1,6 +1,6 @@
const cp = require('child_process'); const cp = require('node:child_process');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const BASE = path.resolve(__dirname, '../..'); const BASE = path.resolve(__dirname, '../..');
const NAN_DIR = path.resolve(BASE, 'third_party', 'nan'); const NAN_DIR = path.resolve(BASE, 'third_party', 'nan');

View file

@ -1,6 +1,6 @@
const cp = require('child_process'); const cp = require('node:child_process');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const args = require('minimist')(process.argv.slice(2), { const args = require('minimist')(process.argv.slice(2), {
boolean: ['default', 'validateDisabled'], boolean: ['default', 'validateDisabled'],

View file

@ -1,9 +1,9 @@
if (!process.env.CI) require('dotenv-safe').load(); if (!process.env.CI) require('dotenv-safe').load();
const assert = require('assert'); const assert = require('node:assert');
const fs = require('fs'); const fs = require('node:fs');
const got = require('got'); const got = require('got');
const path = require('path'); const path = require('node:path');
const { handleGitCall, ELECTRON_DIR } = require('./lib/utils.js'); const { handleGitCall, ELECTRON_DIR } = require('./lib/utils.js');
const { Octokit } = require('@octokit/rest'); const { Octokit } = require('@octokit/rest');
const octokit = new Octokit(); const octokit = new Octokit();

View file

@ -1,5 +1,5 @@
const { appCredentialsFromString, getTokenForRepo } = require('@electron/github-app-auth'); const { appCredentialsFromString, getTokenForRepo } = require('@electron/github-app-auth');
const cp = require('child_process'); const cp = require('node:child_process');
if (!process.env.CIRCLE_BRANCH) { if (!process.env.CIRCLE_BRANCH) {
console.error('Not building for a specific branch, can\'t autopush a patch'); console.error('Not building for a specific branch, can\'t autopush a patch');

View file

@ -1,6 +1,6 @@
if (!process.env.CI) require('dotenv-safe').load(); if (!process.env.CI) require('dotenv-safe').load();
const assert = require('assert'); const assert = require('node:assert');
const got = require('got'); const got = require('got');
const { Octokit } = require('@octokit/rest'); const { Octokit } = require('@octokit/rest');

View file

@ -1,5 +1,5 @@
const got = require('got'); const got = require('got');
const url = require('url'); const url = require('node:url');
module.exports = async function getUrlHash (targetUrl, algorithm = 'sha256', attempts = 3) { module.exports = async function getUrlHash (targetUrl, algorithm = 'sha256', attempts = 3) {
const options = { const options = {

View file

@ -2,7 +2,7 @@
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const minimist = require('minimist'); const minimist = require('minimist');
const path = require('path'); const path = require('node:path');
const semver = require('semver'); const semver = require('semver');
const { ELECTRON_DIR } = require('../../lib/utils'); const { ELECTRON_DIR } = require('../../lib/utils');

View file

@ -2,8 +2,8 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');

View file

@ -6,11 +6,11 @@ const args = require('minimist')(process.argv.slice(2), {
}); });
const ciReleaseBuild = require('./ci-release-build'); const ciReleaseBuild = require('./ci-release-build');
const { Octokit } = require('@octokit/rest'); const { Octokit } = require('@octokit/rest');
const { execSync } = require('child_process'); const { execSync } = require('node:child_process');
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const path = require('path'); const path = require('node:path');
const readline = require('readline'); const readline = require('node:readline');
const releaseNotesGenerator = require('./notes/index.js'); const releaseNotesGenerator = require('./notes/index.js');
const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js'); const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js');
const bumpType = args._[0]; const bumpType = args._[0];

View file

@ -1,7 +1,7 @@
const temp = require('temp'); const temp = require('temp');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const childProcess = require('child_process'); const childProcess = require('node:child_process');
const got = require('got'); const got = require('got');
const semver = require('semver'); const semver = require('semver');

View file

@ -5,7 +5,7 @@ const args = require('minimist')(process.argv.slice(2), {
string: ['tag', 'releaseID'], string: ['tag', 'releaseID'],
default: { releaseID: '' } default: { releaseID: '' }
}); });
const { execSync } = require('child_process'); const { execSync } = require('node:child_process');
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js'); const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js');
const { Octokit } = require('@octokit/rest'); const { Octokit } = require('@octokit/rest');

View file

@ -9,13 +9,13 @@ const args = require('minimist')(process.argv.slice(2), {
], ],
default: { verboseNugget: false } default: { verboseNugget: false }
}); });
const fs = require('fs'); const fs = require('node:fs');
const { execSync } = require('child_process'); const { execSync } = require('node:child_process');
const got = require('got'); const got = require('got');
const path = require('path'); const path = require('node:path');
const semver = require('semver'); const semver = require('semver');
const temp = require('temp').track(); const temp = require('temp').track();
const { URL } = require('url'); const { URL } = require('node:url');
const { BlobServiceClient } = require('@azure/storage-blob'); const { BlobServiceClient } = require('@azure/storage-blob');
const { Octokit } = require('@octokit/rest'); const { Octokit } = require('@octokit/rest');

View file

@ -1,5 +1,5 @@
import { Octokit } from '@octokit/rest'; import { Octokit } from '@octokit/rest';
import * as fs from 'fs'; import * as fs from 'node:fs';
const octokit = new Octokit({ const octokit = new Octokit({
auth: process.env.ELECTRON_GITHUB_TOKEN auth: process.env.ELECTRON_GITHUB_TOKEN

View file

@ -1,8 +1,8 @@
const path = require('path'); const path = require('node:path');
const fs = require('fs'); const fs = require('node:fs');
const semver = require('semver'); const semver = require('semver');
const { GitProcess } = require('dugite'); const { GitProcess } = require('dugite');
const { promisify } = require('util'); const { promisify } = require('node:util');
const { ELECTRON_DIR } = require('../lib/utils'); const { ELECTRON_DIR } = require('../lib/utils');

View file

@ -1,8 +1,8 @@
import * as childProcess from 'child_process'; import * as childProcess from 'node:child_process';
import * as fs from 'fs'; import * as fs from 'node:fs';
import * as minimist from 'minimist'; import * as minimist from 'minimist';
import * as os from 'os'; import * as os from 'node:os';
import * as path from 'path'; import * as path from 'node:path';
import * as streamChain from 'stream-chain'; import * as streamChain from 'stream-chain';
import * as streamJson from 'stream-json'; import * as streamJson from 'stream-json';
import { ignore as streamJsonIgnore } from 'stream-json/filters/Ignore'; import { ignore as streamJsonIgnore } from 'stream-json/filters/Ignore';

View file

@ -1,5 +1,5 @@
const cp = require('child_process'); const cp = require('node:child_process');
const fs = require('fs'); const fs = require('node:fs');
const checkPath = process.argv[2]; const checkPath = process.argv[2];
const command = process.argv.slice(3); const command = process.argv.slice(3);

View file

@ -1,12 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
const { ElectronVersions, Installer } = require('@electron/fiddle-core'); const { ElectronVersions, Installer } = require('@electron/fiddle-core');
const childProcess = require('child_process'); const childProcess = require('node:child_process');
const crypto = require('crypto'); const crypto = require('node:crypto');
const fs = require('fs-extra'); const fs = require('fs-extra');
const { hashElement } = require('folder-hash'); const { hashElement } = require('folder-hash');
const os = require('os'); const os = require('node:os');
const path = require('path'); const path = require('node:path');
const unknownFlags = []; const unknownFlags = [];
require('colors'); require('colors');

View file

@ -1,4 +1,4 @@
const cp = require('child_process'); const cp = require('node:child_process');
const utils = require('./lib/utils'); const utils = require('./lib/utils');
const electronPath = utils.getAbsoluteElectronExec(); const electronPath = utils.getAbsoluteElectronExec();

View file

@ -1,6 +1,6 @@
const cp = require('child_process'); const cp = require('node:child_process');
const fs = require('fs'); const fs = require('node:fs');
const path = require('path'); const path = require('node:path');
const YARN_VERSION = /'yarn_version': '(.+?)'/.exec(fs.readFileSync(path.resolve(__dirname, '../DEPS'), 'utf8'))[1]; const YARN_VERSION = /'yarn_version': '(.+?)'/.exec(fs.readFileSync(path.resolve(__dirname, '../DEPS'), 'utf8'))[1];
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx'; const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';