@vuebro/loader-sfc 2.3.13 → 2.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,9 @@
1
1
  import { compileStyleAsync, compileTemplate, compileScript, parse, } from "vue/compiler-sfc";
2
2
  import { consola } from "consola/browser";
3
3
  import { transform } from "sucrase";
4
+ import { ofetch } from "ofetch";
4
5
  import hash from "hash-sum";
5
- const fetchText = async (input, text = "") => {
6
- try {
7
- const response = await fetch(input);
8
- if (response.ok)
9
- return await response.text();
10
- else
11
- throw new Error(`Response status: ${response.status.toString()}`);
12
- }
13
- catch (error) {
14
- consola.error(error);
15
- return text;
16
- }
17
- }, inject = async (code) => {
6
+ const inject = async (code) => {
18
7
  const objectURL = URL.createObjectURL(new Blob([code], { type: "application/javascript" }));
19
8
  try {
20
9
  return (await import(objectURL));
@@ -22,10 +11,17 @@ const fetchText = async (input, text = "") => {
22
11
  finally {
23
12
  URL.revokeObjectURL(objectURL);
24
13
  }
14
+ }, fetching = async (input) => {
15
+ try {
16
+ return await ofetch(input);
17
+ }
18
+ catch (error) {
19
+ consola.error(error);
20
+ }
25
21
  };
26
22
  export default async (filename, { scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, parseOptions, styleOptions, } = {}) => {
27
23
  const id = `data-v-${hash(filename)}`;
28
- const { errors: parseErrors, descriptor } = parse(await fetchText(filename, "<template></template>"), { filename, ...parseOptions });
24
+ const { errors: parseErrors, descriptor } = parse((await fetching(filename)) ?? "<template></template>", { filename, ...parseOptions });
29
25
  const { scriptSetup, template, slotted, script, styles } = descriptor;
30
26
  const langs = new Set([script, scriptSetup]
31
27
  .filter((scriptBlock) => scriptBlock !== null)
@@ -44,7 +40,7 @@ export default async (filename, { scriptOptions: { templateOptions: { compilerOp
44
40
  }
45
41
  else {
46
42
  const { errors, code } = await compileStyleAsync({
47
- source: src ? await fetchText(src) : content,
43
+ source: src ? ((await fetching(src)) ?? "") : content,
48
44
  filename,
49
45
  modules,
50
46
  scoped,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuebro/loader-sfc",
3
- "version": "2.3.13",
3
+ "version": "2.3.15",
4
4
  "description": "Vue3 Single File Component (SFC) loader. Load .vue files directly from your browser without any build step.",
5
5
  "keywords": [
6
6
  "vue",
@@ -41,6 +41,6 @@
41
41
  "@rollup/plugin-terser": "^0.4.4",
42
42
  "@types/hash-sum": "^1.0.2",
43
43
  "@types/node": "^24.9.1",
44
- "@vuebro/configs": "^1.1.39"
44
+ "@vuebro/configs": "^1.1.42"
45
45
  }
46
46
  }