Skip to content

Commit

Permalink
using node.js API breaks when running in browser; Fixes #68 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand authored Sep 13, 2022
1 parent 5524e7a commit cc3141e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/activateMockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class MockConfigurationProvider implements vscode.DebugConfigurationProvider {
}

export const workspaceFileAccessor: FileAccessor = {
isWindows: false,
async readFile(path: string): Promise<Uint8Array> {
let uri: vscode.Uri;
try {
Expand Down
1 change: 1 addition & 0 deletions src/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FileAccessor } from './mockRuntime';
* So we can only use node.js API for accessing files.
*/
const fsAccessor: FileAccessor = {
isWindows: process.platform === 'win32',
readFile(path: string): Promise<Uint8Array> {
return fs.readFile(path);
},
Expand Down
3 changes: 2 additions & 1 deletion src/mockRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { EventEmitter } from 'events';

export interface FileAccessor {
isWindows: boolean;
readFile(path: string): Promise<Uint8Array>;
writeFile(path: string, contents: Uint8Array): Promise<void>;
}
Expand Down Expand Up @@ -674,7 +675,7 @@ export class MockRuntime extends EventEmitter {
}

private normalizePathAndCasing(path: string) {
if (process.platform === 'win32') {
if (this.fileAccessor.isWindows) {
return path.replace(/\//g, '\\').toLowerCase();
} else {
return path.replace(/\\/g, '/');
Expand Down

0 comments on commit cc3141e

Please sign in to comment.