@shuvi/service 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
- import { Telemetry } from '@shuvi/telemetry';
2
- import { IPluginContext } from '../core';
1
+ import { IPluginContext, Telemetry } from '../core';
3
2
  export declare const analysis: ({ context, telemetry }: {
4
3
  context: IPluginContext;
5
4
  telemetry: Telemetry;
package/lib/core/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Telemetry as TelemetryImpl, RecordObject, TelemetryEvent } from '@shuvi/telemetry';
1
2
  import { FileOption } from '../project';
2
3
  import { Bundler } from '../bundler';
3
4
  import { ServerPluginInstance } from '../server';
@@ -12,12 +13,16 @@ interface IApiOPtions {
12
13
  plugins?: IPluginConfig[];
13
14
  presets?: IPresetConfig[];
14
15
  normalizePlatformConfig?: (rawConfig: ShuviConfig) => ShuviConfig;
16
+ telemetry?: TelemetryImpl;
15
17
  }
16
18
  interface ServerConfigs {
17
19
  serverPlugins: ServerPluginInstance[];
18
20
  getMiddlewares: IPlatformContent['getMiddlewares'];
19
21
  getMiddlewaresBeforeDevMiddlewares: IPlatformContent['getMiddlewaresBeforeDevMiddlewares'];
20
22
  }
23
+ export interface Telemetry {
24
+ record(events: TelemetryEvent | TelemetryEvent[]): Promise<RecordObject>;
25
+ }
21
26
  declare class Api {
22
27
  private _inited;
23
28
  private _cwd;
@@ -33,6 +38,8 @@ declare class Api {
33
38
  private _config;
34
39
  private _plugins;
35
40
  private _presets;
41
+ private _telemetryImpl?;
42
+ private _telemetry;
36
43
  private _platform?;
37
44
  private _normalizePlatformConfig?;
38
45
  private _serverConfigs;
@@ -41,12 +48,13 @@ declare class Api {
41
48
  private _pluginContext;
42
49
  /** will be included by @shuvi/swc-loader */
43
50
  private _runtimePluginDirs;
44
- constructor({ cwd, mode, config, configFile, presets, plugins, phase, platform, normalizePlatformConfig }: IApiOPtions);
51
+ constructor({ cwd, mode, config, configFile, presets, plugins, phase, platform, normalizePlatformConfig, telemetry }: IApiOPtions);
45
52
  get cwd(): string;
46
53
  get mode(): IServiceMode;
47
54
  get pluginManager(): import("@shuvi/hook/lib/hookGroup").HookManager<import("./plugin").PluginHooks, IPluginContext>;
48
55
  get pluginContext(): IPluginContext;
49
56
  get serverConfigs(): ServerConfigs;
57
+ get telemetry(): Telemetry;
50
58
  init(): Promise<void>;
51
59
  getBundler(): Promise<Bundler>;
52
60
  get assetPublicPath(): string;
package/lib/core/api.js CHANGED
@@ -55,7 +55,7 @@ const webpack_watch_wait_for_file_builder_plugin_1 = __importDefault(require("..
55
55
  const config_2 = require("../config");
56
56
  const ServiceModes = ['development', 'production'];
57
57
  class Api {
58
- constructor({ cwd, mode, config, configFile, presets, plugins, phase, platform, normalizePlatformConfig }) {
58
+ constructor({ cwd, mode, config, configFile, presets, plugins, phase, platform, normalizePlatformConfig, telemetry }) {
59
59
  this._inited = false;
60
60
  this._plugins = [];
61
61
  this._presets = [];
@@ -70,6 +70,7 @@ class Api {
70
70
  this._customConfig = config || {};
71
71
  this._customPresets = presets || [];
72
72
  this._customPlugins = plugins || [];
73
+ this._telemetryImpl = telemetry;
73
74
  this._pluginManager = (0, plugin_1.getManager)();
74
75
  this._pluginManager.clear();
75
76
  this._projectBuilder = new project_1.ProjectBuilder();
@@ -90,6 +91,22 @@ class Api {
90
91
  get serverConfigs() {
91
92
  return this._serverConfigs;
92
93
  }
94
+ get telemetry() {
95
+ if (!this._telemetry) {
96
+ this._telemetry = {
97
+ record: (events) => {
98
+ if (!this._telemetryImpl) {
99
+ return Promise.resolve({
100
+ isFulfilled: true,
101
+ isRejected: true
102
+ });
103
+ }
104
+ return this._telemetryImpl.record(events);
105
+ }
106
+ };
107
+ }
108
+ return this._telemetry;
109
+ }
93
110
  init() {
94
111
  return __awaiter(this, void 0, void 0, function* () {
95
112
  if (this._inited) {
@@ -373,7 +390,8 @@ function getApi(options = {}) {
373
390
  platform: options.platform,
374
391
  presets: options.presets,
375
392
  plugins: options.plugins,
376
- normalizePlatformConfig: options.normalizePlatformConfig
393
+ normalizePlatformConfig: options.normalizePlatformConfig,
394
+ telemetry: options.telemetry
377
395
  });
378
396
  try {
379
397
  yield api.init();
@@ -1,4 +1,4 @@
1
- export type { Api } from './api';
1
+ export type { Api, Telemetry } from './api';
2
2
  export { getApi } from './api';
3
3
  export { resolvePlugin } from './getPlugins';
4
4
  export * from './apiTypes';
package/lib/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { Bundler } from './bundler';
4
4
  export { ProjectBuilder } from './project';
5
5
  export { analysis } from './analysis';
6
6
  export { IShuviServer, ShuviRequest, ShuviResponse, IServerPluginContext, ShuviRequestHandler, ServerPluginConstructor, ServerPluginInstance, IServerMiddleware, createShuviServer, createServerPlugin, createServerPluginBefore, createServerPluginAfter } from './server';
7
- export { Api, IPaths, ShuviConfig, IServicePhase, IServiceMode, IPluginConfig, IPresetConfig, PresetFunction, IPresetContent, NormalizedShuviConfig, IPluginContext, IPlatform, IPlatformContent, CorePluginConstructor, CorePluginInstance, getApi, createPlugin, createPluginBefore, createPluginAfter, ResolvedPlugin } from './core';
7
+ export { Api, Telemetry, IPaths, ShuviConfig, IServicePhase, IServiceMode, IPluginConfig, IPresetConfig, PresetFunction, IPresetContent, NormalizedShuviConfig, IPluginContext, IPlatform, IPlatformContent, CorePluginConstructor, CorePluginInstance, getApi, createPlugin, createPluginBefore, createPluginAfter, ResolvedPlugin } from './core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/service",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -29,14 +29,14 @@
29
29
  "@babel/generator": "7.14.5",
30
30
  "@babel/parser": "7.14.7",
31
31
  "@babel/traverse": "7.14.7",
32
- "@shuvi/hook": "1.0.5",
33
- "@shuvi/router": "1.0.5",
34
- "@shuvi/runtime": "1.0.5",
35
- "@shuvi/shared": "1.0.5",
36
- "@shuvi/toolpack": "1.0.5",
37
- "@shuvi/utils": "1.0.5",
38
- "@shuvi/error-overlay": "1.0.5",
39
- "@shuvi/telemetry": "1.0.5",
32
+ "@shuvi/hook": "1.0.7",
33
+ "@shuvi/router": "1.0.7",
34
+ "@shuvi/runtime": "1.0.7",
35
+ "@shuvi/shared": "1.0.7",
36
+ "@shuvi/toolpack": "1.0.7",
37
+ "@shuvi/utils": "1.0.7",
38
+ "@shuvi/error-overlay": "1.0.7",
39
+ "@shuvi/telemetry": "1.0.7",
40
40
  "commander": "5.1.0",
41
41
  "comment-json": "4.2.2",
42
42
  "cross-spawn": "7.0.3",