@hubspot/cli 6.3.0 → 6.4.0-beta.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 (49) hide show
  1. package/bin/cli.js +2 -0
  2. package/commands/doctor.d.ts +8 -0
  3. package/commands/doctor.js +60 -0
  4. package/commands/init.js +20 -7
  5. package/commands/lint.d.ts +4 -1
  6. package/commands/lint.js +11 -2
  7. package/commands/project/installDeps.js +5 -5
  8. package/commands/project/logs.js +1 -1
  9. package/commands/theme/preview.js +38 -20
  10. package/lang/en.lyaml +68 -0
  11. package/lib/DevServerManager.js +2 -5
  12. package/lib/commonOpts.d.ts +3 -2
  13. package/lib/commonOpts.js +2 -2
  14. package/lib/dependencyManagement.d.ts +3 -1
  15. package/lib/dependencyManagement.js +19 -0
  16. package/lib/doctor/Diagnosis.d.ts +27 -0
  17. package/lib/doctor/Diagnosis.js +119 -0
  18. package/lib/doctor/DiagnosticInfoBuilder.d.ts +61 -0
  19. package/lib/doctor/DiagnosticInfoBuilder.js +158 -0
  20. package/lib/doctor/Doctor.d.ts +21 -0
  21. package/lib/doctor/Doctor.js +328 -0
  22. package/lib/errorHandlers/index.d.ts +14 -1
  23. package/lib/errorHandlers/index.js +43 -50
  24. package/lib/errorHandlers/suppressError.d.ts +2 -1
  25. package/lib/errorHandlers/suppressError.js +32 -37
  26. package/lib/interpolation.d.ts +3 -0
  27. package/lib/interpolation.js +4 -3
  28. package/lib/links.d.ts +9 -0
  29. package/lib/links.js +99 -97
  30. package/lib/projects.d.ts +4 -1
  31. package/lib/projects.js +5 -3
  32. package/lib/ui/SpinniesManager.d.ts +39 -1
  33. package/lib/ui/SpinniesManager.js +66 -35
  34. package/lib/ui/git.d.ts +1 -1
  35. package/lib/ui/git.js +17 -17
  36. package/lib/ui/index.d.ts +16 -1
  37. package/lib/ui/index.js +87 -114
  38. package/lib/ui/serverlessFunctionLogs.js +28 -19
  39. package/lib/ui/spinniesUtils.d.ts +31 -0
  40. package/lib/ui/spinniesUtils.js +45 -31
  41. package/lib/ui/supportHyperlinks.d.ts +6 -0
  42. package/lib/ui/supportHyperlinks.js +10 -10
  43. package/lib/ui/supportsColor.d.ts +16 -0
  44. package/lib/ui/supportsColor.js +19 -17
  45. package/lib/ui/table.d.ts +3 -1
  46. package/lib/ui/table.js +17 -11
  47. package/lib/usageTracking.d.ts +2 -1
  48. package/lib/usageTracking.js +2 -0
  49. package/package.json +10 -5
@@ -0,0 +1,61 @@
1
+ import { getProjectConfig } from '../projects';
2
+ import { Environment } from '@hubspot/local-dev-lib/types/Config';
3
+ import { AccessToken, AccountType, AuthType } from '@hubspot/local-dev-lib/types/Accounts';
4
+ import { Project } from '@hubspot/local-dev-lib/types/Project';
5
+ import process from 'process';
6
+ export type ProjectConfig = Awaited<ReturnType<typeof getProjectConfig>>;
7
+ declare const hubspotCli = "@hubspot/cli";
8
+ interface FilesInfo {
9
+ files: string[];
10
+ configFiles: string[];
11
+ packageFiles: string[];
12
+ packageLockFiles: string[];
13
+ envFiles: string[];
14
+ jsonFiles: string[];
15
+ }
16
+ export interface DiagnosticInfo extends FilesInfo {
17
+ path?: string;
18
+ versions: {
19
+ [hubspotCli]: string;
20
+ node: string;
21
+ npm: string | null;
22
+ };
23
+ config: string | null;
24
+ project: {
25
+ details?: Project;
26
+ config?: ProjectConfig;
27
+ };
28
+ arch: typeof process.arch;
29
+ platform: typeof process.platform;
30
+ account: {
31
+ name?: string;
32
+ accountId?: number | null;
33
+ scopeGroups?: AccessToken['scopeGroups'];
34
+ enabledFeatures?: AccessToken['enabledFeatures'];
35
+ accountType?: AccessToken['accountType'];
36
+ authType?: AuthType;
37
+ };
38
+ diagnosis?: string;
39
+ errorCount?: number;
40
+ warningCount?: number;
41
+ }
42
+ export declare class DiagnosticInfoBuilder {
43
+ accountId: number | null;
44
+ readonly env?: Environment;
45
+ readonly authType?: AuthType;
46
+ readonly accountType?: AccountType;
47
+ readonly personalAccessKey?: string;
48
+ private _projectConfig?;
49
+ private accessToken?;
50
+ private projectDetails?;
51
+ private files?;
52
+ readonly processInfo: NodeJS.Process;
53
+ constructor(processInfo: NodeJS.Process);
54
+ generateDiagnosticInfo(): Promise<DiagnosticInfo>;
55
+ private fetchProjectDetails;
56
+ fetchAccessToken(): Promise<AccessToken | undefined>;
57
+ private fetchProjectFilenames;
58
+ private getNpmVersion;
59
+ private generateFilesArrays;
60
+ }
61
+ export {};
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DiagnosticInfoBuilder = void 0;
7
+ const projects_1 = require("../projects");
8
+ const projects_2 = require("@hubspot/local-dev-lib/api/projects");
9
+ const path_1 = __importDefault(require("path"));
10
+ const package_json_1 = __importDefault(require("../../package.json"));
11
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
12
+ const config_1 = require("@hubspot/local-dev-lib/config");
13
+ const config_2 = require("@hubspot/local-dev-lib/config");
14
+ const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
15
+ const fs_1 = require("@hubspot/local-dev-lib/fs");
16
+ const util_1 = __importDefault(require("util"));
17
+ const child_process_1 = require("child_process");
18
+ // This needs to be hardcoded since we are using it in the TS type
19
+ const hubspotCli = '@hubspot/cli';
20
+ const configFiles = [
21
+ 'serverless.json',
22
+ 'hsproject.json',
23
+ 'app.json',
24
+ 'public-app.json',
25
+ 'theme.json',
26
+ 'cms-assets.json',
27
+ ];
28
+ class DiagnosticInfoBuilder {
29
+ accountId;
30
+ env;
31
+ authType;
32
+ accountType;
33
+ personalAccessKey;
34
+ _projectConfig;
35
+ accessToken;
36
+ projectDetails;
37
+ files;
38
+ processInfo;
39
+ constructor(processInfo) {
40
+ this.accountId = (0, config_1.getAccountId)();
41
+ const accountConfig = (0, config_2.getAccountConfig)(this.accountId);
42
+ this.env = accountConfig?.env;
43
+ this.authType = accountConfig?.authType;
44
+ this.accountType = accountConfig?.accountType;
45
+ this.personalAccessKey = accountConfig?.personalAccessKey;
46
+ this.processInfo = processInfo;
47
+ }
48
+ async generateDiagnosticInfo() {
49
+ // @ts-expect-error getProjectConfig not typed yet
50
+ this._projectConfig = await (0, projects_1.getProjectConfig)();
51
+ if (this._projectConfig?.projectConfig) {
52
+ await this.fetchProjectDetails();
53
+ await this.fetchAccessToken();
54
+ await this.fetchProjectFilenames();
55
+ }
56
+ const { platform, arch, versions: { node }, mainModule, } = this.processInfo;
57
+ return {
58
+ platform,
59
+ arch,
60
+ path: mainModule?.path,
61
+ config: (0, config_2.getConfigPath)(),
62
+ versions: {
63
+ [hubspotCli]: package_json_1.default.version,
64
+ node,
65
+ npm: await this.getNpmVersion(),
66
+ },
67
+ account: {
68
+ accountId: this.accountId,
69
+ accountType: this.accountType,
70
+ authType: this.authType,
71
+ name: this.accessToken?.hubName,
72
+ scopeGroups: this.accessToken?.scopeGroups,
73
+ enabledFeatures: this.accessToken?.enabledFeatures,
74
+ },
75
+ project: {
76
+ config: this._projectConfig,
77
+ details: this.projectDetails,
78
+ },
79
+ ...this.generateFilesArrays(),
80
+ files: this.files || [],
81
+ };
82
+ }
83
+ async fetchProjectDetails() {
84
+ try {
85
+ const { data } = await (0, projects_2.fetchProject)(this.accountId, this._projectConfig?.projectConfig?.name);
86
+ this.projectDetails = data;
87
+ }
88
+ catch (e) {
89
+ logger_1.logger.debug(e);
90
+ }
91
+ }
92
+ async fetchAccessToken() {
93
+ try {
94
+ this.accessToken = await (0, personalAccessKey_1.getAccessToken)(this.personalAccessKey, this.env, this.accountId);
95
+ }
96
+ catch (e) {
97
+ logger_1.logger.debug(e);
98
+ }
99
+ return this.accessToken;
100
+ }
101
+ async fetchProjectFilenames() {
102
+ try {
103
+ this.files = (await (0, fs_1.walk)(this._projectConfig?.projectDir))
104
+ .filter(file => !path_1.default.dirname(file).includes('node_modules'))
105
+ .map(filename => path_1.default.relative(this._projectConfig?.projectDir, filename));
106
+ }
107
+ catch (e) {
108
+ logger_1.logger.debug(e);
109
+ }
110
+ }
111
+ async getNpmVersion() {
112
+ const exec = util_1.default.promisify(child_process_1.exec);
113
+ try {
114
+ const { stdout } = await exec('npm --version');
115
+ return stdout.toString().trim();
116
+ }
117
+ catch (e) {
118
+ logger_1.logger.debug(e);
119
+ return null;
120
+ }
121
+ }
122
+ generateFilesArrays() {
123
+ const output = {
124
+ files: this.files || [],
125
+ configFiles: [],
126
+ packageFiles: [],
127
+ packageLockFiles: [],
128
+ envFiles: [],
129
+ jsonFiles: [],
130
+ };
131
+ if (!this.files) {
132
+ return output;
133
+ }
134
+ return this.files.reduce((acc, file) => {
135
+ const { base } = path_1.default.parse(file);
136
+ if (base === 'package.json') {
137
+ acc.packageFiles.push(file);
138
+ }
139
+ else if (configFiles.includes(base)) {
140
+ acc.configFiles.push(file);
141
+ if (file.endsWith('.json')) {
142
+ acc.jsonFiles.push(file);
143
+ }
144
+ }
145
+ else if (base === 'package-lock.json') {
146
+ acc.packageLockFiles.push(file);
147
+ }
148
+ else if (file.endsWith('.env')) {
149
+ acc.envFiles.push(file);
150
+ }
151
+ else if (file.endsWith('.json')) {
152
+ acc.jsonFiles.push(file);
153
+ }
154
+ return acc;
155
+ }, output);
156
+ }
157
+ }
158
+ exports.DiagnosticInfoBuilder = DiagnosticInfoBuilder;
@@ -0,0 +1,21 @@
1
+ import { DiagnosticInfoBuilder, DiagnosticInfo } from './DiagnosticInfoBuilder';
2
+ export declare class Doctor {
3
+ accountId: number | null;
4
+ private diagnosis?;
5
+ private projectConfig?;
6
+ private diagnosticInfo?;
7
+ readonly diagnosticInfoBuilder: DiagnosticInfoBuilder;
8
+ constructor(diagnosticInfoBuilder?: DiagnosticInfoBuilder);
9
+ diagnose(): Promise<DiagnosticInfo>;
10
+ private performCliChecks;
11
+ private performProjectChecks;
12
+ private performCliConfigChecks;
13
+ private checkIfAccessTokenValid;
14
+ private checkIfNodeIsInstalled;
15
+ private checkIfNpmIsInstalled;
16
+ private checkCLIVersion;
17
+ private checkIfNpmInstallRequired;
18
+ private isValidJsonFile;
19
+ private checkProjectConfigJsonFiles;
20
+ private checkIfPortsAreAvailable;
21
+ }
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Doctor = void 0;
7
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
8
+ const config_1 = require("@hubspot/local-dev-lib/config");
9
+ const SpinniesManager_1 = __importDefault(require("../ui/SpinniesManager"));
10
+ const dependencyManagement_1 = require("../dependencyManagement");
11
+ const util_1 = __importDefault(require("util"));
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const Diagnosis_1 = require("./Diagnosis");
15
+ const DiagnosticInfoBuilder_1 = require("./DiagnosticInfoBuilder");
16
+ const portManager_1 = require("@hubspot/local-dev-lib/portManager");
17
+ const ports_1 = require("@hubspot/local-dev-lib/constants/ports");
18
+ const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
19
+ const index_1 = require("@hubspot/local-dev-lib/errors/index");
20
+ const urls_1 = require("@hubspot/local-dev-lib/urls");
21
+ const ui_1 = require("../ui");
22
+ const package_json_1 = __importDefault(require("../../package.json"));
23
+ const { i18n } = require('../lang');
24
+ const { uiLink } = require('../ui');
25
+ const minMajorNodeVersion = 18;
26
+ const i18nKey = `lib.doctor`;
27
+ class Doctor {
28
+ accountId;
29
+ diagnosis;
30
+ projectConfig;
31
+ diagnosticInfo;
32
+ diagnosticInfoBuilder;
33
+ constructor(diagnosticInfoBuilder = new DiagnosticInfoBuilder_1.DiagnosticInfoBuilder(process)) {
34
+ SpinniesManager_1.default.init();
35
+ this.accountId = (0, config_1.getAccountId)();
36
+ this.diagnosticInfoBuilder = diagnosticInfoBuilder;
37
+ }
38
+ async diagnose() {
39
+ SpinniesManager_1.default.add('runningDiagnostics', {
40
+ text: i18n(`${i18nKey}.runningDiagnostics`),
41
+ });
42
+ this.diagnosticInfo = await this.diagnosticInfoBuilder.generateDiagnosticInfo();
43
+ this.projectConfig = this.diagnosticInfo?.project.config;
44
+ this.diagnosis = new Diagnosis_1.Diagnosis({
45
+ diagnosticInfo: this.diagnosticInfo,
46
+ accountId: this.accountId,
47
+ });
48
+ await Promise.all([
49
+ ...this.performCliChecks(),
50
+ ...this.performCliConfigChecks(),
51
+ ...(this.projectConfig?.projectConfig ? this.performProjectChecks() : []),
52
+ ]);
53
+ SpinniesManager_1.default.succeed('runningDiagnostics', {
54
+ text: i18n(`${i18nKey}.diagnosticsComplete`),
55
+ succeedColor: 'white',
56
+ });
57
+ this.diagnosticInfo.diagnosis = this.diagnosis.toString();
58
+ this.diagnosticInfo.errorCount = this.diagnosis.getErrorCount();
59
+ this.diagnosticInfo.warningCount = this.diagnosis.getWarningCount();
60
+ return this.diagnosticInfo;
61
+ }
62
+ performCliChecks() {
63
+ return [
64
+ this.checkIfNodeIsInstalled(),
65
+ this.checkIfNpmIsInstalled(),
66
+ this.checkCLIVersion(),
67
+ ];
68
+ }
69
+ performProjectChecks() {
70
+ return [
71
+ this.checkIfNpmInstallRequired(),
72
+ this.checkProjectConfigJsonFiles(),
73
+ this.checkIfPortsAreAvailable(),
74
+ ];
75
+ }
76
+ performCliConfigChecks() {
77
+ if (!this.diagnosticInfo?.config) {
78
+ this.diagnosis?.addCLIConfigSection({
79
+ type: 'error',
80
+ message: i18n(`${i18nKey}.diagnosis.cliConfig.noConfigFile`),
81
+ secondaryMessaging: i18n(`${i18nKey}.diagnosis.cliConfig.noConfigFileSecondary`, {
82
+ command: (0, ui_1.uiCommandReference)('hs init'),
83
+ }),
84
+ });
85
+ return [];
86
+ }
87
+ return [this.checkIfAccessTokenValid()];
88
+ }
89
+ async checkIfAccessTokenValid() {
90
+ const localI18nKey = `${i18nKey}.accountChecks`;
91
+ try {
92
+ await (0, personalAccessKey_1.accessTokenForPersonalAccessKey)(this.accountId, true);
93
+ this.diagnosis?.addCLIConfigSection({
94
+ type: 'success',
95
+ message: i18n(`${localI18nKey}.active`),
96
+ });
97
+ this.diagnosis?.addCLIConfigSection({
98
+ type: 'success',
99
+ message: i18n(`${localI18nKey}.pak.valid`, {
100
+ link: uiLink(i18n(`${localI18nKey}.pak.viewScopes`), `${(0, urls_1.getHubSpotWebsiteOrigin)(this.diagnosticInfoBuilder?.env || 'PROD')}/personal-access-key/${this.diagnosticInfo?.account.accountId}`),
101
+ }),
102
+ });
103
+ }
104
+ catch (error) {
105
+ const portalNotActive = (0, index_1.isSpecifiedError)(error, {
106
+ statusCode: 401,
107
+ category: 'INVALID_AUTHENTICATION',
108
+ subCategory: 'LocalDevAuthErrorType.PORTAL_NOT_ACTIVE',
109
+ }) ||
110
+ (0, index_1.isSpecifiedError)(error, {
111
+ statusCode: 404,
112
+ category: 'INVALID_AUTHENTICATION',
113
+ subCategory: 'LocalDevAuthErrorType.INVALID_PORTAL_ID',
114
+ });
115
+ if (portalNotActive) {
116
+ this.diagnosis?.addCLIConfigSection({
117
+ type: 'error',
118
+ message: i18n(`${localI18nKey}.inactive`),
119
+ secondaryMessaging: i18n(`${localI18nKey}.inactiveSecondary`, {
120
+ command: (0, ui_1.uiCommandReference)(`hs accounts clean`),
121
+ }),
122
+ });
123
+ }
124
+ else if ((0, index_1.isSpecifiedError)(error, {
125
+ statusCode: 401,
126
+ category: 'INVALID_AUTHENTICATION',
127
+ subCategory: 'LocalDevAuthErrorType.FAILED_TO_SIGN_REFRESH_TOKEN_DECODE',
128
+ })) {
129
+ this.diagnosis?.addCLIConfigSection({
130
+ type: 'success',
131
+ message: i18n(`${localI18nKey}.active`),
132
+ });
133
+ this.diagnosis?.addCLIConfigSection({
134
+ type: 'error',
135
+ message: i18n(`${localI18nKey}.pak.invalid`),
136
+ secondaryMessaging: i18n(`${localI18nKey}.pak.invalidSecondary`, {
137
+ command: (0, ui_1.uiCommandReference)(`hs auth`),
138
+ }),
139
+ });
140
+ }
141
+ else {
142
+ this.diagnosis?.addCLIConfigSection({
143
+ type: 'error',
144
+ message: i18n(`${localI18nKey}.unableToDetermine`),
145
+ });
146
+ }
147
+ }
148
+ }
149
+ async checkIfNodeIsInstalled() {
150
+ const localI18nKey = `${i18nKey}.nodeChecks`;
151
+ if (!this.diagnosticInfo?.versions.node) {
152
+ return this.diagnosis?.addCliSection({
153
+ type: 'error',
154
+ message: i18n(`${localI18nKey}.unableToDetermine`),
155
+ });
156
+ }
157
+ const nodeVersion = this.diagnosticInfo?.versions.node?.split('.');
158
+ const currentNodeMajor = nodeVersion?.[0];
159
+ if (!currentNodeMajor || parseInt(currentNodeMajor) < minMajorNodeVersion) {
160
+ return this.diagnosis?.addCliSection({
161
+ type: 'warning',
162
+ message: i18n(`${localI18nKey}.minimumNotMet`, {
163
+ nodeVersion: this.diagnosticInfo?.versions.node,
164
+ }),
165
+ });
166
+ }
167
+ this.diagnosis?.addCliSection({
168
+ type: 'success',
169
+ message: i18n(`${localI18nKey}.success`, {
170
+ nodeVersion: this.diagnosticInfo?.versions.node,
171
+ }),
172
+ });
173
+ }
174
+ async checkIfNpmIsInstalled() {
175
+ const localI18nKey = `${i18nKey}.npmChecks`;
176
+ const npmVersion = this.diagnosticInfo?.versions?.npm;
177
+ if (!npmVersion) {
178
+ return this.diagnosis?.addCliSection({
179
+ type: 'error',
180
+ message: i18n(`${localI18nKey}.notInstalled`),
181
+ });
182
+ }
183
+ this.diagnosis?.addCliSection({
184
+ type: 'success',
185
+ message: i18n(`${localI18nKey}.installed`, {
186
+ npmVersion,
187
+ }),
188
+ });
189
+ }
190
+ async checkCLIVersion() {
191
+ let latestCLIVersion;
192
+ try {
193
+ latestCLIVersion = await (0, dependencyManagement_1.getLatestCliVersion)();
194
+ }
195
+ catch (e) {
196
+ return this.diagnosis?.addCliSection({
197
+ type: 'error',
198
+ message: i18n(`${i18nKey}.hsChecks.unableToDetermine`),
199
+ secondaryMessaging: i18n(`${i18nKey}.hsChecks.unableToDetermineSecondary`, {
200
+ command: (0, ui_1.uiCommandReference)(`hs --version`),
201
+ link: uiLink(i18n(`${i18nKey}.hsChecks.unableToDetermineSecondaryLink`), `https://www.npmjs.com/package/${package_json_1.default.name}?activeTab=versions`),
202
+ }),
203
+ });
204
+ }
205
+ if (latestCLIVersion !== package_json_1.default.version) {
206
+ this.diagnosis?.addCliSection({
207
+ type: 'warning',
208
+ message: i18n(`${i18nKey}.hsChecks.notLatest`, {
209
+ hsVersion: package_json_1.default.version,
210
+ }),
211
+ secondaryMessaging: i18n(`${i18nKey}.hsChecks.notLatestSecondary`, {
212
+ hsVersion: package_json_1.default.version,
213
+ command: (0, ui_1.uiCommandReference)(`npm install -g ${package_json_1.default.name}`),
214
+ }),
215
+ });
216
+ }
217
+ else {
218
+ this.diagnosis?.addCliSection({
219
+ type: 'success',
220
+ message: i18n(`${i18nKey}.hsChecks.latest`, {
221
+ hsVersion: latestCLIVersion,
222
+ }),
223
+ });
224
+ }
225
+ }
226
+ async checkIfNpmInstallRequired() {
227
+ let foundError = false;
228
+ const localI18nKey = `${i18nKey}.projectDependenciesChecks`;
229
+ for (const packageFile of this.diagnosticInfo?.packageFiles || []) {
230
+ const packageDirName = path_1.default.dirname(packageFile);
231
+ try {
232
+ const needsInstall = await (0, dependencyManagement_1.hasMissingPackages)(path_1.default.join(this.projectConfig?.projectDir, packageDirName));
233
+ if (needsInstall) {
234
+ foundError = true;
235
+ this.diagnosis?.addProjectSection({
236
+ type: 'warning',
237
+ message: i18n(`${localI18nKey}.missingDependencies`, {
238
+ dir: packageDirName,
239
+ }),
240
+ secondaryMessaging: i18n(`${localI18nKey}.missingDependenciesSecondary`, {
241
+ command: (0, ui_1.uiCommandReference)('hs project install-deps'),
242
+ }),
243
+ });
244
+ }
245
+ }
246
+ catch (e) {
247
+ foundError = true;
248
+ if (!(await this.isValidJsonFile(packageFile))) {
249
+ this.diagnosis?.addProjectSection({
250
+ type: 'error',
251
+ message: i18n(`${i18nKey}.files.invalidJson`, {
252
+ filename: packageFile,
253
+ }),
254
+ });
255
+ }
256
+ else {
257
+ this.diagnosis?.addProjectSection({
258
+ type: 'error',
259
+ message: i18n(`${localI18nKey}.unableToDetermine`, {
260
+ dir: packageDirName,
261
+ }),
262
+ });
263
+ }
264
+ logger_1.logger.debug(e);
265
+ }
266
+ }
267
+ if (!foundError) {
268
+ this.diagnosis?.addProjectSection({
269
+ type: 'success',
270
+ message: i18n(`${localI18nKey}.success`),
271
+ });
272
+ }
273
+ }
274
+ async isValidJsonFile(filename) {
275
+ try {
276
+ const readFile = util_1.default.promisify(fs_1.default.readFile);
277
+ const fileContents = await readFile(filename);
278
+ JSON.parse(fileContents.toString());
279
+ }
280
+ catch (e) {
281
+ return false;
282
+ }
283
+ return true;
284
+ }
285
+ async checkProjectConfigJsonFiles() {
286
+ let foundError = false;
287
+ for (const jsonFile of this.diagnosticInfo?.jsonFiles || []) {
288
+ const fileToCheck = path_1.default.join(this.projectConfig?.projectDir, jsonFile);
289
+ if (!(await this.isValidJsonFile(fileToCheck))) {
290
+ foundError = true;
291
+ this.diagnosis?.addProjectSection({
292
+ type: 'error',
293
+ message: i18n(`${i18nKey}.files.invalidJson`, {
294
+ filename: jsonFile,
295
+ }),
296
+ });
297
+ }
298
+ }
299
+ if (!foundError) {
300
+ this.diagnosis?.addProjectSection({
301
+ type: 'success',
302
+ message: i18n(`${i18nKey}.files.validJson`),
303
+ });
304
+ }
305
+ }
306
+ async checkIfPortsAreAvailable() {
307
+ const localI18nKey = `${i18nKey}.port`;
308
+ if (await (0, portManager_1.isPortManagerPortAvailable)()) {
309
+ this.diagnosis?.addProjectSection({
310
+ type: 'success',
311
+ message: i18n(`${localI18nKey}.available`, {
312
+ port: ports_1.PORT_MANAGER_SERVER_PORT,
313
+ }),
314
+ });
315
+ return;
316
+ }
317
+ this.diagnosis?.addProjectSection({
318
+ type: 'warning',
319
+ message: i18n(`${localI18nKey}.inUse`, {
320
+ port: ports_1.PORT_MANAGER_SERVER_PORT,
321
+ }),
322
+ secondaryMessaging: i18n(`${localI18nKey}.inUseSecondary`, {
323
+ command: (0, ui_1.uiCommandReference)('hs project dev'),
324
+ }),
325
+ });
326
+ }
327
+ }
328
+ exports.Doctor = Doctor;
@@ -1 +1,14 @@
1
- export {};
1
+ export declare function logError(error: unknown, context?: ApiErrorContext): void;
2
+ export declare function debugError(error: unknown, context?: ApiErrorContext): void;
3
+ export declare class ApiErrorContext {
4
+ accountId?: number;
5
+ request?: string;
6
+ payload?: string;
7
+ projectName?: string;
8
+ constructor(props?: {
9
+ accountId?: number;
10
+ request?: string;
11
+ payload?: string;
12
+ projectName?: string;
13
+ });
14
+ }