Skip to content

Commit

Permalink
Merge pull request #1369 from samchon/doc/playground-version-fixing
Browse files Browse the repository at this point in the history
Fix playground runtime version of dependencies
  • Loading branch information
samchon authored Nov 21, 2024
2 parents 4efeaba + 2284511 commit 954eaf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion website/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
22 changes: 21 additions & 1 deletion website/src/compilers/RollupBundler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RollupBuild, rollup } from "@rollup/browser";
import { VariadicSingleton } from "tstl";
import lock from "../../package-lock.json";

export namespace RollupBundler {
export const build = async (script: string): Promise<string> => {
Expand Down Expand Up @@ -33,7 +34,26 @@ export namespace RollupBundler {
}

const esm = new VariadicSingleton(async (url: string) => {
const response: Response = await fetch(url);
const response: Response = await fetch(reformUrl(url));
const text: string = await response.text();
return text;
});

const reformUrl = (url: string): string => {
const elements: string[] = url.split("https://esm.sh/")[1].split("/");
if (elements.length === 0) return url;
else if (elements[0].indexOf("@") > 0) return url;

const library: string = elements[0].startsWith("@")
? `${elements[0]}/${elements[1]}`
: elements[0];
const version: string | undefined =
lock.packages[`node_modules/${library}` as "node_modules/typia"]?.version;
if (version === undefined) return url;

const path: string = [
`${library}@${version}`,
...elements.slice(library.startsWith("@") ? 2 : 1).join("/"),
].join("/");
return `https://esm.sh/${path}`;
};

0 comments on commit 954eaf1

Please sign in to comment.