easycom.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.initEasycom = void 0;
  7. const debug_1 = __importDefault(require("debug"));
  8. const uni_shared_1 = require("@dcloudio/uni-shared");
  9. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  10. const debugEasycom = (0, debug_1.default)('uni:easycom');
  11. const initEasycom = (watcher) => {
  12. const { filter, refresh, options } = (0, uni_cli_shared_1.initEasycomsOnce)(process.env.UNI_INPUT_DIR, {
  13. dirs: [(0, uni_cli_shared_1.resolveComponentsLibPath)()],
  14. platform: process.env.UNI_PLATFORM,
  15. isX: process.env.UNI_APP_X === 'true',
  16. });
  17. if (!watcher) {
  18. // build 模式,手动初始化 watcher
  19. debugEasycom('initWatch', options.dirs);
  20. watcher = uni_cli_shared_1.chokidar.watch(options.dirs, {
  21. ignored: ['**/node_modules/**', '**/.git/**'],
  22. ignoreInitial: true,
  23. ignorePermissionErrors: true,
  24. disableGlobbing: true,
  25. });
  26. }
  27. const refreshEasycom = (0, uni_shared_1.debounce)(refresh, 100, { setTimeout, clearTimeout });
  28. watcher.on('all', (eventName, path) => {
  29. if (!['add', 'unlink'].includes(eventName)) {
  30. return;
  31. }
  32. if (filter(path)) {
  33. debugEasycom('watch', eventName, path);
  34. refreshEasycom();
  35. }
  36. });
  37. };
  38. exports.initEasycom = initEasycom;