Signed-off-by: T-Hax <>
This commit is contained in:
T-Hax 2023-04-28 17:40:24 +00:00
commit 1fadb4f915
5 changed files with 141 additions and 0 deletions

65
README.md Normal file
View file

@ -0,0 +1,65 @@
# Setting up yarn v3 to work with Gitea
Instead of using Yarn Classic (V1), we are using V3 for working with new projects. This is for the reason that Yarn Classic is annoying when working with Gitea repositories and shouldn't really be bothered with.
The guide to installing and configuring Yarn V3 follows.
# Install guide
Checkout [tl;dr](./TLDR.md) if you are about to fall asleep.
You should first deinstall the current version of yarn which you are using. If you have legacy repositories with aliased package names (e.g. `"my-package": "npm:@scope/my-package"`), then you should look into use `corepack` on using an older Yarn version on that specific repository.
If you have Node 16.10 or higher, you should already have a program called [**Corepack**](https://nodejs.org/dist/latest/docs/api/corepack.html). If you don't, read the section "Node.js <16.10" below. Otherwise, enable as stated in the section after it.
### Node.js <16.10
Corepack isn't included with Node.js in versions before the 16.10; to address that, run:
```bash
npm i -g corepack
corepack prepare yarn@<version> --activate
yarn --version
```
### Node.js >=16.10
Corepack is included by default with all Node.js installs, but is currently opt-in. To enable it, run the following command:
```bash
corepack enable
corepack prepare yarn@stable --activate
yarn --version
```
## Configuration
Yarn V3 doesn't support global options and instead has project (dir) specific options which write for any non-defaults a new .yarnrc.yml file in your current dir.
This is similar to python packaging (pip and venvs) and is preferable for working with projects.
In any case check out the [sample config for this gitea, it will be kept updated.](./yarnrc.yml).
## Tip
Yarn V1 renaming a package:
```json
{
"dependencies": {
"some-package": "npm:@scope/some-package"
}
}
```
Yarn V2/3 doing the same:
```json
{
"dependencies": {
"some-package": "npm:@scope/some-package@<version statement>"
}
}
```
The range is necessary for installing the package.

30
TLDR.md Normal file
View file

@ -0,0 +1,30 @@
install
```bash
# first deinstall yarn to be safe
npm i -g corepack
corepack prepare yarn@<version> --activate
yarn --version
# Should print 3.X.X or above
```
for node <16.10
```bash
# first deinstall yarn to be safe
corepack enable
corepack prepare yarn@stable --activate
yarn --version
# Should print 3.X.X or above
```
for node >=16.10
then to setup a project
```bash
cp yarnrc.yml your-project-dir/.yarnrc.yml
cp env.example your-project-dir/.env
cat gitignore >> your-project-dir/.gitignore
# Then uncomment one of the possibilities in gitignore
```

2
env.example Normal file
View file

@ -0,0 +1,2 @@
#!/bin/bash
export GITEA_AUTH_TOKEN=

19
gitignore Normal file
View file

@ -0,0 +1,19 @@
# If you're using Zero-Installs:
# .yarn/*
# !.yarn/cache
# !.yarn/patches
# !.yarn/plugins
# !.yarn/releases
# !.yarn/sdks
# !.yarn/versions
# If you're not using Zero-Installs:
# .pnp.*
# .yarn/*
# !.yarn/patches
# !.yarn/plugins
# !.yarn/releases
# !.yarn/sdks
# !.yarn/versions

25
yarnrc.yml Normal file
View file

@ -0,0 +1,25 @@
# So basically, we want to selectively download packages from the Gitea repository but still allow the
# main repositories, so we are going to have to scope OUR packages properly. This means, unless the tornadocash
# Gitea organization defines a default scope, that we'll have to add every user scope. Including my own below.
# Note that all scopes are after @ prefix. So my prefix is @thax
npmScopes:
thax:
npmPublishRegistry: "https://development.tornadocash.community/api/packages/T-Hax/npm/"
npmRegistryServer: "https://development.tornadocash.community/api/packages/T-Hax/npm/"
# The below can be EXPORTED via some env file which actually exports the variables though
# Check the env.example, you will notice it's not a regular env
# So split your env files up, since this is only for manual actions
# npmAuthToken: ${GITEA_AUTH_TOKEN}
# If the following isn't set you won't have a node_modules folder
# You might be used to a node_modules folder instead of a pnp or other folder type
# If you want to use the new linkers uncomment or change the following
nodeLinker: "node-modules"
# So the tornadocash org, the person who maintains it, might setup something (in future) like,
# tornadocash:
# npmPublishRegistry: "https://development.tornadocash.community/api/packages/tornadocash/npm/"
# npmRegistryServer: "https://development.tornadocash.community/api/packages/tornadocash/npm/"
# We disable telemetry for obvious reasons.
enableTelemetry: false