valaxy 1.1.0 → 1.2.1
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.
- package/client/components/ValaxyCopyright.vue +2 -1
- package/client/composables/collections.ts +13 -9
- package/client/composables/decrypt.ts +8 -1
- package/client/composables/outline/anchor.ts +20 -8
- package/client/index.d.ts +0 -1
- package/client/layouts/README.md +1 -1
- package/client/main.ts +35 -20
- package/client/modules/valaxy.ts +14 -5
- package/client/shims.d.ts +20 -0
- package/client/utils/layouts.ts +359 -0
- package/client/utils/path.ts +30 -0
- package/dist/node/cli/index.mjs +4 -11
- package/dist/node/index.d.mts +68 -45
- package/dist/node/index.mjs +4 -11
- package/dist/shared/{valaxy.BU27Owzs.mjs → valaxy.DvkRJomf.mjs} +627 -1886
- package/dist/shared/{valaxy.I4MpBkZO.d.mts → valaxy.EzGcrVef.d.mts} +90 -1
- package/dist/types/index.d.mts +2 -2
- package/package.json +11 -18
- package/types/config.ts +83 -0
- package/types/vue-router.d.ts +8 -0
- package/vendor/README.md +8 -8
- package/vendor/sources.json +0 -31
- package/vendor/i18n/LICENSE +0 -20
- package/vendor/i18n/index.d.mts +0 -7
- package/vendor/i18n/index.mjs +0 -1389
- package/vendor/i18n/types.d.ts +0 -48
- package/vendor/layouts/LICENSE +0 -21
- package/vendor/layouts/client.d.ts +0 -11
- package/vendor/layouts/index.d.mts +0 -86
- package/vendor/layouts/index.mjs +0 -235
- package/vendor/layouts/layoutName-DVkP7Qpo.mjs +0 -82
- package/vendor/layouts/runtime.d.mts +0 -72
- package/vendor/layouts/runtime.mjs +0 -284
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path, { resolve, basename, dirname, relative as relative$1, join, isAbsolute as isAbsolute$1, parse
|
|
2
|
-
import process
|
|
1
|
+
import path, { resolve, basename, dirname, relative as relative$1, join, isAbsolute as isAbsolute$1, parse } from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
5
5
|
import os from 'node:os';
|
|
@@ -10,20 +10,22 @@ import matter from 'gray-matter';
|
|
|
10
10
|
import { glob, globSync } from 'tinyglobby';
|
|
11
11
|
import * as yaml from 'js-yaml';
|
|
12
12
|
import { dump, load, CORE_SCHEMA } from 'js-yaml';
|
|
13
|
-
import { isFunction, ensurePrefix, slash as slash$
|
|
14
|
-
import
|
|
15
|
-
import path$1, { resolve as resolve$1, relative, isAbsolute, normalize, join as join$1, basename as basename$1,
|
|
13
|
+
import { isFunction, ensurePrefix, slash as slash$1, uniq, ensureSuffix, isObject } from '@antfu/utils';
|
|
14
|
+
import _debug from 'debug';
|
|
15
|
+
import path$1, { resolve as resolve$1, relative, isAbsolute, normalize, join as join$1, basename as basename$1, dirname as dirname$1 } from 'pathe';
|
|
16
16
|
import defu, { createDefu } from 'defu';
|
|
17
17
|
import { mergeConfig, loadConfigFromFile as loadConfigFromFile$1, searchForWorkspaceRoot, build as build$3, createServer as createServer$1 } from 'vite';
|
|
18
18
|
import { webcrypto, createHash } from 'node:crypto';
|
|
19
19
|
import { options } from 'floating-vue';
|
|
20
20
|
import { loadConfig } from 'define-config-ts';
|
|
21
21
|
import ora from 'ora';
|
|
22
|
+
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
22
23
|
import spawn$1, { spawn } from 'cross-spawn';
|
|
23
24
|
import { resolvePath } from 'mlly';
|
|
24
25
|
import { resolveGlobal } from 'resolve-global';
|
|
25
26
|
import { normalizeRepositoryUrl } from '@valaxyjs/utils';
|
|
26
|
-
import { existsSync, readFileSync,
|
|
27
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
28
|
+
import picomatch from 'picomatch';
|
|
27
29
|
import { readFile, mkdir, writeFile, realpath, rm, stat } from 'node:fs/promises';
|
|
28
30
|
import dayjs from 'dayjs';
|
|
29
31
|
import { Feed } from 'feed';
|
|
@@ -33,23 +35,14 @@ import { createHooks } from 'hookable';
|
|
|
33
35
|
import { Unhead } from '@unhead/bundler/vite';
|
|
34
36
|
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
|
|
35
37
|
import { isPackageExists } from 'local-pkg';
|
|
36
|
-
import picomatch from 'picomatch';
|
|
37
38
|
import chokidar from 'chokidar';
|
|
38
39
|
import { createUnplugin } from 'unplugin';
|
|
39
40
|
import { createFilter } from 'unplugin-utils';
|
|
40
|
-
import { createDebug
|
|
41
|
+
import { createDebug } from 'obug';
|
|
41
42
|
import MagicString from 'magic-string';
|
|
42
|
-
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
43
43
|
import pMap from 'p-map';
|
|
44
44
|
import pascalCase$1 from 'pascalcase';
|
|
45
|
-
import
|
|
46
|
-
import { generateJSON, generateYAML, generateJavaScript, generateTypescript } from '@intlify/bundle-utils';
|
|
47
|
-
import { createFilter as createFilter$1 } from '@rollup/pluginutils';
|
|
48
|
-
import { parse as parse$2, babelParse } from 'vue/compiler-sfc';
|
|
49
|
-
import pc from 'picocolors';
|
|
50
|
-
import eslintUitls from '@eslint-community/eslint-utils';
|
|
51
|
-
import { transformVTDirective } from '@intlify/vue-i18n-extensions';
|
|
52
|
-
import { analyze } from '@typescript-eslint/scope-manager';
|
|
45
|
+
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
|
|
53
46
|
import MiniSearch from 'minisearch';
|
|
54
47
|
import { transformerNotationDiff, transformerNotationFocus, transformerNotationHighlight, transformerNotationErrorLevel, transformerCompactLineOptions } from '@shikijs/transformers';
|
|
55
48
|
import { LRUCache } from 'lru-cache';
|
|
@@ -72,7 +65,7 @@ import { convert } from 'html-to-text';
|
|
|
72
65
|
import VueRouter from 'vue-router/vite';
|
|
73
66
|
import generateSitemap from 'vite-ssg-sitemap';
|
|
74
67
|
import { renderSSRHead } from '@unhead/vue/server';
|
|
75
|
-
import { createRoutesContext, resolveOptions as resolveOptions$
|
|
68
|
+
import { createRoutesContext, resolveOptions as resolveOptions$2 } from 'vue-router/unplugin';
|
|
76
69
|
import { execSync, exec } from 'node:child_process';
|
|
77
70
|
import { intro, confirm, isCancel, cancel, select, outro } from '@clack/prompts';
|
|
78
71
|
import net from 'node:net';
|
|
@@ -80,7 +73,7 @@ import * as readline from 'node:readline';
|
|
|
80
73
|
import qrcode from 'qrcode';
|
|
81
74
|
import ejs from 'ejs';
|
|
82
75
|
|
|
83
|
-
const version = "1.1
|
|
76
|
+
const version = "1.2.1";
|
|
84
77
|
|
|
85
78
|
const GLOBAL_STATE = {
|
|
86
79
|
valaxyApp: void 0,
|
|
@@ -294,7 +287,7 @@ const replaceArrMerge = createDefu((obj, key, value) => {
|
|
|
294
287
|
async function loadConfigFromFile(name, options = {}) {
|
|
295
288
|
const { config, configFile } = await loadConfig({
|
|
296
289
|
name,
|
|
297
|
-
cwd: options.cwd || process
|
|
290
|
+
cwd: options.cwd || process.cwd(),
|
|
298
291
|
throwOnNotFound: false
|
|
299
292
|
});
|
|
300
293
|
let userConfig = config;
|
|
@@ -544,7 +537,7 @@ const mergeValaxyConfig = createDefu((obj, key, value) => {
|
|
|
544
537
|
}
|
|
545
538
|
});
|
|
546
539
|
async function resolveValaxyConfig(options) {
|
|
547
|
-
const configRoot = options.userRoot || process
|
|
540
|
+
const configRoot = options.userRoot || process.cwd();
|
|
548
541
|
const endCount = countPerformanceTime();
|
|
549
542
|
const { config: userValaxyConfig, configFile } = await resolveValaxyConfigFromRoot(configRoot);
|
|
550
543
|
const duration = endCount();
|
|
@@ -655,13 +648,6 @@ function getCryptoDeriveKey(keyMaterial, salt) {
|
|
|
655
648
|
["encrypt", "decrypt"]
|
|
656
649
|
);
|
|
657
650
|
}
|
|
658
|
-
function bytesToBinaryString(bytes) {
|
|
659
|
-
const CHUNK_SIZE = 32768;
|
|
660
|
-
const chunks = [];
|
|
661
|
-
for (let i = 0; i < bytes.length; i += CHUNK_SIZE)
|
|
662
|
-
chunks.push(String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK_SIZE)));
|
|
663
|
-
return chunks.join("");
|
|
664
|
-
}
|
|
665
651
|
async function encryptContent(content, options) {
|
|
666
652
|
const { password, iv, salt } = options;
|
|
667
653
|
const keyMaterial = await getKeyMaterial(password);
|
|
@@ -675,7 +661,7 @@ async function encryptContent(content, options) {
|
|
|
675
661
|
key,
|
|
676
662
|
enc.encode(content)
|
|
677
663
|
);
|
|
678
|
-
return
|
|
664
|
+
return Buffer$1.from(ciphertextData).toString("base64");
|
|
679
665
|
}
|
|
680
666
|
|
|
681
667
|
function getGitTimestamp(file, type = "updated") {
|
|
@@ -719,7 +705,7 @@ async function resolveImportUrl(id) {
|
|
|
719
705
|
return toAtFS(await resolveImportPath(id, true));
|
|
720
706
|
}
|
|
721
707
|
function toAtFS(path) {
|
|
722
|
-
return `/@fs${ensurePrefix("/", slash$
|
|
708
|
+
return `/@fs${ensurePrefix("/", slash$1(path))}`;
|
|
723
709
|
}
|
|
724
710
|
async function resolveImportPath(importName, ensure = false) {
|
|
725
711
|
try {
|
|
@@ -756,7 +742,7 @@ async function getModuleRoot(name, entry) {
|
|
|
756
742
|
}
|
|
757
743
|
}
|
|
758
744
|
|
|
759
|
-
async function parseAddons(addons, userRoot = process
|
|
745
|
+
async function parseAddons(addons, userRoot = process.cwd()) {
|
|
760
746
|
const spinner = ora(`Resolve ${colors.cyan("addons")} from ${colors.dim(userRoot)}`).start();
|
|
761
747
|
const resolvers = {};
|
|
762
748
|
const mergeResolver = (resolver) => {
|
|
@@ -794,7 +780,7 @@ async function parseAddons(addons, userRoot = process$1.cwd()) {
|
|
|
794
780
|
return resolvedAddons;
|
|
795
781
|
}
|
|
796
782
|
async function readAddonModule(name, options = {}) {
|
|
797
|
-
const root = await getAddonRoot(name, options.cwd || process
|
|
783
|
+
const root = await getAddonRoot(name, options.cwd || process.cwd());
|
|
798
784
|
const packageJSONPath = resolve$1(root, "./package.json");
|
|
799
785
|
if (!await fs.exists(packageJSONPath)) {
|
|
800
786
|
logger.error(`No addon named ${name} found`);
|
|
@@ -867,7 +853,7 @@ async function getThemeRoot(name, entry) {
|
|
|
867
853
|
return await getModuleRoot(themeModule, entry);
|
|
868
854
|
}
|
|
869
855
|
|
|
870
|
-
const debug$
|
|
856
|
+
const debug$6 = _debug("valaxy:options");
|
|
871
857
|
async function processSiteConfig(options) {
|
|
872
858
|
const { config, themeRoot, theme } = options;
|
|
873
859
|
const siteConfig = config.siteConfig;
|
|
@@ -940,10 +926,10 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
940
926
|
consola.debug(` \u2514\u2500 processSiteConfig: ${siteConfigTimer()}`);
|
|
941
927
|
return valaxyOptions;
|
|
942
928
|
}
|
|
943
|
-
async function resolveOptions$
|
|
929
|
+
async function resolveOptions$1(options = { userRoot: process.cwd() }, mode = "dev") {
|
|
944
930
|
const pkgRoot = dirname(await resolveImportPath("valaxy/package.json", true));
|
|
945
931
|
const clientRoot = resolve$1(pkgRoot, "client");
|
|
946
|
-
const userRoot = resolve$1(options.userRoot || process
|
|
932
|
+
const userRoot = resolve$1(options.userRoot || process.cwd());
|
|
947
933
|
consola.start(`Resolve ${colors.magenta("valaxy")} config ...`);
|
|
948
934
|
const configTimer = countPerformanceTime();
|
|
949
935
|
const [resolvedValaxy, resolvedSite, resolvedTheme, pages] = await Promise.all([
|
|
@@ -999,7 +985,7 @@ async function resolveOptions$3(options = { userRoot: process$1.cwd() }, mode =
|
|
|
999
985
|
links: []
|
|
1000
986
|
}
|
|
1001
987
|
};
|
|
1002
|
-
debug$
|
|
988
|
+
debug$6(valaxyOptions);
|
|
1003
989
|
const themeValaxyConfig = await resolveThemeValaxyConfig(valaxyOptions);
|
|
1004
990
|
const valaxyConfig = mergeValaxyConfig(userValaxyConfig, themeValaxyConfig);
|
|
1005
991
|
const processTimer = countPerformanceTime();
|
|
@@ -1067,10 +1053,10 @@ const matterOptions = {
|
|
|
1067
1053
|
};
|
|
1068
1054
|
|
|
1069
1055
|
function isProd() {
|
|
1070
|
-
return process
|
|
1056
|
+
return process.env.NODE_ENV === "production";
|
|
1071
1057
|
}
|
|
1072
1058
|
function setEnv(env = "development") {
|
|
1073
|
-
process
|
|
1059
|
+
process.env.NODE_ENV = env;
|
|
1074
1060
|
consola.level = isProd() ? 2 : 3;
|
|
1075
1061
|
logger.level = consola.level;
|
|
1076
1062
|
}
|
|
@@ -1078,7 +1064,7 @@ function setEnvProd() {
|
|
|
1078
1064
|
return setEnv("production");
|
|
1079
1065
|
}
|
|
1080
1066
|
function setTimezone(timezone) {
|
|
1081
|
-
process
|
|
1067
|
+
process.env.TZ = timezone;
|
|
1082
1068
|
}
|
|
1083
1069
|
async function isPagesDirExist(root) {
|
|
1084
1070
|
const exist = await fs.exists(path.resolve(root, "pages"));
|
|
@@ -1214,7 +1200,7 @@ function registerFuseCommand(cli) {
|
|
|
1214
1200
|
(args) => commonOptions(args).strict().help(),
|
|
1215
1201
|
async ({ root }) => {
|
|
1216
1202
|
setEnvProd();
|
|
1217
|
-
const options = await resolveOptions$
|
|
1203
|
+
const options = await resolveOptions$1({ userRoot: root }, "build");
|
|
1218
1204
|
await execFuse(options);
|
|
1219
1205
|
}
|
|
1220
1206
|
);
|
|
@@ -1265,17 +1251,13 @@ function resolveText(value, lang) {
|
|
|
1265
1251
|
return nodeT(value, lang);
|
|
1266
1252
|
return tObject(value, lang);
|
|
1267
1253
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1254
|
+
const PAGES_SECTION = "Pages";
|
|
1255
|
+
async function loadLlmsPosts(options) {
|
|
1270
1256
|
const { config } = options;
|
|
1271
1257
|
const siteConfig = config.siteConfig;
|
|
1272
1258
|
const llmsConfig = siteConfig.llms;
|
|
1273
1259
|
const lang = siteConfig.lang || "en";
|
|
1274
1260
|
loadLocalesYml(path.resolve(options.userRoot, "locales"));
|
|
1275
|
-
const siteUrl = getSiteUrl(options);
|
|
1276
|
-
if (!siteUrl) {
|
|
1277
|
-
consola.warn("`url` is not set in site.config.ts. llms.txt will use relative paths.");
|
|
1278
|
-
}
|
|
1279
1261
|
const include = llmsConfig.include || ["posts/**/*.md"];
|
|
1280
1262
|
const files = await scanPageFiles(options.userRoot, include);
|
|
1281
1263
|
const rawPosts = await readPostFiles(files);
|
|
@@ -1285,10 +1267,26 @@ async function build$2(options) {
|
|
|
1285
1267
|
description: resolveText(data.description, lang) || "",
|
|
1286
1268
|
date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
|
|
1287
1269
|
urlPath: filePathToUrlPath(filePath, options.userRoot),
|
|
1270
|
+
sourcePath: getPagePath(filePath, options.userRoot),
|
|
1288
1271
|
content,
|
|
1289
1272
|
rawFrontmatter: stripSensitiveFrontmatter(data)
|
|
1290
1273
|
}));
|
|
1291
1274
|
posts.sort((a, b) => +b.date - +a.date);
|
|
1275
|
+
return posts;
|
|
1276
|
+
}
|
|
1277
|
+
async function build$2(options) {
|
|
1278
|
+
consola.start("Generating llms.txt ...");
|
|
1279
|
+
const { config } = options;
|
|
1280
|
+
const siteConfig = config.siteConfig;
|
|
1281
|
+
const llmsConfig = siteConfig.llms;
|
|
1282
|
+
const lang = siteConfig.lang || "en";
|
|
1283
|
+
const siteUrl = getSiteUrl(options);
|
|
1284
|
+
if (!siteUrl) {
|
|
1285
|
+
consola.warn("`url` is not set in site.config.ts. llms.txt will use relative paths.");
|
|
1286
|
+
}
|
|
1287
|
+
const posts = await loadLlmsPosts(options);
|
|
1288
|
+
const selection = llmsSelection(llmsConfig);
|
|
1289
|
+
warnUnmatchedCollapse(posts, selection);
|
|
1292
1290
|
const distPath = path.resolve(options.userRoot, "dist");
|
|
1293
1291
|
await fs.ensureDir(distPath);
|
|
1294
1292
|
const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
|
|
@@ -1298,7 +1296,10 @@ async function build$2(options) {
|
|
|
1298
1296
|
description,
|
|
1299
1297
|
prompt: llmsConfig.prompt,
|
|
1300
1298
|
posts,
|
|
1301
|
-
siteUrl
|
|
1299
|
+
siteUrl,
|
|
1300
|
+
...selection,
|
|
1301
|
+
sectionOrder: llmsConfig.sectionOrder,
|
|
1302
|
+
featured: llmsConfig.featured
|
|
1302
1303
|
});
|
|
1303
1304
|
await fs.writeFile(path.resolve(distPath, "llms.txt"), llmsTxt, "utf-8");
|
|
1304
1305
|
consola.debug(`[llms] Generated ${colors.dim("dist/llms.txt")}`);
|
|
@@ -1307,7 +1308,9 @@ async function build$2(options) {
|
|
|
1307
1308
|
title,
|
|
1308
1309
|
description,
|
|
1309
1310
|
prompt: llmsConfig.prompt,
|
|
1310
|
-
posts
|
|
1311
|
+
posts,
|
|
1312
|
+
exclude: selection.exclude,
|
|
1313
|
+
collapse: selection.collapse
|
|
1311
1314
|
});
|
|
1312
1315
|
await fs.writeFile(path.resolve(distPath, "llms-full.txt"), llmsFullTxt, "utf-8");
|
|
1313
1316
|
consola.debug(`[llms] Generated ${colors.dim("dist/llms-full.txt")}`);
|
|
@@ -1326,64 +1329,277 @@ async function build$2(options) {
|
|
|
1326
1329
|
}
|
|
1327
1330
|
consola.success(`llms.txt generated. (${posts.length} pages)`);
|
|
1328
1331
|
}
|
|
1329
|
-
function
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1332
|
+
function llmsSelection(llms) {
|
|
1333
|
+
return {
|
|
1334
|
+
exclude: llms.exclude,
|
|
1335
|
+
collapse: llms.collapse,
|
|
1336
|
+
locales: llms.locales
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
function warnUnmatchedCollapse(posts, selection) {
|
|
1340
|
+
const rules = selection.collapse || [];
|
|
1341
|
+
if (rules.length === 0)
|
|
1342
|
+
return;
|
|
1343
|
+
const { collapseLinks } = planLlmsPages(posts, selection);
|
|
1344
|
+
for (const [index, rule] of rules.entries()) {
|
|
1345
|
+
if (!rule?.match?.trim())
|
|
1346
|
+
continue;
|
|
1347
|
+
if (!collapseLinks.some((link) => link.ruleIndex === index))
|
|
1348
|
+
consola.warn(`[llms] collapse pattern matched no pages: ${rule.match}`);
|
|
1334
1349
|
}
|
|
1335
|
-
return "Pages";
|
|
1336
1350
|
}
|
|
1337
|
-
function
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
if (
|
|
1351
|
+
function normalizeGlobPattern(pattern) {
|
|
1352
|
+
return pattern.trim().replace(/^\.\//, "").replace(/^\//, "");
|
|
1353
|
+
}
|
|
1354
|
+
function normalizeLlmsPath(input) {
|
|
1355
|
+
let value = input.trim();
|
|
1356
|
+
if (/^https?:\/\//i.test(value)) {
|
|
1357
|
+
try {
|
|
1358
|
+
value = new URL(value).pathname;
|
|
1359
|
+
} catch {
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
if (!value.startsWith("/"))
|
|
1363
|
+
value = `/${value}`;
|
|
1364
|
+
if (value.endsWith("/index.md"))
|
|
1365
|
+
value = value.slice(0, -"/index.md".length);
|
|
1366
|
+
else if (value.endsWith(".md"))
|
|
1367
|
+
value = value.slice(0, -3);
|
|
1368
|
+
if (value.length > 1 && value.endsWith("/"))
|
|
1369
|
+
value = value.slice(0, -1);
|
|
1370
|
+
return value || "/";
|
|
1371
|
+
}
|
|
1372
|
+
function createGlobMatcher(patterns) {
|
|
1373
|
+
const positive = [];
|
|
1374
|
+
const negative = [];
|
|
1375
|
+
for (const value of patterns || []) {
|
|
1376
|
+
const pattern = value.trim();
|
|
1377
|
+
if (pattern.startsWith("!") && !pattern.startsWith("!(")) {
|
|
1378
|
+
const exception = pattern.slice(1);
|
|
1379
|
+
if (!exception.startsWith("!") || exception.startsWith("!("))
|
|
1380
|
+
negative.push(normalizeGlobPattern(exception));
|
|
1381
|
+
} else {
|
|
1382
|
+
positive.push(normalizeGlobPattern(pattern));
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
const isMatch = picomatch(positive.filter(Boolean), { windows: false });
|
|
1386
|
+
const isIgnored = picomatch(negative.filter(Boolean), { windows: false });
|
|
1387
|
+
return (sourcePath) => isMatch(sourcePath) && !isIgnored(sourcePath);
|
|
1388
|
+
}
|
|
1389
|
+
function capitalizeSection(segment) {
|
|
1390
|
+
return segment.charAt(0).toUpperCase() + segment.slice(1);
|
|
1391
|
+
}
|
|
1392
|
+
function splitLlmsLocale(urlPath, locales) {
|
|
1393
|
+
const parts = normalizeLlmsPath(urlPath).split("/").filter(Boolean);
|
|
1394
|
+
if (!locales?.length || parts.length === 0)
|
|
1395
|
+
return { parts };
|
|
1396
|
+
const locale = locales.find((item) => item.toLowerCase() === parts[0].toLowerCase());
|
|
1397
|
+
if (!locale)
|
|
1398
|
+
return { parts };
|
|
1399
|
+
return { locale, parts: parts.slice(1) };
|
|
1400
|
+
}
|
|
1401
|
+
function formatLocaleSection(name, locale) {
|
|
1402
|
+
return locale ? `${name} (${locale})` : name;
|
|
1403
|
+
}
|
|
1404
|
+
function getLlmsSectionName(urlPath, locales) {
|
|
1405
|
+
const { locale, parts } = splitLlmsLocale(urlPath, locales);
|
|
1406
|
+
const name = parts.length >= 2 ? capitalizeSection(parts[0]) : PAGES_SECTION;
|
|
1407
|
+
return formatLocaleSection(name, locale);
|
|
1408
|
+
}
|
|
1409
|
+
function sectionFromHref(href, locales, explicit) {
|
|
1410
|
+
if (explicit)
|
|
1411
|
+
return explicit;
|
|
1412
|
+
const normalized = normalizeLlmsPath(href);
|
|
1413
|
+
const named = getLlmsSectionName(normalized, locales);
|
|
1414
|
+
if (named !== PAGES_SECTION && !named.startsWith(`${PAGES_SECTION} (`))
|
|
1415
|
+
return named;
|
|
1416
|
+
const { locale, parts } = splitLlmsLocale(normalized, locales);
|
|
1417
|
+
if (parts.length === 1)
|
|
1418
|
+
return formatLocaleSection(capitalizeSection(parts[0]), locale);
|
|
1419
|
+
return named;
|
|
1420
|
+
}
|
|
1421
|
+
function entryUrl(siteUrl, href) {
|
|
1422
|
+
if (/^https?:\/\//i.test(href))
|
|
1423
|
+
return href;
|
|
1424
|
+
if (href.endsWith(".md"))
|
|
1425
|
+
return siteUrl ? `${siteUrl}${href.startsWith("/") ? href : `/${href}`}` : href;
|
|
1426
|
+
return hrefToUrl(siteUrl, href);
|
|
1427
|
+
}
|
|
1428
|
+
function hrefToUrl(siteUrl, href) {
|
|
1429
|
+
const trimmed = href.trim();
|
|
1430
|
+
if (/^https?:\/\//i.test(trimmed))
|
|
1431
|
+
return trimmed;
|
|
1432
|
+
const directory = trimmed.endsWith("/");
|
|
1433
|
+
const urlPath = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
1434
|
+
const target = directory || urlPath.endsWith(".md") ? urlPath : `${normalizeLlmsPath(urlPath)}.md`;
|
|
1435
|
+
return siteUrl ? `${siteUrl}${target}` : target;
|
|
1436
|
+
}
|
|
1437
|
+
function planLlmsPages(posts, config = {}) {
|
|
1438
|
+
const excluded = createGlobMatcher(config.exclude);
|
|
1439
|
+
const rules = config.collapse || [];
|
|
1440
|
+
const matchers = rules.map((rule) => createGlobMatcher(rule?.match ? [rule.match] : []));
|
|
1441
|
+
const matched = /* @__PURE__ */ new Set();
|
|
1442
|
+
const visible = [];
|
|
1443
|
+
for (const post of posts) {
|
|
1444
|
+
if (excluded(post.sourcePath))
|
|
1445
|
+
continue;
|
|
1446
|
+
const ruleIndex = matchers.findIndex((match) => match(post.sourcePath));
|
|
1447
|
+
if (ruleIndex >= 0) {
|
|
1448
|
+
matched.add(ruleIndex);
|
|
1449
|
+
continue;
|
|
1450
|
+
}
|
|
1451
|
+
visible.push(post);
|
|
1452
|
+
}
|
|
1453
|
+
const collapseLinks = [...matched].sort((a, b) => a - b).map((ruleIndex) => {
|
|
1454
|
+
const rule = rules[ruleIndex];
|
|
1455
|
+
return {
|
|
1456
|
+
title: rule.title,
|
|
1457
|
+
description: rule.description || "",
|
|
1458
|
+
href: rule.href,
|
|
1459
|
+
section: sectionFromHref(rule.href, config.locales, rule.section),
|
|
1460
|
+
ruleIndex
|
|
1461
|
+
};
|
|
1462
|
+
});
|
|
1463
|
+
return { visible, collapseLinks };
|
|
1464
|
+
}
|
|
1465
|
+
function appendBlockquote(lines, description, prompt) {
|
|
1466
|
+
const promptLines = prompt ? prompt.split(/\r?\n/) : [];
|
|
1467
|
+
if (!description && promptLines.length === 0)
|
|
1468
|
+
return;
|
|
1469
|
+
if (description)
|
|
1470
|
+
lines.push(`> ${description}`);
|
|
1471
|
+
if (promptLines.length > 0) {
|
|
1343
1472
|
if (description)
|
|
1344
|
-
lines.push(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1473
|
+
lines.push(">");
|
|
1474
|
+
for (const line of promptLines)
|
|
1475
|
+
lines.push(line ? `> ${line}` : ">");
|
|
1476
|
+
}
|
|
1477
|
+
lines.push("");
|
|
1478
|
+
}
|
|
1479
|
+
function formatIndexLink(title, url, description) {
|
|
1480
|
+
const desc = description ? `: ${description}` : "";
|
|
1481
|
+
return `- [${title}](${url})${desc}`;
|
|
1482
|
+
}
|
|
1483
|
+
function groupLlmsEntries(params) {
|
|
1484
|
+
const featuredPaths = params.featured?.paths || [];
|
|
1485
|
+
const featuredPosts = [];
|
|
1486
|
+
const rest = [];
|
|
1487
|
+
if (featuredPaths.length > 0) {
|
|
1488
|
+
const byPath = new Map(params.posts.map((post) => [normalizeLlmsPath(post.urlPath), post]));
|
|
1489
|
+
const used = /* @__PURE__ */ new Set();
|
|
1490
|
+
for (const item of featuredPaths) {
|
|
1491
|
+
const post = byPath.get(normalizeLlmsPath(item));
|
|
1492
|
+
if (post && !used.has(post)) {
|
|
1493
|
+
featuredPosts.push(post);
|
|
1494
|
+
used.add(post);
|
|
1495
|
+
}
|
|
1349
1496
|
}
|
|
1350
|
-
|
|
1497
|
+
for (const post of params.posts) {
|
|
1498
|
+
if (!used.has(post))
|
|
1499
|
+
rest.push(post);
|
|
1500
|
+
}
|
|
1501
|
+
} else {
|
|
1502
|
+
rest.push(...params.posts);
|
|
1351
1503
|
}
|
|
1352
1504
|
const sections = /* @__PURE__ */ new Map();
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1505
|
+
const featuredTitle = params.featured?.title || "Docs";
|
|
1506
|
+
if (featuredPosts.length > 0) {
|
|
1507
|
+
sections.set(featuredTitle, featuredPosts.map((post) => ({
|
|
1508
|
+
title: post.title,
|
|
1509
|
+
description: post.description,
|
|
1510
|
+
href: `${post.urlPath}.md`
|
|
1511
|
+
})));
|
|
1512
|
+
}
|
|
1513
|
+
for (const post of rest) {
|
|
1514
|
+
const section = getLlmsSectionName(post.urlPath, params.locales);
|
|
1515
|
+
const entries = sections.get(section);
|
|
1516
|
+
const entry = {
|
|
1517
|
+
title: post.title,
|
|
1518
|
+
description: post.description,
|
|
1519
|
+
href: `${post.urlPath}.md`
|
|
1520
|
+
};
|
|
1521
|
+
if (entries)
|
|
1522
|
+
entries.push(entry);
|
|
1523
|
+
else
|
|
1524
|
+
sections.set(section, [entry]);
|
|
1525
|
+
}
|
|
1526
|
+
const collapsed = /* @__PURE__ */ new Map();
|
|
1527
|
+
for (const link of params.collapseLinks) {
|
|
1528
|
+
const entries = collapsed.get(link.section) || [];
|
|
1529
|
+
entries.push({
|
|
1530
|
+
title: link.title,
|
|
1531
|
+
description: link.description,
|
|
1532
|
+
href: link.href
|
|
1533
|
+
});
|
|
1534
|
+
collapsed.set(link.section, entries);
|
|
1535
|
+
}
|
|
1536
|
+
for (const [section, links] of collapsed) {
|
|
1537
|
+
const entries = sections.get(section);
|
|
1538
|
+
if (entries)
|
|
1539
|
+
entries.splice(section === featuredTitle ? featuredPosts.length : 0, 0, ...links);
|
|
1540
|
+
else
|
|
1541
|
+
sections.set(section, links);
|
|
1542
|
+
}
|
|
1543
|
+
return orderSections(sections, params.sectionOrder, featuredPosts.length > 0 ? featuredTitle : void 0);
|
|
1544
|
+
}
|
|
1545
|
+
function orderSections(sections, sectionOrder, featuredTitle) {
|
|
1546
|
+
const entries = [...sections.entries()];
|
|
1547
|
+
if (!sectionOrder?.length)
|
|
1548
|
+
return sections;
|
|
1549
|
+
const byName = new Map(entries.map(([name, items]) => [name.toLowerCase(), [name, items]]));
|
|
1550
|
+
const used = /* @__PURE__ */ new Set();
|
|
1551
|
+
const ordered = [];
|
|
1552
|
+
if (featuredTitle) {
|
|
1553
|
+
const found = byName.get(featuredTitle.toLowerCase());
|
|
1554
|
+
if (found) {
|
|
1555
|
+
ordered.push([found[0], found[1]]);
|
|
1556
|
+
used.add(found[0]);
|
|
1557
|
+
}
|
|
1358
1558
|
}
|
|
1359
|
-
for (const
|
|
1559
|
+
for (const name of sectionOrder) {
|
|
1560
|
+
const found = byName.get(name.toLowerCase());
|
|
1561
|
+
if (found && !used.has(found[0])) {
|
|
1562
|
+
ordered.push([found[0], found[1]]);
|
|
1563
|
+
used.add(found[0]);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
for (const [name, items] of entries) {
|
|
1567
|
+
if (!used.has(name))
|
|
1568
|
+
ordered.push([name, items]);
|
|
1569
|
+
}
|
|
1570
|
+
return new Map(ordered);
|
|
1571
|
+
}
|
|
1572
|
+
function generateLlmsTxt(params) {
|
|
1573
|
+
const { title, description, prompt, posts, siteUrl } = params;
|
|
1574
|
+
const plan = planLlmsPages(posts, params);
|
|
1575
|
+
const sections = groupLlmsEntries({
|
|
1576
|
+
posts: plan.visible,
|
|
1577
|
+
collapseLinks: plan.collapseLinks,
|
|
1578
|
+
locales: params.locales,
|
|
1579
|
+
sectionOrder: params.sectionOrder,
|
|
1580
|
+
featured: params.featured
|
|
1581
|
+
});
|
|
1582
|
+
const lines = [];
|
|
1583
|
+
lines.push(`# ${title}`);
|
|
1584
|
+
lines.push("");
|
|
1585
|
+
appendBlockquote(lines, description, prompt);
|
|
1586
|
+
for (const [section, entries] of sections) {
|
|
1360
1587
|
lines.push(`## ${section}`);
|
|
1361
1588
|
lines.push("");
|
|
1362
|
-
for (const
|
|
1363
|
-
|
|
1364
|
-
const desc = post.description ? `: ${post.description}` : "";
|
|
1365
|
-
lines.push(`- [${post.title}](${mdUrl})${desc}`);
|
|
1366
|
-
}
|
|
1589
|
+
for (const entry of entries)
|
|
1590
|
+
lines.push(formatIndexLink(entry.title, entryUrl(siteUrl, entry.href), entry.description));
|
|
1367
1591
|
lines.push("");
|
|
1368
1592
|
}
|
|
1369
1593
|
return lines.join("\n");
|
|
1370
1594
|
}
|
|
1371
1595
|
function generateLlmsFullTxt(params) {
|
|
1372
|
-
const { title, description, prompt
|
|
1596
|
+
const { title, description, prompt } = params;
|
|
1597
|
+
const { visible } = planLlmsPages(params.posts, params);
|
|
1373
1598
|
const lines = [];
|
|
1374
1599
|
lines.push(`# ${title}`);
|
|
1375
1600
|
lines.push("");
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
lines.push(`> ${description}`);
|
|
1379
|
-
if (prompt) {
|
|
1380
|
-
if (description)
|
|
1381
|
-
lines.push(">");
|
|
1382
|
-
lines.push(`> ${prompt}`);
|
|
1383
|
-
}
|
|
1384
|
-
lines.push("");
|
|
1385
|
-
}
|
|
1386
|
-
for (const post of posts) {
|
|
1601
|
+
appendBlockquote(lines, description, prompt);
|
|
1602
|
+
for (const post of visible) {
|
|
1387
1603
|
lines.push(`## ${post.title}`);
|
|
1388
1604
|
lines.push("");
|
|
1389
1605
|
const metaLines = formatMetadataLines(post);
|
|
@@ -1462,7 +1678,7 @@ const llmsModule = defineValaxyModule({
|
|
|
1462
1678
|
(args) => commonOptions(args).strict().help(),
|
|
1463
1679
|
async ({ root }) => {
|
|
1464
1680
|
setEnvProd();
|
|
1465
|
-
const options = await resolveOptions$
|
|
1681
|
+
const options = await resolveOptions$1({ userRoot: root }, "build");
|
|
1466
1682
|
await build$2(options);
|
|
1467
1683
|
}
|
|
1468
1684
|
);
|
|
@@ -1475,11 +1691,21 @@ const llmsModule = defineValaxyModule({
|
|
|
1475
1691
|
}
|
|
1476
1692
|
});
|
|
1477
1693
|
|
|
1694
|
+
async function statIfExists(file) {
|
|
1695
|
+
try {
|
|
1696
|
+
return await fs.stat(file);
|
|
1697
|
+
} catch (e) {
|
|
1698
|
+
const code = e.code;
|
|
1699
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
1700
|
+
return void 0;
|
|
1701
|
+
throw e;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1478
1704
|
async function getCreatedTime(file) {
|
|
1479
|
-
return await getGitTimestamp(file, "created") || (await
|
|
1705
|
+
return await getGitTimestamp(file, "created") || (await statIfExists(file))?.ctime || Date.now();
|
|
1480
1706
|
}
|
|
1481
1707
|
async function getUpdatedTime(file) {
|
|
1482
|
-
return await getGitTimestamp(file, "updated") || (await
|
|
1708
|
+
return await getGitTimestamp(file, "updated") || (await statIfExists(file))?.mtime || Date.now();
|
|
1483
1709
|
}
|
|
1484
1710
|
|
|
1485
1711
|
const markdown = createMarkdownExit({
|
|
@@ -1742,7 +1968,7 @@ const rssModule = defineValaxyModule({
|
|
|
1742
1968
|
(args) => commonOptions(args).strict().help(),
|
|
1743
1969
|
async ({ root }) => {
|
|
1744
1970
|
setEnvProd();
|
|
1745
|
-
const options = await resolveOptions$
|
|
1971
|
+
const options = await resolveOptions$1({ userRoot: root }, "build");
|
|
1746
1972
|
await build$1(options);
|
|
1747
1973
|
}
|
|
1748
1974
|
);
|
|
@@ -2047,7 +2273,7 @@ function toArray(array) {
|
|
|
2047
2273
|
function notNullish(v) {
|
|
2048
2274
|
return v != null;
|
|
2049
2275
|
}
|
|
2050
|
-
function slash
|
|
2276
|
+
function slash(str) {
|
|
2051
2277
|
return str.replace(/\\/g, "/");
|
|
2052
2278
|
}
|
|
2053
2279
|
function throttle$1(delay, callback, options) {
|
|
@@ -2090,7 +2316,7 @@ function throttle(...args) {
|
|
|
2090
2316
|
return throttle$1(...args);
|
|
2091
2317
|
}
|
|
2092
2318
|
const DISABLE_COMMENT = "/* unplugin-vue-components disabled */";
|
|
2093
|
-
Boolean(process
|
|
2319
|
+
Boolean(process.env.SSR || process.env.SSG || process.env.VITE_SSR || process.env.VITE_SSG);
|
|
2094
2320
|
function pascalCase(str) {
|
|
2095
2321
|
return capitalize(camelCase(str));
|
|
2096
2322
|
}
|
|
@@ -2121,7 +2347,7 @@ function isEmpty(value) {
|
|
|
2121
2347
|
function matchGlobs(filepath, globs) {
|
|
2122
2348
|
for (const glob of globs) {
|
|
2123
2349
|
const isNegated = glob[0] === "!";
|
|
2124
|
-
if (picomatch(isNegated ? glob.slice(1) : glob)(slash
|
|
2350
|
+
if (picomatch(isNegated ? glob.slice(1) : glob)(slash(filepath))) return !isNegated;
|
|
2125
2351
|
}
|
|
2126
2352
|
return false;
|
|
2127
2353
|
}
|
|
@@ -2159,7 +2385,7 @@ function stringifyComponentImport({ as: name, from: path, name: importName, side
|
|
|
2159
2385
|
}
|
|
2160
2386
|
function getNameFromFilePath(filePath, options) {
|
|
2161
2387
|
const { resolvedDirs, directoryAsNamespace, globalNamespaces, collapseSamePrefixes, root } = options;
|
|
2162
|
-
const parsedFilePath = parse(slash
|
|
2388
|
+
const parsedFilePath = parse(slash(filePath));
|
|
2163
2389
|
let strippedPath = "";
|
|
2164
2390
|
for (const dir of resolvedDirs) if (parsedFilePath.dir.startsWith(dir)) {
|
|
2165
2391
|
strippedPath = parsedFilePath.dir.slice(dir.length);
|
|
@@ -2264,7 +2490,7 @@ function parseDeclaration(code) {
|
|
|
2264
2490
|
function stringifyComponentInfo(filepath, { from: path, as: name, name: importName }, importPathTransform) {
|
|
2265
2491
|
if (!name) return void 0;
|
|
2266
2492
|
path = getTransformedPath(path, importPathTransform);
|
|
2267
|
-
return [name, `typeof import('${slash
|
|
2493
|
+
return [name, `typeof import('${slash(isAbsolute$1(path) ? `./${relative$1(dirname(filepath), path)}` : path)}')['${importName || "default"}']`];
|
|
2268
2494
|
}
|
|
2269
2495
|
function stringifyComponentsInfo(filepath, components, importPathTransform) {
|
|
2270
2496
|
return Object.fromEntries(components.map((info) => stringifyComponentInfo(filepath, info, importPathTransform)).filter(notNullish));
|
|
@@ -2353,9 +2579,9 @@ async function writeComponentsJson(ctx, _removeUnused = false) {
|
|
|
2353
2579
|
})), ...resolveTypeImports(ctx.options.types)];
|
|
2354
2580
|
await writeFile$1(ctx.dumpComponentsInfoPath, JSON.stringify(components, null, 2));
|
|
2355
2581
|
}
|
|
2356
|
-
const debug$4
|
|
2582
|
+
const debug$4 = createDebug("unplugin-vue-components:glob");
|
|
2357
2583
|
function searchComponents(ctx) {
|
|
2358
|
-
debug$4
|
|
2584
|
+
debug$4(`started with: [${ctx.options.globs.join(", ")}]`);
|
|
2359
2585
|
const root = ctx.root;
|
|
2360
2586
|
const files = globSync(ctx.options.globs, {
|
|
2361
2587
|
ignore: ctx.options.globsExclude,
|
|
@@ -2365,7 +2591,7 @@ function searchComponents(ctx) {
|
|
|
2365
2591
|
expandDirectories: false
|
|
2366
2592
|
});
|
|
2367
2593
|
if (!files.length && !ctx.options.resolvers?.length) console.warn("[unplugin-vue-components] no components found");
|
|
2368
|
-
debug$4
|
|
2594
|
+
debug$4(`${files.length} components found.`);
|
|
2369
2595
|
ctx.addComponents(files);
|
|
2370
2596
|
}
|
|
2371
2597
|
const defaultOptions = {
|
|
@@ -2394,9 +2620,9 @@ function normalizeResolvers(resolvers) {
|
|
|
2394
2620
|
}
|
|
2395
2621
|
function resolveGlobsExclude(root, glob2) {
|
|
2396
2622
|
const excludeReg = /^!/;
|
|
2397
|
-
return slash
|
|
2623
|
+
return slash(`${excludeReg.test(glob2) ? "!" : ""}${resolve(root, glob2.replace(excludeReg, ""))}`);
|
|
2398
2624
|
}
|
|
2399
|
-
function resolveOptions
|
|
2625
|
+
function resolveOptions(options, root) {
|
|
2400
2626
|
const resolved = Object.assign({}, defaultOptions, options);
|
|
2401
2627
|
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
|
2402
2628
|
resolved.extensions = toArray(resolved.extensions);
|
|
@@ -2414,7 +2640,7 @@ function resolveOptions$2(options, root) {
|
|
|
2414
2640
|
prefix = "!";
|
|
2415
2641
|
i = i.slice(1);
|
|
2416
2642
|
}
|
|
2417
|
-
return resolved.deep ? prefix + escapeSpecialChars(slash
|
|
2643
|
+
return resolved.deep ? prefix + escapeSpecialChars(slash(join(i, `**/*.${extsGlob}`))) : prefix + escapeSpecialChars(slash(join(i, `*.${extsGlob}`)));
|
|
2418
2644
|
});
|
|
2419
2645
|
if (!resolved.extensions.length) throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
|
2420
2646
|
}
|
|
@@ -2431,7 +2657,7 @@ function resolveOptions$2(options, root) {
|
|
|
2431
2657
|
resolved.directives ??= resolved.resolvers.some((i) => i.type === "directive");
|
|
2432
2658
|
return resolved;
|
|
2433
2659
|
}
|
|
2434
|
-
const debug$3
|
|
2660
|
+
const debug$3 = createDebug("unplugin-vue-components:transform:component");
|
|
2435
2661
|
function resolveVue3$1(code, s, transformerUserResolveFunctions) {
|
|
2436
2662
|
const results = [];
|
|
2437
2663
|
for (const match of code.matchAll(/_?resolveComponent\d*\("(.+?)"\)/g)) {
|
|
@@ -2452,7 +2678,7 @@ async function transformComponent(code, s, ctx, sfcPath) {
|
|
|
2452
2678
|
let no = 0;
|
|
2453
2679
|
const results = resolveVue3$1(code, s, ctx.options.transformerUserResolveFunctions);
|
|
2454
2680
|
for (const { rawName, replace } of results) {
|
|
2455
|
-
debug$3
|
|
2681
|
+
debug$3(`| ${rawName}`);
|
|
2456
2682
|
const name = pascalCase(rawName);
|
|
2457
2683
|
ctx.updateUsageMap(sfcPath, [name]);
|
|
2458
2684
|
const component = await ctx.findComponent(name, "component", [sfcPath]);
|
|
@@ -2467,9 +2693,9 @@ async function transformComponent(code, s, ctx, sfcPath) {
|
|
|
2467
2693
|
replace(varName);
|
|
2468
2694
|
}
|
|
2469
2695
|
}
|
|
2470
|
-
debug$3
|
|
2696
|
+
debug$3(`^ (${no})`);
|
|
2471
2697
|
}
|
|
2472
|
-
const debug$2$1 = createDebug
|
|
2698
|
+
const debug$2$1 = createDebug("unplugin-vue-components:transform:directive");
|
|
2473
2699
|
async function transformDirective(code, s, ctx, sfcPath) {
|
|
2474
2700
|
let no = 0;
|
|
2475
2701
|
const results = resolveVue3(code, s, ctx.options.transformerUserResolveFunctions);
|
|
@@ -2506,12 +2732,12 @@ function resolveVue3(code, s, transformerUserResolveFunctions) {
|
|
|
2506
2732
|
}
|
|
2507
2733
|
return results;
|
|
2508
2734
|
}
|
|
2509
|
-
const debug$1$
|
|
2735
|
+
const debug$1$1 = createDebug("unplugin-vue-components:transformer");
|
|
2510
2736
|
function transformer(ctx) {
|
|
2511
2737
|
return async (code, id, path) => {
|
|
2512
2738
|
ctx.searchGlob();
|
|
2513
2739
|
const sfcPath = ctx.normalizePath(path);
|
|
2514
|
-
debug$1$
|
|
2740
|
+
debug$1$1(sfcPath);
|
|
2515
2741
|
const s = new MagicString(code);
|
|
2516
2742
|
await transformComponent(code, s, ctx, sfcPath);
|
|
2517
2743
|
if (ctx.options.directives) await transformDirective(code, s, ctx, sfcPath);
|
|
@@ -2525,12 +2751,12 @@ function transformer(ctx) {
|
|
|
2525
2751
|
return result;
|
|
2526
2752
|
};
|
|
2527
2753
|
}
|
|
2528
|
-
const debug$
|
|
2529
|
-
components: createDebug
|
|
2530
|
-
search: createDebug
|
|
2531
|
-
hmr: createDebug
|
|
2532
|
-
declaration: createDebug
|
|
2533
|
-
env: createDebug
|
|
2754
|
+
const debug$5 = {
|
|
2755
|
+
components: createDebug("unplugin-vue-components:context:components"),
|
|
2756
|
+
search: createDebug("unplugin-vue-components:context:search"),
|
|
2757
|
+
hmr: createDebug("unplugin-vue-components:context:hmr"),
|
|
2758
|
+
declaration: createDebug("unplugin-vue-components:declaration"),
|
|
2759
|
+
env: createDebug("unplugin-vue-components:env")
|
|
2534
2760
|
};
|
|
2535
2761
|
var Context = class {
|
|
2536
2762
|
rawOptions;
|
|
@@ -2543,13 +2769,13 @@ var Context = class {
|
|
|
2543
2769
|
_directiveCustomMap = {};
|
|
2544
2770
|
_removeUnused = false;
|
|
2545
2771
|
_server;
|
|
2546
|
-
root = process
|
|
2772
|
+
root = process.cwd();
|
|
2547
2773
|
sourcemap = true;
|
|
2548
2774
|
alias = {};
|
|
2549
2775
|
dumpComponentsInfoPath;
|
|
2550
2776
|
constructor(rawOptions) {
|
|
2551
2777
|
this.rawOptions = rawOptions;
|
|
2552
|
-
this.options = resolveOptions
|
|
2778
|
+
this.options = resolveOptions(rawOptions, this.root);
|
|
2553
2779
|
this.sourcemap = rawOptions.sourcemap ?? true;
|
|
2554
2780
|
this.generateDeclaration = throttle(500, this._generateDeclaration.bind(this), { noLeading: false });
|
|
2555
2781
|
this._removeUnused = this.options.syncMode !== "append";
|
|
@@ -2562,9 +2788,9 @@ var Context = class {
|
|
|
2562
2788
|
}
|
|
2563
2789
|
setRoot(root) {
|
|
2564
2790
|
if (this.root === root) return;
|
|
2565
|
-
debug$
|
|
2791
|
+
debug$5.env("root", root);
|
|
2566
2792
|
this.root = root;
|
|
2567
|
-
this.options = resolveOptions
|
|
2793
|
+
this.options = resolveOptions(this.rawOptions, this.root);
|
|
2568
2794
|
}
|
|
2569
2795
|
transform(code, id) {
|
|
2570
2796
|
const { path, query } = parseId(id);
|
|
@@ -2581,13 +2807,13 @@ var Context = class {
|
|
|
2581
2807
|
this._removeUnused = this.options.syncMode === "overwrite";
|
|
2582
2808
|
watcher.on("unlink", (path) => {
|
|
2583
2809
|
if (!matchGlobs(path, globs)) return;
|
|
2584
|
-
path = slash
|
|
2810
|
+
path = slash(path);
|
|
2585
2811
|
this.removeComponents(path);
|
|
2586
2812
|
this.onUpdate(path);
|
|
2587
2813
|
});
|
|
2588
2814
|
watcher.on("add", (path) => {
|
|
2589
2815
|
if (!matchGlobs(path, globs)) return;
|
|
2590
|
-
path = slash
|
|
2816
|
+
path = slash(path);
|
|
2591
2817
|
this.addComponents(path);
|
|
2592
2818
|
this.onUpdate(path);
|
|
2593
2819
|
});
|
|
@@ -2600,13 +2826,13 @@ var Context = class {
|
|
|
2600
2826
|
this._removeUnused = this.options.syncMode === "overwrite";
|
|
2601
2827
|
watcher.on("unlink", (path) => {
|
|
2602
2828
|
if (!matchGlobs(path, globs)) return;
|
|
2603
|
-
path = slash
|
|
2829
|
+
path = slash(path);
|
|
2604
2830
|
this.removeComponents(path);
|
|
2605
2831
|
emitUpdate(path, "unlink");
|
|
2606
2832
|
});
|
|
2607
2833
|
watcher.on("add", (path) => {
|
|
2608
2834
|
if (!matchGlobs(path, globs)) return;
|
|
2609
|
-
path = slash
|
|
2835
|
+
path = slash(path);
|
|
2610
2836
|
this.addComponents(path);
|
|
2611
2837
|
emitUpdate(path, "add");
|
|
2612
2838
|
});
|
|
@@ -2623,7 +2849,7 @@ var Context = class {
|
|
|
2623
2849
|
});
|
|
2624
2850
|
}
|
|
2625
2851
|
addComponents(paths) {
|
|
2626
|
-
debug$
|
|
2852
|
+
debug$5.components("add", paths);
|
|
2627
2853
|
const size = this._componentPaths.size;
|
|
2628
2854
|
toArray(paths).forEach((p) => this._componentPaths.add(p));
|
|
2629
2855
|
if (this._componentPaths.size !== size) {
|
|
@@ -2639,7 +2865,7 @@ var Context = class {
|
|
|
2639
2865
|
if (info.as) this._directiveCustomMap[info.as] = info;
|
|
2640
2866
|
}
|
|
2641
2867
|
removeComponents(paths) {
|
|
2642
|
-
debug$
|
|
2868
|
+
debug$5.components("remove", paths);
|
|
2643
2869
|
const size = this._componentPaths.size;
|
|
2644
2870
|
toArray(paths).forEach((p) => this._componentPaths.delete(p));
|
|
2645
2871
|
if (this._componentPaths.size !== size) {
|
|
@@ -2660,7 +2886,7 @@ var Context = class {
|
|
|
2660
2886
|
const name = pascalCase(getNameFromFilePath(path, this.options));
|
|
2661
2887
|
Object.entries(this._componentUsageMap).forEach(([key, values]) => {
|
|
2662
2888
|
if (values.has(name)) {
|
|
2663
|
-
const r = `/${slash
|
|
2889
|
+
const r = `/${slash(relative$1(this.root, key))}`;
|
|
2664
2890
|
payload.updates.push({
|
|
2665
2891
|
acceptedPath: r,
|
|
2666
2892
|
path: r,
|
|
@@ -2679,7 +2905,7 @@ var Context = class {
|
|
|
2679
2905
|
const fileName = getNameFromFilePath(path, this.options);
|
|
2680
2906
|
const name = this.options.prefix ? `${pascalCase(this.options.prefix)}${pascalCase(fileName)}` : pascalCase(fileName);
|
|
2681
2907
|
if (isExclude(name, this.options.excludeNames)) {
|
|
2682
|
-
debug$
|
|
2908
|
+
debug$5.components("exclude", name);
|
|
2683
2909
|
return;
|
|
2684
2910
|
}
|
|
2685
2911
|
if (this._componentNameMap[name] && !this.options.allowOverrides) {
|
|
@@ -2716,8 +2942,8 @@ var Context = class {
|
|
|
2716
2942
|
return resolveAlias(path, this.viteConfig?.resolve?.alias || this.viteConfig?.alias || []);
|
|
2717
2943
|
}
|
|
2718
2944
|
relative(path) {
|
|
2719
|
-
if (path.startsWith("/") && !path.startsWith(this.root)) return slash
|
|
2720
|
-
return slash
|
|
2945
|
+
if (path.startsWith("/") && !path.startsWith(this.root)) return slash(path.slice(1));
|
|
2946
|
+
return slash(relative$1(this.root, path));
|
|
2721
2947
|
}
|
|
2722
2948
|
_searched = false;
|
|
2723
2949
|
/**
|
|
@@ -2728,12 +2954,12 @@ var Context = class {
|
|
|
2728
2954
|
searchGlob() {
|
|
2729
2955
|
if (this._searched) return;
|
|
2730
2956
|
searchComponents(this);
|
|
2731
|
-
debug$
|
|
2957
|
+
debug$5.search(this._componentNameMap);
|
|
2732
2958
|
this._searched = true;
|
|
2733
2959
|
}
|
|
2734
2960
|
_generateDeclaration(removeUnused = this._removeUnused) {
|
|
2735
2961
|
if (!this.options.dts) return;
|
|
2736
|
-
debug$
|
|
2962
|
+
debug$5.declaration("generating dts");
|
|
2737
2963
|
return writeDeclaration(this, this.options.dts, removeUnused);
|
|
2738
2964
|
}
|
|
2739
2965
|
generateDeclaration(removeUnused = this._removeUnused) {
|
|
@@ -2741,7 +2967,7 @@ var Context = class {
|
|
|
2741
2967
|
}
|
|
2742
2968
|
_generateComponentsJson(removeUnused = this._removeUnused) {
|
|
2743
2969
|
if (!Object.keys(this._componentNameMap).length) return;
|
|
2744
|
-
debug$
|
|
2970
|
+
debug$5.components("generating components-info");
|
|
2745
2971
|
return writeComponentsJson(this, removeUnused);
|
|
2746
2972
|
}
|
|
2747
2973
|
generateComponentsJson(removeUnused = this._removeUnused) {
|
|
@@ -2823,7 +3049,7 @@ var unplugin_default = createUnplugin((options = {}) => {
|
|
|
2823
3049
|
path,
|
|
2824
3050
|
type
|
|
2825
3051
|
});
|
|
2826
|
-
process
|
|
3052
|
+
process.nextTick(() => {
|
|
2827
3053
|
watcher.invalidate();
|
|
2828
3054
|
});
|
|
2829
3055
|
});
|
|
@@ -2844,300 +3070,6 @@ var unplugin_default = createUnplugin((options = {}) => {
|
|
|
2844
3070
|
|
|
2845
3071
|
const Components = unplugin_default.vite;
|
|
2846
3072
|
|
|
2847
|
-
const REGEX_BACKSLASH$1 = /\\/g;
|
|
2848
|
-
const REGEX_SEPARATORS = /[-_/.\s]+/g;
|
|
2849
|
-
const REGEX_NON_ALPHANUMERIC = /[^a-z0-9-]+/gi;
|
|
2850
|
-
const REGEX_REPEATED_DASH = /-+/g;
|
|
2851
|
-
const REGEX_EDGE_DASH = /^-|-$/g;
|
|
2852
|
-
const REGEX_NUMBER = /\d/;
|
|
2853
|
-
function isUppercase(char = "") {
|
|
2854
|
-
if (REGEX_NUMBER.test(char)) return void 0;
|
|
2855
|
-
return char !== char.toLowerCase();
|
|
2856
|
-
}
|
|
2857
|
-
function caseBoundary(previousUpper, isUpper, buffer) {
|
|
2858
|
-
if (previousUpper === false && isUpper === true) return "before";
|
|
2859
|
-
if (previousUpper === true && isUpper === false && buffer.length > 1) return "after";
|
|
2860
|
-
}
|
|
2861
|
-
function splitByCase(value) {
|
|
2862
|
-
const parts = [];
|
|
2863
|
-
let buffer = "";
|
|
2864
|
-
let previousUpper;
|
|
2865
|
-
let previousSplitter;
|
|
2866
|
-
const flush = () => {
|
|
2867
|
-
if (buffer) parts.push(buffer);
|
|
2868
|
-
};
|
|
2869
|
-
for (const char of value) {
|
|
2870
|
-
const isSplitter = REGEX_SEPARATORS.test(char);
|
|
2871
|
-
REGEX_SEPARATORS.lastIndex = 0;
|
|
2872
|
-
if (isSplitter) {
|
|
2873
|
-
flush();
|
|
2874
|
-
buffer = "";
|
|
2875
|
-
previousUpper = void 0;
|
|
2876
|
-
previousSplitter = true;
|
|
2877
|
-
continue;
|
|
2878
|
-
}
|
|
2879
|
-
const isUpper = isUppercase(char);
|
|
2880
|
-
const boundary = previousSplitter === false ? caseBoundary(previousUpper, isUpper, buffer) : void 0;
|
|
2881
|
-
if (boundary === "before") {
|
|
2882
|
-
flush();
|
|
2883
|
-
buffer = char;
|
|
2884
|
-
} else if (boundary === "after") {
|
|
2885
|
-
parts.push(buffer.slice(0, -1));
|
|
2886
|
-
buffer = buffer.at(-1) + char;
|
|
2887
|
-
} else buffer += char;
|
|
2888
|
-
previousUpper = isUpper;
|
|
2889
|
-
previousSplitter = false;
|
|
2890
|
-
}
|
|
2891
|
-
flush();
|
|
2892
|
-
return parts;
|
|
2893
|
-
}
|
|
2894
|
-
function kebabCaseSegments(segments) {
|
|
2895
|
-
return segments.map((segment) => segment.toLowerCase()).join("-").replace(REGEX_NON_ALPHANUMERIC, "-").replace(REGEX_REPEATED_DASH, "-").replace(REGEX_EDGE_DASH, "");
|
|
2896
|
-
}
|
|
2897
|
-
function resolveLayoutNameSegments(fileName, prefixParts) {
|
|
2898
|
-
const fileNameParts = splitByCase(fileName);
|
|
2899
|
-
const fileNamePartsContent = fileNameParts.join("/").toLowerCase();
|
|
2900
|
-
const layoutNameParts = prefixParts.flatMap((part) => splitByCase(part));
|
|
2901
|
-
const matchedSuffix = [];
|
|
2902
|
-
let index = prefixParts.length - 1;
|
|
2903
|
-
while (index >= 0) {
|
|
2904
|
-
const prefixPart = prefixParts[index];
|
|
2905
|
-
matchedSuffix.unshift(...splitByCase(prefixPart).map((part) => part.toLowerCase()));
|
|
2906
|
-
const matchedSuffixContent = matchedSuffix.join("/");
|
|
2907
|
-
if (fileNamePartsContent === matchedSuffixContent || fileNamePartsContent.startsWith(`${matchedSuffixContent}/`) || prefixPart.toLowerCase() === fileNamePartsContent && prefixParts[index + 1] && prefixParts[index] === prefixParts[index + 1]) layoutNameParts.length = index;
|
|
2908
|
-
index -= 1;
|
|
2909
|
-
}
|
|
2910
|
-
return [...layoutNameParts, ...fileNameParts];
|
|
2911
|
-
}
|
|
2912
|
-
function normalizeLayoutName(file) {
|
|
2913
|
-
const normalizedFile = file.replace(REGEX_BACKSLASH$1, "/");
|
|
2914
|
-
const slashIndex = normalizedFile.lastIndexOf("/");
|
|
2915
|
-
const dir = slashIndex === -1 ? "" : normalizedFile.slice(0, slashIndex);
|
|
2916
|
-
const basename = slashIndex === -1 ? normalizedFile : normalizedFile.slice(slashIndex + 1);
|
|
2917
|
-
const dotIndex = basename.lastIndexOf(".");
|
|
2918
|
-
const name = dotIndex <= 0 ? basename : basename.slice(0, dotIndex);
|
|
2919
|
-
const prefixParts = splitByCase(dir);
|
|
2920
|
-
return kebabCaseSegments(resolveLayoutNameSegments(dir && name.toLowerCase() === "index" ? "" : name, prefixParts).filter(Boolean));
|
|
2921
|
-
}
|
|
2922
|
-
|
|
2923
|
-
const RUNTIME_ID = "valaxy/vendor/layouts/runtime.mjs";
|
|
2924
|
-
function getClientCode(importCode, options) {
|
|
2925
|
-
const inheritDefaultLayout = options.inheritDefaultLayout ?? true;
|
|
2926
|
-
const fallbackArg = options.fallbackLayout ? `, '${options.fallbackLayout}'` : "";
|
|
2927
|
-
return `
|
|
2928
|
-
import { createGetRoutes, createLayoutWrapper, createSetupLayouts, lazyLayout, setPageLayout, useLayout } from '${RUNTIME_ID}'
|
|
2929
|
-
export { createGetRoutes, setPageLayout, useLayout }
|
|
2930
|
-
${importCode}
|
|
2931
|
-
const LayoutWrapper = createLayoutWrapper(layouts, '${options.defaultLayout}'${fallbackArg})
|
|
2932
|
-
export const setupLayouts = createSetupLayouts(LayoutWrapper, { inheritDefaultLayout: ${inheritDefaultLayout} })
|
|
2933
|
-
`;
|
|
2934
|
-
}
|
|
2935
|
-
function normalizePath$1(path) {
|
|
2936
|
-
path = path.startsWith("/") ? path : `/${path}`;
|
|
2937
|
-
return posix.normalize(path);
|
|
2938
|
-
}
|
|
2939
|
-
async function createVirtualModuleCode(options) {
|
|
2940
|
-
const { layoutDir, defaultLayout, fallbackLayout, importMode, inheritDefaultLayout = true } = options;
|
|
2941
|
-
const normalizedTarget = normalizePath$1(layoutDir);
|
|
2942
|
-
const isSync = importMode === "sync";
|
|
2943
|
-
const fallbackArg = fallbackLayout ? `, '${fallbackLayout}'` : "";
|
|
2944
|
-
return `
|
|
2945
|
-
import { createGetRoutes, createLayoutWrapper, createSetupLayouts, lazyLayout, normalizeLayoutName, setPageLayout, useLayout } from '${RUNTIME_ID}'
|
|
2946
|
-
export { createGetRoutes, setPageLayout, useLayout }
|
|
2947
|
-
|
|
2948
|
-
const modules = import.meta.glob("${normalizedTarget}/**/*.vue", { eager: ${isSync} })
|
|
2949
|
-
|
|
2950
|
-
export const layouts = {}
|
|
2951
|
-
Object.entries(modules).forEach(([name, module]) => {
|
|
2952
|
-
const key = normalizeLayoutName(name.replace("${normalizedTarget}/", ''))
|
|
2953
|
-
layouts[key] = ${isSync ? "module.default" : "lazyLayout(module)"}
|
|
2954
|
-
})
|
|
2955
|
-
|
|
2956
|
-
const LayoutWrapper = createLayoutWrapper(layouts, '${defaultLayout}'${fallbackArg})
|
|
2957
|
-
export const setupLayouts = createSetupLayouts(LayoutWrapper, { inheritDefaultLayout: ${inheritDefaultLayout} })
|
|
2958
|
-
`;
|
|
2959
|
-
}
|
|
2960
|
-
const REGEX_BACKSLASH = /\\/g;
|
|
2961
|
-
function extensionsToGlob(extensions) {
|
|
2962
|
-
return extensions.length > 1 ? `{${extensions.join(",")}}` : extensions[0] || "";
|
|
2963
|
-
}
|
|
2964
|
-
function normalizePath$2(str) {
|
|
2965
|
-
return str.replace(REGEX_BACKSLASH, "/");
|
|
2966
|
-
}
|
|
2967
|
-
const debug$6 = createDebug("vite-plugin-layouts-next");
|
|
2968
|
-
function resolveDirs(dirs, root) {
|
|
2969
|
-
if (dirs === null) return [];
|
|
2970
|
-
const dirsArray = Array.isArray(dirs) ? dirs : [dirs];
|
|
2971
|
-
const dirsResolved = [];
|
|
2972
|
-
for (const dir of dirsArray) if (dir.includes("**")) {
|
|
2973
|
-
const matches = globSync(dir, { cwd: root, onlyDirectories: true });
|
|
2974
|
-
for (const match of matches) dirsResolved.push(normalizePath$2(resolve(root, match)));
|
|
2975
|
-
} else dirsResolved.push(normalizePath$2(resolve(root, dir)));
|
|
2976
|
-
return dirsResolved;
|
|
2977
|
-
}
|
|
2978
|
-
async function getFilesFromPath(path, options) {
|
|
2979
|
-
const { exclude, extensions } = options;
|
|
2980
|
-
const ext = extensionsToGlob(extensions);
|
|
2981
|
-
debug$6(extensions);
|
|
2982
|
-
return await glob(`**/*.${ext}`, {
|
|
2983
|
-
ignore: [
|
|
2984
|
-
"node_modules",
|
|
2985
|
-
".git",
|
|
2986
|
-
"**/__*__/*",
|
|
2987
|
-
...exclude
|
|
2988
|
-
],
|
|
2989
|
-
onlyFiles: true,
|
|
2990
|
-
cwd: path
|
|
2991
|
-
});
|
|
2992
|
-
}
|
|
2993
|
-
function getImportCode(files, options) {
|
|
2994
|
-
const imports = [];
|
|
2995
|
-
const head = [];
|
|
2996
|
-
let id = 0;
|
|
2997
|
-
for (const __ of files) for (const file of __.files) {
|
|
2998
|
-
const path = __.path.startsWith("/") ? `${__.path}/${file}` : `/${__.path}/${file}`;
|
|
2999
|
-
const name = normalizeLayoutName(file);
|
|
3000
|
-
if (options.importMode(name) === "sync") {
|
|
3001
|
-
const variable = `__layout_${id}`;
|
|
3002
|
-
head.push(`import ${variable} from '${path}'`);
|
|
3003
|
-
imports.push(`'${name}': ${variable},`);
|
|
3004
|
-
id += 1;
|
|
3005
|
-
} else imports.push(`'${name}': lazyLayout(() => import('${path}')),`);
|
|
3006
|
-
}
|
|
3007
|
-
return `
|
|
3008
|
-
${head.join("\n")}
|
|
3009
|
-
export const layouts = {
|
|
3010
|
-
${imports.join("\n")}
|
|
3011
|
-
}`;
|
|
3012
|
-
}
|
|
3013
|
-
const MODULE_ID = "virtual:generated-layouts";
|
|
3014
|
-
const MODULE_ID_VIRTUAL = "/@vite-plugin-vue-layouts-next/generated-layouts";
|
|
3015
|
-
function defaultImportMode(name) {
|
|
3016
|
-
if (process$1.env.VITE_SSG) return "sync";
|
|
3017
|
-
return name === "default" ? "sync" : "async";
|
|
3018
|
-
}
|
|
3019
|
-
function resolveOptions$1(userOptions) {
|
|
3020
|
-
return {
|
|
3021
|
-
defaultLayout: "default",
|
|
3022
|
-
layoutsDirs: "src/layouts",
|
|
3023
|
-
extensions: ["vue"],
|
|
3024
|
-
exclude: [],
|
|
3025
|
-
importMode: defaultImportMode,
|
|
3026
|
-
inheritDefaultLayout: true,
|
|
3027
|
-
...userOptions
|
|
3028
|
-
};
|
|
3029
|
-
}
|
|
3030
|
-
function Layout(userOptions = {}) {
|
|
3031
|
-
if (canEnableClientLayout(userOptions)) return ClientSideLayout({
|
|
3032
|
-
defaultLayout: userOptions.defaultLayout,
|
|
3033
|
-
fallbackLayout: userOptions.fallbackLayout,
|
|
3034
|
-
layoutsDirs: userOptions.layoutsDirs,
|
|
3035
|
-
inheritDefaultLayout: userOptions.inheritDefaultLayout
|
|
3036
|
-
});
|
|
3037
|
-
let config;
|
|
3038
|
-
const options = resolveOptions$1(userOptions);
|
|
3039
|
-
let layoutsDirs;
|
|
3040
|
-
return {
|
|
3041
|
-
name: "vite-plugin-vue-layouts-next",
|
|
3042
|
-
enforce: "pre",
|
|
3043
|
-
config() {
|
|
3044
|
-
return { optimizeDeps: { include: [RUNTIME_ID] } };
|
|
3045
|
-
},
|
|
3046
|
-
configResolved(_config) {
|
|
3047
|
-
config = _config;
|
|
3048
|
-
layoutsDirs = resolveDirs(options.layoutsDirs, config.root);
|
|
3049
|
-
},
|
|
3050
|
-
configureServer({ moduleGraph, watcher, ws }) {
|
|
3051
|
-
watcher.add(options.layoutsDirs);
|
|
3052
|
-
const reloadModule = (module, path = "*") => {
|
|
3053
|
-
if (module) {
|
|
3054
|
-
moduleGraph.invalidateModule(module);
|
|
3055
|
-
if (ws) ws.send({
|
|
3056
|
-
path,
|
|
3057
|
-
type: "full-reload"
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
};
|
|
3061
|
-
const updateVirtualModule = (path) => {
|
|
3062
|
-
path = normalizePath$2(path);
|
|
3063
|
-
if (layoutsDirs.some((dir) => path.startsWith(dir))) {
|
|
3064
|
-
debug$6("reload", path);
|
|
3065
|
-
const module = moduleGraph.getModuleById(MODULE_ID_VIRTUAL);
|
|
3066
|
-
reloadModule(module);
|
|
3067
|
-
}
|
|
3068
|
-
};
|
|
3069
|
-
watcher.on("add", (path) => {
|
|
3070
|
-
updateVirtualModule(path);
|
|
3071
|
-
});
|
|
3072
|
-
watcher.on("unlink", (path) => {
|
|
3073
|
-
updateVirtualModule(path);
|
|
3074
|
-
});
|
|
3075
|
-
watcher.on("change", async (path) => {
|
|
3076
|
-
updateVirtualModule(path);
|
|
3077
|
-
});
|
|
3078
|
-
},
|
|
3079
|
-
resolveId(id) {
|
|
3080
|
-
return id === MODULE_ID || id.startsWith(MODULE_ID) ? MODULE_ID_VIRTUAL : null;
|
|
3081
|
-
},
|
|
3082
|
-
async load(id) {
|
|
3083
|
-
if (id === MODULE_ID_VIRTUAL) {
|
|
3084
|
-
const container = [];
|
|
3085
|
-
for (const dir of layoutsDirs) {
|
|
3086
|
-
const layoutsDirPath = dir.startsWith("/") ? normalizePath$2(dir) : normalizePath$2(resolve(config.root, dir));
|
|
3087
|
-
debug$6("Loading Layout Dir: %O", layoutsDirPath);
|
|
3088
|
-
const _f = await getFilesFromPath(layoutsDirPath, options);
|
|
3089
|
-
container.push({
|
|
3090
|
-
path: layoutsDirPath,
|
|
3091
|
-
files: _f
|
|
3092
|
-
});
|
|
3093
|
-
}
|
|
3094
|
-
const clientCode = getClientCode(getImportCode(container, options), options);
|
|
3095
|
-
debug$6("Client code: %O", clientCode);
|
|
3096
|
-
return {
|
|
3097
|
-
code: clientCode,
|
|
3098
|
-
moduleType: "js"
|
|
3099
|
-
};
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
};
|
|
3103
|
-
}
|
|
3104
|
-
function ClientSideLayout(options) {
|
|
3105
|
-
const { layoutsDirs, layoutDir: legacyLayoutDir, defaultLayout = "default", fallbackLayout, importMode = process$1.env.VITE_SSG ? "sync" : "async", inheritDefaultLayout = true } = options || {};
|
|
3106
|
-
const layoutDir = layoutsDirs ?? legacyLayoutDir ?? "src/layouts";
|
|
3107
|
-
return {
|
|
3108
|
-
name: "vite-plugin-vue-layouts-next",
|
|
3109
|
-
config() {
|
|
3110
|
-
return { optimizeDeps: { include: [RUNTIME_ID] } };
|
|
3111
|
-
},
|
|
3112
|
-
resolveId(id) {
|
|
3113
|
-
if (id === MODULE_ID) return `\0${MODULE_ID}`;
|
|
3114
|
-
},
|
|
3115
|
-
async load(id) {
|
|
3116
|
-
if (id === `\0${MODULE_ID}`) return {
|
|
3117
|
-
code: await createVirtualModuleCode({
|
|
3118
|
-
layoutDir,
|
|
3119
|
-
importMode,
|
|
3120
|
-
defaultLayout,
|
|
3121
|
-
fallbackLayout,
|
|
3122
|
-
inheritDefaultLayout
|
|
3123
|
-
}),
|
|
3124
|
-
moduleType: "js"
|
|
3125
|
-
};
|
|
3126
|
-
}
|
|
3127
|
-
};
|
|
3128
|
-
}
|
|
3129
|
-
function canEnableClientLayout(options) {
|
|
3130
|
-
const keys = Object.keys(options);
|
|
3131
|
-
if (keys.length > 4 || keys.some((key) => ![
|
|
3132
|
-
"layoutsDirs",
|
|
3133
|
-
"defaultLayout",
|
|
3134
|
-
"fallbackLayout",
|
|
3135
|
-
"inheritDefaultLayout"
|
|
3136
|
-
].includes(key))) return false;
|
|
3137
|
-
if (options.layoutsDirs && (Array.isArray(options.layoutsDirs) || options.layoutsDirs.includes("*"))) return false;
|
|
3138
|
-
return true;
|
|
3139
|
-
}
|
|
3140
|
-
|
|
3141
3073
|
function isLoopback(address = "") {
|
|
3142
3074
|
return address === "::1" || /^(?:::ffff:)?127(?:\.\d{1,3}){3}$/.test(address);
|
|
3143
3075
|
}
|
|
@@ -3301,7 +3233,7 @@ class EditorRoutes {
|
|
|
3301
3233
|
}
|
|
3302
3234
|
}
|
|
3303
3235
|
|
|
3304
|
-
const debug$
|
|
3236
|
+
const debug$2 = _debug("valaxy:group-icons");
|
|
3305
3237
|
const codeBlockTitleRE = /^[ \t]{0,3}`{3}[^\n[]*\[((?:[^[\]]|\[[^[\]]*\])*)\]/gm;
|
|
3306
3238
|
async function scanCodeBlockTitles(options) {
|
|
3307
3239
|
const titles = /* @__PURE__ */ new Set();
|
|
@@ -3315,7 +3247,7 @@ async function scanCodeBlockTitles(options) {
|
|
|
3315
3247
|
const content = await readFile(file, "utf-8");
|
|
3316
3248
|
extractCodeBlockTitles(content, titles);
|
|
3317
3249
|
} catch (error) {
|
|
3318
|
-
debug$
|
|
3250
|
+
debug$2("Failed to read %s: %O", page, error);
|
|
3319
3251
|
}
|
|
3320
3252
|
},
|
|
3321
3253
|
{ concurrency: 64 }
|
|
@@ -3820,1368 +3752,215 @@ async function getAlias(options) {
|
|
|
3820
3752
|
return alias;
|
|
3821
3753
|
}
|
|
3822
3754
|
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
let onlyLocales = [];
|
|
3830
|
-
if (options.onlyLocales) {
|
|
3831
|
-
onlyLocales = isArray(options.onlyLocales) ? options.onlyLocales : [options.onlyLocales];
|
|
3832
|
-
}
|
|
3833
|
-
const forceStringify = !!options.forceStringify;
|
|
3834
|
-
const defaultSFCLang = isString(options.defaultSFCLang) ? options.defaultSFCLang : "json";
|
|
3835
|
-
const globalSFCScope = !!options.globalSFCScope;
|
|
3836
|
-
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
3837
|
-
const dropMessageCompiler = !!options.dropMessageCompiler;
|
|
3838
|
-
const compositionOnly = moduleType === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
3839
|
-
const fullInstall = moduleType === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
3840
|
-
const ssrBuild = !!options.ssr;
|
|
3841
|
-
const allowDynamic = !!options.allowDynamic;
|
|
3842
|
-
const strictMessage = isBoolean(options.strictMessage) ? options.strictMessage : true;
|
|
3843
|
-
const escapeHtml = !!options.escapeHtml;
|
|
3844
|
-
const optimizeTranslationDirective = isString(options.optimizeTranslationDirective) || isArray(options.optimizeTranslationDirective) ? options.optimizeTranslationDirective : !!options.optimizeTranslationDirective;
|
|
3845
|
-
const translationIdentifiers = /* @__PURE__ */ new Map();
|
|
3846
|
-
const transformI18nBlock = typeof options.transformI18nBlock === "function" ? options.transformI18nBlock : null;
|
|
3847
|
-
const treeShaking = options.treeShaking ? typeof options.treeShaking === "object" ? {
|
|
3848
|
-
safelist: options.treeShaking.safelist || [],
|
|
3849
|
-
dynamicKeyStrategy: options.treeShaking.dynamicKeyStrategy || "keep-all",
|
|
3850
|
-
scanPatterns: options.treeShaking.scanPatterns
|
|
3851
|
-
} : { safelist: [], dynamicKeyStrategy: "keep-all" } : null;
|
|
3852
|
-
return {
|
|
3853
|
-
include: normalizeGlobOption(options.include || []),
|
|
3854
|
-
exclude: normalizeGlobOption(options.exclude),
|
|
3855
|
-
module: moduleType,
|
|
3856
|
-
onlyLocales,
|
|
3857
|
-
forceStringify,
|
|
3858
|
-
defaultSFCLang,
|
|
3859
|
-
globalSFCScope,
|
|
3860
|
-
runtimeOnly,
|
|
3861
|
-
dropMessageCompiler,
|
|
3862
|
-
compositionOnly,
|
|
3863
|
-
fullInstall,
|
|
3864
|
-
ssrBuild,
|
|
3865
|
-
allowDynamic,
|
|
3866
|
-
strictMessage,
|
|
3867
|
-
escapeHtml,
|
|
3868
|
-
optimizeTranslationDirective,
|
|
3869
|
-
translationIdentifiers,
|
|
3870
|
-
transformI18nBlock,
|
|
3871
|
-
treeShaking
|
|
3872
|
-
};
|
|
3873
|
-
}
|
|
3874
|
-
const PKG_NAME = "unplugin-vue-i18n";
|
|
3875
|
-
function warn(...args) {
|
|
3876
|
-
console.warn(pc.yellow(pc.bold(`[${PKG_NAME}] `)), ...args);
|
|
3877
|
-
}
|
|
3878
|
-
function error(...args) {
|
|
3879
|
-
console.error(pc.red(pc.bold(`[${PKG_NAME}] `)), ...args);
|
|
3880
|
-
}
|
|
3881
|
-
function raiseError(message) {
|
|
3882
|
-
throw new Error(`[${PKG_NAME}] ${message}`);
|
|
3883
|
-
}
|
|
3884
|
-
function resolveNamespace(name) {
|
|
3885
|
-
return `${PKG_NAME}:${name}`;
|
|
3886
|
-
}
|
|
3887
|
-
function getVitePlugin(config, name) {
|
|
3888
|
-
return config.plugins.find((p) => p.name === name);
|
|
3889
|
-
}
|
|
3890
|
-
function checkVuePlugin(vuePlugin) {
|
|
3891
|
-
if (vuePlugin == null || !vuePlugin.api) {
|
|
3892
|
-
error(
|
|
3893
|
-
"`@vitejs/plugin-vue` plugin is not found or invalid version. Please install `@vitejs/plugin-vue` v4.3.4 or later version."
|
|
3894
|
-
);
|
|
3895
|
-
return false;
|
|
3896
|
-
}
|
|
3897
|
-
return true;
|
|
3898
|
-
}
|
|
3899
|
-
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
3900
|
-
const windowsSlashRE = /\\/g;
|
|
3901
|
-
function slash(p) {
|
|
3902
|
-
return p.replace(windowsSlashRE, "/");
|
|
3903
|
-
}
|
|
3904
|
-
function normalizePath(id) {
|
|
3905
|
-
return path.posix.normalize(isWindows ? slash(id) : id);
|
|
3906
|
-
}
|
|
3907
|
-
function parseVueRequest(id) {
|
|
3908
|
-
const [filename, rawQuery] = id.split(`?`, 2);
|
|
3909
|
-
const params = new URLSearchParams(rawQuery);
|
|
3910
|
-
const ret = {};
|
|
3911
|
-
const langPart = Object.keys(Object.fromEntries(params)).find((key) => /lang\./i.test(key));
|
|
3912
|
-
ret.vue = params.has("vue");
|
|
3913
|
-
ret.global = params.has("global");
|
|
3914
|
-
ret.src = params.has("src");
|
|
3915
|
-
ret.raw = params.has("raw");
|
|
3916
|
-
if (params.has("type")) {
|
|
3917
|
-
ret.type = params.get("type");
|
|
3918
|
-
}
|
|
3919
|
-
if (params.has("blockType")) {
|
|
3920
|
-
ret.blockType = params.get("blockType");
|
|
3921
|
-
}
|
|
3922
|
-
if (params.has("index")) {
|
|
3923
|
-
ret.index = Number(params.get("index"));
|
|
3924
|
-
}
|
|
3925
|
-
if (params.has("locale")) {
|
|
3926
|
-
ret.locale = params.get("locale");
|
|
3927
|
-
}
|
|
3928
|
-
if (langPart) {
|
|
3929
|
-
const [, lang] = langPart.split(".");
|
|
3930
|
-
ret.lang = lang;
|
|
3931
|
-
} else if (params.has("lang")) {
|
|
3932
|
-
ret.lang = params.get("lang");
|
|
3933
|
-
}
|
|
3934
|
-
if (params.has("issuerPath")) {
|
|
3935
|
-
ret.issuerPath = params.get("issuerPath");
|
|
3936
|
-
}
|
|
3937
|
-
return {
|
|
3938
|
-
filename,
|
|
3939
|
-
query: ret
|
|
3940
|
-
};
|
|
3941
|
-
}
|
|
3942
|
-
function getVueCompiler(vuePlugin) {
|
|
3943
|
-
return vuePlugin?.api?.options.compiler;
|
|
3944
|
-
}
|
|
3945
|
-
function getVuePluginOptions(vuePlugin) {
|
|
3946
|
-
return {
|
|
3947
|
-
isProduction: vuePlugin?.api?.options.isProduction,
|
|
3948
|
-
root: vuePlugin?.api?.options.root,
|
|
3949
|
-
template: vuePlugin?.api?.options.template,
|
|
3950
|
-
compiler: vuePlugin?.api?.options.compiler
|
|
3951
|
-
};
|
|
3952
|
-
}
|
|
3953
|
-
function createDescriptor(filename, source, { template, compiler }) {
|
|
3954
|
-
const { descriptor, errors } = compiler.parse(source, {
|
|
3955
|
-
filename,
|
|
3956
|
-
templateParseOptions: template?.compilerOptions
|
|
3957
|
-
});
|
|
3958
|
-
return { descriptor, errors };
|
|
3959
|
-
}
|
|
3960
|
-
function getDescriptor(filename, code, options) {
|
|
3961
|
-
const { descriptor, errors } = createDescriptor(filename, code, options);
|
|
3962
|
-
if (errors.length) {
|
|
3963
|
-
throw errors[0];
|
|
3964
|
-
}
|
|
3965
|
-
return descriptor;
|
|
3966
|
-
}
|
|
3967
|
-
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
3968
|
-
const VIRTUAL_PREFIX = "virtual:";
|
|
3969
|
-
const RE_RESOURCE_FORMAT = /\.(json5?|ya?ml|[c|m]?[j|t]s)$/;
|
|
3970
|
-
const RE_SFC_I18N_CUSTOM_BLOCK = /\?vue&type=i18n/;
|
|
3971
|
-
const RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK = /blockType=i18n/;
|
|
3972
|
-
const VITE_VIRTUAL_PREFIX = "virtual:intlify-i18n-";
|
|
3973
|
-
const debug$3 = createDebug(resolveNamespace("resource"));
|
|
3974
|
-
function resourcePlugin({
|
|
3975
|
-
onlyLocales,
|
|
3976
|
-
include,
|
|
3977
|
-
exclude,
|
|
3978
|
-
module,
|
|
3979
|
-
forceStringify,
|
|
3980
|
-
defaultSFCLang,
|
|
3981
|
-
globalSFCScope,
|
|
3982
|
-
runtimeOnly,
|
|
3983
|
-
dropMessageCompiler,
|
|
3984
|
-
compositionOnly,
|
|
3985
|
-
fullInstall,
|
|
3986
|
-
ssrBuild,
|
|
3987
|
-
strictMessage,
|
|
3988
|
-
allowDynamic,
|
|
3989
|
-
escapeHtml,
|
|
3990
|
-
transformI18nBlock
|
|
3991
|
-
}, meta, collector) {
|
|
3992
|
-
function resolveIncludeExclude() {
|
|
3993
|
-
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
3994
|
-
return include ? [[...include, customBlockInclude], exclude] : [[RE_RESOURCE_FORMAT, customBlockInclude], exclude];
|
|
3995
|
-
}
|
|
3996
|
-
function resolveIncludeExcludeForLegacy() {
|
|
3997
|
-
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
3998
|
-
return include ? [[...include, customBlockInclude], void 0] : [void 0, ["**/**"]];
|
|
3999
|
-
}
|
|
4000
|
-
let _filter = null;
|
|
4001
|
-
async function getFilter() {
|
|
4002
|
-
if (_filter != null) {
|
|
4003
|
-
return _filter;
|
|
4004
|
-
}
|
|
4005
|
-
if (meta.framework == "webpack") {
|
|
4006
|
-
debug$3("Using filter for webpack");
|
|
4007
|
-
_filter = createFilter$1(...resolveIncludeExclude());
|
|
4008
|
-
} else if (hasViteJsonPlugin) {
|
|
4009
|
-
debug$3("Using filter for rollup-vite");
|
|
4010
|
-
_filter = createFilter$1(...resolveIncludeExcludeForLegacy());
|
|
4011
|
-
} else {
|
|
4012
|
-
debug$3("Using filter for rolldown-vite");
|
|
4013
|
-
_filter = createFilter$1(...resolveIncludeExclude());
|
|
4014
|
-
}
|
|
4015
|
-
return _filter;
|
|
4016
|
-
}
|
|
4017
|
-
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
|
|
4018
|
-
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
|
|
4019
|
-
};
|
|
4020
|
-
let isProduction = false;
|
|
4021
|
-
let sourceMap = false;
|
|
4022
|
-
let hasViteJsonPlugin = false;
|
|
4023
|
-
const vueI18nAliasName = module;
|
|
4024
|
-
debug$3(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
4025
|
-
let vuePlugin = null;
|
|
4026
|
-
const getSfcParser = () => {
|
|
4027
|
-
return vuePlugin ? getVueCompiler(vuePlugin).parse : parse$2;
|
|
4028
|
-
};
|
|
4029
|
-
const virtualIdToRealPath = /* @__PURE__ */ new Map();
|
|
4030
|
-
const realPathToVirtualId = /* @__PURE__ */ new Map();
|
|
4031
|
-
let virtualCounter = 0;
|
|
4032
|
-
function intlifyVirtualize(realPath) {
|
|
4033
|
-
const normalized = normalize(realPath);
|
|
4034
|
-
let virtualId = realPathToVirtualId.get(normalized);
|
|
4035
|
-
if (!virtualId) {
|
|
4036
|
-
virtualId = `${VITE_VIRTUAL_PREFIX}${virtualCounter++}`;
|
|
4037
|
-
virtualIdToRealPath.set(virtualId, normalized);
|
|
4038
|
-
realPathToVirtualId.set(normalized, virtualId);
|
|
4039
|
-
}
|
|
4040
|
-
return virtualId;
|
|
4041
|
-
}
|
|
4042
|
-
function isIntlifyVirtualId(id) {
|
|
4043
|
-
return virtualIdToRealPath.has(id);
|
|
4044
|
-
}
|
|
4045
|
-
return {
|
|
4046
|
-
name: resolveNamespace("resource"),
|
|
4047
|
-
/**
|
|
4048
|
-
* NOTE:
|
|
4049
|
-
*
|
|
4050
|
-
* For vite, If we have json (including SFC's custom block),
|
|
4051
|
-
* transform it first because it will be transformed into javascript code by `vite:json` plugin.
|
|
4052
|
-
*
|
|
4053
|
-
* For webpack, This plugin will handle with 'post', because vue-loader generate the request query.
|
|
4054
|
-
*/
|
|
4055
|
-
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
4056
|
-
vite: {
|
|
4057
|
-
config() {
|
|
4058
|
-
const defineConfig = {
|
|
4059
|
-
define: {
|
|
4060
|
-
__VUE_I18N_LEGACY_API__: !compositionOnly,
|
|
4061
|
-
__VUE_I18N_FULL_INSTALL__: fullInstall,
|
|
4062
|
-
__INTLIFY_DROP_MESSAGE_COMPILER__: dropMessageCompiler,
|
|
4063
|
-
__VUE_I18N_PROD_DEVTOOLS__: false
|
|
4064
|
-
}
|
|
4065
|
-
};
|
|
4066
|
-
debug$3("define Config:", defineConfig);
|
|
4067
|
-
const aliasConfig = {
|
|
4068
|
-
resolve: {
|
|
4069
|
-
alias: {
|
|
4070
|
-
[vueI18nAliasName]: getVueI18nAliasPath({
|
|
4071
|
-
ssr: ssrBuild,
|
|
4072
|
-
runtimeOnly
|
|
4073
|
-
})
|
|
4074
|
-
}
|
|
4075
|
-
}
|
|
4076
|
-
};
|
|
4077
|
-
debug$3("alias Config:", aliasConfig);
|
|
4078
|
-
return assign(defineConfig, aliasConfig);
|
|
4079
|
-
},
|
|
4080
|
-
async configResolved(config) {
|
|
4081
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
4082
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
4083
|
-
return;
|
|
4084
|
-
}
|
|
4085
|
-
isProduction = config.isProduction;
|
|
4086
|
-
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
4087
|
-
debug$3(`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
4088
|
-
const jsonPlugin = getVitePlugin(config, "vite:json");
|
|
4089
|
-
hasViteJsonPlugin = !!jsonPlugin;
|
|
4090
|
-
if (jsonPlugin && jsonPlugin.transform) {
|
|
4091
|
-
const transform = jsonPlugin.transform;
|
|
4092
|
-
const isObjectHook = typeof transform !== "function" && "handler" in transform;
|
|
4093
|
-
const orgTransform = isObjectHook ? transform.handler : transform;
|
|
4094
|
-
async function overrideJson(code, id) {
|
|
4095
|
-
const filter = await getFilter();
|
|
4096
|
-
if (!/\.json$/.test(id) || filter(id)) {
|
|
4097
|
-
return;
|
|
4098
|
-
}
|
|
4099
|
-
const { query } = parseVueRequest(id);
|
|
4100
|
-
if (query.vue) {
|
|
4101
|
-
return;
|
|
4102
|
-
}
|
|
4103
|
-
debug$3("org json plugin");
|
|
4104
|
-
return orgTransform.apply(this, [code, id]);
|
|
4105
|
-
}
|
|
4106
|
-
if (isObjectHook) {
|
|
4107
|
-
transform.handler = overrideJson;
|
|
4108
|
-
} else {
|
|
4109
|
-
jsonPlugin.transform = overrideJson;
|
|
4110
|
-
}
|
|
4111
|
-
}
|
|
4112
|
-
},
|
|
4113
|
-
handleHotUpdate({ file, modules, server }) {
|
|
4114
|
-
const key = normalize(file);
|
|
4115
|
-
const virtualId = realPathToVirtualId.get(key);
|
|
4116
|
-
const inBundle = !!(include && createFilter$1(include, exclude)(key));
|
|
4117
|
-
if (!virtualId && !inBundle) return;
|
|
4118
|
-
const affected = new Set(modules);
|
|
4119
|
-
const addById = (id) => {
|
|
4120
|
-
const mod = id && server.moduleGraph.getModuleById(id);
|
|
4121
|
-
if (mod) affected.add(mod);
|
|
4122
|
-
};
|
|
4123
|
-
addById(virtualId);
|
|
4124
|
-
if (inBundle) {
|
|
4125
|
-
addById(asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework));
|
|
4126
|
-
}
|
|
4127
|
-
if (affected.size === modules.length) return;
|
|
4128
|
-
return [...affected];
|
|
4129
|
-
}
|
|
4130
|
-
},
|
|
4131
|
-
webpack(compiler) {
|
|
4132
|
-
isProduction = compiler.options.mode !== "development";
|
|
4133
|
-
sourceMap = !!compiler.options.devtool;
|
|
4134
|
-
debug$3(`webpack: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
4135
|
-
compiler.options.resolve = normalizeConfigResolveAlias(
|
|
4136
|
-
compiler.options.resolve,
|
|
4137
|
-
meta.framework
|
|
4138
|
-
);
|
|
4139
|
-
compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath({
|
|
4140
|
-
ssr: ssrBuild,
|
|
4141
|
-
runtimeOnly
|
|
4142
|
-
});
|
|
4143
|
-
debug$3(
|
|
4144
|
-
`set ${vueI18nAliasName}: ${getVueI18nAliasPath({
|
|
4145
|
-
ssr: ssrBuild,
|
|
4146
|
-
runtimeOnly
|
|
4147
|
-
})}`
|
|
4148
|
-
);
|
|
4149
|
-
compiler.options.plugins.push(
|
|
4150
|
-
new compiler.webpack.DefinePlugin({
|
|
4151
|
-
__VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
|
|
4152
|
-
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
4153
|
-
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
4154
|
-
})
|
|
4155
|
-
);
|
|
4156
|
-
debug$3(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
4157
|
-
debug$3(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
4158
|
-
const filter = createFilter$1(...resolveIncludeExclude());
|
|
4159
|
-
if (compiler.options.module) {
|
|
4160
|
-
compiler.options.module.rules.push({
|
|
4161
|
-
test: RE_RESOURCE_FORMAT,
|
|
4162
|
-
type: "javascript/auto",
|
|
4163
|
-
include(resource) {
|
|
4164
|
-
debug$3("webpack resource include", resource);
|
|
4165
|
-
return filter(resource);
|
|
4166
|
-
}
|
|
4167
|
-
});
|
|
4168
|
-
}
|
|
4169
|
-
},
|
|
4170
|
-
resolveId: {
|
|
4171
|
-
async handler(id, importer) {
|
|
4172
|
-
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
4173
|
-
return asVirtualId(id, meta.framework);
|
|
4174
|
-
}
|
|
4175
|
-
if (meta.framework === "vite" && !hasViteJsonPlugin) {
|
|
4176
|
-
if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
|
|
4177
|
-
const { filename, query } = parseVueRequest(id);
|
|
4178
|
-
let virtualKey = id;
|
|
4179
|
-
if (query.src && importer) {
|
|
4180
|
-
const importerPath = (isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer).split("?")[0];
|
|
4181
|
-
if (importerPath.endsWith(".vue")) {
|
|
4182
|
-
const resolvedSidecar = resolve$1(dirname$1(importerPath), filename);
|
|
4183
|
-
virtualKey = id.replace(filename, resolvedSidecar);
|
|
4184
|
-
}
|
|
4185
|
-
}
|
|
4186
|
-
return intlifyVirtualize(virtualKey);
|
|
4187
|
-
}
|
|
4188
|
-
const idPath = id.split("?")[0];
|
|
4189
|
-
if (!RE_RESOURCE_FORMAT.test(idPath)) return;
|
|
4190
|
-
let resolvedPath;
|
|
4191
|
-
if (idPath.startsWith(".")) {
|
|
4192
|
-
const realImporter = importer && isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer;
|
|
4193
|
-
if (!realImporter) return;
|
|
4194
|
-
resolvedPath = resolve$1(dirname$1(realImporter), idPath);
|
|
4195
|
-
} else if (idPath.startsWith("/") || /^[a-z]:[/\\]/i.test(idPath)) {
|
|
4196
|
-
resolvedPath = idPath;
|
|
4197
|
-
} else {
|
|
4198
|
-
return;
|
|
4199
|
-
}
|
|
4200
|
-
const filter = await getFilter();
|
|
4201
|
-
if (!filter(resolvedPath)) return;
|
|
4202
|
-
return intlifyVirtualize(resolvedPath);
|
|
4203
|
-
}
|
|
4204
|
-
}
|
|
4205
|
-
},
|
|
4206
|
-
load: {
|
|
4207
|
-
async handler(id) {
|
|
4208
|
-
debug$3("load", id);
|
|
4209
|
-
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework) && include) {
|
|
4210
|
-
let resourcePaths = [];
|
|
4211
|
-
for (const inc of include) {
|
|
4212
|
-
resourcePaths = [...resourcePaths, ...await glob(inc, { absolute: true })];
|
|
4213
|
-
}
|
|
4214
|
-
resourcePaths = resourcePaths.filter((el, pos) => resourcePaths.indexOf(el) === pos);
|
|
4215
|
-
const code = await generateBundleResources(resourcePaths, isProduction, {
|
|
4216
|
-
forceStringify,
|
|
4217
|
-
strictMessage,
|
|
4218
|
-
escapeHtml,
|
|
4219
|
-
usedKeyFilter: collector ? (keyPath) => collector.shouldKeepKey(keyPath) : void 0
|
|
4220
|
-
});
|
|
4221
|
-
return {
|
|
4222
|
-
moduleType: "js",
|
|
4223
|
-
code,
|
|
4224
|
-
map: { mappings: "" }
|
|
4225
|
-
};
|
|
4226
|
-
}
|
|
4227
|
-
if (isIntlifyVirtualId(id)) {
|
|
4228
|
-
const realId = virtualIdToRealPath.get(id);
|
|
4229
|
-
if (realId.includes("?vue&type=i18n")) {
|
|
4230
|
-
const { filename, query } = parseVueRequest(realId);
|
|
4231
|
-
let source;
|
|
4232
|
-
if (query.src) {
|
|
4233
|
-
this.addWatchFile(filename);
|
|
4234
|
-
source = await promises.readFile(filename, "utf-8");
|
|
4235
|
-
} else {
|
|
4236
|
-
this.addWatchFile(filename);
|
|
4237
|
-
const sfcSource = await promises.readFile(filename, "utf-8");
|
|
4238
|
-
const { descriptor } = getSfcParser()(sfcSource, {
|
|
4239
|
-
sourceMap,
|
|
4240
|
-
filename
|
|
4241
|
-
});
|
|
4242
|
-
const block = descriptor.customBlocks[query.index];
|
|
4243
|
-
if (!block) return;
|
|
4244
|
-
source = block.content;
|
|
4245
|
-
}
|
|
4246
|
-
if (typeof transformI18nBlock === "function") {
|
|
4247
|
-
const modifiedSource = transformI18nBlock(source);
|
|
4248
|
-
if (modifiedSource && typeof modifiedSource === "string") {
|
|
4249
|
-
source = modifiedSource;
|
|
4250
|
-
} else {
|
|
4251
|
-
warn("transformI18nBlock should return a string");
|
|
4252
|
-
}
|
|
4253
|
-
}
|
|
4254
|
-
let langInfo2 = defaultSFCLang;
|
|
4255
|
-
if (isString(query.lang)) {
|
|
4256
|
-
langInfo2 = query.src ? query.lang === "i18n" ? defaultSFCLang : query.lang : query.lang;
|
|
4257
|
-
}
|
|
4258
|
-
if (/\.?[cm]?[jt]s$/.test(langInfo2)) {
|
|
4259
|
-
source = `export default ${source.replace(/^[\s;]+/, "")}`;
|
|
4260
|
-
}
|
|
4261
|
-
const generate2 = getGenerator(langInfo2, generateYAML);
|
|
4262
|
-
const isGlobalBlock = globalSFCScope || !!query.global;
|
|
4263
|
-
const parseOptions2 = getOptions(
|
|
4264
|
-
filename,
|
|
4265
|
-
isProduction,
|
|
4266
|
-
query,
|
|
4267
|
-
sourceMap,
|
|
4268
|
-
{
|
|
4269
|
-
isGlobal: globalSFCScope,
|
|
4270
|
-
allowDynamic,
|
|
4271
|
-
jit: true,
|
|
4272
|
-
strictMessage,
|
|
4273
|
-
escapeHtml,
|
|
4274
|
-
onlyLocales,
|
|
4275
|
-
forceStringify,
|
|
4276
|
-
usedKeyFilter: collector && isGlobalBlock ? (keyPath) => collector.shouldKeepKey(keyPath) : void 0
|
|
4277
|
-
}
|
|
4278
|
-
);
|
|
4279
|
-
const { code: generatedCode2 } = await generate2(source, parseOptions2);
|
|
4280
|
-
return {
|
|
4281
|
-
moduleType: "js",
|
|
4282
|
-
code: generatedCode2,
|
|
4283
|
-
map: { mappings: "" }
|
|
4284
|
-
};
|
|
4285
|
-
}
|
|
4286
|
-
this.addWatchFile(realId);
|
|
4287
|
-
const code = await promises.readFile(realId, "utf-8");
|
|
4288
|
-
const langInfo = parse$1(realId).ext;
|
|
4289
|
-
const generate = getGenerator(langInfo);
|
|
4290
|
-
const parseOptions = getOptions(
|
|
4291
|
-
realId,
|
|
4292
|
-
isProduction,
|
|
4293
|
-
{},
|
|
4294
|
-
sourceMap,
|
|
4295
|
-
{
|
|
4296
|
-
isGlobal: globalSFCScope,
|
|
4297
|
-
allowDynamic,
|
|
4298
|
-
strictMessage,
|
|
4299
|
-
escapeHtml,
|
|
4300
|
-
jit: true,
|
|
4301
|
-
onlyLocales,
|
|
4302
|
-
forceStringify,
|
|
4303
|
-
usedKeyFilter: collector ? (keyPath) => collector.shouldKeepKey(keyPath) : void 0
|
|
4304
|
-
}
|
|
4305
|
-
);
|
|
4306
|
-
const { code: generatedCode } = await generate(code, parseOptions);
|
|
4307
|
-
return {
|
|
4308
|
-
moduleType: "js",
|
|
4309
|
-
code: generatedCode,
|
|
4310
|
-
map: { mappings: "" }
|
|
4311
|
-
};
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
},
|
|
4315
|
-
transform: {
|
|
4316
|
-
async handler(code, id) {
|
|
4317
|
-
if (isIntlifyVirtualId(id)) return;
|
|
4318
|
-
const filter = await getFilter();
|
|
4319
|
-
if (!filter(id)) {
|
|
4320
|
-
return;
|
|
4321
|
-
}
|
|
4322
|
-
const { filename, query } = parseVueRequest(id);
|
|
4323
|
-
debug$3("transform", id, JSON.stringify(query), filename);
|
|
4324
|
-
let langInfo = defaultSFCLang;
|
|
4325
|
-
let inSourceMap;
|
|
4326
|
-
if (!query.vue) {
|
|
4327
|
-
langInfo = parse$1(filename).ext;
|
|
4328
|
-
const generate = getGenerator(langInfo);
|
|
4329
|
-
const parseOptions = getOptions(
|
|
4330
|
-
filename,
|
|
4331
|
-
isProduction,
|
|
4332
|
-
query,
|
|
4333
|
-
sourceMap,
|
|
4334
|
-
{
|
|
4335
|
-
inSourceMap,
|
|
4336
|
-
isGlobal: globalSFCScope,
|
|
4337
|
-
allowDynamic,
|
|
4338
|
-
strictMessage,
|
|
4339
|
-
escapeHtml,
|
|
4340
|
-
jit: true,
|
|
4341
|
-
onlyLocales,
|
|
4342
|
-
forceStringify,
|
|
4343
|
-
usedKeyFilter: collector ? (keyPath) => collector.shouldKeepKey(keyPath) : void 0
|
|
4344
|
-
}
|
|
4345
|
-
);
|
|
4346
|
-
debug$3("parseOptions", parseOptions);
|
|
4347
|
-
const { code: generatedCode, map } = await generate(code, parseOptions);
|
|
4348
|
-
debug$3("generated code", generatedCode);
|
|
4349
|
-
debug$3("sourcemap", map, sourceMap);
|
|
4350
|
-
if (code === generatedCode) return;
|
|
4351
|
-
return {
|
|
4352
|
-
moduleType: "js",
|
|
4353
|
-
code: generatedCode,
|
|
4354
|
-
// prettier-ignore
|
|
4355
|
-
map: { mappings: "" }
|
|
4356
|
-
};
|
|
4357
|
-
} else {
|
|
4358
|
-
if (isCustomBlock(query)) {
|
|
4359
|
-
if (isString(query.lang)) {
|
|
4360
|
-
langInfo = query.src ? query.lang === "i18n" ? defaultSFCLang : query.lang : query.lang;
|
|
4361
|
-
} else if (defaultSFCLang) {
|
|
4362
|
-
langInfo = defaultSFCLang;
|
|
4363
|
-
}
|
|
4364
|
-
debug$3("langInfo", langInfo);
|
|
4365
|
-
const generate = getGenerator(langInfo, generateYAML);
|
|
4366
|
-
const isGlobalBlock = globalSFCScope || !!query.global;
|
|
4367
|
-
const parseOptions = getOptions(
|
|
4368
|
-
filename,
|
|
4369
|
-
isProduction,
|
|
4370
|
-
query,
|
|
4371
|
-
sourceMap,
|
|
4372
|
-
{
|
|
4373
|
-
inSourceMap,
|
|
4374
|
-
isGlobal: globalSFCScope,
|
|
4375
|
-
allowDynamic,
|
|
4376
|
-
jit: true,
|
|
4377
|
-
strictMessage,
|
|
4378
|
-
escapeHtml,
|
|
4379
|
-
onlyLocales,
|
|
4380
|
-
forceStringify,
|
|
4381
|
-
usedKeyFilter: collector && isGlobalBlock ? (keyPath) => collector.shouldKeepKey(keyPath) : void 0
|
|
4382
|
-
}
|
|
4383
|
-
);
|
|
4384
|
-
debug$3("parseOptions", parseOptions);
|
|
4385
|
-
let source = await getCode(
|
|
4386
|
-
code,
|
|
4387
|
-
filename,
|
|
4388
|
-
sourceMap,
|
|
4389
|
-
query,
|
|
4390
|
-
getSfcParser(),
|
|
4391
|
-
meta.framework
|
|
4392
|
-
);
|
|
4393
|
-
if (typeof transformI18nBlock === "function") {
|
|
4394
|
-
const modifiedSource = transformI18nBlock(source);
|
|
4395
|
-
if (modifiedSource && typeof modifiedSource === "string") {
|
|
4396
|
-
source = modifiedSource;
|
|
4397
|
-
} else {
|
|
4398
|
-
warn("transformI18nBlock should return a string");
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
if (/\.?[cm]?[jt]s$/.test(langInfo)) {
|
|
4402
|
-
source = `export default ${source.replace(/^[\s;]+/, "")}`;
|
|
4403
|
-
}
|
|
4404
|
-
const { code: generatedCode, map } = await generate(source, parseOptions);
|
|
4405
|
-
debug$3("generated code", generatedCode);
|
|
4406
|
-
debug$3("sourcemap", map, sourceMap);
|
|
4407
|
-
if (code === generatedCode) return;
|
|
4408
|
-
return {
|
|
4409
|
-
moduleType: "js",
|
|
4410
|
-
code: generatedCode,
|
|
4411
|
-
// prettier-ignore
|
|
4412
|
-
map: { mappings: "" }
|
|
4413
|
-
};
|
|
4414
|
-
}
|
|
4415
|
-
}
|
|
4416
|
-
}
|
|
4417
|
-
}
|
|
4418
|
-
};
|
|
4419
|
-
}
|
|
4420
|
-
function getGenerator(ext, fallback = generateJSON) {
|
|
4421
|
-
if (/\.?json5?$/.test(ext)) {
|
|
4422
|
-
return generateJSON;
|
|
4423
|
-
}
|
|
4424
|
-
if (/\.?ya?ml$/.test(ext)) {
|
|
4425
|
-
return generateYAML;
|
|
4426
|
-
}
|
|
4427
|
-
if (/\.?[cm]?js$/.test(ext)) {
|
|
4428
|
-
return generateJavaScript;
|
|
4429
|
-
}
|
|
4430
|
-
if (/\.?[cm]?ts$/.test(ext)) {
|
|
4431
|
-
return generateTypescript;
|
|
4432
|
-
}
|
|
4433
|
-
return fallback;
|
|
4434
|
-
}
|
|
4435
|
-
function normalizeConfigResolveAlias(resolve2, framework) {
|
|
4436
|
-
if (resolve2 && resolve2.alias) {
|
|
4437
|
-
return resolve2;
|
|
4438
|
-
}
|
|
4439
|
-
if (!resolve2) {
|
|
4440
|
-
if (framework === "vite") {
|
|
4441
|
-
return { alias: [] };
|
|
4442
|
-
} else if (framework === "webpack") {
|
|
4443
|
-
return { alias: {} };
|
|
4444
|
-
}
|
|
4445
|
-
} else if (!resolve2.alias) {
|
|
4446
|
-
if (framework === "vite") {
|
|
4447
|
-
resolve2.alias = [];
|
|
4448
|
-
return resolve2;
|
|
4449
|
-
} else if (framework === "webpack") {
|
|
4450
|
-
resolve2.alias = {};
|
|
4451
|
-
return resolve2;
|
|
4452
|
-
}
|
|
4453
|
-
}
|
|
4454
|
-
}
|
|
4455
|
-
async function generateBundleResources(resources, isProduction, {
|
|
4456
|
-
forceStringify = false,
|
|
4457
|
-
isGlobal = false,
|
|
4458
|
-
onlyLocales = [],
|
|
4459
|
-
strictMessage = true,
|
|
4460
|
-
escapeHtml = false,
|
|
4461
|
-
jit = true,
|
|
4462
|
-
transformI18nBlock = void 0,
|
|
4463
|
-
usedKeyFilter = void 0
|
|
4464
|
-
}) {
|
|
4465
|
-
const codes = [];
|
|
4466
|
-
for (const res of resources) {
|
|
4467
|
-
debug$3(`${res} bundle loading ...`);
|
|
4468
|
-
if (/\.(json5?|ya?ml)$/.test(res)) {
|
|
4469
|
-
const { ext, name } = parse$1(res);
|
|
4470
|
-
const source = await getRaw(res);
|
|
4471
|
-
const generate = /json5?/.test(ext) ? generateJSON : generateYAML;
|
|
4472
|
-
const parseOptions = getOptions(res, isProduction, {}, false, {
|
|
4473
|
-
isGlobal,
|
|
4474
|
-
jit,
|
|
4475
|
-
onlyLocales,
|
|
4476
|
-
strictMessage,
|
|
4477
|
-
escapeHtml,
|
|
4478
|
-
forceStringify,
|
|
4479
|
-
transformI18nBlock,
|
|
4480
|
-
usedKeyFilter
|
|
4481
|
-
});
|
|
4482
|
-
parseOptions.type = "bare";
|
|
4483
|
-
const { code } = generate(source, parseOptions);
|
|
4484
|
-
debug$3("generated code", code);
|
|
4485
|
-
codes.push(`${JSON.stringify(name)}: ${code}`);
|
|
4486
|
-
}
|
|
4487
|
-
}
|
|
4488
|
-
return `const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
|
|
4489
|
-
|
|
4490
|
-
const mergeDeep = (target, ...sources) => {
|
|
4491
|
-
if (!sources.length) return target;
|
|
4492
|
-
const source = sources.shift();
|
|
4493
|
-
|
|
4494
|
-
if (isObject(target) && isObject(source)) {
|
|
4495
|
-
for (const key in source) {
|
|
4496
|
-
if (isObject(source[key])) {
|
|
4497
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
4498
|
-
mergeDeep(target[key], source[key]);
|
|
4499
|
-
} else {
|
|
4500
|
-
Object.assign(target, { [key]: source[key] });
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4504
|
-
|
|
4505
|
-
return mergeDeep(target, ...sources);
|
|
4506
|
-
}
|
|
4507
|
-
|
|
4508
|
-
export default mergeDeep({},
|
|
4509
|
-
${codes.map((code) => `{${code}}`).join(",\n")}
|
|
4510
|
-
);`;
|
|
4511
|
-
}
|
|
4512
|
-
async function getCode(source, filename, sourceMap, query, parser, framework = "vite") {
|
|
4513
|
-
const { index, issuerPath } = query;
|
|
4514
|
-
if (!isNumber(index)) {
|
|
4515
|
-
raiseError(`unexpected index: ${index}`);
|
|
4516
|
-
}
|
|
4517
|
-
if (framework === "webpack") {
|
|
4518
|
-
if (issuerPath) {
|
|
4519
|
-
debug$3(`getCode (webpack) ${index} via issuerPath`, issuerPath);
|
|
4520
|
-
return await getRaw(filename);
|
|
4521
|
-
} else {
|
|
4522
|
-
const result = parser(await getRaw(filename), {
|
|
4523
|
-
sourceMap,
|
|
4524
|
-
filename
|
|
4525
|
-
});
|
|
4526
|
-
const block = result.descriptor.customBlocks[index];
|
|
4527
|
-
if (block) {
|
|
4528
|
-
const code = block.src ? await getRaw(resolveBlockSrc(block.src, filename)) : block.content;
|
|
4529
|
-
debug$3(`getCode (webpack) ${index} from SFC`, code);
|
|
4530
|
-
return code;
|
|
4531
|
-
} else {
|
|
4532
|
-
return source;
|
|
4533
|
-
}
|
|
4534
|
-
}
|
|
4535
|
-
} else {
|
|
4536
|
-
return source;
|
|
4537
|
-
}
|
|
4538
|
-
}
|
|
4539
|
-
function isCustomBlock(query) {
|
|
4540
|
-
return !isEmptyObject(query) && "vue" in query && (query["type"] === "custom" || // for webpack (vue-loader)
|
|
4541
|
-
query["type"] === "i18n" || // for vite (@vite/plugin-vue)
|
|
4542
|
-
query["blockType"] === "i18n");
|
|
4543
|
-
}
|
|
4544
|
-
function getOptions(filename, isProduction, query, sourceMap, {
|
|
4545
|
-
inSourceMap = void 0,
|
|
4546
|
-
forceStringify = false,
|
|
4547
|
-
isGlobal = false,
|
|
4548
|
-
onlyLocales = [],
|
|
4549
|
-
allowDynamic = false,
|
|
4550
|
-
strictMessage = true,
|
|
4551
|
-
escapeHtml = false,
|
|
4552
|
-
jit = true,
|
|
4553
|
-
transformI18nBlock = null,
|
|
4554
|
-
usedKeyFilter = void 0
|
|
4555
|
-
}) {
|
|
4556
|
-
const mode = isProduction ? "production" : "development";
|
|
4557
|
-
const baseOptions = {
|
|
4558
|
-
filename,
|
|
4559
|
-
sourceMap,
|
|
4560
|
-
inSourceMap,
|
|
4561
|
-
forceStringify,
|
|
4562
|
-
allowDynamic,
|
|
4563
|
-
strictMessage,
|
|
4564
|
-
escapeHtml,
|
|
4565
|
-
jit,
|
|
4566
|
-
onlyLocales,
|
|
4567
|
-
usedKeyFilter,
|
|
4568
|
-
env: mode,
|
|
4569
|
-
transformI18nBlock,
|
|
4570
|
-
onWarn: (msg) => {
|
|
4571
|
-
warn(`${filename} ${msg}`);
|
|
4572
|
-
},
|
|
4573
|
-
onError: (msg, extra) => {
|
|
4574
|
-
const codeFrame = generateCodeFrame(
|
|
4575
|
-
extra?.source || extra?.location?.source || "",
|
|
4576
|
-
extra?.location?.start.column,
|
|
4577
|
-
extra?.location?.end.column
|
|
4578
|
-
);
|
|
4579
|
-
const errMssage = `${msg} (error code: ${extra?.code}) in ${filename}
|
|
4580
|
-
target message: ${extra?.source}
|
|
4581
|
-
target message path: ${extra?.path}
|
|
4582
|
-
|
|
4583
|
-
${codeFrame}
|
|
4584
|
-
`;
|
|
4585
|
-
error(errMssage);
|
|
4586
|
-
throw new Error(errMssage);
|
|
4587
|
-
}
|
|
4588
|
-
};
|
|
4589
|
-
if (isCustomBlock(query)) {
|
|
4590
|
-
return assign(baseOptions, {
|
|
4591
|
-
type: "sfc",
|
|
4592
|
-
locale: isString(query.locale) ? query.locale : "",
|
|
4593
|
-
isGlobal: isGlobal || !!query.global
|
|
4594
|
-
});
|
|
4595
|
-
} else {
|
|
4596
|
-
return assign(baseOptions, {
|
|
4597
|
-
type: "plain",
|
|
4598
|
-
isGlobal: false
|
|
4599
|
-
});
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4602
|
-
function resolveBlockSrc(src, sfcFilename) {
|
|
4603
|
-
if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
|
|
4604
|
-
return resolve$1(dirname$1(sfcFilename), src);
|
|
4605
|
-
}
|
|
4606
|
-
return src;
|
|
4607
|
-
}
|
|
4608
|
-
function getVirtualId(id, framework = "vite") {
|
|
4609
|
-
return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
|
|
3755
|
+
const LAYOUTS_MODULE_ID = "virtual:generated-layouts";
|
|
3756
|
+
const RESOLVED_LAYOUTS_MODULE_ID = `\0${LAYOUTS_MODULE_ID}`;
|
|
3757
|
+
function defaultImportMode(name) {
|
|
3758
|
+
if (process.env.VITE_SSG)
|
|
3759
|
+
return "sync";
|
|
3760
|
+
return name === "default" ? "sync" : "async";
|
|
4610
3761
|
}
|
|
4611
|
-
|
|
4612
|
-
|
|
3762
|
+
const REGEX_BACKSLASH = /\\/g;
|
|
3763
|
+
const REGEX_SEPARATORS = /[-_/.\s]/;
|
|
3764
|
+
const REGEX_NON_ALPHANUMERIC = /[^a-z0-9-]+/gi;
|
|
3765
|
+
const REGEX_REPEATED_DASH = /-+/g;
|
|
3766
|
+
const REGEX_EDGE_DASH = /^-|-$/g;
|
|
3767
|
+
const REGEX_NUMBER = /\d/;
|
|
3768
|
+
function isUppercase(char = "") {
|
|
3769
|
+
if (REGEX_NUMBER.test(char))
|
|
3770
|
+
return void 0;
|
|
3771
|
+
return char !== char.toLowerCase();
|
|
4613
3772
|
}
|
|
4614
|
-
|
|
4615
|
-
|
|
3773
|
+
function caseBoundary(previousUpper, isUpper, buffer) {
|
|
3774
|
+
if (previousUpper === false && isUpper === true)
|
|
3775
|
+
return "before";
|
|
3776
|
+
if (previousUpper === true && isUpper === false && buffer.length > 1)
|
|
3777
|
+
return "after";
|
|
4616
3778
|
}
|
|
4617
|
-
|
|
4618
|
-
const
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
translationIdentifiers
|
|
4626
|
-
}) {
|
|
4627
|
-
let vuePlugin = null;
|
|
4628
|
-
let vuePluginOptions = null;
|
|
4629
|
-
const excludeLangs = ["pug", "jsx", "tsx"];
|
|
4630
|
-
return {
|
|
4631
|
-
name: resolveNamespace("directive"),
|
|
4632
|
-
enforce: "pre",
|
|
4633
|
-
vite: {
|
|
4634
|
-
async config(config) {
|
|
4635
|
-
await import('@typescript-eslint/typescript-estree').then((r) => {
|
|
4636
|
-
tsEstree.parse = r.parse;
|
|
4637
|
-
tsEstree.simpleTraverse = r.simpleTraverse;
|
|
4638
|
-
tsEstree.AST_NODE_TYPES = r.AST_NODE_TYPES;
|
|
4639
|
-
return;
|
|
4640
|
-
});
|
|
4641
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
4642
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
4643
|
-
return;
|
|
4644
|
-
}
|
|
4645
|
-
if (optimizeTranslationDirective) {
|
|
4646
|
-
vuePlugin.api.options = resolveVueOptions(
|
|
4647
|
-
vuePlugin,
|
|
4648
|
-
optimizeTranslationDirective,
|
|
4649
|
-
translationIdentifiers
|
|
4650
|
-
);
|
|
4651
|
-
debug$2(`vite:vue options['template']:`, vuePlugin.api.options);
|
|
4652
|
-
}
|
|
4653
|
-
},
|
|
4654
|
-
configResolved(config) {
|
|
4655
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
4656
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
4657
|
-
return;
|
|
4658
|
-
}
|
|
4659
|
-
}
|
|
4660
|
-
},
|
|
4661
|
-
async transform(code, id) {
|
|
4662
|
-
if (id.endsWith(".vue")) {
|
|
4663
|
-
const { filename, query } = parseVueRequest(id);
|
|
4664
|
-
if (!excludeLangs.includes(query.lang ?? "")) {
|
|
4665
|
-
if (vuePluginOptions == null) {
|
|
4666
|
-
vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
4667
|
-
}
|
|
4668
|
-
if (vuePluginOptions?.compiler) {
|
|
4669
|
-
analyzeIdentifiers(
|
|
4670
|
-
getDescriptor(filename, code, vuePluginOptions),
|
|
4671
|
-
vuePluginOptions,
|
|
4672
|
-
translationIdentifiers
|
|
4673
|
-
);
|
|
4674
|
-
return {
|
|
4675
|
-
code,
|
|
4676
|
-
map: { version: 3, mappings: "", sources: [] }
|
|
4677
|
-
};
|
|
4678
|
-
}
|
|
4679
|
-
}
|
|
4680
|
-
}
|
|
4681
|
-
}
|
|
3779
|
+
function splitByCase(value) {
|
|
3780
|
+
const parts = [];
|
|
3781
|
+
let buffer = "";
|
|
3782
|
+
let previousUpper;
|
|
3783
|
+
let previousSplitter;
|
|
3784
|
+
const flush = () => {
|
|
3785
|
+
if (buffer)
|
|
3786
|
+
parts.push(buffer);
|
|
4682
3787
|
};
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
const { filename } = context;
|
|
4691
|
-
const vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
4692
|
-
const normalizedFilename = normalizePath(path.relative(vuePluginOptions.root, filename));
|
|
4693
|
-
const resolveIdentifier2 = translationIdentifiers.get(normalizedFilename);
|
|
4694
|
-
debug$2("resolved vue-i18n Identifier", resolveIdentifier2);
|
|
4695
|
-
if (resolveIdentifier2 == null) {
|
|
4696
|
-
return void 0;
|
|
3788
|
+
for (const char of value) {
|
|
3789
|
+
if (REGEX_SEPARATORS.test(char)) {
|
|
3790
|
+
flush();
|
|
3791
|
+
buffer = "";
|
|
3792
|
+
previousUpper = void 0;
|
|
3793
|
+
previousSplitter = true;
|
|
3794
|
+
continue;
|
|
4697
3795
|
}
|
|
4698
|
-
|
|
4699
|
-
|
|
3796
|
+
const isUpper = isUppercase(char);
|
|
3797
|
+
const boundary = previousSplitter === false ? caseBoundary(previousUpper, isUpper, buffer) : void 0;
|
|
3798
|
+
if (boundary === "before") {
|
|
3799
|
+
flush();
|
|
3800
|
+
buffer = char;
|
|
3801
|
+
} else if (boundary === "after") {
|
|
3802
|
+
parts.push(buffer.slice(0, -1));
|
|
3803
|
+
buffer = buffer.at(-1) + char;
|
|
4700
3804
|
} else {
|
|
4701
|
-
|
|
4702
|
-
return resolveIdentifier2?.style === "script-setup" ? `${resolvedSignature}.t` : resolvedSignature;
|
|
3805
|
+
buffer += char;
|
|
4703
3806
|
}
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
translationSignatures: isBoolean(optimizeTranslationDirective) ? translationSignatureResolver : optimizeTranslationDirective
|
|
4707
|
-
});
|
|
4708
|
-
return vueOptions;
|
|
4709
|
-
}
|
|
4710
|
-
function analyzeIdentifiers(descriptor, { root }, translationIdentifiers) {
|
|
4711
|
-
const source = descriptor.scriptSetup?.content || descriptor.script?.content;
|
|
4712
|
-
debug$2("getDescriptor content", source);
|
|
4713
|
-
if (!source) {
|
|
4714
|
-
return;
|
|
4715
|
-
}
|
|
4716
|
-
const ast = tsEstree.parse(source, { range: true });
|
|
4717
|
-
tsEstree.simpleTraverse(ast, {
|
|
4718
|
-
enter(node, parent) {
|
|
4719
|
-
if (parent) {
|
|
4720
|
-
node.parent = parent;
|
|
4721
|
-
}
|
|
4722
|
-
}
|
|
4723
|
-
});
|
|
4724
|
-
const scopeManager = analyze(ast, { sourceType: "module" });
|
|
4725
|
-
const scope = getScope(scopeManager, ast);
|
|
4726
|
-
const importLocalName = getImportLocalName(scope, "vue-i18n", "useI18n");
|
|
4727
|
-
if (importLocalName == null) {
|
|
4728
|
-
return;
|
|
4729
|
-
}
|
|
4730
|
-
debug$2("importLocalName", importLocalName);
|
|
4731
|
-
const resolvedIdentifier = getVueI18nIdentifier(scope, importLocalName);
|
|
4732
|
-
if (resolvedIdentifier) {
|
|
4733
|
-
const normalizedFilename = normalizePath(path.relative(root, descriptor.filename));
|
|
4734
|
-
debug$2("set vue-i18n resolved identifier: ", resolvedIdentifier);
|
|
4735
|
-
translationIdentifiers.set(normalizedFilename, resolvedIdentifier);
|
|
4736
|
-
}
|
|
4737
|
-
}
|
|
4738
|
-
function getScope(manager, node) {
|
|
4739
|
-
const scope = manager.acquire(node, true);
|
|
4740
|
-
if (scope) {
|
|
4741
|
-
if (scope.type === "function-expression-name") {
|
|
4742
|
-
return scope.childScopes[0];
|
|
4743
|
-
}
|
|
4744
|
-
return scope;
|
|
3807
|
+
previousUpper = isUpper;
|
|
3808
|
+
previousSplitter = false;
|
|
4745
3809
|
}
|
|
4746
|
-
|
|
3810
|
+
flush();
|
|
3811
|
+
return parts;
|
|
4747
3812
|
}
|
|
4748
|
-
function
|
|
4749
|
-
|
|
4750
|
-
if (importDecl) {
|
|
4751
|
-
const specifierNode = importDecl.specifiers.find(
|
|
4752
|
-
(specifierNode2) => isImportedIdentifierInImportClause(specifierNode2) && specifierNode2.imported.name === imported
|
|
4753
|
-
);
|
|
4754
|
-
return specifierNode ? specifierNode.local.name : null;
|
|
4755
|
-
}
|
|
4756
|
-
return null;
|
|
3813
|
+
function kebabCaseSegments(segments) {
|
|
3814
|
+
return segments.map((segment) => segment.toLowerCase()).join("-").replace(REGEX_NON_ALPHANUMERIC, "-").replace(REGEX_REPEATED_DASH, "-").replace(REGEX_EDGE_DASH, "");
|
|
4757
3815
|
}
|
|
4758
|
-
function
|
|
4759
|
-
const
|
|
4760
|
-
const
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
3816
|
+
function resolveLayoutNameSegments(fileName, prefixParts) {
|
|
3817
|
+
const fileNameParts = splitByCase(fileName);
|
|
3818
|
+
const fileNamePartsContent = fileNameParts.join("/").toLowerCase();
|
|
3819
|
+
const layoutNameParts = prefixParts.flatMap((part) => splitByCase(part));
|
|
3820
|
+
const matchedSuffix = [];
|
|
3821
|
+
let index = prefixParts.length - 1;
|
|
3822
|
+
while (index >= 0) {
|
|
3823
|
+
const prefixPart = prefixParts[index];
|
|
3824
|
+
matchedSuffix.unshift(...splitByCase(prefixPart).map((part) => part.toLowerCase()));
|
|
3825
|
+
const matchedSuffixContent = matchedSuffix.join("/");
|
|
3826
|
+
if (fileNamePartsContent === matchedSuffixContent || fileNamePartsContent.startsWith(`${matchedSuffixContent}/`) || prefixPart.toLowerCase() === fileNamePartsContent && prefixParts[index + 1] && prefixParts[index] === prefixParts[index + 1]) {
|
|
3827
|
+
layoutNameParts.length = index;
|
|
4764
3828
|
}
|
|
4765
|
-
|
|
4766
|
-
const refs = Array.from(tracker.iterateEsmReferences(traceMap));
|
|
4767
|
-
return refs.length ? refs[0].node : null;
|
|
4768
|
-
}
|
|
4769
|
-
function isImportedIdentifierInImportClause(node) {
|
|
4770
|
-
return "imported" in node;
|
|
4771
|
-
}
|
|
4772
|
-
function getVueI18nIdentifier(scope, local) {
|
|
4773
|
-
const { callExpression, returnStatement } = getCallExpressionAndReturnStatement(scope, local);
|
|
4774
|
-
if (callExpression == null) {
|
|
4775
|
-
return null;
|
|
4776
|
-
}
|
|
4777
|
-
const id = getVariableDeclarationIdFrom(callExpression);
|
|
4778
|
-
if (id == null) {
|
|
4779
|
-
return null;
|
|
4780
|
-
}
|
|
4781
|
-
const variableIdPairs = parseVariableId(id);
|
|
4782
|
-
debug$2("variableIdPairs:", variableIdPairs);
|
|
4783
|
-
const returnVariableIdPairs = parseReturnStatement(returnStatement);
|
|
4784
|
-
debug$2("returnVariableIdPairs:", returnVariableIdPairs);
|
|
4785
|
-
return resolveIdentifier(variableIdPairs, returnVariableIdPairs);
|
|
4786
|
-
}
|
|
4787
|
-
const EMPTY_NODE_RETURN = {
|
|
4788
|
-
callExpression: null,
|
|
4789
|
-
returnStatement: null
|
|
4790
|
-
};
|
|
4791
|
-
function getCallExpressionAndReturnStatement(scope, local) {
|
|
4792
|
-
const variable = eslintUitls.findVariable(scope, local);
|
|
4793
|
-
if (variable == null) {
|
|
4794
|
-
return EMPTY_NODE_RETURN;
|
|
4795
|
-
}
|
|
4796
|
-
const callExpressionRef = variable.references.find((ref) => {
|
|
4797
|
-
return ref.identifier.parent?.type === tsEstree.AST_NODE_TYPES.CallExpression;
|
|
4798
|
-
});
|
|
4799
|
-
if (callExpressionRef == null) {
|
|
4800
|
-
return EMPTY_NODE_RETURN;
|
|
4801
|
-
}
|
|
4802
|
-
let returnStatement = null;
|
|
4803
|
-
if (callExpressionRef.from.type === "function" && callExpressionRef.from.block.type === tsEstree.AST_NODE_TYPES.FunctionExpression && // @ts-expect-error -- FIXME: type error
|
|
4804
|
-
callExpressionRef.from.block.parent.type === tsEstree.AST_NODE_TYPES.Property && // @ts-expect-error -- FIXME: type error
|
|
4805
|
-
callExpressionRef.from.block.parent.key.type === tsEstree.AST_NODE_TYPES.Identifier && // @ts-expect-error -- FIXME: type error
|
|
4806
|
-
callExpressionRef.from.block.parent.key.name === "setup") {
|
|
4807
|
-
returnStatement = callExpressionRef.from.block.body.body.find((statement) => {
|
|
4808
|
-
return statement.type === tsEstree.AST_NODE_TYPES.ReturnStatement;
|
|
4809
|
-
});
|
|
3829
|
+
index -= 1;
|
|
4810
3830
|
}
|
|
4811
|
-
return
|
|
4812
|
-
// @ts-expect-error -- FIXME: type error
|
|
4813
|
-
callExpression: callExpressionRef.identifier.parent,
|
|
4814
|
-
returnStatement
|
|
4815
|
-
};
|
|
3831
|
+
return [...layoutNameParts, ...fileNameParts];
|
|
4816
3832
|
}
|
|
4817
|
-
function
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
3833
|
+
function normalizeLayoutName(file) {
|
|
3834
|
+
const normalizedFile = file.replace(REGEX_BACKSLASH, "/");
|
|
3835
|
+
const slashIndex = normalizedFile.lastIndexOf("/");
|
|
3836
|
+
const dir = slashIndex === -1 ? "" : normalizedFile.slice(0, slashIndex);
|
|
3837
|
+
const basename = slashIndex === -1 ? normalizedFile : normalizedFile.slice(slashIndex + 1);
|
|
3838
|
+
const dotIndex = basename.lastIndexOf(".");
|
|
3839
|
+
const name = dotIndex <= 0 ? basename : basename.slice(0, dotIndex);
|
|
3840
|
+
const prefixParts = splitByCase(dir);
|
|
3841
|
+
return kebabCaseSegments(
|
|
3842
|
+
resolveLayoutNameSegments(dir && name.toLowerCase() === "index" ? "" : name, prefixParts).filter(Boolean)
|
|
3843
|
+
);
|
|
4822
3844
|
}
|
|
4823
|
-
function
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
const pairs = [];
|
|
4832
|
-
for (const prop of props) {
|
|
4833
|
-
if (prop?.key.type === tsEstree.AST_NODE_TYPES.Identifier && prop?.value.type === tsEstree.AST_NODE_TYPES.Identifier) {
|
|
4834
|
-
pairs.push({ key: prop.key.name, value: prop.value.name });
|
|
4835
|
-
}
|
|
3845
|
+
function resolveLayoutsDirs(layoutsDirs, root) {
|
|
3846
|
+
const dirs = [];
|
|
3847
|
+
for (const dir of Array.isArray(layoutsDirs) ? layoutsDirs : [layoutsDirs]) {
|
|
3848
|
+
if (dir.includes("**")) {
|
|
3849
|
+
const matches = globSync(dir, { cwd: root, onlyDirectories: true, absolute: true, expandDirectories: false });
|
|
3850
|
+
dirs.push(...matches.sort().map((match) => normalize(match).replace(/\/$/, "")));
|
|
3851
|
+
} else {
|
|
3852
|
+
dirs.push(normalize(resolve$1(root, dir)));
|
|
4836
3853
|
}
|
|
4837
|
-
return pairs;
|
|
4838
3854
|
}
|
|
3855
|
+
return dirs;
|
|
4839
3856
|
}
|
|
4840
|
-
function
|
|
4841
|
-
const
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
3857
|
+
function resolveLayoutsOptions(options, userOptions = {}) {
|
|
3858
|
+
const resolved = {
|
|
3859
|
+
layoutsDirs: options.roots.map((root) => `${root}/layouts`),
|
|
3860
|
+
extensions: ["vue"],
|
|
3861
|
+
exclude: [],
|
|
3862
|
+
defaultLayout: "default",
|
|
3863
|
+
// In SSG builds, layout components must be imported synchronously so that
|
|
3864
|
+
// the client-side hydration tree matches the server-rendered HTML. Lazy
|
|
3865
|
+
// non-default layouts (post, home, etc.) would not have resolved when
|
|
3866
|
+
// hydration starts, causing a mismatch.
|
|
3867
|
+
importMode: options.mode === "build" ? () => "sync" : defaultImportMode,
|
|
3868
|
+
inheritDefaultLayout: true
|
|
3869
|
+
};
|
|
3870
|
+
for (const [key, value] of Object.entries(userOptions)) {
|
|
3871
|
+
if (value !== void 0)
|
|
3872
|
+
resolved[key] = value;
|
|
3873
|
+
}
|
|
3874
|
+
return { ...resolved, dirs: resolveLayoutsDirs(resolved.layoutsDirs, options.userRoot) };
|
|
3875
|
+
}
|
|
3876
|
+
async function scanLayouts(options) {
|
|
3877
|
+
const pattern = options.extensions.length > 1 ? `**/*.{${options.extensions.join(",")}}` : `**/*.${options.extensions[0] || ""}`;
|
|
3878
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
3879
|
+
const dirFiles = await Promise.all(options.dirs.map((dir) => glob(pattern, {
|
|
3880
|
+
cwd: dir,
|
|
3881
|
+
ignore: ["**/node_modules/**", "**/.git/**", "**/__*__/*", ...options.exclude],
|
|
3882
|
+
onlyFiles: true,
|
|
3883
|
+
expandDirectories: false
|
|
3884
|
+
})));
|
|
3885
|
+
options.dirs.forEach((dir, index) => {
|
|
3886
|
+
for (const file of dirFiles[index].sort()) {
|
|
3887
|
+
const name = normalizeLayoutName(file);
|
|
3888
|
+
layouts.delete(name);
|
|
3889
|
+
layouts.set(name, normalize(resolve$1(dir, file)));
|
|
4857
3890
|
}
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
return pairs;
|
|
4861
|
-
} else {
|
|
4862
|
-
return pairs;
|
|
4863
|
-
}
|
|
3891
|
+
});
|
|
3892
|
+
return layouts;
|
|
4864
3893
|
}
|
|
4865
|
-
function
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
}
|
|
4875
|
-
|
|
4876
|
-
} else {
|
|
4877
|
-
const variable = localVariables.find((pair) => pair.key === "t");
|
|
4878
|
-
if (variable && variable.value) {
|
|
4879
|
-
const returnVar = returnVariable.find((pair) => pair.value === variable.value);
|
|
4880
|
-
if (returnVar && returnVar.key) {
|
|
4881
|
-
return { type: "identifier", key: returnVar.key };
|
|
4882
|
-
}
|
|
4883
|
-
}
|
|
4884
|
-
const identifierOnly = localVariables.find((pair) => pair.value === null);
|
|
4885
|
-
if (identifierOnly && identifierOnly.key) {
|
|
4886
|
-
const targetKey = identifierOnly.key;
|
|
4887
|
-
const returnVar = returnVariable.find((pair) => pair.value?.startsWith(targetKey));
|
|
4888
|
-
if (returnVar && returnVar.key) {
|
|
4889
|
-
return { type: "object", key: returnVar.key, style: "setup-hook" };
|
|
4890
|
-
}
|
|
3894
|
+
function generateLayoutsCode(layouts, options, runtime) {
|
|
3895
|
+
const head = [];
|
|
3896
|
+
const entries = [];
|
|
3897
|
+
for (const [name, file] of layouts) {
|
|
3898
|
+
const id = JSON.stringify(toAtFS(file));
|
|
3899
|
+
if (options.importMode(name) === "sync") {
|
|
3900
|
+
const variable = `__layout_${head.length}`;
|
|
3901
|
+
head.push(`import ${variable} from ${id}`);
|
|
3902
|
+
entries.push(` ${JSON.stringify(name)}: ${variable},`);
|
|
3903
|
+
} else {
|
|
3904
|
+
entries.push(` ${JSON.stringify(name)}: lazyLayout(() => import(${id})),`);
|
|
4891
3905
|
}
|
|
4892
|
-
return null;
|
|
4893
3906
|
}
|
|
3907
|
+
const fallbackArg = options.fallbackLayout ? `, ${JSON.stringify(options.fallbackLayout)}` : "";
|
|
3908
|
+
return `import { createGetRoutes, createLayoutWrapper, createSetupLayouts, lazyLayout, setPageLayout, useLayout } from ${JSON.stringify(toAtFS(runtime))}
|
|
3909
|
+
${head.join("\n")}
|
|
3910
|
+
export { createGetRoutes, setPageLayout, useLayout }
|
|
3911
|
+
export const layouts = {
|
|
3912
|
+
${entries.join("\n")}
|
|
4894
3913
|
}
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
3914
|
+
const LayoutWrapper = createLayoutWrapper(layouts, ${JSON.stringify(options.defaultLayout)}${fallbackArg})
|
|
3915
|
+
export const setupLayouts = createSetupLayouts(LayoutWrapper, { inheritDefaultLayout: ${options.inheritDefaultLayout} })
|
|
3916
|
+
`;
|
|
4898
3917
|
}
|
|
4899
|
-
function
|
|
4900
|
-
const
|
|
4901
|
-
const
|
|
4902
|
-
const
|
|
4903
|
-
|
|
4904
|
-
|
|
3918
|
+
function createLayoutsPlugin(options) {
|
|
3919
|
+
const runtime = resolve$1(options.clientRoot, "utils/layouts.ts");
|
|
3920
|
+
const resolveOptions = () => resolveLayoutsOptions(options, options.config.layouts);
|
|
3921
|
+
const isLayoutFile = (file, layoutsOptions) => {
|
|
3922
|
+
const path = normalize(file);
|
|
3923
|
+
return layoutsOptions.extensions.some((ext) => path.endsWith(`.${ext}`)) && layoutsOptions.dirs.some((dir) => {
|
|
3924
|
+
const rel = relative(dir, path);
|
|
3925
|
+
return !!rel && !rel.startsWith("..") && !isAbsolute(rel);
|
|
3926
|
+
});
|
|
3927
|
+
};
|
|
4905
3928
|
return {
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
return dynamicKeysDetected;
|
|
4911
|
-
},
|
|
4912
|
-
set dynamicKeysDetected(val) {
|
|
4913
|
-
dynamicKeysDetected = val;
|
|
4914
|
-
},
|
|
4915
|
-
safelistPatterns,
|
|
4916
|
-
removedKeys,
|
|
4917
|
-
addKey(key) {
|
|
4918
|
-
usedKeys.add(key);
|
|
4919
|
-
},
|
|
4920
|
-
markDynamic() {
|
|
4921
|
-
dynamicKeysDetected = true;
|
|
4922
|
-
},
|
|
4923
|
-
shouldKeepKey(keyPath) {
|
|
4924
|
-
if (dynamicKeysDetected && dynamicKeyStrategy === "keep-all") {
|
|
4925
|
-
return true;
|
|
4926
|
-
}
|
|
4927
|
-
if (safelistPatterns.some((pattern) => matchSafelistPattern(keyPath, pattern))) {
|
|
4928
|
-
return true;
|
|
4929
|
-
}
|
|
4930
|
-
if (usedKeys.has(keyPath)) {
|
|
4931
|
-
return true;
|
|
4932
|
-
}
|
|
4933
|
-
for (const key of usedKeys) {
|
|
4934
|
-
if (key.startsWith(keyPath + ".")) {
|
|
4935
|
-
return true;
|
|
4936
|
-
}
|
|
4937
|
-
}
|
|
4938
|
-
return false;
|
|
3929
|
+
name: "valaxy:layouts",
|
|
3930
|
+
resolveId(id) {
|
|
3931
|
+
if (id === LAYOUTS_MODULE_ID)
|
|
3932
|
+
return RESOLVED_LAYOUTS_MODULE_ID;
|
|
4939
3933
|
},
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
3934
|
+
async load(id) {
|
|
3935
|
+
if (id !== RESOLVED_LAYOUTS_MODULE_ID)
|
|
3936
|
+
return;
|
|
3937
|
+
const layoutsOptions = resolveOptions();
|
|
3938
|
+
return {
|
|
3939
|
+
code: generateLayoutsCode(await scanLayouts(layoutsOptions), layoutsOptions, runtime),
|
|
3940
|
+
moduleType: "js"
|
|
3941
|
+
};
|
|
4947
3942
|
},
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
}
|
|
4953
|
-
return { totalRemoved, byFile: removedKeys };
|
|
4954
|
-
}
|
|
4955
|
-
};
|
|
4956
|
-
}
|
|
4957
|
-
const I18N_FUNCTIONS = /* @__PURE__ */ new Set(["t", "$t", "tc", "$tc", "te", "$te", "d", "$d", "n", "$n"]);
|
|
4958
|
-
const TEMPLATE_T_REGEX = /\$?t\s*\(\s*['"]([^'"]+)['"]/g;
|
|
4959
|
-
const VT_DIRECTIVE_STRING_REGEX = /v-t\s*=\s*"'([^']+)'"/g;
|
|
4960
|
-
const VT_DIRECTIVE_PATH_REGEX = /v-t\s*=\s*"\{[^}]*path\s*:\s*'([^']+)'/g;
|
|
4961
|
-
const TEMPLATE_DYNAMIC_T_REGEX = /\$?t\s*\(\s*[a-zA-Z_$]/g;
|
|
4962
|
-
async function extractKeysFromScript(source) {
|
|
4963
|
-
const keys = [];
|
|
4964
|
-
let hasDynamic = false;
|
|
4965
|
-
let tsEstree2;
|
|
4966
|
-
try {
|
|
4967
|
-
tsEstree2 = await import('@typescript-eslint/typescript-estree');
|
|
4968
|
-
} catch {
|
|
4969
|
-
return extractKeysFromScriptRegex(source);
|
|
4970
|
-
}
|
|
4971
|
-
try {
|
|
4972
|
-
const ast = tsEstree2.parse(source, {
|
|
4973
|
-
range: true,
|
|
4974
|
-
jsx: true,
|
|
4975
|
-
allowInvalidAST: true,
|
|
4976
|
-
suppressDeprecatedPropertyWarnings: true
|
|
4977
|
-
});
|
|
4978
|
-
tsEstree2.simpleTraverse(ast, {
|
|
4979
|
-
enter(node) {
|
|
4980
|
-
if (node.type !== tsEstree2.AST_NODE_TYPES.CallExpression) {
|
|
4981
|
-
return;
|
|
4982
|
-
}
|
|
4983
|
-
const calleeName = getCalleeName(node, tsEstree2.AST_NODE_TYPES);
|
|
4984
|
-
if (!calleeName || !I18N_FUNCTIONS.has(calleeName)) {
|
|
4985
|
-
return;
|
|
4986
|
-
}
|
|
4987
|
-
const firstArg = node.arguments[0];
|
|
4988
|
-
if (!firstArg) {
|
|
3943
|
+
configureServer(server) {
|
|
3944
|
+
server.watcher.add(resolveOptions().dirs);
|
|
3945
|
+
const invalidate = (file) => {
|
|
3946
|
+
if (!isLayoutFile(file, resolveOptions()))
|
|
4989
3947
|
return;
|
|
3948
|
+
for (const environment of Object.values(server.environments)) {
|
|
3949
|
+
const module = environment.moduleGraph.getModuleById(RESOLVED_LAYOUTS_MODULE_ID);
|
|
3950
|
+
if (module)
|
|
3951
|
+
environment.moduleGraph.invalidateModule(module);
|
|
4990
3952
|
}
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
} else {
|
|
4999
|
-
hasDynamic = true;
|
|
5000
|
-
}
|
|
5001
|
-
}
|
|
5002
|
-
});
|
|
5003
|
-
} catch {
|
|
5004
|
-
return extractKeysFromScriptRegex(source);
|
|
5005
|
-
}
|
|
5006
|
-
return { keys, hasDynamic };
|
|
5007
|
-
}
|
|
5008
|
-
function getCalleeName(node, AST_NODE_TYPES) {
|
|
5009
|
-
const callee = node.callee;
|
|
5010
|
-
if (callee.type === AST_NODE_TYPES.Identifier) {
|
|
5011
|
-
return callee.name;
|
|
5012
|
-
}
|
|
5013
|
-
if (callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier) {
|
|
5014
|
-
return callee.property.name;
|
|
5015
|
-
}
|
|
5016
|
-
return null;
|
|
5017
|
-
}
|
|
5018
|
-
function extractKeysFromScriptRegex(source) {
|
|
5019
|
-
const keys = [];
|
|
5020
|
-
let match;
|
|
5021
|
-
const regex = /\b(?:\$?t|tc|\$tc|te|\$te|d|\$d|n|\$n)\s*\(\s*['"]([^'"]+)['"]/g;
|
|
5022
|
-
while ((match = regex.exec(source)) !== null) {
|
|
5023
|
-
keys.push(match[1]);
|
|
5024
|
-
}
|
|
5025
|
-
return { keys, hasDynamic: false };
|
|
5026
|
-
}
|
|
5027
|
-
function extractKeysFromTemplate(templateContent) {
|
|
5028
|
-
const keys = [];
|
|
5029
|
-
let hasDynamic = false;
|
|
5030
|
-
let match;
|
|
5031
|
-
TEMPLATE_T_REGEX.lastIndex = 0;
|
|
5032
|
-
VT_DIRECTIVE_STRING_REGEX.lastIndex = 0;
|
|
5033
|
-
VT_DIRECTIVE_PATH_REGEX.lastIndex = 0;
|
|
5034
|
-
TEMPLATE_DYNAMIC_T_REGEX.lastIndex = 0;
|
|
5035
|
-
while ((match = TEMPLATE_T_REGEX.exec(templateContent)) !== null) {
|
|
5036
|
-
keys.push(match[1]);
|
|
5037
|
-
}
|
|
5038
|
-
while ((match = VT_DIRECTIVE_STRING_REGEX.exec(templateContent)) !== null) {
|
|
5039
|
-
keys.push(match[1]);
|
|
5040
|
-
}
|
|
5041
|
-
while ((match = VT_DIRECTIVE_PATH_REGEX.exec(templateContent)) !== null) {
|
|
5042
|
-
keys.push(match[1]);
|
|
5043
|
-
}
|
|
5044
|
-
if (TEMPLATE_DYNAMIC_T_REGEX.test(templateContent)) {
|
|
5045
|
-
hasDynamic = true;
|
|
5046
|
-
}
|
|
5047
|
-
return { keys, hasDynamic };
|
|
5048
|
-
}
|
|
5049
|
-
async function analyzeVueSFC(content) {
|
|
5050
|
-
const keys = [];
|
|
5051
|
-
let hasDynamic = false;
|
|
5052
|
-
let parse2;
|
|
5053
|
-
try {
|
|
5054
|
-
const compilerSfc = await import('vue/compiler-sfc');
|
|
5055
|
-
parse2 = compilerSfc.parse;
|
|
5056
|
-
} catch {
|
|
5057
|
-
const templateResult = extractKeysFromTemplate(content);
|
|
5058
|
-
const scriptResult = await extractKeysFromScript(content);
|
|
5059
|
-
return {
|
|
5060
|
-
keys: [...templateResult.keys, ...scriptResult.keys],
|
|
5061
|
-
hasDynamic: templateResult.hasDynamic || scriptResult.hasDynamic
|
|
5062
|
-
};
|
|
5063
|
-
}
|
|
5064
|
-
const { descriptor } = parse2(content);
|
|
5065
|
-
if (descriptor.template?.content) {
|
|
5066
|
-
const templateResult = extractKeysFromTemplate(descriptor.template.content);
|
|
5067
|
-
keys.push(...templateResult.keys);
|
|
5068
|
-
if (templateResult.hasDynamic) {
|
|
5069
|
-
hasDynamic = true;
|
|
5070
|
-
}
|
|
5071
|
-
}
|
|
5072
|
-
const scriptContent = descriptor.scriptSetup?.content || descriptor.script?.content;
|
|
5073
|
-
if (scriptContent) {
|
|
5074
|
-
const scriptResult = await extractKeysFromScript(scriptContent);
|
|
5075
|
-
keys.push(...scriptResult.keys);
|
|
5076
|
-
if (scriptResult.hasDynamic) {
|
|
5077
|
-
hasDynamic = true;
|
|
5078
|
-
}
|
|
5079
|
-
}
|
|
5080
|
-
return { keys, hasDynamic };
|
|
5081
|
-
}
|
|
5082
|
-
async function analyzeFile(content, filePath, collector) {
|
|
5083
|
-
let result;
|
|
5084
|
-
if (filePath.endsWith(".vue")) {
|
|
5085
|
-
result = await analyzeVueSFC(content);
|
|
5086
|
-
} else {
|
|
5087
|
-
result = await extractKeysFromScript(content);
|
|
5088
|
-
}
|
|
5089
|
-
for (const key of result.keys) {
|
|
5090
|
-
collector.addKey(key);
|
|
5091
|
-
}
|
|
5092
|
-
if (result.hasDynamic) {
|
|
5093
|
-
collector.markDynamic();
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
|
-
const debug$1$1 = createDebug(resolveNamespace("tree-shaking"));
|
|
5097
|
-
function treeShakingPlugin(resolvedOptions, collector) {
|
|
5098
|
-
let projectRoot = "";
|
|
5099
|
-
return {
|
|
5100
|
-
name: resolveNamespace("tree-shaking"),
|
|
5101
|
-
enforce: "pre",
|
|
5102
|
-
vite: {
|
|
5103
|
-
configResolved(config) {
|
|
5104
|
-
projectRoot = config.root;
|
|
5105
|
-
}
|
|
5106
|
-
},
|
|
5107
|
-
webpack(compiler) {
|
|
5108
|
-
projectRoot = compiler.options.context || process.cwd();
|
|
5109
|
-
},
|
|
5110
|
-
async buildStart() {
|
|
5111
|
-
const treeShaking = resolvedOptions.treeShaking;
|
|
5112
|
-
const patterns = treeShaking?.scanPatterns || [`${projectRoot}/src/**/*.{vue,ts,js,tsx,jsx}`];
|
|
5113
|
-
debug$1$1("scanning patterns:", patterns);
|
|
5114
|
-
const files = await glob(patterns, {
|
|
5115
|
-
ignore: ["**/node_modules/**"],
|
|
5116
|
-
absolute: true
|
|
3953
|
+
server.ws.send({ type: "full-reload" });
|
|
3954
|
+
};
|
|
3955
|
+
server.watcher.on("add", invalidate);
|
|
3956
|
+
server.watcher.on("unlink", invalidate);
|
|
3957
|
+
server.httpServer?.once("close", () => {
|
|
3958
|
+
server.watcher.off("add", invalidate);
|
|
3959
|
+
server.watcher.off("unlink", invalidate);
|
|
5117
3960
|
});
|
|
5118
|
-
debug$1$1(`found ${files.length} source files to scan`);
|
|
5119
|
-
for (const file of files) {
|
|
5120
|
-
try {
|
|
5121
|
-
const content = await promises.readFile(file, "utf-8");
|
|
5122
|
-
await analyzeFile(content, file, collector);
|
|
5123
|
-
} catch (err) {
|
|
5124
|
-
debug$1$1(`failed to analyze file: ${file}`, err);
|
|
5125
|
-
}
|
|
5126
|
-
}
|
|
5127
|
-
debug$1$1(
|
|
5128
|
-
`scan complete: ${collector.usedKeys.size} used keys found, dynamic: ${collector.dynamicKeysDetected}`
|
|
5129
|
-
);
|
|
5130
|
-
if (collector.dynamicKeysDetected) {
|
|
5131
|
-
const strategy = treeShaking?.dynamicKeyStrategy || "keep-all";
|
|
5132
|
-
if (strategy === "keep-all") {
|
|
5133
|
-
warn(
|
|
5134
|
-
"Tree-shaking: dynamic key usage detected. All keys will be preserved (dynamicKeyStrategy: keep-all)."
|
|
5135
|
-
);
|
|
5136
|
-
} else {
|
|
5137
|
-
warn(
|
|
5138
|
-
"Tree-shaking: dynamic key usage detected. Unused keys will still be removed (dynamicKeyStrategy: ignore)."
|
|
5139
|
-
);
|
|
5140
|
-
}
|
|
5141
|
-
}
|
|
5142
|
-
},
|
|
5143
|
-
buildEnd() {
|
|
5144
|
-
const diagnostics = collector.getDiagnostics();
|
|
5145
|
-
if (diagnostics.totalRemoved > 0) {
|
|
5146
|
-
debug$1$1(`tree-shaking: removed ${diagnostics.totalRemoved} unused message keys`);
|
|
5147
|
-
for (const [file, keys] of diagnostics.byFile) {
|
|
5148
|
-
debug$1$1(` ${file}: removed ${keys.length} keys (${keys.join(", ")})`);
|
|
5149
|
-
}
|
|
5150
|
-
} else {
|
|
5151
|
-
debug$1$1("tree-shaking: no keys removed");
|
|
5152
|
-
}
|
|
5153
3961
|
}
|
|
5154
3962
|
};
|
|
5155
3963
|
}
|
|
5156
|
-
const debug$4 = createDebug(resolveNamespace("root"));
|
|
5157
|
-
const unpluginFactory = (options = {}, meta) => {
|
|
5158
|
-
debug$4("meta framework", meta.framework);
|
|
5159
|
-
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
5160
|
-
raiseError(`This plugin is supported 'vite' and 'webpack' only`);
|
|
5161
|
-
}
|
|
5162
|
-
debug$4("plugin options (resolving):", options);
|
|
5163
|
-
const resolvedOptions = resolveOptions(options);
|
|
5164
|
-
debug$4("plugin options (resolved):", resolvedOptions);
|
|
5165
|
-
const collector = resolvedOptions.treeShaking ? createUsedKeysCollector(resolvedOptions.treeShaking) : null;
|
|
5166
|
-
const plugins = [];
|
|
5167
|
-
if (resolvedOptions.treeShaking && collector) {
|
|
5168
|
-
plugins.push(treeShakingPlugin(resolvedOptions, collector));
|
|
5169
|
-
}
|
|
5170
|
-
plugins.push(resourcePlugin(resolvedOptions, meta, collector));
|
|
5171
|
-
if (resolvedOptions.optimizeTranslationDirective) {
|
|
5172
|
-
if (meta.framework === "webpack") {
|
|
5173
|
-
raiseError(
|
|
5174
|
-
`The 'optimizeTranslationDirective' option still is not supported for webpack.
|
|
5175
|
-
We are waiting for your Pull Request \u{1F642}.`
|
|
5176
|
-
);
|
|
5177
|
-
}
|
|
5178
|
-
plugins.push(directivePlugin(resolvedOptions));
|
|
5179
|
-
}
|
|
5180
|
-
return plugins;
|
|
5181
|
-
};
|
|
5182
|
-
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
5183
|
-
|
|
5184
|
-
const VueI18n = unplugin.vite;
|
|
5185
3964
|
|
|
5186
3965
|
function createLlmsPlugin(options) {
|
|
5187
3966
|
const llmsConfig = options.config.siteConfig.llms;
|
|
@@ -5218,51 +3997,30 @@ function createLlmsPlugin(options) {
|
|
|
5218
3997
|
}
|
|
5219
3998
|
};
|
|
5220
3999
|
}
|
|
5221
|
-
|
|
5222
|
-
const
|
|
5223
|
-
const siteConfig = config.siteConfig;
|
|
4000
|
+
function llmsDocumentInput(options, posts) {
|
|
4001
|
+
const siteConfig = options.config.siteConfig;
|
|
5224
4002
|
const lang = siteConfig.lang || "en";
|
|
5225
|
-
const
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
title,
|
|
5231
|
-
description,
|
|
5232
|
-
prompt: siteConfig.llms.prompt,
|
|
4003
|
+
const llms = siteConfig.llms;
|
|
4004
|
+
return {
|
|
4005
|
+
title: resolveText(siteConfig.title, lang) || "Valaxy Blog",
|
|
4006
|
+
description: resolveText(siteConfig.description, lang),
|
|
4007
|
+
prompt: llms.prompt,
|
|
5233
4008
|
posts,
|
|
5234
|
-
siteUrl
|
|
5235
|
-
|
|
4009
|
+
siteUrl: getSiteUrl(options),
|
|
4010
|
+
exclude: llms.exclude,
|
|
4011
|
+
locales: llms.locales,
|
|
4012
|
+
sectionOrder: llms.sectionOrder,
|
|
4013
|
+
featured: llms.featured,
|
|
4014
|
+
collapse: llms.collapse
|
|
4015
|
+
};
|
|
5236
4016
|
}
|
|
5237
|
-
async function
|
|
5238
|
-
const
|
|
5239
|
-
|
|
5240
|
-
const lang = siteConfig.lang || "en";
|
|
5241
|
-
const posts = await collectPosts(options, lang);
|
|
5242
|
-
const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
|
|
5243
|
-
const description = resolveText(siteConfig.description, lang);
|
|
5244
|
-
return generateLlmsFullTxt({
|
|
5245
|
-
title,
|
|
5246
|
-
description,
|
|
5247
|
-
prompt: siteConfig.llms.prompt,
|
|
5248
|
-
posts
|
|
5249
|
-
});
|
|
4017
|
+
async function buildLlmsTxt(options) {
|
|
4018
|
+
const posts = await loadLlmsPosts(options);
|
|
4019
|
+
return generateLlmsTxt(llmsDocumentInput(options, posts));
|
|
5250
4020
|
}
|
|
5251
|
-
async function
|
|
5252
|
-
const
|
|
5253
|
-
|
|
5254
|
-
const rawPosts = await readPostFiles(files);
|
|
5255
|
-
const publicPosts = filterPublicPosts(rawPosts);
|
|
5256
|
-
const posts = publicPosts.map(({ data, content, filePath }) => ({
|
|
5257
|
-
title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
|
|
5258
|
-
description: resolveText(data.description, lang) || "",
|
|
5259
|
-
date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
|
|
5260
|
-
urlPath: filePathToUrlPath(filePath, options.userRoot),
|
|
5261
|
-
content,
|
|
5262
|
-
rawFrontmatter: stripSensitiveFrontmatter(data)
|
|
5263
|
-
}));
|
|
5264
|
-
posts.sort((a, b) => +b.date - +a.date);
|
|
5265
|
-
return posts;
|
|
4021
|
+
async function buildLlmsFullTxt(options) {
|
|
4022
|
+
const posts = await loadLlmsPosts(options);
|
|
4023
|
+
return generateLlmsFullTxt(llmsDocumentInput(options, posts));
|
|
5266
4024
|
}
|
|
5267
4025
|
async function resolveRawMd(url, options) {
|
|
5268
4026
|
const page = url.slice(1);
|
|
@@ -5280,6 +4038,7 @@ async function resolveRawMd(url, options) {
|
|
|
5280
4038
|
title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
|
|
5281
4039
|
description: resolveText(data.description, lang) || "",
|
|
5282
4040
|
date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
|
|
4041
|
+
sourcePath: getPagePath(filePath, options.userRoot),
|
|
5283
4042
|
rawFrontmatter: cleanedFrontmatter
|
|
5284
4043
|
};
|
|
5285
4044
|
const header = formatMetadataHeader(post);
|
|
@@ -6720,7 +5479,7 @@ function cacheMarkdownRender(md, state, base, fileInfoFor) {
|
|
|
6720
5479
|
maxSize: 32 * 1024 * 1024,
|
|
6721
5480
|
sizeCalculation: (item) => item.bytes
|
|
6722
5481
|
});
|
|
6723
|
-
const log =
|
|
5482
|
+
const log = _debug("valaxy:md");
|
|
6724
5483
|
const getBase = createMarkdownBaseResolver(base);
|
|
6725
5484
|
const render = md.renderAsync.bind(md);
|
|
6726
5485
|
let active = true;
|
|
@@ -6755,7 +5514,7 @@ function cacheMarkdownRender(md, state, base, fileInfoFor) {
|
|
|
6755
5514
|
const KNOWN_EXTENSIONS = /* @__PURE__ */ new Set();
|
|
6756
5515
|
function treatAsHtml(filename) {
|
|
6757
5516
|
if (KNOWN_EXTENSIONS.size === 0) {
|
|
6758
|
-
const extraExts = typeof process
|
|
5517
|
+
const extraExts = typeof process === "object" && process.env.VITE_EXTRA_EXTENSIONS || process.env?.VITE_EXTRA_EXTENSIONS || "";
|
|
6759
5518
|
`3g2,3gp,aac,ai,apng,au,avif,bin,bmp,cer,class,conf,crl,css,csv,dll,doc,eps,epub,exe,gif,gz,ics,ief,jar,jpe,jpeg,jpg,js,json,jsonld,m4a,man,mid,midi,mjs,mov,mp2,mp3,mp4,mpe,mpeg,mpg,mpp,oga,ogg,ogv,ogx,opus,otf,p10,p7c,p7m,p7s,pdf,png,ps,qt,roff,rtf,rtx,ser,svg,t,tif,tiff,tr,ts,tsv,ttf,txt,vtt,wav,weba,webm,webp,woff,woff2,xhtml,xml,yaml,yml,zip${extraExts && typeof extraExts === "string" ? `,${extraExts}` : ""}`.split(",").forEach((ext2) => KNOWN_EXTENSIONS.add(ext2));
|
|
6760
5519
|
}
|
|
6761
5520
|
const ext = filename.split(".").pop();
|
|
@@ -6805,7 +5564,7 @@ function resolveTransformIncludes(code, id, options) {
|
|
|
6805
5564
|
code = code.replace(includedRE, (m, m1) => {
|
|
6806
5565
|
const atPresent = m1.startsWith("@");
|
|
6807
5566
|
const includePath = atPresent ? path$1.resolve(options.userRoot, m1.slice(m1[1] === "/" ? 2 : 1)) : path$1.join(dir, m1);
|
|
6808
|
-
includes.push(slash$
|
|
5567
|
+
includes.push(slash$1(includePath));
|
|
6809
5568
|
return "";
|
|
6810
5569
|
});
|
|
6811
5570
|
return {
|
|
@@ -6956,7 +5715,7 @@ async function createLightMarkdownRenderer(options, base) {
|
|
|
6956
5715
|
return md;
|
|
6957
5716
|
}
|
|
6958
5717
|
|
|
6959
|
-
const debug$1 =
|
|
5718
|
+
const debug$1 = _debug("valaxy:local-search");
|
|
6960
5719
|
const LOCAL_SEARCH_INDEX_ID = "@localSearchIndex";
|
|
6961
5720
|
const LOCAL_SEARCH_INDEX_REQUEST_PATH = `/${LOCAL_SEARCH_INDEX_ID}`;
|
|
6962
5721
|
async function localSearchPlugin(options, base) {
|
|
@@ -6981,7 +5740,7 @@ async function localSearchPlugin(options, base) {
|
|
|
6981
5740
|
async function render(file) {
|
|
6982
5741
|
if (!fs.existsSync(file))
|
|
6983
5742
|
return { html: "", shared: false };
|
|
6984
|
-
const relativePath = getPagePath(file, options.userRoot) || slash$
|
|
5743
|
+
const relativePath = getPagePath(file, options.userRoot) || slash$1(path.relative(srcDir, file));
|
|
6985
5744
|
const env = { path: file, relativePath };
|
|
6986
5745
|
const mdRaw = await fs.promises.readFile(file, "utf-8");
|
|
6987
5746
|
const { data: fm, content } = matter(mdRaw, matterOptions);
|
|
@@ -7025,8 +5784,8 @@ async function localSearchPlugin(options, base) {
|
|
|
7025
5784
|
}
|
|
7026
5785
|
}
|
|
7027
5786
|
function getDocId(file) {
|
|
7028
|
-
const relFile = getPagePath(file, options.userRoot) || slash$
|
|
7029
|
-
let id = slash$
|
|
5787
|
+
const relFile = getPagePath(file, options.userRoot) || slash$1(path.relative(srcDir, file));
|
|
5788
|
+
let id = slash$1(path.join("/", relFile));
|
|
7030
5789
|
id = id.replace(/(^|\/)index\.md$/, "$1");
|
|
7031
5790
|
id = id.replace(/\.md$/, "");
|
|
7032
5791
|
return id;
|
|
@@ -7152,7 +5911,7 @@ async function localSearchPlugin(options, base) {
|
|
|
7152
5911
|
},
|
|
7153
5912
|
async load(id) {
|
|
7154
5913
|
if (id === LOCAL_SEARCH_INDEX_REQUEST_PATH) {
|
|
7155
|
-
if (process
|
|
5914
|
+
if (process.env.NODE_ENV === "production") {
|
|
7156
5915
|
await scanForBuild();
|
|
7157
5916
|
}
|
|
7158
5917
|
const records = [];
|
|
@@ -7174,7 +5933,7 @@ async function localSearchPlugin(options, base) {
|
|
|
7174
5933
|
},
|
|
7175
5934
|
async handleHotUpdate({ file }) {
|
|
7176
5935
|
if (file.endsWith(".md")) {
|
|
7177
|
-
const relPath = getPagePath(file, options.userRoot) || slash$
|
|
5936
|
+
const relPath = getPagePath(file, options.userRoot) || slash$1(path.relative(srcDir, file));
|
|
7178
5937
|
if (!relPath.startsWith("..")) {
|
|
7179
5938
|
changedPages.add(relPath);
|
|
7180
5939
|
await flushUpdates();
|
|
@@ -7283,7 +6042,7 @@ function createScanDeadLinks(options) {
|
|
|
7283
6042
|
if (url.endsWith("/"))
|
|
7284
6043
|
url += `index`;
|
|
7285
6044
|
const resolved = decodeURIComponent(
|
|
7286
|
-
slash$
|
|
6045
|
+
slash$1(
|
|
7287
6046
|
url.startsWith("/") ? url.slice(1) : path$1.normalize(path$1.join(path$1.dirname(logicalFile), url))
|
|
7288
6047
|
)
|
|
7289
6048
|
// /index => /
|
|
@@ -7310,7 +6069,7 @@ function createTransformEncrypt(options) {
|
|
|
7310
6069
|
"</ClientOnly>"
|
|
7311
6070
|
].join("");
|
|
7312
6071
|
};
|
|
7313
|
-
const globalPassword = process
|
|
6072
|
+
const globalPassword = process.env.VALAXY_ENCRYPT_PASSWORD;
|
|
7314
6073
|
const password = frontmatter.password || frontmatter.encrypt === true && globalPassword || void 0;
|
|
7315
6074
|
if (password && !frontmatter.password && globalPassword) {
|
|
7316
6075
|
if (!globalPasswordLoggedOnce) {
|
|
@@ -7520,7 +6279,7 @@ async function generatePageData(code, context, options) {
|
|
|
7520
6279
|
return pageData;
|
|
7521
6280
|
}
|
|
7522
6281
|
|
|
7523
|
-
const debug =
|
|
6282
|
+
const debug = _debug("valaxy:md");
|
|
7524
6283
|
const caches = /* @__PURE__ */ new WeakMap();
|
|
7525
6284
|
function getMarkdownCache(state) {
|
|
7526
6285
|
let cache = caches.get(state);
|
|
@@ -7629,7 +6388,7 @@ function createClientSetupPlugin(options) {
|
|
|
7629
6388
|
if (legacySetup)
|
|
7630
6389
|
warnMermaidMigration(options, legacySetup);
|
|
7631
6390
|
}
|
|
7632
|
-
const setupEntry = slash$
|
|
6391
|
+
const setupEntry = slash$1(resolve(clientRoot, "setup"));
|
|
7633
6392
|
return {
|
|
7634
6393
|
name: "valaxy:setup",
|
|
7635
6394
|
enforce: "pre",
|
|
@@ -8052,7 +6811,7 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
8052
6811
|
};
|
|
8053
6812
|
const configFiles = [options.configFile, options.siteConfigFile, resolve$1(options.themeRoot, "valaxy.config.ts")];
|
|
8054
6813
|
if (configFiles.includes(file)) {
|
|
8055
|
-
const { config } = await resolveOptions$
|
|
6814
|
+
const { config } = await resolveOptions$1({ userRoot: options.userRoot });
|
|
8056
6815
|
return reloadConfigAndEntries(config);
|
|
8057
6816
|
}
|
|
8058
6817
|
if (file === options.themeConfigFile) {
|
|
@@ -8200,8 +6959,12 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
8200
6959
|
}
|
|
8201
6960
|
}
|
|
8202
6961
|
const path = route.components.get("default") || "";
|
|
8203
|
-
|
|
8204
|
-
|
|
6962
|
+
const md = path.endsWith(".md") ? await fs.readFile(path, "utf-8").catch((e) => {
|
|
6963
|
+
if (e.code === "ENOENT" || e.code === "ENOTDIR")
|
|
6964
|
+
return void 0;
|
|
6965
|
+
throw e;
|
|
6966
|
+
}) : void 0;
|
|
6967
|
+
if (md !== void 0) {
|
|
8205
6968
|
const { data, excerpt, content } = parseMatter(md);
|
|
8206
6969
|
const mdFm = data;
|
|
8207
6970
|
const lastUpdated = valaxyConfig.siteConfig.lastUpdated;
|
|
@@ -8479,17 +7242,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {},
|
|
|
8479
7242
|
Unhead(),
|
|
8480
7243
|
// https://router.vuejs.org/file-based-routing/
|
|
8481
7244
|
RouterPlugin,
|
|
8482
|
-
|
|
8483
|
-
Layout({
|
|
8484
|
-
layoutsDirs: roots.map((root) => `${root}/layouts`),
|
|
8485
|
-
// In SSG builds, layout components must be imported synchronously so that
|
|
8486
|
-
// the client-side hydration tree matches the server-rendered HTML. Without
|
|
8487
|
-
// this, non-default layouts (post, home, etc.) are lazy-loaded and haven't
|
|
8488
|
-
// resolved when hydration starts, causing a mismatch. The built-in SSG
|
|
8489
|
-
// engine needs an explicit importMode override to force synchronous imports.
|
|
8490
|
-
...options.mode === "build" ? { importMode: () => "sync" } : {},
|
|
8491
|
-
...valaxyConfig.layouts
|
|
8492
|
-
}),
|
|
7245
|
+
createLayoutsPlugin(options),
|
|
8493
7246
|
// https://github.com/antfu/unplugin-vue-components
|
|
8494
7247
|
Components({
|
|
8495
7248
|
extensions: ["vue", "md"],
|
|
@@ -8568,13 +7321,13 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {},
|
|
|
8568
7321
|
}
|
|
8569
7322
|
|
|
8570
7323
|
async function profileBuildPhase(phase, run) {
|
|
8571
|
-
if (!process
|
|
7324
|
+
if (!process.env.VALAXY_BUILD_PROFILE)
|
|
8572
7325
|
return run();
|
|
8573
7326
|
const started = performance.now();
|
|
8574
7327
|
try {
|
|
8575
7328
|
return await run();
|
|
8576
7329
|
} finally {
|
|
8577
|
-
process
|
|
7330
|
+
process.stdout.write(`[valaxy:build] ${JSON.stringify({ phase, durationMs: performance.now() - started, rssMiB: process.memoryUsage().rss / 1024 / 1024 })}
|
|
8578
7331
|
`);
|
|
8579
7332
|
}
|
|
8580
7333
|
}
|
|
@@ -8657,7 +7410,15 @@ function serializeState(state) {
|
|
|
8657
7410
|
const serialised = JSON.stringify(state).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
8658
7411
|
return `<script>window.__INITIAL_STATE__='${serialised}'<\/script>`;
|
|
8659
7412
|
}
|
|
7413
|
+
function decodePathSegment(segment) {
|
|
7414
|
+
try {
|
|
7415
|
+
return decodeURIComponent(segment);
|
|
7416
|
+
} catch {
|
|
7417
|
+
return segment;
|
|
7418
|
+
}
|
|
7419
|
+
}
|
|
8660
7420
|
function routeToFileName(route) {
|
|
7421
|
+
route = route.split("/").map(decodePathSegment).join("/");
|
|
8661
7422
|
if (route.endsWith("/"))
|
|
8662
7423
|
return `${route}index.html`.slice(1);
|
|
8663
7424
|
if (route.endsWith(".html"))
|
|
@@ -9146,7 +7907,7 @@ function getServerInfoText(msg) {
|
|
|
9146
7907
|
return `${valaxyPrefix} ${colors.gray(msg)}`;
|
|
9147
7908
|
}
|
|
9148
7909
|
async function createServer(valaxyApp, viteConfig = {}, serverOptions = {}) {
|
|
9149
|
-
process
|
|
7910
|
+
process.env.EDITOR = process.env.EDITOR || "code";
|
|
9150
7911
|
const { options } = valaxyApp;
|
|
9151
7912
|
const pluginsTimer = countPerformanceTime();
|
|
9152
7913
|
const plugins = await ViteValaxyPlugins(valaxyApp, serverOptions, viteConfig);
|
|
@@ -9280,7 +8041,7 @@ async function initServer(valaxyApp, viteConfig) {
|
|
|
9280
8041
|
} catch (e) {
|
|
9281
8042
|
consola.error("failed to start server. error:\n");
|
|
9282
8043
|
console.error(e);
|
|
9283
|
-
process
|
|
8044
|
+
process.exit(1);
|
|
9284
8045
|
}
|
|
9285
8046
|
}
|
|
9286
8047
|
|
|
@@ -9289,7 +8050,7 @@ async function execBuild({ ssg, root, output, log, siteUrl }) {
|
|
|
9289
8050
|
if (!await isPagesDirExist(root))
|
|
9290
8051
|
throw new Error(`Pages directory not found: ${root}`);
|
|
9291
8052
|
const userRoot = path.resolve(root);
|
|
9292
|
-
const options = await profileBuildPhase("resolve-options", () => resolveOptions$
|
|
8053
|
+
const options = await profileBuildPhase("resolve-options", () => resolveOptions$1({ userRoot }, "build"));
|
|
9293
8054
|
if (siteUrl)
|
|
9294
8055
|
options.config.siteConfig.url = siteUrl;
|
|
9295
8056
|
setTimezone(options.config.siteConfig.timezone);
|
|
@@ -9369,8 +8130,8 @@ function registerBuildCommand(cli) {
|
|
|
9369
8130
|
}
|
|
9370
8131
|
|
|
9371
8132
|
async function cleanDist() {
|
|
9372
|
-
const distDir = path.join(process
|
|
9373
|
-
const cacheDir = path.join(process
|
|
8133
|
+
const distDir = path.join(process.cwd(), "dist");
|
|
8134
|
+
const cacheDir = path.join(process.cwd(), ".valaxy");
|
|
9374
8135
|
consola.box("\u{1F9F9} Starting clean...");
|
|
9375
8136
|
if (await fs.exists(distDir)) {
|
|
9376
8137
|
consola.info("dist directory exists, removing...");
|
|
@@ -9410,28 +8171,8 @@ function registerCleanCommand(cli) {
|
|
|
9410
8171
|
}
|
|
9411
8172
|
|
|
9412
8173
|
async function resolveContentLayouts(options) {
|
|
9413
|
-
const
|
|
9414
|
-
|
|
9415
|
-
const plugin = Layout({
|
|
9416
|
-
...configured,
|
|
9417
|
-
// Array form selects the server-side registry generator, including for one directory.
|
|
9418
|
-
layoutsDirs: Array.isArray(dirs) ? dirs : [dirs]
|
|
9419
|
-
});
|
|
9420
|
-
const configure = plugin.configResolved;
|
|
9421
|
-
const load = plugin.load;
|
|
9422
|
-
configure({ root: options.userRoot });
|
|
9423
|
-
const source = await load("/@vite-plugin-vue-layouts-next/generated-layouts");
|
|
9424
|
-
const ast = babelParse(source.code, { sourceType: "module" });
|
|
9425
|
-
for (const statement of ast.program.body) {
|
|
9426
|
-
if (statement.type !== "ExportNamedDeclaration" || statement.declaration?.type !== "VariableDeclaration")
|
|
9427
|
-
continue;
|
|
9428
|
-
for (const declaration of statement.declaration.declarations) {
|
|
9429
|
-
if (declaration.id.type !== "Identifier" || declaration.id.name !== "layouts" || declaration.init?.type !== "ObjectExpression")
|
|
9430
|
-
continue;
|
|
9431
|
-
return new Set(declaration.init.properties.flatMap((property) => property.type === "ObjectProperty" && property.key.type === "StringLiteral" ? [property.key.value] : []));
|
|
9432
|
-
}
|
|
9433
|
-
}
|
|
9434
|
-
throw new Error("Layout registry was not generated");
|
|
8174
|
+
const layouts = await scanLayouts(resolveLayoutsOptions(options, options.config.layouts));
|
|
8175
|
+
return new Set(layouts.keys());
|
|
9435
8176
|
}
|
|
9436
8177
|
|
|
9437
8178
|
const safeMatterOptions = {
|
|
@@ -9501,7 +8242,7 @@ function createContentService(app, settings = {}) {
|
|
|
9501
8242
|
const options = await routerOptions;
|
|
9502
8243
|
const routes = [];
|
|
9503
8244
|
routerApp.options.redirects.length = 0;
|
|
9504
|
-
const context = createRoutesContext(resolveOptions$
|
|
8245
|
+
const context = createRoutesContext(resolveOptions$2({
|
|
9505
8246
|
...options,
|
|
9506
8247
|
root: userRoot,
|
|
9507
8248
|
dts: false,
|
|
@@ -9726,7 +8467,7 @@ function registerContentCommands(cli) {
|
|
|
9726
8467
|
setEnv();
|
|
9727
8468
|
if (json)
|
|
9728
8469
|
setLogLevel(-999);
|
|
9729
|
-
const options = await resolveOptions$
|
|
8470
|
+
const options = await resolveOptions$1({ userRoot: resolve$1(root) });
|
|
9730
8471
|
setTimezone(options.config.siteConfig.timezone);
|
|
9731
8472
|
const app = createValaxyNode(options);
|
|
9732
8473
|
if (options.config.loaders?.length) {
|
|
@@ -9742,7 +8483,7 @@ function registerContentCommands(cli) {
|
|
|
9742
8483
|
});
|
|
9743
8484
|
const result = command === "inspect" ? await service.inspectPage(file) : await service.checkPage(file);
|
|
9744
8485
|
if ("ok" in result && !result.ok)
|
|
9745
|
-
process
|
|
8486
|
+
process.exitCode = 1;
|
|
9746
8487
|
if (json || !("diagnostics" in result)) {
|
|
9747
8488
|
console.log(JSON.stringify(result, null, 2));
|
|
9748
8489
|
} else {
|
|
@@ -9752,7 +8493,7 @@ function registerContentCommands(cli) {
|
|
|
9752
8493
|
${diagnostic.hint}`);
|
|
9753
8494
|
}
|
|
9754
8495
|
} catch (error) {
|
|
9755
|
-
process
|
|
8496
|
+
process.exitCode = 1;
|
|
9756
8497
|
const message = error instanceof Error ? error.message : "Content inspection failed";
|
|
9757
8498
|
if (json)
|
|
9758
8499
|
console.log(JSON.stringify({ path: file, ok: false, error: message }));
|
|
@@ -9779,12 +8520,12 @@ async function collectDebugInfo() {
|
|
|
9779
8520
|
const info = {
|
|
9780
8521
|
os: os.platform(),
|
|
9781
8522
|
arch: os.arch(),
|
|
9782
|
-
node: process
|
|
8523
|
+
node: process.version,
|
|
9783
8524
|
pnpm: getPnpmVersion(),
|
|
9784
8525
|
valaxy: version
|
|
9785
8526
|
};
|
|
9786
8527
|
try {
|
|
9787
|
-
const options = await resolveOptions$
|
|
8528
|
+
const options = await resolveOptions$1({ userRoot: process.cwd() });
|
|
9788
8529
|
info.userRoot = options.userRoot;
|
|
9789
8530
|
info.theme = options.theme;
|
|
9790
8531
|
info.themeVersion = options.config.themeConfig?.pkg?.version;
|
|
@@ -9892,12 +8633,12 @@ function registerDeployCommand(cli) {
|
|
|
9892
8633
|
});
|
|
9893
8634
|
if (isCancel(shouldBuild)) {
|
|
9894
8635
|
cancel("Operation cancelled.");
|
|
9895
|
-
process
|
|
8636
|
+
process.exit(0);
|
|
9896
8637
|
}
|
|
9897
8638
|
if (shouldBuild) {
|
|
9898
8639
|
await execBuild({ ssg: true, root, output, log: "info" });
|
|
9899
8640
|
}
|
|
9900
|
-
const options = await resolveOptions$
|
|
8641
|
+
const options = await resolveOptions$1({ userRoot: root }, "build");
|
|
9901
8642
|
const configDeployType = type ?? options.config.deploy?.type;
|
|
9902
8643
|
const deployType = configDeployType ?? await select({
|
|
9903
8644
|
message: "Where do you want to deploy?",
|
|
@@ -9908,7 +8649,7 @@ function registerDeployCommand(cli) {
|
|
|
9908
8649
|
});
|
|
9909
8650
|
if (isCancel(deployType)) {
|
|
9910
8651
|
cancel("Operation cancelled.");
|
|
9911
|
-
process
|
|
8652
|
+
process.exit(0);
|
|
9912
8653
|
}
|
|
9913
8654
|
if (deployType === "gh-pages") {
|
|
9914
8655
|
let isGhPagesInstalled = false;
|
|
@@ -9921,7 +8662,7 @@ function registerDeployCommand(cli) {
|
|
|
9921
8662
|
});
|
|
9922
8663
|
if (isCancel(installGhPages)) {
|
|
9923
8664
|
cancel("Operation cancelled.");
|
|
9924
|
-
process
|
|
8665
|
+
process.exit(0);
|
|
9925
8666
|
}
|
|
9926
8667
|
if (installGhPages) {
|
|
9927
8668
|
try {
|
|
@@ -10008,7 +8749,7 @@ const SHORTCUTS = [
|
|
|
10008
8749
|
key: "e",
|
|
10009
8750
|
description: "edit",
|
|
10010
8751
|
action() {
|
|
10011
|
-
exec(`code "${process
|
|
8752
|
+
exec(`code "${process.cwd()}"`, (err) => {
|
|
10012
8753
|
if (err)
|
|
10013
8754
|
console.error("Failed to open editor", err);
|
|
10014
8755
|
});
|
|
@@ -10016,15 +8757,15 @@ const SHORTCUTS = [
|
|
|
10016
8757
|
}
|
|
10017
8758
|
];
|
|
10018
8759
|
function bindShortcuts(server, createDevServer) {
|
|
10019
|
-
if (!server.httpServer || !process
|
|
8760
|
+
if (!server.httpServer || !process.stdin.isTTY || process.env.CI)
|
|
10020
8761
|
return;
|
|
10021
|
-
process
|
|
10022
|
-
process
|
|
10023
|
-
readline.emitKeypressEvents(process
|
|
10024
|
-
process
|
|
8762
|
+
process.stdin.resume();
|
|
8763
|
+
process.stdin.setEncoding("utf8");
|
|
8764
|
+
readline.emitKeypressEvents(process.stdin);
|
|
8765
|
+
process.stdin.setRawMode(true);
|
|
10025
8766
|
async function onKeyPress(str, key) {
|
|
10026
8767
|
if (key.ctrl && key.name === "c") {
|
|
10027
|
-
process
|
|
8768
|
+
process.exit();
|
|
10028
8769
|
} else {
|
|
10029
8770
|
const shortcut = SHORTCUTS.find((shortcut2) => shortcut2.key === str);
|
|
10030
8771
|
if (!shortcut)
|
|
@@ -10036,14 +8777,14 @@ function bindShortcuts(server, createDevServer) {
|
|
|
10036
8777
|
}
|
|
10037
8778
|
}
|
|
10038
8779
|
}
|
|
10039
|
-
process
|
|
8780
|
+
process.stdin.on("keypress", onKeyPress);
|
|
10040
8781
|
server.httpServer.on("close", () => {
|
|
10041
|
-
process
|
|
8782
|
+
process.stdin.off("keypress", onKeyPress);
|
|
10042
8783
|
});
|
|
10043
8784
|
}
|
|
10044
8785
|
|
|
10045
8786
|
async function startValaxyDev({
|
|
10046
|
-
root = process
|
|
8787
|
+
root = process.cwd(),
|
|
10047
8788
|
port,
|
|
10048
8789
|
remote,
|
|
10049
8790
|
log,
|
|
@@ -10055,10 +8796,10 @@ async function startValaxyDev({
|
|
|
10055
8796
|
if (log === "debug")
|
|
10056
8797
|
setLogLevel(4);
|
|
10057
8798
|
if (!await isPagesDirExist(root))
|
|
10058
|
-
process
|
|
8799
|
+
process.exit(0);
|
|
10059
8800
|
port = port || await findFreePort(4859);
|
|
10060
8801
|
const resolveTimer = countPerformanceTime();
|
|
10061
|
-
const resolvedOptions = await resolveOptions$
|
|
8802
|
+
const resolvedOptions = await resolveOptions$1({ userRoot: root });
|
|
10062
8803
|
vLogger.debug(`resolveOptions: ${resolveTimer()}`);
|
|
10063
8804
|
setTimezone(resolvedOptions.config.siteConfig.timezone);
|
|
10064
8805
|
const createNodeTimer = countPerformanceTime();
|
|
@@ -10168,7 +8909,7 @@ function registerDevCommand(cli) {
|
|
|
10168
8909
|
);
|
|
10169
8910
|
}
|
|
10170
8911
|
|
|
10171
|
-
const userRoot = process
|
|
8912
|
+
const userRoot = process.cwd();
|
|
10172
8913
|
const defaultPostTemplate = `---
|
|
10173
8914
|
layout: <%=layout%>
|
|
10174
8915
|
title: <%=title%>
|
|
@@ -10177,7 +8918,7 @@ date: <%=date%>
|
|
|
10177
8918
|
`;
|
|
10178
8919
|
|
|
10179
8920
|
async function getTemplate(layout) {
|
|
10180
|
-
const { clientRoot, themeRoot } = await resolveOptions$
|
|
8921
|
+
const { clientRoot, themeRoot } = await resolveOptions$1({ userRoot });
|
|
10181
8922
|
const roots = [userRoot, themeRoot, clientRoot];
|
|
10182
8923
|
for (const root of roots) {
|
|
10183
8924
|
const scaffoldPath = path.resolve(root, "scaffolds", `${layout}.md`);
|
|
@@ -10218,7 +8959,7 @@ async function genLayoutTemplate({
|
|
|
10218
8959
|
let template = await getTemplate(layout);
|
|
10219
8960
|
if (!template)
|
|
10220
8961
|
template = defaultPostTemplate;
|
|
10221
|
-
const dateFormat = "YYYY-MM-
|
|
8962
|
+
const dateFormat = "YYYY-MM-DDTHH:mm:ssZ";
|
|
10222
8963
|
return ejs.render(template, { title, layout, date: date ? dayjs().format(dateFormat) : "" });
|
|
10223
8964
|
}
|
|
10224
8965
|
|
|
@@ -10283,18 +9024,18 @@ function createCoreCli(argv) {
|
|
|
10283
9024
|
});
|
|
10284
9025
|
return cli.help();
|
|
10285
9026
|
}
|
|
10286
|
-
async function createCli(argv = hideBin(process
|
|
9027
|
+
async function createCli(argv = hideBin(process.argv), options = {}) {
|
|
10287
9028
|
const cli = createCoreCli(argv);
|
|
10288
9029
|
if (!shouldResolveAddonCli(argv))
|
|
10289
9030
|
return cli;
|
|
10290
|
-
const userRoot = resolve(options.userRoot || process
|
|
9031
|
+
const userRoot = resolve(options.userRoot || process.cwd());
|
|
10291
9032
|
const extensions = await resolveAddonCliExtensions(userRoot);
|
|
10292
9033
|
registerAddonCliExtensions(cli, extensions, userRoot);
|
|
10293
9034
|
return cli;
|
|
10294
9035
|
}
|
|
10295
|
-
async function run(argv = hideBin(process
|
|
9036
|
+
async function run(argv = hideBin(process.argv), options = {}) {
|
|
10296
9037
|
const cli = await createCli(argv, options);
|
|
10297
9038
|
await cli.parseAsync();
|
|
10298
9039
|
}
|
|
10299
9040
|
|
|
10300
|
-
export { resolveUserThemeConfig as $, ALL_ROUTE as A, isInstalledGlobally as B, isKatexEnabled as C, isKatexPluginNeeded as D, EXCERPT_SEPARATOR as E, isMathJaxEnabled as F, GLOBAL_STATE as G, isPath as H, loadAllContent as I, loadConfigFromFile as J, mergeValaxyConfig as K, mergeViteConfigs as L, postProcessForSSG as M, processValaxyOptions as N, registerDevCommand as O, PATHNAME_PROTOCOL_RE as P, resolveAddonsConfig as Q, resolveFootnoteConfig as R, StateManager as S, resolveImportPath as T, resolveImportUrl as U, ViteValaxyPlugins as V, resolveOptions$
|
|
9041
|
+
export { resolveUserThemeConfig as $, ALL_ROUTE as A, isInstalledGlobally as B, isKatexEnabled as C, isKatexPluginNeeded as D, EXCERPT_SEPARATOR as E, isMathJaxEnabled as F, GLOBAL_STATE as G, isPath as H, loadAllContent as I, loadConfigFromFile as J, mergeValaxyConfig as K, mergeViteConfigs as L, postProcessForSSG as M, processValaxyOptions as N, registerDevCommand as O, PATHNAME_PROTOCOL_RE as P, resolveAddonsConfig as Q, resolveFootnoteConfig as R, StateManager as S, resolveImportPath as T, resolveImportUrl as U, ViteValaxyPlugins as V, resolveOptions$1 as W, resolveSiteConfig as X, resolveSiteConfigFromRoot as Y, resolveThemeConfigFromRoot as Z, resolveThemeValaxyConfig as _, createContentService as a, resolveValaxyConfig as a0, resolveValaxyConfigFromRoot as a1, run as a2, ssgBuild as a3, startValaxyDev as a4, toAtFS as a5, transformObject as a6, version as a7, build as b, createCli as c, createMemoryReleasePlugin as d, createServer as e, createValaxyNode as f, createValaxyPlugin as g, customElements as h, defaultSiteConfig as i, defaultValaxyConfig as j, defaultViteConfig as k, defineAddon as l, defineConfig as m, defineSiteConfig as n, defineTheme as o, defineValaxyAddon as p, defineValaxyConfig as q, defineValaxyTheme as r, desktopRuntimeVersion as s, encryptContent as t, execBuild as u, generateClientRedirects as v, getGitTimestamp as w, getIndexHtml as x, getServerInfoText as y, isExternal as z };
|