silgi 0.41.4 → 0.41.6
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/dist/cli/build.mjs +122 -123
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.mjs +12 -5
- package/dist/types/index.d.mts +1 -0
- package/package.json +1 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { consola } from 'consola';
|
|
|
2
2
|
import { createHooks, createDebugger } from 'hookable';
|
|
3
3
|
import { resolve, join, relative, extname, basename, dirname, isAbsolute } from 'pathe';
|
|
4
4
|
import { useSilgiCLI, replaceRuntimeValues, silgiCLICtx, autoImportTypes } from 'silgi';
|
|
5
|
-
import { isPresents, addTemplate, addCoreFile, genEnsureSafeVar, getServicePath, writeFile, relativeWithDot, hash, removeExtension, resolveAlias, directoryToURL, baseHeaderBannerComment, addImports,
|
|
5
|
+
import { isPresents, addTemplate, addCoreFile, genEnsureSafeVar, getServicePath, writeFile, relativeWithDot, hash, removeExtension, resolveAlias, directoryToURL, baseHeaderBannerComment, addImports, resolveSilgiPath, hasSilgiModule, normalizeTemplate, useLogger, toArray, isDirectory } from 'silgi/kit';
|
|
6
6
|
import { initRuntimeConfig, useRuntimeConfig, sharedRuntimeConfig } from 'silgi/runtime';
|
|
7
7
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
8
8
|
import { scanExports, createUnimport, toExports } from 'unimport';
|
|
@@ -1332,127 +1332,6 @@ async function createStorageCLI(silgi) {
|
|
|
1332
1332
|
return storage;
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
1335
|
-
const vueShim = {
|
|
1336
|
-
filename: "delete/testtest.d.ts",
|
|
1337
|
-
where: ".silgi",
|
|
1338
|
-
getContents: ({ app }) => {
|
|
1339
|
-
if (!app.options.typescript.shim) {
|
|
1340
|
-
return "";
|
|
1341
|
-
}
|
|
1342
|
-
return [
|
|
1343
|
-
"declare module '*.vue' {",
|
|
1344
|
-
" import { DefineComponent } from 'vue'",
|
|
1345
|
-
" const component: DefineComponent<{}, {}, any>",
|
|
1346
|
-
" export default component",
|
|
1347
|
-
"}"
|
|
1348
|
-
].join("\n");
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
const pluginsDeclaration = {
|
|
1352
|
-
filename: "delete/testtest1.d.ts",
|
|
1353
|
-
where: ".silgi",
|
|
1354
|
-
getContents: async () => {
|
|
1355
|
-
return `
|
|
1356
|
-
declare module 'nuxt' {
|
|
1357
|
-
interface NuxtApp {
|
|
1358
|
-
$myPlugin: any;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
`;
|
|
1362
|
-
}
|
|
1363
|
-
};
|
|
1364
|
-
|
|
1365
|
-
const defaultTemplates = {
|
|
1366
|
-
__proto__: null,
|
|
1367
|
-
pluginsDeclaration: pluginsDeclaration,
|
|
1368
|
-
vueShim: vueShim
|
|
1369
|
-
};
|
|
1370
|
-
|
|
1371
|
-
const postTemplates = [
|
|
1372
|
-
pluginsDeclaration.filename
|
|
1373
|
-
];
|
|
1374
|
-
const logger = useLogger("silgi");
|
|
1375
|
-
async function generateApp(app, options = {}) {
|
|
1376
|
-
app.templates = Object.values(defaultTemplates).concat(app.options.build.templates);
|
|
1377
|
-
await app.callHook("app:templates", app);
|
|
1378
|
-
app.templates = app.templates.map((tmpl) => {
|
|
1379
|
-
const dir = tmpl.where === ".silgi" ? app.options.build.dir : tmpl.where === "server" ? app.options.silgi.serverDir : tmpl.where === "client" ? app.options.silgi.clientDir : app.options.silgi.vfsDir;
|
|
1380
|
-
return normalizeTemplate(tmpl, dir);
|
|
1381
|
-
});
|
|
1382
|
-
const filteredTemplates = {
|
|
1383
|
-
pre: [],
|
|
1384
|
-
post: []
|
|
1385
|
-
};
|
|
1386
|
-
for (const template of app.templates) {
|
|
1387
|
-
if (options.filter && !options.filter(template)) {
|
|
1388
|
-
continue;
|
|
1389
|
-
}
|
|
1390
|
-
const key = template.filename && postTemplates.includes(template.filename) ? "post" : "pre";
|
|
1391
|
-
filteredTemplates[key].push(template);
|
|
1392
|
-
}
|
|
1393
|
-
const templateContext = { app };
|
|
1394
|
-
const writes = [];
|
|
1395
|
-
const dirs = /* @__PURE__ */ new Set();
|
|
1396
|
-
const changedTemplates = [];
|
|
1397
|
-
async function processTemplate(template) {
|
|
1398
|
-
const dir = template.where === ".silgi" ? app.options.build.dir : template.where === "server" ? app.options.silgi.serverDir : template.where === "client" ? app.options.silgi.clientDir : app.options.silgi.vfsDir;
|
|
1399
|
-
const fullPath = template.dst || resolve(dir, template.filename);
|
|
1400
|
-
const start = performance.now();
|
|
1401
|
-
const contents = await compileTemplate(template, templateContext).catch((e) => {
|
|
1402
|
-
logger.error(`Could not compile template \`${template.filename}\`.`);
|
|
1403
|
-
logger.error(e);
|
|
1404
|
-
throw e;
|
|
1405
|
-
});
|
|
1406
|
-
template.modified = true;
|
|
1407
|
-
if (template.modified) {
|
|
1408
|
-
changedTemplates.push(template);
|
|
1409
|
-
}
|
|
1410
|
-
const perf = performance.now() - start;
|
|
1411
|
-
const setupTime = Math.round(perf * 100) / 100;
|
|
1412
|
-
if (app.options.debug || setupTime > 500) {
|
|
1413
|
-
logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`);
|
|
1414
|
-
}
|
|
1415
|
-
if (template.modified && template.write) {
|
|
1416
|
-
dirs.add(dirname(fullPath));
|
|
1417
|
-
if (template.skipIfExists && existsSync(fullPath)) {
|
|
1418
|
-
return;
|
|
1419
|
-
}
|
|
1420
|
-
writes.push(() => writeFileSync(fullPath, contents, "utf8"));
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
await Promise.allSettled(filteredTemplates.pre.map(processTemplate));
|
|
1424
|
-
await Promise.allSettled(filteredTemplates.post.map(processTemplate));
|
|
1425
|
-
for (const dir of dirs) {
|
|
1426
|
-
mkdirSync(dir, { recursive: true });
|
|
1427
|
-
}
|
|
1428
|
-
for (const write of writes) {
|
|
1429
|
-
if (!app.errors.length) {
|
|
1430
|
-
write();
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
if (changedTemplates.length) {
|
|
1434
|
-
await app.callHook("app:templatesGenerated", app, changedTemplates, options);
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
async function compileTemplate(template, ctx) {
|
|
1438
|
-
delete ctx.utils;
|
|
1439
|
-
if (template.src) {
|
|
1440
|
-
try {
|
|
1441
|
-
return await promises.readFile(template.src, "utf-8");
|
|
1442
|
-
} catch (err) {
|
|
1443
|
-
logger.error(`[nuxt] Error reading template from \`${template.src}\``);
|
|
1444
|
-
throw err;
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
if (template.getContents) {
|
|
1448
|
-
return template.getContents({
|
|
1449
|
-
...ctx,
|
|
1450
|
-
options: template.options
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
throw new Error(`[nuxt] Invalid template. Templates must have either \`src\` or \`getContents\`: ${JSON.stringify(template)}`);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
1335
|
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
1457
1336
|
async function scanAndSyncOptions(silgi) {
|
|
1458
1337
|
const scannedModules = await scanModules(silgi);
|
|
@@ -1559,7 +1438,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1559
1438
|
silgi.logger.level = silgi.options.logLevel;
|
|
1560
1439
|
}
|
|
1561
1440
|
silgi.hooks.addHooks(silgi.options.hooks);
|
|
1562
|
-
await generateApp(silgi);
|
|
1563
1441
|
if (silgi.options.imports) {
|
|
1564
1442
|
silgi.options.imports.dirs ??= [];
|
|
1565
1443
|
silgi.options.imports.dirs = silgi.options.imports.dirs.map((dir) => {
|
|
@@ -1626,6 +1504,127 @@ async function generateApiFul(silgi) {
|
|
|
1626
1504
|
});
|
|
1627
1505
|
}
|
|
1628
1506
|
|
|
1507
|
+
const vueShim = {
|
|
1508
|
+
filename: "delete/testtest.d.ts",
|
|
1509
|
+
where: ".silgi",
|
|
1510
|
+
getContents: ({ app }) => {
|
|
1511
|
+
if (!app.options.typescript.shim) {
|
|
1512
|
+
return "";
|
|
1513
|
+
}
|
|
1514
|
+
return [
|
|
1515
|
+
"declare module '*.vue' {",
|
|
1516
|
+
" import { DefineComponent } from 'vue'",
|
|
1517
|
+
" const component: DefineComponent<{}, {}, any>",
|
|
1518
|
+
" export default component",
|
|
1519
|
+
"}"
|
|
1520
|
+
].join("\n");
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
const pluginsDeclaration = {
|
|
1524
|
+
filename: "delete/testtest1.d.ts",
|
|
1525
|
+
where: ".silgi",
|
|
1526
|
+
getContents: async () => {
|
|
1527
|
+
return `
|
|
1528
|
+
declare module 'nuxt' {
|
|
1529
|
+
interface NuxtApp {
|
|
1530
|
+
$myPlugin: any;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
`;
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
const defaultTemplates = {
|
|
1538
|
+
__proto__: null,
|
|
1539
|
+
pluginsDeclaration: pluginsDeclaration,
|
|
1540
|
+
vueShim: vueShim
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
const postTemplates = [
|
|
1544
|
+
pluginsDeclaration.filename
|
|
1545
|
+
];
|
|
1546
|
+
const logger = useLogger("silgi");
|
|
1547
|
+
async function generateApp(app, options = {}) {
|
|
1548
|
+
app.templates = Object.values(defaultTemplates).concat(app.options.build.templates);
|
|
1549
|
+
await app.callHook("app:templates", app);
|
|
1550
|
+
app.templates = app.templates.map((tmpl) => {
|
|
1551
|
+
const dir = tmpl.where === ".silgi" ? app.options.build.dir : tmpl.where === "server" ? app.options.silgi.serverDir : tmpl.where === "client" ? app.options.silgi.clientDir : app.options.silgi.vfsDir;
|
|
1552
|
+
return normalizeTemplate(tmpl, dir);
|
|
1553
|
+
});
|
|
1554
|
+
const filteredTemplates = {
|
|
1555
|
+
pre: [],
|
|
1556
|
+
post: []
|
|
1557
|
+
};
|
|
1558
|
+
for (const template of app.templates) {
|
|
1559
|
+
if (options.filter && !options.filter(template)) {
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
const key = template.filename && postTemplates.includes(template.filename) ? "post" : "pre";
|
|
1563
|
+
filteredTemplates[key].push(template);
|
|
1564
|
+
}
|
|
1565
|
+
const templateContext = { app };
|
|
1566
|
+
const writes = [];
|
|
1567
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
1568
|
+
const changedTemplates = [];
|
|
1569
|
+
async function processTemplate(template) {
|
|
1570
|
+
const dir = template.where === ".silgi" ? app.options.build.dir : template.where === "server" ? app.options.silgi.serverDir : template.where === "client" ? app.options.silgi.clientDir : app.options.silgi.vfsDir;
|
|
1571
|
+
const fullPath = template.dst || resolve(dir, template.filename);
|
|
1572
|
+
const start = performance.now();
|
|
1573
|
+
const contents = await compileTemplate(template, templateContext).catch((e) => {
|
|
1574
|
+
logger.error(`Could not compile template \`${template.filename}\`.`);
|
|
1575
|
+
logger.error(e);
|
|
1576
|
+
throw e;
|
|
1577
|
+
});
|
|
1578
|
+
template.modified = true;
|
|
1579
|
+
if (template.modified) {
|
|
1580
|
+
changedTemplates.push(template);
|
|
1581
|
+
}
|
|
1582
|
+
const perf = performance.now() - start;
|
|
1583
|
+
const setupTime = Math.round(perf * 100) / 100;
|
|
1584
|
+
if (app.options.debug || setupTime > 500) {
|
|
1585
|
+
logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`);
|
|
1586
|
+
}
|
|
1587
|
+
if (template.modified && template.write) {
|
|
1588
|
+
dirs.add(dirname(fullPath));
|
|
1589
|
+
if (template.skipIfExists && existsSync(fullPath)) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
writes.push(() => writeFileSync(fullPath, contents, "utf8"));
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
await Promise.allSettled(filteredTemplates.pre.map(processTemplate));
|
|
1596
|
+
await Promise.allSettled(filteredTemplates.post.map(processTemplate));
|
|
1597
|
+
for (const dir of dirs) {
|
|
1598
|
+
mkdirSync(dir, { recursive: true });
|
|
1599
|
+
}
|
|
1600
|
+
for (const write of writes) {
|
|
1601
|
+
if (!app.errors.length) {
|
|
1602
|
+
write();
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
if (changedTemplates.length) {
|
|
1606
|
+
await app.callHook("app:templatesGenerated", app, changedTemplates, options);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
async function compileTemplate(template, ctx) {
|
|
1610
|
+
delete ctx.utils;
|
|
1611
|
+
if (template.src) {
|
|
1612
|
+
try {
|
|
1613
|
+
return await promises.readFile(template.src, "utf-8");
|
|
1614
|
+
} catch (err) {
|
|
1615
|
+
logger.error(`[nuxt] Error reading template from \`${template.src}\``);
|
|
1616
|
+
throw err;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
if (template.getContents) {
|
|
1620
|
+
return template.getContents({
|
|
1621
|
+
...ctx,
|
|
1622
|
+
options: template.options
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
throw new Error(`[nuxt] Invalid template. Templates must have either \`src\` or \`getContents\`: ${JSON.stringify(template)}`);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1629
1628
|
function debugMode(name) {
|
|
1630
1629
|
const silgi = useSilgiCLI$1();
|
|
1631
1630
|
if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
|
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.mjs
CHANGED
|
@@ -576,10 +576,10 @@ function getUrlPrefix(path, method) {
|
|
|
576
576
|
};
|
|
577
577
|
}
|
|
578
578
|
|
|
579
|
-
async function orchestrate(route, event, _input
|
|
579
|
+
async function orchestrate(route, event, _input) {
|
|
580
580
|
const silgiCtx = useSilgi();
|
|
581
581
|
const silgiURL = getUrlPrefix(route.route || event.req.url, route.method);
|
|
582
|
-
const input = _input || (route.service?.setup.rules?.readBeforeBody === false || graphql ? {} : await parseRequestInput(event.req));
|
|
582
|
+
const input = _input || (route.service?.setup.rules?.readBeforeBody === false || route.graphql ? {} : await parseRequestInput(event.req));
|
|
583
583
|
const hookContext = { earlyReturnValue: false };
|
|
584
584
|
const routerParams = _input ? input.path : getRouterParams(event);
|
|
585
585
|
const queryParams = _input ? input.query : getQuery(event);
|
|
@@ -988,7 +988,14 @@ async function handler(event, url, input) {
|
|
|
988
988
|
const data = middleware(event, url);
|
|
989
989
|
_chain = data;
|
|
990
990
|
if (silgiCtx.router) {
|
|
991
|
-
const match = findRoute(silgiCtx.router, url?.method || event.req.method, pathname)
|
|
991
|
+
const match = !url?.graphql ? findRoute(silgiCtx.router, url?.method || event.req.method, pathname) : {
|
|
992
|
+
data: {
|
|
993
|
+
graphql: true,
|
|
994
|
+
method: url?.method || event.req.method,
|
|
995
|
+
route: url.path
|
|
996
|
+
},
|
|
997
|
+
params: {}
|
|
998
|
+
};
|
|
992
999
|
if (match) {
|
|
993
1000
|
if (_chain) {
|
|
994
1001
|
return _chain.then(async (_previous) => {
|
|
@@ -997,12 +1004,12 @@ async function handler(event, url, input) {
|
|
|
997
1004
|
}
|
|
998
1005
|
event.context.params = match.params;
|
|
999
1006
|
event.context.matchedRoute = match.data;
|
|
1000
|
-
return orchestrate(match.data, event, input
|
|
1007
|
+
return orchestrate(match.data, event, input);
|
|
1001
1008
|
});
|
|
1002
1009
|
} else {
|
|
1003
1010
|
event.context.params = match.params;
|
|
1004
1011
|
event.context.matchedRoute = match.data;
|
|
1005
|
-
return orchestrate(match.data, event, input
|
|
1012
|
+
return orchestrate(match.data, event, input);
|
|
1006
1013
|
}
|
|
1007
1014
|
}
|
|
1008
1015
|
}
|
package/dist/types/index.d.mts
CHANGED