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

Update Nix and Node JS versions #3549

Merged
merged 18 commits into from
Apr 20, 2023
Merged

Update Nix and Node JS versions #3549

merged 18 commits into from
Apr 20, 2023

Conversation

Rheeseyb
Copy link
Contributor

@Rheeseyb Rheeseyb commented Apr 17, 2023

Problem:
The version of node.js we have been using is old and needed updating in order to build the latest version of VS Code.

Fix:
Update the node.js version to v16.18.1, and update nix to the latest stable version (22.11).
The reason for the nix update is because the previous version of node we were using was the latest v16 version available on the older nix release.

Updating nix revealed that a package we were using on the server for the AWS API (amazonka) had been effectively abandoned and marked as broken, so that has been replaced with a new package (aws). Whilst we were there we also updated the version of the haskell compiler so that we could continue to pull cached builds from hydra as part of the server build (without that we'd have to build every single package in the dependency chain, making the build very long and painful).

Updating Node introduced / flagged the following issues that are resolved in this PR:

  • An error Error: error:0308010C:digital envelope routines::unsupported is thrown by webpack builds due to its use of a crypto function now considered to be legacy. The workaround for this is to use the node flag --openssl-legacy-provider pretty much everywhere. Further details here.
  • The updated version of pnpm seems to have introduced some change that was causing ts-loader resolution issues in webpack builds, so we had to replace an exclude rule with an explicit include rule in the editor's webpack config file for that loader. I'm not entirely sure why this only affects the dependency on utopia-api and not utopia-vscode-common.
  • It seems that by using pnpx tsc in places we were using a different version of tsc to the one coming from the typescript package specified in the package.json, so those cases have been replaced with an explicit node script instead.
  • patch-package was causing issues with pnpm, and is no longer necessary as pnpm has native support for patching, so the patches and package.json have been updated to reflect that.
  • The custom install steps we had for utopia-api were not only unnecessary, but were actively causing issues during the build, so those have been removed now and replaced with an install and build step in the install-editor script used everywhere.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 17, 2023

Try me

@relativeci
Copy link

relativeci bot commented Apr 17, 2023

Job #5649: Bundle Size — 49.78MiB (+0.41%).

5c12b96(current) vs c4aaee4 master#5645(baseline)

⚠️ Bundle removed 15 duplicate packages, 46 duplicate packages remaining
⚠️ Bundle introduced 2 new packages: utopia-api, utopia-vscode-common

Metrics (9 changes)
                 Current
Job #5649
     Baseline
Job #5645
Initial JS 32.15MiB(-0.63%) 32.35MiB
Initial CSS 0B 0B
Cache Invalidation 73.22% 21.79%
Chunks 26(+8.33%) 24
Assets 30(+7.14%) 28
Modules 3618(-1.26%) 3664
Duplicate Modules 353(+0.28%) 352
Duplicate Code 17.28%(+4.85%) 16.48%
Packages 373(-3.37%) 386
Duplicate Packages 46(-24.59%) 61
Total size by type (2 changes)
                 Current
Job #5649
     Baseline
Job #5645
CSS 0B 0B
Fonts 0B 0B
HTML 11.57KiB (~-0.01%) 11.57KiB
IMG 0B 0B
JS 49.77MiB (+0.41%) 49.57MiB
Media 0B 0B
Other 0B 0B

View job #5649 reportView chore/update-nix-node branch activity

@github-actions
Copy link
Contributor

github-actions bot commented Apr 17, 2023

Performance test results:
(Chart1)
(Chart2)

@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@concrete-utopia concrete-utopia deleted a comment from github-actions bot Apr 18, 2023
@@ -1,7 +1,7 @@
diff --git a/node_modules/@emotion/react/dist/emotion-react.browser.cjs.js b/node_modules/@emotion/react/dist/emotion-react.browser.cjs.js
diff --git a/dist/emotion-react.browser.cjs.js b/dist/emotion-react.browser.cjs.js
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the patches are file renames (to match the style used by pnpm's native patching support to make updating the patches later easier), and the removal of /node_modules/<package_name> from the file paths used in the diffs (like has happened here), so you can ignore the patch diffs

@@ -116,7 +116,7 @@ module.exports = {
'\\.[jt]sx?$': 'babel-jest',
},
roots: ['src', 'node_modules', '<rootDir>/node_modules'],
transformIgnorePatterns: ['/node_modules/(?!utopia-api)'], // this lets ts-jest work on `/node_modules/utopia-api` which is a simlink to `../utopia-api`.
transformIgnorePatterns: ['<rootDir>/node_modules/.pnpm/(?!file+..+)'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm honestly not sure how this hadn't broken before, but it seems like we were on the edge of this breaking since we first switched to pnpm

"lint": "pnpx eslint \"src/**/*.{js,ts,tsx}\" --quiet",
"lint-loud": "pnpx eslint \"src/**/*.{js,ts,tsx}\"",
"check-code": "tsc --version && tsc --noEmit && pnpm run lint && pnpm run check-dependency-cruiser && pnpm run prettier-check",
"lint": "eslint \"src/**/*.{js,ts,tsx}\" --quiet",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pnpx had been changed over a year ago to become an alias for pnpm dlx, which downloads and runs the latest version of a package, rather than using the locally installed version

Copy link
Contributor

Choose a reason for hiding this comment

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

wow, good to know!

if (filePath.includes('node_modules')) {
// We need to use the ts-loader to load the utopia-api module,
// but nothing else from node_modules
return filePath.includes('/utopia-api/')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, it seems like we have been on the verge of this breaking since we made the switch to pnpm

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know you can write a function here instead of a regex. this makes it much easier to maintain! bonus points for the comments!

Comment on lines +33 to +39
(pkgs.writeScriptBin "install-utopia-api" ''
#!/usr/bin/env bash
set -e
cd $(${pkgs.git}/bin/git rev-parse --show-toplevel)/utopia-api
pnpm install
pnpm run build
'')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added to replace the script previously living in the editor's package.json, which was causing build issues

Comment on lines +17 to +24
pnpm = node.pkgs.pnpm;
yarn = pkgs.yarn;

pnpmPkg = pkgs.nodePackages_latest.pnpm.override {
nativeBuildInputs = [ pkgs.makeWrapper ];

preRebuild = ''
sed 's/"link:/"file:/g' --in-place package.json
'';

postInstall = let
pnpmLibPath = pkgs.lib.makeBinPath [
node.passthru.python
node
];
in ''
for prog in $out/lib/node_modules/pnpm/bin/*; do
wrapProgram "$prog" --prefix PATH : ${pnpmLibPath}
done
'';
};
pnpm = "${pnpmPkg}/lib/node_modules/pnpm/bin/pnpm.cjs";
pnpx = "${pnpmPkg}/lib/node_modules/pnpm/bin/pnpx.cjs";

yarn = "${pkgs.nodePackages_latest.yarn}/lib/node_modules/yarn/bin/yarn.js";
nodePackages = [
node
pnpm
(yarn.override { nodejs = node; })
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is synching up the version of node used by pnpm and yarn

@maltenuhn
Copy link
Member

FWIW

  • I've been able to build the project with this change, even on my cursed machine
  • I've had this branch open all day and making theme-related changes, including occasional full reloads, and everything worked as expected

"eslint-check": "eslint --quiet --ignore-path ./.eslintignore --config ./.eslintrc.js --ext .ts --ext .tsx src ../utopia-api/src ../utopia-vscode-extension/src ../utopia-vscode-common/src ../puppeteer-tests/src ../website-next/",
"prettier-check": "prettier --ignore-path ../.prettierignore --config ../prettier.config.js --check src/** ../utopia-api/src/**/* ../utopia-vscode-common/src/** ../utopia-vscode-extension/src/** ../puppeteer-tests/src/** ../website-next/pages/** ../website-next/components/**",
"parse-print-analysis": "npx -s sh ts-node --require ignore-styles --transpile-only ./src/scripts/parse-print-analysis.ts",
"parse-debug": "npx -s sh ts-node --pretty --require ignore-styles --transpile-only ./src/scripts/parse-debug.ts",
"fetch-tailwind-classes": "npx -s sh ts-node --pretty --require ignore-styles --transpile-only ./src/scripts/fetch-and-parse-tailwind-classes.ts && npx prettier --write ./src/core/third-party/tailwind-defaults.ts",
"lint-editor": "lint-staged",
"dev-fast": "APP_ENV=development REACT_APP_ENVIRONMENT_CONFIG=development REACT_APP_AUTH0_CLIENT_ID=$AUTH0_CLIENT_ID REACT_APP_AUTH0_ENDPOINT=$AUTH0_ENDPOINT REACT_APP_AUTH0_REDIRECT_URI=$AUTH0_REDIRECT_URI REACT_APP_COMMIT_HASH=`git rev-parse HEAD` vite --force",
"vite-build": "node --max_old_space_size=16384 ./node_modules/vite/bin/vite build -- -DEBUG"
"vite-build": "node --max_old_space_size=16384 ./node_modules/vite/bin/vite build -- -DEBUG",
"watch-tsc": "tsc --watch && NODE_OPTIONS='--max_old_space_size=4096 --openssl-legacy-provider'"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will also make iTerm 2's cmd + click to open VSCode work properly!

"staging-print-json": "pnpm run staging -- --json=lib/staging-stats.json",
"install-utopia-api": "cd ../utopia-api && pnpm install && pnpm run build && pnpm run dts-bundle",
"preinstall": "npx only-allow pnpm && pnpm run install-utopia-api",
"postinstall": "patch-package",
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

@Rheeseyb Rheeseyb merged commit bcd5023 into master Apr 20, 2023
@Rheeseyb Rheeseyb deleted the chore/update-nix-node branch April 20, 2023 10:15
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.

7 participants