Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from AtkinsSJ/fix-browser-build-after-path-com…
Browse files Browse the repository at this point in the history
…mand-provider

Fix a couple of issues with the web build, caused by CLI changes
  • Loading branch information
KernelDeimos authored Apr 12, 2024
2 parents 84c2450 + 8ededf6 commit 6ac511e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ansi-shell/ANSIShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ANSIShell extends EventTarget {
}

async doPromptIteration() {
if ( globalThis.force_eot ) {
if ( globalThis.force_eot && this.ctx.platform.name === 'node' ) {
process.exit(0);
}
const { readline } = this.ctx.externs;
Expand Down
6 changes: 4 additions & 2 deletions src/ansi-shell/pipeline/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ export class PreparedCommand {
// but for some reason Node crashes first, unless we set this handler,
// EVEN IF IT DOES NOTHING. I also can't find a place to safely remove it,
// so apologies if it makes debugging promises harder.
const rejectionCatcher = (reason, promise) => {};
process.on('unhandledRejection', rejectionCatcher);
if (ctx.platform.name === 'node') {
const rejectionCatcher = (reason, promise) => { };
process.on('unhandledRejection', rejectionCatcher);
}

let exit_code = 0;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-shell/readline/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ReadlineProcessorBuilder = builder => builder
externs.out.write('^C\n');
// Exit if input line is empty
// FIXME: Check for 'process' is so we only do this on Node. How should we handle exiting in Puter terminal?
if ( process && ctx.vars.result.length === 0 ) {
if ( typeof process !== 'undefined' && ctx.vars.result.length === 0 ) {
process.exit(1);
return;
}
Expand Down
10 changes: 7 additions & 3 deletions src/puter-shell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { Context } from "contextlink";
import { SHELL_VERSIONS } from "../meta/versions.js";
import { PuterShellParser } from "../ansi-shell/parsing/PuterShellParser.js";
import { BuiltinCommandProvider } from "./providers/BuiltinCommandProvider.js";
import { PathCommandProvider } from "./providers/PathCommandProvider.js";
import { CreateChatHistoryPlugin } from './plugins/ChatHistoryPlugin.js';
import { Pipe } from '../ansi-shell/pipeline/Pipe.js';
import { Coupler } from '../ansi-shell/pipeline/Coupler.js';
Expand Down Expand Up @@ -83,10 +82,15 @@ export const launchPuterShell = async (ctx) => {
await sdkv2.setAPIOrigin(source_without_trailing_slash);
}

// PathCommandProvider is only compatible with node.js for now
// HACK: The import path is split to fool rollup into not including it.
const { PathCommandProvider } = (ctx.platform.name === 'node')
? await import('./providers/' + 'PathCommandProvider.js')
: { PathCommandProvider: null };

const commandProvider = new CompositeCommandProvider([
new BuiltinCommandProvider(),
// PathCommandProvider is only compatible with node.js for now
...(ctx.platform.name === 'node' ? [new PathCommandProvider()] : []),
...(PathCommandProvider ? [new PathCommandProvider()] : []),
new ScriptCommandProvider(),
]);

Expand Down

0 comments on commit 6ac511e

Please sign in to comment.