Skip to content

Commit cbb4757

Browse files
build: run the JS linter on the build folder (electron#24513)
1 parent e18f508 commit cbb4757

9 files changed

+60
-60
lines changed

build/webpack/get-outputs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
process.env.PRINT_WEBPACK_GRAPH = true
2-
require('./run-compiler')
1+
process.env.PRINT_WEBPACK_GRAPH = true;
2+
require('./run-compiler');

build/webpack/run-compiler.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
const fs = require('fs');
2-
const path = require('path')
3-
const webpack = require('webpack')
2+
const path = require('path');
3+
const webpack = require('webpack');
44

5-
const configPath = process.argv[2]
6-
const outPath = path.resolve(process.argv[3])
7-
const config = require(configPath)
5+
const configPath = process.argv[2];
6+
const outPath = path.resolve(process.argv[3]);
7+
const config = require(configPath);
88
config.output = {
99
path: path.dirname(outPath),
1010
filename: path.basename(outPath)
11-
}
11+
};
1212

1313
const { wrapInitWithProfilingTimeout } = config;
1414
delete config.wrapInitWithProfilingTimeout;
1515

1616
webpack(config, (err, stats) => {
1717
if (err) {
18-
console.error(err)
19-
process.exit(1)
18+
console.error(err);
19+
process.exit(1);
2020
} else if (stats.hasErrors()) {
21-
console.error(stats.toString('normal'))
22-
process.exit(1)
21+
console.error(stats.toString('normal'));
22+
process.exit(1);
2323
} else {
2424
if (wrapInitWithProfilingTimeout) {
2525
const contents = fs.readFileSync(outPath, 'utf8');
@@ -33,6 +33,6 @@ if ((globalThis.process || binding.process).argv.includes("--profile-electron-in
3333
}`;
3434
fs.writeFileSync(outPath, newContents);
3535
}
36-
process.exit(0)
36+
process.exit(0);
3737
}
38-
})
38+
});
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const webpack = require('webpack')
1+
const fs = require('fs');
2+
const path = require('path');
3+
const webpack = require('webpack');
44
const TerserPlugin = require('terser-webpack-plugin');
55

6-
const electronRoot = path.resolve(__dirname, '../..')
6+
const electronRoot = path.resolve(__dirname, '../..');
77

8-
const onlyPrintingGraph = !!process.env.PRINT_WEBPACK_GRAPH
8+
const onlyPrintingGraph = !!process.env.PRINT_WEBPACK_GRAPH;
99

1010
class AccessDependenciesPlugin {
11-
apply(compiler) {
11+
apply (compiler) {
1212
// Only hook into webpack when we are printing the dependency graph
13-
if (!onlyPrintingGraph) return
13+
if (!onlyPrintingGraph) return;
1414

1515
compiler.hooks.compilation.tap('AccessDependenciesPlugin', compilation => {
1616
compilation.hooks.finishModules.tap('AccessDependenciesPlugin', modules => {
17-
const filePaths = modules.map(m => m.resource).filter(p => p).map(p => path.relative(electronRoot, p))
18-
console.info(JSON.stringify(filePaths))
19-
})
20-
})
17+
const filePaths = modules.map(m => m.resource).filter(p => p).map(p => path.relative(electronRoot, p));
18+
console.info(JSON.stringify(filePaths));
19+
});
20+
});
2121
}
2222
}
2323

2424
const defines = {
2525
BUILDFLAG: onlyPrintingGraph ? '(a => a)' : ''
26-
}
26+
};
2727

28-
const buildFlagsPrefix = '--buildflags='
28+
const buildFlagsPrefix = '--buildflags=';
2929
const buildFlagArg = process.argv.find(arg => arg.startsWith(buildFlagsPrefix));
3030

3131
if (buildFlagArg) {
32-
const buildFlagPath = buildFlagArg.substr(buildFlagsPrefix.length)
32+
const buildFlagPath = buildFlagArg.substr(buildFlagsPrefix.length);
3333

34-
const flagFile = fs.readFileSync(buildFlagPath, 'utf8')
34+
const flagFile = fs.readFileSync(buildFlagPath, 'utf8');
3535
for (const line of flagFile.split(/(\r\n|\r|\n)/g)) {
36-
const flagMatch = line.match(/#define BUILDFLAG_INTERNAL_(.+?)\(\) \(([01])\)/)
36+
const flagMatch = line.match(/#define BUILDFLAG_INTERNAL_(.+?)\(\) \(([01])\)/);
3737
if (flagMatch) {
3838
const [, flagName, flagValue] = flagMatch;
3939
defines[flagName] = JSON.stringify(Boolean(parseInt(flagValue, 10)));
4040
}
4141
}
4242
}
4343

44-
const ignoredModules = []
44+
const ignoredModules = [];
4545

46-
if (defines['ENABLE_DESKTOP_CAPTURER'] === 'false') {
46+
if (defines.ENABLE_DESKTOP_CAPTURER === 'false') {
4747
ignoredModules.push(
4848
'@electron/internal/browser/desktop-capturer',
4949
'@electron/internal/browser/api/desktop-capturer',
5050
'@electron/internal/renderer/api/desktop-capturer'
51-
)
51+
);
5252
}
5353

54-
if (defines['ENABLE_REMOTE_MODULE'] === 'false') {
54+
if (defines.ENABLE_REMOTE_MODULE === 'false') {
5555
ignoredModules.push(
5656
'@electron/internal/browser/remote/server',
5757
'@electron/internal/renderer/api/remote'
58-
)
58+
);
5959
}
6060

61-
if (defines['ENABLE_VIEWS_API'] === 'false') {
61+
if (defines.ENABLE_VIEWS_API === 'false') {
6262
ignoredModules.push(
6363
'@electron/internal/browser/api/views/image-view.js'
64-
)
64+
);
6565
}
6666

6767
module.exports = ({
@@ -71,9 +71,9 @@ module.exports = ({
7171
target,
7272
wrapInitWithProfilingTimeout
7373
}) => {
74-
let entry = path.resolve(electronRoot, 'lib', target, 'init.ts')
74+
let entry = path.resolve(electronRoot, 'lib', target, 'init.ts');
7575
if (!fs.existsSync(entry)) {
76-
entry = path.resolve(electronRoot, 'lib', target, 'init.js')
76+
entry = path.resolve(electronRoot, 'lib', target, 'init.js');
7777
}
7878

7979
return ({
@@ -88,16 +88,16 @@ module.exports = ({
8888
resolve: {
8989
alias: {
9090
'@electron/internal': path.resolve(electronRoot, 'lib'),
91-
'electron': path.resolve(electronRoot, 'lib', loadElectronFromAlternateTarget || target, 'api', 'exports', 'electron.ts'),
91+
electron: path.resolve(electronRoot, 'lib', loadElectronFromAlternateTarget || target, 'api', 'exports', 'electron.ts'),
9292
// Force timers to resolve to our dependency that doesn't use window.postMessage
93-
'timers': path.resolve(electronRoot, 'node_modules', 'timers-browserify', 'main.js')
93+
timers: path.resolve(electronRoot, 'node_modules', 'timers-browserify', 'main.js')
9494
},
9595
extensions: ['.ts', '.js']
9696
},
9797
module: {
9898
rules: [{
9999
test: (moduleName) => !onlyPrintingGraph && ignoredModules.includes(moduleName),
100-
loader: 'null-loader',
100+
loader: 'null-loader'
101101
}, {
102102
test: /\.ts$/,
103103
loader: 'ts-loader',
@@ -106,7 +106,7 @@ module.exports = ({
106106
transpileOnly: onlyPrintingGraph,
107107
ignoreDiagnostics: [
108108
// File '{0}' is not under 'rootDir' '{1}'.
109-
6059,
109+
6059
110110
]
111111
}
112112
}]
@@ -116,32 +116,32 @@ module.exports = ({
116116
__filename: false,
117117
// We provide our own "timers" import above, any usage of setImmediate inside
118118
// one of our renderer bundles should import it from the 'timers' package
119-
setImmediate: false,
119+
setImmediate: false
120120
},
121121
optimization: {
122122
minimize: true,
123123
minimizer: [
124124
new TerserPlugin({
125125
terserOptions: {
126126
keep_classnames: true,
127-
keep_fnames: true,
128-
},
129-
}),
130-
],
127+
keep_fnames: true
128+
}
129+
})
130+
]
131131
},
132132
plugins: [
133133
new AccessDependenciesPlugin(),
134134
...(targetDeletesNodeGlobals ? [
135135
new webpack.ProvidePlugin({
136136
process: ['@electron/internal/renderer/webpack-provider', 'process'],
137137
global: ['@electron/internal/renderer/webpack-provider', '_global'],
138-
Buffer: ['@electron/internal/renderer/webpack-provider', 'Buffer'],
138+
Buffer: ['@electron/internal/renderer/webpack-provider', 'Buffer']
139139
})
140140
] : []),
141141
new webpack.ProvidePlugin({
142-
Promise: ['@electron/internal/common/webpack-globals-provider', 'Promise'],
142+
Promise: ['@electron/internal/common/webpack-globals-provider', 'Promise']
143143
}),
144-
new webpack.DefinePlugin(defines),
144+
new webpack.DefinePlugin(defines)
145145
]
146-
})
147-
}
146+
});
147+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = require('./webpack.config.base')({
22
target: 'browser',
33
alwaysHasNode: true
4-
})
4+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = require('./webpack.config.base')({
22
target: 'isolated_renderer',
33
alwaysHasNode: false
4-
})
4+
});

build/webpack/webpack.config.renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = require('./webpack.config.base')({
33
alwaysHasNode: true,
44
targetDeletesNodeGlobals: true,
55
wrapInitWithProfilingTimeout: true
6-
})
6+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = require('./webpack.config.base')({
22
target: 'sandboxed_renderer',
33
alwaysHasNode: false,
4-
wrapInitWithProfilingTimeout: true,
5-
})
4+
wrapInitWithProfilingTimeout: true
5+
});

build/webpack/webpack.config.worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = require('./webpack.config.base')({
33
loadElectronFromAlternateTarget: 'renderer',
44
alwaysHasNode: true,
55
targetDeletesNodeGlobals: true
6-
})
6+
});

script/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const LINTERS = [{
9090
}
9191
}, {
9292
key: 'javascript',
93-
roots: ['lib', 'spec', 'spec-main', 'script', 'default_app'],
93+
roots: ['lib', 'spec', 'spec-main', 'script', 'default_app', 'build'],
9494
ignoreRoots: ['spec/node_modules', 'spec-main/node_modules'],
9595
test: filename => filename.endsWith('.js') || filename.endsWith('.ts'),
9696
run: (opts, filenames) => {

0 commit comments

Comments
 (0)