@dtwo/kit 3.1.2 → 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 +12 -3
- package/dist/index.mjs +19 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
@@ -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, ExtendRouteRulesOptions, ExtendWebpackConfigOptions, ExtendWiteConfigOptions, LoadDtwoConfigOptions, LoadDtwoOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -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, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtwo/kit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"repository": "d2js/dtwo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dtwo/schema": "3.
|
|
13
|
+
"@dtwo/schema": "3.2.0",
|
|
14
14
|
"c12": "1.1.0",
|
|
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.
|
|
21
|
-
"kdimport": "2.
|
|
20
|
+
"jiti": "1.17.0",
|
|
21
|
+
"kdimport": "2.2.4",
|
|
22
22
|
"knitwork": "1.0.0",
|
|
23
23
|
"lodash.template": "4.5.0",
|
|
24
24
|
"mlly": "1.1.0",
|