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

meta: Don't exclude 'loophole' or 'pegjs' packages #206

Merged
merged 1 commit into from Dec 10, 2022

Conversation

DeeDeeG
Copy link
Member

@DeeDeeG DeeDeeG commented Dec 9, 2022

Requirements for Contributing a Bug Fix (click to expand):

Identify the Bug

When trying to type a tab character in a document or file, after #201 was merged, there is an error:

Uncaught Error: Cannot find module 'loophole'
Screenshot (click to expand):

Cannot Find Module 'loophole'

Uncaught Error: Cannot find module 'pegjs'
Screenshot (click to expand):

Cannot Find Module 'pegjs'

Explanation as for why this happens:

There is a file snippet-body.pegjs which 'snippets' expects to have been compiled from .pegjs to .js. If it can't require the plain .js file successfully (it assumes this is because the .pegjs file hasn't been transpiled to plain JS yet, which is correct in our case)... then it appears to fall back on live-transpiling the .pegjs file using the 'pegjs' module.

See: https://github.com/pulsar-edit/snippets/blob/388d9b63cacbc124652e9cec6ce4be6e3d6d46bf/lib/snippet-body-parser.js#L2-L12

So we need to have the 'pegjs' module (and 'loophole', whatever that is) in order to load 'snippets' package properly and restore the ability to type tab characters. (The app appears to trigger the 'snippets' package to activate every time you type a Tab? Which I understand is for code autocompletion purposes.)

Description of the Change

Don't exclude 'loophole' or 'pegjs' packages from the app bundle. Allows the 'snippets' package to work again.

Alternate Designs

We can attempt to compile the PegJS files to plain JS, like the old build scripts used to do. See: script/lib/transpile-peg-js-paths.js at Atom core repo.

At which point we apparently wouldn't need these packages.

Possible Drawbacks

Increases the final app bundle size by some 0.2 Megabytes, after compression, adds more files to the final bundle.

Verification Process

Tested CI binaries with/without these changes on my Windows 10 machine:

  • master with #201: Affected by the tab bug described at the top of this PR. ❌
  • This branch: Not affected by bug ✔️

Release Notes

Fix a bug when typing a tab character in a document or file

We need these when typing a "tab" character in a document or file.

(Without 'loophole' and 'pegjs' in the app bundle,
'snippets' tries and fails to require() those packages,
and it errors out every time you type a tab character.)

Explanation:

Our PegJS files _aren't_ pre-compiled at the moment.
We removed the old build scripts that used to transpile these files
during the build, and without replacing that functionality yet.

So...

When a certain PegJS --> JS file isn't available in the 'snippets'
package (because it hasn't been transpiled to plain JS yet yet),
'snippets' require()s some modules that let it live-transpile
the needed code, or at least that's what I think it's doing
in that scenario.

If the modules it conditionally require()s in that scenario aren't
in the Pulsar bundle, due to being explicitly excluded, then we get a
require() error, since they legitimately aren't in the bundle.
@preland
Copy link

preland commented Dec 9, 2022

I can also confirm that this issue occurs in the newest version of master. I will check if this PR fixes the issue (Intel Mac).

@preland
Copy link

preland commented Dec 9, 2022

Update: this PR fixes the issue for me. I don't see any other side effects from the changes.

Copy link
Member

@confused-Techie confused-Techie left a comment

Choose a reason for hiding this comment

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

Appreciate you catching this oversight. Now ideally we could build our transpiled pegjs files during a GitHub action so that there is always a normal js file available.

But until such time as that happens lets merge this one to get things working.

Thanks as always for the contribution!

@confused-Techie confused-Techie merged commit 021d1dd into master Dec 10, 2022
@DeeDeeG DeeDeeG deleted the fewer-package-exclusions branch December 14, 2022 23:50
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.

None yet

3 participants