@dcloudio/uni-cli-shared 3.0.0-alpha-4020520240731001 → 3.0.0-alpha-4020620240820001

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.
@@ -152,12 +152,25 @@ function uniEncryptUniModulesPlugin() {
152
152
  autoImports[source] = allAutoImports[source];
153
153
  }
154
154
  });
155
+ const uni_modules = [];
156
+ const pkgJson = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', uniModule, 'package.json');
157
+ if (fs_extra_1.default.existsSync(pkgJson)) {
158
+ try {
159
+ const pkg = require(pkgJson);
160
+ if (pkg.uni_modules?.dependencies) {
161
+ uni_modules.push(...pkg.uni_modules.dependencies);
162
+ }
163
+ }
164
+ catch (e) {
165
+ console.error(e);
166
+ }
167
+ }
155
168
  const result = await compiler.compile(pluginDir, {
156
169
  isX: process.env.UNI_APP_X === 'true',
157
170
  isSingleThread: true,
158
171
  isPlugin: false,
159
172
  sourceMap: false,
160
- uni_modules: [],
173
+ uni_modules,
161
174
  transform: {
162
175
  uvueClassNamePrefix: 'Gen',
163
176
  autoImports,
@@ -22,30 +22,25 @@ function uniViteCopyPlugin({ targets, }) {
22
22
  return;
23
23
  }
24
24
  initialized = true;
25
+ const is_prod = process.env.NODE_ENV !== 'development' ||
26
+ process.env.UNI_AUTOMATOR_CONFIG;
27
+ const onChange = is_prod
28
+ ? undefined
29
+ : (0, uni_shared_1.debounce)(() => {
30
+ (0, logs_1.resetOutput)('log');
31
+ (0, logs_1.output)('log', messages_1.M['dev.watching.end']);
32
+ }, 100, { setTimeout, clearTimeout });
25
33
  return new Promise((resolve) => {
26
34
  Promise.all(targets.map(({ watchOptions, ...target }) => {
27
35
  return new Promise((resolve) => {
28
- // 防抖,可能短时间触发很多次add,unlink
29
- const onChange = (0, uni_shared_1.debounce)(() => {
30
- (0, logs_1.resetOutput)('log');
31
- (0, logs_1.output)('log', messages_1.M['dev.watching.end']);
32
- }, 100, { setTimeout, clearTimeout });
33
36
  new watcher_1.FileWatcher({
34
37
  ...target,
35
38
  }).watch({
36
39
  cwd: process.env.UNI_INPUT_DIR,
40
+ persistent: is_prod ? false : true,
37
41
  ...watchOptions,
38
- }, (watcher) => {
39
- if (process.env.NODE_ENV !== 'development' ||
40
- process.env.UNI_AUTOMATOR_CONFIG) {
41
- // 生产或自动化测试模式下,延迟 close,否则会影响 chokidar 初始化的 add 等事件
42
- setTimeout(() => {
43
- watcher.close().then(() => resolve(void 0));
44
- }, 2000);
45
- }
46
- else {
47
- resolve(void 0);
48
- }
42
+ }, () => {
43
+ resolve(void 0);
49
44
  }, onChange);
50
45
  });
51
46
  })).then(() => resolve());
package/dist/watcher.d.ts CHANGED
@@ -15,12 +15,13 @@ export declare class FileWatcher {
15
15
  constructor({ src, dest, transform }: FileWatcherOptions);
16
16
  watch(watchOptions: WatchOptions & {
17
17
  cwd: string;
18
+ readyTimeout?: number;
18
19
  }, onReady?: (watcher: FSWatcher) => void, onChange?: () => void): FSWatcher;
19
20
  add(paths: string | ReadonlyArray<string>): FSWatcher;
20
21
  unwatch(paths: string | ReadonlyArray<string>): FSWatcher;
21
22
  close(): Promise<void>;
22
- copy(from: string): Promise<void | undefined>;
23
- remove(from: string): Promise<void | undefined>;
23
+ copy(from: string): void;
24
+ remove(from: string): void;
24
25
  info(type: 'close' | 'copy' | 'remove' | 'add' | 'unwatch', msg?: string | unknown): void;
25
26
  from(from: string): string;
26
27
  to(from: string): string;
package/dist/watcher.js CHANGED
@@ -23,17 +23,26 @@ class FileWatcher {
23
23
  const remove = this.remove.bind(this);
24
24
  // escape chokidar cwd
25
25
  const src = this.src.map((src) => (0, utils_1.pathToGlob)(path_1.default.resolve(watchOptions.cwd), src));
26
+ let closeTimer;
27
+ const checkReady = () => {
28
+ if (closeTimer) {
29
+ clearTimeout(closeTimer);
30
+ }
31
+ closeTimer = setTimeout(() => {
32
+ onReady && onReady(this.watcher);
33
+ // 等首次change完,触发完ready,在切换到真实的onChange
34
+ this.onChange = onChange;
35
+ }, watchOptions.readyTimeout || 300);
36
+ };
37
+ this.onChange = checkReady;
26
38
  this.watcher = (0, chokidar_1.watch)(src, watchOptions)
27
39
  .on('add', copy)
28
- .on('addDir', copy)
40
+ // .on('addDir', copy)
29
41
  .on('change', copy)
30
42
  .on('unlink', remove)
31
- .on('unlinkDir', remove)
43
+ // .on('unlinkDir', remove)
32
44
  .on('ready', () => {
33
- onReady && onReady(this.watcher);
34
- setTimeout(() => {
35
- this.onChange = onChange;
36
- }, 1000);
45
+ checkReady();
37
46
  })
38
47
  .on('error', (e) => console.error('watch', e));
39
48
  }
@@ -60,29 +69,18 @@ class FileWatcher {
60
69
  content = this.transform(fs_extra_1.default.readFileSync(filename), filename);
61
70
  }
62
71
  if (content) {
63
- return fs_extra_1.default
64
- .outputFile(to, content)
65
- .catch(() => {
66
- // this.info('copy', e)
67
- })
68
- .then(() => this.onChange && this.onChange());
72
+ fs_extra_1.default.outputFileSync(to, content);
73
+ this.onChange && this.onChange();
74
+ return;
69
75
  }
70
- return fs_extra_1.default
71
- .copy(this.from(from), to, { overwrite: true })
72
- .catch(() => {
73
- // this.info('copy', e)
74
- })
75
- .then(() => this.onChange && this.onChange());
76
+ fs_extra_1.default.copySync(this.from(from), to, { overwrite: true });
77
+ this.onChange && this.onChange();
76
78
  }
77
79
  remove(from) {
78
80
  const to = this.to(from);
79
81
  this.info('remove', from + '=>' + to);
80
- return fs_extra_1.default
81
- .remove(to)
82
- .catch(() => {
83
- // this.info('remove', e)
84
- })
85
- .then(() => this.onChange && this.onChange());
82
+ fs_extra_1.default.removeSync(to);
83
+ this.onChange && this.onChange();
86
84
  }
87
85
  info(type, msg) {
88
86
  debugWatcher.enabled && debugWatcher(type, msg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-4020520240731001",
3
+ "version": "3.0.0-alpha-4020620240820001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "@babel/core": "^7.23.3",
27
27
  "@babel/parser": "^7.23.9",
28
28
  "@babel/types": "^7.20.7",
29
- "@dcloudio/uni-i18n": "3.0.0-alpha-4020520240731001",
30
- "@dcloudio/uni-shared": "3.0.0-alpha-4020520240731001",
29
+ "@dcloudio/uni-i18n": "3.0.0-alpha-4020620240820001",
30
+ "@dcloudio/uni-shared": "3.0.0-alpha-4020620240820001",
31
31
  "@intlify/core-base": "9.1.9",
32
32
  "@intlify/shared": "9.1.9",
33
33
  "@intlify/vue-devtools": "9.1.9",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
73
73
  "devDependencies": {
74
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-4020520240731001",
74
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-4020620240820001",
75
75
  "@types/adm-zip": "^0.5.5",
76
76
  "@types/babel__code-frame": "^7.0.6",
77
77
  "@types/babel__core": "^7.1.19",