Skip to content

Commit

Permalink
Test yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube committed Aug 2, 2024
1 parent 32f5fba commit 2e6d29b
Show file tree
Hide file tree
Showing 27 changed files with 11,527 additions and 13,445 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/!build-comment-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: 🚧 Install Node dependencies
run: |
cd frontend
npm ci
yarn install --imutable --immutable-cache
- name: 🦀 Install the latest Rust
run: |
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
NODE_ENV: production
run: |
cd frontend
mold -run npm run ${{ steps.build_command.outputs.command }}
mold -run yarn ${{ steps.build_command.outputs.command }}
- name: 📤 Publish to Cloudflare Pages
id: cloudflare
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-and-dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: 🚧 Install Node dependencies
run: |
cd frontend
npm ci
yarn install --imutable --immutable-cache
- name: 🦀 Install the latest Rust
run: |
Expand All @@ -59,7 +59,7 @@ jobs:
NODE_ENV: production
run: |
cd frontend
mold -run npm run build
mold -run yarn build
- name: 📤 Publish to Cloudflare Pages
id: cloudflare
Expand All @@ -77,7 +77,7 @@ jobs:
NODE_ENV: production
run: |
cd frontend
npm run lint
yarn lint
- name: 🔬 Check Rust formatting
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: 🚧 Install Node dependencies
run: |
cd frontend
npm ci
yarn install --imutable --immutable-cache
- name: 🦀 Install the latest Rust
run: |
Expand All @@ -54,7 +54,7 @@ jobs:
NODE_ENV: production
run: |
cd frontend
mold -run npm run build
mold -run yarn build
- name: 📤 Publish to Cloudflare Pages
id: cloudflare
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
target/
*.spv
*.exrc
.pnp.cjs
.pnp.loader.mjs
.yarn/
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modules/
wasm/pkg/
public/build/
dist/
.install-timestamp
.pnp.cjs
.pnp.loader.mjs
4 changes: 2 additions & 2 deletions frontend/.prettierrc → frontend/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
module.exports = {
"singleQuote": false,
"useTabs": true,
"tabWidth": 4,
"printWidth": 200,
"plugins": [
"prettier-plugin-svelte"
import("prettier-plugin-svelte")
],
"overrides": [
{
Expand Down
6 changes: 3 additions & 3 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Wraps the editor backend codebase (`/editor`) and provides a JS-centric API for

## ESLint configurations: `.eslintrc.js`

[ESLint](https://eslint.org/) is the tool which enforces style rules on the JS, TS, and Svelte files in our frontend codebase. As it is set up in this config file, ESLint will complain about bad practices and often help reformat code automatically when (in VS Code) the file is saved or `npm run lint` is executed. (If you don't use VS Code, remember to run this command before committing!) This config file for ESLint sets our style preferences and configures our usage of extensions/plugins for Svelte support, [Airbnb](https://github.com/airbnb/javascript)'s popular catalog of sane defaults, and [Prettier](https://prettier.io/)'s role as a code formatter.
[ESLint](https://eslint.org/) is the tool which enforces style rules on the JS, TS, and Svelte files in our frontend codebase. As it is set up in this config file, ESLint will complain about bad practices and often help reformat code automatically when (in VS Code) the file is saved or `yarn lint` is executed. (If you don't use VS Code, remember to run this command before committing!) This config file for ESLint sets our style preferences and configures our usage of extensions/plugins for Svelte support, [Airbnb](https://github.com/airbnb/javascript)'s popular catalog of sane defaults, and [Prettier](https://prettier.io/)'s role as a code formatter.

## npm ecosystem packages: `package.json`

While we don't use Node.js as a JS-based server, we do have to rely on its wide ecosystem of packages for our build system toolchain. If you're just getting started, make sure to install the latest LTS copy of Node.js. Our project's philosophy on third-party packages is to keep our dependency tree as light as possible, so adding anything new to our `package.json` should have overwhelming justification. Most of the packages are just development tooling (TypeScript, Vite, ESLint, Prettier, wasm-pack, and [Sass](https://sass-lang.com/)) that run in your console during the build process.

## npm package installed versions: `package-lock.json`
## npm package installed versions: `yarn.lock`

Specifies the exact versions of packages installed in the npm dependency tree. While `package.json` specifies which packages to install and their minimum/maximum acceptable version numbers, `package-lock.json` represents the exact versions of each dependency and sub-dependency. Running `npm ci` will grab these exact versions to ensure you are using the same packages as everyone else working on Graphite. `npm update` will modify `package-lock.json` to specify newer versions of any updated (sub-)dependencies and download those, as long as they don't exceed the maximum version allowed in `package.json`. To check for newer versions that exceed the max version, run `npm outdated` to see a list. Unless you know why you are doing it, try to avoid committing updates to `package-lock.json` by mistake if your code changes don't pertain to package updates. And never manually modify the file.
Specifies the exact versions of packages installed in the npm dependency tree. While `package.json` specifies which packages to install and their minimum/maximum acceptable version numbers, `yarn.lock` represents the exact versions of each dependency and sub-dependency. Running `yarn install --immutable --immutable-cache` will grab these exact versions to ensure you are using the same packages as everyone else working on Graphite. `yarn upgrade` will modify `yarn.lock` to specify newer versions of any updated (sub-)dependencies and download those, as long as they don't exceed the maximum version allowed in `package.json`. To check for newer versions that exceed the max version, run `npm outdated` to see a list. Unless you know why you are doing it, try to avoid committing updates to `yarn.lock` by mistake if your code changes don't pertain to package updates. And never manually modify the file.

## TypeScript configurations: `tsconfig.json`

Expand Down
24 changes: 12 additions & 12 deletions frontend/package-installer.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
// This script automatically installs the npm packages listed in package-lock.json and runs before `npm start`.
// It skips the installation if this has already run and neither package.json nor package-lock.json has been modified since.
// This script automatically installs the packages listed in yarn.lock and runs before `yarn start`.
// It skips the installation if this has already run and neither package.json nor yarn.lock has been modified since.

import { execSync } from "child_process";
import { existsSync, statSync, writeFileSync } from "fs";

const INSTALL_TIMESTAMP_FILE = "node_modules/.install-timestamp";
const INSTALL_TIMESTAMP_FILE = ".install-timestamp";

// Checks if the install is needed by comparing modification times
const isInstallNeeded = () => {
if (!existsSync(INSTALL_TIMESTAMP_FILE)) return true;

const timestamp = statSync(INSTALL_TIMESTAMP_FILE).mtime;
return ["package.json", "package-lock.json"].some((file) => {
return ["package.json", "yarn.lock"].some((file) => {
return existsSync(file) && statSync(file).mtime > timestamp;
});
};

// Run `npm ci` if needed and update the install timestamp
// Run `yarn install` if needed and update the install timestamp
if (isInstallNeeded()) {
try {
// eslint-disable-next-line no-console
console.log("Installing npm packages...");
console.log("Installing yarn packages...");

// Check if packages are up to date, doing so quickly by using `npm ci`, preferring local cached packages, and skipping the package audit and other checks
execSync("npm ci --prefer-offline --no-audit --no-fund", { stdio: "inherit" });
// Check if packages are up to date, doing so quickly by using `--immutable` and `--immutable-cache`.
execSync("yarn install --immutable --immutable-cache", { stdio: "inherit" });

// Touch the install timestamp file
writeFileSync(INSTALL_TIMESTAMP_FILE, "");

// eslint-disable-next-line no-console
console.log("Finished installing npm packages.");
} catch (error) {
console.log("Finished installing yarn packages.");
} catch {
// eslint-disable-next-line no-console
console.error("Failed to install npm packages. Please run `npm install` from the `/frontend` directory.");
console.error("Failed to install yarn packages. Please run `yarn install` from the `/frontend` directory.");
process.exit(1);
}
} else {
// eslint-disable-next-line no-console
console.log("All npm packages are up-to-date.");
console.log("All yarn packages are up-to-date.");
}
Loading

0 comments on commit 2e6d29b

Please sign in to comment.