@yannick-z/modulo 0.3.6 → 0.3.8

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.
Files changed (37) hide show
  1. package/bin/modulo.js +0 -10
  2. package/dist/131.js +1 -1
  3. package/package.json +3 -3
  4. package/types/rslib.config.d.ts +2 -0
  5. package/types/src/args/get-framework-name.d.ts +1 -0
  6. package/types/src/args/index.d.ts +20 -0
  7. package/types/src/args/preset.d.ts +2 -0
  8. package/types/src/bin/modulo.d.ts +1 -0
  9. package/types/src/cli/init.d.ts +2 -0
  10. package/types/src/cli/pack-code.d.ts +2 -0
  11. package/types/src/config/example/example-config.d.ts +4 -0
  12. package/types/src/config/example/example-externals.d.ts +12 -0
  13. package/types/src/config/index.d.ts +25 -0
  14. package/types/src/config/presets.d.ts +97 -0
  15. package/types/src/config/type.d.ts +33 -0
  16. package/types/src/index.d.ts +2 -0
  17. package/types/src/initiator/create-config-file.d.ts +2 -0
  18. package/types/src/initiator/create-project.d.ts +2 -0
  19. package/types/src/initiator/modify-scripts.d.ts +2 -0
  20. package/types/src/packer/auto-external-plugin.d.ts +18 -0
  21. package/types/src/packer/collect-modules.d.ts +11 -0
  22. package/types/src/packer/get-externals-and-tags.d.ts +13 -0
  23. package/types/src/packer/lib.d.ts +9 -0
  24. package/types/src/packer/page.d.ts +9 -0
  25. package/types/src/packer/prepare.d.ts +7 -0
  26. package/types/src/tools/cli.d.ts +6 -0
  27. package/types/src/tools/file.d.ts +30 -0
  28. package/types/src/tools/find-path-root.d.ts +2 -0
  29. package/types/src/tools/get-framework-name.d.ts +1 -0
  30. package/types/src/tools/get-ui-plugin.d.ts +4 -0
  31. package/types/src/tools/json.d.ts +15 -0
  32. package/types/src/tools/log.d.ts +18 -0
  33. package/types/src/tools/merge-user-config.d.ts +1 -0
  34. package/types/src/tools/omit-root-path.d.ts +12 -0
  35. package/types/src/tools/panic.d.ts +1 -0
  36. package/types/src/tools/string.d.ts +10 -0
  37. package/types/src/type/guard.d.ts +7 -0
package/bin/modulo.js CHANGED
@@ -1,15 +1,5 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- const requiredVersion = 24;
4
- const currentVersion = process.version.match(/^v(\d+)/)?.[1];
5
-
6
- if (!currentVersion || parseInt(currentVersion, 10) < requiredVersion) {
7
- console.error(
8
- `\x1b[31mError: Node.js version ${process.version} is not supported. Please use Node.js v${requiredVersion} or higher.\x1b[0m`,
9
- );
10
- process.exit(1);
11
- }
12
-
13
3
  import("../src/index.ts")
14
4
  .then((module) => {
15
5
  // console.log("\nsupport ts, use Typescript code\n");
package/dist/131.js CHANGED
@@ -27,7 +27,7 @@ const logger = {
27
27
  }
28
28
  };
29
29
  var package_namespaceObject = {
30
- rE: "0.3.5"
30
+ rE: "0.3.8"
31
31
  };
32
32
  const cli = cac("modulo");
33
33
  cli.command("init <target>", "Initialize modulo configuration or scripts").option("-f, --force", "Force overwrite existing files").option("--path <path>", "Specify the path to initialize").option("--preset <preset>", "Specify the preset to use").action((target, options)=>{
package/package.json CHANGED
@@ -2,13 +2,12 @@
2
2
  "name": "@yannick-z/modulo",
3
3
  "description": "",
4
4
  "type": "module",
5
- "version": "0.3.6",
5
+ "version": "0.3.8",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./types/src/index.d.ts",
8
8
  "author": "oyangxiao",
9
9
  "scripts": {
10
- "build": "rslib build && tsc",
11
- "build.d.ts": "tsc --emitDeclarationOnly",
10
+ "build": "rslib build && tsc --emitDeclarationOnly",
12
11
  "lint": "biome lint src bin rslib.config.ts",
13
12
  "format": "biome format --write src bin rslib.config.ts package.json biome.json",
14
13
  "check": "biome check --write src bin rslib.config.ts package.json biome.json"
@@ -20,6 +19,7 @@
20
19
  "dist",
21
20
  "bin",
22
21
  "src",
22
+ "types",
23
23
  "template",
24
24
  "README.md",
25
25
  "LICENSE"
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@rslib/core").RslibConfig;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export declare function detect_preset(): string;
@@ -0,0 +1,20 @@
1
+ import type { preset_ui_libs } from "../config/presets.ts";
2
+ export interface ModuloArgs_Pack {
3
+ cmd: "build" | "dev" | "preview";
4
+ target: "page" | "module" | "all";
5
+ pack: {
6
+ config?: string;
7
+ env: "dev" | "prd";
8
+ watch: boolean;
9
+ esm: boolean;
10
+ };
11
+ }
12
+ export interface ModuloArgs_Init {
13
+ cmd: "init";
14
+ target: "config" | "script" | "project";
15
+ init: {
16
+ path: string;
17
+ force: boolean;
18
+ preset: keyof typeof preset_ui_libs;
19
+ };
20
+ }
@@ -0,0 +1,2 @@
1
+ import type minimist from "minimist";
2
+ export declare function get_preset_for_init(argv: minimist.ParsedArgs): any;
@@ -0,0 +1 @@
1
+ #! /usr/bin/env node
@@ -0,0 +1,2 @@
1
+ import type { ModuloArgs_Init } from "../args/index.ts";
2
+ export declare function init_tool(args: ModuloArgs_Init): void;
@@ -0,0 +1,2 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ export declare function pack_code(args: ModuloArgs_Pack): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { preset_ui_libs } from "../presets.ts";
2
+ import type { USER_CONFIG } from "../type.ts";
3
+ export declare function get_example_config(preset?: keyof typeof preset_ui_libs | undefined): USER_CONFIG;
4
+ export declare const default_config_file_name = "modulo.config.ts";
@@ -0,0 +1,12 @@
1
+ import type { ExternalLibs } from "../type.ts";
2
+ export declare const vue2_example_externals: ExternalLibs;
3
+ export declare const react19_example_externals: ExternalLibs;
4
+ export declare const common_example_externals: ExternalLibs;
5
+ export declare const presets: {
6
+ vue2: {
7
+ [x: string]: string | import("../type.ts").ImportExternal | import("../type.ts").EnvExternalUrl;
8
+ };
9
+ react19: {
10
+ [x: string]: string | import("../type.ts").ImportExternal | import("../type.ts").EnvExternalUrl;
11
+ };
12
+ };
@@ -0,0 +1,25 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ import type { GLOBAL_CONFIG } from "./type.ts";
3
+ /**
4
+ * 命令启动时候的目录作为根目录
5
+ */
6
+ export declare const root: string;
7
+ interface PackageJson {
8
+ name: string;
9
+ dependencies: Record<string, string>;
10
+ scripts: undefined | Record<string, string>;
11
+ }
12
+ export declare function get_packagejson(customRoot?: string): PackageJson;
13
+ /**
14
+ * 获取全局配置(单例模式)
15
+ *
16
+ * 1. 读取用户配置文件
17
+ * 2. 处理 extends 继承逻辑
18
+ * 3. 与默认配置进行合并
19
+ * 4. 处理路径别名、环境变量、目录解析等
20
+ *
21
+ * @param args CLI 参数
22
+ * @returns 合并后的全局配置对象
23
+ */
24
+ export declare function get_global_config(args: ModuloArgs_Pack): Promise<GLOBAL_CONFIG>;
25
+ export {};
@@ -0,0 +1,97 @@
1
+ import type { OutputConfig } from "@rsbuild/core";
2
+ import type { ExternalLibs } from "./type.ts";
3
+ export declare const preset_alias: Record<string, string>;
4
+ export declare const preset_dev_server_config: {
5
+ open: false | string[];
6
+ port: number;
7
+ proxy: Record<string, string | {
8
+ target: string;
9
+ pathRewrite?: Record<string, string>;
10
+ changeOrigin?: boolean;
11
+ secure?: boolean;
12
+ }>;
13
+ };
14
+ export type DEV_SERVER_CONFIG = typeof preset_dev_server_config;
15
+ export declare const preset_input_dirs: {
16
+ src: string;
17
+ pages: string;
18
+ modules: string;
19
+ };
20
+ export declare const preset_output_dirs: {
21
+ distPath: string;
22
+ pages: string;
23
+ modules: string;
24
+ filenameHash: boolean;
25
+ };
26
+ export interface Tag {
27
+ append?: boolean;
28
+ attrs?: Record<string, string>;
29
+ children?: string;
30
+ hash?: boolean | string;
31
+ head?: boolean;
32
+ publicPath?: string | boolean;
33
+ tag: string;
34
+ }
35
+ export declare const default_html_config: {
36
+ meta: Record<string, string>;
37
+ root: string;
38
+ tags: Tag[];
39
+ template: string;
40
+ title: string;
41
+ };
42
+ export type HTML_CONFIG = typeof default_html_config;
43
+ export declare const preset_ui_libs: {
44
+ react19: string;
45
+ vue2: string;
46
+ };
47
+ export declare const preset_minify_config: OutputConfig["minify"];
48
+ export declare const preset_url_config: {
49
+ base: string;
50
+ cdn: string;
51
+ };
52
+ export declare const preset_config: {
53
+ analyze: boolean;
54
+ define: Record<string, string | boolean | number>;
55
+ dev_server: {
56
+ open: false | string[];
57
+ port: number;
58
+ proxy: Record<string, string | {
59
+ target: string;
60
+ pathRewrite?: Record<string, string>;
61
+ changeOrigin?: boolean;
62
+ secure?: boolean;
63
+ }>;
64
+ };
65
+ externals: ExternalLibs;
66
+ html: {
67
+ meta: Record<string, string>;
68
+ root: string;
69
+ tags: Tag[];
70
+ template: string;
71
+ title: string;
72
+ };
73
+ input: {
74
+ src: string;
75
+ pages: string;
76
+ modules: string;
77
+ };
78
+ minify: OutputConfig["minify"];
79
+ output: {
80
+ distPath: string;
81
+ pages: string;
82
+ modules: string;
83
+ filenameHash: boolean;
84
+ };
85
+ ui_lib: {
86
+ react19: string;
87
+ vue2: string;
88
+ };
89
+ url: {
90
+ base: string;
91
+ cdn: string;
92
+ };
93
+ alias: Record<string, string>;
94
+ webhost: boolean | "auto";
95
+ autoExternal: boolean;
96
+ externalsType: "importmap" | "script";
97
+ };
@@ -0,0 +1,33 @@
1
+ import type { preset_config } from "./presets.ts";
2
+ export type GLOBAL_CONFIG = typeof preset_config;
3
+ export interface EnvExternalUrl {
4
+ dev: string;
5
+ prd: string;
6
+ }
7
+ export type ConfigExternalUrl = EnvExternalUrl | string;
8
+ export interface ImportExternal {
9
+ url: ConfigExternalUrl;
10
+ importName?: string | string[];
11
+ global?: string;
12
+ preset?: string;
13
+ }
14
+ export type ExternalLibs = {
15
+ [name: string]: ImportExternal | EnvExternalUrl | string;
16
+ };
17
+ export interface USER_CONFIG {
18
+ extends?: string;
19
+ analyze?: boolean;
20
+ define?: GLOBAL_CONFIG["define"];
21
+ dev_server?: Partial<GLOBAL_CONFIG["dev_server"]>;
22
+ externals?: GLOBAL_CONFIG["externals"];
23
+ html?: Partial<GLOBAL_CONFIG["html"]>;
24
+ input?: Partial<GLOBAL_CONFIG["input"]>;
25
+ minify?: Partial<GLOBAL_CONFIG["minify"]> | boolean;
26
+ output?: Partial<GLOBAL_CONFIG["output"]>;
27
+ ui_lib?: Partial<GLOBAL_CONFIG["ui_lib"]>;
28
+ alias?: GLOBAL_CONFIG["alias"];
29
+ url?: Partial<GLOBAL_CONFIG["url"]>;
30
+ webhost?: GLOBAL_CONFIG["webhost"];
31
+ autoExternal?: boolean;
32
+ externalsType?: "importmap" | "script";
33
+ }
@@ -0,0 +1,2 @@
1
+ export type { USER_CONFIG as UserConfig } from "./config/type.ts";
2
+ export declare function exec(): void;
@@ -0,0 +1,2 @@
1
+ import type { ModuloArgs_Init } from "../args/index.ts";
2
+ export declare function create_config_file(args: ModuloArgs_Init): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { ModuloArgs_Init } from "../args/index.ts";
2
+ export declare function create_project(args: ModuloArgs_Init): Promise<void>;
@@ -0,0 +1,2 @@
1
+ export declare const star_line = "**********************";
2
+ export declare function modify_scripts(): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ import type { GLOBAL_CONFIG } from "../config/type.ts";
3
+ /**
4
+ * 自动 External 插件
5
+ *
6
+ * 1. 扫描编译过程中使用到的 node_modules 依赖
7
+ * 2. 如果这些依赖在 config.externals 中定义了,则标记为已使用
8
+ * 3. 在 HTML 生成阶段,仅注入已使用的依赖的 importmap 或 script 标签
9
+ */
10
+ export declare class AutoExternalPlugin {
11
+ private externalLibNames;
12
+ private usedExternals;
13
+ private args;
14
+ private config;
15
+ constructor(args: ModuloArgs_Pack, config: GLOBAL_CONFIG);
16
+ apply(compiler: any): void;
17
+ private processTags;
18
+ }
@@ -0,0 +1,11 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ import type { GLOBAL_CONFIG } from "../config/type.ts";
3
+ /**
4
+ * 收集模块入口文件
5
+ * 扫描指定目录下的子目录,查找符合规则的入口文件(index/main/同名文件)
6
+ *
7
+ * @param args CLI 参数
8
+ * @param kind 模块类型(page 或 module)
9
+ * @returns 模块名到入口文件路径的映射对象,如果未找到任何模块则返回 undefined
10
+ */
11
+ export declare function collect_modules(args: ModuloArgs_Pack, kind: "page" | "module", global_config: GLOBAL_CONFIG): Record<string, string> | undefined;
@@ -0,0 +1,13 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ import { type ExternalLibs } from "../config/type.ts";
3
+ /**
4
+ * 解析 External 配置,生成 externals 对象和 importMap
5
+ * @param args CLI 参数
6
+ * @param externalLibs 外部依赖配置
7
+ * @param externalsType External 类型(importmap 或 script)
8
+ * @returns externals 和 importMap
9
+ */
10
+ export declare function getExternalsAndImportMap(args: ModuloArgs_Pack, externalLibs: ExternalLibs, externalsType?: "importmap" | "script"): {
11
+ externals: Record<string, string>;
12
+ importMap: Record<string, string>;
13
+ };
@@ -0,0 +1,9 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ /**
3
+ * 执行库(module)打包
4
+ *
5
+ * 使用 Rslib 将模块目录下的代码打包为 ESM 和 UMD 格式。
6
+ *
7
+ * @param args CLI 参数
8
+ */
9
+ export declare function lib_pack(args: ModuloArgs_Pack): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ /**
3
+ * 执行页面(page)打包
4
+ *
5
+ * 使用 Rsbuild 构建单页应用或多页应用。
6
+ *
7
+ * @param args CLI 参数
8
+ */
9
+ export declare function page_pack(args: ModuloArgs_Pack): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import type { ModuloArgs_Pack } from "../args/index.ts";
2
+ import type { GLOBAL_CONFIG } from "../config/type.ts";
3
+ export declare function prepare_config(args: ModuloArgs_Pack, kind: "page" | "module", config: GLOBAL_CONFIG): {
4
+ entries: Record<string, string> | undefined;
5
+ externals: Record<string, string>;
6
+ importMapsTag: any;
7
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CLI 交互式确认
3
+ * @param message 提示信息
4
+ * @returns Promise<boolean> 用户是否确认 (Y/y 为 true)
5
+ */
6
+ export declare function confirm(message: string): Promise<boolean>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 读取文件内容
3
+ * @param path 文件绝对路径
4
+ * @param error_msg 自定义错误消息(可选)
5
+ * @param throwError 是否抛出错误(默认 false)
6
+ * @returns 文件内容字符串,如果失败则返回空字符串(除非 throwError 为 true)
7
+ */
8
+ export declare function read_file(path: string, error_msg?: string, throwError?: boolean): string;
9
+ /**
10
+ * 解析路径并读取文件
11
+ */
12
+ export declare function resolve_and_read(root: string, name: string): string;
13
+ /**
14
+ * 获取指定目录下的所有子目录名称
15
+ * @param path 目标目录路径
16
+ * @returns 子目录名称列表
17
+ */
18
+ export declare function get_directories(path: string): string[];
19
+ /**
20
+ * 在目录中查找入口文件
21
+ * @param dir 目标目录
22
+ * @param candidates 候选文件名(不含扩展名)列表,优先级按顺序
23
+ * @param extensions 支持的扩展名列表,优先级按顺序
24
+ * @returns 找到的入口文件绝对路径,如果未找到返回 undefined
25
+ */
26
+ export declare function find_entry_file(dir: string, candidates: string[], extensions?: string[]): string | undefined;
27
+ /**
28
+ * 检查文件是否存在
29
+ */
30
+ export declare function exists(path: string): boolean;
@@ -0,0 +1,2 @@
1
+ export declare function get_package_root(): string;
2
+ export declare function find_workspace_root(cwd: string): string | undefined;
@@ -0,0 +1 @@
1
+ export declare function get_framework_name(): "vue" | "react";
@@ -0,0 +1,4 @@
1
+ import { type PluginReactOptions } from "@rsbuild/plugin-react";
2
+ import { type PluginVueOptions } from "@rsbuild/plugin-vue2";
3
+ import type { GLOBAL_CONFIG } from "../config/type.ts";
4
+ export declare function framework_plugin(global_config: GLOBAL_CONFIG, options?: PluginVueOptions | PluginReactOptions): import("@rsbuild/core").RsbuildPlugin;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 解析 JSON 字符串
3
+ * @param input JSON 字符串
4
+ * @param defaultValue 解析失败或输入为空时的默认值(可选)
5
+ * @returns 解析后的对象或默认值
6
+ */
7
+ export declare function jsonparse<T>(input: string, defaultValue?: T): T | undefined;
8
+ /**
9
+ * 更新 JSON 文件
10
+ * @param path 文件路径
11
+ * @param updater 更新函数,接收当前数据并返回新数据
12
+ * @param createIfNotExist 如果文件不存在是否创建(默认 false)
13
+ * @returns 是否更新成功
14
+ */
15
+ export declare function update_json_file<T = any>(path: string, updater: (data: T) => T, createIfNotExist?: boolean): boolean;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 调试日志函数
3
+ *
4
+ * 仅在 process.env.DEBUG 开启或 CLI 参数包含 --debug/--verbose 时输出。
5
+ * - --verbose: 直接输出到控制台
6
+ * - --debug: 输出日志文件到当前目录的 modulo.debug.log,并在控制台打印序号
7
+ *
8
+ * @param hint 日志标题或提示信息
9
+ * @param params 日志内容(可以是任意对象)
10
+ */
11
+ export declare function debug_log(hint: string, ...params: unknown[]): void;
12
+ export declare const logger: {
13
+ info: (msg: string) => void;
14
+ success: (msg: string) => void;
15
+ warn: (msg: string) => void;
16
+ error: (msg: string) => void;
17
+ debug: (msg: string) => void;
18
+ };
@@ -0,0 +1 @@
1
+ export declare function merge_user_config(target: any, input: any): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 获取相对于根目录的路径
3
+ * @param path 绝对路径
4
+ * @returns 相对路径(以 / 开头)
5
+ */
6
+ export declare function omit_root_path(path: string): string;
7
+ /**
8
+ * 批量处理入口文件路径
9
+ */
10
+ export declare function omit_root_path_for_entries(entries: Record<string, string>): {
11
+ [k: string]: string;
12
+ };
@@ -0,0 +1 @@
1
+ export declare function PANIC_IF(status?: boolean, msg?: string, halt?: boolean): asserts status is false;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 首字母大写,其余小写
3
+ * @param str 输入字符串
4
+ * @returns 格式化后的字符串
5
+ */
6
+ export declare function capitalize(str: string): string;
7
+ /**
8
+ * @deprecated Use capitalize instead
9
+ */
10
+ export declare const first_letter_upper: typeof capitalize;
@@ -0,0 +1,7 @@
1
+ import { type EnvExternalUrl, type ConfigExternalUrl, type ImportExternal } from "../config/type.ts";
2
+ export declare function is_string(data: unknown): data is string;
3
+ export declare function is_true_string(data: unknown): data is string;
4
+ export declare function is_record(data: unknown): data is Record<string, unknown>;
5
+ export declare function is_env_external(data: unknown): data is EnvExternalUrl;
6
+ export declare function is_url_config(data: unknown): data is ConfigExternalUrl;
7
+ export declare function is_import_external(data: unknown): data is ImportExternal;