From 4d50f3f62c6d1e6fe6f9bfb9a26c543bf356c283 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 7 Aug 2020 13:48:46 -0700 Subject: [PATCH] build: convert some scripts to TS (#24891) --- package.json | 6 +-- ...heck-patch-diff.js => check-patch-diff.ts} | 5 +-- .../codesign/{gen-trust.js => gen-trust.ts} | 6 +-- script/codesign/generate-identity.sh | 2 +- script/{gen-filenames.js => gen-filenames.ts} | 42 ++++++++++--------- 5 files changed, 32 insertions(+), 29 deletions(-) rename script/{check-patch-diff.js => check-patch-diff.ts} (82%) rename script/codesign/{gen-trust.js => gen-trust.ts} (92%) rename script/{gen-filenames.js => gen-filenames.ts} (68%) diff --git a/package.json b/package.json index a7a3a1c5a25..1a277e6d169 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "node script/lint.js --js --fix --only --" ], "*.{js,ts,d.ts}": [ - "node script/gen-filenames.js" + "ts-node script/gen-filenames.ts" ], "*.{cc,mm,c,h}": [ "python script/run-clang-format.py -r -c --fix" @@ -124,13 +124,13 @@ "node script/lint.js --py --fix --only --" ], "docs/api/**/*.md": [ - "node script/gen-filenames.js", + "ts-node script/gen-filenames.ts", "python script/check-trailing-whitespace.py --fix", "git add filenames.auto.gni" ], "{*.patch,.patches}": [ "node script/lint.js --patches --only --", - "node script/check-patch-diff.js" + "ts-node script/check-patch-diff.ts" ], "DEPS": [ "node script/gen-hunspell-filenames.js" diff --git a/script/check-patch-diff.js b/script/check-patch-diff.ts similarity index 82% rename from script/check-patch-diff.js rename to script/check-patch-diff.ts index 98b138fbca3..8b2bccc26d6 100644 --- a/script/check-patch-diff.js +++ b/script/check-patch-diff.ts @@ -1,6 +1,5 @@ -const { spawnSync } = require('child_process'); -const path = require('path'); -const { inspect } = require('util'); +import { spawnSync } from 'child_process'; +import * as path from 'path'; const srcPath = path.resolve(__dirname, '..', '..', '..'); const patchExportFnPath = path.resolve(__dirname, 'export_all_patches.py'); diff --git a/script/codesign/gen-trust.js b/script/codesign/gen-trust.ts similarity index 92% rename from script/codesign/gen-trust.js rename to script/codesign/gen-trust.ts index 9dca60aab0b..3f39f0e74b6 100644 --- a/script/codesign/gen-trust.js +++ b/script/codesign/gen-trust.ts @@ -1,6 +1,6 @@ -const cp = require('child_process'); -const fs = require('fs'); -const path = require('path'); +import * as cp from 'child_process'; +import * as fs from 'fs'; +import * as path from 'path'; const certificatePath = process.argv[2]; const outPath = process.argv[3]; diff --git a/script/codesign/generate-identity.sh b/script/codesign/generate-identity.sh index 27a1c8f244f..025662ffc3b 100755 --- a/script/codesign/generate-identity.sh +++ b/script/codesign/generate-identity.sh @@ -40,7 +40,7 @@ DevToolsSecurity -enable # security import "$dir"/public.key -k $KEY_CHAIN # Generate Trust Settings -node "$(dirname $0)"/gen-trust.js "$dir"/certificate.cer "$dir"/trust.xml +npx ts-node node "$(dirname $0)"/gen-trust.ts "$dir"/certificate.cer "$dir"/trust.xml # Import Trust Settings sudo security trust-settings-import -d "$dir/trust.xml" diff --git a/script/gen-filenames.js b/script/gen-filenames.ts similarity index 68% rename from script/gen-filenames.js rename to script/gen-filenames.ts index 18018995481..d9c93c84d47 100644 --- a/script/gen-filenames.js +++ b/script/gen-filenames.ts @@ -1,7 +1,7 @@ -const cp = require('child_process'); -const fs = require('fs-extra'); -const os = require('os'); -const path = require('path'); +import * as cp from 'child_process'; +import * as fs from 'fs-extra'; +import * as os from 'os'; +import * as path from 'path'; const rootPath = path.resolve(__dirname, '..'); const gniPath = path.resolve(__dirname, '../filenames.auto.gni'); @@ -43,7 +43,7 @@ const main = async () => { } ]; - await Promise.all(webpackTargets.map(async webpackTarget => { + const webpackTargetsWithDeps = await Promise.all(webpackTargets.map(async webpackTarget => { const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-')); const child = cp.spawn('node', [ 'build/webpack/get-outputs.js', @@ -66,20 +66,24 @@ const main = async () => { resolve(); })); - webpackTarget.dependencies = JSON.parse(output) - // Remove whitespace - .map(line => line.trim()) - // Get the relative path - .map(line => path.relative(rootPath, line).replace(/\\/g, '/')) - // Only care about files in //electron - .filter(line => !line.startsWith('..')) - // Only care about our own files - .filter(line => !line.startsWith('node_modules')) - // All webpack builds depend on the tsconfig and package json files - .concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json', ...typingFiles]) - // Make the generated list easier to read - .sort(); + const webpackTargetWithDeps = { + ...webpackTarget, + dependencies: (JSON.parse(output) as string[]) + // Remove whitespace + .map(line => line.trim()) + // Get the relative path + .map(line => path.relative(rootPath, line).replace(/\\/g, '/')) + // Only care about files in //electron + .filter(line => !line.startsWith('..')) + // Only care about our own files + .filter(line => !line.startsWith('node_modules')) + // All webpack builds depend on the tsconfig and package json files + .concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json', ...typingFiles]) + // Make the generated list easier to read + .sort() + }; await fs.remove(tmpDir); + return webpackTargetWithDeps; })); fs.writeFileSync( @@ -90,7 +94,7 @@ auto_filenames = { ${allDocs.map(doc => ` "${doc}",`).join('\n')} ] -${webpackTargets.map(target => ` ${target.name} = [ +${webpackTargetsWithDeps.map(target => ` ${target.name} = [ ${target.dependencies.map(dep => ` "${dep}",`).join('\n')} ]`).join('\n\n')} }