@dev-to/react-plugin 0.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/dist/lan.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function getLanIPv4Hosts(): string[];
2
+ //# sourceMappingURL=lan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lan.d.ts","sourceRoot":"","sources":["../src/lan.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAc1C"}
@@ -0,0 +1,44 @@
1
+ import { type ConfigEnv, type UserConfig } from 'vite';
2
+ import type { DevToReactPluginOptions, ResolvedDevComponentConfig } from './types.js';
3
+ /** 判断是否为 lib 模式构建 */
4
+ export declare function isLibBuild(env?: ConfigEnv): boolean;
5
+ /** 转换为安全的输出目录名 */
6
+ export declare function toSafeOutDirName(componentName: string): string;
7
+ /** 转换为合法的 UMD 全局变量名 */
8
+ export declare function toSafeUmdName(componentName: string): string;
9
+ /** 校验是否为合法 JS 标识符 */
10
+ export declare function isValidJsIdentifier(name: string): boolean;
11
+ /** 生成库模式的虚拟入口模块代码(智能处理导出) */
12
+ export declare function generateLibVirtualEntryCode(params: {
13
+ rootDir: string;
14
+ defaultEntryAbs: string;
15
+ componentName: string;
16
+ }): string;
17
+ /** 生成虚拟入口模块路径(用于 lib.entry 配置) */
18
+ export declare function getLibVirtualEntryPath(componentName: string): string;
19
+ /** 将生成的 CSS 文件重命名为与 Component 同名 */
20
+ export declare function normalizeLibCss(outDir: string, baseName: string): void;
21
+ /** 解析当前的构建目标列表 */
22
+ export declare function resolveBuildTargets(params: {
23
+ componentMap: Record<string, string>;
24
+ requestedRaw: string;
25
+ defaultEntryAbs: string;
26
+ }): string[];
27
+ /** 生成库模式的构建配置 */
28
+ export declare function generateLibBuildNextConfig(params: {
29
+ rootDir: string;
30
+ configDir?: string;
31
+ picked: string;
32
+ componentMap: Record<string, string>;
33
+ resolvedConfig: ResolvedDevComponentConfig;
34
+ options: DevToReactPluginOptions;
35
+ userConfig: UserConfig;
36
+ }): {
37
+ next: UserConfig;
38
+ outDir: string;
39
+ outBase: string;
40
+ buildTargets: string[];
41
+ virtualEntryCode: string;
42
+ resolvedEntryAbs: string;
43
+ };
44
+ //# sourceMappingURL=libBuildUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libBuildUtils.d.ts","sourceRoot":"","sources":["../src/libBuildUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAKnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAErF,qBAAqB;AACrB,wBAAgB,UAAU,CAAC,GAAG,CAAC,EAAE,SAAS,WAEzC;AAED,kBAAkB;AAClB,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,UAErD;AAED,uBAAuB;AACvB,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,UAKlD;AAED,qBAAqB;AACrB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,WAE/C;AA8LD,6BAA6B;AAC7B,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;CACtB,GAAG,MAAM,CA+IT;AAED,kCAAkC;AAClC,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,oCAAoC;AACpC,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QA+B/D;AAED,kBAAkB;AAClB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB,YA8BA;AAED,iBAAiB;AACjB,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,cAAc,EAAE,0BAA0B,CAAA;IAC1C,OAAO,EAAE,uBAAuB,CAAA;IAChC,UAAU,EAAE,UAAU,CAAA;CACvB,GAAG;IACF,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAuGA"}
@@ -0,0 +1,7 @@
1
+ /** 将 Vite 内部的 /@fs 路径转换为真实文件系统路径 */
2
+ export declare function toFsPathFromViteEntry(entry: string): string | null;
3
+ /** 尝试补全扩展名进行文件探测 */
4
+ export declare function tryResolveWithExtensions(p: string): string | null;
5
+ /** 解析入口文件的绝对路径,支持相对路径、绝对路径和 / 开头的路径 */
6
+ export declare function resolveEntryAbsPath(rootDir: string, entry: string, defaultEntryAbs?: string, fallbackRoot?: string): string | null;
7
+ //# sourceMappingURL=pathUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAKA,oCAAoC;AACpC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQlE;AAED,oBAAoB;AACpB,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBjE;AAED,uCAAuC;AACvC,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,EACxB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,GAAG,IAAI,CA4Bf"}
@@ -0,0 +1,6 @@
1
+ import { type Plugin } from 'vite';
2
+ import type { DevComponentMapInput, DevToReactPluginOptions } from './types.js';
3
+ export declare const devToReactPlugin: (devComponentMap?: DevComponentMapInput, options?: DevToReactPluginOptions) => Plugin[];
4
+ /** @deprecated Use `devToReactPlugin` instead. */
5
+ export declare const viteHostReactBridgePlugin: (devComponentMap?: DevComponentMapInput, options?: DevToReactPluginOptions) => Plugin[];
6
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAA+B,KAAK,MAAM,EAAwC,MAAM,MAAM,CAAA;AA4BrG,OAAO,KAAK,EAIV,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AA0BnB,eAAO,MAAM,gBAAgB,GAC3B,kBAAiB,oBAAyB,EAC1C,UAAS,uBAA4B,KACpC,MAAM,EA8fR,CAAA;AAED,kDAAkD;AAClD,eAAO,MAAM,yBAAyB,qBAngBnB,oBAAoB,YAC5B,uBAAuB,KAC/B,MAAM,EAigBgD,CAAA"}
@@ -0,0 +1,27 @@
1
+ export declare function injectReactImport(code: string, id: string): {
2
+ code: string;
3
+ map: null;
4
+ } | null;
5
+ /**
6
+ * 转换静态资源导入路径
7
+ * 在 Electron file:// 宿主中,将相对路径转换为带 Origin 的完整 URL
8
+ */
9
+ export declare function transformAssetUrl(code: string, id: string): {
10
+ code: string;
11
+ map: null;
12
+ } | null;
13
+ /**
14
+ * Fix Vite dev CSS asset URLs for cross-origin hosts.
15
+ *
16
+ * In Vite dev mode, CSS is served as a JS module that injects a <style> tag,
17
+ * and asset urls are commonly rewritten to root-relative paths (e.g. "/src/..").
18
+ * When this module is imported cross-origin (e.g. host is http://localhost:8080),
19
+ * those urls will wrongly resolve against the host origin.
20
+ *
21
+ * We patch the injected CSS string at runtime to prefix the dev server origin.
22
+ */
23
+ export declare function transformViteDevCssAssetUrls(code: string, id: string): {
24
+ code: string;
25
+ map: null;
26
+ } | null;
27
+ //# sourceMappingURL=transformUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformUtils.d.ts","sourceRoot":"","sources":["../src/transformUtils.ts"],"names":[],"mappings":"AAQA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;SAczD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;SA8BzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;SA2CpE"}
@@ -0,0 +1,74 @@
1
+ import type { BuildOptions, CSSOptions } from 'vite';
2
+ export interface DevToReactPluginOptions {
3
+ /**
4
+ * 透传给 Vite 的 `css` 配置(开发与构建态均生效)。
5
+ *
6
+ * 默认提供稳定的 CSS Modules 命名规则:
7
+ * `[name]__[local]___[hash:base64:5]`
8
+ *
9
+ * - 传 `false`:禁用插件注入的所有 CSS 配置
10
+ * - 传对象:与插件默认配置深度合并
11
+ */
12
+ css?: CSSOptions | false;
13
+ /**
14
+ * 透传给 Vite 的 `build` 配置(仅在 `vite build --mode lib` 时生效)。
15
+ *
16
+ * 典型用途:
17
+ * - 调整资源内联:`assetsInlineLimit`
18
+ * - 调整 rollup:`rollupOptions`
19
+ * - 调整压缩/产物:`minify` / `sourcemap` / `target` 等
20
+ *
21
+ * 插件会将此配置与内部生成的 `next.build` 做深度合并(以这里传入的为准)。
22
+ */
23
+ build?: BuildOptions;
24
+ /**
25
+ * 启动开发服务器后,是否自动在浏览器中打开调试面板。
26
+ * @default false
27
+ */
28
+ open?: boolean;
29
+ }
30
+ /** @deprecated Use `DevToReactPluginOptions` instead. */
31
+ export type ViteHostReactBridgePluginOptions = DevToReactPluginOptions;
32
+ export type DevComponentMapInput = Record<string, string> | string | undefined | null;
33
+ export interface DevComponentAudit {
34
+ defaultEntryAbs: string;
35
+ defaultEntryExists: boolean;
36
+ componentMapCount: number;
37
+ missingEntries: Array<{
38
+ componentName: string;
39
+ filePath: string;
40
+ }>;
41
+ }
42
+ export interface ResolvedDevComponentConfig {
43
+ defaultEntryAbs: string;
44
+ defaultEntry: string;
45
+ componentMap: Record<string, string>;
46
+ audit: DevComponentAudit;
47
+ }
48
+ export interface BridgeStatsBucket {
49
+ count: number;
50
+ lastAt: number;
51
+ }
52
+ export interface BridgeStats {
53
+ contract: BridgeStatsBucket;
54
+ init: BridgeStatsBucket;
55
+ runtime: BridgeStatsBucket;
56
+ }
57
+ export interface BridgeContract {
58
+ paths: {
59
+ contract: string;
60
+ initClient: string;
61
+ reactRuntime: string;
62
+ };
63
+ events: {
64
+ fullReload: string;
65
+ hmrUpdate: string;
66
+ };
67
+ dev: {
68
+ componentMap: Record<string, string>;
69
+ };
70
+ }
71
+ export interface DebugStartupState {
72
+ didPrintStartupDebugUrl: boolean;
73
+ }
74
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEpD,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,CAAA;IAExB;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,yDAAyD;AACzD,MAAM,MAAM,gCAAgC,GAAG,uBAAuB,CAAA;AAEtE,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;AAErF,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,KAAK,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACnE;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,KAAK,EAAE,iBAAiB,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,IAAI,EAAE,iBAAiB,CAAA;IACvB,OAAO,EAAE,iBAAiB,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAA;QAChB,UAAU,EAAE,MAAM,CAAA;QAClB,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;IACD,GAAG,EAAE;QACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACrC,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,uBAAuB,EAAE,OAAO,CAAA;CACjC"}
@@ -0,0 +1,5 @@
1
+ import type { BridgeContract } from './types.js';
2
+ export declare function createContractVirtualModuleCode(contract: BridgeContract): string;
3
+ export declare function createInitVirtualModuleCode(): string;
4
+ export declare function createReactRuntimeVirtualModuleCode(): string;
5
+ //# sourceMappingURL=virtualModules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtualModules.d.ts","sourceRoot":"","sources":["../src/virtualModules.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,cAAc,UAuBvE;AAED,wBAAgB,2BAA2B,WAqE1C;AAED,wBAAgB,mCAAmC,WAuBlD"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@dev-to/react-plugin",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "peerDependencies": {
18
+ "react": ">=18.0.0",
19
+ "react-dom": ">=18.0.0",
20
+ "typescript": ">=5.0.0",
21
+ "vite": ">=4.0.0"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/YangYongAn/dev-to.git",
26
+ "directory": "packages/react-plugin"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "picocolors": "^1.1.0",
33
+ "typescript": "^5.4.5",
34
+ "@dev-to/react-shared": "0.1.0"
35
+ },
36
+ "scripts": {
37
+ "build": "rslib build",
38
+ "dev": "rslib build --watch",
39
+ "lint": "pnpm -w lint",
40
+ "test": "echo 'test @dev-to/react-plugin'"
41
+ }
42
+ }