diff --git a/bun.lockb b/bun.lockb index 0b2c4c2..3ffcc49 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/deno/web.ts b/deno/web.ts index fda08f1..f74bea1 100644 --- a/deno/web.ts +++ b/deno/web.ts @@ -1,4 +1,4 @@ -import { parse, serialize } from 'npm:cookie-es' +import { parse, serialize } from 'npm:cookie-es@^1.0.0' import { getExistCookies, getHeaderLanguagesWithGetter, diff --git a/package.json b/package.json index 50549f3..42ebf1b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/scripts/bump-deno.ts b/scripts/bump-deno.ts new file mode 100644 index 0000000..8f04c25 --- /dev/null +++ b/scripts/bump-deno.ts @@ -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) +})