@dtwo/kit 3.1.2 → 3.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 - Dtwo Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 - Dtwo Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ModuleOptions, ModuleDefinition, DtwoModule, Dtwo, DtwoConfig, DtwoOptions, SchemaDefinition, ImportPresetWithDeprecation, DtwoCompatibility, DtwoCompatibilityIssues, ComponentsDir, Component, DtwoTemplate, DtwoHooks, DtwoPlugin, DtwoPluginTemplate, ResolvedDtwoTemplate } from '@dtwo/schema';
1
+ import { ModuleOptions, ModuleDefinition, DtwoModule, Dtwo, DtwoConfig, DtwoOptions, SchemaDefinition, ImportPresetWithDeprecation, DtwoCompatibility, DtwoCompatibilityIssues, ComponentsDir, Component, DtwoTemplate, DtwoHooks, DtwoMiddleware, DtwoPlugin, DtwoPluginTemplate, ResolvedDtwoTemplate } from '@dtwo/schema';
2
2
  import { LoadConfigOptions } from 'c12';
3
3
  import { Import } from 'kdimport';
4
4
  import { Configuration, WebpackPluginInstance } from 'webpack';
5
- import { UserConfig, Plugin } from 'wite';
5
+ import { UserConfig, Plugin } from 'lahm';
6
6
  import * as unctx_index from 'unctx/index';
7
7
  import { HoleEventHandler, HoleDevEventHandler, Hole, HoleRouteConfig } from 'holepack';
8
8
  import * as consola from 'consola';
@@ -68,7 +68,7 @@ interface ExtendConfigOptions {
68
68
  }
69
69
  interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
70
70
  }
71
- interface ExtendWiteConfigOptions extends ExtendConfigOptions {
71
+ interface ExtendLahmConfigOptions extends ExtendConfigOptions {
72
72
  }
73
73
  /**
74
74
  * Extend webpack config
@@ -78,17 +78,17 @@ interface ExtendWiteConfigOptions extends ExtendConfigOptions {
78
78
  */
79
79
  declare function extendWebpackConfig(fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions): void;
80
80
  /**
81
- * Extend Wite config
81
+ * Extend Lahm config
82
82
  */
83
- declare function extendWiteConfig(fn: ((config: UserConfig) => void), options?: ExtendWiteConfigOptions): (() => void) | undefined;
83
+ declare function extendLahmConfig(fn: ((config: UserConfig) => void), options?: ExtendLahmConfigOptions): (() => void) | undefined;
84
84
  /**
85
85
  * Append webpack plugin to the config.
86
86
  */
87
87
  declare function addWebpackPlugin(plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions): void;
88
88
  /**
89
- * Append Wite plugin to the config.
89
+ * Append Lahm plugin to the config.
90
90
  */
91
- declare function addWitePlugin(plugin: Plugin | Plugin[], options?: ExtendWiteConfigOptions): void;
91
+ declare function addLahmPlugin(plugin: Plugin | Plugin[], options?: ExtendLahmConfigOptions): void;
92
92
 
93
93
  /**
94
94
  * Check version constraints and return incompatibility issues as an array
@@ -211,7 +211,16 @@ interface ExtendRouteRulesOptions {
211
211
  */
212
212
  override?: boolean;
213
213
  }
214
- declare function extendRouteRules(route: string, rule: HoleRouteConfig, options?: ExtendRouteRulesOptions): void;
214
+ declare function extendRouteRules(route: string, rule: HoleRouteConfig, options?: ExtendRouteRulesOptions): void;
215
+ interface AddRouteMiddlewareOptions {
216
+ /**
217
+ * Override existing middleware with the same name, if it exists
218
+ *
219
+ * @default false
220
+ */
221
+ override?: boolean;
222
+ }
223
+ declare function addRouteMiddleware(input: DtwoMiddleware | DtwoMiddleware[], options?: AddRouteMiddlewareOptions): void;
215
224
 
216
225
  /**
217
226
  * Normalize a dtwo plugin object
@@ -341,4 +350,4 @@ declare const templateUtils: {
341
350
  }) => string;
342
351
  };
343
352
 
344
- export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendRouteRulesOptions, ExtendWebpackConfigOptions, ExtendWiteConfigOptions, LoadDtwoConfigOptions, LoadDtwoOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addServerHandler, addServerPlugin, addTemplate, addWebpackPlugin, addWitePlugin, assertDtwoCompatibility, buildDtwo, checkDtwoCompatibility, clearRequireCache, compileTemplate, createResolver, defineDtwoModule, dtwoCtx, extendDtwoSchema, extendPages, extendRouteRules, extendWebpackConfig, extendWiteConfig, findPath, getDtwoVersion, getRequireCacheItem, hasDtwoCompatibility, importModule, installModule, isDtwo2, isDtwo3, isIgnored, isNodeModules, loadDtwo, loadDtwoConfig, logger, normalizePlugin, normalizeTemplate, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseDtwo, updateTemplates, useDtwo, useHole, useLogger };
353
+ export { AddComponentOptions, AddPluginOptions, AddRouteMiddlewareOptions, ExtendConfigOptions, ExtendLahmConfigOptions, ExtendRouteRulesOptions, ExtendWebpackConfigOptions, LoadDtwoConfigOptions, LoadDtwoOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLahmPlugin, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addWebpackPlugin, assertDtwoCompatibility, buildDtwo, checkDtwoCompatibility, clearRequireCache, compileTemplate, createResolver, defineDtwoModule, dtwoCtx, extendDtwoSchema, extendLahmConfig, extendPages, extendRouteRules, extendWebpackConfig, findPath, getDtwoVersion, getRequireCacheItem, hasDtwoCompatibility, importModule, installModule, isDtwo2, isDtwo3, isIgnored, isNodeModules, loadDtwo, loadDtwoConfig, logger, normalizePlugin, normalizeTemplate, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseDtwo, updateTemplates, useDtwo, useHole, useLogger };
package/dist/index.mjs CHANGED
@@ -522,7 +522,7 @@ async function loadDtwo(opts) {
522
522
  configOverrides: opts.overrides,
523
523
  ready: opts.ready,
524
524
  envConfig: opts.dotenv
525
- // TODO: Backward format convertion
525
+ // TODO: Backward format conversion
526
526
  });
527
527
  return dtwo;
528
528
  }
@@ -589,7 +589,7 @@ function extendWebpackConfig(fn, options = {}) {
589
589
  }
590
590
  });
591
591
  }
592
- function extendWiteConfig(fn, options = {}) {
592
+ function extendLahmConfig(fn, options = {}) {
593
593
  const dtwo = useDtwo();
594
594
  if (options.dev === false && dtwo.options.dev) {
595
595
  return;
@@ -598,9 +598,9 @@ function extendWiteConfig(fn, options = {}) {
598
598
  return;
599
599
  }
600
600
  if (options.server !== false && options.client !== false) {
601
- return dtwo.hook("wite:extend", ({ config }) => fn(config));
601
+ return dtwo.hook("lahm:extend", ({ config }) => fn(config));
602
602
  }
603
- dtwo.hook("wite:extendConfig", (config, { isClient, isServer }) => {
603
+ dtwo.hook("lahm:extendConfig", (config, { isClient, isServer }) => {
604
604
  if (options.server !== false && isServer) {
605
605
  return fn(config);
606
606
  }
@@ -619,8 +619,8 @@ function addWebpackPlugin(plugin, options) {
619
619
  }
620
620
  }, options);
621
621
  }
622
- function addWitePlugin(plugin, options) {
623
- extendWiteConfig((config) => {
622
+ function addLahmPlugin(plugin, options) {
623
+ extendLahmConfig((config) => {
624
624
  config.plugins = config.plugins || [];
625
625
  if (Array.isArray(plugin)) {
626
626
  config.plugins.push(...plugin);
@@ -800,6 +800,24 @@ function extendRouteRules(route, rule, options = {}) {
800
800
  opts.routeRules[route] = options.override ? defu(rule, opts.routeRules[route]) : defu(opts.routeRules[route], rule);
801
801
  }
802
802
  }
803
+ function addRouteMiddleware(input, options = {}) {
804
+ const dtwo = useDtwo();
805
+ const middlewares = Array.isArray(input) ? input : [input];
806
+ dtwo.hook("app:resolve", (app) => {
807
+ for (const middleware of middlewares) {
808
+ const find = app.middleware.findIndex((item) => item.name === middleware.name);
809
+ if (find >= 0) {
810
+ if (options.override === true) {
811
+ app.middleware[find] = middleware;
812
+ } else {
813
+ console.warn(`'${middleware.name}' middleware already exists at '${app.middleware[find].path}'. You can set \`override: true\` to replace it.`);
814
+ }
815
+ } else {
816
+ app.middleware.push(middleware);
817
+ }
818
+ }
819
+ });
820
+ }
803
821
 
804
822
  function normalizePlugin(plugin) {
805
823
  if (typeof plugin === "string") {
@@ -832,4 +850,4 @@ function addPluginTemplate(plugin, opts = {}) {
832
850
  return addPlugin(normalizedPlugin, opts);
833
851
  }
834
852
 
835
- export { addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addServerHandler, addServerPlugin, addTemplate, addWebpackPlugin, addWitePlugin, assertDtwoCompatibility, buildDtwo, checkDtwoCompatibility, clearRequireCache, compileTemplate, createResolver, defineDtwoModule, dtwoCtx, extendDtwoSchema, extendPages, extendRouteRules, extendWebpackConfig, extendWiteConfig, findPath, getDtwoVersion, getRequireCacheItem, hasDtwoCompatibility, importModule, installModule, isDtwo2, isDtwo3, isIgnored, isNodeModules, loadDtwo, loadDtwoConfig, logger, normalizePlugin, normalizeTemplate, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseDtwo, updateTemplates, useDtwo, useHole, useLogger };
853
+ export { addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLahmPlugin, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addWebpackPlugin, assertDtwoCompatibility, buildDtwo, checkDtwoCompatibility, clearRequireCache, compileTemplate, createResolver, defineDtwoModule, dtwoCtx, extendDtwoSchema, extendLahmConfig, extendPages, extendRouteRules, extendWebpackConfig, findPath, getDtwoVersion, getRequireCacheItem, hasDtwoCompatibility, importModule, installModule, isDtwo2, isDtwo3, isIgnored, isNodeModules, loadDtwo, loadDtwoConfig, logger, normalizePlugin, normalizeTemplate, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseDtwo, updateTemplates, useDtwo, useHole, useLogger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtwo/kit",
3
- "version": "3.1.2",
3
+ "version": "3.2.1",
4
4
  "repository": "d2js/dtwo",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,23 +10,23 @@
10
10
  "dist"
11
11
  ],
12
12
  "dependencies": {
13
- "@dtwo/schema": "3.1.2",
14
- "c12": "1.1.0",
13
+ "@dtwo/schema": "3.2.1",
14
+ "c12": "1.1.2",
15
15
  "consola": "2.15.3",
16
16
  "defu": "6.1.2",
17
17
  "globby": "13.1.3",
18
18
  "hash-sum": "2.0.0",
19
19
  "ignore": "5.2.4",
20
- "jiti": "1.16.2",
21
- "kdimport": "2.1.0",
20
+ "jiti": "1.17.1",
21
+ "kdimport": "2.2.4",
22
22
  "knitwork": "1.0.0",
23
23
  "lodash.template": "4.5.0",
24
- "mlly": "1.1.0",
24
+ "mlly": "1.1.1",
25
25
  "pathe": "1.1.0",
26
- "pkg-types": "1.0.1",
26
+ "pkg-types": "1.0.2",
27
27
  "scule": "1.0.0",
28
28
  "semver": "7.3.8",
29
- "unctx": "2.1.1",
29
+ "unctx": "2.1.2",
30
30
  "untyped": "1.2.2"
31
31
  },
32
32
  "devDependencies": {
@@ -35,7 +35,7 @@
35
35
  "unbuild": "1.1.1"
36
36
  },
37
37
  "engines": {
38
- "node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
38
+ "node": "^14.18.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
39
39
  },
40
40
  "scripts": {}
41
41
  }
package/README.md DELETED
@@ -1,7 +0,0 @@
1
- # Dtwo
2
-
3
- Dtwo 3: **The Intuitive Web Framework** ✨
4
-
5
- ## License
6
-
7
- [MIT](./LICENSE)