Skip to content

Commit 459f520

Browse files
authored
Use newest framework version for yarn new (#4767)
1 parent f6c01f2 commit 459f520

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

.changeset/famous-peas-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/ea-scripts': minor
3+
---
4+
5+
Use newest framework version for yarn new

.pnp.cjs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/scripts/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"json-schema-ref-parser": "9.0.9",
2020
"mockserver-client": "5.15.0",
2121
"rxjs": "7.4.0",
22+
"semver": "7.7.2",
2223
"shelljs": "0.8.5",
2324
"snake-case": "3.0.4",
2425
"swagger-jsdoc": "6.1.0",
@@ -29,6 +30,7 @@
2930
"@types/command-line-args": "5.2.3",
3031
"@types/command-line-usage": "5.0.4",
3132
"@types/jest": "^29.5.14",
33+
"@types/semver": "7.5.8",
3234
"@types/shelljs": "0.8.16",
3335
"@types/swagger-jsdoc": "6.0.4",
3436
"@types/yaml": "1.9.7",

packages/scripts/src/new/index.ts

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
11
import { execSync } from 'child_process'
2+
import { gt } from 'semver'
23
import { generate, writeJson } from './lib'
34

5+
const FRAMEWORK = '@chainlink/external-adapter-framework@'
6+
const EA_SCRIPTS = '@chainlink/ea-scripts@workspace:packages/scripts'
7+
8+
type WhyRow = { value: string; children: Record<string, unknown> }
9+
10+
function descriptor(childKey: string): string | null {
11+
return childKey.startsWith(FRAMEWORK) ? childKey.slice(FRAMEWORK.length) : null
12+
}
13+
14+
// Returns highest framework version used in the repo.
15+
// Except it returns the portal version if it's used in ea-scripts.
16+
function getFrameworkVersionSpecFromRepo(): string {
17+
const out = execSync('yarn why @chainlink/external-adapter-framework --json', {
18+
encoding: 'utf-8',
19+
})
20+
21+
const rows = out
22+
.trimEnd()
23+
.split('\n')
24+
.map((line) => JSON.parse(line.trim()) as WhyRow)
25+
26+
const eaScripts = rows.find((r) => r.value === EA_SCRIPTS)!
27+
28+
for (const key of Object.keys(eaScripts.children)) {
29+
const d = descriptor(key)
30+
if (d?.startsWith('portal:')) {
31+
return d
32+
}
33+
}
34+
35+
let max: string | undefined
36+
for (const row of rows) {
37+
for (const key of Object.keys(row.children)) {
38+
const d = descriptor(key)
39+
if (!d?.startsWith('npm:')) {
40+
continue
41+
}
42+
const v = d.slice('npm:'.length)
43+
if (max === undefined || gt(v, max)) {
44+
max = v
45+
}
46+
}
47+
}
48+
49+
return `npm:${max}`
50+
}
51+
452
if (process.argv[2] == 'tsconfig') {
553
// Update tsconfig files
654
generate().then(writeJson)
@@ -27,14 +75,7 @@ if (process.argv[2] == 'tsconfig') {
2775
execSync(`rm -rf ./.yarn/cache/node_modules`)
2876
// This should give either something like 'npm:1.2.3' or
2977
// 'portal:some/local/path:...'
30-
const frameworkVersion = execSync(
31-
`yarn --cwd packages/scripts info @chainlink/external-adapter-framework --json | jq -r '.value'`,
32-
{
33-
encoding: 'utf-8',
34-
},
35-
)
36-
.trim()
37-
.split('@')[2]
78+
const frameworkVersion = getFrameworkVersionSpecFromRepo()
3879

3980
let generatorIndexPath = ''
4081

yarn.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,7 @@ __metadata:
32213221
"@types/command-line-args": "npm:5.2.3"
32223222
"@types/command-line-usage": "npm:5.0.4"
32233223
"@types/jest": "npm:^29.5.14"
3224+
"@types/semver": "npm:7.5.8"
32243225
"@types/shelljs": "npm:0.8.16"
32253226
"@types/swagger-jsdoc": "npm:6.0.4"
32263227
"@types/yaml": "npm:1.9.7"
@@ -3237,6 +3238,7 @@ __metadata:
32373238
json-schema-ref-parser: "npm:9.0.9"
32383239
mockserver-client: "npm:5.15.0"
32393240
rxjs: "npm:7.4.0"
3241+
semver: "npm:7.7.2"
32403242
shelljs: "npm:0.8.5"
32413243
snake-case: "npm:3.0.4"
32423244
swagger-jsdoc: "npm:6.1.0"
@@ -9890,7 +9892,7 @@ __metadata:
98909892
languageName: node
98919893
linkType: hard
98929894

9893-
"@types/semver@npm:^7.3.12":
9895+
"@types/semver@npm:7.5.8, @types/semver@npm:^7.3.12":
98949896
version: 7.5.8
98959897
resolution: "@types/semver@npm:7.5.8"
98969898
checksum: 10/3496808818ddb36deabfe4974fd343a78101fa242c4690044ccdc3b95dcf8785b494f5d628f2f47f38a702f8db9c53c67f47d7818f2be1b79f2efb09692e1178
@@ -17883,7 +17885,7 @@ __metadata:
1788317885
languageName: node
1788417886
linkType: hard
1788517887

17886-
"semver@npm:7.x, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.7.2":
17888+
"semver@npm:7.7.2, semver@npm:7.x, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.7.2":
1788717889
version: 7.7.2
1788817890
resolution: "semver@npm:7.7.2"
1788917891
bin:

0 commit comments

Comments
 (0)