@playcraft/build 0.1.66 → 0.1.68

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.
@@ -45,6 +45,7 @@ export declare class GenericAdapter {
45
45
  * 超时:5 分钟
46
46
  */
47
47
  private runNpmBuild;
48
+ private buildOutputFingerprints;
48
49
  /**
49
50
  * 查找构建输出目录
50
51
  * 按优先级搜索:dist/、build/、out/,并兼容编辑器型引擎常见的
@@ -179,6 +179,7 @@ export class GenericAdapter {
179
179
  const cmd = packageManager === 'npm' ? 'npm' : packageManager;
180
180
  const args = packageManager === 'npm' || packageManager === 'bun' ? ['run', script] : [script];
181
181
  console.log(`[GenericAdapter] 运行: ${cmd} ${args.join(' ')}`);
182
+ const previousOutputs = await this.buildOutputFingerprints();
182
183
  await this.runCommandWithTimeout(cmd, args, {
183
184
  cwd: this.projectDir,
184
185
  timeout: 5 * 60 * 1000, // 5 分钟
@@ -190,7 +191,46 @@ export class GenericAdapter {
190
191
  });
191
192
  console.log('[GenericAdapter] 项目构建完成');
192
193
  // 查找构建输出目录
193
- return this.findBuildOutputDir();
194
+ return this.findBuildOutputDir(previousOutputs);
195
+ }
196
+ async buildOutputFingerprints() {
197
+ const files = new Map();
198
+ const visit = async (directory, depth) => {
199
+ if (depth > 3)
200
+ return;
201
+ let entries;
202
+ try {
203
+ entries = await fs.readdir(path.join(this.projectDir, directory), { withFileTypes: true });
204
+ }
205
+ catch {
206
+ return;
207
+ }
208
+ for (const entry of entries) {
209
+ const relative = path.join(directory, entry.name);
210
+ if (entry.isFile() && entry.name.toLowerCase() === 'index.html') {
211
+ const stat = await fs.stat(path.join(this.projectDir, relative));
212
+ files.set(relative, JSON.stringify([stat.dev, stat.ino, stat.size, stat.mtimeMs, stat.ctimeMs]));
213
+ }
214
+ else if (entry.isDirectory() && !['node_modules', '.git', 'library', 'temp', 'local'].includes(entry.name))
215
+ await visit(relative, depth + 1);
216
+ }
217
+ };
218
+ const directories = new Set(['dist', 'build', 'out', 'web-mobile', 'web-desktop', 'html5']);
219
+ try {
220
+ const pkg = JSON.parse(await fs.readFile(path.join(this.projectDir, 'package.json'), 'utf8'));
221
+ for (const field of ['build.outDir', 'build.outdir', 'outDir', 'output', 'dist', 'buildDir']) {
222
+ const value = this.getNestedValue(pkg, field);
223
+ if (typeof value === 'string' && value) {
224
+ const relative = path.relative(this.projectDir, path.resolve(this.projectDir, value));
225
+ if (relative && !relative.startsWith('..') && !path.isAbsolute(relative))
226
+ directories.add(relative);
227
+ }
228
+ }
229
+ }
230
+ catch { /* Fixed build roots remain available without optional output metadata. */ }
231
+ for (const directory of directories)
232
+ await visit(directory, 0);
233
+ return files;
194
234
  }
195
235
  /**
196
236
  * 查找构建输出目录
@@ -201,9 +241,15 @@ export class GenericAdapter {
201
241
  * 资源目录」,放的是 favicon、robots.txt 这类原样文件,本身不是构建产物。
202
242
  * 一旦里面有 index.html,就会被误当成构建结果整目录复制出去。
203
243
  */
204
- async findBuildOutputDir() {
244
+ async findBuildOutputDir(previous) {
245
+ const current = await this.buildOutputFingerprints();
246
+ const fresh = (directory) => {
247
+ const file = path.join(directory, 'index.html');
248
+ return current.has(file) && current.get(file) !== previous.get(file);
249
+ };
205
250
  const possibleDirs = [
206
251
  'dist',
252
+ 'dist/preview',
207
253
  'build',
208
254
  'out',
209
255
  'build/web-mobile',
@@ -222,7 +268,7 @@ export class GenericAdapter {
222
268
  if (stat.isDirectory()) {
223
269
  // 检查目录中是否有 index.html
224
270
  const files = await fs.readdir(fullPath);
225
- if (files.includes('index.html')) {
271
+ if (files.includes('index.html') && fresh(dir)) {
226
272
  console.log(`[GenericAdapter] 找到构建输出目录: ${dir}`);
227
273
  return fullPath;
228
274
  }
@@ -247,7 +293,7 @@ export class GenericAdapter {
247
293
  catch {
248
294
  return null;
249
295
  }
250
- if (entries.some((entry) => entry.isFile() && entry.name.toLowerCase() === 'index.html')) {
296
+ if (entries.some((entry) => entry.isFile() && entry.name.toLowerCase() === 'index.html') && fresh(root)) {
251
297
  return fullRoot;
252
298
  }
253
299
  for (const entry of entries) {
@@ -277,7 +323,7 @@ export class GenericAdapter {
277
323
  const fullPath = path.join(this.projectDir, value);
278
324
  try {
279
325
  const stat = await fs.stat(fullPath);
280
- if (stat.isDirectory()) {
326
+ if (stat.isDirectory() && fresh(value)) {
281
327
  console.log(`[GenericAdapter] 从 package.json 找到构建目录: ${value}`);
282
328
  return fullPath;
283
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/build",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",