@dtwo/schema 3.1.1 → 3.2.0

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/index.d.ts CHANGED
@@ -460,71 +460,286 @@ interface ImportPresetWithDeprecation extends InlinePreset {
460
460
  interface GenerateAppOptions {
461
461
  filter?: (template: ResolvedDtwoTemplate<any>) => boolean;
462
462
  }
463
+ /**
464
+ * The listeners to Dtwo build time events
465
+ */
463
466
  interface DtwoHooks {
467
+ /**
468
+ * Allows extending compatibility checks.
469
+ * @param compatibility Compatibility object
470
+ * @param issues Issues to be mapped
471
+ * @returns Promise
472
+ */
464
473
  'kit:compatibility': (compatibility: DtwoCompatibility, issues: DtwoCompatibilityIssues) => HookResult;
474
+ /**
475
+ * Called after Dtwo initialization, when the Dtwo instance is ready to work.
476
+ * @param dtwo The configured Dtwo object
477
+ * @returns Promise
478
+ */
465
479
  'ready': (dtwo: Dtwo) => HookResult;
480
+ /**
481
+ * Called when Dtwo instance is gracefully closing.
482
+ * @param dtwo The configured Dtwo object
483
+ * @returns Promise
484
+ */
466
485
  'close': (dtwo: Dtwo) => HookResult;
486
+ /**
487
+ * Called during Dtwo initialization, before installing user modules.
488
+ * @returns Promise
489
+ */
467
490
  'modules:before': () => HookResult;
491
+ /**
492
+ * Called during Dtwo initialization, after installing user modules.
493
+ * @returns Promise
494
+ */
468
495
  'modules:done': () => HookResult;
496
+ /**
497
+ * Called after resolving the `app` instance.
498
+ * @param app The resolved `DtwoApp` object
499
+ * @returns Promise
500
+ */
469
501
  'app:resolve': (app: DtwoApp) => HookResult;
502
+ /**
503
+ * Called during `DtwoApp` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.dtwo`).
504
+ * @param app The configured `DtwoApp` object
505
+ * @returns Promise
506
+ */
470
507
  'app:templates': (app: DtwoApp) => HookResult;
508
+ /**
509
+ * Called after templates are compiled into the [virtual file system](https://dtwojs.web.app/docs/guide/directory-structure/dtwo#virtual-file-system) (vfs).
510
+ * @param app The configured `DtwoApp` object
511
+ * @returns Promise
512
+ */
471
513
  'app:templatesGenerated': (app: DtwoApp) => HookResult;
514
+ /**
515
+ * Called before Dtwo bundle builder.
516
+ * @returns Promise
517
+ */
472
518
  'build:before': () => HookResult;
519
+ /**
520
+ * Called after Dtwo bundle builder is complete.
521
+ * @returns Promise
522
+ */
473
523
  'build:done': () => HookResult;
524
+ /**
525
+ * Called during the manifest build by Wite and Webpack. This allows customizing the manifest that Hole will use to render `<script>` and `<link>` tags in the final HTML.
526
+ * @param manifest The manifest object to build
527
+ * @returns Promise
528
+ */
474
529
  'build:manifest': (manifest: Manifest) => HookResult;
530
+ /**
531
+ * Called before generating the app.
532
+ * @param options GenerateAppOptions object
533
+ * @returns Promise
534
+ */
475
535
  'builder:generateApp': (options?: GenerateAppOptions) => HookResult;
536
+ /**
537
+ * Called at build time in development when the watcher spots a change to a file or directory in the project.
538
+ * @param event "add" | "addDir" | "change" | "unlink" | "unlinkDir"
539
+ * @param path the path to the watched file
540
+ * @returns Promise
541
+ */
476
542
  'builder:watch': (event: WatchEvent, path: string) => HookResult;
543
+ /**
544
+ * Called after pages routes are resolved.
545
+ * @param pages Array containing resolved pages
546
+ * @returns Promise
547
+ */
477
548
  'pages:extend': (pages: DtwoPage[]) => HookResult;
549
+ /**
550
+ * Called when the dev middleware is being registered on the Hole dev server.
551
+ * @param handler the Wite or Webpack event handler
552
+ * @returns Promise
553
+ */
478
554
  'server:devHandler': (handler: EventHandler) => HookResult;
555
+ /**
556
+ * Called at setup allowing modules to extend sources.
557
+ * @param presets Array containing presets objects
558
+ * @returns Promise
559
+ */
479
560
  'imports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult;
561
+ /**
562
+ * Called at setup allowing modules to extend imports.
563
+ * @param imports Array containing the imports to extend
564
+ * @returns Promise
565
+ */
480
566
  'imports:extend': (imports: Import[]) => HookResult;
567
+ /**
568
+ * Called when the `kdimport` context is created.
569
+ * @param context The Kdimport context
570
+ * @returns Promise
571
+ */
481
572
  'imports:context': (context: Kdimport) => HookResult;
573
+ /**
574
+ * Allows extending import directories.
575
+ * @param dirs Array containing directories as string
576
+ * @returns Promise
577
+ */
482
578
  'imports:dirs': (dirs: string[]) => HookResult;
579
+ /**
580
+ * Called within `app:resolve` allowing to extend the directories that are scanned for auto-importable components.
581
+ * @param dirs The `dirs` option to push new items
582
+ * @returns Promise
583
+ */
483
584
  'components:dirs': (dirs: ComponentsOptions['dirs']) => HookResult;
585
+ /**
586
+ * Allows extending new components.
587
+ * @param components The `components` array to push new items
588
+ * @returns Promise
589
+ */
484
590
  'components:extend': (components: Component[]) => HookResult;
591
+ /**
592
+ * Called before initializing Hole, allowing customization of Hole's configuration.
593
+ * @param holeConfig The hole config to be extended
594
+ * @returns Promise
595
+ */
485
596
  'hole:config': (holeConfig: HoleConfig) => HookResult;
597
+ /**
598
+ * Called after Hole is initialized, which allows registering Hole hooks and interacting directly with Hole.
599
+ * @param hole The created hole object
600
+ * @returns Promise
601
+ */
486
602
  'hole:init': (hole: Hole) => HookResult;
603
+ /**
604
+ * Called before building the Hole instance.
605
+ * @param hole The created hole object
606
+ * @returns Promise
607
+ */
487
608
  'hole:build:before': (hole: Hole) => HookResult;
609
+ /**
610
+ * Allows extending the routes to be pre-rendered.
611
+ * @param ctx Dtwo context
612
+ * @returns Promise
613
+ */
488
614
  'prerender:routes': (ctx: {
489
615
  routes: Set<string>;
490
616
  }) => HookResult;
617
+ /**
618
+ * Called when an error occurs at build time.
619
+ * @param error Error object
620
+ * @returns Promise
621
+ */
491
622
  'build:error': (error: Error) => HookResult;
623
+ /**
624
+ * Called before Dtwc writes `.dtwo/tsconfig.json` and `.dtwo/dtwo.d.ts`, allowing addition of custom references and declarations in `dtwo.d.ts`, or directly modifying the options in `tsconfig.json`
625
+ * @param options Objects containing `references`, `declarations`, `tsConfig`
626
+ * @returns Promise
627
+ */
492
628
  'prepare:types': (options: {
493
629
  references: TSReference[];
494
630
  declarations: string[];
495
631
  tsConfig: TSConfig;
496
632
  }) => HookResult;
633
+ /**
634
+ * Called when the dev server is loading.
635
+ * @param listenerServer The HTTP/HTTPS server object
636
+ * @param listener The server's listener object
637
+ * @returns Promise
638
+ */
497
639
  'listen': (listenerServer: Server | Server$1, listener: any) => HookResult;
640
+ /**
641
+ * Allows extending default schemas.
642
+ * @param schemas Schemas to be extend
643
+ * @returns void
644
+ */
498
645
  'schema:extend': (schemas: SchemaDefinition[]) => void;
646
+ /**
647
+ * Allows extending resolved schema.
648
+ * @param schema Schema object
649
+ * @returns void
650
+ */
499
651
  'schema:resolved': (schema: Schema) => void;
652
+ /**
653
+ * Called before writing the given schema.
654
+ * @param schema Schema object
655
+ * @returns void
656
+ */
500
657
  'schema:beforeWrite': (schema: Schema) => void;
658
+ /**
659
+ * Called after the schema is written.
660
+ * @returns void
661
+ */
501
662
  'schema:written': () => void;
663
+ /**
664
+ * Allows to extend Wite default context.
665
+ * @param witeBuildContext The wite build context object
666
+ * @returns Promise
667
+ */
502
668
  'wite:extend': (witeBuildContext: {
503
669
  dtwo: Dtwo;
504
670
  config: InlineConfig;
505
671
  }) => HookResult;
672
+ /**
673
+ * Allows to extend Wite default config.
674
+ * @param witeInlineConfig The wite inline config object
675
+ * @param env Server or client
676
+ * @returns Promise
677
+ */
506
678
  'wite:extendConfig': (witeInlineConfig: InlineConfig, env: {
507
679
  isClient: boolean;
508
680
  isServer: boolean;
509
681
  }) => HookResult;
682
+ /**
683
+ * Called when the Wite server is created.
684
+ * @param witeServer Wite development server
685
+ * @param env Server or client
686
+ * @returns Promise
687
+ */
510
688
  'wite:serverCreated': (witeServer: WiteDevServer, env: {
511
689
  isClient: boolean;
512
690
  isServer: boolean;
513
691
  }) => HookResult;
692
+ /**
693
+ * Called after Wite server is compiled.
694
+ * @returns Promise
695
+ */
514
696
  'wite:compiled': () => HookResult;
697
+ /**
698
+ * Called before configuring the webpack compiler.
699
+ * @param webpackConfigs Configs objects to be pushed to the compiler
700
+ * @returns Promise
701
+ */
515
702
  'webpack:config': (webpackConfigs: Configuration[]) => HookResult;
703
+ /**
704
+ * Called right before compilation.
705
+ * @param options The options to be added
706
+ * @returns Promise
707
+ */
516
708
  'webpack:compile': (options: {
517
709
  name: string;
518
710
  compiler: Compiler;
519
711
  }) => HookResult;
712
+ /**
713
+ * Called after resources are loaded.
714
+ * @param options The compiler options
715
+ * @returns Promise
716
+ */
520
717
  'webpack:compiled': (options: {
521
718
  name: string;
522
719
  compiler: Compiler;
523
720
  stats: Stats;
524
721
  }) => HookResult;
722
+ /**
723
+ * Called on `change` on WebpackBar.
724
+ * @param shortPath the short path
725
+ * @returns void
726
+ */
525
727
  'webpack:change': (shortPath: string) => void;
728
+ /**
729
+ * Called on `done` if has errors on WebpackBar.
730
+ * @returns void
731
+ */
526
732
  'webpack:error': () => void;
733
+ /**
734
+ * Called on `allDone` on WebpackBar.
735
+ * @returns void
736
+ */
527
737
  'webpack:done': () => void;
738
+ /**
739
+ * Called on `progress` on WebpackBar.
740
+ * @param statesArray The array containing the states on progress
741
+ * @returns void
742
+ */
528
743
  'webpack:progress': (statesArray: any[]) => void;
529
744
  }
530
745
  type DtwoHookName = keyof DtwoHooks;
@@ -611,8 +826,9 @@ interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
611
826
  setup?: (this: void, resolvedOptions: T, dtwo: Dtwo) => void | Promise<void>;
612
827
  }
613
828
  /** Dtwo modules are always a simple function. */
829
+ type Awaitable<T> = T | Promise<T>;
614
830
  interface DtwoModule<T extends ModuleOptions = ModuleOptions> {
615
- (this: void, inlineOptions: T, dtwo: Dtwo): void | Promise<void>;
831
+ (this: void, inlineOptions: T, dtwo: Dtwo): Awaitable<void | false>;
616
832
  getOptions?: (inlineOptions?: T, dtwo?: Dtwo) => Promise<T>;
617
833
  getMeta?: () => Promise<ModuleMeta>;
618
834
  }
@@ -2034,9 +2250,20 @@ type AppHeadMetaObject = MetaObjectRaw & {
2034
2250
  type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? {
2035
2251
  [P in keyof T]?: DeepPartial<T[P]>;
2036
2252
  } : T;
2253
+ type ExtractUpperChunk<T extends string> = T extends `${infer A}${infer B}` ? A extends Uppercase<A> ? B extends `${Uppercase<string>}${infer Rest}` ? B extends `${infer C}${Rest}` ? `${A}${C}${ExtractUpperChunk<Rest>}` : never : A : '' : never;
2254
+ type SliceLast<T extends string> = T extends `${infer A}${infer B}` ? B extends `${infer C}${infer D}` ? D extends '' ? A : `${A}${C}${SliceLast<D>}` : '' : never;
2255
+ type UpperSnakeCase<T extends string, State extends 'start' | 'lower' | 'upper' = 'start'> = T extends `${infer A}${infer B}` ? A extends Uppercase<A> ? A extends `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0}` ? `${A}${UpperSnakeCase<B, 'lower'>}` : State extends 'lower' | 'upper' ? B extends `${SliceLast<ExtractUpperChunk<B>>}${infer Rest}` ? SliceLast<ExtractUpperChunk<B>> extends '' ? `_${A}_${UpperSnakeCase<B, 'start'>}` : `_${A}${SliceLast<ExtractUpperChunk<B>>}_${UpperSnakeCase<Rest, 'start'>}` : B extends Uppercase<B> ? `_${A}${B}` : `_${A}${UpperSnakeCase<B, 'lower'>}` : State extends 'start' ? `${A}${UpperSnakeCase<B, 'lower'>}` : never : State extends 'start' | 'lower' ? `${Uppercase<A>}${UpperSnakeCase<B, 'lower'>}` : `_${Uppercase<A>}${UpperSnakeCase<B, 'lower'>}` : Uppercase<T>;
2256
+ declare const message: unique symbol;
2257
+ type RuntimeValue<T, B extends string> = T & {
2258
+ [message]?: B;
2259
+ };
2260
+ type Overrideable<T extends Record<string, any>, Path extends string = ''> = {
2261
+ [K in keyof T]?: K extends string ? T[K] extends Record<string, any> ? RuntimeValue<Overrideable<T[K], `${Path}_${UpperSnakeCase<K>}`>, `You can override this value at runtime with DTWO${Path}_${UpperSnakeCase<K>}`> : RuntimeValue<T[K], `You can override this value at runtime with DTWO${Path}_${UpperSnakeCase<K>}`> : never;
2262
+ };
2037
2263
  /** User configuration in `dtwo.config` file */
2038
- interface DtwoConfig extends DeepPartial<Omit<ConfigSchema, 'wite'>> {
2264
+ interface DtwoConfig extends DeepPartial<Omit<ConfigSchema, 'wite' | 'runtimeConfig'>> {
2039
2265
  wite?: ConfigSchema['wite'];
2266
+ runtimeConfig?: Overrideable<RuntimeConfig>;
2040
2267
  /**
2041
2268
  * Experimental custom config schema
2042
2269
  */
@@ -2108,4 +2335,4 @@ declare const _default: {
2108
2335
  [x: string]: untyped.SchemaDefinition | untyped.JSValue | untyped.InputObject;
2109
2336
  };
2110
2337
 
2111
- export { AppConfig, AppConfigInput, AppHeadMetaObject, Component, ComponentsDir, ComponentsOptions, Dtwo, DtwoApp, DtwoAppConfig, DtwoCompatibility, DtwoCompatibilityIssue, DtwoCompatibilityIssues, DtwoConfig, DtwoConfigLayer, _default as DtwoConfigSchema, DtwoHookName, DtwoHooks, DtwoLayout, DtwoMiddleware, DtwoModule, DtwoOptions, DtwoPage, DtwoPlugin, DtwoPluginTemplate, DtwoTemplate, GenerateAppOptions, HeadAugmentations, HookResult, ImportPresetWithDeprecation, ImportsOptions, MetaObject, MetaObjectRaw, ModuleDefinition, ModuleMeta, ModuleOptions, PublicRuntimeConfig, ResolvedDtwoTemplate, RouterConfig, RouterConfigSerializable, RouterOptions, RuntimeConfig, ScanDir, TSReference, WatchEvent, WiteConfig };
2338
+ export { AppConfig, AppConfigInput, AppHeadMetaObject, Component, ComponentsDir, ComponentsOptions, Dtwo, DtwoApp, DtwoAppConfig, DtwoCompatibility, DtwoCompatibilityIssue, DtwoCompatibilityIssues, DtwoConfig, DtwoConfigLayer, _default as DtwoConfigSchema, DtwoHookName, DtwoHooks, DtwoLayout, DtwoMiddleware, DtwoModule, DtwoOptions, DtwoPage, DtwoPlugin, DtwoPluginTemplate, DtwoTemplate, GenerateAppOptions, HeadAugmentations, HookResult, ImportPresetWithDeprecation, ImportsOptions, MetaObject, MetaObjectRaw, ModuleDefinition, ModuleMeta, ModuleOptions, PublicRuntimeConfig, ResolvedDtwoTemplate, RouterConfig, RouterConfigSerializable, RouterOptions, RuntimeConfig, RuntimeValue, ScanDir, TSReference, WatchEvent, WiteConfig };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineUntypedSchema } from 'untyped';
2
- import defu from 'defu';
2
+ import { defu } from 'defu';
3
3
  import { join, resolve } from 'pathe';
4
4
  import { isDevelopment, isDebug } from 'std-env';
5
5
  import { findWorkspaceDir } from 'pkg-types';
@@ -757,14 +757,17 @@ const common = defineUntypedSchema({
757
757
  * @type {typeof import('../src/types/config').RuntimeConfig}
758
758
  */
759
759
  runtimeConfig: {
760
- $resolve: async (val, get) => defu(val, {
761
- public: {},
762
- app: {
763
- baseURL: (await get("app")).baseURL,
764
- buildAssetsDir: (await get("app")).buildAssetsDir,
765
- cdnURL: (await get("app")).cdnURL
766
- }
767
- })
760
+ $resolve: async (val, get) => {
761
+ provideFallbackValues(val);
762
+ return defu(val, {
763
+ public: {},
764
+ app: {
765
+ baseURL: (await get("app")).baseURL,
766
+ buildAssetsDir: (await get("app")).buildAssetsDir,
767
+ cdnURL: (await get("app")).cdnURL
768
+ }
769
+ });
770
+ }
768
771
  },
769
772
  /**
770
773
  * Additional app configuration
@@ -777,6 +780,15 @@ const common = defineUntypedSchema({
777
780
  appConfig: {},
778
781
  $schema: {}
779
782
  });
783
+ function provideFallbackValues(obj) {
784
+ for (const key in obj) {
785
+ if (typeof obj[key] === "undefined" || obj[key] === null) {
786
+ obj[key] = "";
787
+ } else if (typeof obj[key] === "object") {
788
+ provideFallbackValues(obj[key]);
789
+ }
790
+ }
791
+ }
780
792
 
781
793
  const dev = defineUntypedSchema({
782
794
  devServer: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtwo/schema",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "repository": "d2js/dtwo",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,25 +13,25 @@
13
13
  "devDependencies": {
14
14
  "@types/lodash.template": "4.5.1",
15
15
  "@types/semver": "7.3.13",
16
- "@kdhead/schema": "1.0.19",
16
+ "@kdhead/schema": "1.0.21",
17
17
  "@witejs/plugin-kdu": "4.0.0",
18
- "holepack": "2.0.0",
18
+ "holepack": "2.2.1",
19
19
  "kdu-router": "4.1.6",
20
20
  "unbuild": "1.1.1",
21
- "wite": "4.0.0"
21
+ "wite": "4.2.0"
22
22
  },
23
23
  "dependencies": {
24
24
  "c12": "1.1.0",
25
25
  "create-require": "1.1.1",
26
26
  "defu": "6.1.2",
27
27
  "hookable": "5.4.2",
28
- "jiti": "1.16.2",
29
- "kdimport": "2.0.1",
28
+ "jiti": "1.17.0",
29
+ "kdimport": "2.2.4",
30
30
  "pathe": "1.1.0",
31
31
  "pkg-types": "1.0.1",
32
32
  "postcss-import-resolver": "2.0.0",
33
33
  "scule": "1.0.0",
34
- "std-env": "3.3.1",
34
+ "std-env": "3.3.2",
35
35
  "ufo": "1.0.1",
36
36
  "untyped": "1.2.2"
37
37
  },