@plugin-light/shared 0.0.11 → 0.0.14

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/README.md CHANGED
@@ -1,19 +1,23 @@
1
1
  ## 公共包
2
2
 
3
- 除 `t-comm` 外,`plugin-light` 中最底层的依赖,业务无需使用。
3
+ 除 `t-comm` 外,`plugin-light-shared` 是整个工具库中最底层的依赖,业务无需直接引用。
4
4
 
5
5
  ### 如何使用
6
6
 
7
7
  安装
8
8
 
9
9
  ```bash
10
- pnpm add plugin-light-shared -D
10
+ pnpm add @plugin-light/shared -D
11
11
  ```
12
12
 
13
13
  使用
14
14
 
15
15
  ```js
16
- import { getDeps } from 'plugin-light-shared';
16
+ import { getDeps } from '@plugin-light/shared';
17
17
 
18
18
  getDeps(__dirname);
19
19
  ```
20
+
21
+ ### 更新日志
22
+
23
+ [点此查看](./CHANGELOG.md)
@@ -0,0 +1,2 @@
1
+ export type IBlackList = Array<string | RegExp>;
2
+ export declare function isInBlackList(filePath: string, blackList?: IBlackList): boolean;
@@ -2,5 +2,6 @@ export * from './cross-game-style';
2
2
  export * from './gen-version';
3
3
  export * from './ifdef';
4
4
  export * from './inject-dynamic-style';
5
+ export * from './node-module-file';
5
6
  export * from './replace-vue-directive';
6
7
  export * from './v-lazy';
@@ -0,0 +1,7 @@
1
+ export type IFindNodeModuleFile = {
2
+ name: string;
3
+ target: string;
4
+ filePath: string;
5
+ root?: string;
6
+ };
7
+ export declare function findNodeModuleFile({ name, target, filePath, root, }: IFindNodeModuleFile): string[];
@@ -0,0 +1 @@
1
+ export { findNodeModuleFile, type IFindNodeModuleFile } from './find';
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './core';
2
+ export { isInBlackList, } from './black-list';
2
3
  export { checkBundleAnalyze, checkDebugMode, } from './bundle-analyze';
3
4
  export { PLATFORM_MAP, ALL_PLATFORM, PLATFORMS_ALL, PLATFORMS_MP, HTML_MAP, CSS_MAP, CSS_POSTFIX_MAP, CDN_MAP, } from './config';
4
5
  export { DEFAULT_TRANSPILE_DEPENDENCIES, DEFAULT_ADAPTER_DIRS, AEGIS_EXTERNAL_SCRIPT_LINK, UNI_SIMPLE_ROUTER_SCRIPT_LINK, EXTERNAL_LINK_MAP, } from './config-project';
@@ -13,3 +14,4 @@ export { getProjectName, getSubProjectName, } from './project-name';
13
14
  export { updateManifest, revertManifest, } from './replace-manifest';
14
15
  export { getRootDir, } from './root';
15
16
  export { getSubProjectConfig, getSubProjectRoot, } from './sub-project';
17
+ export { getPlatform, getUtsPlatform, getAppPlatform, isH5, isApp, isAppAndroid, isAppIOS, isMp, isMpWeixin, isMpAlipay, isMpBaidu, isMpKuaishou, isMpQQ, isMpToutiao, isQuickapp, isQuickappUnion, isQuickappHuawei, } from './uni-env';
package/lib/index.js CHANGED
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var fs = require('fs');
6
6
  var path = require('path');
7
7
  var tComm = require('t-comm');
8
+ var path$1 = require('node:path');
9
+ var fs$1 = require('node:fs');
8
10
 
9
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
12
 
@@ -28,7 +30,8 @@ function _interopNamespace(e) {
28
30
 
29
31
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
32
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
31
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
33
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
34
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
32
35
 
33
36
  function getRootDir() {
34
37
  return process.cwd();
@@ -267,6 +270,30 @@ function getComponentName(dir) {
267
270
  return match?.[1] || '';
268
271
  }
269
272
 
273
+ function findNodeModuleFile({ name, target, filePath, root, }) {
274
+ const iRoot = root ?? process.cwd();
275
+ const NODE_MODULES = 'node_modules';
276
+ const PNPM = `${NODE_MODULES}/.pnpm`;
277
+ const nodeModulesTargetFile = path__default["default"].resolve(iRoot, NODE_MODULES, name, filePath);
278
+ const exist = fs__default["default"].existsSync(nodeModulesTargetFile);
279
+ if (exist) {
280
+ return [
281
+ nodeModulesTargetFile,
282
+ ];
283
+ }
284
+ const pnpmRoot = path__default["default"].resolve(iRoot, PNPM);
285
+ if (!fs__default["default"].existsSync(pnpmRoot)) {
286
+ return [];
287
+ }
288
+ const pnpmList = fs__default["default"].readdirSync(pnpmRoot);
289
+ const list = pnpmList.filter(item => item.startsWith(target));
290
+ const innerFileList = list.map((file) => {
291
+ const targetFile = path__default["default"].resolve(`${PNPM}/${file}/node_modules/${name}/${filePath}`);
292
+ return targetFile;
293
+ }).filter(file => fs__default["default"].existsSync(file));
294
+ return innerFileList;
295
+ }
296
+
270
297
  function replaceDirective(source, list) {
271
298
  if (!list.length)
272
299
  return source;
@@ -342,6 +369,19 @@ function handleImg(str = '', urlHandler = '') {
342
369
  return res;
343
370
  }
344
371
 
372
+ function isInBlackList(filePath, blackList) {
373
+ if (!blackList) {
374
+ return false;
375
+ }
376
+ const found = blackList.find((item) => {
377
+ if (typeof item === 'string') {
378
+ return filePath.includes(item);
379
+ }
380
+ return item.test(filePath);
381
+ });
382
+ return !!found;
383
+ }
384
+
345
385
  function checkBundleAnalyze() {
346
386
  return process.argv.includes('--bundleAnalyzer')
347
387
  || !!process.env.npm_config_report;
@@ -712,6 +752,24 @@ function getSubProjectConfig(subProjectRoot) {
712
752
  return res;
713
753
  }
714
754
 
755
+ const getPlatform = () => process.env.UNI_PLATFORM || '';
756
+ const getUtsPlatform = () => process.env.UNI_UTS_PLATFORM || '';
757
+ const getAppPlatform = () => process.env.UNI_APP_PLATFORM || '';
758
+ const isH5 = () => getPlatform() === 'h5';
759
+ const isApp = () => getPlatform() === 'app';
760
+ const isAppAndroid = () => getAppPlatform() === 'android' || getUtsPlatform() === 'app-android';
761
+ const isAppIOS = () => getAppPlatform() === 'ios' || getUtsPlatform() === 'app-ios';
762
+ const isMp = () => /^mp-/i.test(getPlatform());
763
+ const isMpWeixin = () => getPlatform() === 'mp-weixin';
764
+ const isMpAlipay = () => getPlatform() === 'mp-alipay';
765
+ const isMpBaidu = () => getPlatform() === 'mp-baidu';
766
+ const isMpKuaishou = () => getPlatform() === 'mp-kuaishou';
767
+ const isMpQQ = () => getPlatform() === 'mp-qq';
768
+ const isMpToutiao = () => getPlatform() === 'mp-toutiao';
769
+ const isQuickapp = () => /^quickapp-webview/i.test(getPlatform());
770
+ const isQuickappUnion = () => getPlatform() === 'quickapp-webview-union';
771
+ const isQuickappHuawei = () => getPlatform() === 'quickapp-webview-huawei';
772
+
715
773
  exports.AEGIS_EXTERNAL_SCRIPT_LINK = AEGIS_EXTERNAL_SCRIPT_LINK;
716
774
  exports.ALL_PLATFORM = ALL_PLATFORM;
717
775
  exports.BASE_SCSS = BASE_SCSS;
@@ -734,7 +792,9 @@ exports.checkH5 = checkH5;
734
792
  exports.createLogDir = createLogDir;
735
793
  exports.crossGameStyle = crossGameStyle;
736
794
  exports.findDependencies = findDependencies;
795
+ exports.findNodeModuleFile = findNodeModuleFile;
737
796
  exports.genInjectContent = genInjectContent;
797
+ exports.getAppPlatform = getAppPlatform;
738
798
  exports.getCommitCode = getCommitCode;
739
799
  exports.getComponentName = getComponentName;
740
800
  exports.getDeps = getDeps;
@@ -743,6 +803,7 @@ exports.getLoaderFile = getLoaderFile;
743
803
  exports.getLoaderProdFile = getLoaderProdFile;
744
804
  exports.getMpInsertCode = getMpInsertCode;
745
805
  exports.getMpVersionCode = getMpVersionCode;
806
+ exports.getPlatform = getPlatform;
746
807
  exports.getProjectName = getProjectName;
747
808
  exports.getRelativePath = getRelativePath;
748
809
  exports.getRootDir = getRootDir;
@@ -751,8 +812,24 @@ exports.getSubProjectConfig = getSubProjectConfig;
751
812
  exports.getSubProjectName = getSubProjectName;
752
813
  exports.getSubProjectRoot = getSubProjectRoot;
753
814
  exports.getUniCliCache = getUniCliCache;
815
+ exports.getUtsPlatform = getUtsPlatform;
754
816
  exports.getVersionCode = getVersionCode;
755
817
  exports.getWebInsertCode = getWebInsertCode;
818
+ exports.isApp = isApp;
819
+ exports.isAppAndroid = isAppAndroid;
820
+ exports.isAppIOS = isAppIOS;
821
+ exports.isH5 = isH5;
822
+ exports.isInBlackList = isInBlackList;
823
+ exports.isMp = isMp;
824
+ exports.isMpAlipay = isMpAlipay;
825
+ exports.isMpBaidu = isMpBaidu;
826
+ exports.isMpKuaishou = isMpKuaishou;
827
+ exports.isMpQQ = isMpQQ;
828
+ exports.isMpToutiao = isMpToutiao;
829
+ exports.isMpWeixin = isMpWeixin;
830
+ exports.isQuickapp = isQuickapp;
831
+ exports.isQuickappHuawei = isQuickappHuawei;
832
+ exports.isQuickappUnion = isQuickappUnion;
756
833
  exports.normalizePath = normalizePath;
757
834
  exports.parseSetDeps = parseSetDeps;
758
835
  exports.recordLoaderLog = recordLoaderLog;
@@ -0,0 +1,17 @@
1
+ export declare const getPlatform: () => string;
2
+ export declare const getUtsPlatform: () => string;
3
+ export declare const getAppPlatform: () => string;
4
+ export declare const isH5: () => boolean;
5
+ export declare const isApp: () => boolean;
6
+ export declare const isAppAndroid: () => boolean;
7
+ export declare const isAppIOS: () => boolean;
8
+ export declare const isMp: () => boolean;
9
+ export declare const isMpWeixin: () => boolean;
10
+ export declare const isMpAlipay: () => boolean;
11
+ export declare const isMpBaidu: () => boolean;
12
+ export declare const isMpKuaishou: () => boolean;
13
+ export declare const isMpQQ: () => boolean;
14
+ export declare const isMpToutiao: () => boolean;
15
+ export declare const isQuickapp: () => boolean;
16
+ export declare const isQuickappUnion: () => boolean;
17
+ export declare const isQuickappHuawei: () => boolean;
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@plugin-light/shared",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "main": "./lib/index",
5
5
  "files": [
6
6
  "lib/"
7
7
  ],
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/novlan1/uni-plugin-light"
10
+ "url": "https://github.com/novlan1/plugin-light"
11
11
  },
12
12
  "author": "guowangyang",
13
- "homepage": "https://novlan1.github.io/uni-plugin-light/",
13
+ "homepage": "https://novlan1.github.io/plugin-light//",
14
14
  "bugs": {
15
- "url": "https://github.com/novlan1/uni-plugin-light/issues"
15
+ "url": "https://github.com/novlan1/plugin-light/issues"
16
16
  },
17
17
  "dependencies": {
18
- "t-comm": "^1.3.104"
18
+ "t-comm": "^1.3.126"
19
19
  },
20
20
  "scripts": {
21
21
  "build": "rm -rf lib && rollup -c",