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

Remove usage of process.chdir from language parser #10

Merged
merged 1 commit into from
Oct 16, 2017
Merged

Remove usage of process.chdir from language parser #10

merged 1 commit into from
Oct 16, 2017

Conversation

scholtzm
Copy link
Contributor

The problem

Electron's asar archive does not allow process.chdir to be set inside the archive itself. However, the language parser in steam resources sets working directory when parsing files.

When packaging this module inside asar archive, it will simply fail to load. Skipping archiving is not an option since the dependency tree may contain very large paths and makes it "almost" impossible to work on Windows.

TL;DR Remove process.chdir calls to make the module fully compatible with Electron's standard asar archive format.

Official docs:

Related issues:

Affected files

Solution

We can preload language files and simply serve them from cache. No need to tinker with cwd.

There might be a simpler, more elegant solution so let's discuss.

@DoctorMcKay
Copy link
Owner

Is there any particular reason why you didn't just remove chdir calls and instead prefix the readFileSync calls with __dirname? I won't reject the way you did it, just curious.

@scholtzm
Copy link
Contributor Author

scholtzm commented Oct 15, 2017

I could remove chdir calls from here and simply readFileSync with full path, but in this file, analyzer doesn't know where the imported file is located. At this point, process.cwd() = steam-resources/steam_language_parser and __dirname = steam-resources/steam_language_parser/parser.

if (cur.value == 'import') {
var parentTokens = language_parser.tokenizeString(require('fs').readFileSync(text.value, { encoding: 'ascii' }));

var parentTokens = language_parser.tokenizeString(file_cache.cache[text.value]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be a good idea to throw here in case file_cache.cache[text.value] is undefined.

@scholtzm
Copy link
Contributor Author

scholtzm commented Oct 15, 2017

I think we could also prefix text.value here with hardcoded path e.g. ../../steam_language and this ought to work as well.

Need to be careful when changing build script.

@DoctorMcKay DoctorMcKay merged commit 5d5798d into DoctorMcKay:master Oct 16, 2017
@scholtzm scholtzm deleted the remove-process-chdir-from-lang-parser branch October 16, 2017 19:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants