netcreateorg / netcreate-2018

Please report bugs, problems, ideas in the project Issues page: https://github.com/netcreateorg/netcreate-2018/issues
Other
11 stars 3 forks source link

DRAFT: Force VSC Integrated Terminal X86_64 Architecture with correct NODE version #273

Open daveseah opened 1 year ago

daveseah commented 1 year ago

THIS PULL REQUEST SHOULD NOT BE MERGED WITHOUT TESTING ON MULTIPLE PLATFORMS BY MULTIPLE DEVS

The 2018 build of NetCreate uses an older version of node (set in .nvmrc as v10.22.0). This version does not officially support Apple Silicon (e.g. M1, M2 processors), but we don't want to update it yet because there are many packages that also need updating.

Why is this important?

Many of the packages in NPM have native code elements that have dependencies to a processor and operating system platform, and they often also tied to the nodejs major version. Many the packages used for NetCreate predate Apple Silicon and may not compile correctly, causing unusual errors.

TESTING ARCHITECTURE

This requires an Apple Silicon Mac (M1, M2, etc)

  1. Pull the test branch
  2. Make sure the the integrated terminal isn't already open by clicking the TRASH CAN icon to kill it
  3. Reopen the integrated terminal
  4. Type arch. If it says i386 then it's working

Next, make sure NetCreate is using the correct NodeJS architecture. Since the processor type has changed, it's likely that the codebase may need to be repulled.

  1. cd build
  2. Type nvm version to see what version of node is running. It should be v10.22.0. If it isn't the case then type nvm use.
  3. Type npm ci to reload all the library dependencies set in package-lock.json and see if there are errors.
  4. If no errors, try running netcreate in the usual way and make sure it works.

TESTING NODE VERSION MISMATCH

When the brunch-server.js file runs, it now checks that the node version output matches what is inside of .nvmrc and will halt the server with instructions on what to do.

TECHNICAL INFORMATION

This patch adds the following settings to netcreate-2018.code-workspace

"terminal.integrated.profiles.osx": {
  "x86 zsh": {
    "path": "/usr/bin/arch",
    "args": ["-arch", "x86_64", "zsh"]
  }
},
"terminal.integrated.defaultProfile.osx": "x86 zsh"

The effect of these settings is to define a profile for osx machines "x86 zsh" which will execute the arch command that tells Rosetta (apple's Intel processor emulator) to switch to X86_64 mode when opening the integrated terminal inside of Visual Studio Code. The second setting tells VSC to use this new profile for every new one.

This does not affect other terminal windows, but you can do the same thing by issuing the arch command BEFORE you run npm use && npm ci when starting it up for the first time in a terminal window:

# see current architecture
arch # says arm64
# run a new shell as an emulated intel processor
arch -arch x86_64 /bin/zsh
arch # now says i386
daveseah commented 1 year ago

DEVELOPER POLL (June 2023)

Ben is using an Intel MacBook Pro:

arch:        i386
nvm version: v10.22.0

Joshua is using an M2 MacBook Pro:

arch:        arm64
nvm version: v14.18.1

Node v14.18 is compatible with Apple Silicon, but he is not using the version specified in .nvmrc which is v10.22.0 Sri is using an M1 MacBook Pro

arch:        i386
nvm version: v14.18.1

Ooops! I did a nvm use then npm ci to make sure it still worked. Though, this might not apply to our package-lock.json file because it's been frozen and changes only when we are adding/removing packages via npm install.

Every time I launch a shell, it's using the default node version set by nvm alias default v14.18.1, which is handy as a default but means we have to be careful about what version is in place. There's a way I can make VSCODE run a custom shell task defined in the workspace settings, so I'll have to try that...

daveseah commented 1 year ago

I added a check for the node version to brunch-server.js, see updated testing.

daveseah commented 1 year ago

Added additional warning when there is an architecture mismatch, which catches the case when netcreate is run outside of the integrated terminal. The check does not prevent the code from running as does the node version check.