Skip to content

Commit

Permalink
chore: refactor code to use platform()
Browse files Browse the repository at this point in the history
  • Loading branch information
raix committed Sep 14, 2019
1 parent be729a5 commit 042aea5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { EventEmitter } from 'events';

import { convertToPerlPath } from "./filepath";
import { breakpointParser } from './breakpointParser';
import { platform } from 'os';

interface ResponseError {
filename: string,
ln: number,
Expand Down Expand Up @@ -718,7 +720,7 @@ export class perlDebuggerConnection extends EventEmitter {
this.rootPath = args.root;
this.filename = args.program;

this.logDebug(`Platform: ${process.platform}`);
this.logDebug(`Platform: ${platform()}`);

Object.keys(args.env || {}).forEach(key => {
this.logDebug(`env.${key}: "${args.env[key]}"`);
Expand All @@ -741,7 +743,7 @@ export class perlDebuggerConnection extends EventEmitter {
this.logOutput(`Error: Folder ${args.root} not found`);
}

this.logOutput(`Platform: ${process.platform}`);
this.logOutput(`Platform: ${platform()}`);

// This is the actual launch
await this.launchSession(args, session);
Expand Down Expand Up @@ -989,8 +991,8 @@ export class perlDebuggerConnection extends EventEmitter {
// The issue is due to differences between perl5db.pl versions, we should use that as a reference instead of
// using perl/os
const isBrokenPerl = (this.perlVersion >= '5.022000' || this.perlVersion < '5.018000');
const isBrokenLinux = process.platform === 'linux' && isBrokenPerl;
const isBrokenWindows = /^win/.test(process.platform) && isBrokenPerl;
const isBrokenLinux = platform() === 'linux' && isBrokenPerl;
const isBrokenWindows = platform() === "win32" && isBrokenPerl;
const fix = isBrokenLinux || isBrokenWindows;
return fix ? level - 1 : level;
}
Expand Down
3 changes: 2 additions & 1 deletion src/streamCatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {Writable, Readable} from 'stream';
import * as RX from './regExp';
import { EventEmitter } from 'events';
import { platform } from 'os';

interface RequestTask {
command: string | null,
Expand Down Expand Up @@ -54,7 +55,7 @@ export class StreamCatcher extends EventEmitter {
// xxx: Windows restart workaround
// the windows perl debugger doesn't end the current restart request so we have to
// simulate a proper request end.
if ((/^win/.test(process.platform) && RX.restartWarning.test(firstLine)) || timeout) {
if ((platform() === "win32" && RX.restartWarning.test(firstLine)) || timeout) {

if (RX.restartWarning.test(firstLine)) {
this.logDebug('RAW> Waiting to fake end of restart request');
Expand Down
4 changes: 2 additions & 2 deletions src/tests/multisession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('multisession support', () => {

let mainDc: DebugClient;

beforeEach( () => {
beforeEach(async () => {
mainDc = new DebugClient('node', DEBUG_ADAPTER, 'perl');
return mainDc.start();
await mainDc.start();
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ describe('Perl debugger connection', () => {

let conn: perlDebuggerConnection;

beforeEach(() => {
beforeEach(async () => {
conn = new perlDebuggerConnection();
return conn.initializeRequest();
await conn.initializeRequest();
});

afterEach(() => {
Expand Down

0 comments on commit 042aea5

Please sign in to comment.