Skip to content

Commit

Permalink
break: use '/x' script for loading unocss (esm-dev#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije authored Dec 31, 2024
1 parent d172f29 commit a5b6232
Show file tree
Hide file tree
Showing 23 changed files with 405 additions and 527 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/demo/preact/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/svelte/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</script>
</head>
<body>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/with-markdown/preact/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/with-markdown/react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/with-markdown/svelte/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/with-markdown/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</script>
</head>
<body>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion cli/cmd/demo/with-markdown/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions cli/cmd/demo/with-unocss/preact/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
}
}
</script>
<script src="https://esm.sh/uno"></script>
<script src="https://esm.sh/x" href="./uno.css"></script>
</head>
<body>
<div id="root">
<p class="center-box font-sans text-gray-400">Loading...</p>
</div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions cli/cmd/demo/with-unocss/react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
}
}
</script>
<script src="https://esm.sh/uno"></script>
<script src="https://esm.sh/x" href="./uno.css"></script>
</head>
<body>
<div id="root">
<p class="center-box font-sans text-gray-400">Loading...</p>
</div>
<script type="module" src="https://esm.sh/x" main="./app/main.tsx"></script>
<script src="https://esm.sh/x" href="./app/main.tsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions cli/cmd/demo/with-unocss/svelte/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
}
}
</script>
<script src="https://esm.sh/uno"></script>
<script src="https://esm.sh/x" href="./uno.css"></script>
</head>
<body>
<div id="root">
<p class="center-box font-sans text-gray-400">Loading...</p>
</div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions cli/cmd/demo/with-unocss/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"imports": {}
}
</script>
<script src="https://esm.sh/uno"></script>
<script src="https://esm.sh/x" href="./uno.css"></script>
</head>
<body>
<div class="center-box relative">
Expand All @@ -25,6 +25,6 @@ <h1 class="font-sans text-5xl fw500 text-primary select-none">esm.sh</h1>
<a class="logo i-tabler-brand-github" href="https://github.com/esm-dev/esm.sh" target="_blank" title="Github"></a>
</div>
</div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions cli/cmd/demo/with-unocss/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
}
}
</script>
<script src="https://esm.sh/uno"></script>
<script src="https://esm.sh/x" href="./uno.css"></script>
</head>
<body>
<div id="root">
<p class="center-box font-sans text-gray-400">Loading...</p>
</div>
<script type="module" src="https://esm.sh/x" main="./app/main.ts"></script>
<script src="https://esm.sh/x" href="./app/main.ts"></script>
</body>
</html>
18 changes: 3 additions & 15 deletions cli/cmd/internal/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const regexpVuePath = /^\/\*?vue@([~\^]?[\w\+\-\.]+)(\/|\?|&|$)/;
const regexpSveltePath = /^\/\*?svelte@([~\^]?[\w\+\-\.]+)(\/|\?|&|$)/;
const output = (type, data) => Deno.stdout.write(enc.encode(">>>" + type + ":" + JSON.stringify(data) + "\n"));

let tsx
let tsx;
let unoGenerators;

async function transformModule(filename, importMap, sourceCode) {
Expand Down Expand Up @@ -118,30 +118,18 @@ function isHttpSpecifier(specifier) {
}

async function unocss(config, content, id) {
const generatorId = config?.filename ?? ".";
if (!unoGenerators) {
unoGenerators = new Map();
}
const generatorId = config?.filename ?? ".";
let uno = unoGenerators.get(generatorId);
if (!uno || uno.configCSS !== config?.css) {
uno = import("npm:@esm.sh/[email protected]").then(({ init }) => init({ configCSS: config?.css }));
uno.configCSS = config?.css;
unoGenerators.set(generatorId, uno);
}
const { update, generate } = await uno;
if (id) {
if (!(await update(content, id))) {
return "";
}
} else {
if (typeof content === "object" && content !== null) {
for (const [id, code] of Array.isArray(content) ? content : Object.entries(content)) {
await update(code, id);
}
} else if (typeof content === "string") {
await update(content);
}
}
await update(content, id);
return await generate();
}

Expand Down
Loading

0 comments on commit a5b6232

Please sign in to comment.