Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

script/redownload-electron-bins.js: Fix finding the Atom repo's package.json#2534

Merged
smashwilson merged 2 commits intoatom:masterfrom
DeeDeeG:fix-redownload-electron-bins
Sep 29, 2020
Merged

script/redownload-electron-bins.js: Fix finding the Atom repo's package.json#2534
smashwilson merged 2 commits intoatom:masterfrom
DeeDeeG:fix-redownload-electron-bins

Conversation

@DeeDeeG
Copy link
Contributor

@DeeDeeG DeeDeeG commented Sep 29, 2020

Please be sure to read the contributor's guide to the GitHub package before submitting any pull requests.

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • Suggestion: You can use checklists to keep track of progress for the sections on metrics, tests, documentation, and user research.

Description of the Change

  • 🐛 Construct the path to Atom's package.json as an absolute path, because fs.existsSync() and require() interpret relative paths differently.
  • ⌨️ Fix a typo (an incorrectly capitalized variable name) that would have meant require([path/to/Atom's/package.json]) would have errored out.

Screenshot/Gif

N/A

Alternate Designs

N/A. These are just typo/bug fixes. The overall design was reviewed in #2513, but this small typo and bug slipped past my/the reviewer's radars at the time.

Benefits

Fixes the original intended behavior of script/redownload-electron-bins.js:

When installing this package as a dependency in the Atom repo, and running this package's tests in that context, this package now installs/tests against the version of Electron specified in Atom's package.json. Should provide more relevant results when running the package tests in Atom's CI.

(Was falling back on a "fallback" version hard-coded in script/redownload-electron-bins.js.)

Possible Drawbacks

N/A, these are just bug-fixes.

(I don't think I missed anything this time! This is a very small change, only 12 characters of diff.)

Applicable Issues

Follow-up to #2513

Metrics

N/A

Tests

Steps to confirm that this change works (click to expand):

Clone this repo (with fix), positioned as if it were a dependency in the Atom repo:

  • cd into the Atom repo.
  • backup the github dependency if already installed.
    • mv node_modules/github node_modules/_github_backup
  • clone this repo under Atom's main node_modules dir
    • cd node_modules && git clone https://github.com/DeeDeeG/github
  • Checkout the branch with this fix
    • cd github && git checkout fix-redownload-electron-bins

Confirm the fix is working:

  • In the github folder we just cloned, do npm install to install all dependencies and devDevpendencies
    • Observe that the postinstall script says it wants to download Electron "6.1.12" (or whatever is in Atom's main package.json as the value for electronVersion)
  • Edit the electronVersion in Atom's package.json and run npm install again in the github folder
    • Observe that the github postinstall script wants to install the Electron version you just edited into Atom's package.json
  • Optionally, check that the filesize of the mksnapshot binary changes when instaling different major versions
    • ls -lah ./node_modules/electron-mksnapshot/bin/mksnapshot

Confirm this behavior doesn't work as intended without the fix from this PR:

  • Checkout the master branch in the github folder, and run npm install again
    • git checkout master && npm install
    • Observe that the postinstall script now wants to install the "6.1.12" hard-coded in script/redownload-electron-bins.js
  • Edit the hard-coded target Electron version in script/redownload-electron-bins.js and run npm install again
    • Observe that without the fix from this PR, the hard-coded Electron version from script/redownload-electron-bins.js is always downloaded.

I followed these steps, and I am able to confirm this fix makes things work as I originally intended them to.

Documentation

N/A

Release Notes

N/A

User Experience Research (Optional)

None.

Incorrect capitalization caused this line to reference
a non-existent/undefined variable.
Construct the atomRepoPath variable starting with __dirname,
so that atomRepoPath is an absolute path.

For example: '/Users/[username]/atom/package.json',
versus '../../../../atom/package.json'.

---

Explanation for why this is necessary:

The require() and fs.existsSync() functions interpret
relative paths differently.

require() is relative to the current script's containing folder,
(which is the same as __dirname),
whereas 'fs.existsSync()' is relative to the working directory
(which is the same as process.cwd()).

When constructing the path to the Atom repo's main package.json,
we should construct it as an absolute path, for consistency's sake.
Otherwise the script will error out, or use the wrong package.json.
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Sep 29, 2020

cc @smashwilson who reviewed the initial PR for this script.

This script from #2513 has a nifty feature that makes the github package test against the Electron version Atom uses, if possible. I just noticed today it has a typo and a small bug in how paths are interpreted in Node.

This PR is to fix those two small issues.

Please take a look if you get the chance. Thank you.

const atomRepoPath = path.join('..', '..', '..', '..', 'atom', 'package.json');
const electronVersion = fs.existsSync(atomRepoPath) ? require(atomrepoPath).electronVersion : '6.1.12'
const atomRepoPath = path.join(__dirname, '..', '..', '..', '..', 'atom', 'package.json');
const electronVersion = fs.existsSync(atomRepoPath) ? require(atomRepoPath).electronVersion : '6.1.12'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Off-topic, but it might make sense to call this variable atomMetadata or atomMetadataPath instead of atomRepoPath. That's more consistent with how Atom's scripts refer to package.json files (as "metadata").

@DeeDeeG DeeDeeG changed the title Fix finding the Atom repo's package.json in script/redownload-electron-bins.js script/redownload-electron-bins: Fix finding the Atom repo's package.json Sep 29, 2020
@DeeDeeG DeeDeeG changed the title script/redownload-electron-bins: Fix finding the Atom repo's package.json script/redownload-electron-bins.js: Fix finding the Atom repo's package.json Sep 29, 2020
@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #2534 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2534   +/-   ##
=======================================
  Coverage   93.43%   93.43%           
=======================================
  Files         236      236           
  Lines       13204    13204           
  Branches     1899     1899           
=======================================
  Hits        12337    12337           
  Misses        867      867           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee1502b...f1d86dc. Read the comment docs.

Copy link
Contributor

@smashwilson smashwilson left a comment

Choose a reason for hiding this comment

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

Ah... good catch 👍🏻 Thanks for the follow-up!

@smashwilson smashwilson merged commit 5a8faf5 into atom:master Sep 29, 2020
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.

3 participants