build: lint the npm folder (#26085)

This commit is contained in:
David Sanders 2020-10-21 15:43:52 -07:00 committed by GitHub
parent 22cb3cd18b
commit 2aa5a1f494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 51 deletions

View file

@ -1,25 +1,25 @@
#!/usr/bin/env node #!/usr/bin/env node
var electron = require('./') const electron = require('./');
var proc = require('child_process') const proc = require('child_process');
var child = proc.spawn(electron, process.argv.slice(2), { stdio: 'inherit', windowsHide: false }) const child = proc.spawn(electron, process.argv.slice(2), { stdio: 'inherit', windowsHide: false });
child.on('close', function (code, signal) { child.on('close', function (code, signal) {
if (code === null) { if (code === null) {
console.error(electron, 'exited with signal', signal) console.error(electron, 'exited with signal', signal);
process.exit(1) process.exit(1);
} }
process.exit(code) process.exit(code);
}) });
const handleTerminationSignal = function (signal) { const handleTerminationSignal = function (signal) {
process.on(signal, function signalHandler () { process.on(signal, function signalHandler () {
if (!child.killed) { if (!child.killed) {
child.kill(signal) child.kill(signal);
} }
}) });
} };
handleTerminationSignal('SIGINT') handleTerminationSignal('SIGINT');
handleTerminationSignal('SIGTERM') handleTerminationSignal('SIGTERM');

View file

@ -1,18 +1,18 @@
var fs = require('fs') const fs = require('fs');
var path = require('path') const path = require('path');
var pathFile = path.join(__dirname, 'path.txt') const pathFile = path.join(__dirname, 'path.txt');
function getElectronPath () { function getElectronPath () {
if (fs.existsSync(pathFile)) { if (fs.existsSync(pathFile)) {
var executablePath = fs.readFileSync(pathFile, 'utf-8') const executablePath = fs.readFileSync(pathFile, 'utf-8');
if (process.env.ELECTRON_OVERRIDE_DIST_PATH) { if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {
return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath) return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath);
} }
return path.join(__dirname, 'dist', executablePath) return path.join(__dirname, 'dist', executablePath);
} else { } else {
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again') throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
} }
} }
module.exports = getElectronPath() module.exports = getElectronPath();

View file

@ -1,21 +1,21 @@
#!/usr/bin/env node #!/usr/bin/env node
const {version} = require('./package') const { version } = require('./package');
const fs = require('fs') const fs = require('fs');
const os = require('os') const os = require('os');
const path = require('path') const path = require('path');
const extract = require('extract-zip') const extract = require('extract-zip');
const { downloadArtifact } = require('@electron/get') const { downloadArtifact } = require('@electron/get');
if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) { if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
process.exit(0) process.exit(0);
} }
const platformPath = getPlatformPath() const platformPath = getPlatformPath();
if (isInstalled()) { if (isInstalled()) {
process.exit(0) process.exit(0);
} }
// downloads if not cached // downloads if not cached
@ -27,57 +27,57 @@ downloadArtifact({
platform: process.env.npm_config_platform || process.platform, platform: process.env.npm_config_platform || process.platform,
arch: process.env.npm_config_arch || process.arch arch: process.env.npm_config_arch || process.arch
}).then(extractFile).catch(err => { }).then(extractFile).catch(err => {
console.error(err.stack) console.error(err.stack);
process.exit(1) process.exit(1);
}) });
function isInstalled () { function isInstalled () {
try { try {
if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) { if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
return false return false;
} }
if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) { if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) {
return false return false;
} }
} catch (ignored) { } catch (ignored) {
return false return false;
} }
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath) const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath);
return fs.existsSync(electronPath) return fs.existsSync(electronPath);
} }
// unzips and makes path.txt point at the correct executable // unzips and makes path.txt point at the correct executable
function extractFile (zipPath) { function extractFile (zipPath) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extract(zipPath, { dir: path.join(__dirname, 'dist') }, err => { extract(zipPath, { dir: path.join(__dirname, 'dist') }, err => {
if (err) return reject(err) if (err) return reject(err);
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, err => { fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, err => {
if (err) return reject(err) if (err) return reject(err);
resolve() resolve();
}) });
}) });
}) });
} }
function getPlatformPath () { function getPlatformPath () {
const platform = process.env.npm_config_platform || os.platform() const platform = process.env.npm_config_platform || os.platform();
switch (platform) { switch (platform) {
case 'mas': case 'mas':
case 'darwin': case 'darwin':
return 'Electron.app/Contents/MacOS/Electron' return 'Electron.app/Contents/MacOS/Electron';
case 'freebsd': case 'freebsd':
case 'openbsd': case 'openbsd':
case 'linux': case 'linux':
return 'electron' return 'electron';
case 'win32': case 'win32':
return 'electron.exe' return 'electron.exe';
default: default:
throw new Error('Electron builds are not available on platform: ' + platform) throw new Error('Electron builds are not available on platform: ' + platform);
} }
} }

View file

@ -93,7 +93,7 @@ const LINTERS = [{
} }
}, { }, {
key: 'javascript', key: 'javascript',
roots: ['lib', 'spec', 'spec-main', 'script', 'default_app', 'build'], roots: ['build', 'default_app', 'lib', 'npm', 'script', 'spec', 'spec-main'],
ignoreRoots: ['spec/node_modules', 'spec-main/node_modules'], ignoreRoots: ['spec/node_modules', 'spec-main/node_modules'],
test: filename => filename.endsWith('.js') || filename.endsWith('.ts'), test: filename => filename.endsWith('.js') || filename.endsWith('.ts'),
run: (opts, filenames) => { run: (opts, filenames) => {