@vuebro/loader-sfc 2.3.10 → 2.3.12

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,14 +1,18 @@
1
+ import { compileStyleAsync, compileTemplate, compileScript, parse, } from "vue/compiler-sfc";
1
2
  import { consola } from "consola/browser";
2
- import hash from "hash-sum";
3
3
  import { transform } from "sucrase";
4
- import { compileScript, compileStyleAsync, compileTemplate, parse, } from "vue/compiler-sfc";
5
- const fetchText = async (url) => {
4
+ import hash from "hash-sum";
5
+ const fetchText = async (input, text = "") => {
6
6
  try {
7
- const response = await fetch(url);
8
- return response.ok ? response : new Response("");
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()}`);
9
12
  }
10
- catch {
11
- return new Response("");
13
+ catch (error) {
14
+ consola.error(error);
15
+ return text;
12
16
  }
13
17
  }, inject = async (code) => {
14
18
  const objectURL = URL.createObjectURL(new Blob([code], { type: "application/javascript" }));
@@ -19,32 +23,32 @@ const fetchText = async (url) => {
19
23
  URL.revokeObjectURL(objectURL);
20
24
  }
21
25
  };
22
- export default async (filename, { parseOptions, scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, styleOptions, } = {}) => {
26
+ export default async (filename, { scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, parseOptions, styleOptions, } = {}) => {
23
27
  const id = `data-v-${hash(filename)}`;
24
- const { descriptor, errors: parseErrors } = parse((await (await fetchText(filename)).text()) || "<template></template>", { filename, ...parseOptions });
25
- const { script, scriptSetup, slotted, styles, template } = descriptor;
28
+ const { errors: parseErrors, descriptor } = parse(await fetchText(filename, "<template></template>"), { filename, ...parseOptions });
29
+ const { scriptSetup, template, slotted, script, styles } = descriptor;
26
30
  const langs = new Set([script, scriptSetup]
27
31
  .filter((scriptBlock) => scriptBlock !== null)
28
32
  .flatMap(({ lang = "js" }) => [
29
33
  ...(/[jt]sx$/.test(lang) ? ["jsx"] : []),
30
34
  ...(/tsx?$/.test(lang) ? ["typescript"] : []),
31
- ])), { ast, content: source = "" } = template ?? {};
35
+ ])), { content: source = "", ast } = template ?? {};
32
36
  let styleWarning = "";
33
37
  const styleErrors = [];
34
38
  const style = !(document.getElementById(id) instanceof HTMLStyleElement)
35
- ? Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
39
+ ? Promise.all(styles.map(async ({ scoped = false, content, module, src }) => {
36
40
  const modules = !!module;
37
41
  if (modules && !styleWarning) {
38
42
  styleWarning = "<style module> is not supported in the playground.";
39
43
  return "";
40
44
  }
41
45
  else {
42
- const { code, errors } = await compileStyleAsync({
46
+ const { errors, code } = await compileStyleAsync({
47
+ source: src ? await fetchText(src) : content,
43
48
  filename,
44
- id,
45
49
  modules,
46
50
  scoped,
47
- source: src ? await (await fetchText(src)).text() : content,
51
+ id,
48
52
  ...styleOptions,
49
53
  });
50
54
  styleErrors.push(...errors);
@@ -56,34 +60,34 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
56
60
  expressionPlugins: [
57
61
  ...new Set([...(expressionPlugins ?? []), ...langs]),
58
62
  ],
59
- filename,
60
63
  scopeId: id,
64
+ filename,
61
65
  slotted,
62
66
  ...restCompilerOptions,
63
67
  }, templateOptions = {
68
+ scoped: styles.some(({ scoped }) => scoped),
64
69
  compilerOptions,
65
70
  filename,
66
- id,
67
- scoped: styles.some(({ scoped }) => scoped),
68
71
  slotted,
72
+ id,
69
73
  ...restTemplateOptions,
70
74
  }, scriptOptions = {
71
- id,
72
75
  templateOptions,
76
+ id,
73
77
  ...restScriptOptions,
74
78
  }, sucraseOptions = {
75
- jsxRuntime: "preserve",
76
79
  transforms: [...langs],
80
+ jsxRuntime: "preserve",
77
81
  };
78
- const { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
82
+ const { warnings: scriptWarnings, bindings, content, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
79
83
  if (bindings)
80
84
  compilerOptions.bindingMetadata = bindings;
81
- const { code, errors: templateErrors, tips: templateTips, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
85
+ const { errors: templateErrors, tips: templateTips, code, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
82
86
  ? compileTemplate({
83
87
  ...ast,
84
88
  filename,
85
- id,
86
89
  source,
90
+ id,
87
91
  ...templateOptions,
88
92
  })
89
93
  : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuebro/loader-sfc",
3
- "version": "2.3.10",
3
+ "version": "2.3.12",
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",
@@ -34,15 +34,13 @@
34
34
  },
35
35
  "prettier": "@vuebro/configs/prettierrc",
36
36
  "dependencies": {
37
- "consola": "^3.4.2",
38
37
  "hash-sum": "^2.0.0",
39
- "sucrase": "^3.35.0",
40
- "vue": "^3.5.22"
38
+ "sucrase": "^3.35.0"
41
39
  },
42
40
  "devDependencies": {
43
41
  "@rollup/plugin-terser": "^0.4.4",
44
42
  "@types/hash-sum": "^1.0.2",
45
43
  "@types/node": "^24.9.1",
46
- "@vuebro/configs": "^1.1.34"
44
+ "@vuebro/configs": "^1.1.38"
47
45
  }
48
46
  }