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

Refactor/monorepo (WIP) #561

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!.eslintrc.js
!.meta-updater
coverage
dist
test/setup.ts
services/**/*.mjs
*.js
*.mjs
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
extends: ['@heise'],
plugins: ['sort-keys-fix', 'eslint-plugin-no-only-tests'],
plugins: ['sort-keys-fix'],
rules: {
'sort-keys-fix/sort-keys-fix': 'error',
'no-prototype-builtins': 'off',
Expand All @@ -17,6 +17,10 @@ module.exports = {
es6: true,
},
overrides: [
{
files: ['jest.config.ts'],
rules: {'node/no-extraneous-import': 'off'},
},
{
files: ['*.test.ts', '*.js', '__tests__/**/*.ts'],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: pnpm semantic-release
run: pnpm release
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tsconfig.build.tsbuildinfo
**/main
*.tsbuildinfo
.eslintcache
dist
# Logs
Expand Down
1 change: 1 addition & 0 deletions .meta-updater/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tagFormat":"@edged/updater@v${version}"}
3 changes: 3 additions & 0 deletions .meta-updater/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import updater from './dist/index.js'

export default updater
20 changes: 20 additions & 0 deletions .meta-updater/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@edged/updater",
"version": "1.0.0",
"main": "dist/index.js",
"private": true,
"type": "module",
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"@pnpm/find-workspace-packages": "^3.1.12",
"@pnpm/lockfile-file": "^4.1.1",
"@pnpm/logger": "^4.0.0",
"@pnpm/types": "^7.4.0",
"@types/normalize-path": "^3.0.0",
"is-subdir": "^1.2.0",
"normalize-path": "^3.0.0"
},
"author": "Philipp Busse"
}
92 changes: 92 additions & 0 deletions .meta-updater/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable sonarjs/cognitive-complexity */

import { readWantedLockfile } from '@pnpm/lockfile-file'
import { LockfileFile } from '@pnpm/lockfile-file/lib/write'
import { ProjectManifest } from '@pnpm/types'
import { existsSync } from 'fs'
import normalizePath from 'normalize-path'
import path from 'path'

type UpdateFunc = (
data: Record<string, unknown>,
dir: string,
manifest: ProjectManifest,
) => Record<string, unknown> | Promise<Record<string, unknown> | null> | null

export default async (
workspaceDir: string,
): Promise<Record<string, UpdateFunc>> => {
const lockfile = await readWantedLockfile(workspaceDir, {
ignoreIncompatible: false,
})

if (lockfile == null) {
throw new Error('no lockfile found')
}

return {
'.releaserc.json': (releaseRc, _dir: string, manifest) => {
if (!manifest.name) {
return {}
}

return { tagFormat: `${manifest.name}@v\${version}`, ...releaseRc }
},
'package.json': updatePackageJson(workspaceDir, lockfile),
'tsconfig.build.json': updateTsConfig(workspaceDir, lockfile),
'tsconfig.json': updateTsConfig(workspaceDir, lockfile),
}
}

function updatePackageJson(_workspaceDir: string, _lockfile: LockfileFile) {
return (manifest: ProjectManifest, _dir: string) => {
return {
...manifest,
author: 'Philipp Busse',
}
}
}

function updateTsConfig(workspaceDir: string, lockfile: LockfileFile) {
Copy link

Choose a reason for hiding this comment

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

Function updateTsConfig has 32 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

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

Function updateTsConfig has 34 lines of code (exceeds 25 allowed). Consider refactoring.

return (
tsConfig: Record<string, unknown>,
dir: string,
manifest: ProjectManifest,
) => {
if (tsConfig == null || manifest.name?.includes('/tsconfig')) {
return tsConfig
}

const relative = normalizePath(path.relative(workspaceDir, dir))

const importer = lockfile.importers?.[relative]

if (!importer) {
return tsConfig
}

const deps = {
...importer.dependencies,
...importer.devDependencies,
}

const references = Object.values(deps)
.filter((dep) => dep.startsWith('link:'))
.filter((dep) => !dep.endsWith('tsconfig'))
.map((dep) => dep.slice('link:'.length))
.filter((relativePath) =>
existsSync(path.join(dir, relativePath, 'tsconfig.json')),
)
.map((path) => ({ path }))

console.log(`Updating tsconfig for ${dir}: ${JSON.stringify(references)}`)

return {
...tsConfig,
exclude: ['node_modules', 'dist'],
...(references && {
references: references.sort((r1, r2) => r1.path.localeCompare(r2.path)),
}),
}
}
}
11 changes: 11 additions & 0 deletions .meta-updater/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@edged/tsconfig",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"module": "ES2020"
},
"include": ["src/**/*"],
"references": [],
"exclude": ["node_modules", "dist"]
}
18 changes: 0 additions & 18 deletions .releaserc

This file was deleted.

25 changes: 25 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"tagFormat": "@edged/repo@v${version}",
"branches": ["master"],
"repositoryUrl": "[email protected]:pmb0/express-sharp.git",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": ["package.json", "CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
}
]
],
"fail": false,
"success": false
}
9 changes: 0 additions & 9 deletions __mocks__/got.ts

This file was deleted.

Loading