@4399ywkf/core 4.0.61

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 (61) hide show
  1. package/README.md +3 -0
  2. package/compiled/dotenv/LICENSE +23 -0
  3. package/compiled/dotenv/index.js +1 -0
  4. package/compiled/dotenv/lib/main.d.ts +73 -0
  5. package/compiled/dotenv/package.json +1 -0
  6. package/compiled/dotenv/types/index.d.ts +59 -0
  7. package/compiled/dotenv-expand/LICENSE +24 -0
  8. package/compiled/dotenv-expand/index.js +1 -0
  9. package/compiled/dotenv-expand/lib/main.d.ts +29 -0
  10. package/compiled/dotenv-expand/package.json +1 -0
  11. package/compiled/just-diff/LICENSE +21 -0
  12. package/compiled/just-diff/index.d.ts +20 -0
  13. package/compiled/just-diff/index.js +1 -0
  14. package/compiled/just-diff/package.json +1 -0
  15. package/dist/config/config.d.ts +62 -0
  16. package/dist/config/config.js +240 -0
  17. package/dist/config/utils.d.ts +8 -0
  18. package/dist/config/utils.js +40 -0
  19. package/dist/constants.d.ts +9 -0
  20. package/dist/constants.js +45 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +51 -0
  23. package/dist/route/defineRoutes.d.ts +1 -0
  24. package/dist/route/defineRoutes.js +61 -0
  25. package/dist/route/route.d.ts +3 -0
  26. package/dist/route/route.js +27 -0
  27. package/dist/route/routeUtils.d.ts +8 -0
  28. package/dist/route/routeUtils.js +46 -0
  29. package/dist/route/routesConfig.d.ts +6 -0
  30. package/dist/route/routesConfig.js +125 -0
  31. package/dist/route/routesConvention.d.ts +5 -0
  32. package/dist/route/routesConvention.js +88 -0
  33. package/dist/route/utils.d.ts +8 -0
  34. package/dist/route/utils.js +59 -0
  35. package/dist/service/command.d.ts +30 -0
  36. package/dist/service/command.js +46 -0
  37. package/dist/service/env.d.ts +4 -0
  38. package/dist/service/env.js +46 -0
  39. package/dist/service/generatePlugin.d.ts +4 -0
  40. package/dist/service/generatePlugin.js +102 -0
  41. package/dist/service/generator.d.ts +71 -0
  42. package/dist/service/generator.js +40 -0
  43. package/dist/service/hook.d.ts +16 -0
  44. package/dist/service/hook.js +57 -0
  45. package/dist/service/path.d.ts +15 -0
  46. package/dist/service/path.js +55 -0
  47. package/dist/service/plugin.d.ts +61 -0
  48. package/dist/service/plugin.js +177 -0
  49. package/dist/service/pluginAPI.d.ts +49 -0
  50. package/dist/service/pluginAPI.js +237 -0
  51. package/dist/service/service.d.ts +147 -0
  52. package/dist/service/service.js +538 -0
  53. package/dist/service/servicePlugin.d.ts +3 -0
  54. package/dist/service/servicePlugin.js +37 -0
  55. package/dist/service/telemetry.d.ts +32 -0
  56. package/dist/service/telemetry.js +127 -0
  57. package/dist/service/utils.d.ts +2 -0
  58. package/dist/service/utils.js +36 -0
  59. package/dist/types.d.ts +116 -0
  60. package/dist/types.js +77 -0
  61. package/package.json +49 -0
@@ -0,0 +1,538 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/service/service.ts
30
+ var service_exports = {};
31
+ __export(service_exports, {
32
+ Service: () => Service
33
+ });
34
+ module.exports = __toCommonJS(service_exports);
35
+ var import_tapable = require("@4399ywkf/bundler-utils/compiled/tapable");
36
+ var import_utils = require("@4399ywkf/utils");
37
+ var import_assert = __toESM(require("assert"));
38
+ var import_fs = require("fs");
39
+ var import_path = require("path");
40
+ var import_config = require("../config/config");
41
+ var import_constants = require("../constants");
42
+ var import_types = require("../types");
43
+ var import_env = require("./env");
44
+ var import_path2 = require("./path");
45
+ var import_plugin = require("./plugin");
46
+ var import_pluginAPI = require("./pluginAPI");
47
+ var import_telemetry = require("./telemetry");
48
+ var Service = class {
49
+ opts;
50
+ appData = {};
51
+ args = { _: [], $0: "" };
52
+ commands = {};
53
+ generators = {};
54
+ config = {};
55
+ configSchemas = {};
56
+ configDefaults = {};
57
+ configOnChanges = {};
58
+ cwd;
59
+ env;
60
+ hooks = {};
61
+ name = "";
62
+ paths = {};
63
+ // preset is plugin with different type
64
+ plugins = {};
65
+ keyToPluginMap = {};
66
+ pluginMethods = {};
67
+ skipPluginIds = /* @__PURE__ */ new Set();
68
+ stage = import_types.ServiceStage.uninitialized;
69
+ userConfig = {};
70
+ configManager = null;
71
+ pkg = {};
72
+ pkgPath = "";
73
+ telemetry = new import_telemetry.Telemetry();
74
+ constructor(opts) {
75
+ this.cwd = opts.cwd;
76
+ this.env = opts.env;
77
+ this.opts = opts;
78
+ (0, import_assert.default)((0, import_fs.existsSync)(this.cwd), `Invalid cwd ${this.cwd}, it's not found.`);
79
+ }
80
+ applyPlugins(opts) {
81
+ const hooks = this.hooks[opts.key] || [];
82
+ let type = opts.type;
83
+ if (!type) {
84
+ if (opts.key.startsWith("on")) {
85
+ type = import_types.ApplyPluginsType.event;
86
+ } else if (opts.key.startsWith("modify")) {
87
+ type = import_types.ApplyPluginsType.modify;
88
+ } else if (opts.key.startsWith("add")) {
89
+ type = import_types.ApplyPluginsType.add;
90
+ } else {
91
+ throw new Error(
92
+ `Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`
93
+ );
94
+ }
95
+ }
96
+ switch (type) {
97
+ case import_types.ApplyPluginsType.add:
98
+ (0, import_assert.default)(
99
+ !("initialValue" in opts) || Array.isArray(opts.initialValue),
100
+ `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`
101
+ );
102
+ const tAdd = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
103
+ for (const hook of hooks) {
104
+ if (!this.isPluginEnable(hook)) continue;
105
+ tAdd.tapPromise(
106
+ {
107
+ name: hook.plugin.key,
108
+ stage: hook.stage || 0,
109
+ before: hook.before
110
+ },
111
+ async (memo) => {
112
+ var _a, _b;
113
+ const dateStart = /* @__PURE__ */ new Date();
114
+ const items = await hook.fn(opts.args);
115
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
116
+ hook.plugin.time.hooks[opts.key].push(
117
+ (/* @__PURE__ */ new Date()).getTime() - dateStart.getTime()
118
+ );
119
+ return memo.concat(items);
120
+ }
121
+ );
122
+ }
123
+ return tAdd.promise(opts.initialValue || []);
124
+ case import_types.ApplyPluginsType.modify:
125
+ const tModify = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
126
+ for (const hook of hooks) {
127
+ if (!this.isPluginEnable(hook)) continue;
128
+ tModify.tapPromise(
129
+ {
130
+ name: hook.plugin.key,
131
+ stage: hook.stage || 0,
132
+ before: hook.before
133
+ },
134
+ async (memo) => {
135
+ var _a, _b;
136
+ const dateStart = /* @__PURE__ */ new Date();
137
+ const ret = await hook.fn(memo, opts.args);
138
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
139
+ hook.plugin.time.hooks[opts.key].push(
140
+ (/* @__PURE__ */ new Date()).getTime() - dateStart.getTime()
141
+ );
142
+ return ret;
143
+ }
144
+ );
145
+ }
146
+ return tModify.promise(opts.initialValue);
147
+ case import_types.ApplyPluginsType.event:
148
+ if (opts.sync) {
149
+ const tEvent2 = new import_tapable.SyncWaterfallHook(["_"]);
150
+ hooks.forEach((hook) => {
151
+ if (this.isPluginEnable(hook)) {
152
+ tEvent2.tap(
153
+ {
154
+ name: hook.plugin.key,
155
+ stage: hook.stage || 0,
156
+ before: hook.before
157
+ },
158
+ () => {
159
+ var _a, _b;
160
+ const dateStart = /* @__PURE__ */ new Date();
161
+ hook.fn(opts.args);
162
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
163
+ hook.plugin.time.hooks[opts.key].push(
164
+ (/* @__PURE__ */ new Date()).getTime() - dateStart.getTime()
165
+ );
166
+ }
167
+ );
168
+ }
169
+ });
170
+ return tEvent2.call(1);
171
+ }
172
+ const tEvent = new import_tapable.AsyncSeriesWaterfallHook(["_"]);
173
+ for (const hook of hooks) {
174
+ if (!this.isPluginEnable(hook)) continue;
175
+ tEvent.tapPromise(
176
+ {
177
+ name: hook.plugin.key,
178
+ stage: hook.stage || 0,
179
+ before: hook.before
180
+ },
181
+ async () => {
182
+ var _a, _b;
183
+ const dateStart = /* @__PURE__ */ new Date();
184
+ await hook.fn(opts.args);
185
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
186
+ hook.plugin.time.hooks[opts.key].push(
187
+ (/* @__PURE__ */ new Date()).getTime() - dateStart.getTime()
188
+ );
189
+ }
190
+ );
191
+ }
192
+ return tEvent.promise(1);
193
+ default:
194
+ throw new Error(
195
+ `applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`
196
+ );
197
+ }
198
+ }
199
+ async run(opts) {
200
+ const { name, args = {} } = opts;
201
+ args._ = args._ || [];
202
+ if (args._[0] === name) args._.shift();
203
+ this.args = args;
204
+ this.name = name;
205
+ this.stage = import_types.ServiceStage.init;
206
+ (0, import_env.loadEnv)({ cwd: this.cwd, envFile: ".env" });
207
+ let pkg = {};
208
+ let pkgPath = "";
209
+ try {
210
+ pkg = require((0, import_path.join)(this.cwd, "package.json"));
211
+ pkgPath = (0, import_path.join)(this.cwd, "package.json");
212
+ } catch (_e) {
213
+ if (this.cwd !== process.cwd()) {
214
+ try {
215
+ pkg = require((0, import_path.join)(process.cwd(), "package.json"));
216
+ pkgPath = (0, import_path.join)(process.cwd(), "package.json");
217
+ } catch (_e2) {
218
+ }
219
+ }
220
+ }
221
+ this.pkg = pkg;
222
+ this.pkgPath = pkgPath || (0, import_path.join)(this.cwd, "package.json");
223
+ const prefix = this.opts.frameworkName || import_constants.DEFAULT_FRAMEWORK_NAME;
224
+ const specifiedEnv = process.env[`${prefix}_ENV`.toUpperCase()];
225
+ const configManager = new import_config.Config({
226
+ cwd: this.cwd,
227
+ env: this.env,
228
+ defaultConfigFiles: this.opts.defaultConfigFiles,
229
+ specifiedEnv
230
+ });
231
+ this.configManager = configManager;
232
+ this.userConfig = configManager.getUserConfig().config;
233
+ this.paths = await this.getPaths();
234
+ const { plugins, presets } = import_plugin.Plugin.getPluginsAndPresets({
235
+ cwd: this.cwd,
236
+ pkg,
237
+ plugins: [require.resolve("./generatePlugin")].concat(
238
+ this.opts.plugins || []
239
+ ),
240
+ presets: [require.resolve("./servicePlugin")].concat(
241
+ this.opts.presets || []
242
+ ),
243
+ userConfig: this.userConfig,
244
+ prefix
245
+ });
246
+ this.stage = import_types.ServiceStage.initPresets;
247
+ const presetPlugins = [];
248
+ while (presets.length) {
249
+ await this.initPreset({
250
+ preset: presets.shift(),
251
+ presets,
252
+ plugins: presetPlugins
253
+ });
254
+ }
255
+ plugins.unshift(...presetPlugins);
256
+ this.stage = import_types.ServiceStage.initPlugins;
257
+ while (plugins.length) {
258
+ await this.initPlugin({ plugin: plugins.shift(), plugins });
259
+ }
260
+ const command = this.commands[name];
261
+ if (!command) {
262
+ this.commandGuessHelper(Object.keys(this.commands), name);
263
+ throw Error(`Invalid command ${import_utils.chalk.red(name)}, it's not registered.`);
264
+ }
265
+ for (const id of Object.keys(this.plugins)) {
266
+ const { config, key } = this.plugins[id];
267
+ if (config.schema) this.configSchemas[key] = config.schema;
268
+ if (config.default !== void 0) {
269
+ this.configDefaults[key] = config.default;
270
+ }
271
+ this.configOnChanges[key] = config.onChange || import_types.ConfigChangeType.reload;
272
+ }
273
+ this.stage = import_types.ServiceStage.resolveConfig;
274
+ const { defaultConfig } = await this.resolveConfig();
275
+ if (this.config.outputPath) {
276
+ this.paths.absOutputPath = (0, import_path.isAbsolute)(this.config.outputPath) ? this.config.outputPath : (0, import_path.join)(this.cwd, this.config.outputPath);
277
+ }
278
+ this.paths = await this.applyPlugins({
279
+ key: "modifyPaths",
280
+ initialValue: this.paths
281
+ });
282
+ const storage = await this.applyPlugins({
283
+ key: "modifyTelemetryStorage",
284
+ initialValue: import_telemetry.noopStorage
285
+ });
286
+ this.telemetry.useStorage(storage);
287
+ this.stage = import_types.ServiceStage.collectAppData;
288
+ this.appData = await this.applyPlugins({
289
+ key: "modifyAppData",
290
+ initialValue: {
291
+ // base
292
+ cwd: this.cwd,
293
+ pkg,
294
+ pkgPath,
295
+ plugins: this.plugins,
296
+ presets,
297
+ name,
298
+ args,
299
+ // config
300
+ userConfig: this.userConfig,
301
+ mainConfigFile: configManager.mainConfigFile,
302
+ config: this.config,
303
+ defaultConfig
304
+ // TODO
305
+ // moduleGraph,
306
+ // routes,
307
+ // npmClient,
308
+ // nodeVersion,
309
+ // gitInfo,
310
+ // gitBranch,
311
+ // debugger info,
312
+ // devPort,
313
+ // devHost,
314
+ // env
315
+ }
316
+ });
317
+ this.stage = import_types.ServiceStage.onCheck;
318
+ await this.applyPlugins({
319
+ key: "onCheck"
320
+ });
321
+ this.stage = import_types.ServiceStage.onStart;
322
+ await this.applyPlugins({
323
+ key: "onStart"
324
+ });
325
+ this.stage = import_types.ServiceStage.runCommand;
326
+ let ret = await command.fn({ args });
327
+ this._profilePlugins();
328
+ return ret;
329
+ }
330
+ async getPaths() {
331
+ const paths = (0, import_path2.getPaths)({
332
+ cwd: this.cwd,
333
+ env: this.env,
334
+ prefix: this.opts.frameworkName || import_constants.DEFAULT_FRAMEWORK_NAME
335
+ });
336
+ return paths;
337
+ }
338
+ async resolveConfig() {
339
+ (0, import_assert.default)(
340
+ this.stage > import_types.ServiceStage.init,
341
+ `Can't generate final config before init stage`
342
+ );
343
+ const resolveMode = this.commands[this.name].configResolveMode;
344
+ const config = await this.applyPlugins({
345
+ key: "modifyConfig",
346
+ // why clone deep?
347
+ // user may change the config in modifyConfig
348
+ // e.g. memo.alias = xxx
349
+ initialValue: import_utils.lodash.cloneDeep(
350
+ resolveMode === "strict" ? this.configManager.getConfig({
351
+ schemas: this.configSchemas
352
+ }).config : this.configManager.getUserConfig().config
353
+ ),
354
+ args: { paths: this.paths }
355
+ });
356
+ const defaultConfig = await this.applyPlugins({
357
+ key: "modifyDefaultConfig",
358
+ // 避免 modifyDefaultConfig 时修改 this.configDefaults
359
+ initialValue: import_utils.lodash.cloneDeep(this.configDefaults)
360
+ });
361
+ this.config = import_utils.lodash.merge(defaultConfig, config);
362
+ return { config, defaultConfig };
363
+ }
364
+ _profilePlugins() {
365
+ if (this.args.profilePlugins) {
366
+ console.log();
367
+ Object.keys(this.plugins).map((id) => {
368
+ const plugin = this.plugins[id];
369
+ const total = totalTime(plugin);
370
+ return {
371
+ id,
372
+ total,
373
+ register: plugin.time.register || 0,
374
+ hooks: plugin.time.hooks
375
+ };
376
+ }).filter((time) => {
377
+ return time.total > (this.args.profilePluginsLimit ?? 10);
378
+ }).sort((a, b) => b.total > a.total ? 1 : -1).forEach((time) => {
379
+ console.log(import_utils.chalk.green("plugin"), time.id, time.total);
380
+ if (this.args.profilePluginsVerbose) {
381
+ console.log(" ", import_utils.chalk.green("register"), time.register);
382
+ console.log(
383
+ " ",
384
+ import_utils.chalk.green("hooks"),
385
+ JSON.stringify(sortHooks(time.hooks))
386
+ );
387
+ }
388
+ });
389
+ }
390
+ function sortHooks(hooks) {
391
+ const ret = {};
392
+ Object.keys(hooks).sort((a, b) => {
393
+ return add(hooks[b]) - add(hooks[a]);
394
+ }).forEach((key) => {
395
+ ret[key] = hooks[key];
396
+ });
397
+ return ret;
398
+ }
399
+ function totalTime(plugin) {
400
+ const time = plugin.time;
401
+ return (time.register || 0) + Object.values(time.hooks).reduce((a, b) => a + add(b), 0);
402
+ }
403
+ function add(nums) {
404
+ return nums.reduce((a, b) => a + b, 0);
405
+ }
406
+ }
407
+ async initPreset(opts) {
408
+ const { presets, plugins } = await this.initPlugin({
409
+ plugin: opts.preset,
410
+ presets: opts.presets,
411
+ plugins: opts.plugins
412
+ });
413
+ opts.presets.unshift(...presets || []);
414
+ opts.plugins.push(...plugins || []);
415
+ }
416
+ async initPlugin(opts) {
417
+ var _a, _b;
418
+ (0, import_assert.default)(
419
+ !this.plugins[opts.plugin.id],
420
+ `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) == null ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`
421
+ );
422
+ this.plugins[opts.plugin.id] = opts.plugin;
423
+ const pluginAPI = new import_pluginAPI.PluginAPI({
424
+ plugin: opts.plugin,
425
+ service: this
426
+ });
427
+ pluginAPI.registerPresets = pluginAPI.registerPresets.bind(
428
+ pluginAPI,
429
+ opts.presets || []
430
+ );
431
+ pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(
432
+ pluginAPI,
433
+ opts.plugins
434
+ );
435
+ const proxyPluginAPI = import_pluginAPI.PluginAPI.proxyPluginAPI({
436
+ service: this,
437
+ pluginAPI,
438
+ serviceProps: [
439
+ "appData",
440
+ "applyPlugins",
441
+ "args",
442
+ "config",
443
+ "cwd",
444
+ "pkg",
445
+ "pkgPath",
446
+ "name",
447
+ "paths",
448
+ "userConfig",
449
+ "env",
450
+ "isPluginEnable"
451
+ ],
452
+ staticProps: {
453
+ ApplyPluginsType: import_types.ApplyPluginsType,
454
+ ConfigChangeType: import_types.ConfigChangeType,
455
+ EnableBy: import_types.EnableBy,
456
+ ServiceStage: import_types.ServiceStage,
457
+ service: this
458
+ }
459
+ });
460
+ let dateStart = /* @__PURE__ */ new Date();
461
+ let ret = await opts.plugin.apply()(proxyPluginAPI);
462
+ opts.plugin.time.register = (/* @__PURE__ */ new Date()).getTime() - dateStart.getTime();
463
+ if (opts.plugin.type === "plugin") {
464
+ (0, import_assert.default)(!ret, `plugin should return nothing`);
465
+ }
466
+ (0, import_assert.default)(
467
+ !this.keyToPluginMap[opts.plugin.key],
468
+ `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) == null ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`
469
+ );
470
+ this.keyToPluginMap[opts.plugin.key] = opts.plugin;
471
+ if (ret == null ? void 0 : ret.presets) {
472
+ ret.presets = ret.presets.map(
473
+ (preset) => new import_plugin.Plugin({
474
+ path: preset,
475
+ type: import_types.PluginType.preset,
476
+ cwd: this.cwd
477
+ })
478
+ );
479
+ }
480
+ if (ret == null ? void 0 : ret.plugins) {
481
+ ret.plugins = ret.plugins.map(
482
+ (plugin) => new import_plugin.Plugin({
483
+ path: plugin,
484
+ type: import_types.PluginType.plugin,
485
+ cwd: this.cwd
486
+ })
487
+ );
488
+ }
489
+ return ret || {};
490
+ }
491
+ isPluginEnable(hook) {
492
+ let plugin;
493
+ if (hook.plugin) {
494
+ plugin = hook.plugin;
495
+ } else {
496
+ plugin = this.keyToPluginMap[hook];
497
+ if (!plugin) return false;
498
+ }
499
+ const { id, key, enableBy } = plugin;
500
+ if (this.skipPluginIds.has(id)) return false;
501
+ if (this.userConfig[key] === false) return false;
502
+ if (this.config[key] === false) return false;
503
+ if (enableBy === import_types.EnableBy.config) {
504
+ return key in this.userConfig || this.config && key in this.config;
505
+ }
506
+ if (typeof enableBy === "function")
507
+ return enableBy({
508
+ userConfig: this.userConfig,
509
+ config: this.config,
510
+ env: this.env
511
+ });
512
+ return true;
513
+ }
514
+ commandGuessHelper(commands, currentCmd) {
515
+ const altCmds = commands.filter((cmd) => {
516
+ return import_utils.fastestLevenshtein.distance(currentCmd, cmd) < currentCmd.length * 0.6 && currentCmd !== cmd;
517
+ });
518
+ const printHelper = altCmds.slice(0, 3).map((cmd) => {
519
+ return ` - ${import_utils.chalk.green(cmd)}`;
520
+ }).join("\n");
521
+ if (altCmds.length) {
522
+ console.log();
523
+ console.log(
524
+ [
525
+ import_utils.chalk.cyan(
526
+ altCmds.length === 1 ? "Did you mean this command ?" : "Did you mean one of these commands ?"
527
+ ),
528
+ printHelper
529
+ ].join("\n")
530
+ );
531
+ console.log();
532
+ }
533
+ }
534
+ };
535
+ // Annotate the CommonJS export names for ESM import in node:
536
+ 0 && (module.exports = {
537
+ Service
538
+ });
@@ -0,0 +1,3 @@
1
+ import { PluginAPI } from './pluginAPI';
2
+ declare const _default: (api: PluginAPI) => void;
3
+ export default _default;
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/service/servicePlugin.ts
20
+ var servicePlugin_exports = {};
21
+ __export(servicePlugin_exports, {
22
+ default: () => servicePlugin_default
23
+ });
24
+ module.exports = __toCommonJS(servicePlugin_exports);
25
+ var servicePlugin_default = (api) => {
26
+ [
27
+ "onCheck",
28
+ "onStart",
29
+ "modifyAppData",
30
+ "modifyConfig",
31
+ "modifyDefaultConfig",
32
+ "modifyPaths",
33
+ "modifyTelemetryStorage"
34
+ ].forEach((name) => {
35
+ api.registerMethod({ name });
36
+ });
37
+ };
@@ -0,0 +1,32 @@
1
+ declare type MetreEvent = {
2
+ name: string;
3
+ timestamp?: number;
4
+ payload: any;
5
+ };
6
+ interface IStorage {
7
+ save(e: MetreEvent): Promise<void>;
8
+ }
9
+ export interface IMetry {
10
+ record(e: MetreEvent): void;
11
+ recordAsync(e: MetreEvent): Promise<boolean>;
12
+ flush(): Promise<void>;
13
+ }
14
+ export declare class Telemetry implements IMetry {
15
+ private queuedEvents;
16
+ private storage;
17
+ constructor();
18
+ prefixWith(prefix: string): IMetry;
19
+ useStorage(s: IStorage): void;
20
+ record(e: MetreEvent): void;
21
+ recordAsync(e: MetreEvent): Promise<boolean>;
22
+ flush(): Promise<void>;
23
+ private scheduleFlush;
24
+ private afterFlush;
25
+ private unFinishedEvents;
26
+ private addTimeStamp;
27
+ }
28
+ declare class NoopStorage implements IStorage {
29
+ save(_e: MetreEvent): Promise<void>;
30
+ }
31
+ export declare const noopStorage: NoopStorage;
32
+ export {};