@vcp-dev/site-edit-engine 0.6.5 → 0.6.6
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SiteEditInsertNodeSpec, SiteEditMoveTarget, SiteEditOperationParams, SiteEditOperationRequest, SiteEditOperationTarget, SiteEditOperationType, SiteEditOperationValue, SiteEditStyleBreakpoint, SiteEditStyleProperty, SiteEditStyleStateMode } from "@vcp-dev/contracts";
|
|
1
|
+
import type { SiteEditInsertNodeSpec, SiteEditMoveTarget, SiteEditOperationParams, SiteEditOperationRequest, SiteEditOperationTarget, SiteEditOperationType, SiteEditOperationValue, SiteEditStyleBreakpoint, SiteEditStyleProperty, SiteEditStyleStateMode, SiteEditOperationOutput } from "@vcp-dev/contracts";
|
|
2
2
|
import type { OperationError } from "./error.js";
|
|
3
3
|
/** caller-facing 操作类型 */
|
|
4
4
|
export type OperationType = SiteEditOperationType;
|
|
@@ -72,6 +72,8 @@ export interface OperationResult {
|
|
|
72
72
|
error?: OperationError;
|
|
73
73
|
/** 本次操作实际影响的文件路径 */
|
|
74
74
|
affectedFiles?: string[];
|
|
75
|
+
/** Project-level operations return their typed domain result here. */
|
|
76
|
+
output?: SiteEditOperationOutput;
|
|
75
77
|
/** 操作完成后建议恢复/选中的节点;move-node 会在 structural key 改变时返回新 key。 */
|
|
76
78
|
selectionRef?: OperationSelectionRef;
|
|
77
79
|
}
|
|
@@ -255,7 +255,7 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
255
255
|
};
|
|
256
256
|
data: {
|
|
257
257
|
requestId: string;
|
|
258
|
-
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit";
|
|
258
|
+
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit" | "insert-page-resource";
|
|
259
259
|
target: {
|
|
260
260
|
kind: "node";
|
|
261
261
|
key: string;
|
|
@@ -272,6 +272,8 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
272
272
|
} | {
|
|
273
273
|
kind: "source-batch";
|
|
274
274
|
paths: string[];
|
|
275
|
+
} | {
|
|
276
|
+
kind: "project";
|
|
275
277
|
};
|
|
276
278
|
resultVersion: number;
|
|
277
279
|
};
|
|
@@ -279,7 +281,7 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
279
281
|
ok: true;
|
|
280
282
|
data: {
|
|
281
283
|
requestId: string;
|
|
282
|
-
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit";
|
|
284
|
+
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit" | "insert-page-resource";
|
|
283
285
|
target: {
|
|
284
286
|
kind: "node";
|
|
285
287
|
key: string;
|
|
@@ -296,6 +298,8 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
296
298
|
} | {
|
|
297
299
|
kind: "source-batch";
|
|
298
300
|
paths: string[];
|
|
301
|
+
} | {
|
|
302
|
+
kind: "project";
|
|
299
303
|
};
|
|
300
304
|
resultVersion: number;
|
|
301
305
|
affectedFiles?: string[] | undefined;
|
|
@@ -304,6 +308,16 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
304
308
|
instanceIndex?: number | undefined;
|
|
305
309
|
instanceCount?: number | undefined;
|
|
306
310
|
} | undefined;
|
|
311
|
+
output?: {
|
|
312
|
+
kind: "insert-page-resource";
|
|
313
|
+
package_instance_id: string;
|
|
314
|
+
pages: {
|
|
315
|
+
template_page_id: string;
|
|
316
|
+
title: string;
|
|
317
|
+
final_route: string;
|
|
318
|
+
route_file_path: string;
|
|
319
|
+
}[];
|
|
320
|
+
} | undefined;
|
|
307
321
|
};
|
|
308
322
|
error?: undefined;
|
|
309
323
|
}>;
|
|
@@ -315,7 +329,7 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
315
329
|
};
|
|
316
330
|
data: {
|
|
317
331
|
requestId: string;
|
|
318
|
-
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit";
|
|
332
|
+
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit" | "insert-page-resource";
|
|
319
333
|
target: {
|
|
320
334
|
kind: "node";
|
|
321
335
|
key: string;
|
|
@@ -332,6 +346,8 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
332
346
|
} | {
|
|
333
347
|
kind: "source-batch";
|
|
334
348
|
paths: string[];
|
|
349
|
+
} | {
|
|
350
|
+
kind: "project";
|
|
335
351
|
};
|
|
336
352
|
resultVersion: number;
|
|
337
353
|
};
|
|
@@ -339,7 +355,7 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
339
355
|
ok: true;
|
|
340
356
|
data: {
|
|
341
357
|
requestId: string;
|
|
342
|
-
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit";
|
|
358
|
+
kind: "insert-child" | "update-text" | "update-array-item" | "remove-node" | "move-node" | "set-class-name-source" | "set-props" | "apply-style-draft" | "source-edit" | "insert-page-resource";
|
|
343
359
|
target: {
|
|
344
360
|
kind: "node";
|
|
345
361
|
key: string;
|
|
@@ -356,6 +372,8 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
356
372
|
} | {
|
|
357
373
|
kind: "source-batch";
|
|
358
374
|
paths: string[];
|
|
375
|
+
} | {
|
|
376
|
+
kind: "project";
|
|
359
377
|
};
|
|
360
378
|
resultVersion: number;
|
|
361
379
|
affectedFiles?: string[] | undefined;
|
|
@@ -364,6 +382,16 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
|
|
|
364
382
|
instanceIndex?: number | undefined;
|
|
365
383
|
instanceCount?: number | undefined;
|
|
366
384
|
} | undefined;
|
|
385
|
+
output?: {
|
|
386
|
+
kind: "insert-page-resource";
|
|
387
|
+
package_instance_id: string;
|
|
388
|
+
pages: {
|
|
389
|
+
template_page_id: string;
|
|
390
|
+
title: string;
|
|
391
|
+
final_route: string;
|
|
392
|
+
route_file_path: string;
|
|
393
|
+
}[];
|
|
394
|
+
} | undefined;
|
|
367
395
|
};
|
|
368
396
|
error?: undefined;
|
|
369
397
|
}>;
|
package/dist/source-watcher.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class SiteEditSourceWatcher {
|
|
|
23
23
|
private readonly registeredWatcherDirs;
|
|
24
24
|
private readonly fileMtimes;
|
|
25
25
|
private readonly queuedChangedFiles;
|
|
26
|
+
private hasReportedTruncatedBatch;
|
|
26
27
|
private pollingTimer;
|
|
27
28
|
private changeFlushTimer;
|
|
28
29
|
private isPolling;
|
|
@@ -35,8 +36,10 @@ export declare class SiteEditSourceWatcher {
|
|
|
35
36
|
private getBudget;
|
|
36
37
|
private registerWatcher;
|
|
37
38
|
private poll;
|
|
39
|
+
private startPolling;
|
|
38
40
|
private scanFiles;
|
|
39
41
|
private queueChangedFile;
|
|
40
42
|
private flushQueuedChanges;
|
|
43
|
+
private shouldReportQueuedFile;
|
|
41
44
|
private emitDiagnostic;
|
|
42
45
|
}
|
package/dist/source-watcher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"node:fs";import h from"node:path";var
|
|
1
|
+
import u from"node:fs";import h from"node:path";var y=["app","src/app","components/site","src/components/site","lib/generated","src/lib/generated","public"],F=/\.(?:tsx|ts|jsx|js|mjs|cjs|css|scss|sass|mdx|json)$/,D=new Set([".git",".next",".turbo","build","coverage","dist","node_modules","output"]),_=512,M=5e3,w=8,T=1e3,b=50,v=500,x=class{constructor(t){this.options=t,this.watchers=[],this.registeredWatcherDirs=new Set,this.fileMtimes=new Map,this.queuedChangedFiles=new Set,this.hasReportedTruncatedBatch=!1,this.pollingTimer=null,this.changeFlushTimer=null,this.isPolling=!1,this.isStarted=!1,this.hasScanned=!1}start(){if(this.isStarted)return()=>this.stop();this.isStarted=!0;let t=!1,e=Date.now(),s=this.getBudget();for(let i of this.getWatchDirs()){if(g(e,s.maxStartupMs)){this.emitDiagnostic({code:"startup-budget-exceeded",message:"Source watcher startup budget was exceeded before all roots were registered.",details:{maxStartupMs:s.maxStartupMs}});break}let a=h.join(this.options.projectRoot,i);if(!u.existsSync(a))continue;if(this.registerWatcher(a,!0)){t=!0;continue}let o=P(this.options.projectRoot,a,{maxDirs:s.maxDirs,maxDepth:s.maxDepth,maxStartupMs:s.maxStartupMs,startedAt:e});o.truncated&&this.emitDiagnostic(o.truncated);for(let r of o.directories)t=this.registerWatcher(r,!1)||t}return this.scanFiles(),t||this.startPolling(),()=>this.stop()}stop(){if(this.isStarted){this.pollingTimer&&(clearInterval(this.pollingTimer),this.pollingTimer=null),this.changeFlushTimer&&(clearTimeout(this.changeFlushTimer),this.changeFlushTimer=null),this.queuedChangedFiles.clear(),this.hasReportedTruncatedBatch=!1;for(let t of this.watchers)t.close();this.watchers.length=0,this.registeredWatcherDirs.clear(),this.isStarted=!1}}getWatchDirs(){return C(this.options.projectRoot,this.options.watch_dirs?.length?this.options.watch_dirs:y)}getBudget(){return{maxDirs:Math.max(1,this.options.max_dirs??_),maxFiles:Math.max(1,this.options.max_files??M),maxDepth:Math.max(1,this.options.max_depth??w),maxStartupMs:Math.max(1,this.options.max_startup_ms??T),debounceMs:Math.max(0,this.options.debounce_ms??b),maxChangedFilesPerBatch:Math.max(1,this.options.max_changed_files_per_batch??v)}}registerWatcher(t,e){let s=f(this.options.projectRoot,t);if(this.registeredWatcherDirs.has(s))return!0;if(this.registeredWatcherDirs.size>=this.getBudget().maxDirs)return this.emitDiagnostic({code:"watcher-budget-exceeded",message:"Source watcher native watcher budget was exceeded.",details:{maxDirs:this.getBudget().maxDirs}}),!1;try{let i=u.watch(t,{recursive:e},(o,r)=>{let c=r?h.join(t,r.toString()):null;if(c&&u.existsSync(c))try{let d=u.lstatSync(c);if(d.isSymbolicLink())return;if(d.isDirectory()){let p=f(this.options.projectRoot,c);m(p)||(this.registerWatcher(c,!1),this.poll());return}if(!d.isFile())return}catch{}let l=A(this.options.projectRoot,t,r);if(l){this.queueChangedFile(l);return}this.poll()}),a=!1;return i.on("error",()=>{if(!this.isStarted||a)return;a=!0,i.close();let o=this.watchers.indexOf(i);o>=0&&this.watchers.splice(o,1),this.registeredWatcherDirs.delete(s),this.poll(),this.startPolling()}),i?.unref?.(),this.watchers.push(i),this.registeredWatcherDirs.add(s),!0}catch{return!1}}poll(){if(!this.isPolling){this.isPolling=!0;try{this.scanFiles()}finally{this.isPolling=!1}}}startPolling(){if(this.pollingTimer||!this.isStarted)return;let t=this.options.interval_ms??1e3;this.pollingTimer=setInterval(()=>this.poll(),t),this.pollingTimer?.unref?.()}scanFiles(){let t=new Set,e=!0,s=this.getBudget(),i=Date.now();for(let a of this.getWatchDirs()){let o=h.join(this.options.projectRoot,a);if(!u.existsSync(o))continue;let r=R(this.options.projectRoot,o,{maxFiles:s.maxFiles,maxDepth:s.maxDepth,maxStartupMs:s.maxStartupMs,startedAt:i});r.truncated&&this.emitDiagnostic(r.truncated),(!r.complete||r.truncated)&&(e=!1);for(let c of r.files)try{let l=u.statSync(c),d=f(this.options.projectRoot,c);t.add(d);let p=this.fileMtimes.get(d);if(this.hasScanned&&(p===void 0||p!==l.mtimeMs)){this.queueChangedFile(d);continue}this.fileMtimes.set(d,l.mtimeMs)}catch{e=!1}}if(this.hasScanned&&e)for(let a of this.fileMtimes.keys())t.has(a)||this.queueChangedFile(a);e&&(this.hasScanned=!0)}queueChangedFile(t){let e=this.getBudget();if(this.queuedChangedFiles.size>=e.maxChangedFilesPerBatch){!this.queuedChangedFiles.has(t)&&!this.hasReportedTruncatedBatch&&(this.hasReportedTruncatedBatch=!0,this.emitDiagnostic({code:"change-batch-truncated",message:"Source watcher change batch exceeded the configured file budget.",details:{maxChangedFiles:e.maxChangedFilesPerBatch}}));return}if(this.queuedChangedFiles.add(t),this.changeFlushTimer)return;let s=()=>this.flushQueuedChanges();if(e.debounceMs===0){s();return}this.changeFlushTimer=setTimeout(s,e.debounceMs),this.changeFlushTimer?.unref?.()}flushQueuedChanges(){if(this.changeFlushTimer&&(clearTimeout(this.changeFlushTimer),this.changeFlushTimer=null),this.queuedChangedFiles.size===0)return;let t=[...this.queuedChangedFiles].filter(e=>this.shouldReportQueuedFile(e)).sort();if(this.queuedChangedFiles.clear(),this.hasReportedTruncatedBatch=!1,t.length!==0){if(this.options.on_batch_change){this.options.on_batch_change(t);return}for(let e of t)this.options.on_change(e)}}shouldReportQueuedFile(t){let e=h.join(this.options.projectRoot,...t.split("/"));try{let s=u.lstatSync(e);if(!s.isFile()||s.isSymbolicLink())return!1;let i=this.fileMtimes.get(t);return this.fileMtimes.set(t,s.mtimeMs),i===void 0?this.hasScanned:i!==s.mtimeMs}catch(s){return W(s)?this.fileMtimes.delete(t):!1}}emitDiagnostic(t){this.options.on_diagnostic?.(t)}};function C(n,t){let e=h.resolve(n),s=new Set;for(let o of t){let r=j(e,o);!r||m(r)||s.add(r)}let i=[...s].sort((o,r)=>o.split("/").length-r.split("/").length||o.length-r.length||o.localeCompare(r)),a=[];for(let o of i)a.some(r=>o===r||o.startsWith(`${r}/`))||a.push(o);return a}function j(n,t){let e=t.trim();if(!e)return"";let s=h.isAbsolute(e)?h.resolve(e):h.resolve(n,e),i=h.relative(n,s);return!i||i.startsWith("..")?"":i.replace(/\\/g,"/").replace(/^\.\//,"")}function P(n,t,e){let s=[],i=[{directory:t,depth:0}];for(;i.length>0;){let a=i.shift();if(s.length>=e.maxDirs)return{directories:s,truncated:{code:"directory-budget-exceeded",message:"Source watcher fallback directory scan was truncated by max_dirs.",details:{maxDirs:e.maxDirs}}};if(g(e.startedAt,e.maxStartupMs))return{directories:s,truncated:{code:"startup-budget-exceeded",message:"Source watcher fallback directory scan exceeded max_startup_ms.",details:{maxStartupMs:e.maxStartupMs}}};if(s.push(a.directory),a.depth>=e.maxDepth)continue;let o;try{o=u.readdirSync(a.directory,{withFileTypes:!0})}catch{continue}for(let r of o){if(!r.isDirectory()||S(r.name))continue;let c=h.join(a.directory,r.name),l=f(n,c);m(l)||i.push({directory:c,depth:a.depth+1})}}return{directories:s}}function R(n,t,e){let s=[],i=[{directory:t,depth:0}];for(;i.length>0;){let a=i.shift();if(g(e.startedAt,e.maxStartupMs))return{files:s,complete:!1,truncated:{code:"startup-budget-exceeded",message:"Source watcher file scan exceeded max_startup_ms.",details:{maxStartupMs:e.maxStartupMs}}};let o;try{o=u.readdirSync(a.directory,{withFileTypes:!0})}catch{return{files:s,complete:!1}}for(let r of o){let c=h.join(a.directory,r.name);if(r.isDirectory()){!S(r.name)&&a.depth<e.maxDepth&&!m(f(n,c))&&i.push({directory:c,depth:a.depth+1});continue}let l=f(n,c);if(!m(l)&&F.test(l)){if(s.length>=e.maxFiles)return{files:s,complete:!1,truncated:{code:"file-budget-exceeded",message:"Source watcher file scan was truncated by max_files.",details:{maxFiles:e.maxFiles}}};s.push(c)}}}return{files:s,complete:!0}}function W(n){return n instanceof Error&&"code"in n&&(n.code==="ENOENT"||n.code==="ENOTDIR")}function A(n,t,e){if(!e)return null;let s=h.join(t,e.toString()),i=f(n,s);return!i||i.startsWith("..")||m(i)||!F.test(i)?null:i}function S(n){return n.startsWith(".")||D.has(n)}function m(n){return n.split("/").some(t=>D.has(t))}function g(n,t){return Date.now()-n>t}function f(n,t){return h.relative(n,t).replace(/\\/g,"/")}export{x as SiteEditSourceWatcher};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vcp-dev/site-edit-engine",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"node": ">=24.0.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"build": "
|
|
54
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node -e \"const fs=require('node:fs'); fs.mkdirSync('dist', { recursive: true }); fs.copyFileSync('src/site-edit-instrumentation-loader.cjs', 'dist/site-edit-instrumentation-loader.cjs'); fs.copyFileSync('src/site-edit-instrumentation-loader.d.cts', 'dist/site-edit-instrumentation-loader.d.cts'); fs.copyFileSync('src/webpack-loader.cjs', 'dist/webpack-loader.cjs'); fs.copyFileSync('src/webpack-loader.d.cts', 'dist/webpack-loader.d.cts')\"",
|
|
55
55
|
"test": "vitest run --root ../.. packages/site-edit-engine/src",
|
|
56
56
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
57
57
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@babel/parser": "^7.29.3",
|
|
61
61
|
"@babel/traverse": "^7.29.0",
|
|
62
62
|
"@babel/types": "^7.29.0",
|
|
63
|
-
"@vcp-dev/contracts": "0.6.
|
|
63
|
+
"@vcp-dev/contracts": "0.6.6",
|
|
64
64
|
"yaml": "^2.9.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|