From 462d5a1e861b841e2f72d9cee31f7af28c452416 Mon Sep 17 00:00:00 2001 From: Wojciech Pawlik Date: Mon, 17 Jul 2023 23:45:56 +0200 Subject: [PATCH 1/4] build: add `bundling/build-cjs.ts` --- bundling/build-cjs.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ bundling/bundle-web.ts | 15 +++++---------- deno.jsonc | 10 ++++------ package.json | 8 ++------ tsconfig.json | 26 -------------------------- 5 files changed, 53 insertions(+), 48 deletions(-) create mode 100755 bundling/build-cjs.ts delete mode 100644 tsconfig.json diff --git a/bundling/build-cjs.ts b/bundling/build-cjs.ts new file mode 100755 index 00000000..dac8d7e0 --- /dev/null +++ b/bundling/build-cjs.ts @@ -0,0 +1,42 @@ +#!/usr/bin/env -S deno run --no-prompt --allow-read=. --allow-write=out/ +import { + Context, + deno2node, + emit, + ts, +} from "https://raw.githubusercontent.com/fromdeno/deno2node/70cddb305e3e65f51da4c34e7e8ebfc5f2085d38/src/mod.ts"; + +const compilerOptions: ts.CompilerOptions = { + "forceConsistentCasingInFileNames": true, + "newLine": ts.NewLineKind.LineFeed, + "noImplicitReturns": true, + "noUnusedParameters": true, + "rootDir": "src/", + "strict": true, + "declaration": true, + "module": ts.ModuleKind.CommonJS, + "outDir": "out/", + "skipLibCheck": true, + "target": ts.ScriptTarget.ES2019, +}; + +const ctx = new Context({ compilerOptions }); +ctx.config = { shim: "src/shim.node.ts" }; + +console.time("Loading source files"); +ctx.project.addSourceFilesAtPaths(Deno.args); +ctx.project.resolveSourceFileDependencies(); +console.timeEnd("Loading source files"); + +await deno2node(ctx); + +console.time("Emitting"); +const diagnostics = await emit(ctx.project); +console.timeEnd("Emitting"); + +if (diagnostics.length !== 0) { + console.info(ctx.project.formatDiagnosticsWithColorAndContext(diagnostics)); + console.info("TypeScript", ts.version); + console.info(`Found ${diagnostics.length} errors.`); + Deno.exit(1); +} diff --git a/bundling/bundle-web.ts b/bundling/bundle-web.ts index 01e64b37..d9139a87 100644 --- a/bundling/bundle-web.ts +++ b/bundling/bundle-web.ts @@ -7,14 +7,9 @@ const [release, source = `https://deno.land/x/grammy@${release}/mod.ts`] = if (!release) throw new Error("No release specified!"); // Rewrite imports from .deno.ts to .web.ts -const cache = createCache(); -const load = (specifier: string) => { - if (specifier.endsWith(".deno.ts")) { - const baseLength = specifier.length - ".deno.ts".length; - specifier = specifier.substring(0, baseLength) + ".web.ts"; - } - return cache.load(specifier); -}; +const cache = createCache({ root: "deno_cache/" }); +const load = (specifier: string) => + cache.load(specifier.replace(/\.deno\.ts$/, ".web.ts")); console.log(`Bundling version '${release}' from ${source} ...`); // Bundle code @@ -30,11 +25,11 @@ const { code: bundledCode } = await bundle(source, { console.log("Emitting ..."); // Strip the huge inline source map which is somehow generated anyway await Deno.writeTextFile( - "../out/web.mjs", + "out/web.mjs", bundledCode.replace(/\/\/# sourceMappingURL=.*\n/, ""), ); await Deno.writeTextFile( - "../out/web.d.ts", + "out/web.d.ts", 'export * from "./mod";\n', ); diff --git a/deno.jsonc b/deno.jsonc index d37f0745..e86b7545 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -2,13 +2,13 @@ "lock": false, "tasks": { "check": "deno cache --check=all src/mod.ts", - "backport": "deno run --no-prompt --allow-read=. --allow-write=. https://deno.land/x/deno2node@v1.8.1/src/cli.ts tsconfig.json", + "contribs": "npx --yes all-contributors-cli@6", + "backport": "deno run --no-prompt --allow-read=. --allow-write=out/ bundling/build-cjs.ts src/mod.ts", "test": "deno test --seed=123456 --parallel ./test/", "dev": "deno fmt && deno lint && deno task test && deno task check", "coverage": "rm -rf ./test/cov_profile && deno task test --coverage=./test/cov_profile && deno coverage --lcov --output=./coverage.lcov ./test/cov_profile", "report": "genhtml ./coverage.lcov --output-directory ./test/coverage/ && echo 'Point your browser to test/coverage/index.html to see the test coverage report.'", - "bundle": "cd bundling && ./bundle-all.sh", - "bundle-web": "mkdir -p out deno_cache && cd bundling && DENO_DIR=$PWD/../deno_cache deno run --unstable --quiet --allow-net --allow-read --allow-env=DENO_DIR,XDG_CACHE_HOME,HOME,DENO_AUTH_TOKENS --allow-write=../out,$PWD/../deno_cache bundle-web.ts dev ../src/mod.ts" + "bundle-web": "mkdir -p out deno_cache && deno run --quiet --allow-net --allow-read --allow-env=DENO_AUTH_TOKENS --allow-write=out/,deno_cache/ bundling/bundle-web.ts dev src/mod.ts" }, "fmt": { "indentWidth": 4, @@ -18,7 +18,6 @@ "./node_modules/", "./out/", "./package-lock.json", - "./bundling/bundles", "./test/cov_profile" ] }, @@ -27,8 +26,7 @@ "./deno_cache/", "./node_modules/", "./out/", - "./package-lock.json", - "./bundling/bundles" + "./package-lock.json" ] } } diff --git a/package.json b/package.json index ac661260..044a0c7b 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,7 @@ "url": "https://github.com/grammyjs/grammY" }, "scripts": { - "prepare": "npm run backport", - "backport": "deno2node tsconfig.json", - "contribs": "all-contributors" + "prepare": "deno task --quiet backport" }, "dependencies": { "@grammyjs/types": "3.1.2", @@ -26,9 +24,7 @@ "devDependencies": { "@types/debug": "^4.1.8", "@types/node": "^12.20.55", - "@types/node-fetch": "2.6.2", - "all-contributors-cli": "6.24.0", - "deno2node": "^1.8.1" + "@types/node-fetch": "2.6.2" }, "files": [ "out/" diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 1a4ac785..00000000 --- a/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "forceConsistentCasingInFileNames": true, - "newLine": "lf", - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "noUnusedParameters": true, - "rootDir": "./src/", - "strict": true, - "declaration": true, - "moduleResolution": "node", - "module": "commonjs", - "outDir": "./out/", - "skipLibCheck": true, - "target": "es2019" - }, - "include": [ - "src/" - ], - "exclude": [ - "src/*.web.ts" - ], - "deno2node": { - "shim": "./src/shim.node.ts" - } -} From 96585d71160290e772a832c0dc8eb6c7f79a5438 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Mon, 7 Aug 2023 10:33:15 +0200 Subject: [PATCH 2/4] refactor: avoid regex --- bundling/bundle-web.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bundling/bundle-web.ts b/bundling/bundle-web.ts index d9139a87..26df3844 100644 --- a/bundling/bundle-web.ts +++ b/bundling/bundle-web.ts @@ -8,8 +8,13 @@ if (!release) throw new Error("No release specified!"); // Rewrite imports from .deno.ts to .web.ts const cache = createCache({ root: "deno_cache/" }); -const load = (specifier: string) => - cache.load(specifier.replace(/\.deno\.ts$/, ".web.ts")); +const load = (specifier: string) => { + if (specifier.endsWith(".deno.ts")) { + const baseLength = specifier.length - ".deno.ts".length; + specifier = specifier.substring(0, baseLength) + ".web.ts"; + } + return cache.load(specifier); +}; console.log(`Bundling version '${release}' from ${source} ...`); // Bundle code From 4b1b585f2c4bab12d0ee24f86553f3b7755978db Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Mon, 7 Aug 2023 10:43:23 +0200 Subject: [PATCH 3/4] chore: fix ci --- .github/workflows/deno.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index 70e1d9e9..f1917332 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -25,7 +25,7 @@ jobs: run: npm install --ignore-scripts - name: Run backporting - run: npm run backport + run: deno task backport format-and-lint: runs-on: ubuntu-latest From 8beaebc4461f495a95c32976a19310361dda62f8 Mon Sep 17 00:00:00 2001 From: Wojciech Pawlik Date: Mon, 20 Nov 2023 14:24:28 +0100 Subject: [PATCH 4/4] chore: update ci --- .github/workflows/deno.yml | 22 +++++++++------------- bundling/build-cjs.ts | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index f1917332..90412d89 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -19,7 +19,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v1 - name: Install dependencies run: npm install --ignore-scripts @@ -31,11 +33,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: denoland/setup-deno@main - with: - deno-version: v1.x + - uses: denoland/setup-deno@v1 - name: Check Format run: deno fmt --check @@ -52,11 +52,9 @@ jobs: steps: - name: Setup repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: denoland/setup-deno@main - with: - deno-version: v1.x + - uses: denoland/setup-deno@v1 - name: Cache Dependencies run: deno cache src/mod.ts @@ -68,13 +66,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: denoland/setup-deno@main - with: - deno-version: v1.x + - uses: denoland/setup-deno@v1 - name: Create coverage files run: deno task coverage diff --git a/bundling/build-cjs.ts b/bundling/build-cjs.ts index dac8d7e0..dc9a4ed3 100755 --- a/bundling/build-cjs.ts +++ b/bundling/build-cjs.ts @@ -4,7 +4,7 @@ import { deno2node, emit, ts, -} from "https://raw.githubusercontent.com/fromdeno/deno2node/70cddb305e3e65f51da4c34e7e8ebfc5f2085d38/src/mod.ts"; +} from "https://deno.land/x/deno2node@v1.10.1/src/mod.ts"; const compilerOptions: ts.CompilerOptions = { "forceConsistentCasingInFileNames": true,