@dtwo/kit 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 +12 -3
- package/dist/index.mjs +26 -5
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promises, existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import
|
|
2
|
+
import { defu } from 'defu';
|
|
3
3
|
import { applyDefaults } from 'untyped';
|
|
4
4
|
import { dirname, join, normalize, relative, isAbsolute, resolve, basename, parse } from 'pathe';
|
|
5
5
|
import consola from 'consola';
|
|
@@ -147,7 +147,7 @@ function defineDtwoModule(definition) {
|
|
|
147
147
|
if (uniqueKey) {
|
|
148
148
|
dtwo.options._requiredModules = dtwo.options._requiredModules || {};
|
|
149
149
|
if (dtwo.options._requiredModules[uniqueKey]) {
|
|
150
|
-
return;
|
|
150
|
+
return false;
|
|
151
151
|
}
|
|
152
152
|
dtwo.options._requiredModules[uniqueKey] = true;
|
|
153
153
|
}
|
|
@@ -432,7 +432,10 @@ async function resolveFiles(path, pattern, opts = {}) {
|
|
|
432
432
|
async function installModule(moduleToInstall, _inlineOptions, _dtwo) {
|
|
433
433
|
const dtwo = useDtwo();
|
|
434
434
|
const { dtwoModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions);
|
|
435
|
-
await dtwoModule(inlineOptions, dtwo);
|
|
435
|
+
const res = await dtwoModule(inlineOptions, dtwo);
|
|
436
|
+
if (res === false) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
436
439
|
if (typeof moduleToInstall === "string") {
|
|
437
440
|
dtwo.options.build.transpile.push(moduleToInstall);
|
|
438
441
|
}
|
|
@@ -794,9 +797,27 @@ function extendRouteRules(route, rule, options = {}) {
|
|
|
794
797
|
if (!opts.routeRules) {
|
|
795
798
|
opts.routeRules = {};
|
|
796
799
|
}
|
|
797
|
-
opts.routeRules[route] = options.override ? defu
|
|
800
|
+
opts.routeRules[route] = options.override ? defu(rule, opts.routeRules[route]) : defu(opts.routeRules[route], rule);
|
|
798
801
|
}
|
|
799
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
|
+
}
|
|
800
821
|
|
|
801
822
|
function normalizePlugin(plugin) {
|
|
802
823
|
if (typeof plugin === "string") {
|
|
@@ -829,4 +850,4 @@ function addPluginTemplate(plugin, opts = {}) {
|
|
|
829
850
|
return addPlugin(normalizedPlugin, opts);
|
|
830
851
|
}
|
|
831
852
|
|
|
832
|
-
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",
|