Skip to content

Commit

Permalink
Merge remote-tracking branch 'SuperFlyTV/feat/require-node20'
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Feb 4, 2025
2 parents bc87e8c + 46253cb commit aba716a
Show file tree
Hide file tree
Showing 13 changed files with 963 additions and 3,115 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- name: Use Node.js 14.x
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 22.x
- name: Check release is desired
id: do-publish
run: |
corepack enable
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
echo "No Token"
else
Expand Down Expand Up @@ -83,12 +85,13 @@ jobs:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js 14.x
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 22.x
- name: Prepare Environment
run: |
corepack enable
yarn install
env:
CI: true
Expand All @@ -112,12 +115,13 @@ jobs:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js 14.x
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 22.x
- name: Prepare Environment
run: |
corepack enable
yarn install
env:
CI: true
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- name: Use Node.js 14.x
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 22.x
- name: Check release is desired
id: do-publish
run: |
Expand All @@ -34,6 +34,7 @@ jobs:
- name: Prepare Environment
if: ${{ steps.do-publish.outputs.publish }}
run: |
corepack enable
yarn install
env:
CI: true
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"semi": false,
"singleQuote": true,
"useTabs": true,
"endOfLine": "lf"
"endOfLine": "lf",
"trailingComma": "es5"
}
873 changes: 0 additions & 873 deletions .yarn/releases/yarn-3.5.0.cjs

This file was deleted.

8 changes: 0 additions & 8 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.5.0.cjs
120 changes: 82 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Sofie Code Standard Preset

[![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)
[![npm](https://img.shields.io/npm/v/@sofie-automation/code-standard-preset)](https://www.npmjs.com/package/@sofie-automation/code-standard-preset)

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

## General Sofie System Information
* [_Sofie_ Documentation](https://nrkno.github.io/sofie-core/)
* [_Sofie_ Releases](https://nrkno.github.io/sofie-core/releases)
* [Contribution Guidelines](CONTRIBUTING.md)
* [License](LICENSE)

- [_Sofie_ Documentation](https://nrkno.github.io/sofie-core/)
- [_Sofie_ Releases](https://nrkno.github.io/sofie-core/releases)
- [Contribution Guidelines](CONTRIBUTING.md)
- [License](LICENSE)

---

## Installation

`yarn add --dev @sofie-automation/code-standard-preset`
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.

`yarn add --dev @sofie-automation/code-standard-preset eslint typescript husky lint-staged prettier`

### Packages

Expand All @@ -26,19 +31,19 @@ A script for checking compatible licenses is included.
...,
"scripts": {
...,
"prepare": "husky install",
"lint:raw": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx --ignore-pattern dist",
"lint": "yarn lint:raw .",
"lint-fix": "yarn lint --fix",
"license-validate": "yarn sofie-licensecheck"
"prepare": "husky",
"lint:raw": "eslint",
"lint": "run lint:raw .",
"lint-fix": "run lint --fix",
"license-validate": "sofie-licensecheck"
},
"prettier": "@sofie-automation/code-standard-preset/.prettierrc.json",
"lint-staged": {
"*.{css,json,md,scss}": [
"prettier --write"
],
"*.{ts,tsx,js,jsx}": [
"yarn lint:raw --fix"
"run lint:raw --fix"
]
},
...
Expand All @@ -48,48 +53,63 @@ A script for checking compatible licenses is included.
**Create** the husky hook file `.husky/pre-commit`

```sh
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
lint-staged
```

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

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

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

**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`

### Files

**Add** the following files:

_.eslintrc.json_
_eslint.config.mjs_

```json
{
"extends": "./node_modules/@sofie-automation/code-standard-preset/eslint/main"
}
```mjs
import { generateEslintConfig } from '@sofie-automation/code-standard-preset/eslint/main.mjs'

export default await generateEslintConfig({})
```

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

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

Add _.eslintignore_ if any folders or files should be ignored by the linter.
If you need to add additional rules, you can do so by building off the generated config, such as:

```mjs
import { generateEslintConfig } from '@sofie-automation/code-standard-preset/eslint/main.mjs'
import pluginYaml from 'eslint-plugin-yml'

const extendedRules = await generateEslintConfig({
ignores: ['client', 'server'],
})
extendedRules.push(...pluginYaml.configs['flat/recommended'], {
files: ['**/*.yaml'],

rules: {
'yml/quotes': ['error', { prefer: 'single' }],
'yml/spaced-comment': ['error'],
'spaced-comment': ['off'],
},
})

export default extendedRules
```

_tsconfig.json_

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

```javascript
module.exports = {
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json'
}
}, // ...
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
// ...
```
**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.
## Upgrade
### v2 to v3.0
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.
1. Make sure that you are ready to do a semver major bump, with a new minimum nodejs version of v20.
1. Update your package.json engines to require node 20
1. Install the updated `@sofie-automation/code-standard-preset` package
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.
1. Check the package.json scripts;
- Change `husky install` to `husky`
- Change the `lint:raw` to simply `eslint`
- Check if any `yarn X` can be made simply `X` or `run X`
1. In `.husky/pre-commit`, replace the contents to be simply `lint-staged`
1. Ensure the project has an updated typescript
- This may require updating other tools, be sure to check jest/compiling later
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.
1. In your code, any references to eslint rules `node/*` have been renamed to `n/*`
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
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.
### v2.0 to v2.1
This release introduces a simple replacement for `standard-version`
Expand All @@ -163,6 +207,7 @@ Steps:
- Below any `yarn publish ....` lines, add `echo "**Published:** $NEW_VERSION" >> $GITHUB_STEP_SUMMARY` to log the publish in the github action workflow
While you are here, try to update any `uses:` lines in the actions workflows, common ones that need updating:
- `actions/checkout@v3`
- `actions/setup-node@v3`
Expand All @@ -176,7 +221,6 @@ Steps:
- Remove the old husky config from `package.json`
- Update the scripts and lint-staged config in `package.json`
---
_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._
40 changes: 21 additions & 19 deletions bin/checkLicenses.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
'use strict'
import meow from 'meow'
import { readPackageUpSync } from 'read-pkg-up'
import { readPackageUpSync } from 'read-package-up'
import path from 'path'
import checker from 'license-checker'

Expand All @@ -27,7 +27,7 @@ const cli = meow(
type: 'string',
},
},
}
},
)

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

checker.init({
start: path.resolve('.'),
onlyAllow: allowList,
excludePackages: excludePackages,
summary: !cli.flags.debug
}, (err, packages) => {

if (err) {
//Handle error
console.error(err)
process.exit(1)
} else {
if (cli.flags.debug) {
console.log(packages)
checker.init(
{
start: path.resolve('.'),
onlyAllow: allowList,
excludePackages: excludePackages,
summary: !cli.flags.debug,
},
(err, packages) => {
if (err) {
//Handle error
console.error(err)
process.exit(1)
} else {
if (cli.flags.debug) {
console.log(packages)
}
process.exit(0)
}
process.exit(0)
}
});
},
)
Loading

0 comments on commit aba716a

Please sign in to comment.