@vforsh/argus 0.1.14 → 0.1.15
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/dist/.tsbuildinfo +1 -1
- package/dist/argus.js +1199 -915
- package/dist/cli/defineWatcherCommand.d.ts +17 -0
- package/dist/cli/defineWatcherCommand.d.ts.map +1 -1
- package/dist/cli/defineWatcherCommand.js +19 -2
- package/dist/cli/defineWatcherCommand.js.map +1 -1
- package/dist/cli/plugins/pluginAliases.d.ts +6 -0
- package/dist/cli/plugins/pluginAliases.d.ts.map +1 -0
- package/dist/cli/plugins/pluginAliases.js +10 -0
- package/dist/cli/plugins/pluginAliases.js.map +1 -0
- package/dist/cli/plugins/pluginHost.d.ts +3 -0
- package/dist/cli/plugins/pluginHost.d.ts.map +1 -0
- package/dist/cli/plugins/pluginHost.js +30 -0
- package/dist/cli/plugins/pluginHost.js.map +1 -0
- package/dist/cli/plugins/registerPlugins.d.ts +32 -1
- package/dist/cli/plugins/registerPlugins.d.ts.map +1 -1
- package/dist/cli/plugins/registerPlugins.js +102 -12
- package/dist/cli/plugins/registerPlugins.js.map +1 -1
- package/dist/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +2 -0
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/register/index.d.ts.map +1 -1
- package/dist/cli/register/index.js +2 -0
- package/dist/cli/register/index.js.map +1 -1
- package/dist/cli/register/registerAuth.d.ts.map +1 -1
- package/dist/cli/register/registerAuth.js +13 -8
- package/dist/cli/register/registerAuth.js.map +1 -1
- package/dist/cli/register/registerEval.d.ts.map +1 -1
- package/dist/cli/register/registerEval.js +6 -0
- package/dist/cli/register/registerEval.js.map +1 -1
- package/dist/cli/register/registerPlugin.d.ts +3 -0
- package/dist/cli/register/registerPlugin.d.ts.map +1 -0
- package/dist/cli/register/registerPlugin.js +34 -0
- package/dist/cli/register/registerPlugin.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +4 -9
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/authCookieSupport.d.ts.map +1 -1
- package/dist/commands/authCookieSupport.js +4 -6
- package/dist/commands/authCookieSupport.js.map +1 -1
- package/dist/commands/authCookies.d.ts +4 -4
- package/dist/commands/authCookies.d.ts.map +1 -1
- package/dist/commands/authCookies.js +85 -105
- package/dist/commands/authCookies.js.map +1 -1
- package/dist/commands/code.js +3 -25
- package/dist/commands/code.js.map +1 -1
- package/dist/commands/codeEdit.js +3 -3
- package/dist/commands/codeEdit.js.map +1 -1
- package/dist/commands/configInit.d.ts.map +1 -1
- package/dist/commands/configInit.js +1 -0
- package/dist/commands/configInit.js.map +1 -1
- package/dist/commands/domAdd.d.ts +1 -1
- package/dist/commands/domAdd.d.ts.map +1 -1
- package/dist/commands/domAdd.js +26 -30
- package/dist/commands/domAdd.js.map +1 -1
- package/dist/commands/domInfo.d.ts +1 -1
- package/dist/commands/domInfo.d.ts.map +1 -1
- package/dist/commands/domInfo.js +18 -23
- package/dist/commands/domInfo.js.map +1 -1
- package/dist/commands/domKeydown.d.ts +1 -1
- package/dist/commands/domKeydown.d.ts.map +1 -1
- package/dist/commands/domKeydown.js +22 -43
- package/dist/commands/domKeydown.js.map +1 -1
- package/dist/commands/domModify.js +27 -30
- package/dist/commands/domModify.js.map +1 -1
- package/dist/commands/domScroll.d.ts +1 -1
- package/dist/commands/domScroll.d.ts.map +1 -1
- package/dist/commands/domScroll.js +18 -24
- package/dist/commands/domScroll.js.map +1 -1
- package/dist/commands/domScrollTo.d.ts +1 -1
- package/dist/commands/domScrollTo.d.ts.map +1 -1
- package/dist/commands/domScrollTo.js +15 -24
- package/dist/commands/domScrollTo.js.map +1 -1
- package/dist/commands/domTree.d.ts +1 -1
- package/dist/commands/domTree.d.ts.map +1 -1
- package/dist/commands/domTree.js +18 -24
- package/dist/commands/domTree.js.map +1 -1
- package/dist/commands/eval.d.ts +2 -0
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +43 -62
- package/dist/commands/eval.js.map +1 -1
- package/dist/commands/evalPolling.d.ts +55 -0
- package/dist/commands/evalPolling.d.ts.map +1 -0
- package/dist/commands/evalPolling.js +59 -0
- package/dist/commands/evalPolling.js.map +1 -0
- package/dist/commands/evalShared.d.ts +13 -0
- package/dist/commands/evalShared.d.ts.map +1 -1
- package/dist/commands/evalShared.js +54 -7
- package/dist/commands/evalShared.js.map +1 -1
- package/dist/commands/evalUntil.d.ts +2 -0
- package/dist/commands/evalUntil.d.ts.map +1 -1
- package/dist/commands/evalUntil.js +47 -70
- package/dist/commands/evalUntil.js.map +1 -1
- package/dist/commands/locate.js +2 -2
- package/dist/commands/locate.js.map +1 -1
- package/dist/commands/logs.d.ts +1 -1
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +18 -27
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/net.d.ts +1 -1
- package/dist/commands/net.d.ts.map +1 -1
- package/dist/commands/net.js +14 -19
- package/dist/commands/net.js.map +1 -1
- package/dist/commands/netClear.d.ts +1 -1
- package/dist/commands/netClear.d.ts.map +1 -1
- package/dist/commands/netClear.js +7 -19
- package/dist/commands/netClear.js.map +1 -1
- package/dist/commands/netSse.js +2 -2
- package/dist/commands/netSse.js.map +1 -1
- package/dist/commands/netWebSocket.js +3 -3
- package/dist/commands/netWebSocket.js.map +1 -1
- package/dist/commands/pageEmulation.d.ts +3 -3
- package/dist/commands/pageEmulation.d.ts.map +1 -1
- package/dist/commands/pageEmulation.js +72 -143
- package/dist/commands/pageEmulation.js.map +1 -1
- package/dist/commands/pluginConfig.d.ts +7 -0
- package/dist/commands/pluginConfig.d.ts.map +1 -0
- package/dist/commands/pluginConfig.js +199 -0
- package/dist/commands/pluginConfig.js.map +1 -0
- package/dist/commands/pluginList.d.ts +5 -0
- package/dist/commands/pluginList.d.ts.map +1 -0
- package/dist/commands/pluginList.js +26 -0
- package/dist/commands/pluginList.js.map +1 -0
- package/dist/commands/screenshot.d.ts +1 -1
- package/dist/commands/screenshot.d.ts.map +1 -1
- package/dist/commands/screenshot.js +12 -18
- package/dist/commands/screenshot.js.map +1 -1
- package/dist/commands/watcherStatus.d.ts +1 -1
- package/dist/commands/watcherStatus.d.ts.map +1 -1
- package/dist/commands/watcherStatus.js +8 -21
- package/dist/commands/watcherStatus.js.map +1 -1
- package/dist/config/argusConfig.d.ts +5 -0
- package/dist/config/argusConfig.d.ts.map +1 -1
- package/dist/config/argusConfig.js +33 -2
- package/dist/config/argusConfig.js.map +1 -1
- package/package.json +1 -1
- package/schemas/argus.config.schema.json +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netClear.js","sourceRoot":"","sources":["../../src/commands/netClear.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"netClear.js","sourceRoot":"","sources":["../../src/commands/netClear.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AAMrE,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAAoC;IAClF,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACvE,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;QAC9C,MAAM,CAAC,UAAU,CAAC,WAAW,QAAQ,CAAC,OAAO,kBAAkB,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7E,CAAC;CACD,CAAC,CAAA"}
|
package/dist/commands/netSse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendNetCommandParams } from './netShared.js';
|
|
2
|
+
import { requestWatcherCommandAction } from '../cli/defineWatcherCommand.js';
|
|
2
3
|
import { formatSseSummary } from '../output/net.js';
|
|
3
4
|
import { createOutput } from '../output/io.js';
|
|
4
|
-
import { requestWatcherAction } from '../watchers/requestWatcher.js';
|
|
5
5
|
export const runNetSse = async (id, options) => {
|
|
6
6
|
const output = createOutput(options);
|
|
7
7
|
const params = new URLSearchParams();
|
|
@@ -11,7 +11,7 @@ export const runNetSse = async (id, options) => {
|
|
|
11
11
|
process.exitCode = 2;
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const result = await
|
|
14
|
+
const result = await requestWatcherCommandAction({ id, path: '/net/sse', query: params, timeoutMs: 5_000 }, output);
|
|
15
15
|
if (!result) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netSse.js","sourceRoot":"","sources":["../../src/commands/netSse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"netSse.js","sourceRoot":"","sources":["../../src/commands/netSse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAM9C,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,EAAsB,EAAE,OAAsB,EAAiB,EAAE;IAChG,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;IACpC,MAAM,KAAK,GAAG,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrD,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAM;IACP,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,2BAA2B,CAAiB,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC,CAAA;IACnI,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAM;IACP,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACrC,OAAM;IACP,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5C,CAAC;AACF,CAAC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendNetCommandParams } from './netShared.js';
|
|
2
|
+
import { requestWatcherCommandAction } from '../cli/defineWatcherCommand.js';
|
|
2
3
|
import { formatWebSocketDetail, formatWebSocketSummary } from '../output/net.js';
|
|
3
4
|
import { createOutput } from '../output/io.js';
|
|
4
|
-
import { requestWatcherAction } from '../watchers/requestWatcher.js';
|
|
5
5
|
export const runNetWebSocket = async (id, options) => {
|
|
6
6
|
const output = createOutput(options);
|
|
7
7
|
const params = new URLSearchParams();
|
|
@@ -11,7 +11,7 @@ export const runNetWebSocket = async (id, options) => {
|
|
|
11
11
|
process.exitCode = 2;
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const result = await
|
|
14
|
+
const result = await requestWatcherCommandAction({ id, path: '/net/ws', query: params, timeoutMs: 5_000 }, output);
|
|
15
15
|
if (!result) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -29,7 +29,7 @@ export const runNetWebSocketShow = async (id, connection, options) => {
|
|
|
29
29
|
if (!query) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const result = await
|
|
32
|
+
const result = await requestWatcherCommandAction({ id, path: '/net/ws/connection', query, timeoutMs: 5_000 }, output);
|
|
33
33
|
if (!result) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netWebSocket.js","sourceRoot":"","sources":["../../src/commands/netWebSocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"netWebSocket.js","sourceRoot":"","sources":["../../src/commands/netWebSocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAU9C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAsB,EAAE,OAA4B,EAAiB,EAAE;IAC5G,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;IACpC,MAAM,KAAK,GAAG,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrD,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAM;IACP,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,2BAA2B,CAAwB,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC,CAAA;IACzI,IAAI,CAAC,MAAM,EAAE,CA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;IACnC,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAC3B,OAAO,KAAK,CAAA;IACb,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;QACxB,MAAM,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAA;QACpD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;IAClC,OAAO,KAAK,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -8,13 +8,13 @@ export type PageEmulationSetOptions = {
|
|
|
8
8
|
ua?: string;
|
|
9
9
|
json?: boolean;
|
|
10
10
|
};
|
|
11
|
-
export declare const runPageEmulationSet: (
|
|
11
|
+
export declare const runPageEmulationSet: import("../cli/defineWatcherCommand.js").WatcherCommandRunner<[], PageEmulationSetOptions>;
|
|
12
12
|
export type PageEmulationClearOptions = {
|
|
13
13
|
json?: boolean;
|
|
14
14
|
};
|
|
15
|
-
export declare const runPageEmulationClear: (
|
|
15
|
+
export declare const runPageEmulationClear: import("../cli/defineWatcherCommand.js").WatcherCommandRunner<[], PageEmulationClearOptions>;
|
|
16
16
|
export type PageEmulationStatusOptions = {
|
|
17
17
|
json?: boolean;
|
|
18
18
|
};
|
|
19
|
-
export declare const runPageEmulationStatus: (
|
|
19
|
+
export declare const runPageEmulationStatus: import("../cli/defineWatcherCommand.js").WatcherCommandRunner<[], PageEmulationStatusOptions>;
|
|
20
20
|
//# sourceMappingURL=pageEmulation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageEmulation.d.ts","sourceRoot":"","sources":["../../src/commands/pageEmulation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pageEmulation.d.ts","sourceRoot":"","sources":["../../src/commands/pageEmulation.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,uBAAuB,GAAG;IACrC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAED,eAAO,MAAM,mBAAmB,4FAiB9B,CAAA;AAyFF,MAAM,MAAM,yBAAyB,GAAG;IACvC,IAAI,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAED,eAAO,MAAM,qBAAqB,8FAKhC,CAAA;AAMF,MAAM,MAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAED,eAAO,MAAM,sBAAsB,+FAkCjC,CAAA"}
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { requestWatcherJson, writeRequestError } from '../watchers/requestWatcher.js';
|
|
1
|
+
import { defineWatcherCommand } from '../cli/defineWatcherCommand.js';
|
|
3
2
|
import { resolvePreset, listPresetNames } from '../emulation/devices.js';
|
|
4
|
-
export const runPageEmulationSet =
|
|
5
|
-
|
|
3
|
+
export const runPageEmulationSet = defineWatcherCommand({
|
|
4
|
+
build: (_args, options, output) => buildPageEmulationSetPlan(options, output),
|
|
5
|
+
formatHuman: (res, { output, options }) => {
|
|
6
|
+
const state = buildEmulationState(options);
|
|
7
|
+
const label = formatViewportLabel(state.viewport, state.touch.enabled, state.userAgent.value);
|
|
8
|
+
if (res.applied) {
|
|
9
|
+
output.writeHuman(`Applied emulation: ${label}`);
|
|
10
|
+
}
|
|
11
|
+
else if (!res.attached) {
|
|
12
|
+
output.writeHuman(`Queued emulation (watcher detached): ${label}`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
output.writeHuman(`Emulation set but not applied: ${label}`);
|
|
16
|
+
if (res.error) {
|
|
17
|
+
output.writeWarn(`Error: ${res.error.message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const buildPageEmulationSetPlan = (options, output) => {
|
|
23
|
+
const state = buildEmulationState(options, output);
|
|
24
|
+
if (!state)
|
|
25
|
+
return null;
|
|
26
|
+
return { path: '/emulation', method: 'POST', body: { action: 'set', state }, timeoutMs: 10_000 };
|
|
27
|
+
};
|
|
28
|
+
const buildEmulationState = (options, output) => {
|
|
6
29
|
// Resolve base from preset (if any)
|
|
7
30
|
let base = null;
|
|
8
31
|
if (options.device) {
|
|
9
32
|
const preset = resolvePreset(options.device);
|
|
10
33
|
if (!preset) {
|
|
11
|
-
output
|
|
12
|
-
output
|
|
34
|
+
output?.writeWarn(`Unknown device: ${options.device}`);
|
|
35
|
+
output?.writeWarn(`Available: ${listPresetNames().join(', ')}`);
|
|
13
36
|
process.exitCode = 2;
|
|
14
|
-
return;
|
|
37
|
+
return null;
|
|
15
38
|
}
|
|
16
39
|
base = { viewport: preset.viewport, touch: preset.touch, userAgent: preset.userAgent };
|
|
17
40
|
}
|
|
@@ -20,36 +43,36 @@ export const runPageEmulationSet = async (id, options) => {
|
|
|
20
43
|
const heightRaw = options.height != null ? Number(options.height) : null;
|
|
21
44
|
const dprRaw = options.dpr != null ? Number(options.dpr) : null;
|
|
22
45
|
if (widthRaw != null && (!Number.isInteger(widthRaw) || widthRaw <= 0)) {
|
|
23
|
-
output
|
|
46
|
+
output?.writeWarn('--width must be a positive integer');
|
|
24
47
|
process.exitCode = 2;
|
|
25
|
-
return;
|
|
48
|
+
return null;
|
|
26
49
|
}
|
|
27
50
|
if (heightRaw != null && (!Number.isInteger(heightRaw) || heightRaw <= 0)) {
|
|
28
|
-
output
|
|
51
|
+
output?.writeWarn('--height must be a positive integer');
|
|
29
52
|
process.exitCode = 2;
|
|
30
|
-
return;
|
|
53
|
+
return null;
|
|
31
54
|
}
|
|
32
55
|
if (dprRaw != null && (!Number.isFinite(dprRaw) || dprRaw <= 0)) {
|
|
33
|
-
output
|
|
56
|
+
output?.writeWarn('--dpr must be a positive number');
|
|
34
57
|
process.exitCode = 2;
|
|
35
|
-
return;
|
|
58
|
+
return null;
|
|
36
59
|
}
|
|
37
60
|
// If width or height given without the other and no preset → error
|
|
38
61
|
const hasWidth = widthRaw != null;
|
|
39
62
|
const hasHeight = heightRaw != null;
|
|
40
63
|
if ((hasWidth || hasHeight) && !base) {
|
|
41
64
|
if (!hasWidth || !hasHeight) {
|
|
42
|
-
output
|
|
65
|
+
output?.writeWarn('Both --width and --height are required when not using --device');
|
|
43
66
|
process.exitCode = 2;
|
|
44
|
-
return;
|
|
67
|
+
return null;
|
|
45
68
|
}
|
|
46
69
|
}
|
|
47
70
|
// If no preset and no viewport override → error
|
|
48
71
|
if (!base && !hasWidth) {
|
|
49
|
-
output
|
|
50
|
-
output
|
|
72
|
+
output?.writeWarn('Provide --device or --width + --height');
|
|
73
|
+
output?.writeWarn(`Available devices: ${listPresetNames().join(', ')}`);
|
|
51
74
|
process.exitCode = 2;
|
|
52
|
-
return;
|
|
75
|
+
return null;
|
|
53
76
|
}
|
|
54
77
|
// Build viewport
|
|
55
78
|
const baseViewport = base?.viewport ?? null;
|
|
@@ -62,143 +85,49 @@ export const runPageEmulationSet = async (id, options) => {
|
|
|
62
85
|
const touchEnabled = options.touch ?? base?.touch ?? false;
|
|
63
86
|
// User-agent
|
|
64
87
|
const uaValue = options.ua !== undefined ? options.ua : (base?.userAgent ?? null);
|
|
65
|
-
|
|
88
|
+
return {
|
|
66
89
|
viewport,
|
|
67
90
|
touch: { enabled: touchEnabled },
|
|
68
91
|
userAgent: { value: uaValue },
|
|
69
92
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
output.writeJson(response);
|
|
93
|
+
};
|
|
94
|
+
export const runPageEmulationClear = defineWatcherCommand({
|
|
95
|
+
build: () => ({ path: '/emulation', method: 'POST', body: { action: 'clear' }, timeoutMs: 10_000 }),
|
|
96
|
+
formatHuman: (_response, { output }) => {
|
|
97
|
+
output.writeHuman('Cleared emulation');
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
export const runPageEmulationStatus = defineWatcherCommand({
|
|
101
|
+
build: () => ({ path: '/emulation', method: 'GET', timeoutMs: 5_000 }),
|
|
102
|
+
formatHuman: (res, { output }) => {
|
|
103
|
+
const lines = [];
|
|
104
|
+
lines.push(`attached: ${res.attached}`);
|
|
105
|
+
lines.push(`applied: ${res.applied}`);
|
|
106
|
+
if (res.state?.viewport) {
|
|
107
|
+
const vp = res.state.viewport;
|
|
108
|
+
lines.push(`viewport: ${vp.width}x${vp.height}@${vp.deviceScaleFactor} ${vp.mobile ? 'mobile' : 'desktop'}`);
|
|
87
109
|
}
|
|
88
110
|
else {
|
|
89
|
-
|
|
111
|
+
lines.push('viewport: none');
|
|
90
112
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
output.writeJson(response);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const res = response;
|
|
99
|
-
const label = formatViewportLabel(viewport, touchEnabled, uaValue);
|
|
100
|
-
if (res.applied) {
|
|
101
|
-
output.writeHuman(`Applied emulation: ${label}`);
|
|
102
|
-
}
|
|
103
|
-
else if (!res.attached) {
|
|
104
|
-
output.writeHuman(`Queued emulation (watcher detached): ${label}`);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
output.writeHuman(`Emulation set but not applied: ${label}`);
|
|
108
|
-
if (res.error) {
|
|
109
|
-
output.writeWarn(`Error: ${res.error.message}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
export const runPageEmulationClear = async (id, options) => {
|
|
114
|
-
const output = createOutput(options);
|
|
115
|
-
const result = await requestWatcherJson({
|
|
116
|
-
id,
|
|
117
|
-
path: '/emulation',
|
|
118
|
-
method: 'POST',
|
|
119
|
-
body: { action: 'clear' },
|
|
120
|
-
timeoutMs: 10_000,
|
|
121
|
-
returnErrorResponse: true,
|
|
122
|
-
});
|
|
123
|
-
if (!result.ok) {
|
|
124
|
-
writeRequestError(result, output);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const response = result.data;
|
|
128
|
-
if (!response.ok) {
|
|
129
|
-
const err = response;
|
|
130
|
-
if (options.json) {
|
|
131
|
-
output.writeJson(response);
|
|
113
|
+
lines.push(`touch: ${res.state?.touch?.enabled ? 'enabled' : 'disabled'}`);
|
|
114
|
+
if (res.state?.userAgent?.value) {
|
|
115
|
+
const ua = res.state.userAgent.value;
|
|
116
|
+
lines.push(`ua: ${ua.length > 80 ? ua.slice(0, 77) + '...' : ua}`);
|
|
132
117
|
}
|
|
133
118
|
else {
|
|
134
|
-
|
|
119
|
+
lines.push('ua: default');
|
|
135
120
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (options.json) {
|
|
140
|
-
output.writeJson(response);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
output.writeHuman('Cleared emulation');
|
|
144
|
-
};
|
|
145
|
-
export const runPageEmulationStatus = async (id, options) => {
|
|
146
|
-
const output = createOutput(options);
|
|
147
|
-
const result = await requestWatcherJson({
|
|
148
|
-
id,
|
|
149
|
-
path: '/emulation',
|
|
150
|
-
method: 'GET',
|
|
151
|
-
timeoutMs: 5_000,
|
|
152
|
-
returnErrorResponse: true,
|
|
153
|
-
});
|
|
154
|
-
if (!result.ok) {
|
|
155
|
-
writeRequestError(result, output);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const response = result.data;
|
|
159
|
-
if (!response.ok) {
|
|
160
|
-
const err = response;
|
|
161
|
-
if (options.json) {
|
|
162
|
-
output.writeJson(response);
|
|
121
|
+
if (res.baseline.userAgent) {
|
|
122
|
+
const bua = res.baseline.userAgent;
|
|
123
|
+
lines.push(`baseline: ${bua.length > 80 ? bua.slice(0, 77) + '...' : bua}`);
|
|
163
124
|
}
|
|
164
|
-
|
|
165
|
-
|
|
125
|
+
if (res.lastError) {
|
|
126
|
+
lines.push(`error: ${res.lastError.message}`);
|
|
166
127
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (options.json) {
|
|
171
|
-
output.writeJson(response);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const res = response;
|
|
175
|
-
const lines = [];
|
|
176
|
-
lines.push(`attached: ${res.attached}`);
|
|
177
|
-
lines.push(`applied: ${res.applied}`);
|
|
178
|
-
if (res.state?.viewport) {
|
|
179
|
-
const vp = res.state.viewport;
|
|
180
|
-
lines.push(`viewport: ${vp.width}x${vp.height}@${vp.deviceScaleFactor} ${vp.mobile ? 'mobile' : 'desktop'}`);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
lines.push('viewport: none');
|
|
184
|
-
}
|
|
185
|
-
lines.push(`touch: ${res.state?.touch?.enabled ? 'enabled' : 'disabled'}`);
|
|
186
|
-
if (res.state?.userAgent?.value) {
|
|
187
|
-
const ua = res.state.userAgent.value;
|
|
188
|
-
lines.push(`ua: ${ua.length > 80 ? ua.slice(0, 77) + '...' : ua}`);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
lines.push('ua: default');
|
|
192
|
-
}
|
|
193
|
-
if (res.baseline.userAgent) {
|
|
194
|
-
const bua = res.baseline.userAgent;
|
|
195
|
-
lines.push(`baseline: ${bua.length > 80 ? bua.slice(0, 77) + '...' : bua}`);
|
|
196
|
-
}
|
|
197
|
-
if (res.lastError) {
|
|
198
|
-
lines.push(`error: ${res.lastError.message}`);
|
|
199
|
-
}
|
|
200
|
-
output.writeHuman(lines.join('\n'));
|
|
201
|
-
};
|
|
128
|
+
output.writeHuman(lines.join('\n'));
|
|
129
|
+
},
|
|
130
|
+
});
|
|
202
131
|
// ---------------------------------------------------------------------------
|
|
203
132
|
// helpers
|
|
204
133
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageEmulation.js","sourceRoot":"","sources":["../../src/commands/pageEmulation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pageEmulation.js","sourceRoot":"","sources":["../../src/commands/pageEmulation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAA2B,MAAM,gCAAgC,CAAA;AAE9F,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAuBxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAgD;IACtG,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,yBAAyB,CAAC,OAAO,EAAE,MAAM,CAAC;IAC7E,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;QACzC,MAAM,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAE,CAAA;QAC3C,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAE7F,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,UAAU,CAAC,sBAAsB,KAAK,EAAE,CAAC,CAAA;QACjD,CAAC;aAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC1B,MAAM,CAAC,UAAU,CAAC,wCAAwC,KAAK,E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AAC;QAED,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YACnB,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,CAAC;QAED,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACpC,CAAC;CACD,CAAC,CAAA;AAEF,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,CAC3B,QAAuF,EACvF,KAAc,EACd,EAAiB,EACR,EAAE;IACX,MAAM,KAAK,GAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAA;IAC9F,IAAI,QAAQ,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACzC,IAAI,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PluginConfigMutationOptions = {
|
|
2
|
+
path?: string;
|
|
3
|
+
json?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const runPluginAdd: (targetSpec: string, options: PluginConfigMutationOptions) => Promise<void>;
|
|
6
|
+
export declare const runPluginRemove: (targetSpec: string, options: PluginConfigMutationOptions) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=pluginConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginConfig.d.ts","sourceRoot":"","sources":["../../src/commands/pluginConfig.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,2BAA2B,GAAG;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAqID,eAAO,MAAM,YAAY,GAAU,YAAY,MAAM,EAAE,SAAS,2BAA2B,KAAG,OAAO,CAAC,IAAI,CAsCzG,CAAA;AAED,eAAO,MAAM,eAAe,GAAU,YAAY,MAAM,EAAE,SAAS,2BAA2B,KAAG,OAAO,CAAC,IAAI,CA4B5G,CAAA"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createOutput } from '../output/io.js';
|
|
5
|
+
import { resolveArgusConfigPath } from '../config/argusConfig.js';
|
|
6
|
+
import { BUILTIN_PLUGIN_ALIASES, resolvePluginAlias } from '../cli/plugins/pluginAliases.js';
|
|
7
|
+
const DEFAULT_CONFIG_PATH = '.argus/config.json';
|
|
8
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
+
const resolveTargetConfigPath = (cwd, cliPath) => {
|
|
10
|
+
if (cliPath) {
|
|
11
|
+
const resolved = path.isAbsolute(cliPath) ? cliPath : path.resolve(cwd, cliPath);
|
|
12
|
+
return { path: resolved, exists: existsSync(resolved) };
|
|
13
|
+
}
|
|
14
|
+
const discovered = resolveArgusConfigPath({ cwd });
|
|
15
|
+
if (discovered)
|
|
16
|
+
return { path: discovered, exists: true };
|
|
17
|
+
if (process.exitCode)
|
|
18
|
+
return null;
|
|
19
|
+
return { path: path.resolve(cwd, DEFAULT_CONFIG_PATH), exists: false };
|
|
20
|
+
};
|
|
21
|
+
const readConfigObject = async (configPath, exists) => {
|
|
22
|
+
if (!exists)
|
|
23
|
+
return {};
|
|
24
|
+
let raw;
|
|
25
|
+
try {
|
|
26
|
+
raw = await fs.readFile(configPath, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Failed to read Argus config at ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30
|
+
process.exitCode = 2;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(raw);
|
|
35
|
+
if (isRecord(parsed))
|
|
36
|
+
return parsed;
|
|
37
|
+
console.error(`Invalid Argus config at ${configPath}: config root must be an object.`);
|
|
38
|
+
process.exitCode = 2;
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(`Invalid Argus config at ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
process.exitCode = 2;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const getPluginSpecs = (config, configPath) => {
|
|
48
|
+
const value = config.plugins;
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return [];
|
|
51
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || item.trim() === '')) {
|
|
52
|
+
console.error(`Invalid Argus config at ${configPath}: "plugins" must be an array of non-empty strings.`);
|
|
53
|
+
process.exitCode = 2;
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
const getPluginAliases = (config, configPath) => {
|
|
59
|
+
const value = config.pluginAliases;
|
|
60
|
+
if (value === undefined)
|
|
61
|
+
return {};
|
|
62
|
+
if (!isRecord(value)) {
|
|
63
|
+
console.error(`Invalid Argus config at ${configPath}: "pluginAliases" must be an object with string values.`);
|
|
64
|
+
process.exitCode = 2;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const aliases = {};
|
|
68
|
+
for (const [alias, spec] of Object.entries(value)) {
|
|
69
|
+
if (alias.trim() === '' || typeof spec !== 'string' || spec.trim() === '') {
|
|
70
|
+
console.error(`Invalid Argus config at ${configPath}: "pluginAliases" keys and values must be non-empty strings.`);
|
|
71
|
+
process.exitCode = 2;
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
aliases[alias] = spec;
|
|
75
|
+
}
|
|
76
|
+
return aliases;
|
|
77
|
+
};
|
|
78
|
+
const writeConfigObject = async (configPath, config) => {
|
|
79
|
+
try {
|
|
80
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
81
|
+
await fs.writeFile(configPath, `${JSON.stringify(config, null, '\t')}\n`, 'utf8');
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error(`Failed to write Argus config at ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
86
|
+
process.exitCode = 2;
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const loadMutablePluginConfig = async (options) => {
|
|
91
|
+
const target = resolveTargetConfigPath(process.cwd(), options.path);
|
|
92
|
+
if (!target)
|
|
93
|
+
return null;
|
|
94
|
+
const config = await readConfigObject(target.path, target.exists);
|
|
95
|
+
if (!config)
|
|
96
|
+
return null;
|
|
97
|
+
const plugins = getPluginSpecs(config, target.path);
|
|
98
|
+
if (!plugins)
|
|
99
|
+
return null;
|
|
100
|
+
const pluginAliases = getPluginAliases(config, target.path);
|
|
101
|
+
if (!pluginAliases)
|
|
102
|
+
return null;
|
|
103
|
+
return { path: target.path, config, plugins, pluginAliases };
|
|
104
|
+
};
|
|
105
|
+
const parsePluginAddTarget = (raw, aliases) => {
|
|
106
|
+
const trimmed = raw.trim();
|
|
107
|
+
if (!trimmed)
|
|
108
|
+
return null;
|
|
109
|
+
const separator = trimmed.indexOf('=');
|
|
110
|
+
if (separator < 0) {
|
|
111
|
+
const resolved = resolvePluginAlias(trimmed, aliases);
|
|
112
|
+
return { spec: trimmed, alias: resolved.alias, resolvedSpec: resolved.spec };
|
|
113
|
+
}
|
|
114
|
+
const alias = trimmed.slice(0, separator).trim();
|
|
115
|
+
const spec = trimmed.slice(separator + 1).trim();
|
|
116
|
+
return alias && spec ? { spec: alias, alias, resolvedSpec: spec } : null;
|
|
117
|
+
};
|
|
118
|
+
export const runPluginAdd = async (targetSpec, options) => {
|
|
119
|
+
const output = createOutput(options);
|
|
120
|
+
const loaded = await loadMutablePluginConfig(options);
|
|
121
|
+
if (!loaded)
|
|
122
|
+
return;
|
|
123
|
+
const parsed = parsePluginAddTarget(targetSpec, { ...BUILTIN_PLUGIN_ALIASES, ...loaded.pluginAliases });
|
|
124
|
+
if (!parsed) {
|
|
125
|
+
output.writeWarn('Plugin specifier is required.');
|
|
126
|
+
process.exitCode = 2;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const aliases = { ...BUILTIN_PLUGIN_ALIASES, ...loaded.pluginAliases };
|
|
130
|
+
const hasSameResolvedPlugin = loaded.plugins.some((spec) => resolvePluginAlias(spec, aliases).spec === parsed.resolvedSpec);
|
|
131
|
+
const changed = !loaded.plugins.includes(parsed.spec) && !hasSameResolvedPlugin;
|
|
132
|
+
const aliasChanged = parsed.alias !== null && loaded.pluginAliases[parsed.alias] !== parsed.resolvedSpec;
|
|
133
|
+
if (changed) {
|
|
134
|
+
loaded.plugins = [...loaded.plugins, parsed.spec];
|
|
135
|
+
loaded.config.plugins = loaded.plugins;
|
|
136
|
+
}
|
|
137
|
+
if (aliasChanged && parsed.alias) {
|
|
138
|
+
loaded.pluginAliases[parsed.alias] = parsed.resolvedSpec;
|
|
139
|
+
loaded.config.pluginAliases = loaded.pluginAliases;
|
|
140
|
+
}
|
|
141
|
+
if ((changed || aliasChanged) && !(await writeConfigObject(loaded.path, loaded.config)))
|
|
142
|
+
return;
|
|
143
|
+
const response = {
|
|
144
|
+
configPath: loaded.path,
|
|
145
|
+
spec: parsed.spec,
|
|
146
|
+
alias: parsed.alias,
|
|
147
|
+
resolvedSpec: parsed.resolvedSpec,
|
|
148
|
+
changed: changed || aliasChanged,
|
|
149
|
+
plugins: loaded.plugins,
|
|
150
|
+
pluginAliases: loaded.pluginAliases,
|
|
151
|
+
};
|
|
152
|
+
if (options.json)
|
|
153
|
+
output.writeJson(response);
|
|
154
|
+
else
|
|
155
|
+
output.writeHuman(response.changed ? `Added plugin ${parsed.spec} to ${loaded.path}` : `Plugin already configured: ${parsed.spec}`);
|
|
156
|
+
};
|
|
157
|
+
export const runPluginRemove = async (targetSpec, options) => {
|
|
158
|
+
const output = createOutput(options);
|
|
159
|
+
const normalized = targetSpec.trim();
|
|
160
|
+
if (!normalized) {
|
|
161
|
+
output.writeWarn('Plugin specifier or name is required.');
|
|
162
|
+
process.exitCode = 2;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const loaded = await loadMutablePluginConfig(options);
|
|
166
|
+
if (!loaded)
|
|
167
|
+
return;
|
|
168
|
+
const aliases = { ...BUILTIN_PLUGIN_ALIASES, ...loaded.pluginAliases };
|
|
169
|
+
const next = loaded.plugins.filter((spec) => !matchesPluginSpecifier(spec, normalized, aliases));
|
|
170
|
+
const nextAliases = Object.fromEntries(Object.entries(loaded.pluginAliases).filter(([alias, spec]) => !matchesPluginAlias(alias, spec, normalized)));
|
|
171
|
+
const changed = next.length !== loaded.plugins.length;
|
|
172
|
+
const aliasChanged = Object.keys(nextAliases).length !== Object.keys(loaded.pluginAliases).length;
|
|
173
|
+
if (changed || aliasChanged) {
|
|
174
|
+
loaded.config.plugins = next;
|
|
175
|
+
loaded.config.pluginAliases = Object.keys(nextAliases).length > 0 ? nextAliases : undefined;
|
|
176
|
+
if (!(await writeConfigObject(loaded.path, loaded.config)))
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const response = { configPath: loaded.path, target: normalized, changed: changed || aliasChanged, plugins: next, pluginAliases: nextAliases };
|
|
180
|
+
if (options.json)
|
|
181
|
+
output.writeJson(response);
|
|
182
|
+
else
|
|
183
|
+
output.writeHuman(response.changed ? `Removed plugin ${normalized} from ${loaded.path}` : `Plugin not configured: ${normalized}`);
|
|
184
|
+
};
|
|
185
|
+
const matchesPluginSpecifier = (spec, target, aliases) => {
|
|
186
|
+
const resolved = resolvePluginAlias(spec, aliases);
|
|
187
|
+
return (spec === target ||
|
|
188
|
+
resolved.spec === target ||
|
|
189
|
+
resolved.alias === target ||
|
|
190
|
+
pluginKey(spec) === pluginKey(target) ||
|
|
191
|
+
pluginKey(resolved.spec) === pluginKey(target));
|
|
192
|
+
};
|
|
193
|
+
const matchesPluginAlias = (alias, spec, target) => alias === target || spec === target || pluginKey(alias) === pluginKey(target) || pluginKey(spec) === pluginKey(target);
|
|
194
|
+
const pluginKey = (value) => {
|
|
195
|
+
const withoutPath = value.replace(/\\/g, '/').split('/').filter(Boolean).pop() ?? value;
|
|
196
|
+
const withoutExt = withoutPath.replace(/\.(mjs|js|ts)$/, '');
|
|
197
|
+
return withoutExt.replace(/^argus-plugin-/, '').replace(/^@[^/]+\/argus-plugin-/, '');
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=pluginConfig.js.map
|