build: auto-generate the browserify step GN inputs (#17626)

This commit is contained in:
Samuel Attard 2019-04-02 17:12:10 -07:00 committed by GitHub
parent 53f6cbccbf
commit dc4fe537ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 164 additions and 25 deletions

View file

@ -76,15 +76,7 @@ npm_action("atom_browserify_sandbox") {
":build_electron_definitions", ":build_electron_definitions",
] ]
inputs = [ inputs = auto_filenames.sandbox_browserify_deps
# FIXME(zcbenz): The dependencies of these files are not listed here, so
# the generated file will be out-dated when dependencies are modified.
# Use a script to generate all dependencies and put them here.
"lib/sandboxed_renderer/init.js",
"lib/sandboxed_renderer/api/exports/electron.js",
"tsconfig.electron.json",
"tsconfig.json",
]
outputs = [ outputs = [
"$target_gen_dir/js2c/preload_bundle.js", "$target_gen_dir/js2c/preload_bundle.js",
@ -113,11 +105,7 @@ npm_action("atom_browserify_isolated") {
":build_electron_definitions", ":build_electron_definitions",
] ]
inputs = [ inputs = auto_filenames.isolated_browserify_deps
"lib/isolated_renderer/init.js",
"tsconfig.electron.json",
"tsconfig.json",
]
outputs = [ outputs = [
"$target_gen_dir/js2c/isolated_bundle.js", "$target_gen_dir/js2c/isolated_bundle.js",
@ -144,11 +132,7 @@ npm_action("atom_browserify_content_script") {
":build_electron_definitions", ":build_electron_definitions",
] ]
inputs = [ inputs = auto_filenames.context_script_browserify_deps
"lib/content_script/init.js",
"tsconfig.electron.json",
"tsconfig.json",
]
outputs = [ outputs = [
"$target_gen_dir/js2c/content_script_bundle.js", "$target_gen_dir/js2c/content_script_bundle.js",

View file

@ -109,4 +109,73 @@ auto_filenames = {
"docs/api/structures/upload-raw-data.md", "docs/api/structures/upload-raw-data.md",
"docs/api/structures/web-source.md", "docs/api/structures/web-source.md",
] ]
sandbox_browserify_deps = [
"lib/browser/api/module-list.js",
"lib/common/api/deprecate.ts",
"lib/common/api/is-promise.js",
"lib/common/api/module-list.js",
"lib/common/api/native-image.js",
"lib/common/atom-binding-setup.ts",
"lib/common/buffer-utils.js",
"lib/common/crash-reporter.js",
"lib/common/error-utils.js",
"lib/common/web-view-methods.js",
"lib/renderer/api/crash-reporter.js",
"lib/renderer/api/desktop-capturer.js",
"lib/renderer/api/ipc-renderer.js",
"lib/renderer/api/remote.js",
"lib/renderer/api/web-frame.ts",
"lib/renderer/callbacks-registry.js",
"lib/renderer/chrome-api.ts",
"lib/renderer/content-scripts-injector.ts",
"lib/renderer/extensions/event.js",
"lib/renderer/extensions/i18n.js",
"lib/renderer/extensions/storage.js",
"lib/renderer/extensions/web-navigation.js",
"lib/renderer/inspector.ts",
"lib/renderer/ipc-renderer-internal-utils.ts",
"lib/renderer/ipc-renderer-internal.ts",
"lib/renderer/security-warnings.ts",
"lib/renderer/web-frame-init.ts",
"lib/renderer/web-view/guest-view-internal.ts",
"lib/renderer/web-view/web-view-attributes.ts",
"lib/renderer/web-view/web-view-element.ts",
"lib/renderer/web-view/web-view-impl.ts",
"lib/renderer/web-view/web-view-init.ts",
"lib/sandboxed_renderer/api/exports/electron.js",
"lib/sandboxed_renderer/api/module-list.js",
"lib/sandboxed_renderer/init.js",
"tsconfig.json",
"tsconfig.electron.json",
"package.json",
]
isolated_browserify_deps = [
"lib/common/atom-binding-setup.ts",
"lib/isolated_renderer/init.js",
"lib/renderer/ipc-renderer-internal.ts",
"lib/renderer/web-view/web-view-element.ts",
"lib/renderer/window-setup.ts",
"tsconfig.json",
"tsconfig.electron.json",
"package.json",
]
context_script_browserify_deps = [
"lib/common/atom-binding-setup.ts",
"lib/common/error-utils.js",
"lib/content_script/init.js",
"lib/renderer/chrome-api.ts",
"lib/renderer/extensions/event.js",
"lib/renderer/extensions/i18n.js",
"lib/renderer/extensions/storage.js",
"lib/renderer/extensions/web-navigation.js",
"lib/renderer/ipc-renderer-internal-utils.ts",
"lib/renderer/ipc-renderer-internal.ts",
"lib/renderer/window-setup.ts",
"tsconfig.json",
"tsconfig.electron.json",
"package.json",
]
} }

View file

@ -104,6 +104,10 @@
"node script/lint.js --js --fix --only --", "node script/lint.js --js --fix --only --",
"git add" "git add"
], ],
"*.{js,ts,d.ts}": [
"node script/gen-filenames.js",
"git add"
],
"*.{cc,mm,c,h}": [ "*.{cc,mm,c,h}": [
"python script/run-clang-format.py -r -c --fix", "python script/run-clang-format.py -r -c --fix",
"git add" "git add"

View file

@ -1,6 +1,9 @@
const fs = require('fs') const cp = require('child_process')
const fs = require('fs-extra')
const os = require('os')
const path = require('path') const path = require('path')
const rootPath = path.resolve(__dirname, '..')
const gniPath = path.resolve(__dirname, '../filenames.auto.gni') const gniPath = path.resolve(__dirname, '../filenames.auto.gni')
const allDocs = fs.readdirSync(path.resolve(__dirname, '../docs/api')) const allDocs = fs.readdirSync(path.resolve(__dirname, '../docs/api'))
@ -10,6 +13,74 @@ const allDocs = fs.readdirSync(path.resolve(__dirname, '../docs/api'))
.map(doc => `docs/api/structures/${doc}`) .map(doc => `docs/api/structures/${doc}`)
) )
const main = async () => {
const browserifyTargets = [
{
name: 'sandbox_browserify_deps',
entry: 'lib/sandboxed_renderer/init.js'
},
{
name: 'isolated_browserify_deps',
entry: 'lib/isolated_renderer/init.js'
},
{
name: 'context_script_browserify_deps',
entry: 'lib/content_script/init.js'
}
]
await Promise.all(browserifyTargets.map(async browserifyTarget => {
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'))
const child = cp.spawn('node', [
'node_modules/browserify/bin/cmd.js',
browserifyTarget.entry,
...(browserifyTarget.name === 'sandbox_browserify_deps' ? [
'-r',
'./lib/sandboxed_renderer/api/exports/electron.js:electron'
] : []),
'-t',
'aliasify',
'-p',
'[',
'tsify',
'-p',
'tsconfig.electron.json',
']',
'-o',
path.resolve(tmpDir, 'out.js'),
'--list'
], {
cwd: path.resolve(__dirname, '..')
})
let output = ''
child.stdout.on('data', chunk => {
output += chunk.toString()
})
await new Promise((resolve, reject) => child.on('exit', (code) => {
if (code !== 0) return reject(new Error(`Failed to list browserify dependencies for entry: ${browserifyTarget.name}`))
resolve()
}))
browserifyTarget.dependencies = output
.split('\n')
// Remove whitespace
.map(line => line.trim())
// Ignore empty lines
.filter(line => line)
// Get the relative path
.map(line => path.relative(rootPath, line))
// Only care about files in //electron
.filter(line => !line.startsWith('..'))
// Only care about our own files
.filter(line => !line.startsWith('node_modules'))
// Make the generated list easier to read
.sort()
// All browserify commands depend on the tsconfig and package json files
.concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json'])
await fs.remove(tmpDir)
}))
fs.writeFileSync( fs.writeFileSync(
gniPath, gniPath,
`# THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT BY HAND `# THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT BY HAND
@ -17,6 +88,17 @@ auto_filenames = {
api_docs = [ api_docs = [
${allDocs.map(doc => ` "${doc}",`).join('\n')} ${allDocs.map(doc => ` "${doc}",`).join('\n')}
] ]
${browserifyTargets.map(target => ` ${target.name} = [
${target.dependencies.map(dep => ` "${dep}",`).join('\n')}
]`).join('\n\n')}
}
`)
}
if (process.mainModule === module) {
main().catch((err) => {
console.error(err)
process.exit(1)
})
} }
`
)