@dtwo/kit 3.0.0 → 3.1.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/LICENSE +1 -1
- package/README.md +6 -2
- package/dist/index.d.ts +17 -6
- package/dist/index.mjs +40 -4
- package/package.json +23 -23
package/LICENSE
CHANGED
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ModuleOptions, ModuleDefinition, DtwoModule, Dtwo, DtwoConfig, DtwoOptions, 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, 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
5
|
import { UserConfig, Plugin } from 'wite';
|
|
6
6
|
import * as unctx_index from 'unctx/index';
|
|
7
|
-
import { HoleEventHandler, HoleDevEventHandler, Hole } from 'holepack';
|
|
7
|
+
import { HoleEventHandler, HoleDevEventHandler, Hole, HoleRouteConfig } from 'holepack';
|
|
8
8
|
import * as consola from 'consola';
|
|
9
9
|
import { genSafeVariableName } from 'knitwork';
|
|
10
10
|
|
|
@@ -34,6 +34,8 @@ interface LoadDtwoOptions extends LoadDtwoConfigOptions {
|
|
|
34
34
|
declare function loadDtwo(opts: LoadDtwoOptions): Promise<Dtwo>;
|
|
35
35
|
declare function buildDtwo(dtwo: Dtwo): Promise<any>;
|
|
36
36
|
|
|
37
|
+
declare function extendDtwoSchema(def: SchemaDefinition | (() => SchemaDefinition)): void;
|
|
38
|
+
|
|
37
39
|
declare function addImports(imports: Import | Import[]): void;
|
|
38
40
|
declare function addImportsDir(dirs: string | string[]): void;
|
|
39
41
|
declare function addImportsSources(presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]): void;
|
|
@@ -69,7 +71,7 @@ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
|
|
69
71
|
interface ExtendWiteConfigOptions extends ExtendConfigOptions {
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
|
-
* Extend
|
|
74
|
+
* Extend webpack config
|
|
73
75
|
*
|
|
74
76
|
* The fallback function might be called multiple times
|
|
75
77
|
* when applying to both client and server builds.
|
|
@@ -80,7 +82,7 @@ declare function extendWebpackConfig(fn: ((config: Configuration) => void), opti
|
|
|
80
82
|
*/
|
|
81
83
|
declare function extendWiteConfig(fn: ((config: UserConfig) => void), options?: ExtendWiteConfigOptions): (() => void) | undefined;
|
|
82
84
|
/**
|
|
83
|
-
* Append
|
|
85
|
+
* Append webpack plugin to the config.
|
|
84
86
|
*/
|
|
85
87
|
declare function addWebpackPlugin(plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions): void;
|
|
86
88
|
/**
|
|
@@ -200,7 +202,16 @@ declare function isIgnored(pathname: string): boolean;
|
|
|
200
202
|
|
|
201
203
|
declare function addLayout(this: any, template: DtwoTemplate, name?: string): void;
|
|
202
204
|
|
|
203
|
-
declare function extendPages(cb: DtwoHooks['pages:extend']): void;
|
|
205
|
+
declare function extendPages(cb: DtwoHooks['pages:extend']): void;
|
|
206
|
+
interface ExtendRouteRulesOptions {
|
|
207
|
+
/**
|
|
208
|
+
* Override route rule config
|
|
209
|
+
*
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
override?: boolean;
|
|
213
|
+
}
|
|
214
|
+
declare function extendRouteRules(route: string, rule: HoleRouteConfig, options?: ExtendRouteRulesOptions): void;
|
|
204
215
|
|
|
205
216
|
/**
|
|
206
217
|
* Normalize a dtwo plugin object
|
|
@@ -330,4 +341,4 @@ declare const templateUtils: {
|
|
|
330
341
|
}) => string;
|
|
331
342
|
};
|
|
332
343
|
|
|
333
|
-
export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, 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, extendPages, 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 };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promises, existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import defu from 'defu';
|
|
2
|
+
import defu, { defu as defu$1 } 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';
|
|
@@ -259,9 +259,11 @@ function requireModulePkg(id, opts = {}) {
|
|
|
259
259
|
function resolveModule(id, opts = {}) {
|
|
260
260
|
return normalize(_require.resolve(id, {
|
|
261
261
|
paths: [].concat(
|
|
262
|
+
// @ts-ignore
|
|
262
263
|
global.__DTWO_PREPATHS__,
|
|
263
264
|
opts.paths || [],
|
|
264
265
|
process.cwd(),
|
|
266
|
+
// @ts-ignore
|
|
265
267
|
global.__DTWO_PATHS__
|
|
266
268
|
).filter(Boolean)
|
|
267
269
|
}));
|
|
@@ -311,18 +313,35 @@ function isIgnored(pathname) {
|
|
|
311
313
|
}
|
|
312
314
|
if (!dtwo._ignore) {
|
|
313
315
|
dtwo._ignore = ignore(dtwo.options.ignoreOptions);
|
|
314
|
-
dtwo.
|
|
316
|
+
const resolvedIgnore = dtwo.options.ignore.flatMap((s) => resolveGroupSyntax(s));
|
|
317
|
+
dtwo._ignore.add(resolvedIgnore);
|
|
315
318
|
const dtwoignoreFile = join(dtwo.options.rootDir, ".dtwoignore");
|
|
316
319
|
if (existsSync(dtwoignoreFile)) {
|
|
317
320
|
dtwo._ignore.add(readFileSync(dtwoignoreFile, "utf-8"));
|
|
318
321
|
}
|
|
319
322
|
}
|
|
320
|
-
const
|
|
323
|
+
const cwds = dtwo.options._layers?.map((layer2) => layer2.cwd).sort((a, b) => b.length - a.length);
|
|
324
|
+
const layer = cwds?.find((cwd) => pathname.startsWith(cwd));
|
|
325
|
+
const relativePath = relative(layer ?? dtwo.options.rootDir, pathname);
|
|
321
326
|
if (relativePath.startsWith("..")) {
|
|
322
327
|
return false;
|
|
323
328
|
}
|
|
324
329
|
return !!(relativePath && dtwo._ignore.ignores(relativePath));
|
|
325
330
|
}
|
|
331
|
+
function resolveGroupSyntax(group) {
|
|
332
|
+
let groups = [group];
|
|
333
|
+
while (groups.some((group2) => group2.includes("{"))) {
|
|
334
|
+
groups = groups.flatMap((group2) => {
|
|
335
|
+
const [head, ...tail] = group2.split("{");
|
|
336
|
+
if (tail.length) {
|
|
337
|
+
const [body, ...rest] = tail.join("{").split("}");
|
|
338
|
+
return body.split(",").map((part) => `${head}${part}${rest.join("")}`);
|
|
339
|
+
}
|
|
340
|
+
return group2;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return groups;
|
|
344
|
+
}
|
|
326
345
|
|
|
327
346
|
async function resolvePath(path, opts = {}) {
|
|
328
347
|
const _path = path;
|
|
@@ -500,6 +519,7 @@ async function loadDtwo(opts) {
|
|
|
500
519
|
configOverrides: opts.overrides,
|
|
501
520
|
ready: opts.ready,
|
|
502
521
|
envConfig: opts.dotenv
|
|
522
|
+
// TODO: Backward format convertion
|
|
503
523
|
});
|
|
504
524
|
return dtwo;
|
|
505
525
|
}
|
|
@@ -513,6 +533,13 @@ async function buildDtwo(dtwo) {
|
|
|
513
533
|
return build(dtwo);
|
|
514
534
|
}
|
|
515
535
|
|
|
536
|
+
function extendDtwoSchema(def) {
|
|
537
|
+
const dtwo = useDtwo();
|
|
538
|
+
dtwo.hook("schema:extend", (schemas) => {
|
|
539
|
+
schemas.push(typeof def === "function" ? def() : def);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
516
543
|
function addImports(imports) {
|
|
517
544
|
assertDtwoCompatibility({ bridge: true });
|
|
518
545
|
useDtwo().hook("imports:extend", (_imports) => {
|
|
@@ -761,6 +788,15 @@ function extendPages(cb) {
|
|
|
761
788
|
dtwo.hook("pages:extend", cb);
|
|
762
789
|
}
|
|
763
790
|
}
|
|
791
|
+
function extendRouteRules(route, rule, options = {}) {
|
|
792
|
+
const dtwo = useDtwo();
|
|
793
|
+
for (const opts of [dtwo.options, dtwo.options.hole]) {
|
|
794
|
+
if (!opts.routeRules) {
|
|
795
|
+
opts.routeRules = {};
|
|
796
|
+
}
|
|
797
|
+
opts.routeRules[route] = options.override ? defu$1(rule, opts.routeRules[route]) : defu$1(opts.routeRules[route], rule);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
764
800
|
|
|
765
801
|
function normalizePlugin(plugin) {
|
|
766
802
|
if (typeof plugin === "string") {
|
|
@@ -793,4 +829,4 @@ function addPluginTemplate(plugin, opts = {}) {
|
|
|
793
829
|
return addPlugin(normalizedPlugin, opts);
|
|
794
830
|
}
|
|
795
831
|
|
|
796
|
-
export { addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addServerHandler, addServerPlugin, addTemplate, addWebpackPlugin, addWitePlugin, assertDtwoCompatibility, buildDtwo, checkDtwoCompatibility, clearRequireCache, compileTemplate, createResolver, defineDtwoModule, dtwoCtx, extendPages, 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 };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtwo/kit",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"repository": "d2js/
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"repository": "d2js/dtwo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.mjs",
|
|
@@ -10,29 +10,29 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dtwo/schema": "3.
|
|
14
|
-
"c12": "
|
|
15
|
-
"consola": "
|
|
16
|
-
"defu": "
|
|
17
|
-
"globby": "
|
|
18
|
-
"hash-sum": "
|
|
19
|
-
"ignore": "
|
|
20
|
-
"jiti": "
|
|
21
|
-
"kdimport": "
|
|
22
|
-
"knitwork": "
|
|
23
|
-
"lodash.template": "
|
|
24
|
-
"mlly": "
|
|
25
|
-
"pathe": "
|
|
26
|
-
"pkg-types": "
|
|
27
|
-
"scule": "
|
|
28
|
-
"semver": "
|
|
29
|
-
"unctx": "
|
|
30
|
-
"untyped": "
|
|
13
|
+
"@dtwo/schema": "3.1.0",
|
|
14
|
+
"c12": "1.1.0",
|
|
15
|
+
"consola": "2.15.3",
|
|
16
|
+
"defu": "6.1.1",
|
|
17
|
+
"globby": "13.1.3",
|
|
18
|
+
"hash-sum": "2.0.0",
|
|
19
|
+
"ignore": "5.2.4",
|
|
20
|
+
"jiti": "1.16.2",
|
|
21
|
+
"kdimport": "2.0.1",
|
|
22
|
+
"knitwork": "1.0.0",
|
|
23
|
+
"lodash.template": "4.5.0",
|
|
24
|
+
"mlly": "1.1.0",
|
|
25
|
+
"pathe": "1.0.0",
|
|
26
|
+
"pkg-types": "1.0.1",
|
|
27
|
+
"scule": "1.0.0",
|
|
28
|
+
"semver": "7.3.8",
|
|
29
|
+
"unctx": "2.1.1",
|
|
30
|
+
"untyped": "1.2.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/lodash.template": "
|
|
34
|
-
"@types/semver": "
|
|
35
|
-
"unbuild": "
|
|
33
|
+
"@types/lodash.template": "4.5.1",
|
|
34
|
+
"@types/semver": "7.3.13",
|
|
35
|
+
"unbuild": "1.1.1"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|