From 5d712f51fb58c891d312405346a19b3c75d0171e Mon Sep 17 00:00:00 2001 From: InkoHX Date: Sat, 9 Mar 2024 18:49:52 +0900 Subject: [PATCH] BREAKING: Move to JSR --- .vscode/settings.json | 3 +- basic-auth/fetcher.test.ts | 8 +-- basic-auth/fetcher.ts | 4 +- build.ts | 113 ------------------------------------- deno.json | 23 ++++---- deno.lock | 49 +++++++++++++++- deps.ts | 1 - deps_test.ts | 10 ---- oauth1/hmac.test.ts | 2 +- oauth1/hmac.ts | 4 +- oauth1/oauth1a.test.ts | 9 +-- oauth1/oauth1a.ts | 4 +- oauth2/fetcher.test.ts | 8 +-- utils/percent.test.ts | 2 +- utils/url.test.ts | 2 +- 15 files changed, 76 insertions(+), 166 deletions(-) delete mode 100644 build.ts delete mode 100644 deps.ts delete mode 100644 deps_test.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index cbac569..aa1c94e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "deno.enable": true + "deno.enable": true, + "deno.unstable": true } diff --git a/basic-auth/fetcher.test.ts b/basic-auth/fetcher.test.ts index db558e5..ed1849e 100644 --- a/basic-auth/fetcher.test.ts +++ b/basic-auth/fetcher.test.ts @@ -1,9 +1,5 @@ -import { - assertInstanceOf, - assertSpyCalls, - assertStrictEquals, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { assertSpyCalls, stub } from "@std/testing/mock"; import { fetcher as basicAuth } from "./fetcher.ts"; Deno.test('When calling fetch, the "Authorization" header must be set to the correct value.', async () => { diff --git a/basic-auth/fetcher.ts b/basic-auth/fetcher.ts index 45e6d84..fe85b86 100644 --- a/basic-auth/fetcher.ts +++ b/basic-auth/fetcher.ts @@ -1,4 +1,4 @@ -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; import { resolveURL } from "../utils/url.ts"; /** @@ -21,7 +21,7 @@ import { resolveURL } from "../utils/url.ts"; * @param password your password */ export const fetcher = (username: string, password: string) => { - const token = base64encode(`${username}:${password}`); + const token = encodeBase64(`${username}:${password}`); return (input: string | Request, init?: RequestInit) => { const url = resolveURL(input); diff --git a/build.ts b/build.ts deleted file mode 100644 index aa1d0d2..0000000 --- a/build.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { build, emptyDir } from "https://deno.land/x/dnt@0.33.0/mod.ts"; -import * as semver from "https://deno.land/std@0.175.0/semver/mod.ts"; - -const trimVersion = (str: string) => - /^refs\/tags\/v(.+)$/.exec(str)?.at(1)?.trim(); -const version = semver.valid(trimVersion(Deno.args[0]) ?? null); - -if (!version) { - console.error("Incorrect version"); - Deno.exit(1); -} - -await emptyDir("npm"); -await build({ - entryPoints: ["./mod.ts"], - outDir: "./npm", - typeCheck: false, - test: false, // NOTE: 一時的に無効 - compilerOptions: { - lib: ["dom", "esnext"], - target: "ES2020", - }, - package: { - name: "twitter-api-fetch", - version, - description: "fetch-like implementation designed for Twitter API", - author: "InkoHX ", - homepage: "https://github.com/nexterias/twitter-api-fetch#readme", - license: "MIT", - repository: { - type: "git", - url: "https://github.com/nexterias/twitter-api-fetch.git", - }, - bugs: { - url: "https://github.com/nexterias/twitter-api-fetch/issues", - }, - keywords: [ - "twitter-api", - "fetch", - ], - }, - shims: { - crypto: true, - deno: "dev", - custom: [{ - package: { - name: "cross-fetch", - version: "~3.1.5", - }, - globalNames: [ - { - name: "fetch", - exportName: "default", - }, - { - name: "Request", - }, - { - name: "Response", - }, - { - name: "Headers", - }, - ], - }], - }, -}); - -Deno.copyFileSync("./README.md", "./npm/README.md"); -Deno.copyFileSync("./LICENSE", "./npm/LICENSE"); - -// Bundling for Edge runtime. -{ - const process = Deno.run({ - cmd: ["deno", "bundle", "./mod.ts", "--", "./npm/edge.js"], - }); - const status = await process.status(); - - if (!status.success) { - console.error("Bundling failed."); - Deno.exit(status.code); - } - - await Deno.writeTextFile( - "./npm/edge.d.ts", - 'export * from "./types/mod.js";', - ); - - const metadata = JSON.parse( - await Deno.readTextFile("./npm/package.json"), - // deno-lint-ignore no-explicit-any - ) as Record; - - await Deno.writeTextFile( - "./npm/package.json", - JSON.stringify( - { - ...metadata, - exports: { - ...metadata.exports, - "./edge": { - import: { - types: "./edge.d.ts", - default: "./edge.js", - }, - }, - }, - }, - null, - 2, - ), - ); -} diff --git a/deno.json b/deno.json index 27e41f6..81ef957 100644 --- a/deno.json +++ b/deno.json @@ -1,20 +1,19 @@ { - "tasks": { - "build:node": "deno run -A ./build.ts" - }, + "name": "@nexterias/twitter-api-fetch", + "version": "3.0.0", + "exports": "./mod.ts", "lint": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] }, "fmt": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] }, "test": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] + }, + "imports": { + "@std/assert": "jsr:@std/assert@^0.219.1", + "@std/encoding": "jsr:@std/encoding@^0.219.1", + "@std/testing": "jsr:@std/testing@^0.219.1" } } diff --git a/deno.lock b/deno.lock index d0d5bd8..add232c 100644 --- a/deno.lock +++ b/deno.lock @@ -1,5 +1,43 @@ { - "version": "2", + "version": "3", + "packages": { + "specifiers": { + "jsr:@std/assert@^0.219.1": "jsr:@std/assert@0.219.1", + "jsr:@std/async@^0.219.1": "jsr:@std/async@0.219.1", + "jsr:@std/data-structures@^0.219.1": "jsr:@std/data-structures@0.219.1", + "jsr:@std/encoding@^0.219.1": "jsr:@std/encoding@0.219.1", + "jsr:@std/fmt@^0.219.1": "jsr:@std/fmt@0.219.1", + "jsr:@std/testing@^0.219.1": "jsr:@std/testing@0.219.1" + }, + "jsr": { + "@std/assert@0.219.1": { + "integrity": "e76c2a1799a78f0f4db7de04bdc9b908a7a4b821bb65eda0285885297d4fb8af", + "dependencies": [ + "jsr:@std/fmt@^0.219.1" + ] + }, + "@std/async@0.219.1": { + "integrity": "9401a6aa5a3292d639b71beceb19fb53c2148238c4d36b3ddf8c30980baa10e0" + }, + "@std/data-structures@0.219.1": { + "integrity": "f79ca4db7f126aed00529f1a63e975dc523f9b43939eec84e7a520b8425a8762" + }, + "@std/encoding@0.219.1": { + "integrity": "77b30e481a596cfb2a8f2f38c3165e6035a4f76a7259bf89b6a622ceaf57d575" + }, + "@std/fmt@0.219.1": { + "integrity": "2432152e927df249a207177aa048a6d9465956ea0047653ee6abd4f514db504f" + }, + "@std/testing@0.219.1": { + "integrity": "a87945273d41853cd5afbdd4d6cea123c6126d005a645c10f487ac35e31da75b", + "dependencies": [ + "jsr:@std/assert@^0.219.1", + "jsr:@std/async@^0.219.1", + "jsr:@std/data-structures@^0.219.1" + ] + } + } + }, "remote": { "https://deno.land/std@0.111.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", "https://deno.land/std@0.111.0/_util/os.ts": "dfb186cc4e968c770ab6cc3288bd65f4871be03b93beecae57d657232ecffcac", @@ -136,5 +174,12 @@ "https://deno.land/x/ts_morph@17.0.1/common/ts_morph_common.js": "49a79124b941ba2b35d81ac9eb90fc33c957b2640cdb97569c1941bac5a3bbdb", "https://deno.land/x/ts_morph@17.0.1/common/typescript.d.ts": "57e52a0882af4e835473dda27e4316cc31149866970210f9f79b940e916b7838", "https://deno.land/x/ts_morph@17.0.1/common/typescript.js": "5dd669eb199ee2a539924c63a92e23d95df43dfe2fbe3a9d68c871648be1ad5e" + }, + "workspace": { + "dependencies": [ + "jsr:@std/assert@^0.219.1", + "jsr:@std/encoding@^0.219.1", + "jsr:@std/testing@^0.219.1" + ] } -} \ No newline at end of file +} diff --git a/deps.ts b/deps.ts deleted file mode 100644 index d2a3fc4..0000000 --- a/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export { encode as base64encode } from "https://deno.land/std@0.175.0/encoding/base64.ts"; diff --git a/deps_test.ts b/deps_test.ts deleted file mode 100644 index 9403715..0000000 --- a/deps_test.ts +++ /dev/null @@ -1,10 +0,0 @@ -export { - assertInstanceOf, - assertStrictEquals, - assertThrows, -} from "https://deno.land/std@0.175.0/testing/asserts.ts"; -export { FakeTime } from "https://deno.land/std@0.175.0/testing/time.ts"; -export { - assertSpyCalls, - stub, -} from "https://deno.land/std@0.175.0/testing/mock.ts"; diff --git a/oauth1/hmac.test.ts b/oauth1/hmac.test.ts index c7c75be..7bf84da 100644 --- a/oauth1/hmac.test.ts +++ b/oauth1/hmac.test.ts @@ -1,5 +1,5 @@ import * as hmac from "./hmac.ts"; -import { assertStrictEquals } from "../deps_test.ts"; +import { assertStrictEquals } from "@std/assert"; import * as oauth1a from "./oauth1a.ts"; const credentials = { diff --git a/oauth1/hmac.ts b/oauth1/hmac.ts index 8a57fff..d7a47a8 100644 --- a/oauth1/hmac.ts +++ b/oauth1/hmac.ts @@ -5,7 +5,7 @@ import { OAuth1aSignedParameters, } from "./types.ts"; import * as percent from "../utils/percent.ts"; -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; /** * {@link https://developer.twitter.com/en/docs/authentication/oauth-1-0a/creating-a-signature Creating a signature | Docs | Twitter Developer Platform} - Getting a signing key @@ -73,7 +73,7 @@ export const sign = async ( textEncoder.encode(message), ); - clonedParams.set("oauth_signature", base64encode(hash)); + clonedParams.set("oauth_signature", encodeBase64(hash)); return clonedParams; }; diff --git a/oauth1/oauth1a.test.ts b/oauth1/oauth1a.test.ts index 7c9d547..013c407 100644 --- a/oauth1/oauth1a.test.ts +++ b/oauth1/oauth1a.test.ts @@ -1,9 +1,6 @@ -import { - assertInstanceOf, - assertStrictEquals, - FakeTime, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { stub } from "@std/testing/mock"; +import { FakeTime } from "@std/testing/time"; import { createBaseParams, createHttpHeader } from "./oauth1a.ts"; Deno.test("createBaseParams", () => { diff --git a/oauth1/oauth1a.ts b/oauth1/oauth1a.ts index 183c816..6c2307c 100644 --- a/oauth1/oauth1a.ts +++ b/oauth1/oauth1a.ts @@ -1,4 +1,4 @@ -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; import { OAuth1aBaseParameters, OAuth1aSignedParameters } from "./types.ts"; import * as percent from "../utils/percent.ts"; @@ -10,7 +10,7 @@ export const createBaseParams = ( return new Map([ ["oauth_consumer_key", consumerKey], - ["oauth_nonce", base64encode(randomBytes)], + ["oauth_nonce", encodeBase64(randomBytes)], ["oauth_timestamp", (Date.now() / 1000).toFixed(0)], ["oauth_token", accessToken], ["oauth_version", "1.0"], diff --git a/oauth2/fetcher.test.ts b/oauth2/fetcher.test.ts index c33208d..42c9c67 100644 --- a/oauth2/fetcher.test.ts +++ b/oauth2/fetcher.test.ts @@ -1,9 +1,5 @@ -import { - assertInstanceOf, - assertSpyCalls, - assertStrictEquals, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { assertSpyCalls, stub } from "@std/testing/mock"; import { fetcher as oauth2 } from "./fetcher.ts"; Deno.test('When calling fetch, the "Authorization" header must be set to the correct value.', async () => { diff --git a/utils/percent.test.ts b/utils/percent.test.ts index 91bad21..c5140f5 100644 --- a/utils/percent.test.ts +++ b/utils/percent.test.ts @@ -1,4 +1,4 @@ -import { assertStrictEquals } from "../deps_test.ts"; +import { assertStrictEquals } from "@std/assert"; import * as percent from "./percent.ts"; Deno.test("encode", () => { diff --git a/utils/url.test.ts b/utils/url.test.ts index bbb12db..2e6c861 100644 --- a/utils/url.test.ts +++ b/utils/url.test.ts @@ -2,7 +2,7 @@ import { assertInstanceOf, assertStrictEquals, assertThrows, -} from "../deps_test.ts"; +} from "@std/assert"; import { resolveURL } from "./url.ts"; Deno.test("Returns URL (string) when a Request object is passed", () => {