silgi 0.41.3 → 0.41.5

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.
@@ -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, normalizeTemplate, useLogger, resolveSilgiPath, hasSilgiModule, toArray, isDirectory } from 'silgi/kit';
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]) {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.41.3";
4
+ const version = "0.41.5";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -186,12 +186,12 @@ declare function createService<Path extends string = string, Input extends Stand
186
186
 
187
187
  type WildcardVariants<Path extends string, Acc extends string = ''> = Path extends `${infer Head}/${infer Tail}` ? Tail extends '' ? `${Acc}${Head}` : `${Acc}${Head}/${Tail}` | `${Acc}${Head}/*` | `${Acc}${Head}/**` | WildcardVariants<Tail, `${Acc}${Head}/`> : `${Acc}${Path}`;
188
188
  type MiddlewarePath<S extends WildcardVariants<keyof ServicesObject>> = S | 'global';
189
- type CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Key extends string = string> = {
189
+ interface CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Key extends string = string> {
190
190
  path: MiddlewarePath<S>;
191
191
  methods?: UsedMethod;
192
192
  setup: MiddlewareSetup;
193
193
  key: Key;
194
- };
194
+ }
195
195
  type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Key extends string = string> = {
196
196
  [K in `${Key}:${Path}`]: {
197
197
  setup: MiddlewareSetup;
@@ -16,6 +16,7 @@ import * as h3 from 'h3';
16
16
  import { Session } from 'h3';
17
17
  import * as nitropack_types from 'nitropack/types';
18
18
  import { ESMImport, ESMCodeGenOptions } from 'knitwork';
19
+ import { IResolvers } from '@graphql-tools/utils';
19
20
  import { StandardSchemaV1 } from '@standard-schema/spec';
20
21
  import { NitroApp } from 'nitropack';
21
22
  import { RouterContext } from 'rou3';
@@ -315,7 +316,7 @@ interface SilgiCLI {
315
316
  services: ResolvedServiceDefinition;
316
317
  middleware: SilgiRoute[];
317
318
  shareds: SilgiRuntimeShareds;
318
- resolvers: any[];
319
+ resolvers: IResolvers<any, any>[];
319
320
  schemas: Record<string, any>;
320
321
  templates: SilgiTemplate[];
321
322
  hooks: Hookable<SilgiCLIHooks>;
@@ -707,7 +708,7 @@ interface Silgi {
707
708
  globalMiddlewares: SilgiRoute[];
708
709
  routerPrefixs: string[];
709
710
  schemas: ResolvedSchemaDefinition;
710
- resolvers: any[];
711
+ resolvers: IResolvers<any, any>[];
711
712
  services: ResolvedServiceDefinition;
712
713
  shared: SilgiRuntimeShareds;
713
714
  plugins: SilgiAppPlugin[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.41.3",
4
+ "version": "0.41.5",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -98,6 +98,7 @@
98
98
  "@antfu/ni": "^24.3.0",
99
99
  "@clack/prompts": "^0.10.1",
100
100
  "@fastify/deepmerge": "^3.1.0",
101
+ "@graphql-tools/utils": "^10.8.6",
101
102
  "@standard-community/standard-json": "^0.2.0",
102
103
  "@standard-schema/spec": "^1.0.0",
103
104
  "apiful": "^2.2.0",