Skip to content

Commit 9da3bc7

Browse files
committed
Revert "chore(chromium): add chromium to cli and lib (#400)"
This reverts commit e2c7d2b.
1 parent 1c85882 commit 9da3bc7

File tree

7 files changed

+8
-141
lines changed

7 files changed

+8
-141
lines changed

lib/cli/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ const chromedriverLogsOption: yargs.Options = {
1818
describe: 'File path to chrome logs.',
1919
type: 'string'
2020
};
21-
const CHROMIUM = 'chromium';
22-
const chromiumOptions: yargs.Options = {
23-
describe: 'Download chromium.',
24-
default: false,
25-
type: 'boolean'
26-
};
2721
const DETACH = 'detach';
2822
const detachOption: yargs.Options = {
2923
describe: 'Once the selenium server is up and running, return ' +
@@ -74,11 +68,6 @@ const maxVersionsChromedriverOption: yargs.Options = {
7468
describe: 'The chromedriver max version used only for update.',
7569
type: 'string'
7670
};
77-
const MAX_VERSIONS_CHROMIUM = 'max_versions.chromium';
78-
const maxVersionsChromiumOptions: yargs.Options = {
79-
describe: 'The chromium max version used only for update.',
80-
type: 'string'
81-
};
8271
const MAX_VERSIONS_GECKODRIVER_ALIAS = 'max_versions.gecko';
8372
const MAX_VERSIONS_GECKODRIVER = 'max_versions.geckodriver';
8473
const maxVersionsGeckodriverOption: yargs.Options = {
@@ -225,7 +214,6 @@ yargs
225214
return yargs.option(OUT_DIR, outDirOption)
226215
.option(CHROMEDRIVER, chromedriverOption)
227216
.alias(CHROMEDRIVER_ALIAS, CHROMEDRIVER)
228-
.option(CHROMIUM, chromiumOptions)
229217
.option(GECKODRIVER, geckodriverOption)
230218
.alias(GECKODRIVER_ALIAS, GECKODRIVER)
231219
.option(GITHUB_TOKEN, githubTokenOption)
@@ -235,13 +223,11 @@ yargs
235223
.option(LOG_LEVEL, logLevelOption)
236224
.option(MAX_VERSIONS_CHROMEDRIVER, maxVersionsChromedriverOption)
237225
.alias(MAX_VERSIONS_CHROMEDRIVER_ALIAS, MAX_VERSIONS_CHROMEDRIVER)
238-
.option(MAX_VERSIONS_CHROMIUM, maxVersionsChromiumOptions)
239226
.option(MAX_VERSIONS_GECKODRIVER, maxVersionsGeckodriverOption)
240227
.alias(MAX_VERSIONS_GECKODRIVER_ALIAS, MAX_VERSIONS_GECKODRIVER)
241228
.option(MAX_VERSIONS_IEDRIVER, maxVersionsIedriverOption)
242229
.alias(MAX_VERSIONS_IEDRIVER_ALIAS, MAX_VERSIONS_IEDRIVER)
243230
.option(MAX_VERSIONS_SELENIUM, maxVersionsSeleniumOption)
244-
.alias(MAX_VERSIONS_SELENIUM_ALIAS, MAX_VERSIONS_SELENIUM)
245231
.option(OUT_DIR, outDirOption)
246232
.option(PROXY, proxyOption)
247233
.option(SELENIUM, seleniumOption)

lib/cmds/options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export interface Options {
1616
githubToken?: string;
1717
}
1818

19-
export type BrowserDriverName =
20-
'chromedriver'|'geckodriver'|'iedriver'|'chromium';
19+
export type BrowserDriverName = 'chromedriver'|'geckodriver'|'iedriver';
2120

2221
/**
2322
* Contains information about a browser driver.

lib/cmds/utils.spec-unit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('utils', () => {
1313
};
1414
const options = convertArgs2AllOptions(argv);
1515
expect(options.browserDrivers).toBeTruthy();
16-
expect(options.browserDrivers.length).toBe(4);
16+
expect(options.browserDrivers.length).toBe(3);
1717
expect(options.server).toBeTruthy();
1818
expect(options.server.name).toBe('selenium');
1919
expect(options.outDir).toBe('foobar_download');

lib/cmds/utils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {SeleniumServer, SeleniumServerProviderConfig} from '../provider/selenium
77

88
import {BrowserDriver, BrowserDriverName, Options} from './options';
99
import {OptionsBinary} from './options_binary';
10-
import { Chromium } from '../provider/chromium';
1110

1211
/**
1312
* Converts an options object into an options binary object.
@@ -28,8 +27,6 @@ export function addOptionsBinary(options: Options): OptionsBinary {
2827
for (const browserDriver of optionsBinary.browserDrivers) {
2928
if (browserDriver.name === 'chromedriver') {
3029
browserDriver.binary = new ChromeDriver(providerConfig);
31-
} else if (browserDriver.name === 'chromium') {
32-
browserDriver.binary = new Chromium(providerConfig);
3330
} else if (browserDriver.name === 'geckodriver') {
3431
const geckoProviderConfig = providerConfig;
3532
geckoProviderConfig.oauthToken = optionsBinary.githubToken;
@@ -60,7 +57,6 @@ export function convertArgs2AllOptions(argv: yargs.Arguments): Options {
6057
return {
6158
browserDrivers: [
6259
{name: 'chromedriver'},
63-
{name: 'chromium'},
6460
{name: 'geckodriver'},
6561
{name: 'iedriver'}
6662
],
@@ -87,9 +83,6 @@ export function convertArgs2Options(argv: yargs.Arguments): Options {
8783
if (argv['chromedriver'] as boolean) {
8884
setVersions('chromedriver', argv, options.browserDrivers);
8985
}
90-
if (argv['chromium'] as boolean) {
91-
setVersions('chromium', argv, options.browserDrivers);
92-
}
9386
if (argv['geckodriver'] as boolean) {
9487
setVersions('geckodriver', argv, options.browserDrivers);
9588
}

lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {start} from './cmds/start';
1313
export {status} from './cmds/status';
1414
export {update} from './cmds/update';
1515
export {ChromeDriver} from './provider/chromedriver';
16-
export {Chromium} from './provider/chromium';
1716
export {GeckoDriver} from './provider/geckodriver';
1817
export {IEDriver} from './provider/iedriver';
1918
export {ProviderConfig, ProviderInterface} from './provider/provider';

lib/provider/chromium.ts

Lines changed: 5 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import * as childProcess from 'child_process';
21
import * as fs from 'fs';
32
import * as os from 'os';
43
import * as path from 'path';
54
import * as semver from 'semver';
6-
75
import { requestBody, JsonObject, requestBinary } from './utils/http_utils';
8-
import { changeFilePermissions, generateConfigFile, getBinaryPathFromConfig, removeFiles, unzipFile } from './utils/file_utils';
6+
import { getBinaryPathFromConfig, removeFiles, unzipFile } from './utils/file_utils';
97
import { isExpired } from './utils/file_utils';
108
import { OUT_DIR, ProviderClass, ProviderConfig, ProviderInterface } from './provider';
11-
import rimraf = require('rimraf');
129

1310
export class Chromium extends ProviderClass implements ProviderInterface {
1411
cacheFileName = 'chromium-all.json';
@@ -21,7 +18,6 @@ export class Chromium extends ProviderClass implements ProviderInterface {
2118
osArch = os.arch();
2219
outDir = OUT_DIR;
2320
proxy: string = null;
24-
maxVersion: string = null;
2521

2622
constructor(config?: ProviderConfig) {
2723
super();
@@ -32,7 +28,6 @@ export class Chromium extends ProviderClass implements ProviderInterface {
3228
this.osType = this.setVar('osType', this.osType, config);
3329
this.outDir = this.setVar('outDir', this.outDir, config);
3430
this.proxy = this.setVar('proxy', this.proxy, config);
35-
this.maxVersion = this.setVar('maxVersion', this.maxVersion, config);
3631
}
3732

3833
private makeDirectory(fileName: string) {
@@ -228,69 +223,16 @@ export class Chromium extends ProviderClass implements ProviderInterface {
228223
}
229224
}
230225
}
231-
232-
if (this.osType === 'Linux') {
233-
unzipFile(fileName, this.outDir);
234-
changeFilePermissions(
235-
path.resolve(this.outDir, 'chrome-linux/chrome'), '0755', this.osType);
236-
} else if (this.osType === 'Darwin') {
237-
spawnProcess('unzip', [fileName, '-d', this.outDir], 'ignore');
238-
} else if (this.osType === 'Windows_NT') {
239-
unzipFile(fileName, this.outDir);
240-
}
226+
unzipFile(fileName, this.outDir);
241227
}
242228

243-
async updateBinary(_: string, majorVersion?: string): Promise<void> {
244-
try {
245-
this.cleanFiles();
246-
} catch (_) {
247-
// no-op: best attempt to clean files, there can be only one version.
248-
}
229+
async updateBinary(majorVersion?: string): Promise<void> {
249230
const allJson = await this.downloadAllJson();
250231
const downloadVersionJson = await this.downloadVersionJson(
251232
allJson, majorVersion);
252233
const storageObject = await this.downloadStorageObject(
253234
downloadVersionJson, majorVersion);
254235
await this.downloadUrl(storageObject, majorVersion);
255-
256-
let binaryFolder = (): string => {
257-
if (this.osType === 'Linux') {
258-
return path.resolve(this.outDir, 'chrome-linux');
259-
} else if (this.osType === 'Darwin') {
260-
return path.resolve(this.outDir,
261-
'chrome-mac/Chromium.app/Contents/MacOS');
262-
} else if (this.osType === 'Windows_NT') {
263-
return 'fix me';
264-
}
265-
throw new Error('os does not exist');
266-
}
267-
268-
let binaryRegex = (): RegExp => {
269-
if (this.osType === 'Linux') {
270-
return /chrome$/g;
271-
} else if (this.osType === 'Darwin') {
272-
return /Chromium/g;
273-
} else if (this.osType === 'Windows_NT') {
274-
return /fix-me/g;
275-
}
276-
throw new Error('os does not exist');
277-
};
278-
279-
let binaryFile = (): string => {
280-
if (this.osType === 'Linux') {
281-
return path.resolve(this.outDir, 'chrome-linux/chrome');
282-
} else if (this.osType === 'Darwin') {
283-
return path.resolve(this.outDir,
284-
'chrome-mac/Chromium.app/Contents/MacOS/Chromium');
285-
} else if (this.osType === 'Windows_NT') {
286-
return 'fix me';
287-
}
288-
throw new Error('os does not exist');
289-
}
290-
291-
generateConfigFile(binaryFolder(),
292-
path.resolve(this.outDir, this.configFileName),
293-
binaryRegex(), binaryFile());
294236
}
295237

296238
getBinaryPath(version?: string): string | null {
@@ -303,47 +245,11 @@ export class Chromium extends ProviderClass implements ProviderInterface {
303245
}
304246

305247
getStatus(): string | null {
306-
try {
307-
const existFiles = fs.readdirSync(this.outDir);
308-
for (const existFile of existFiles) {
309-
if (existFile.match(/chromium\-version\.*/g)) {
310-
const regex = /chromium\-version\-(\d+)\.json/g;
311-
const exec = regex.exec(existFile);
312-
if (exec) {
313-
return exec[1];
314-
}
315-
}
316-
}
317-
return null;
318-
} catch (_) {
319-
return null;
320-
}
248+
return '';
321249
}
322250

323251
cleanFiles(): string {
324-
let chromiumPath= '';
325-
if (this.osType === 'Darwin') {
326-
chromiumPath = 'chrome-mac/';
327-
} else if (this.osType === 'Linux') {
328-
chromiumPath = 'chrome-linux/';
329-
} else if (this.osType === 'Windows_NT') {
330-
chromiumPath = 'chrome-win/';
331-
}
332-
333-
rimraf.sync(path.resolve(this.outDir, chromiumPath));
334-
const files = removeFiles(this.outDir, [/chromium.*/g]);
335-
try {
336-
const fileList = files.split('\n');
337-
if (files.length === 0) {
338-
// No files listed to clean.
339-
return '';
340-
}
341-
fileList.push(chromiumPath);
342-
return (fileList.sort()).join('\n');
343-
} catch (_) {
344-
// If files returns null, catch split error.
345-
return '';
346-
}
252+
return removeFiles(this.outDir, [/chromium.*/g]);
347253
}
348254
}
349255

@@ -369,21 +275,4 @@ export function osHelper(ostype: string, osarch: string): string {
369275
}
370276
}
371277
return null;
372-
}
373-
374-
/**
375-
* A command line to run. Example 'npm start', the task='npm' and the
376-
* opt_arg=['start']
377-
* @param task The task string.
378-
* @param optArg Optional task args.
379-
* @param optIo Optional io arg. By default, it should log to console.
380-
* @returns The child process.
381-
*/
382-
export function spawnProcess(task: string, optArg?: string[], optIo?: string) {
383-
optArg = typeof optArg !== 'undefined' ? optArg : [];
384-
let stdio: childProcess.StdioOptions = 'inherit';
385-
if (optIo === 'ignore') {
386-
stdio = 'ignore';
387-
}
388-
return childProcess.spawnSync(task, optArg, {stdio});
389278
}

lib/provider/utils/file_utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function unzipFile(zipFileName: string, dstDir: string): string[] {
105105
const zip = new AdmZip(zipFileName);
106106
zip.extractAllTo(dstDir, true);
107107
for (const fileItem of zipFileList(zipFileName)) {
108+
console.log(fileItem);
108109
fileList.push(path.resolve(dstDir, fileItem));
109110
}
110111
return fileList;

0 commit comments

Comments
 (0)