Skip to content

Commit

Permalink
chore: add bump deno
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Mar 2, 2024
1 parent 84c19f0 commit d9d16c4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion deno/web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse, serialize } from 'npm:cookie-es'
import { parse, serialize } from 'npm:cookie-es@^1.0.0'
import {
getExistCookies,
getHeaderLanguagesWithGetter,
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"prepare": "git config --local core.hooksPath .githooks",
"changelog": "gh-changelogen --repo=intlify/utils",
"release": "bumpp --commit \"release: v%s\" --push --tag",
"version": "npx tsx scripts/bump-deno.ts",
"fix": "run-p lint format",
"lint": "deno lint",
"format": "deno fmt",
Expand Down Expand Up @@ -103,6 +104,7 @@
"devDependencies": {
"@cloudflare/workers-types": "^4.20231016.0",
"@types/node": "^20.11.24",
"@types/semver": "^7.5.8",
"@types/supertest": "^2.0.12",
"@vitest/coverage-v8": "^1.3.0",
"bumpp": "^9.2.0",
Expand All @@ -111,12 +113,14 @@
"gh-changelogen": "^0.2.8",
"h3": "^1.8.1",
"hono": "^3.8.1",
"jsonc-parser": "^3.2.1",
"lint-staged": "^15.0.0",
"npm-run-all2": "^6.0.0",
"miniflare": "^3.20231016.0",
"supertest": "^6.3.3",
"playwright": "^1.38.1",
"npm-run-all2": "^6.0.0",
"pkg-types": "^1.0.2",
"playwright": "^1.38.1",
"semver": "^7.6.0",
"supertest": "^6.3.3",
"typescript": "^5.4.1-rc",
"unbuild": "^2.0.0",
"vitest": "^1.3.0",
Expand Down
44 changes: 44 additions & 0 deletions scripts/bump-deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { applyEdits, modify, parse } from 'jsonc-parser'
import { promises as fs } from 'node:fs'
import { resolve } from 'node:path'
import semver from 'semver'
import { readPackageJSON } from 'pkg-types'

import type { ParseError } from 'jsonc-parser'

async function main() {
const npmPath = resolve(process.cwd(), 'package.json')
const npm = await readPackageJSON(npmPath)
if (npm.version == null) {
throw new Error('Failed to read package.json: version is not found')
}

const denoPath = resolve(process.cwd(), 'deno.jsonc')
const denoConfig = await fs.readFile(denoPath, 'utf-8').catch(() => '{}')
const errors: ParseError[] = []
const deno = parse(denoConfig, errors, { allowTrailingComma: true })
if (errors.length > 0) {
throw new Error(`Failed to parse deno.jsonc: ${errors.map((e) => e.error).join(', ')}`)
}
if (deno.version == null) {
throw new Error('Failed to read deno.jsonc: version is not found')
}

if (!semver.gt(npm.version, deno.version)) {
throw new Error(
`Failed to bump: npm version (${npm.version}) is not greater than deno version (${deno.version})`,
)
}

console.log(`Bump deno version to ${npm.version}`)
const denoConfigEdit = modify(denoConfig, ['version'], npm.version, {
formattingOptions: { tabSize: 2, insertSpaces: true },
})
const denoConfigModified = applyEdits(denoConfig, denoConfigEdit)
await fs.writeFile(denoPath, denoConfigModified)
}

main().catch((err) => {
console.error(err)
process.exit(1)
})

0 comments on commit d9d16c4

Please sign in to comment.