diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index 70e1d9e9..90412d89 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -19,23 +19,23 @@ 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 - name: Run backporting - run: npm run backport + run: deno task backport format-and-lint: 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 new file mode 100755 index 00000000..dc9a4ed3 --- /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://deno.land/x/deno2node@v1.10.1/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 63bce7a7..ced92da0 100644 --- a/bundling/bundle-web.ts +++ b/bundling/bundle-web.ts @@ -7,7 +7,7 @@ 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 cache = createCache({ root: "deno_cache/" }); const load = (specifier: string) => { if (specifier.endsWith(".deno.ts")) { const baseLength = specifier.length - ".deno.ts".length; @@ -30,11 +30,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 df75d165..b362b0df 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -2,14 +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.9.0/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", - "contribs": "deno run --allow-env --allow-read --allow-write=. --allow-net=api.github.com npm:all-contributors-cli" + "bundle-web": "mkdir -p out deno_cache && deno run --quiet --allow-net --allow-read --allow-env=DENO_DIR,XDG_CACHE_HOME,HOME,DENO_AUTH_TOKENS--allow-write=out/,deno_cache/ bundling/bundle-web.ts dev src/mod.ts" }, "fmt": { "indentWidth": 4, @@ -19,7 +18,6 @@ "./node_modules/", "./out/", "./package-lock.json", - "./bundling/bundles", "./test/cov_profile" ] }, @@ -28,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 fb29db46..86a124f9 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "url": "https://github.com/grammyjs/grammY" }, "scripts": { - "prepare": "npm run backport", - "backport": "deno2node tsconfig.json" + "prepare": "deno task --quiet backport" }, "dependencies": { "@grammyjs/types": "3.3.0", @@ -25,8 +24,7 @@ "devDependencies": { "@types/debug": "^4.1.9", "@types/node": "^12.20.55", - "@types/node-fetch": "2.6.2", - "deno2node": "^1.9.0" + "@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" - } -}