Skip to content

Commit aba716a

Browse files
committed
Merge remote-tracking branch 'SuperFlyTV/feat/require-node20'
2 parents bc87e8c + 46253cb commit aba716a

File tree

13 files changed

+963
-3115
lines changed

13 files changed

+963
-3115
lines changed

.github/workflows/node.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ jobs:
2525
with:
2626
fetch-depth: 0
2727
persist-credentials: false
28-
- name: Use Node.js 14.x
28+
- name: Use Node.js 22.x
2929
uses: actions/setup-node@v4
3030
with:
31-
node-version: 14.x
31+
node-version: 22.x
3232
- name: Check release is desired
3333
id: do-publish
3434
run: |
35+
corepack enable
36+
3537
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
3638
echo "No Token"
3739
else
@@ -83,12 +85,13 @@ jobs:
8385
- uses: actions/checkout@v4
8486
with:
8587
persist-credentials: false
86-
- name: Use Node.js 14.x
88+
- name: Use Node.js 22.x
8789
uses: actions/setup-node@v4
8890
with:
89-
node-version: 14.x
91+
node-version: 22.x
9092
- name: Prepare Environment
9193
run: |
94+
corepack enable
9295
yarn install
9396
env:
9497
CI: true
@@ -112,12 +115,13 @@ jobs:
112115
- uses: actions/checkout@v4
113116
with:
114117
persist-credentials: false
115-
- name: Use Node.js 14.x
118+
- name: Use Node.js 22.x
116119
uses: actions/setup-node@v4
117120
with:
118-
node-version: 14.x
121+
node-version: 22.x
119122
- name: Prepare Environment
120123
run: |
124+
corepack enable
121125
yarn install
122126
env:
123127
CI: true

.github/workflows/publish.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
with:
1616
fetch-depth: 0
1717
persist-credentials: false
18-
- name: Use Node.js 14.x
18+
- name: Use Node.js 22.x
1919
uses: actions/setup-node@v4
2020
with:
21-
node-version: 14.x
21+
node-version: 22.x
2222
- name: Check release is desired
2323
id: do-publish
2424
run: |
@@ -34,6 +34,7 @@ jobs:
3434
- name: Prepare Environment
3535
if: ${{ steps.do-publish.outputs.publish }}
3636
run: |
37+
corepack enable
3738
yarn install
3839
env:
3940
CI: true

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"semi": false,
66
"singleQuote": true,
77
"useTabs": true,
8-
"endOfLine": "lf"
8+
"endOfLine": "lf",
9+
"trailingComma": "es5"
910
}

.yarn/releases/yarn-3.5.0.cjs

Lines changed: 0 additions & 873 deletions
This file was deleted.

.yarnrc.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
11
nodeLinker: node-modules
2-
3-
plugins:
4-
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
5-
spec: "@yarnpkg/plugin-version"
6-
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
7-
spec: "@yarnpkg/plugin-interactive-tools"
8-
9-
yarnPath: .yarn/releases/yarn-3.5.0.cjs

README.md

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Sofie Code Standard Preset
2+
23
[![Node CI](https://github.com/nrkno/sofie-code-standard-preset/actions/workflows/node.yaml/badge.svg)](https://github.com/nrkno/sofie-code-standard-preset/actions/workflows/node.yaml)
34
[![npm](https://img.shields.io/npm/v/@sofie-automation/code-standard-preset)](https://www.npmjs.com/package/@sofie-automation/code-standard-preset)
45

@@ -7,15 +8,19 @@ This is the _Sofie_ code standard preset library used in the [_**Sofie** TV Auto
78
A script for checking compatible licenses is included.
89

910
## General Sofie System Information
10-
* [_Sofie_ Documentation](https://nrkno.github.io/sofie-core/)
11-
* [_Sofie_ Releases](https://nrkno.github.io/sofie-core/releases)
12-
* [Contribution Guidelines](CONTRIBUTING.md)
13-
* [License](LICENSE)
11+
12+
- [_Sofie_ Documentation](https://nrkno.github.io/sofie-core/)
13+
- [_Sofie_ Releases](https://nrkno.github.io/sofie-core/releases)
14+
- [Contribution Guidelines](CONTRIBUTING.md)
15+
- [License](LICENSE)
1416

1517
---
18+
1619
## Installation
1720

18-
`yarn add --dev @sofie-automation/code-standard-preset`
21+
This readme assumes you are using yarn v4. For other package managers the steps should be similar but may vary a little from what is written here.
22+
23+
`yarn add --dev @sofie-automation/code-standard-preset eslint typescript husky lint-staged prettier`
1924

2025
### Packages
2126

@@ -26,19 +31,19 @@ A script for checking compatible licenses is included.
2631
...,
2732
"scripts": {
2833
...,
29-
"prepare": "husky install",
30-
"lint:raw": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx --ignore-pattern dist",
31-
"lint": "yarn lint:raw .",
32-
"lint-fix": "yarn lint --fix",
33-
"license-validate": "yarn sofie-licensecheck"
34+
"prepare": "husky",
35+
"lint:raw": "eslint",
36+
"lint": "run lint:raw .",
37+
"lint-fix": "run lint --fix",
38+
"license-validate": "sofie-licensecheck"
3439
},
3540
"prettier": "@sofie-automation/code-standard-preset/.prettierrc.json",
3641
"lint-staged": {
3742
"*.{css,json,md,scss}": [
3843
"prettier --write"
3944
],
4045
"*.{ts,tsx,js,jsx}": [
41-
"yarn lint:raw --fix"
46+
"run lint:raw --fix"
4247
]
4348
},
4449
...
@@ -48,48 +53,63 @@ A script for checking compatible licenses is included.
4853
**Create** the husky hook file `.husky/pre-commit`
4954

5055
```sh
51-
#!/bin/sh
52-
. "$(dirname "$0")/_/husky.sh"
53-
54-
yarn lint-staged
56+
lint-staged
5557
```
5658

5759
**Adjust** build script references to make sure they use `tsconfig.build.json`, e.g. `tsc -p tsconfig.build.json`.
5860

5961
**Ensure** the following development dependencies are present:
6062

6163
- `@types\node` and `@types\jest` (if using)
62-
- Typescript 4 or above, e.g. `~4.0` with an up-to-date `tslib`
64+
- Typescript 5.7 or above, e.g. `~5.7` with an up-to-date `tslib`
6365
- `jest` and `ts-jest`, if using
6466

65-
**Remove** any other linting configurations or linters. Also, `node-license-validator` is no longer required. Remove libraries that are re-exported by this project `husky`, `lint-staged`, `eslint` and `prettier`
66-
6767
### Files
6868

6969
**Add** the following files:
7070

71-
_.eslintrc.json_
71+
_eslint.config.mjs_
7272

73-
```json
74-
{
75-
"extends": "./node_modules/@sofie-automation/code-standard-preset/eslint/main"
76-
}
73+
```mjs
74+
import { generateEslintConfig } from '@sofie-automation/code-standard-preset/eslint/main.mjs'
75+
76+
export default await generateEslintConfig({})
7777
```
7878

79-
If you are not using jest in your project, you will need to tell eslint to not try to detect the jest version:
79+
The parameter to the `generateEslintConfig` contains various option fields that can be configured.
8080

81-
```json
81+
```ts
8282
{
83-
"extends": "./node_modules/@sofie-automation/code-standard-preset/eslint/main",
84-
"settings": {
85-
"jest": {
86-
"version": "latest"
87-
}
88-
}
83+
/** Any extra paths to be ignored by eslint */
84+
ignores?: string[]
85+
/** If you need eslint to use a non-default tsconfig, provide the path. When not set it uses the default search behaviour */
86+
tsconfigName?: string | string[]
87+
/** If the project is browser based instead of node based, you can disable the node runtime rules */
88+
disableNodeRules?: boolean
8989
}
9090
```
9191

92-
Add _.eslintignore_ if any folders or files should be ignored by the linter.
92+
If you need to add additional rules, you can do so by building off the generated config, such as:
93+
94+
```mjs
95+
import { generateEslintConfig } from '@sofie-automation/code-standard-preset/eslint/main.mjs'
96+
import pluginYaml from 'eslint-plugin-yml'
97+
98+
const extendedRules = await generateEslintConfig({
99+
ignores: ['client', 'server'],
100+
})
101+
extendedRules.push(...pluginYaml.configs['flat/recommended'], {
102+
files: ['**/*.yaml'],
103+
104+
rules: {
105+
'yml/quotes': ['error', { prefer: 'single' }],
106+
'yml/spaced-comment': ['error'],
107+
'spaced-comment': ['off'],
108+
},
109+
})
110+
111+
export default extendedRules
112+
```
93113

94114
_tsconfig.json_
95115

@@ -136,17 +156,41 @@ _Note: replace the {{PACKAGE-NAME}} with the correct package name, i.e. `hyperde
136156

137157
```javascript
138158
module.exports = {
139-
globals: {
140-
'ts-jest': {
141-
tsconfig: 'tsconfig.json'
142-
}
143-
}, // ...
159+
transform: {
160+
'^.+\\.(ts|tsx)$': [
161+
'ts-jest',
162+
{
163+
tsconfig: 'tsconfig.json',
164+
},
165+
],
166+
},
167+
// ...
144168
```
145169
146170
**Remove** any other old linting or tsconfig files and refernces to them, for example a `config` folder containing `tsconfig...` files. These are no longer required.
147171
148172
## Upgrade
149173
174+
### v2 to v3.0
175+
176+
If not already, the project should be updated to yarn v4 instead of yarn v1. yarn v1 was EOL a few years ago, and v4 is working for us quite nicely.
177+
178+
1. Make sure that you are ready to do a semver major bump, with a new minimum nodejs version of v20.
179+
1. Update your package.json engines to require node 20
180+
1. Install the updated `@sofie-automation/code-standard-preset` package
181+
1. Install tools that used to be included by the preset package: `yarn add eslint husky lint-staged prettier`, any you do not need can be omitted.
182+
1. Check the package.json scripts;
183+
- Change `husky install` to `husky`
184+
- Change the `lint:raw` to simply `eslint`
185+
- Check if any `yarn X` can be made simply `X` or `run X`
186+
1. In `.husky/pre-commit`, replace the contents to be simply `lint-staged`
187+
1. Ensure the project has an updated typescript
188+
- This may require updating other tools, be sure to check jest/compiling later
189+
1. Remove the existing `.eslintrc.json` and replace with the new `eslint.config.mjs` example above. If you have modified your file from the default, you will need to translate that across.
190+
1. In your code, any references to eslint rules `node/*` have been renamed to `n/*`
191+
1. Due to the rules requiring conforming to ESM import syntax, you may need to update many file imports. You can use `npx fix-esm-import-path src` as an easy way of updating all the imports in the project
192+
1. Make sure that everything is working. You will likely have a bunch of linter failures due to updated formatting and linting rules, which will need resolving.
193+
150194
### v2.0 to v2.1
151195
152196
This release introduces a simple replacement for `standard-version`
@@ -163,6 +207,7 @@ Steps:
163207
- Below any `yarn publish ....` lines, add `echo "**Published:** $NEW_VERSION" >> $GITHUB_STEP_SUMMARY` to log the publish in the github action workflow
164208
165209
While you are here, try to update any `uses:` lines in the actions workflows, common ones that need updating:
210+
166211
- `actions/checkout@v3`
167212
- `actions/setup-node@v3`
168213
@@ -176,7 +221,6 @@ Steps:
176221
- Remove the old husky config from `package.json`
177222
- Update the scripts and lint-staged config in `package.json`
178223
179-
180224
---
181225
182226
_The NRK logo is a registered trademark of Norsk rikskringkasting AS. The license does not grant any right to use, in any way, any trademarks, service marks or logos of Norsk rikskringkasting AS._

bin/checkLicenses.mjs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env node
22
'use strict'
33
import meow from 'meow'
4-
import { readPackageUpSync } from 'read-pkg-up'
4+
import { readPackageUpSync } from 'read-package-up'
55
import path from 'path'
66
import checker from 'license-checker'
77

@@ -27,7 +27,7 @@ const cli = meow(
2727
type: 'string',
2828
},
2929
},
30-
}
30+
},
3131
)
3232

3333
// This is so that when used in a private project it validates
@@ -65,21 +65,23 @@ if (cli.flags.debug) {
6565
console.log('allowList', allowList)
6666
}
6767

68-
checker.init({
69-
start: path.resolve('.'),
70-
onlyAllow: allowList,
71-
excludePackages: excludePackages,
72-
summary: !cli.flags.debug
73-
}, (err, packages) => {
74-
75-
if (err) {
76-
//Handle error
77-
console.error(err)
78-
process.exit(1)
79-
} else {
80-
if (cli.flags.debug) {
81-
console.log(packages)
68+
checker.init(
69+
{
70+
start: path.resolve('.'),
71+
onlyAllow: allowList,
72+
excludePackages: excludePackages,
73+
summary: !cli.flags.debug,
74+
},
75+
(err, packages) => {
76+
if (err) {
77+
//Handle error
78+
console.error(err)
79+
process.exit(1)
80+
} else {
81+
if (cli.flags.debug) {
82+
console.log(packages)
83+
}
84+
process.exit(0)
8285
}
83-
process.exit(0)
84-
}
85-
});
86+
},
87+
)

0 commit comments

Comments
 (0)