Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web bundle concept #82

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ test/cov_profile
coverage.lcov

# Build output
deno_cache/
out/
44 changes: 44 additions & 0 deletions bundling/bundle-web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {bundle} from "https://deno.land/x/[email protected]/mod.ts";
import {createCache} from "https://deno.land/x/[email protected]/mod.ts";

// Parse args
const [release, source = `https://deno.land/x/grammy@${release}/mod.ts`] = Deno.args;
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";
console.log(specifier);
}
return cache.load(specifier);
};

console.log(`Bundling version '${release}' from ${source} ...`);
// Bundle code
const {code: bundledCode} = await bundle(
"../src/mod.ts",
{
load,
compilerOptions: {
sourceMap: false,
inlineSources: false,
inlineSourceMap: false,
}
}
);

console.log("Emitting ...");
// Strip the huge inline source map which is somehow generated anyway
await Deno.writeTextFile(
"../out/web.mjs",
bundledCode.replace(/\/\/# sourceMappingURL=.*\n/, ""),
);
await Deno.writeTextFile(
"../out/web.d.ts",
'export * from "./mod";\n',
);

console.log("Done.");
5 changes: 4 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"dev": "deno fmt && deno lint && deno task test && deno task check",
"clean": "git clean -fX out test/cov_profile test/coverage coverage.lcov",
"coverage": "deno task clean && 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.'"
"report": "genhtml ./coverage.lcov --output-directory ./test/coverage/ && echo 'Point your browser to test/coverage/index.html to see the test coverage report.'",
"bundle-web": "mkdir -p out deno_cache && cd bundling && deno run --unstable --quiet --allow-net --allow-read=.. --allow-write=../out,../deno_cache https://raw.githubusercontent.com/grammyjs/grammY/v1.17.2/bundling/bundle-web.ts dev ../src/mod.ts",
},
"fmt": {
"indentWidth": 4,
"proseWrap": "preserve",
"exclude": [
"./deno_cache/",
"./node_modules/",
"./out/",
"./package-lock.json",
Expand All @@ -21,6 +23,7 @@
},
"lint": {
"exclude": [
"./deno_cache/",
"./node_modules/",
"./out/",
"./package-lock.json"
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
],
"main": "./out/mod.js",
"types": "./out/mod.d.ts",
"exports": {
".": {
"types": "./out/mod.d.ts",
"node": "./out/mod.js",
"browser": "./out/web.mjs",
"default": "./out/web.mjs"
},
"./web": {
"types": "./out/web.d.ts",
"default": "./out/web.mjs"
}
},
"keywords": [
"telegram",
"bot",
Expand Down
7 changes: 7 additions & 0 deletions src/deps.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
delistify,
GLOBAL_CONSTRUCTOR_MAP,
listify,
} from "https://deno.land/x/[email protected]/mod.ts";
export * from "https://lib.deno.dev/x/grammy@v1/mod.ts";
export * from "https://lib.deno.dev/x/grammy@v1/types.ts";
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
"skipLibCheck": true,
"target": "es2019"
},
"include": ["src/"]
"include": [
"src/"
],
"exclude": [
"src/*.web.ts"
]
}