Skip to content

Commit

Permalink
add typescript as a peer dependency and upgrade to 4.9.5
Browse files Browse the repository at this point in the history
Typescript doesn't follow semantic versioning (microsoft/TypeScript#39269). This means that there could be breaking changes in caret (`^`) ranges.

This change:
- upgrades to Typescript 4.9.5 for building the typescript files
- adds Typescript ~4.9.5 as a `peerDependency` of the generated npm package
- adds a `scroogeTypescriptPeerDependencies` setting to enable plugin users to add peer dependencies to the `package.json`
- fixes a mismatched type in the `decode-encode` module
  • Loading branch information
georgeblahblah authored and rtyley committed Jan 11, 2024
1 parent 75e6d07 commit 83e8d19
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Here are some settings you may want to use:
- scroogeTypescriptPackageLicense: The license of the package on NPM
- scroogeTypescriptPackageMapping: The mapping between scala libraries and their NPM equivalent
- scroogeTypescriptDevDependencies: The dev dependencies to put in the `package.json`
- scroogeTypescriptPeerDependencies: The peer dependencies to put in the `package.json`
- scroogeTypescriptDependencies: The dependencies to put in the `package.json`
- scroogeTypescriptDryRun: To be able to run everything without publishing to NPM
- scroogeTypescriptPublishTag: An optional tag for your NPM release, primarily for beta.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"homepage": "https://github.com/guardian/scrooge-extras#readme",
"devDependencies": {
"typescript": "^4.1.5"
"typescript": "4.9.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object ScroogeTypescriptGen extends AutoPlugin {

// the settings to customise the generation process
lazy val scroogeTypescriptDevDependencies = settingKey[Map[String, String]]("The node devDependencies to include in the package.json")
lazy val scroogeTypescriptPeerDependencies = settingKey[Map[String, String]]("The node peerDependencies to include in the package.json")
lazy val scroogeTypescriptDependencies = settingKey[Map[String, String]]("The node dependencies to include in the package.json")
lazy val scroogeTypescriptPackageDirectory = settingKey[File]("The directory where the node package will be generated")
lazy val scroogeTypescriptPackageLicense = settingKey[String]("The license used to publish the package")
Expand All @@ -47,6 +48,7 @@ object ScroogeTypescriptGen extends AutoPlugin {

override def projectSettings: Seq[Def.Setting[_]] = Seq(
scroogeTypescriptDevDependencies := NPMLibraries.devDependencies,
scroogeTypescriptPeerDependencies := NPMLibraries.peerDependencies,
scroogeTypescriptDependencies := {
val dependencies = (Compile / scroogeThriftDependencies).value.flatMap { dependency =>
for {
Expand Down Expand Up @@ -79,7 +81,8 @@ object ScroogeTypescriptGen extends AutoPlugin {
| "author": "",
| "license": "${scroogeTypescriptPackageLicense.value}",
| "devDependencies": ${asHash(scroogeTypescriptDevDependencies.value)},
| "dependencies": ${asHash(scroogeTypescriptDependencies.value)}
| "dependencies": ${asHash(scroogeTypescriptDependencies.value)},
| "peerDependencies": ${asHash(scroogeTypescriptPeerDependencies.value)},
|}""".stripMargin
IO.write(packageJson, content)
packageJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package com.gu.scrooge.backend.typescript
object NPMLibraries {
val dependencies = Map(
"@types/node-int64" -> "^0.4.29",
"@types/thrift" -> "^0.10.11",
"@types/thrift" -> "^0.10.12",
"node-int64" -> "^0.4.0",
"thrift" -> "^0.15.0"
)

val devDependencies = Map("typescript" -> "^4.5.4")
val devDependencies = Map("typescript" -> "4.9.5")
val peerDependencies = Map("typescript" -> "~4.9.5")
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ async function decode(buffer: Buffer): Promise<School> {
async function encode(school: School): Promise<Buffer> {
return new Promise((resolve, reject) => {
const outputBufferTransport = new TBufferedTransport(undefined, (buffer, seqId) => {
resolve(buffer);
if (buffer !== undefined) {
resolve(buffer);
} else {
reject();
}
});
const outputProtocol = new TCompactProtocol(outputBufferTransport);
SchoolSerde.write(outputProtocol, school);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "4.9.5"
},
"dependencies": {
"@guardian/school": "file:../school",
"@types/thrift": "^0.10.9",
"thrift": "^0.12.0"
"@types/thrift": "^0.10.12",
"thrift": "^0.15.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "4.9.5"
},
"dependencies": {
"@types/node-int64": "^0.4.29",
"@types/thrift": "^0.10.9",
"@types/thrift": "^0.10.12",
"node-int64": "^0.4.0",
"thrift": "^0.12.0"
"thrift": "^0.15.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "4.9.5"
},
"dependencies": {
"@types/node-int64": "^0.4.29",
"@types/thrift": "^0.10.9",
"@types/thrift": "^0.10.12",
"node-int64": "^0.4.0",
"thrift": "^0.12.0"
"thrift": "^0.15.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "4.9.5"
},
"dependencies": {
"@types/node-int64": "^0.4.29",
"@types/thrift": "^0.10.9",
"@types/thrift": "^0.10.12",
"node-int64": "^0.4.0",
"thrift": "^0.12.0"
"thrift": "^0.15.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "^4.9.5"
},
"dependencies": {
"@types/node-int64": "^0.4.29",
"@types/thrift": "^0.10.9",
"@types/thrift": "^0.10.12",
"node-int64": "^0.4.0",
"thrift": "^0.12.0"
"thrift": "^0.15.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "A test package.json",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.8.3"
"typescript": "4.9.5"
},
"dependencies": {
"@guardian/external": "file:../external",
"@guardian/external": "file:../external",
"@types/node-int64": "^0.4.29",
"@types/thrift": "^0.10.9",
"@types/thrift": "^0.10.12",
"node-int64": "^0.4.0",
"thrift": "^0.12.0"
"thrift": "^0.15.0"
}
}

0 comments on commit 83e8d19

Please sign in to comment.