@10stars/config 15.5.5 → 15.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10stars/config",
3
- "version": "15.5.5",
3
+ "version": "15.6.1",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "config": "./src/index.ts"
@@ -25,6 +25,7 @@
25
25
  "@types/bun": "^1.3.14",
26
26
  "@types/node": "^25.9.1",
27
27
  "@types/react": "^19.2.16",
28
+ "@types/react-dom": "^19.2.0",
28
29
  "husky": "^9.1.7",
29
30
  "oxfmt": "0.51.0",
30
31
  "oxlint": "^1.68.0",
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import path from "node:path"
5
5
 
6
6
  import { resetColorIndex } from "./colors"
7
7
  import { checkIsMonorepo, linkPackages } from "./link-packages"
8
+ import { setupOverrides } from "./manage-overrides"
8
9
  import { runConcurrently, type CommandConfig } from "./runner"
9
10
  import { setupVSCode } from "./vscode-config"
10
11
 
@@ -51,6 +52,7 @@ const actions = {
51
52
 
52
53
  exec(`husky`) // husky is intended only for local development (not in CI)
53
54
  await setupVSCode(cwd) // create/update .vscode directory with standardized extensions.json and settings.json
55
+ await setupOverrides(cwd) // sync standardized package.json overrides
54
56
 
55
57
  const config = await getConfig()
56
58
  if (config?.linkPackages) await linkPackages(cwd, config.linkPackages)
@@ -0,0 +1,65 @@
1
+ import { execSync } from "node:child_process"
2
+ import fs from "node:fs/promises"
3
+ import path from "node:path"
4
+
5
+ import type * as TF from "type-fest"
6
+
7
+ // Packages whose overrides are derived from this package's own dependency versions.
8
+ const managedPackages = ["@types/node", "@types/react", "@types/react-dom", "type-fest"]
9
+
10
+ const getMajor = (range: string): string | null => {
11
+ const major = range.match(/\d+/)?.[0]
12
+ return major ?? null
13
+ }
14
+
15
+ const buildManagedOverrides = async (): Promise<Record<string, string>> => {
16
+ const ownPkgPath = new URL("../package.json", import.meta.url).pathname
17
+ const ownPkg: TF.PackageJson = JSON.parse(await fs.readFile(ownPkgPath, `utf8`))
18
+ const deps = { ...ownPkg.devDependencies, ...ownPkg.dependencies }
19
+
20
+ const overrides: Record<string, string> = {}
21
+ for (const name of managedPackages) {
22
+ const range = deps[name]
23
+ if (!range) {
24
+ console.warn(`Skipping override for "${name}": not found in @10stars/config dependencies`)
25
+ continue
26
+ }
27
+ const major = getMajor(range)
28
+ if (!major) {
29
+ console.warn(`Skipping override for "${name}": cannot parse major version from "${range}"`)
30
+ continue
31
+ }
32
+ overrides[name] = `^${major}.0.0`
33
+ }
34
+ return overrides
35
+ }
36
+
37
+ export const setupOverrides = async (cwd: string) => {
38
+ const pkgPath = path.join(cwd, `package.json`)
39
+
40
+ let pkgJson: TF.PackageJson
41
+ try {
42
+ pkgJson = JSON.parse(await fs.readFile(pkgPath, `utf8`))
43
+ } catch (error) {
44
+ console.error(`Error reading or parsing package.json:`, error)
45
+ return
46
+ }
47
+
48
+ const managedOverrides = await buildManagedOverrides()
49
+
50
+ // Merge: managed values win, any existing unmanaged override keys are preserved.
51
+ const merged = { ...pkgJson.overrides, ...managedOverrides }
52
+ const sorted = Object.fromEntries(Object.entries(merged).sort(([a], [b]) => a.localeCompare(b)))
53
+
54
+ const changed = JSON.stringify(pkgJson.overrides ?? {}) !== JSON.stringify(sorted)
55
+ if (!changed) return
56
+
57
+ pkgJson.overrides = sorted
58
+
59
+ await fs.writeFile(pkgPath, JSON.stringify(pkgJson, null, 2) + `\n`)
60
+ console.info(`Written: ${pkgPath}`)
61
+ execSync(`bunx oxfmt ${pkgPath}`, { cwd, stdio: `inherit` })
62
+
63
+ console.info(`Overrides changed, running "bun install"...`)
64
+ execSync(`bun install`, { cwd, stdio: `inherit` })
65
+ }