agent-plugin-lifecycle 0.1.1 → 0.3.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.
Files changed (178) hide show
  1. package/README.md +256 -57
  2. package/bin/cli.js +8 -1
  3. package/dist/cjs/apm.d.cts +62 -13
  4. package/dist/cjs/apm.d.ts +62 -13
  5. package/dist/cjs/apm.js +534 -115
  6. package/dist/cjs/apm.js.map +1 -1
  7. package/dist/cjs/approvals.d.cts +26 -0
  8. package/dist/cjs/approvals.d.ts +26 -0
  9. package/dist/cjs/approvals.js +302 -0
  10. package/dist/cjs/approvals.js.map +1 -0
  11. package/dist/cjs/cli/index.d.cts +5 -0
  12. package/dist/cjs/cli/index.d.ts +5 -0
  13. package/dist/cjs/cli/index.js +53 -0
  14. package/dist/cjs/cli/index.js.map +1 -0
  15. package/dist/cjs/cli/install.d.cts +17 -0
  16. package/dist/cjs/cli/install.d.ts +17 -0
  17. package/dist/cjs/cli/install.js +308 -0
  18. package/dist/cjs/cli/install.js.map +1 -0
  19. package/dist/cjs/cli/report.d.cts +6 -0
  20. package/dist/cjs/cli/report.d.ts +6 -0
  21. package/dist/cjs/cli/report.js +47 -0
  22. package/dist/cjs/cli/report.js.map +1 -0
  23. package/dist/cjs/cli/status.d.cts +2 -0
  24. package/dist/cjs/cli/status.d.ts +2 -0
  25. package/dist/cjs/cli/status.js +222 -0
  26. package/dist/cjs/cli/status.js.map +1 -0
  27. package/dist/cjs/cli/types.d.cts +10 -0
  28. package/dist/cjs/cli/types.d.ts +10 -0
  29. package/dist/cjs/cli/types.js +6 -0
  30. package/dist/cjs/cli/types.js.map +1 -0
  31. package/dist/cjs/cli/usage.d.cts +2 -0
  32. package/dist/cjs/cli/usage.d.ts +2 -0
  33. package/dist/cjs/cli/usage.js +21 -0
  34. package/dist/cjs/cli/usage.js.map +1 -0
  35. package/dist/cjs/cli.d.cts +2 -1
  36. package/dist/cjs/cli.d.ts +2 -1
  37. package/dist/cjs/cli.js +65 -204
  38. package/dist/cjs/cli.js.map +1 -1
  39. package/dist/cjs/constants.d.cts +35 -0
  40. package/dist/cjs/constants.d.ts +35 -0
  41. package/dist/cjs/constants.js +115 -0
  42. package/dist/cjs/constants.js.map +1 -0
  43. package/dist/cjs/copies.d.cts +40 -0
  44. package/dist/cjs/copies.d.ts +40 -0
  45. package/dist/cjs/copies.js +937 -0
  46. package/dist/cjs/copies.js.map +1 -0
  47. package/dist/cjs/index.d.cts +3 -6
  48. package/dist/cjs/index.d.ts +3 -6
  49. package/dist/cjs/index.js +20 -19
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/install.d.cts +6 -0
  52. package/dist/cjs/install.d.ts +6 -0
  53. package/dist/cjs/install.js +511 -0
  54. package/dist/cjs/install.js.map +1 -0
  55. package/dist/cjs/lib/errors.d.cts +5 -0
  56. package/dist/cjs/lib/errors.d.ts +5 -0
  57. package/dist/cjs/lib/errors.js +41 -0
  58. package/dist/cjs/lib/errors.js.map +1 -0
  59. package/dist/cjs/lib/object.d.cts +2 -0
  60. package/dist/cjs/lib/object.d.ts +2 -0
  61. package/dist/cjs/lib/object.js +18 -0
  62. package/dist/cjs/lib/object.js.map +1 -0
  63. package/dist/cjs/lib/options.d.cts +10 -0
  64. package/dist/cjs/lib/options.d.ts +10 -0
  65. package/dist/cjs/lib/options.js +26 -0
  66. package/dist/cjs/lib/options.js.map +1 -0
  67. package/dist/cjs/lib/run.d.cts +2 -0
  68. package/dist/cjs/lib/run.d.ts +2 -0
  69. package/dist/cjs/lib/run.js +40 -0
  70. package/dist/cjs/lib/run.js.map +1 -0
  71. package/dist/cjs/lib/store.d.cts +9 -0
  72. package/dist/cjs/lib/store.d.ts +9 -0
  73. package/dist/cjs/lib/store.js +418 -0
  74. package/dist/cjs/lib/store.js.map +1 -0
  75. package/dist/cjs/lib/visible.d.cts +9 -0
  76. package/dist/cjs/lib/visible.d.ts +9 -0
  77. package/dist/cjs/lib/visible.js +26 -0
  78. package/dist/cjs/lib/visible.js.map +1 -0
  79. package/dist/cjs/manifest.d.cts +4 -0
  80. package/dist/cjs/manifest.d.ts +4 -0
  81. package/dist/cjs/{config.js → manifest.js} +33 -94
  82. package/dist/cjs/manifest.js.map +1 -0
  83. package/dist/cjs/state.d.cts +17 -0
  84. package/dist/cjs/state.d.ts +17 -0
  85. package/dist/cjs/state.js +143 -0
  86. package/dist/cjs/state.js.map +1 -0
  87. package/dist/cjs/status.d.cts +3 -0
  88. package/dist/cjs/status.d.ts +3 -0
  89. package/dist/cjs/status.js +273 -0
  90. package/dist/cjs/status.js.map +1 -0
  91. package/dist/cjs/types.d.cts +39 -0
  92. package/dist/cjs/types.d.ts +39 -0
  93. package/dist/cjs/types.js +5 -0
  94. package/dist/cjs/types.js.map +1 -0
  95. package/dist/esm/apm.d.ts +62 -13
  96. package/dist/esm/apm.js +208 -96
  97. package/dist/esm/apm.js.map +1 -1
  98. package/dist/esm/approvals.d.ts +26 -0
  99. package/dist/esm/approvals.js +43 -0
  100. package/dist/esm/approvals.js.map +1 -0
  101. package/dist/esm/cli/index.d.ts +5 -0
  102. package/dist/esm/cli/index.js +5 -0
  103. package/dist/esm/cli/index.js.map +1 -0
  104. package/dist/esm/cli/install.d.ts +17 -0
  105. package/dist/esm/cli/install.js +89 -0
  106. package/dist/esm/cli/install.js.map +1 -0
  107. package/dist/esm/cli/report.d.ts +6 -0
  108. package/dist/esm/cli/report.js +21 -0
  109. package/dist/esm/cli/report.js.map +1 -0
  110. package/dist/esm/cli/status.d.ts +2 -0
  111. package/dist/esm/cli/status.js +41 -0
  112. package/dist/esm/cli/status.js.map +1 -0
  113. package/dist/esm/cli/types.d.ts +10 -0
  114. package/dist/esm/cli/types.js +2 -0
  115. package/dist/esm/cli/types.js.map +1 -0
  116. package/dist/esm/cli/usage.d.ts +2 -0
  117. package/dist/esm/cli/usage.js +2 -0
  118. package/dist/esm/cli/usage.js.map +1 -0
  119. package/dist/esm/cli.d.ts +2 -1
  120. package/dist/esm/cli.js +46 -65
  121. package/dist/esm/cli.js.map +1 -1
  122. package/dist/esm/constants.d.ts +35 -0
  123. package/dist/esm/constants.js +37 -0
  124. package/dist/esm/constants.js.map +1 -0
  125. package/dist/esm/copies.d.ts +40 -0
  126. package/dist/esm/copies.js +226 -0
  127. package/dist/esm/copies.js.map +1 -0
  128. package/dist/esm/index.d.ts +3 -6
  129. package/dist/esm/index.js +3 -3
  130. package/dist/esm/index.js.map +1 -1
  131. package/dist/esm/install.d.ts +6 -0
  132. package/dist/esm/install.js +116 -0
  133. package/dist/esm/install.js.map +1 -0
  134. package/dist/esm/lib/errors.d.ts +5 -0
  135. package/dist/esm/lib/errors.js +9 -0
  136. package/dist/esm/lib/errors.js.map +1 -0
  137. package/dist/esm/lib/object.d.ts +2 -0
  138. package/dist/esm/lib/object.js +3 -0
  139. package/dist/esm/lib/object.js.map +1 -0
  140. package/dist/esm/lib/options.d.ts +10 -0
  141. package/dist/esm/lib/options.js +15 -0
  142. package/dist/esm/lib/options.js.map +1 -0
  143. package/dist/esm/lib/run.d.ts +2 -0
  144. package/dist/esm/lib/run.js +29 -0
  145. package/dist/esm/lib/run.js.map +1 -0
  146. package/dist/esm/lib/store.d.ts +9 -0
  147. package/dist/esm/lib/store.js +91 -0
  148. package/dist/esm/lib/store.js.map +1 -0
  149. package/dist/esm/lib/visible.d.ts +9 -0
  150. package/dist/esm/lib/visible.js +12 -0
  151. package/dist/esm/lib/visible.js.map +1 -0
  152. package/dist/esm/manifest.d.ts +4 -0
  153. package/dist/esm/manifest.js +25 -0
  154. package/dist/esm/manifest.js.map +1 -0
  155. package/dist/esm/state.d.ts +17 -0
  156. package/dist/esm/state.js +32 -0
  157. package/dist/esm/state.js.map +1 -0
  158. package/dist/esm/status.d.ts +3 -0
  159. package/dist/esm/status.js +44 -0
  160. package/dist/esm/status.js.map +1 -0
  161. package/dist/esm/types.d.ts +39 -0
  162. package/dist/esm/types.js +1 -0
  163. package/dist/esm/types.js.map +1 -0
  164. package/package.json +25 -9
  165. package/config/config.example.json +0 -22
  166. package/dist/cjs/config.d.cts +0 -16
  167. package/dist/cjs/config.d.ts +0 -16
  168. package/dist/cjs/config.js.map +0 -1
  169. package/dist/cjs/runner.d.cts +0 -19
  170. package/dist/cjs/runner.d.ts +0 -19
  171. package/dist/cjs/runner.js +0 -1157
  172. package/dist/cjs/runner.js.map +0 -1
  173. package/dist/esm/config.d.ts +0 -16
  174. package/dist/esm/config.js +0 -74
  175. package/dist/esm/config.js.map +0 -1
  176. package/dist/esm/runner.d.ts +0 -19
  177. package/dist/esm/runner.js +0 -248
  178. package/dist/esm/runner.js.map +0 -1
package/dist/cjs/apm.js CHANGED
@@ -9,31 +9,39 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- get loadLock () {
13
- return loadLock;
12
+ get isUnreadable () {
13
+ return isUnreadable;
14
14
  },
15
- get localEventName () {
16
- return localEventName;
17
- },
18
- get lockIdentity () {
19
- return lockIdentity;
20
- },
21
- get matchesSource () {
22
- return matchesSource;
15
+ get packageFolders () {
16
+ return packageFolders;
23
17
  },
24
18
  get parseLock () {
25
19
  return parseLock;
26
20
  },
27
- get samePath () {
28
- return samePath;
21
+ get readLock () {
22
+ return readLock;
23
+ },
24
+ get recordedFolders () {
25
+ return recordedFolders;
29
26
  },
30
- get sourceParts () {
31
- return sourceParts;
27
+ get resolveScope () {
28
+ return resolveScope;
32
29
  }
33
30
  });
34
31
  var _promises = require("node:fs/promises");
35
32
  var _nodepath = require("node:path");
36
33
  var _yaml = require("yaml");
34
+ var _constantsts = require("./constants.js");
35
+ var _errorsts = require("./lib/errors.js");
36
+ var _objectts = require("./lib/object.js");
37
+ function _array_like_to_array(arr, len) {
38
+ if (len == null || len > arr.length) len = arr.length;
39
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
40
+ return arr2;
41
+ }
42
+ function _array_without_holes(arr) {
43
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
44
+ }
37
45
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
38
46
  try {
39
47
  var info = gen[key](arg);
@@ -60,6 +68,66 @@ function _async_to_generator(fn) {
60
68
  });
61
69
  };
62
70
  }
71
+ function _define_property(obj, key, value) {
72
+ if (key in obj) {
73
+ Object.defineProperty(obj, key, {
74
+ value: value,
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true
78
+ });
79
+ } else obj[key] = value;
80
+ return obj;
81
+ }
82
+ function _iterable_to_array(iter) {
83
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
84
+ return Array.from(iter);
85
+ }
86
+ }
87
+ function _non_iterable_spread() {
88
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89
+ }
90
+ function _object_spread(target) {
91
+ for(var i = 1; i < arguments.length; i++){
92
+ var source = arguments[i] != null ? arguments[i] : {};
93
+ var ownKeys = Object.keys(source);
94
+ if (typeof Object.getOwnPropertySymbols === "function") {
95
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
96
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
97
+ }));
98
+ }
99
+ ownKeys.forEach(function(key) {
100
+ _define_property(target, key, source[key]);
101
+ });
102
+ }
103
+ return target;
104
+ }
105
+ function ownKeys(object, enumerableOnly) {
106
+ var keys = Object.keys(object);
107
+ if (Object.getOwnPropertySymbols) {
108
+ var symbols = Object.getOwnPropertySymbols(object);
109
+ if (enumerableOnly) {
110
+ symbols = symbols.filter(function(sym) {
111
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
112
+ });
113
+ }
114
+ keys.push.apply(keys, symbols);
115
+ }
116
+ return keys;
117
+ }
118
+ function _object_spread_props(target, source) {
119
+ source = source != null ? source : {};
120
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
121
+ else {
122
+ ownKeys(Object(source)).forEach(function(key) {
123
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
124
+ });
125
+ }
126
+ return target;
127
+ }
128
+ function _to_consumable_array(arr) {
129
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
130
+ }
63
131
  function _ts_generator(thisArg, body) {
64
132
  var f, y, t, _ = {
65
133
  label: 0,
@@ -159,12 +227,19 @@ function _ts_generator(thisArg, body) {
159
227
  };
160
228
  }
161
229
  }
162
- function _type_of(obj) {
163
- "@swc/helpers - typeof";
164
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
230
+ function _unsupported_iterable_to_array(o, minLen) {
231
+ if (!o) return;
232
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
233
+ var n = Object.prototype.toString.call(o).slice(8, -1);
234
+ if (n === "Object" && o.constructor) n = o.constructor.name;
235
+ if (n === "Map" || n === "Set") return Array.from(o);
236
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
165
237
  }
238
+ var isUnreadable = function isUnreadable(row) {
239
+ return 'reason' in row;
240
+ };
166
241
  function record(value, label) {
167
- if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object' || Array.isArray(value)) throw new Error("".concat(label, " must be an object"));
242
+ if (!(0, _objectts.isRecord)(value)) throw new Error("".concat(label, " must be an object"));
168
243
  return value;
169
244
  }
170
245
  function requiredString(value, label) {
@@ -180,128 +255,320 @@ function safePath(value, label) {
180
255
  })) throw new Error("".concat(label, " contains an unsafe path segment"));
181
256
  return path;
182
257
  }
183
- function sourceParts(source) {
184
- var host;
185
- var path;
186
- var scp = source.includes('://') ? null : /^(?:[^@/:]+@)?([^/:]+):(.+)$/.exec(source);
187
- if (scp) {
188
- host = scp[1];
189
- path = scp[2];
190
- } else {
191
- try {
192
- var url = new URL(source);
193
- if (![
194
- 'https:',
195
- 'ssh:',
196
- 'http:'
197
- ].includes(url.protocol)) return undefined;
198
- host = url.hostname;
199
- path = url.pathname.replace(/^\//, '');
200
- } catch (unused) {
201
- return undefined;
202
- }
203
- }
204
- path = path.replace(/\.git$/, '').replace(/\/$/, '');
205
- if (!host || !path || path.split('/').some(function(part) {
206
- return !part || part === '.' || part === '..';
207
- })) return undefined;
208
- return {
209
- host: host.toLowerCase(),
210
- repo: path
211
- };
258
+ function optionalRecord(value, label) {
259
+ return value === undefined || value === null ? undefined : record(value, label);
212
260
  }
213
- function samePath(left, right) {
214
- var platform = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : process.platform;
215
- if (platform !== 'win32') return _nodepath.posix.resolve(left) === _nodepath.posix.resolve(right);
216
- return _nodepath.win32.resolve(left).toLowerCase() === _nodepath.win32.resolve(right).toLowerCase();
261
+ function optionalString(value, label) {
262
+ return value === undefined || value === null ? undefined : requiredString(value, label);
217
263
  }
218
- function matchesSource(policySource, plugin) {
219
- var platform = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : process.platform;
220
- if (plugin.localPath !== undefined) return samePath(policySource, plugin.localPath, platform);
221
- var parts = sourceParts(policySource);
222
- return !!parts && parts.host === plugin.host.toLowerCase() && parts.repo === plugin.repo.replace(/\.git$/, '');
223
- }
224
- function localEventName(source) {
225
- return "_local/".concat((0, _nodepath.basename)(source).replace(/\/$/, ''));
264
+ function deployedFiles(value, label, absolute) {
265
+ var deployed = value !== null && value !== void 0 ? value : [];
266
+ if (!Array.isArray(deployed) || !deployed.every(function(file) {
267
+ return typeof file === 'string';
268
+ })) throw new Error("".concat(label, ".deployed_files must be an array of paths"));
269
+ return deployed.map(function(file, index) {
270
+ return absolute && (0, _nodepath.isAbsolute)(file) ? file : safePath(file, "".concat(label, ".deployed_files[").concat(index, "]"));
271
+ });
226
272
  }
227
- function lockIdentity(plugin) {
228
- var _plugin_localPath;
229
- return JSON.stringify([
230
- plugin.host,
231
- plugin.repo,
232
- plugin.path,
233
- (_plugin_localPath = plugin.localPath) !== null && _plugin_localPath !== void 0 ? _plugin_localPath : null
234
- ]);
273
+ /**
274
+ * `repo_url` as a path, and the host when it is a URL (APM's spec: `host` is recorded "when not inferable from `repo_url`"). An unsafe
275
+ * path throws, for the whole lock; a value that names no path (empty, or a URL that does not parse) is `undefined`, for its row alone.
276
+ */ function repository(value, label) {
277
+ if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return value ? {
278
+ repo: safePath(value, label)
279
+ } : undefined;
280
+ var url = URL.parse(value);
281
+ var path = url === null || url === void 0 ? void 0 : url.pathname.slice(1);
282
+ return url && path ? {
283
+ host: url.host,
284
+ repo: safePath(path, label)
285
+ } : undefined;
235
286
  }
236
287
  function parseLock(value) {
288
+ var absolute = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
237
289
  var root = record(value, 'APM lock');
238
290
  if (!Array.isArray(root.dependencies)) throw new Error('APM lock dependencies must be an array');
239
291
  var seen = new Set();
240
- return root.dependencies.map(function(raw, index) {
292
+ return root.dependencies.map(function(source, index) {
241
293
  var label = "APM lock dependencies[".concat(index, "]");
242
- var source = record(raw, label);
243
- var plugin;
244
- if (source.source === 'local' && source.package_type === 'agent_plugin') {
245
- var repo = safePath(source.repo_url, "".concat(label, ".repo_url"));
246
- if (!repo.startsWith('_local/')) throw new Error("".concat(label, ".repo_url is not a local plugin key"));
247
- var localPath = requiredString(source.local_path, "".concat(label, ".local_path"));
248
- var hash = requiredString(source.content_hash, "".concat(label, ".content_hash"));
249
- if (!/^sha256:[0-9a-f]{64}$/.test(hash)) throw new Error("".concat(label, " has invalid content hash"));
250
- plugin = {
251
- host: 'local',
252
- repo: repo,
253
- path: '.',
254
- revision: hash,
255
- localPath: localPath,
256
- deployedFiles: []
257
- };
258
- } else {
259
- var _source_deployed_files;
260
- var host = requiredString(source.host, "".concat(label, ".host"));
261
- var repo1 = safePath(source.repo_url, "".concat(label, ".repo_url"));
262
- // APM writes no virtual_path for a plugin at the repository root (recorded from APM 0.37.0)
263
- var path = source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, "".concat(label, ".virtual_path"), true);
264
- var commit = requiredString(source.resolved_commit, "".concat(label, ".resolved_commit"));
265
- var hash1 = requiredString(source.content_hash, "".concat(label, ".content_hash"));
266
- if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(commit) || !/^sha256:[0-9a-f]{64}$/.test(hash1)) throw new Error("".concat(label, " has invalid revision evidence"));
267
- var native = source.native_plugin === undefined || source.native_plugin === null ? undefined : record(source.native_plugin, "".concat(label, ".native_plugin"));
268
- var nativePluginRoot = native ? safePath(native.root, "".concat(label, ".native_plugin.root")) : undefined;
269
- var deployed = (_source_deployed_files = source.deployed_files) !== null && _source_deployed_files !== void 0 ? _source_deployed_files : [];
270
- if (!Array.isArray(deployed) || !deployed.every(function(file) {
271
- return typeof file === 'string';
272
- })) throw new Error("".concat(label, ".deployed_files must be an array of paths"));
273
- var deployedFiles = deployed.map(function(file, fileIndex) {
274
- return safePath(file, "".concat(label, ".deployed_files[").concat(fileIndex, "]"));
275
- });
276
- plugin = {
277
- host: host,
278
- repo: repo1,
279
- path: path,
280
- revision: "".concat(commit, ":").concat(hash1),
294
+ if (!(0, _objectts.isRecord)(source)) return {
295
+ name: "dependencies[".concat(index, "]"),
296
+ reason: "".concat(label, " must be an object"),
297
+ deployedFiles: []
298
+ };
299
+ var local = source.source === 'local';
300
+ // the paths: where apl looks for copies, and APM's cache of the package
301
+ var native = optionalRecord(source.native_plugin, "".concat(label, ".native_plugin"));
302
+ var nativePluginRoot = native ? safePath(native.root, "".concat(label, ".native_plugin.root")) : undefined;
303
+ var deployed = deployedFiles(source.deployed_files, label, absolute);
304
+ var located = typeof source.repo_url === 'string' ? repository(source.repo_url, "".concat(label, ".repo_url")) : undefined;
305
+ // APM writes no virtual_path for a plugin at the repository root
306
+ var path = local || source.virtual_path === undefined || source.virtual_path === null ? '.' : safePath(source.virtual_path, "".concat(label, ".virtual_path"), true);
307
+ try {
308
+ var _item_host, _item_localPath;
309
+ if (!located) throw new Error("".concat(label, ".repo_url must be a repository path or URL"));
310
+ var revision = [
311
+ optionalString(source.resolved_commit, "".concat(label, ".resolved_commit")),
312
+ optionalString(source.resolved_hash, "".concat(label, ".resolved_hash")),
313
+ optionalString(source.content_hash, "".concat(label, ".content_hash"))
314
+ ].filter(Boolean).join(':');
315
+ if (!revision) throw new Error("".concat(label, " has none of resolved_commit, resolved_hash and content_hash"));
316
+ var item;
317
+ if (local) {
318
+ if (!located.repo.startsWith('_local/')) throw new Error("".concat(label, ".repo_url is not a local package key"));
319
+ item = {
320
+ repo: located.repo,
321
+ path: path,
322
+ localPath: requiredString(source.local_path, "".concat(label, ".local_path")),
323
+ revision: revision,
324
+ nativePluginRoot: nativePluginRoot,
325
+ deployedFiles: deployed
326
+ };
327
+ } else {
328
+ var _optionalString;
329
+ var host = (_optionalString = optionalString(source.host, "".concat(label, ".host"))) !== null && _optionalString !== void 0 ? _optionalString : located.host;
330
+ if (source.port !== undefined && source.port !== null && !Number.isInteger(source.port)) throw new Error("".concat(label, ".port must be an integer"));
331
+ var port = host === undefined || source.port === undefined || source.port === null ? '' : ":".concat(source.port);
332
+ item = _object_spread_props(_object_spread({}, host === undefined ? {} : {
333
+ host: "".concat(host).concat(port)
334
+ }), {
335
+ repo: located.repo,
336
+ path: path,
337
+ revision: revision,
338
+ nativePluginRoot: nativePluginRoot,
339
+ deployedFiles: deployed
340
+ });
341
+ }
342
+ var identity = JSON.stringify([
343
+ (_item_host = item.host) !== null && _item_host !== void 0 ? _item_host : null,
344
+ item.repo,
345
+ item.path,
346
+ (_item_localPath = item.localPath) !== null && _item_localPath !== void 0 ? _item_localPath : null
347
+ ]);
348
+ if (seen.has(identity)) throw new Error("".concat(label, " duplicates another lock entry"));
349
+ seen.add(identity);
350
+ return item;
351
+ } catch (error) {
352
+ return {
353
+ name: typeof source.repo_url === 'string' && source.repo_url ? source.repo_url : "dependencies[".concat(index, "]"),
354
+ reason: (0, _errorsts.message)(error),
281
355
  nativePluginRoot: nativePluginRoot,
282
- deployedFiles: deployedFiles
356
+ deployedFiles: deployed
283
357
  };
284
358
  }
285
- var identity = lockIdentity(plugin);
286
- if (seen.has(identity)) throw new Error("".concat(label, " duplicates another lock entry"));
287
- seen.add(identity);
288
- return plugin;
289
359
  });
290
360
  }
291
- function loadLock(path) {
361
+ function readLock(path) {
362
+ var absolute = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
292
363
  return _async_to_generator(function() {
364
+ var text, error;
293
365
  return _ts_generator(this, function(_state) {
294
366
  switch(_state.label){
295
367
  case 0:
368
+ _state.trys.push([
369
+ 0,
370
+ 2,
371
+ ,
372
+ 3
373
+ ]);
296
374
  return [
297
375
  4,
298
376
  (0, _promises.readFile)(path, 'utf8')
299
377
  ];
378
+ case 1:
379
+ text = _state.sent();
380
+ return [
381
+ 3,
382
+ 3
383
+ ];
384
+ case 2:
385
+ error = _state.sent();
386
+ if ((0, _errorsts.missing)(error)) return [
387
+ 2,
388
+ undefined
389
+ ];
390
+ throw error;
391
+ case 3:
392
+ try {
393
+ // no pretty errors: the message quotes none of the file
394
+ return [
395
+ 2,
396
+ parseLock((0, _yaml.parse)(text, {
397
+ prettyErrors: false
398
+ }), absolute)
399
+ ];
400
+ } catch (error) {
401
+ throw new Error("cannot read ".concat(path, ": ").concat((0, _errorsts.message)(error)));
402
+ }
403
+ return [
404
+ 2
405
+ ];
406
+ }
407
+ });
408
+ })();
409
+ }
410
+ function samePlace(left, right) {
411
+ return _async_to_generator(function() {
412
+ var _, error;
413
+ return _ts_generator(this, function(_state) {
414
+ switch(_state.label){
415
+ case 0:
416
+ _state.trys.push([
417
+ 0,
418
+ 3,
419
+ ,
420
+ 4
421
+ ]);
422
+ return [
423
+ 4,
424
+ (0, _promises.realpath)(left)
425
+ ];
426
+ case 1:
427
+ _ = _state.sent();
428
+ return [
429
+ 4,
430
+ (0, _promises.realpath)(right)
431
+ ];
432
+ case 2:
433
+ return [
434
+ 2,
435
+ _ === _state.sent()
436
+ ];
437
+ case 3:
438
+ error = _state.sent();
439
+ if ((0, _errorsts.missing)(error)) return [
440
+ 2,
441
+ false
442
+ ];
443
+ throw error;
444
+ case 4:
445
+ return [
446
+ 2
447
+ ];
448
+ }
449
+ });
450
+ })();
451
+ }
452
+ function resolveScope(options) {
453
+ return _async_to_generator(function() {
454
+ var cwd, home, apmHome, _tmp;
455
+ return _ts_generator(this, function(_state) {
456
+ switch(_state.label){
457
+ case 0:
458
+ cwd = options.cwd, home = options.home, apmHome = options.apmHome;
459
+ _tmp = options.global;
460
+ if (_tmp) return [
461
+ 3,
462
+ 2
463
+ ];
464
+ return [
465
+ 4,
466
+ samePlace(cwd, apmHome)
467
+ ];
468
+ case 1:
469
+ _tmp = _state.sent();
470
+ _state.label = 2;
471
+ case 2:
472
+ if (_tmp) return [
473
+ 2,
474
+ {
475
+ global: true,
476
+ lock: (0, _nodepath.join)(apmHome, _constantsts.APM_LOCK),
477
+ root: home,
478
+ manifestRoot: apmHome,
479
+ modules: (0, _nodepath.join)(apmHome, _constantsts.APM_MODULES)
480
+ }
481
+ ];
482
+ return [
483
+ 2,
484
+ {
485
+ global: false,
486
+ lock: (0, _nodepath.join)(cwd, _constantsts.APM_LOCK),
487
+ root: cwd,
488
+ manifestRoot: cwd,
489
+ modules: (0, _nodepath.join)(cwd, _constantsts.APM_MODULES)
490
+ }
491
+ ];
492
+ }
493
+ });
494
+ })();
495
+ }
496
+ var native = function native(path) {
497
+ return _nodepath.join.apply(void 0, _to_consumable_array(path.split('/')));
498
+ };
499
+ function skillFolders(folder, bound) {
500
+ return _async_to_generator(function() {
501
+ var entries, error;
502
+ return _ts_generator(this, function(_state) {
503
+ switch(_state.label){
504
+ case 0:
505
+ _state.trys.push([
506
+ 0,
507
+ 2,
508
+ ,
509
+ 3
510
+ ]);
511
+ return [
512
+ 4,
513
+ (0, _promises.readdir)((0, _nodepath.join)(folder, _constantsts.SKILLS), {
514
+ withFileTypes: true
515
+ })
516
+ ];
517
+ case 1:
518
+ entries = _state.sent();
519
+ return [
520
+ 2,
521
+ entries.filter(function(entry) {
522
+ return entry.isDirectory();
523
+ }).map(function(entry) {
524
+ return entry.name;
525
+ }).sort().map(function(name) {
526
+ return _object_spread({
527
+ folder: (0, _nodepath.join)(folder, _constantsts.SKILLS, name),
528
+ within: "".concat(_constantsts.SKILLS, "/").concat(name)
529
+ }, bound === undefined ? {} : {
530
+ bound: bound
531
+ });
532
+ })
533
+ ];
534
+ case 2:
535
+ error = _state.sent();
536
+ if ((0, _errorsts.missing)(error)) return [
537
+ 2,
538
+ []
539
+ ];
540
+ throw error;
541
+ case 3:
542
+ return [
543
+ 2
544
+ ];
545
+ }
546
+ });
547
+ })();
548
+ }
549
+ /** A folder and its `skills/<name>/` folders. */ function withSkills(folder, bound) {
550
+ return _async_to_generator(function() {
551
+ var _, _1;
552
+ return _ts_generator(this, function(_state) {
553
+ switch(_state.label){
554
+ case 0:
555
+ _1 = (_ = [
556
+ _object_spread({
557
+ folder: folder,
558
+ within: ''
559
+ }, bound === undefined ? {} : {
560
+ bound: bound
561
+ })
562
+ ]).concat;
563
+ return [
564
+ 4,
565
+ skillFolders(folder, bound)
566
+ ];
300
567
  case 1:
301
568
  return [
302
569
  2,
303
- parseLock.apply(void 0, [
304
- _yaml.parse.apply(void 0, [
570
+ _1.apply(_, [
571
+ _to_consumable_array.apply(void 0, [
305
572
  _state.sent()
306
573
  ])
307
574
  ])
@@ -310,4 +577,156 @@ function loadLock(path) {
310
577
  });
311
578
  })();
312
579
  }
580
+ /** `entry` is a folder in APM's record: another recorded path lies under it. */ function recordedFolder(entry, entries) {
581
+ return entries.some(function(other) {
582
+ return other.length > entry.length && other.startsWith(entry) && (other[entry.length] === '/' || other[entry.length] === '\\');
583
+ });
584
+ }
585
+ function recordedFolders(item, scope) {
586
+ return _async_to_generator(function() {
587
+ var folders, seen, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, entry, absolute, folder, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, found, err;
588
+ return _ts_generator(this, function(_state) {
589
+ switch(_state.label){
590
+ case 0:
591
+ folders = [];
592
+ seen = new Set();
593
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
594
+ try {
595
+ for(_iterator = item.deployedFiles[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
596
+ entry = _step.value;
597
+ if (!recordedFolder(entry, item.deployedFiles)) continue;
598
+ absolute = (0, _nodepath.isAbsolute)(entry);
599
+ // an absolute path in the platform's own form: APM on Windows records `D:/...` with forward slashes
600
+ folder = absolute ? (0, _nodepath.resolve)(entry) : (0, _nodepath.join)(scope.root, native(entry));
601
+ if (seen.has(folder)) continue;
602
+ seen.add(folder);
603
+ folders.push(_object_spread({
604
+ folder: folder,
605
+ within: "".concat(_constantsts.SKILLS, "/").concat((0, _nodepath.basename)(folder))
606
+ }, absolute ? {} : {
607
+ bound: scope.root
608
+ }));
609
+ }
610
+ } catch (err) {
611
+ _didIteratorError = true;
612
+ _iteratorError = err;
613
+ } finally{
614
+ try {
615
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
616
+ _iterator.return();
617
+ }
618
+ } finally{
619
+ if (_didIteratorError) {
620
+ throw _iteratorError;
621
+ }
622
+ }
623
+ }
624
+ if (!item.nativePluginRoot) return [
625
+ 3,
626
+ 8
627
+ ];
628
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
629
+ _state.label = 1;
630
+ case 1:
631
+ _state.trys.push([
632
+ 1,
633
+ 6,
634
+ 7,
635
+ 8
636
+ ]);
637
+ return [
638
+ 4,
639
+ withSkills((0, _nodepath.join)(scope.root, native(item.nativePluginRoot)), scope.root)
640
+ ];
641
+ case 2:
642
+ _iterator1 = _state.sent()[Symbol.iterator]();
643
+ _state.label = 3;
644
+ case 3:
645
+ if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
646
+ 3,
647
+ 5
648
+ ];
649
+ found = _step1.value;
650
+ if (!seen.has(found.folder)) folders.push(found);
651
+ _state.label = 4;
652
+ case 4:
653
+ _iteratorNormalCompletion1 = true;
654
+ return [
655
+ 3,
656
+ 3
657
+ ];
658
+ case 5:
659
+ return [
660
+ 3,
661
+ 8
662
+ ];
663
+ case 6:
664
+ err = _state.sent();
665
+ _didIteratorError1 = true;
666
+ _iteratorError1 = err;
667
+ return [
668
+ 3,
669
+ 8
670
+ ];
671
+ case 7:
672
+ try {
673
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
674
+ _iterator1.return();
675
+ }
676
+ } finally{
677
+ if (_didIteratorError1) {
678
+ throw _iteratorError1;
679
+ }
680
+ }
681
+ return [
682
+ 7
683
+ ];
684
+ case 8:
685
+ return [
686
+ 2,
687
+ folders
688
+ ];
689
+ }
690
+ });
691
+ })();
692
+ }
693
+ function packageFolders(item, scope) {
694
+ return _async_to_generator(function() {
695
+ var folders, carried, cache;
696
+ return _ts_generator(this, function(_state) {
697
+ switch(_state.label){
698
+ case 0:
699
+ return [
700
+ 4,
701
+ recordedFolders(item, scope)
702
+ ];
703
+ case 1:
704
+ folders = _state.sent();
705
+ carried = new Set(folders.map(function(found) {
706
+ return found.within;
707
+ }));
708
+ return [
709
+ 4,
710
+ withSkills(_nodepath.join.apply(void 0, [
711
+ scope.modules,
712
+ native(item.repo)
713
+ ].concat(_to_consumable_array(item.path === '.' ? [] : [
714
+ native(item.path)
715
+ ]))))
716
+ ];
717
+ case 2:
718
+ cache = _state.sent().filter(function(found) {
719
+ return !carried.has(found.within);
720
+ });
721
+ return [
722
+ 2,
723
+ {
724
+ folders: folders,
725
+ cache: cache
726
+ }
727
+ ];
728
+ }
729
+ });
730
+ })();
731
+ }
313
732
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }