@vixt/core 0.7.0 → 0.7.2
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/node/index.d.mts +19 -6
- package/dist/node/index.mjs +17 -7
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ConfigLayer, ConfigLayerMeta, LoadConfigOptions } from "c12";
|
|
1
|
+
import { ConfigLayer, ConfigLayerMeta, LoadConfigOptions, ResolvedConfig } from "c12";
|
|
3
2
|
import * as vite0 from "vite";
|
|
4
3
|
import { HtmlTagDescriptor, InlineConfig, LogLevel, PluginOption, ServerOptions, UserConfig } from "vite";
|
|
5
4
|
import Legacy from "@vitejs/plugin-legacy";
|
|
@@ -38,7 +37,10 @@ interface VixtModule<T extends ModuleOptions = ModuleOptions> {
|
|
|
38
37
|
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
39
38
|
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
40
39
|
declare function installModule<T extends ModuleOptions = ModuleOptions>(module: VixtModule<T>, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
41
|
-
declare function applyLayerModules(
|
|
40
|
+
declare function applyLayerModules({
|
|
41
|
+
config,
|
|
42
|
+
layers
|
|
43
|
+
}: ResolvedVixtConfig): Promise<VixtModule[]>;
|
|
42
44
|
//#endregion
|
|
43
45
|
//#region src/node/config.d.ts
|
|
44
46
|
interface VixtOptions {
|
|
@@ -137,6 +139,12 @@ interface VixtOptions {
|
|
|
137
139
|
plugins?: string[];
|
|
138
140
|
/** typescript */
|
|
139
141
|
typescript?: TypescriptOptions;
|
|
142
|
+
/**
|
|
143
|
+
* Whether to copy layers from `node_modules` to `.vixt/layers`
|
|
144
|
+
* @default true
|
|
145
|
+
* @experimental
|
|
146
|
+
*/
|
|
147
|
+
copyLayers?: boolean;
|
|
140
148
|
/** custom options */
|
|
141
149
|
[key: string]: any;
|
|
142
150
|
}
|
|
@@ -251,9 +259,14 @@ interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta>
|
|
|
251
259
|
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
252
260
|
cwd?: string;
|
|
253
261
|
}
|
|
262
|
+
interface LoadVixtConfigOptions extends LoadConfigOptions<VixtOptions, VixtConfigLayerMeta> {}
|
|
263
|
+
interface ResolvedVixtConfig extends ResolvedConfig<VixtOptions, VixtConfigLayerMeta> {}
|
|
254
264
|
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
255
|
-
declare function loadVixtConfig(opts?:
|
|
256
|
-
declare function applyLayers(
|
|
265
|
+
declare function loadVixtConfig(opts?: LoadVixtConfigOptions): Promise<ResolvedVixtConfig>;
|
|
266
|
+
declare function applyLayers({
|
|
267
|
+
config,
|
|
268
|
+
layers
|
|
269
|
+
}: ResolvedVixtConfig): VixtConfigLayer[];
|
|
257
270
|
declare function isSamePath(a: string, b: string): boolean;
|
|
258
271
|
declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
|
|
259
272
|
declare const VixtClientAutoImports: Record<string, string[]>;
|
|
@@ -301,4 +314,4 @@ declare const virtualModuleIds: {
|
|
|
301
314
|
};
|
|
302
315
|
declare const builtinModules: (VixtModule<ModuleOptions> | VixtModule<AliasOptions> | VixtModule<AppOptions> | VixtModule<BuildOptions> | VixtModule<DevServerOptions> | VixtModule<TypescriptOptions>)[];
|
|
303
316
|
//#endregion
|
|
304
|
-
export { AliasOptions, AppHead, AppHeadAttrs, AppOptions, BuildOptions, DevServerOptions, ExtractPluginOptions, GlobalCLIOptions, ModuleDefinition, ModuleMeta, ModuleOptions, TypescriptOptions, Vixt, VixtClientAutoImports, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions, applyLayerModules, applyLayers, builtinModules, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadCLIOptions, loadEnv, loadMode, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, virtualModuleIds };
|
|
317
|
+
export { AliasOptions, AppHead, AppHeadAttrs, AppOptions, BuildOptions, DevServerOptions, ExtractPluginOptions, GlobalCLIOptions, LoadVixtConfigOptions, ModuleDefinition, ModuleMeta, ModuleOptions, ResolvedVixtConfig, TypescriptOptions, Vixt, VixtClientAutoImports, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions, applyLayerModules, applyLayers, builtinModules, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadCLIOptions, loadEnv, loadMode, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, virtualModuleIds };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loadConfig } from "c12";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import path, { normalize, resolve } from "pathe";
|
|
4
|
-
import
|
|
4
|
+
import { cwd, env } from "node:process";
|
|
5
5
|
import { cac } from "cac";
|
|
6
6
|
import { findUpSync } from "find-up";
|
|
7
7
|
import { loadEnv as loadEnv$1, mergeConfig, parseAst } from "vite";
|
|
@@ -73,14 +73,24 @@ async function loadVixtConfig(opts) {
|
|
|
73
73
|
config.pluginsDir ??= resolve(config.srcDir, "plugins");
|
|
74
74
|
return result;
|
|
75
75
|
}
|
|
76
|
-
function applyLayers(
|
|
77
|
-
const { rootDir } = config;
|
|
76
|
+
function applyLayers({ config, layers = [] }) {
|
|
77
|
+
const { rootDir, buildLayersDir, copyLayers = true } = config;
|
|
78
78
|
return layers.filter((e) => e.cwd).map((layer) => {
|
|
79
79
|
layer.config ??= {};
|
|
80
80
|
layer.config.meta ??= {};
|
|
81
81
|
const meta = layer.config.meta;
|
|
82
82
|
const layerName = meta.name || layer.cwd.split("/").pop();
|
|
83
83
|
if (!isSamePath(layer.cwd, resolve(rootDir))) meta.alias = `#/layers/${layerName}`;
|
|
84
|
+
if (copyLayers && layer.cwd?.includes("node_modules")) {
|
|
85
|
+
const newCwd = resolve(buildLayersDir, layerName);
|
|
86
|
+
fs.removeSync(newCwd);
|
|
87
|
+
fs.copySync(layer.cwd, newCwd, { filter: (src) => {
|
|
88
|
+
const nodeModulesPath = resolve(layer.cwd, "node_modules");
|
|
89
|
+
const tsConfigPath = resolve(layer.cwd, "tsconfig.json");
|
|
90
|
+
return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
|
|
91
|
+
} });
|
|
92
|
+
layer.cwd = newCwd;
|
|
93
|
+
}
|
|
84
94
|
layer.config.rootDir ??= layer.cwd;
|
|
85
95
|
layer.config.srcDir ??= resolve(layer.config.rootDir, "src");
|
|
86
96
|
layer.config.modulesDir ??= resolve(layer.config.srcDir, "modules");
|
|
@@ -141,10 +151,10 @@ function defineVixtModule(definition) {
|
|
|
141
151
|
function installModule(module, inlineOptions, vixt) {
|
|
142
152
|
return module(inlineOptions, vixt);
|
|
143
153
|
}
|
|
144
|
-
async function applyLayerModules(layers) {
|
|
154
|
+
async function applyLayerModules({ config, layers = [] }) {
|
|
145
155
|
const { modules: modulesDirs = [] } = resolveLayersDirs(layers);
|
|
146
156
|
const modules = [];
|
|
147
|
-
const jiti = createJiti(
|
|
157
|
+
const jiti = createJiti(config.rootDir, { moduleCache: false });
|
|
148
158
|
for (const m of modulesDirs.reverse()) if (fs.existsSync(m)) {
|
|
149
159
|
const files = fs.readdirSync(m);
|
|
150
160
|
for (const f of files) try {
|
|
@@ -614,8 +624,8 @@ async function loadVixt(opts) {
|
|
|
614
624
|
cliOptions.force && fs.removeSync(result.config.buildDir);
|
|
615
625
|
result.config.debug = !!cliOptions.debug;
|
|
616
626
|
result.config.dev = env.NODE_ENV !== "production";
|
|
617
|
-
result.layers = applyLayers(result
|
|
618
|
-
const layerModules = await applyLayerModules(result
|
|
627
|
+
result.layers = applyLayers(result);
|
|
628
|
+
const layerModules = await applyLayerModules(result);
|
|
619
629
|
return {
|
|
620
630
|
options: result.config,
|
|
621
631
|
_layers: result.layers ?? [],
|