@weapp-tailwindcss/env 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +56 -2
- package/README.zh-CN.md +57 -0
- package/dist/index.cjs +670 -0
- package/dist/index.d.cts +140 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.js +623 -0
- package/package.json +57 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type DetectableAppType = 'mpx' | 'taro' | 'uni-app' | 'uni-app-vite' | 'uni-app-x' | 'weapp-vite';
|
|
3
|
+
type FrameworkEnv = Record<string, string | undefined> & Partial<Record<'MPX_CLI_MODE' | 'MPX_CURRENT_TARGET_MODE' | 'NODE_PATH' | 'TARO_ENV' | 'UNI_PLATFORM' | 'UNI_UTS_PLATFORM' | 'WEAPP_TAILWINDCSS_TARGET' | 'WEAPP_TW_TARGET', string | undefined>>;
|
|
4
|
+
interface UniPlatformInfo {
|
|
5
|
+
raw: string | undefined;
|
|
6
|
+
normalized: string | undefined;
|
|
7
|
+
isApp: boolean;
|
|
8
|
+
isAppAndroid: boolean;
|
|
9
|
+
isAppHarmony: boolean;
|
|
10
|
+
isAppIos: boolean;
|
|
11
|
+
isMp: boolean;
|
|
12
|
+
isWeb: boolean;
|
|
13
|
+
}
|
|
14
|
+
type CanonicalPlatform = 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-jd' | 'mp-qq' | 'mp-toutiao' | 'mp-dingtalk' | 'web' | 'app' | 'app-plus' | 'app-android' | 'app-ios' | 'app-harmony';
|
|
15
|
+
interface PlatformIdentityInfo {
|
|
16
|
+
raw: string | undefined;
|
|
17
|
+
normalized: string | undefined;
|
|
18
|
+
canonical: CanonicalPlatform | undefined;
|
|
19
|
+
}
|
|
20
|
+
interface HBuilderXRuntimeHints {
|
|
21
|
+
cwd?: string | undefined;
|
|
22
|
+
env?: FrameworkEnv | undefined;
|
|
23
|
+
nodePath?: string | null | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface PackageJsonLike {
|
|
26
|
+
'dependencies'?: Record<string, string> | undefined;
|
|
27
|
+
'devDependencies'?: Record<string, string> | undefined;
|
|
28
|
+
'peerDependencies'?: Record<string, string> | undefined;
|
|
29
|
+
'optionalDependencies'?: Record<string, string> | undefined;
|
|
30
|
+
'scripts'?: Record<string, string> | undefined;
|
|
31
|
+
'uni-app'?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface UniAppManifestLike {
|
|
34
|
+
'uni-app-x'?: unknown;
|
|
35
|
+
}
|
|
36
|
+
interface DetectAppTypeOptions {
|
|
37
|
+
/**
|
|
38
|
+
* 项目根目录。传入后会读取 marker、manifest.json 与 package.json。
|
|
39
|
+
*/
|
|
40
|
+
root?: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 已解析的 package.json 内容。适合在调用方已经读取配置时复用。
|
|
43
|
+
*/
|
|
44
|
+
packageJson?: PackageJsonLike | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* 已解析的 uni-app manifest.json 内容,用于识别 uni-app x。
|
|
47
|
+
*/
|
|
48
|
+
manifest?: UniAppManifestLike | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* 是否从 root 向上查找 package.json 与 manifest.json。
|
|
51
|
+
*
|
|
52
|
+
* @default `true`
|
|
53
|
+
*/
|
|
54
|
+
searchUp?: boolean | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* 环境变量快照。传入后可用于识别 HBuilderX、Taro、MPX 与 uni-app 运行环境。
|
|
57
|
+
* 缺失字段不会回退到进程环境。
|
|
58
|
+
*/
|
|
59
|
+
env?: FrameworkEnv | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* 是否读取当前进程环境变量参与推断。
|
|
62
|
+
*
|
|
63
|
+
* @default `false`
|
|
64
|
+
*/
|
|
65
|
+
detectEnv?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* HBuilderX 插件运行时的工作目录。默认使用 `root`,启用 `detectEnv` 时会回退到 `process.cwd()`。
|
|
68
|
+
*/
|
|
69
|
+
cwd?: string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* 是否在 HBuilderX 插件运行时把 uni-app 识别为 uni-app Vite。
|
|
72
|
+
*
|
|
73
|
+
* @default `true`
|
|
74
|
+
*/
|
|
75
|
+
hbuilderxVite?: boolean | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** 框架识别实际命中的配置、文件或环境信号。 */
|
|
78
|
+
interface AppTypeDetectionEvidence {
|
|
79
|
+
source: 'manifest' | 'dependency' | 'script' | 'package-field' | 'marker' | 'env' | 'hbuilderx';
|
|
80
|
+
key: string;
|
|
81
|
+
path?: string | undefined;
|
|
82
|
+
value?: string | undefined;
|
|
83
|
+
}
|
|
84
|
+
/** 同一框架在首次命中阶段的全部证据。 */
|
|
85
|
+
interface AppTypeDetectionCandidate {
|
|
86
|
+
appType: DetectableAppType;
|
|
87
|
+
evidence: AppTypeDetectionEvidence[];
|
|
88
|
+
}
|
|
89
|
+
/** 当前识别决定的解释;不扫描被优先阶段遮蔽的项目。 */
|
|
90
|
+
interface AppTypeDetectionReport {
|
|
91
|
+
appType: DetectableAppType | undefined;
|
|
92
|
+
candidates: AppTypeDetectionCandidate[];
|
|
93
|
+
conflicts: DetectableAppType[];
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/detect-env.d.ts
|
|
97
|
+
interface EnvironmentDetectionOptions {
|
|
98
|
+
cwd?: string | undefined;
|
|
99
|
+
hbuilderxVite?: boolean | undefined;
|
|
100
|
+
}
|
|
101
|
+
export declare function detectAppTypeFromEnv(env?: FrameworkEnv, options?: EnvironmentDetectionOptions): DetectableAppType | undefined;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/hbuilderx.d.ts
|
|
104
|
+
export declare function isRunningInHBuilderX(options?: HBuilderXRuntimeHints): boolean;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/package.d.ts
|
|
107
|
+
export declare function isWeappVitePackage(pkg: PackageJsonLike): boolean;
|
|
108
|
+
export declare function isMpxPackage(pkg: PackageJsonLike): boolean;
|
|
109
|
+
export declare function isTaroPackage(pkg: PackageJsonLike): boolean;
|
|
110
|
+
export declare function isUniAppVitePackage(pkg: PackageJsonLike): boolean;
|
|
111
|
+
export declare function isUniAppXPackage(pkg: PackageJsonLike): boolean;
|
|
112
|
+
export declare function isUniAppPackage(pkg: PackageJsonLike): boolean;
|
|
113
|
+
export declare function isUniAppXManifest(manifest: UniAppManifestLike | undefined): boolean;
|
|
114
|
+
export declare function detectAppTypeFromPackageJson(pkg: PackageJsonLike): DetectableAppType | undefined;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/platform.d.ts
|
|
117
|
+
export declare function resolvePlatform(value: string | undefined): UniPlatformInfo;
|
|
118
|
+
export declare function resolveTaroPlatform(value?: string | undefined): UniPlatformInfo;
|
|
119
|
+
/** 读取 Taro 环境快照;省略快照时才使用调用时的进程环境。 */
|
|
120
|
+
export declare function resolveTaroPlatformFromEnv(env?: FrameworkEnv): UniPlatformInfo;
|
|
121
|
+
export declare function resolveMpxPlatform(value?: string | undefined): UniPlatformInfo;
|
|
122
|
+
/** 读取 MPX 环境快照,保留 current mode 的空字符串优先级。 */
|
|
123
|
+
export declare function resolveMpxPlatformFromEnv(env?: FrameworkEnv): UniPlatformInfo;
|
|
124
|
+
export declare function resolveUniPlatform(value?: string | undefined): UniPlatformInfo;
|
|
125
|
+
export declare function resolveUniUtsPlatform(value?: string | undefined): UniPlatformInfo;
|
|
126
|
+
export declare function resolveUniAppXPlatform(value?: string | undefined): UniPlatformInfo;
|
|
127
|
+
export declare function resolveUniPlatformsFromEnv(env?: FrameworkEnv): {
|
|
128
|
+
uniPlatform: UniPlatformInfo;
|
|
129
|
+
uniAppXPlatform: UniPlatformInfo;
|
|
130
|
+
uniUtsPlatform: UniPlatformInfo;
|
|
131
|
+
};
|
|
132
|
+
export declare function normalizeFrameworkStylePlatform(platform: string | undefined, appType: string | undefined): string | undefined;
|
|
133
|
+
export declare function resolvePlatformIdentity(platform: string | undefined, appType?: DetectableAppType): PlatformIdentityInfo;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/project.d.ts
|
|
136
|
+
export declare function detectAppType(options?: DetectAppTypeOptions): DetectableAppType | undefined;
|
|
137
|
+
/** 解释首次命中阶段的框架候选与冲突,不扩大项目搜索范围。 */
|
|
138
|
+
export declare function detectAppTypeReport(options?: DetectAppTypeOptions): AppTypeDetectionReport;
|
|
139
|
+
//#endregion
|
|
140
|
+
export type { AppTypeDetectionCandidate, AppTypeDetectionEvidence, AppTypeDetectionReport, CanonicalPlatform, DetectAppTypeOptions, DetectableAppType, FrameworkEnv, HBuilderXRuntimeHints, PackageJsonLike, PlatformIdentityInfo, UniAppManifestLike, UniPlatformInfo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type DetectableAppType = 'mpx' | 'taro' | 'uni-app' | 'uni-app-vite' | 'uni-app-x' | 'weapp-vite';
|
|
3
|
+
type FrameworkEnv = Record<string, string | undefined> & Partial<Record<'MPX_CLI_MODE' | 'MPX_CURRENT_TARGET_MODE' | 'NODE_PATH' | 'TARO_ENV' | 'UNI_PLATFORM' | 'UNI_UTS_PLATFORM' | 'WEAPP_TAILWINDCSS_TARGET' | 'WEAPP_TW_TARGET', string | undefined>>;
|
|
4
|
+
interface UniPlatformInfo {
|
|
5
|
+
raw: string | undefined;
|
|
6
|
+
normalized: string | undefined;
|
|
7
|
+
isApp: boolean;
|
|
8
|
+
isAppAndroid: boolean;
|
|
9
|
+
isAppHarmony: boolean;
|
|
10
|
+
isAppIos: boolean;
|
|
11
|
+
isMp: boolean;
|
|
12
|
+
isWeb: boolean;
|
|
13
|
+
}
|
|
14
|
+
type CanonicalPlatform = 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-jd' | 'mp-qq' | 'mp-toutiao' | 'mp-dingtalk' | 'web' | 'app' | 'app-plus' | 'app-android' | 'app-ios' | 'app-harmony';
|
|
15
|
+
interface PlatformIdentityInfo {
|
|
16
|
+
raw: string | undefined;
|
|
17
|
+
normalized: string | undefined;
|
|
18
|
+
canonical: CanonicalPlatform | undefined;
|
|
19
|
+
}
|
|
20
|
+
interface HBuilderXRuntimeHints {
|
|
21
|
+
cwd?: string | undefined;
|
|
22
|
+
env?: FrameworkEnv | undefined;
|
|
23
|
+
nodePath?: string | null | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface PackageJsonLike {
|
|
26
|
+
'dependencies'?: Record<string, string> | undefined;
|
|
27
|
+
'devDependencies'?: Record<string, string> | undefined;
|
|
28
|
+
'peerDependencies'?: Record<string, string> | undefined;
|
|
29
|
+
'optionalDependencies'?: Record<string, string> | undefined;
|
|
30
|
+
'scripts'?: Record<string, string> | undefined;
|
|
31
|
+
'uni-app'?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface UniAppManifestLike {
|
|
34
|
+
'uni-app-x'?: unknown;
|
|
35
|
+
}
|
|
36
|
+
interface DetectAppTypeOptions {
|
|
37
|
+
/**
|
|
38
|
+
* 项目根目录。传入后会读取 marker、manifest.json 与 package.json。
|
|
39
|
+
*/
|
|
40
|
+
root?: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 已解析的 package.json 内容。适合在调用方已经读取配置时复用。
|
|
43
|
+
*/
|
|
44
|
+
packageJson?: PackageJsonLike | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* 已解析的 uni-app manifest.json 内容,用于识别 uni-app x。
|
|
47
|
+
*/
|
|
48
|
+
manifest?: UniAppManifestLike | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* 是否从 root 向上查找 package.json 与 manifest.json。
|
|
51
|
+
*
|
|
52
|
+
* @default `true`
|
|
53
|
+
*/
|
|
54
|
+
searchUp?: boolean | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* 环境变量快照。传入后可用于识别 HBuilderX、Taro、MPX 与 uni-app 运行环境。
|
|
57
|
+
* 缺失字段不会回退到进程环境。
|
|
58
|
+
*/
|
|
59
|
+
env?: FrameworkEnv | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* 是否读取当前进程环境变量参与推断。
|
|
62
|
+
*
|
|
63
|
+
* @default `false`
|
|
64
|
+
*/
|
|
65
|
+
detectEnv?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* HBuilderX 插件运行时的工作目录。默认使用 `root`,启用 `detectEnv` 时会回退到 `process.cwd()`。
|
|
68
|
+
*/
|
|
69
|
+
cwd?: string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* 是否在 HBuilderX 插件运行时把 uni-app 识别为 uni-app Vite。
|
|
72
|
+
*
|
|
73
|
+
* @default `true`
|
|
74
|
+
*/
|
|
75
|
+
hbuilderxVite?: boolean | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** 框架识别实际命中的配置、文件或环境信号。 */
|
|
78
|
+
interface AppTypeDetectionEvidence {
|
|
79
|
+
source: 'manifest' | 'dependency' | 'script' | 'package-field' | 'marker' | 'env' | 'hbuilderx';
|
|
80
|
+
key: string;
|
|
81
|
+
path?: string | undefined;
|
|
82
|
+
value?: string | undefined;
|
|
83
|
+
}
|
|
84
|
+
/** 同一框架在首次命中阶段的全部证据。 */
|
|
85
|
+
interface AppTypeDetectionCandidate {
|
|
86
|
+
appType: DetectableAppType;
|
|
87
|
+
evidence: AppTypeDetectionEvidence[];
|
|
88
|
+
}
|
|
89
|
+
/** 当前识别决定的解释;不扫描被优先阶段遮蔽的项目。 */
|
|
90
|
+
interface AppTypeDetectionReport {
|
|
91
|
+
appType: DetectableAppType | undefined;
|
|
92
|
+
candidates: AppTypeDetectionCandidate[];
|
|
93
|
+
conflicts: DetectableAppType[];
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/detect-env.d.ts
|
|
97
|
+
interface EnvironmentDetectionOptions {
|
|
98
|
+
cwd?: string | undefined;
|
|
99
|
+
hbuilderxVite?: boolean | undefined;
|
|
100
|
+
}
|
|
101
|
+
export declare function detectAppTypeFromEnv(env?: FrameworkEnv, options?: EnvironmentDetectionOptions): DetectableAppType | undefined;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/hbuilderx.d.ts
|
|
104
|
+
export declare function isRunningInHBuilderX(options?: HBuilderXRuntimeHints): boolean;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/package.d.ts
|
|
107
|
+
export declare function isWeappVitePackage(pkg: PackageJsonLike): boolean;
|
|
108
|
+
export declare function isMpxPackage(pkg: PackageJsonLike): boolean;
|
|
109
|
+
export declare function isTaroPackage(pkg: PackageJsonLike): boolean;
|
|
110
|
+
export declare function isUniAppVitePackage(pkg: PackageJsonLike): boolean;
|
|
111
|
+
export declare function isUniAppXPackage(pkg: PackageJsonLike): boolean;
|
|
112
|
+
export declare function isUniAppPackage(pkg: PackageJsonLike): boolean;
|
|
113
|
+
export declare function isUniAppXManifest(manifest: UniAppManifestLike | undefined): boolean;
|
|
114
|
+
export declare function detectAppTypeFromPackageJson(pkg: PackageJsonLike): DetectableAppType | undefined;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/platform.d.ts
|
|
117
|
+
export declare function resolvePlatform(value: string | undefined): UniPlatformInfo;
|
|
118
|
+
export declare function resolveTaroPlatform(value?: string | undefined): UniPlatformInfo;
|
|
119
|
+
/** 读取 Taro 环境快照;省略快照时才使用调用时的进程环境。 */
|
|
120
|
+
export declare function resolveTaroPlatformFromEnv(env?: FrameworkEnv): UniPlatformInfo;
|
|
121
|
+
export declare function resolveMpxPlatform(value?: string | undefined): UniPlatformInfo;
|
|
122
|
+
/** 读取 MPX 环境快照,保留 current mode 的空字符串优先级。 */
|
|
123
|
+
export declare function resolveMpxPlatformFromEnv(env?: FrameworkEnv): UniPlatformInfo;
|
|
124
|
+
export declare function resolveUniPlatform(value?: string | undefined): UniPlatformInfo;
|
|
125
|
+
export declare function resolveUniUtsPlatform(value?: string | undefined): UniPlatformInfo;
|
|
126
|
+
export declare function resolveUniAppXPlatform(value?: string | undefined): UniPlatformInfo;
|
|
127
|
+
export declare function resolveUniPlatformsFromEnv(env?: FrameworkEnv): {
|
|
128
|
+
uniPlatform: UniPlatformInfo;
|
|
129
|
+
uniAppXPlatform: UniPlatformInfo;
|
|
130
|
+
uniUtsPlatform: UniPlatformInfo;
|
|
131
|
+
};
|
|
132
|
+
export declare function normalizeFrameworkStylePlatform(platform: string | undefined, appType: string | undefined): string | undefined;
|
|
133
|
+
export declare function resolvePlatformIdentity(platform: string | undefined, appType?: DetectableAppType): PlatformIdentityInfo;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/project.d.ts
|
|
136
|
+
export declare function detectAppType(options?: DetectAppTypeOptions): DetectableAppType | undefined;
|
|
137
|
+
/** 解释首次命中阶段的框架候选与冲突,不扩大项目搜索范围。 */
|
|
138
|
+
export declare function detectAppTypeReport(options?: DetectAppTypeOptions): AppTypeDetectionReport;
|
|
139
|
+
//#endregion
|
|
140
|
+
export type { AppTypeDetectionCandidate, AppTypeDetectionEvidence, AppTypeDetectionReport, CanonicalPlatform, DetectAppTypeOptions, DetectableAppType, FrameworkEnv, HBuilderXRuntimeHints, PackageJsonLike, PlatformIdentityInfo, UniAppManifestLike, UniPlatformInfo };
|