Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working for Windows #466

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

aakash-a-dev
Copy link
Contributor

Fix: #297
Changes are made but requires to test on different OS.
Proof of work video here:
https://youtu.be/DC6lnsA_itU

finalEnv.PATH = newPaths + (existingPath ? ';' + existingPath : '');
}

console.log(`Executing command: ${finalCommand}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the debug logs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

import Path from 'node:path';
import { spawn } from 'node:child_process';

interface NodeError extends Error {
code?: string;
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay on it

@aakash-a-dev
Copy link
Contributor Author

Removed Debugging console & Comments made from my side

@aakash-a-dev
Copy link
Contributor Author

The updated code improves maintainability, efficiency, and cross-platform compatibility by centralizing executable resolution into a reusable ExecutableResolver singleton. It leverages where on Windows and which on Unix to dynamically resolve paths, caching results to avoid redundant calls. This ensures consistent handling of executables like node, tsx, and vite while prioritizing system executables (e.g., those in Program Files). Platform-specific differences, such as handling .cmd files on Windows, are abstracted, reducing complexity in individual functions. This approach is cleaner, more scalable, and minimizes duplication, making the code easier to extend for additional commands or environments in the future.

packages/api/tsserver/tsservers.mts Outdated Show resolved Hide resolved
args: process.platform === 'win32' ? ['vite', ...args] : args,
env: {
...env,
FORCE_COLOR: '1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..env is for copying all the object, for creating in the following object although I added FORCE_COLOR: '1' Because it was getting difficult to find the response so for making it shine I added, I will remove it if you want

args: process.platform === 'win32' ? ['vite', ...args] : args,
env: {
...env,
FORCE_COLOR: '1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For just making sure I can track that this log can easily noticeable while I was debugging, if you want I will remove FORCE_COLOR it was for me to make sure that it is logging

command:
process.platform === 'win32' ? 'npx.cmd' : Path.join(cwd, 'node_modules', '.bin', 'vite'),
cwd,
args: process.platform === 'win32' ? ['vite', ...args] : args,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on windows, we need to call the command and then add vite as an arg? Feels like this is vite vite. Surprising

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to hard code it, only then it's running otherwise vite is not getting started, atleast for me it havn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alien, Yes! While Vite code which was already there didn't started vite and thrown error, require to hard code this in the following way

export function spawnCall(options: SpawnCallRequestType) {
const { cwd, env, command, args, stdout, stderr, onExit, onError } = options;
const child = spawn(command, args, { cwd: cwd, env: env });
class ExecutableResolver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit scared of this change. It's a pretty big refactor of an important part of the app.

I'm wondering if we can remove the new class implementation, and instead have some simple function based routing.

So first run a function spawnCall which will call:
spawnCallUnix and spawnCallWindows based on the process.platform switch you do line 56.

That way the mac / unix code can stay the exact same which I think is safeer, and windows can have it's own code path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me change it then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating ts srcbook on windows
2 participants