@appium/execute-driver-plugin 5.0.3 → 5.1.0
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/build/lib/execute-child.d.ts +2 -28
- package/build/lib/execute-child.d.ts.map +1 -1
- package/build/lib/execute-child.js +15 -39
- package/build/lib/execute-child.js.map +1 -1
- package/build/lib/index.d.ts +4 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +9 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/plugin.d.ts +22 -14
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +19 -24
- package/build/lib/plugin.js.map +1 -1
- package/build/lib/types.d.ts +22 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/lib/{execute-child.js → execute-child.ts} +26 -54
- package/lib/index.ts +3 -0
- package/lib/{plugin.js → plugin.ts} +32 -33
- package/lib/types.ts +24 -0
- package/package.json +11 -11
- package/tsconfig.json +3 -2
- package/LICENSE +0 -201
- package/index.js +0 -1
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
export const W3C_ELEMENT_KEY: "element-6066-11e4-a52e-4f735466cecf";
|
|
2
|
-
export const MJSONWP_ELEMENT_KEY
|
|
3
|
-
export type DriverScriptMessageEvent = {
|
|
4
|
-
/**
|
|
5
|
-
* - the driver options
|
|
6
|
-
*/
|
|
7
|
-
driverOpts: any;
|
|
8
|
-
/**
|
|
9
|
-
* - the javascript to execute
|
|
10
|
-
*/
|
|
11
|
-
script: string;
|
|
12
|
-
/**
|
|
13
|
-
* - script timeout in milliseconds
|
|
14
|
-
*/
|
|
15
|
-
timeoutMs: number;
|
|
16
|
-
};
|
|
17
|
-
export type ScriptResult = {
|
|
18
|
-
success?: any;
|
|
19
|
-
error?: ScriptResultError | undefined;
|
|
20
|
-
};
|
|
21
|
-
export type ScriptResultError = {
|
|
22
|
-
message: any;
|
|
23
|
-
stack: any;
|
|
24
|
-
};
|
|
25
|
-
export type RunScriptResult = {
|
|
26
|
-
result: any;
|
|
27
|
-
logs: object;
|
|
28
|
-
};
|
|
1
|
+
export declare const W3C_ELEMENT_KEY: "element-6066-11e4-a52e-4f735466cecf";
|
|
2
|
+
export declare const MJSONWP_ELEMENT_KEY = "ELEMENT";
|
|
29
3
|
//# sourceMappingURL=execute-child.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-child.d.ts","sourceRoot":"","sources":["../../lib/execute-child.
|
|
1
|
+
{"version":3,"file":"execute-child.d.ts","sourceRoot":"","sources":["../../lib/execute-child.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,uCAAkC,CAAC;AAC/D,eAAO,MAAM,mBAAmB,YAAY,CAAC"}
|
|
@@ -9,9 +9,6 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
|
9
9
|
const node_vm_1 = __importDefault(require("node:vm"));
|
|
10
10
|
const support_1 = require("appium/support");
|
|
11
11
|
const log = support_1.logger.getLogger('ExecuteDriver Child');
|
|
12
|
-
/**
|
|
13
|
-
* @type {(res: ScriptResult) => Promise<void>}
|
|
14
|
-
*/
|
|
15
12
|
let send;
|
|
16
13
|
// duplicate defining these keys here so we don't need to re-load a huge appium
|
|
17
14
|
// dependency tree into memory just to run a wdio script
|
|
@@ -19,8 +16,8 @@ exports.W3C_ELEMENT_KEY = support_1.util.W3C_WEB_ELEMENT_IDENTIFIER;
|
|
|
19
16
|
exports.MJSONWP_ELEMENT_KEY = 'ELEMENT';
|
|
20
17
|
/**
|
|
21
18
|
* Run the script in a VM.
|
|
22
|
-
* @param
|
|
23
|
-
* @returns
|
|
19
|
+
* @param eventParams - The driver script message event parameters
|
|
20
|
+
* @returns Promise resolving to the run script result
|
|
24
21
|
* @throws {TypeError}
|
|
25
22
|
*/
|
|
26
23
|
async function runScript(eventParams) {
|
|
@@ -30,15 +27,17 @@ async function runScript(eventParams) {
|
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
29
|
* set up fake logger
|
|
33
|
-
* @type {string[]}
|
|
34
30
|
*/
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const logs = {
|
|
32
|
+
error: [],
|
|
33
|
+
warn: [],
|
|
34
|
+
log: [],
|
|
35
|
+
};
|
|
36
|
+
const consoleFns = {
|
|
37
|
+
error: (...logMsgs) => logs.error.push(...logMsgs),
|
|
38
|
+
warn: (...logMsgs) => logs.warn.push(...logMsgs),
|
|
39
|
+
log: (...logMsgs) => logs.log.push(...logMsgs),
|
|
40
|
+
};
|
|
42
41
|
const { attach } = await import('webdriverio');
|
|
43
42
|
const driver = await attach(driverOpts);
|
|
44
43
|
const fullScript = `(async () => {${script}})();`;
|
|
@@ -56,9 +55,8 @@ async function runScript(eventParams) {
|
|
|
56
55
|
* response. So make sure we convert the things we know about to their
|
|
57
56
|
* appropriate response format, and squash other weird things.
|
|
58
57
|
*
|
|
59
|
-
* @param
|
|
60
|
-
*
|
|
61
|
-
* @return {Object} - safely converted object
|
|
58
|
+
* @param obj - object to convert and sanitize
|
|
59
|
+
* @return safely converted object
|
|
62
60
|
*/
|
|
63
61
|
function coerceScriptResult(obj) {
|
|
64
62
|
// first ensure obj is of a type that can be JSON encoded safely. This will
|
|
@@ -107,12 +105,11 @@ function coerceScriptResult(obj) {
|
|
|
107
105
|
}
|
|
108
106
|
/**
|
|
109
107
|
* Entry point to runScript
|
|
110
|
-
* @param
|
|
108
|
+
* @param eventParams - The driver script message event parameters
|
|
111
109
|
*/
|
|
112
110
|
async function main(eventParams) {
|
|
113
111
|
/**
|
|
114
112
|
* keep the response of runScript
|
|
115
|
-
* @type {ScriptResult}
|
|
116
113
|
*/
|
|
117
114
|
let res;
|
|
118
115
|
log.info('Parameters received from parent process');
|
|
@@ -132,25 +129,4 @@ if (require.main === module && lodash_1.default.isFunction(process.send)) {
|
|
|
132
129
|
log.info('Running driver execution in child process');
|
|
133
130
|
process.on('message', main);
|
|
134
131
|
}
|
|
135
|
-
/**
|
|
136
|
-
* @typedef DriverScriptMessageEvent
|
|
137
|
-
* @property {any} driverOpts - the driver options
|
|
138
|
-
* @property {string} script - the javascript to execute
|
|
139
|
-
* @property {number} timeoutMs - script timeout in milliseconds
|
|
140
|
-
*/
|
|
141
|
-
/**
|
|
142
|
-
* @typedef ScriptResult
|
|
143
|
-
* @property {any} [success]
|
|
144
|
-
* @property {ScriptResultError} [error]
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* @typedef ScriptResultError
|
|
148
|
-
* @property {any} message
|
|
149
|
-
* @property {any} stack
|
|
150
|
-
*/
|
|
151
|
-
/**
|
|
152
|
-
* @typedef RunScriptResult
|
|
153
|
-
* @property {any} result
|
|
154
|
-
* @property {object} logs
|
|
155
|
-
*/
|
|
156
132
|
//# sourceMappingURL=execute-child.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-child.js","sourceRoot":"","sources":["../../lib/execute-child.
|
|
1
|
+
{"version":3,"file":"execute-child.js","sourceRoot":"","sources":["../../lib/execute-child.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,wDAAyB;AACzB,sDAAyB;AACzB,4CAA4C;AAG5C,MAAM,GAAG,GAAG,gBAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;AACpD,IAAI,IAA0C,CAAC;AAE/C,+EAA+E;AAC/E,wDAAwD;AAC3C,QAAA,eAAe,GAAG,cAAI,CAAC,0BAA0B,CAAC;AAClD,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAE7C;;;;;GAKG;AACH,KAAK,UAAU,SAAS,CAAC,WAAqC;IAC5D,MAAM,EAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAC,GAAG,WAAW,CAAC;IACpD,IAAI,CAAC,gBAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,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AAC,MAAM,iBAAiB,CAAC;AACrE,mBAAmB,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MJSONWP_ELEMENT_KEY = exports.W3C_ELEMENT_KEY = exports.ExecuteDriverPlugin = void 0;
|
|
4
|
+
var plugin_1 = require("./plugin");
|
|
5
|
+
Object.defineProperty(exports, "ExecuteDriverPlugin", { enumerable: true, get: function () { return plugin_1.ExecuteDriverPlugin; } });
|
|
6
|
+
var execute_child_1 = require("./execute-child");
|
|
7
|
+
Object.defineProperty(exports, "W3C_ELEMENT_KEY", { enumerable: true, get: function () { return execute_child_1.W3C_ELEMENT_KEY; } });
|
|
8
|
+
Object.defineProperty(exports, "MJSONWP_ELEMENT_KEY", { enumerable: true, get: function () { return execute_child_1.MJSONWP_ELEMENT_KEY; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAArC,6GAAA,mBAAmB,OAAA;AAC3B,iDAAqE;AAA7D,gHAAA,eAAe,OAAA;AAAE,oHAAA,mBAAmB,OAAA"}
|
package/build/lib/plugin.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
export default class ExecuteDriverPlugin extends BasePlugin {
|
|
2
|
-
static newMethodMap: {
|
|
3
|
-
readonly '/session/:sessionId/appium/execute_driver': {
|
|
4
|
-
readonly POST: {
|
|
5
|
-
readonly command: "executeDriverScript";
|
|
6
|
-
readonly payloadParams: {
|
|
7
|
-
readonly required: readonly ["script"];
|
|
8
|
-
readonly optional: readonly ["type", "timeout"];
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
executeDriverScript(next: import("@appium/types").NextPluginCallback<unknown>, driver: import("@appium/types").ExternalDriver<import("@appium/types").Constraints, string, import("@appium/types").StringRecord, import("@appium/types").StringRecord, import("@appium/types").DefaultCreateSessionResult<import("@appium/types").Constraints>, void, import("@appium/types").StringRecord>, script: string, scriptType: string | undefined, timeoutMs: number | undefined): Promise<unknown>;
|
|
14
|
-
}
|
|
15
1
|
import { BasePlugin } from 'appium/plugin';
|
|
2
|
+
import type { ExternalDriver, MethodMap, PluginCommand } from '@appium/types';
|
|
3
|
+
export declare class ExecuteDriverPlugin extends BasePlugin {
|
|
4
|
+
static newMethodMap: MethodMap<ExecuteDriverPlugin>;
|
|
5
|
+
/**
|
|
6
|
+
* This method takes a string which is executed as javascript in the context of
|
|
7
|
+
* a new nodejs VM, and which has available a webdriverio driver object, having
|
|
8
|
+
* already been attached to the currently running session.
|
|
9
|
+
*
|
|
10
|
+
* @param next - standard behaviour for executeDriverScript
|
|
11
|
+
* @param driver - Appium driver handling this command
|
|
12
|
+
* @param script - the string representing the driver script to run
|
|
13
|
+
* @param scriptType - the name of the driver script library (currently only webdriverio is supported). Defaults to `'webdriverio'`.
|
|
14
|
+
* @param timeoutMs - timeout for the script process. Defaults to `3600000`.
|
|
15
|
+
* @returns a JSONifiable object representing the return value of the script
|
|
16
|
+
* @throws {Error}
|
|
17
|
+
*/
|
|
18
|
+
executeDriverScript: PluginCommand<ExternalDriver, [
|
|
19
|
+
script: string,
|
|
20
|
+
scriptType?: string,
|
|
21
|
+
timeoutMs?: number
|
|
22
|
+
], any>;
|
|
23
|
+
}
|
|
16
24
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAKzC,OAAO,KAAK,EAAC,cAAc,EAAsB,SAAS,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAMhG,qBAAa,mBAAoB,SAAQ,UAAU;IACjD,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,mBAAmB,CAAC,CAOxC;IAEX;;;;;;;;;;;;OAYG;IACH,mBAAmB,EAAE,aAAa,CAChC,cAAc,EACd;QAAC,MAAM,EAAE,MAAM;QAAE,UAAU,CAAC,EAAE,MAAM;QAAE,SAAS,CAAC,EAAE,MAAM;KAAC,EACzD,GAAG,CACJ,CA2HC;CACH"}
|
package/build/lib/plugin.js
CHANGED
|
@@ -6,39 +6,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ExecuteDriverPlugin = void 0;
|
|
7
7
|
const plugin_1 = require("appium/plugin");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
-
const
|
|
9
|
+
const node_child_process_1 = __importDefault(require("node:child_process"));
|
|
10
10
|
const support_1 = require("appium/support");
|
|
11
11
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
12
12
|
const FEAT_FLAG = 'execute_driver_script';
|
|
13
13
|
const DEFAULT_SCRIPT_TIMEOUT_MS = 1000 * 60 * 60; // default to 1 hour timeout
|
|
14
14
|
const SCRIPT_TYPE_WDIO = 'webdriverio';
|
|
15
15
|
class ExecuteDriverPlugin extends plugin_1.BasePlugin {
|
|
16
|
-
static newMethodMap =
|
|
16
|
+
static newMethodMap = {
|
|
17
17
|
'/session/:sessionId/appium/execute_driver': {
|
|
18
18
|
POST: {
|
|
19
19
|
command: 'executeDriverScript',
|
|
20
20
|
payloadParams: { required: ['script'], optional: ['type', 'timeout'] },
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
/**
|
|
25
25
|
* This method takes a string which is executed as javascript in the context of
|
|
26
26
|
* a new nodejs VM, and which has available a webdriverio driver object, having
|
|
27
27
|
* already been attached to the currently running session.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
35
|
-
*
|
|
36
|
-
* @returns {Promise<any>} - a JSONifiable object representing the return value of
|
|
37
|
-
* the script
|
|
38
|
-
* @type {import('@appium/types').PluginCommand<import('@appium/types').ExternalDriver, [script: string, scriptType: string?, timeoutMs: number?]>}
|
|
29
|
+
* @param next - standard behaviour for executeDriverScript
|
|
30
|
+
* @param driver - Appium driver handling this command
|
|
31
|
+
* @param script - the string representing the driver script to run
|
|
32
|
+
* @param scriptType - the name of the driver script library (currently only webdriverio is supported). Defaults to `'webdriverio'`.
|
|
33
|
+
* @param timeoutMs - timeout for the script process. Defaults to `3600000`.
|
|
34
|
+
* @returns a JSONifiable object representing the return value of the script
|
|
39
35
|
* @throws {Error}
|
|
40
36
|
*/
|
|
41
|
-
async
|
|
37
|
+
executeDriverScript = async (next, driver, script, scriptType = 'webdriverio', timeoutMs = DEFAULT_SCRIPT_TIMEOUT_MS) => {
|
|
42
38
|
if (!driver.isFeatureEnabled(FEAT_FLAG)) {
|
|
43
39
|
throw new Error(`Execute driver script functionality is not available ` +
|
|
44
40
|
`unless server is started with --allow-insecure including ` +
|
|
@@ -69,11 +65,11 @@ class ExecuteDriverPlugin extends plugin_1.BasePlugin {
|
|
|
69
65
|
isMobile: true,
|
|
70
66
|
capabilities: driver.caps,
|
|
71
67
|
};
|
|
72
|
-
this.
|
|
68
|
+
this.log.info(`Constructed webdriverio driver options; W3C mode is ${driverOpts.isW3C ? 'on' : 'off'}`);
|
|
73
69
|
// fork the execution script as a child process
|
|
74
70
|
const childScript = require.resolve('./execute-child.js');
|
|
75
|
-
this.
|
|
76
|
-
const scriptProc =
|
|
71
|
+
this.log.info(`Forking process to run webdriver script as child using ${childScript}`);
|
|
72
|
+
const scriptProc = node_child_process_1.default.fork(childScript);
|
|
77
73
|
// keep track of whether we have canceled the script timeout, so we can stop
|
|
78
74
|
// waiting for it and allow this process to finish gracefully
|
|
79
75
|
let timeoutCanceled = false;
|
|
@@ -85,7 +81,7 @@ class ExecuteDriverPlugin extends plugin_1.BasePlugin {
|
|
|
85
81
|
const res = await new bluebird_1.default((res) => {
|
|
86
82
|
scriptProc.on('message', res); // this is node IPC
|
|
87
83
|
});
|
|
88
|
-
this.
|
|
84
|
+
this.log.info('Received execute driver script result from child process, shutting it down');
|
|
89
85
|
if (res.error) {
|
|
90
86
|
throw new Error(res.error.message);
|
|
91
87
|
}
|
|
@@ -106,7 +102,7 @@ class ExecuteDriverPlugin extends plugin_1.BasePlugin {
|
|
|
106
102
|
};
|
|
107
103
|
// now that the child script is alive, send it the data it needs to start
|
|
108
104
|
// running the driver script
|
|
109
|
-
this.
|
|
105
|
+
this.log.info('Sending driver and script data to child');
|
|
110
106
|
scriptProc.send({ driverOpts, script, timeoutMs });
|
|
111
107
|
// and set up a race between the response from the child and the timeout
|
|
112
108
|
return await bluebird_1.default.race([waitForResult(), waitForTimeout()]);
|
|
@@ -119,19 +115,18 @@ class ExecuteDriverPlugin extends plugin_1.BasePlugin {
|
|
|
119
115
|
// spinning and allows this process to die gracefully
|
|
120
116
|
timeoutCanceled = true;
|
|
121
117
|
if (scriptProc.connected) {
|
|
122
|
-
this.
|
|
118
|
+
this.log.info('Disconnecting from child proc');
|
|
123
119
|
scriptProc.disconnect();
|
|
124
120
|
}
|
|
125
121
|
if (scriptProc.exitCode === null) {
|
|
126
|
-
this.
|
|
122
|
+
this.log.info('Disconnecting from and killing driver script child proc');
|
|
127
123
|
scriptProc.kill();
|
|
128
124
|
}
|
|
129
125
|
else {
|
|
130
|
-
this.
|
|
126
|
+
this.log.info('Script already ended on its own, no need to kill it');
|
|
131
127
|
}
|
|
132
128
|
}
|
|
133
|
-
}
|
|
129
|
+
};
|
|
134
130
|
}
|
|
135
|
-
exports.default = ExecuteDriverPlugin;
|
|
136
131
|
exports.ExecuteDriverPlugin = ExecuteDriverPlugin;
|
|
137
132
|
//# sourceMappingURL=plugin.js.map
|
package/build/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAyC;AACzC,oDAAuB;AACvB,4EAAoC;AACpC,4CAAsC;AACtC,wDAAyB;AAGzB,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAC1C,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,4BAA4B;AAC9E,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC,MAAa,mBAAoB,SAAQ,mBAAU;IACjD,MAAM,CAAC,YAAY,GAAmC;QACpD,2CAA2C,EAAE;YAC3C,IAAI,EAAE;gBACJ,OAAO,EAAE,qBAAqB;gBAC9B,aAAa,EAAE,EAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,EAAC;aACrE;SACF;KACO,CAAC;IAEX;;;;;;;;;;;;OAYG;IACH,mBAAmB,GAIf,KAAK,EACP,IAAwB,EACxB,MAAsB,EACtB,MAAc,EACd,aAAqB,aAAa,EAClC,YAAoB,yBAAyB,EAC7C,EAAE;QACF,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,uDAAuD;gBACrD,2DAA2D;gBAC3D,QAAQ,SAAS,gBAAgB;gBACjC,oBAAoB,MAAM,CAAC,IAAI,CAAC,cAAc,IAAI,GAAG,IAAI,SAAS,EAAE,CACvE,CAAC;QACJ,CAAC;QAED,IAAI,UAAU,KAAK,gBAAgB,EAAE,CAAC;YACpC,MAAM,IAAI,SAAS,CAAC,aAAa,gBAAgB,sCAAsC,CAAC,CAAC;QAC3F,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,UA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;YACxE,qDAAqD;YACrD,eAAe,GAAG,IAAI,CAAC;YAEvB,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;gBACzB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;gBAC/C,UAAU,CAAC,UAAU,EAAE,CAAC;YAC1B,CAAC;YAED,IAAI,UAAU,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACjC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;gBACzE,UAAU,CAAC,IAAI,EAAE,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC,CAAC;;AAtJJ,kDAuJC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface DriverScriptMessageEvent {
|
|
2
|
+
driverOpts: any;
|
|
3
|
+
script: string;
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ScriptResultError {
|
|
7
|
+
message: any;
|
|
8
|
+
stack: any;
|
|
9
|
+
}
|
|
10
|
+
export interface ScriptResult {
|
|
11
|
+
success?: RunScriptResult;
|
|
12
|
+
error?: ScriptResultError;
|
|
13
|
+
}
|
|
14
|
+
export interface RunScriptResult {
|
|
15
|
+
result: any;
|
|
16
|
+
logs: {
|
|
17
|
+
error: any[];
|
|
18
|
+
warn: any[];
|
|
19
|
+
log: any[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,GAAG,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,GAAG,EAAE,GAAG,EAAE,CAAC;KACZ,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":""}
|
|
@@ -2,12 +2,10 @@ import _ from 'lodash';
|
|
|
2
2
|
import B from 'bluebird';
|
|
3
3
|
import vm from 'node:vm';
|
|
4
4
|
import {logger, util} from 'appium/support';
|
|
5
|
+
import type {DriverScriptMessageEvent, ScriptResult, RunScriptResult} from './types';
|
|
5
6
|
|
|
6
7
|
const log = logger.getLogger('ExecuteDriver Child');
|
|
7
|
-
|
|
8
|
-
* @type {(res: ScriptResult) => Promise<void>}
|
|
9
|
-
*/
|
|
10
|
-
let send;
|
|
8
|
+
let send: (res: ScriptResult) => Promise<void>;
|
|
11
9
|
|
|
12
10
|
// duplicate defining these keys here so we don't need to re-load a huge appium
|
|
13
11
|
// dependency tree into memory just to run a wdio script
|
|
@@ -16,11 +14,11 @@ export const MJSONWP_ELEMENT_KEY = 'ELEMENT';
|
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Run the script in a VM.
|
|
19
|
-
* @param
|
|
20
|
-
* @returns
|
|
17
|
+
* @param eventParams - The driver script message event parameters
|
|
18
|
+
* @returns Promise resolving to the run script result
|
|
21
19
|
* @throws {TypeError}
|
|
22
20
|
*/
|
|
23
|
-
async function runScript(eventParams) {
|
|
21
|
+
async function runScript(eventParams: DriverScriptMessageEvent): Promise<RunScriptResult> {
|
|
24
22
|
const {driverOpts, script, timeoutMs} = eventParams;
|
|
25
23
|
if (!_.isNumber(timeoutMs)) {
|
|
26
24
|
throw new TypeError('Timeout parameter must be a number');
|
|
@@ -28,15 +26,17 @@ async function runScript(eventParams) {
|
|
|
28
26
|
|
|
29
27
|
/**
|
|
30
28
|
* set up fake logger
|
|
31
|
-
* @type {string[]}
|
|
32
29
|
*/
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const logs: {error: any[]; warn: any[]; log: any[]} = {
|
|
31
|
+
error: [],
|
|
32
|
+
warn: [],
|
|
33
|
+
log: [],
|
|
34
|
+
};
|
|
35
|
+
const consoleFns: {error: (...args: any[]) => void; warn: (...args: any[]) => void; log: (...args: any[]) => void} = {
|
|
36
|
+
error: (...logMsgs) => logs.error.push(...logMsgs),
|
|
37
|
+
warn: (...logMsgs) => logs.warn.push(...logMsgs),
|
|
38
|
+
log: (...logMsgs) => logs.log.push(...logMsgs),
|
|
39
|
+
};
|
|
40
40
|
|
|
41
41
|
const {attach} = await import('webdriverio');
|
|
42
42
|
|
|
@@ -51,7 +51,7 @@ async function runScript(eventParams) {
|
|
|
51
51
|
let result = await vm.runInNewContext(
|
|
52
52
|
fullScript,
|
|
53
53
|
{driver, console: consoleFns, Promise: B},
|
|
54
|
-
{timeout: timeoutMs, breakOnSigint: true}
|
|
54
|
+
{timeout: timeoutMs, breakOnSigint: true}
|
|
55
55
|
);
|
|
56
56
|
|
|
57
57
|
result = coerceScriptResult(result);
|
|
@@ -65,11 +65,10 @@ async function runScript(eventParams) {
|
|
|
65
65
|
* response. So make sure we convert the things we know about to their
|
|
66
66
|
* appropriate response format, and squash other weird things.
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
69
|
-
*
|
|
70
|
-
* @return {Object} - safely converted object
|
|
68
|
+
* @param obj - object to convert and sanitize
|
|
69
|
+
* @return safely converted object
|
|
71
70
|
*/
|
|
72
|
-
function coerceScriptResult(obj) {
|
|
71
|
+
function coerceScriptResult(obj: any): any {
|
|
73
72
|
// first ensure obj is of a type that can be JSON encoded safely. This will
|
|
74
73
|
// get rid of custom objects, functions, etc... and turn them into POJOs
|
|
75
74
|
try {
|
|
@@ -77,12 +76,12 @@ function coerceScriptResult(obj) {
|
|
|
77
76
|
} catch {
|
|
78
77
|
log.warn(
|
|
79
78
|
'Could not convert executeDriverScript to safe response!' +
|
|
80
|
-
`Result was: ${JSON.stringify(obj)}. Will make it null
|
|
79
|
+
`Result was: ${JSON.stringify(obj)}. Will make it null`
|
|
81
80
|
);
|
|
82
81
|
return null;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
let res;
|
|
84
|
+
let res: any;
|
|
86
85
|
|
|
87
86
|
// now we begin our recursive case options
|
|
88
87
|
if (_.isPlainObject(obj)) {
|
|
@@ -125,19 +124,18 @@ function coerceScriptResult(obj) {
|
|
|
125
124
|
|
|
126
125
|
/**
|
|
127
126
|
* Entry point to runScript
|
|
128
|
-
* @param
|
|
127
|
+
* @param eventParams - The driver script message event parameters
|
|
129
128
|
*/
|
|
130
|
-
async function main(eventParams) {
|
|
129
|
+
async function main(eventParams: DriverScriptMessageEvent): Promise<void> {
|
|
131
130
|
/**
|
|
132
131
|
* keep the response of runScript
|
|
133
|
-
* @type {ScriptResult}
|
|
134
132
|
*/
|
|
135
|
-
let res;
|
|
133
|
+
let res: ScriptResult;
|
|
136
134
|
log.info('Parameters received from parent process');
|
|
137
135
|
try {
|
|
138
136
|
res = {success: await runScript(eventParams)};
|
|
139
137
|
log.info('runScript success');
|
|
140
|
-
} catch (error) {
|
|
138
|
+
} catch (error: any) {
|
|
141
139
|
log.info('runScript error');
|
|
142
140
|
res = {error: {message: error.message, stack: error.stack}};
|
|
143
141
|
}
|
|
@@ -146,33 +144,7 @@ async function main(eventParams) {
|
|
|
146
144
|
|
|
147
145
|
// ensure we're running this script in IPC mode
|
|
148
146
|
if (require.main === module && _.isFunction(process.send)) {
|
|
149
|
-
send = B.promisify(process.send, {context: process})
|
|
147
|
+
send = B.promisify(process.send, {context: process}) as (res: ScriptResult) => Promise<void>;
|
|
150
148
|
log.info('Running driver execution in child process');
|
|
151
149
|
process.on('message', main);
|
|
152
150
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @typedef DriverScriptMessageEvent
|
|
157
|
-
* @property {any} driverOpts - the driver options
|
|
158
|
-
* @property {string} script - the javascript to execute
|
|
159
|
-
* @property {number} timeoutMs - script timeout in milliseconds
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @typedef ScriptResult
|
|
164
|
-
* @property {any} [success]
|
|
165
|
-
* @property {ScriptResultError} [error]
|
|
166
|
-
*/
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @typedef ScriptResultError
|
|
170
|
-
* @property {any} message
|
|
171
|
-
* @property {any} stack
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @typedef RunScriptResult
|
|
176
|
-
* @property {any} result
|
|
177
|
-
* @property {object} logs
|
|
178
|
-
*/
|
package/lib/index.ts
ADDED
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import {BasePlugin} from 'appium/plugin';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
import cp from 'child_process';
|
|
3
|
+
import cp from 'node:child_process';
|
|
4
4
|
import {timing} from 'appium/support';
|
|
5
5
|
import B from 'bluebird';
|
|
6
|
+
import type {ExternalDriver, NextPluginCallback, MethodMap, PluginCommand} from '@appium/types';
|
|
6
7
|
|
|
7
8
|
const FEAT_FLAG = 'execute_driver_script';
|
|
8
9
|
const DEFAULT_SCRIPT_TIMEOUT_MS = 1000 * 60 * 60; // default to 1 hour timeout
|
|
9
10
|
const SCRIPT_TYPE_WDIO = 'webdriverio';
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
-
static newMethodMap =
|
|
12
|
+
export class ExecuteDriverPlugin extends BasePlugin {
|
|
13
|
+
static newMethodMap: MethodMap<ExecuteDriverPlugin> = {
|
|
13
14
|
'/session/:sessionId/appium/execute_driver': {
|
|
14
15
|
POST: {
|
|
15
16
|
command: 'executeDriverScript',
|
|
16
17
|
payloadParams: {required: ['script'], optional: ['type', 'timeout']},
|
|
17
18
|
},
|
|
18
19
|
},
|
|
19
|
-
}
|
|
20
|
+
} as const;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* This method takes a string which is executed as javascript in the context of
|
|
23
24
|
* a new nodejs VM, and which has available a webdriverio driver object, having
|
|
24
25
|
* already been attached to the currently running session.
|
|
25
26
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
* @returns {Promise<any>} - a JSONifiable object representing the return value of
|
|
34
|
-
* the script
|
|
35
|
-
* @type {import('@appium/types').PluginCommand<import('@appium/types').ExternalDriver, [script: string, scriptType: string?, timeoutMs: number?]>}
|
|
27
|
+
* @param next - standard behaviour for executeDriverScript
|
|
28
|
+
* @param driver - Appium driver handling this command
|
|
29
|
+
* @param script - the string representing the driver script to run
|
|
30
|
+
* @param scriptType - the name of the driver script library (currently only webdriverio is supported). Defaults to `'webdriverio'`.
|
|
31
|
+
* @param timeoutMs - timeout for the script process. Defaults to `3600000`.
|
|
32
|
+
* @returns a JSONifiable object representing the return value of the script
|
|
36
33
|
* @throws {Error}
|
|
37
34
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
executeDriverScript: PluginCommand<
|
|
36
|
+
ExternalDriver,
|
|
37
|
+
[script: string, scriptType?: string, timeoutMs?: number],
|
|
38
|
+
any
|
|
39
|
+
> = async (
|
|
40
|
+
next: NextPluginCallback,
|
|
41
|
+
driver: ExternalDriver,
|
|
42
|
+
script: string,
|
|
43
|
+
scriptType: string = 'webdriverio',
|
|
44
|
+
timeoutMs: number = DEFAULT_SCRIPT_TIMEOUT_MS
|
|
45
|
+
) => {
|
|
45
46
|
if (!driver.isFeatureEnabled(FEAT_FLAG)) {
|
|
46
47
|
throw new Error(
|
|
47
48
|
`Execute driver script functionality is not available ` +
|
|
@@ -80,13 +81,13 @@ export default class ExecuteDriverPlugin extends BasePlugin {
|
|
|
80
81
|
isMobile: true,
|
|
81
82
|
capabilities: driver.caps,
|
|
82
83
|
};
|
|
83
|
-
this.
|
|
84
|
+
this.log.info(
|
|
84
85
|
`Constructed webdriverio driver options; W3C mode is ${driverOpts.isW3C ? 'on' : 'off'}`
|
|
85
86
|
);
|
|
86
87
|
|
|
87
88
|
// fork the execution script as a child process
|
|
88
89
|
const childScript = require.resolve('./execute-child.js');
|
|
89
|
-
this.
|
|
90
|
+
this.log.info(`Forking process to run webdriver script as child using ${childScript}`);
|
|
90
91
|
const scriptProc = cp.fork(childScript);
|
|
91
92
|
|
|
92
93
|
// keep track of whether we have canceled the script timeout, so we can stop
|
|
@@ -99,11 +100,11 @@ export default class ExecuteDriverPlugin extends BasePlugin {
|
|
|
99
100
|
|
|
100
101
|
// promise that deals with the result from the child process
|
|
101
102
|
const waitForResult = async () => {
|
|
102
|
-
const res = await new B((res) => {
|
|
103
|
+
const res = await new B<{error?: {message: string}; success?: any}>((res) => {
|
|
103
104
|
scriptProc.on('message', res); // this is node IPC
|
|
104
105
|
});
|
|
105
106
|
|
|
106
|
-
this.
|
|
107
|
+
this.log.info(
|
|
107
108
|
'Received execute driver script result from child process, shutting it down'
|
|
108
109
|
);
|
|
109
110
|
|
|
@@ -134,12 +135,12 @@ export default class ExecuteDriverPlugin extends BasePlugin {
|
|
|
134
135
|
|
|
135
136
|
// now that the child script is alive, send it the data it needs to start
|
|
136
137
|
// running the driver script
|
|
137
|
-
this.
|
|
138
|
+
this.log.info('Sending driver and script data to child');
|
|
138
139
|
scriptProc.send({driverOpts, script, timeoutMs});
|
|
139
140
|
|
|
140
141
|
// and set up a race between the response from the child and the timeout
|
|
141
142
|
return await B.race([waitForResult(), waitForTimeout()]);
|
|
142
|
-
} catch (err) {
|
|
143
|
+
} catch (err: any) {
|
|
143
144
|
throw new Error(`Could not execute driver script. Original error was: ${err}`);
|
|
144
145
|
} finally {
|
|
145
146
|
// ensure we always cancel the timeout so that the timeout promise stops
|
|
@@ -147,18 +148,16 @@ export default class ExecuteDriverPlugin extends BasePlugin {
|
|
|
147
148
|
timeoutCanceled = true;
|
|
148
149
|
|
|
149
150
|
if (scriptProc.connected) {
|
|
150
|
-
this.
|
|
151
|
+
this.log.info('Disconnecting from child proc');
|
|
151
152
|
scriptProc.disconnect();
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
if (scriptProc.exitCode === null) {
|
|
155
|
-
this.
|
|
156
|
+
this.log.info('Disconnecting from and killing driver script child proc');
|
|
156
157
|
scriptProc.kill();
|
|
157
158
|
} else {
|
|
158
|
-
this.
|
|
159
|
+
this.log.info('Script already ended on its own, no need to kill it');
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
}
|
|
162
|
+
};
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
-
export {ExecuteDriverPlugin};
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface DriverScriptMessageEvent {
|
|
2
|
+
driverOpts: any;
|
|
3
|
+
script: string;
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ScriptResultError {
|
|
8
|
+
message: any;
|
|
9
|
+
stack: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ScriptResult {
|
|
13
|
+
success?: RunScriptResult;
|
|
14
|
+
error?: ScriptResultError;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RunScriptResult {
|
|
18
|
+
result: any;
|
|
19
|
+
logs: {
|
|
20
|
+
error: any[];
|
|
21
|
+
warn: any[];
|
|
22
|
+
log: any[];
|
|
23
|
+
};
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/execute-driver-plugin",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Plugin for batching and executing Appium driver commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -23,25 +23,25 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"author": "https://github.com/appium",
|
|
26
|
-
"
|
|
26
|
+
"main": "./build/lib/index.js",
|
|
27
|
+
"types": "./build/lib/index.d.ts",
|
|
27
28
|
"files": [
|
|
28
29
|
"build",
|
|
29
30
|
"lib",
|
|
30
|
-
"index.js",
|
|
31
31
|
"tsconfig.json",
|
|
32
|
-
"!build/tsconfig.tsbuildinfo"
|
|
32
|
+
"!build/tsconfig.tsbuildinfo",
|
|
33
|
+
"!build/test"
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"test": "npm run test:unit",
|
|
36
|
-
"test:e2e": "mocha --exit -t 160s --slow 20s \"./test/e2e/**/*.spec
|
|
37
|
-
"test:smoke": "node ./index.js",
|
|
38
|
-
"test:unit": "mocha \"./test/unit/**/*.spec
|
|
37
|
+
"test:e2e": "mocha --exit -t 160s --slow 20s \"./test/e2e/**/*.spec.*ts\"",
|
|
38
|
+
"test:smoke": "node ./build/lib/index.js",
|
|
39
|
+
"test:unit": "mocha \"./test/unit/**/*.spec.*ts\""
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"bluebird": "3.7.2",
|
|
42
|
-
"lodash": "4.17.
|
|
43
|
-
"
|
|
44
|
-
"webdriverio": "9.21.0"
|
|
43
|
+
"lodash": "4.17.23",
|
|
44
|
+
"webdriverio": "9.23.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"appium": "^3.0.0-beta.0"
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"pluginName": "execute-driver",
|
|
58
58
|
"mainClass": "ExecuteDriverPlugin"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "f7b20335eab4022e5cbbb627ec86866a994444f8"
|
|
61
61
|
}
|
package/tsconfig.json
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"outDir": "build",
|
|
4
4
|
"checkJs": true,
|
|
5
|
-
"esModuleInterop": true
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"types": ["mocha", "chai", "chai-as-promised"]
|
|
6
7
|
},
|
|
7
8
|
"extends": "@appium/tsconfig/tsconfig.plugin.json",
|
|
8
|
-
"include": ["lib"]
|
|
9
|
+
"include": ["lib", "test"]
|
|
9
10
|
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./build/lib/plugin');
|