@hylid/env 3.0.0-alpha.4 → 3.0.0-alpha.7

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/lib/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { ClientEnv, PlatformEnv } from './types';
2
- declare let client: string | undefined;
3
- declare let platform: string | undefined;
2
+ export declare function getDefaultDiscernEnv(): {
3
+ client: string | undefined;
4
+ platform: string | undefined;
5
+ };
6
+ declare let client: string | undefined, platform: string | undefined;
4
7
  interface CustomEnv {
5
8
  client?: string;
6
9
  platform?: string;
package/lib/index.js CHANGED
@@ -1,30 +1,39 @@
1
1
  import { createCommonEnv, getSettingName, isMP, notice } from "./utils";
2
2
  import { getName4MP, getName4MpWeb, getName4Web } from "./getClientName";
3
3
  import { CLIENT, PLATFORM } from "./constants";
4
- var client;
5
- var platform;
6
- if (isMP()) {
7
- client = getName4MP();
8
- platform = PLATFORM.MP;
9
- } else {
10
- var setting = getSettingName();
11
- if (setting.platform) {
12
- platform = setting.platform;
13
- client = setting.client || (platform === 'mpweb' ? getName4MpWeb() : getName4Web());
4
+ export function getDefaultDiscernEnv() {
5
+ var client;
6
+ var platform;
7
+ if (isMP()) {
8
+ client = getName4MP();
9
+ platform = PLATFORM.MP;
14
10
  } else {
15
- // 如果只设置了 client,默认是套壳场景
16
- client = setting.client || getName4MpWeb();
17
- if (client) {
18
- platform = PLATFORM.MPWEB;
11
+ var setting = getSettingName();
12
+ if (setting.platform) {
13
+ platform = setting.platform;
14
+ client = setting.client || (platform === 'mpweb' ? getName4MpWeb() : getName4Web());
19
15
  } else {
20
- client = getName4Web();
21
- platform = PLATFORM.WEB;
16
+ // 如果只设置了 client,默认是套壳场景
17
+ client = setting.client || getName4MpWeb();
18
+ if (client) {
19
+ platform = PLATFORM.MPWEB;
20
+ } else {
21
+ client = getName4Web();
22
+ platform = PLATFORM.WEB;
23
+ }
22
24
  }
23
25
  }
26
+ if (!platform || !client) {
27
+ notice('Cannot identify your client.');
28
+ }
29
+ return {
30
+ client: client,
31
+ platform: platform
32
+ };
24
33
  }
25
- if (!platform || !client) {
26
- notice('Cannot identify your client.');
27
- }
34
+ var _a = getDefaultDiscernEnv(),
35
+ client = _a.client,
36
+ platform = _a.platform;
28
37
  export function customEnv(config) {
29
38
  var custom = typeof config === 'function' ? config({
30
39
  client: client,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hylid/env",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.7",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib"