start-slicemachine 0.12.60-alpha.xru-prevent-sentry-errors.1 → 0.12.60-alpha.xru-prevent-sentry-errors-2.1
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/dist/StartSliceMachineProcess.cjs +0 -8
- package/dist/StartSliceMachineProcess.cjs.map +1 -1
- package/dist/StartSliceMachineProcess.js +0 -8
- package/dist/StartSliceMachineProcess.js.map +1 -1
- package/dist/lib/sentryErrorHandlers.cjs +10 -5
- package/dist/lib/sentryErrorHandlers.cjs.map +1 -1
- package/dist/lib/sentryErrorHandlers.js +10 -5
- package/dist/lib/sentryErrorHandlers.js.map +1 -1
- package/dist/packages/start-slicemachine/package.json.cjs +1 -1
- package/dist/packages/start-slicemachine/package.json.js +1 -1
- package/package.json +2 -2
- package/src/StartSliceMachineProcess.ts +0 -12
- package/src/lib/sentryErrorHandlers.ts +17 -6
|
@@ -73,14 +73,6 @@ class StartSliceMachineProcess {
|
|
|
73
73
|
sliceMachineManager: this._sliceMachineManager
|
|
74
74
|
});
|
|
75
75
|
const server = app.listen(this.port);
|
|
76
|
-
server.on("error", (error) => {
|
|
77
|
-
if (error.code === "EADDRINUSE") {
|
|
78
|
-
console.error(`Error starting Slice Machine: Port ${this.port} is already in use. Please try a different port.`);
|
|
79
|
-
} else {
|
|
80
|
-
console.error("Error starting Slice Machine:", error);
|
|
81
|
-
}
|
|
82
|
-
process.exit(1);
|
|
83
|
-
});
|
|
84
76
|
const address = server.address();
|
|
85
77
|
const url = `http://localhost:${address.port}`;
|
|
86
78
|
if (this.open) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StartSliceMachineProcess.cjs","sources":["../../src/StartSliceMachineProcess.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport type { AddressInfo } from \"node:net\";\nimport chalk from \"chalk\";\nimport open from \"open\";\nimport os from \"node:os\";\n\nimport {\n\tPrismicUserProfile,\n\tSliceMachineManager,\n\tcreateSliceMachineManager,\n} from \"@slicemachine/manager\";\n\nimport { createSliceMachineExpressApp } from \"./lib/createSliceMachineExpressApp\";\nimport { setupSentry } from \"./lib/setupSentry\";\nimport { migrateSMJSON } from \"./legacyMigrations/migrateSMJSON\";\nimport { migrateAssets } from \"./legacyMigrations/migrateAssets\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"./constants\";\nimport { safelyExecute } from \"./lib/safelyExecute\";\n\nconst DEFAULT_SERVER_PORT = 9999;\n\ntype CreateStartSliceMachineProcessArgs = ConstructorParameters<\n\ttypeof StartSliceMachineProcess\n>;\n\nexport const createStartSliceMachineProcess = (\n\t...args: CreateStartSliceMachineProcessArgs\n): StartSliceMachineProcess => {\n\treturn new StartSliceMachineProcess(...args);\n};\n\nexport type StartSliceMachineProcessConstructorArgs = {\n\topen: boolean;\n\tport?: number;\n};\n\n/**\n * Manages the process that runs Slice Machine's server.\n */\nexport class StartSliceMachineProcess {\n\t/**\n\t * Determines if Slice Machine should automatically be opened once the server\n\t * starts.\n\t *\n\t * @defaultValue `false`\n\t */\n\topen: boolean;\n\n\t/**\n\t * The port on which to start the Slice Machine server.\n\t *\n\t * @defaultValue `9999`\n\t */\n\tport: number;\n\n\t/**\n\t * The Slice Machine manager used for the process.\n\t */\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(args: StartSliceMachineProcessConstructorArgs) {\n\t\tthis._sliceMachineManager = createSliceMachineManager();\n\n\t\tthis.open = args.open ?? false;\n\t\tthis.port = args.port ?? DEFAULT_SERVER_PORT;\n\t}\n\n\t/**\n\t * Runs the process.\n\t */\n\tasync run(): Promise<void> {\n\t\t// This migration needs to run before the plugins are initialised\n\t\t// Nothing can start without the config file\n\t\tawait migrateSMJSON(this._sliceMachineManager);\n\n\t\t// Initialize Segment and Sentry\n\t\tconst appVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\t\tawait this._sliceMachineManager.telemetry.initTelemetry({\n\t\t\tappName: SLICE_MACHINE_NPM_PACKAGE_NAME,\n\t\t\tappVersion,\n\t\t});\n\t\tconst isTelemetryEnabled =\n\t\t\tawait this._sliceMachineManager.telemetry.checkIsTelemetryEnabled();\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tawait setupSentry(this._sliceMachineManager);\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed tracking set up. We probably couldn't determine the\n\t\t\t\t// Sentry environment.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error setting up Sentry:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._sliceMachineManager.plugins.initPlugins();\n\n\t\t// TODO: MIGRATION - Move this to the Migration Manager\n\t\tawait migrateAssets(this._sliceMachineManager);\n\n\t\tawait this._validateProject();\n\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tthis._trackStart();\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed start event tracking.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error tracking start event:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst app = await createSliceMachineExpressApp({\n\t\t\tsliceMachineManager: this._sliceMachineManager,\n\t\t});\n\n\t\tconst server = app.listen(this.port);\n\t\tserver.on(\"error\", (error: NodeJS.ErrnoException) => {\n\t\t\tif (error.code === \"EADDRINUSE\") {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error starting Slice Machine: Port ${this.port} is already in use. Please try a different port.`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconsole.error(\"Error starting Slice Machine:\", error);\n\t\t\t}\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\tconst address = server.address() as AddressInfo;\n\t\tconst url = `http://localhost:${address.port}`;\n\n\t\tif (this.open) {\n\t\t\tawait open(url);\n\t\t}\n\n\t\tconsole.log();\n\t\tconsole.log(\n\t\t\tawait this._buildSliceMachineRunningLine(\n\t\t\t\t`Running at ${chalk.magenta(url)}`,\n\t\t\t),\n\t\t);\n\t\tconsole.log();\n\n\t\tconst profile = await this._fetchProfile();\n\n\t\tif (profile) {\n\t\t\tthis._sliceMachineManager.telemetry.identify({\n\t\t\t\tuserID: profile.shortId,\n\t\t\t\tintercomHash: profile.intercomHash,\n\t\t\t});\n\n\t\t\tawait Promise.allSettled([\n\t\t\t\t// noop - We'll try again when needed.\n\t\t\t\tthis._sliceMachineManager.user.refreshAuthenticationToken(),\n\t\t\t\t// noop - We'll try again before uploading a screenshot.\n\t\t\t\tthis._sliceMachineManager.screenshots.initS3ACL(),\n\t\t\t]);\n\t\t}\n\t}\n\n\t/**\n\t * Returns a string with Slice Machine info formatted for the console.\n\t *\n\t * @param value - Info to display.\n\t *\n\t * @returns String to pass to the console.\n\t */\n\tprivate async _buildSliceMachineRunningLine(value: string): Promise<string> {\n\t\tconst currentVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\n\t\treturn `${chalk.bgBlack(\n\t\t\t` ${chalk.bold.white(\"Slice Machine\")} ${chalk.magenta(\n\t\t\t\t`v${currentVersion}`,\n\t\t\t)} `,\n\t\t)} ${chalk.dim(\"→\")} ${value}`;\n\t}\n\n\t/**\n\t * Validates the project's config and content models.\n\t *\n\t * @throws Throws if a Library name is invalid.\n\t * @throws Throws if a Slice model is invalid.\n\t * @throws Throws if a Custom Type model is invalid.\n\t */\n\tprivate async _validateProject(): Promise<void> {\n\t\t// Validate Slice Machine config.\n\t\tconst config =\n\t\t\tawait this._sliceMachineManager.project.loadSliceMachineConfig();\n\n\t\t// Validate Library IDs\n\t\tconst invalidLibraries =\n\t\t\tconfig.libraries?.filter(\n\t\t\t\t(library) => library.startsWith(\"@\") || library.startsWith(\"~\"),\n\t\t\t) || [];\n\t\tif (invalidLibraries.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The following Slice libraries have invalid names: ${invalidLibraries.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Slice library names must not start with \"@\" nor \"~\".`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Slice models.\n\t\tconst allSlices = await this._sliceMachineManager.slices.readAllSlices();\n\t\tif (allSlices.errors.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Errors occurred while validating your project's slices.\\n\\n${allSlices.errors.join(\n\t\t\t\t\t\"\\n\\n\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Custom Type models.\n\t\tconst allCustomTypes =\n\t\t\tawait this._sliceMachineManager.customTypes.readAllCustomTypes();\n\t\tif (allCustomTypes.errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new Error(allCustomTypes.errors.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the logged in Prismic user's profile. If the user is not logged in,\n\t * `undefined` is returned.\n\t *\n\t * @returns The logged in Prismic user's profile, or `undefined` if not logged\n\t * in.\n\t */\n\tprivate async _fetchProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tconst isLoggedIn = await this._sliceMachineManager.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\treturn await this._sliceMachineManager.user.getProfile();\n\t\t}\n\t}\n\n\t/**\n\t * Tracks the start of Slice Machine.\n\t *\n\t * This method is called after Slice Machine has started and so it will not\n\t * cause the process to wait for the tracking to complete.\n\t */\n\tprivate async _trackStart(): Promise<void> {\n\t\tconst [\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tcustomTypes,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tpackageManager,\n\t\t\tsimulatorUrl,\n\t\t\tsliceMachineVersion,\n\t\t\tslices,\n\t\t\tversionControlSystem,\n\t\t] = await Promise.all([\n\t\t\tsafelyExecute(() => this._sliceMachineManager.project.getAdapterName()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningAdapterVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.customTypes.readAllCustomTypes(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.git.detectGitProvider()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsAdapterUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.user.checkIsLoggedIn()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsSliceMachineUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.checkIsTypeScript(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectPackageManager(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.simulator.getLocalSliceSimulatorURL(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningSliceMachineVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.slices.readAllSlices()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectVersionControlSystem(),\n\t\t\t),\n\t\t]);\n\n\t\tthis._sliceMachineManager.telemetry.track({\n\t\t\tevent: \"slice-machine:start\",\n\t\t\t_includeEnvironmentKind: true,\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tnodeVersion: process.versions.node,\n\t\t\tnumberOfCustomTypes: customTypes?.models.length,\n\t\t\tnumberOfSlices: slices?.models.length,\n\t\t\tosPlatform: os.platform(),\n\t\t\t// Ensure we escape the \"@\" character to prevent it from being interpreted\n\t\t\t// as an email address and being considered sensitive and stripped off.\n\t\t\tpackageManager: packageManager?.replace(\"@\", \"[at]\"),\n\t\t\tprojectPort: simulatorUrl ? new URL(simulatorUrl).port : undefined,\n\t\t\tsliceMachineVersion,\n\t\t\tversionControlSystem,\n\t\t});\n\t}\n}\n"],"names":["createSliceMachineManager","migrateSMJSON","SLICE_MACHINE_NPM_PACKAGE_NAME","setupSentry","migrateAssets","createSliceMachineExpressApp","safelyExecute"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAMf,MAAA,iCAAiC,IAC1C,SAC0B;AACtB,SAAA,IAAI,yBAAyB,GAAG,IAAI;AAC5C;MAUa,yBAAwB;AAAA,EAqBpC,YAAY,MAA6C;AAdzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKQ;AAAA;AAAA;AAAA;AAGP,SAAK,uBAAuBA,QAAAA;AAEvB,SAAA,OAAO,KAAK,QAAQ;AACpB,SAAA,OAAO,KAAK,QAAQ;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAG;AAGF,UAAAC,cAAA,cAAc,KAAK,oBAAoB;AAG7C,UAAM,aACL,MAAM,KAAK,qBAAqB,SAAS,8BAA6B;AACjE,UAAA,KAAK,qBAAqB,UAAU,cAAc;AAAA,MACvD,SAASC,UAAA;AAAA,MACT;AAAA,IAAA,CACA;AACD,UAAM,qBACL,MAAM,KAAK,qBAAqB,UAAU,wBAAuB;AAClE,QAAI,oBAAoB;AACnB,UAAA;AACG,cAAAC,YAAA,YAAY,KAAK,oBAAoB;AAAA,eACnC,OAAO;AAAA,MAQhB;AAAA,IACD;AAEM,UAAA,KAAK,qBAAqB,QAAQ;AAGlC,UAAAC,cAAA,cAAc,KAAK,oBAAoB;A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../src/StartSliceMachineProcess.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport type { AddressInfo } from \"node:net\";\nimport chalk from \"chalk\";\nimport open from \"open\";\nimport os from \"node:os\";\n\nimport {\n\tPrismicUserProfile,\n\tSliceMachineManager,\n\tcreateSliceMachineManager,\n} from \"@slicemachine/manager\";\n\nimport { createSliceMachineExpressApp } from \"./lib/createSliceMachineExpressApp\";\nimport { setupSentry } from \"./lib/setupSentry\";\nimport { migrateSMJSON } from \"./legacyMigrations/migrateSMJSON\";\nimport { migrateAssets } from \"./legacyMigrations/migrateAssets\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"./constants\";\nimport { safelyExecute } from \"./lib/safelyExecute\";\n\nconst DEFAULT_SERVER_PORT = 9999;\n\ntype CreateStartSliceMachineProcessArgs = ConstructorParameters<\n\ttypeof StartSliceMachineProcess\n>;\n\nexport const createStartSliceMachineProcess = (\n\t...args: CreateStartSliceMachineProcessArgs\n): StartSliceMachineProcess => {\n\treturn new StartSliceMachineProcess(...args);\n};\n\nexport type StartSliceMachineProcessConstructorArgs = {\n\topen: boolean;\n\tport?: number;\n};\n\n/**\n * Manages the process that runs Slice Machine's server.\n */\nexport class StartSliceMachineProcess {\n\t/**\n\t * Determines if Slice Machine should automatically be opened once the server\n\t * starts.\n\t *\n\t * @defaultValue `false`\n\t */\n\topen: boolean;\n\n\t/**\n\t * The port on which to start the Slice Machine server.\n\t *\n\t * @defaultValue `9999`\n\t */\n\tport: number;\n\n\t/**\n\t * The Slice Machine manager used for the process.\n\t */\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(args: StartSliceMachineProcessConstructorArgs) {\n\t\tthis._sliceMachineManager = createSliceMachineManager();\n\n\t\tthis.open = args.open ?? false;\n\t\tthis.port = args.port ?? DEFAULT_SERVER_PORT;\n\t}\n\n\t/**\n\t * Runs the process.\n\t */\n\tasync run(): Promise<void> {\n\t\t// This migration needs to run before the plugins are initialised\n\t\t// Nothing can start without the config file\n\t\tawait migrateSMJSON(this._sliceMachineManager);\n\n\t\t// Initialize Segment and Sentry\n\t\tconst appVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\t\tawait this._sliceMachineManager.telemetry.initTelemetry({\n\t\t\tappName: SLICE_MACHINE_NPM_PACKAGE_NAME,\n\t\t\tappVersion,\n\t\t});\n\t\tconst isTelemetryEnabled =\n\t\t\tawait this._sliceMachineManager.telemetry.checkIsTelemetryEnabled();\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tawait setupSentry(this._sliceMachineManager);\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed tracking set up. We probably couldn't determine the\n\t\t\t\t// Sentry environment.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error setting up Sentry:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._sliceMachineManager.plugins.initPlugins();\n\n\t\t// TODO: MIGRATION - Move this to the Migration Manager\n\t\tawait migrateAssets(this._sliceMachineManager);\n\n\t\tawait this._validateProject();\n\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tthis._trackStart();\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed start event tracking.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error tracking start event:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst app = await createSliceMachineExpressApp({\n\t\t\tsliceMachineManager: this._sliceMachineManager,\n\t\t});\n\t\tconst server = app.listen(this.port);\n\t\tconst address = server.address() as AddressInfo;\n\t\tconst url = `http://localhost:${address.port}`;\n\n\t\tif (this.open) {\n\t\t\tawait open(url);\n\t\t}\n\n\t\tconsole.log();\n\t\tconsole.log(\n\t\t\tawait this._buildSliceMachineRunningLine(\n\t\t\t\t`Running at ${chalk.magenta(url)}`,\n\t\t\t),\n\t\t);\n\t\tconsole.log();\n\n\t\tconst profile = await this._fetchProfile();\n\n\t\tif (profile) {\n\t\t\tthis._sliceMachineManager.telemetry.identify({\n\t\t\t\tuserID: profile.shortId,\n\t\t\t\tintercomHash: profile.intercomHash,\n\t\t\t});\n\n\t\t\tawait Promise.allSettled([\n\t\t\t\t// noop - We'll try again when needed.\n\t\t\t\tthis._sliceMachineManager.user.refreshAuthenticationToken(),\n\t\t\t\t// noop - We'll try again before uploading a screenshot.\n\t\t\t\tthis._sliceMachineManager.screenshots.initS3ACL(),\n\t\t\t]);\n\t\t}\n\t}\n\n\t/**\n\t * Returns a string with Slice Machine info formatted for the console.\n\t *\n\t * @param value - Info to display.\n\t *\n\t * @returns String to pass to the console.\n\t */\n\tprivate async _buildSliceMachineRunningLine(value: string): Promise<string> {\n\t\tconst currentVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\n\t\treturn `${chalk.bgBlack(\n\t\t\t` ${chalk.bold.white(\"Slice Machine\")} ${chalk.magenta(\n\t\t\t\t`v${currentVersion}`,\n\t\t\t)} `,\n\t\t)} ${chalk.dim(\"→\")} ${value}`;\n\t}\n\n\t/**\n\t * Validates the project's config and content models.\n\t *\n\t * @throws Throws if a Library name is invalid.\n\t * @throws Throws if a Slice model is invalid.\n\t * @throws Throws if a Custom Type model is invalid.\n\t */\n\tprivate async _validateProject(): Promise<void> {\n\t\t// Validate Slice Machine config.\n\t\tconst config =\n\t\t\tawait this._sliceMachineManager.project.loadSliceMachineConfig();\n\n\t\t// Validate Library IDs\n\t\tconst invalidLibraries =\n\t\t\tconfig.libraries?.filter(\n\t\t\t\t(library) => library.startsWith(\"@\") || library.startsWith(\"~\"),\n\t\t\t) || [];\n\t\tif (invalidLibraries.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The following Slice libraries have invalid names: ${invalidLibraries.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Slice library names must not start with \"@\" nor \"~\".`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Slice models.\n\t\tconst allSlices = await this._sliceMachineManager.slices.readAllSlices();\n\t\tif (allSlices.errors.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Errors occurred while validating your project's slices.\\n\\n${allSlices.errors.join(\n\t\t\t\t\t\"\\n\\n\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Custom Type models.\n\t\tconst allCustomTypes =\n\t\t\tawait this._sliceMachineManager.customTypes.readAllCustomTypes();\n\t\tif (allCustomTypes.errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new Error(allCustomTypes.errors.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the logged in Prismic user's profile. If the user is not logged in,\n\t * `undefined` is returned.\n\t *\n\t * @returns The logged in Prismic user's profile, or `undefined` if not logged\n\t * in.\n\t */\n\tprivate async _fetchProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tconst isLoggedIn = await this._sliceMachineManager.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\treturn await this._sliceMachineManager.user.getProfile();\n\t\t}\n\t}\n\n\t/**\n\t * Tracks the start of Slice Machine.\n\t *\n\t * This method is called after Slice Machine has started and so it will not\n\t * cause the process to wait for the tracking to complete.\n\t */\n\tprivate async _trackStart(): Promise<void> {\n\t\tconst [\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tcustomTypes,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tpackageManager,\n\t\t\tsimulatorUrl,\n\t\t\tsliceMachineVersion,\n\t\t\tslices,\n\t\t\tversionControlSystem,\n\t\t] = await Promise.all([\n\t\t\tsafelyExecute(() => this._sliceMachineManager.project.getAdapterName()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningAdapterVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.customTypes.readAllCustomTypes(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.git.detectGitProvider()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsAdapterUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.user.checkIsLoggedIn()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsSliceMachineUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.checkIsTypeScript(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectPackageManager(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.simulator.getLocalSliceSimulatorURL(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningSliceMachineVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.slices.readAllSlices()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectVersionControlSystem(),\n\t\t\t),\n\t\t]);\n\n\t\tthis._sliceMachineManager.telemetry.track({\n\t\t\tevent: \"slice-machine:start\",\n\t\t\t_includeEnvironmentKind: true,\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tnodeVersion: process.versions.node,\n\t\t\tnumberOfCustomTypes: customTypes?.models.length,\n\t\t\tnumberOfSlices: slices?.models.length,\n\t\t\tosPlatform: os.platform(),\n\t\t\t// Ensure we escape the \"@\" character to prevent it from being interpreted\n\t\t\t// as an email address and being considered sensitive and stripped off.\n\t\t\tpackageManager: packageManager?.replace(\"@\", \"[at]\"),\n\t\t\tprojectPort: simulatorUrl ? new URL(simulatorUrl).port : undefined,\n\t\t\tsliceMachineVersion,\n\t\t\tversionControlSystem,\n\t\t});\n\t}\n}\n"],"names":["createSliceMachineManager","migrateSMJSON","SLICE_MACHINE_NPM_PACKAGE_NAME","setupSentry","migrateAssets","createSliceMachineExpressApp","safelyExecute"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAMf,MAAA,iCAAiC,IAC1C,SAC0B;AACtB,SAAA,IAAI,yBAAyB,GAAG,IAAI;AAC5C;MAUa,yBAAwB;AAAA,EAqBpC,YAAY,MAA6C;AAdzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKQ;AAAA;AAAA;AAAA;AAGP,SAAK,uBAAuBA,QAAAA;AAEvB,SAAA,OAAO,KAAK,QAAQ;AACpB,SAAA,OAAO,KAAK,QAAQ;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAG;AAGF,UAAAC,cAAA,cAAc,KAAK,oBAAoB;AAG7C,UAAM,aACL,MAAM,KAAK,qBAAqB,SAAS,8BAA6B;AACjE,UAAA,KAAK,qBAAqB,UAAU,cAAc;AAAA,MACvD,SAASC,UAAA;AAAA,MACT;AAAA,IAAA,CACA;AACD,UAAM,qBACL,MAAM,KAAK,qBAAqB,UAAU,wBAAuB;AAClE,QAAI,oBAAoB;AACnB,UAAA;AACG,cAAAC,YAAA,YAAY,KAAK,oBAAoB;AAAA,eACnC,OAAO;AAAA,MAQhB;AAAA,IACD;AAEM,UAAA,KAAK,qBAAqB,QAAQ;AAGlC,UAAAC,cAAA,cAAc,KAAK,oBAAoB;AAE7C,UAAM,KAAK;AAEX,QAAI,oBAAoB;AACnB,UAAA;AACH,aAAK,YAAW;AAAA,eACR,OAAO;AAAA,M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ACb,KAAK,qBAAqB,SAAS,oCAAoC;AAAA,MAExEA,cAAAA,cAAc,MACb,KAAK,qBAAqB,QAAQ,mBAAmB;AAAA,MAEtDA,cAAAA,cAAc,MACb,KAAK,qBAAqB,QAAQ,sBAAsB;AAAA,MAEzDA,cAAAA,cAAc,MACb,KAAK,qBAAqB,UAAU,2BAA2B;AAAA,MAEhEA,cAAAA,cAAc,MACb,KAAK,qBAAqB,SAAS,+BAA+B;AAAA,MAEnEA,cAAAA,cAAc,MAAM,KAAK,qBAAqB,OAAO,eAAe;AAAA,MACpEA,cAAAA,cAAc,MACb,KAAK,qBAAqB,QAAQ,4BAA4B;AAAA,IAAA,CAE/D;AAEI,SAAA,qBAAqB,UAAU,MAAM;AAAA,MACzC,OAAO;AAAA,MACP,yBAAyB;AAAA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,QAAQ,SAAS;AAAA,MAC9B,qBAAqB,2CAAa,OAAO;AAAA,MACzC,gBAAgB,iCAAQ,OAAO;AAAA,MAC/B,YAAY,GAAG,SAAU;AAAA;AAAA;AAAA,MAGzB,gBAAgB,iDAAgB,QAAQ,KAAK;AAAA,MAC7C,aAAa,eAAe,IAAI,IAAI,YAAY,EAAE,OAAO;AAAA,MACzD;AAAA,MACA;AAAA,IAAA,CACA;AAAA,EACF;AACA;;;"}
|
|
@@ -71,14 +71,6 @@ class StartSliceMachineProcess {
|
|
|
71
71
|
sliceMachineManager: this._sliceMachineManager
|
|
72
72
|
});
|
|
73
73
|
const server = app.listen(this.port);
|
|
74
|
-
server.on("error", (error) => {
|
|
75
|
-
if (error.code === "EADDRINUSE") {
|
|
76
|
-
console.error(`Error starting Slice Machine: Port ${this.port} is already in use. Please try a different port.`);
|
|
77
|
-
} else {
|
|
78
|
-
console.error("Error starting Slice Machine:", error);
|
|
79
|
-
}
|
|
80
|
-
process.exit(1);
|
|
81
|
-
});
|
|
82
74
|
const address = server.address();
|
|
83
75
|
const url = `http://localhost:${address.port}`;
|
|
84
76
|
if (this.open) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StartSliceMachineProcess.js","sources":["../../src/StartSliceMachineProcess.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport type { AddressInfo } from \"node:net\";\nimport chalk from \"chalk\";\nimport open from \"open\";\nimport os from \"node:os\";\n\nimport {\n\tPrismicUserProfile,\n\tSliceMachineManager,\n\tcreateSliceMachineManager,\n} from \"@slicemachine/manager\";\n\nimport { createSliceMachineExpressApp } from \"./lib/createSliceMachineExpressApp\";\nimport { setupSentry } from \"./lib/setupSentry\";\nimport { migrateSMJSON } from \"./legacyMigrations/migrateSMJSON\";\nimport { migrateAssets } from \"./legacyMigrations/migrateAssets\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"./constants\";\nimport { safelyExecute } from \"./lib/safelyExecute\";\n\nconst DEFAULT_SERVER_PORT = 9999;\n\ntype CreateStartSliceMachineProcessArgs = ConstructorParameters<\n\ttypeof StartSliceMachineProcess\n>;\n\nexport const createStartSliceMachineProcess = (\n\t...args: CreateStartSliceMachineProcessArgs\n): StartSliceMachineProcess => {\n\treturn new StartSliceMachineProcess(...args);\n};\n\nexport type StartSliceMachineProcessConstructorArgs = {\n\topen: boolean;\n\tport?: number;\n};\n\n/**\n * Manages the process that runs Slice Machine's server.\n */\nexport class StartSliceMachineProcess {\n\t/**\n\t * Determines if Slice Machine should automatically be opened once the server\n\t * starts.\n\t *\n\t * @defaultValue `false`\n\t */\n\topen: boolean;\n\n\t/**\n\t * The port on which to start the Slice Machine server.\n\t *\n\t * @defaultValue `9999`\n\t */\n\tport: number;\n\n\t/**\n\t * The Slice Machine manager used for the process.\n\t */\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(args: StartSliceMachineProcessConstructorArgs) {\n\t\tthis._sliceMachineManager = createSliceMachineManager();\n\n\t\tthis.open = args.open ?? false;\n\t\tthis.port = args.port ?? DEFAULT_SERVER_PORT;\n\t}\n\n\t/**\n\t * Runs the process.\n\t */\n\tasync run(): Promise<void> {\n\t\t// This migration needs to run before the plugins are initialised\n\t\t// Nothing can start without the config file\n\t\tawait migrateSMJSON(this._sliceMachineManager);\n\n\t\t// Initialize Segment and Sentry\n\t\tconst appVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\t\tawait this._sliceMachineManager.telemetry.initTelemetry({\n\t\t\tappName: SLICE_MACHINE_NPM_PACKAGE_NAME,\n\t\t\tappVersion,\n\t\t});\n\t\tconst isTelemetryEnabled =\n\t\t\tawait this._sliceMachineManager.telemetry.checkIsTelemetryEnabled();\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tawait setupSentry(this._sliceMachineManager);\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed tracking set up. We probably couldn't determine the\n\t\t\t\t// Sentry environment.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error setting up Sentry:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._sliceMachineManager.plugins.initPlugins();\n\n\t\t// TODO: MIGRATION - Move this to the Migration Manager\n\t\tawait migrateAssets(this._sliceMachineManager);\n\n\t\tawait this._validateProject();\n\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tthis._trackStart();\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed start event tracking.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error tracking start event:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst app = await createSliceMachineExpressApp({\n\t\t\tsliceMachineManager: this._sliceMachineManager,\n\t\t});\n\n\t\tconst server = app.listen(this.port);\n\t\tserver.on(\"error\", (error: NodeJS.ErrnoException) => {\n\t\t\tif (error.code === \"EADDRINUSE\") {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error starting Slice Machine: Port ${this.port} is already in use. Please try a different port.`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconsole.error(\"Error starting Slice Machine:\", error);\n\t\t\t}\n\t\t\tprocess.exit(1);\n\t\t});\n\n\t\tconst address = server.address() as AddressInfo;\n\t\tconst url = `http://localhost:${address.port}`;\n\n\t\tif (this.open) {\n\t\t\tawait open(url);\n\t\t}\n\n\t\tconsole.log();\n\t\tconsole.log(\n\t\t\tawait this._buildSliceMachineRunningLine(\n\t\t\t\t`Running at ${chalk.magenta(url)}`,\n\t\t\t),\n\t\t);\n\t\tconsole.log();\n\n\t\tconst profile = await this._fetchProfile();\n\n\t\tif (profile) {\n\t\t\tthis._sliceMachineManager.telemetry.identify({\n\t\t\t\tuserID: profile.shortId,\n\t\t\t\tintercomHash: profile.intercomHash,\n\t\t\t});\n\n\t\t\tawait Promise.allSettled([\n\t\t\t\t// noop - We'll try again when needed.\n\t\t\t\tthis._sliceMachineManager.user.refreshAuthenticationToken(),\n\t\t\t\t// noop - We'll try again before uploading a screenshot.\n\t\t\t\tthis._sliceMachineManager.screenshots.initS3ACL(),\n\t\t\t]);\n\t\t}\n\t}\n\n\t/**\n\t * Returns a string with Slice Machine info formatted for the console.\n\t *\n\t * @param value - Info to display.\n\t *\n\t * @returns String to pass to the console.\n\t */\n\tprivate async _buildSliceMachineRunningLine(value: string): Promise<string> {\n\t\tconst currentVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\n\t\treturn `${chalk.bgBlack(\n\t\t\t` ${chalk.bold.white(\"Slice Machine\")} ${chalk.magenta(\n\t\t\t\t`v${currentVersion}`,\n\t\t\t)} `,\n\t\t)} ${chalk.dim(\"→\")} ${value}`;\n\t}\n\n\t/**\n\t * Validates the project's config and content models.\n\t *\n\t * @throws Throws if a Library name is invalid.\n\t * @throws Throws if a Slice model is invalid.\n\t * @throws Throws if a Custom Type model is invalid.\n\t */\n\tprivate async _validateProject(): Promise<void> {\n\t\t// Validate Slice Machine config.\n\t\tconst config =\n\t\t\tawait this._sliceMachineManager.project.loadSliceMachineConfig();\n\n\t\t// Validate Library IDs\n\t\tconst invalidLibraries =\n\t\t\tconfig.libraries?.filter(\n\t\t\t\t(library) => library.startsWith(\"@\") || library.startsWith(\"~\"),\n\t\t\t) || [];\n\t\tif (invalidLibraries.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The following Slice libraries have invalid names: ${invalidLibraries.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Slice library names must not start with \"@\" nor \"~\".`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Slice models.\n\t\tconst allSlices = await this._sliceMachineManager.slices.readAllSlices();\n\t\tif (allSlices.errors.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Errors occurred while validating your project's slices.\\n\\n${allSlices.errors.join(\n\t\t\t\t\t\"\\n\\n\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Custom Type models.\n\t\tconst allCustomTypes =\n\t\t\tawait this._sliceMachineManager.customTypes.readAllCustomTypes();\n\t\tif (allCustomTypes.errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new Error(allCustomTypes.errors.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the logged in Prismic user's profile. If the user is not logged in,\n\t * `undefined` is returned.\n\t *\n\t * @returns The logged in Prismic user's profile, or `undefined` if not logged\n\t * in.\n\t */\n\tprivate async _fetchProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tconst isLoggedIn = await this._sliceMachineManager.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\treturn await this._sliceMachineManager.user.getProfile();\n\t\t}\n\t}\n\n\t/**\n\t * Tracks the start of Slice Machine.\n\t *\n\t * This method is called after Slice Machine has started and so it will not\n\t * cause the process to wait for the tracking to complete.\n\t */\n\tprivate async _trackStart(): Promise<void> {\n\t\tconst [\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tcustomTypes,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tpackageManager,\n\t\t\tsimulatorUrl,\n\t\t\tsliceMachineVersion,\n\t\t\tslices,\n\t\t\tversionControlSystem,\n\t\t] = await Promise.all([\n\t\t\tsafelyExecute(() => this._sliceMachineManager.project.getAdapterName()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningAdapterVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.customTypes.readAllCustomTypes(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.git.detectGitProvider()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsAdapterUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.user.checkIsLoggedIn()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsSliceMachineUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.checkIsTypeScript(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectPackageManager(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.simulator.getLocalSliceSimulatorURL(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningSliceMachineVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.slices.readAllSlices()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectVersionControlSystem(),\n\t\t\t),\n\t\t]);\n\n\t\tthis._sliceMachineManager.telemetry.track({\n\t\t\tevent: \"slice-machine:start\",\n\t\t\t_includeEnvironmentKind: true,\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tnodeVersion: process.versions.node,\n\t\t\tnumberOfCustomTypes: customTypes?.models.length,\n\t\t\tnumberOfSlices: slices?.models.length,\n\t\t\tosPlatform: os.platform(),\n\t\t\t// Ensure we escape the \"@\" character to prevent it from being interpreted\n\t\t\t// as an email address and being considered sensitive and stripped off.\n\t\t\tpackageManager: packageManager?.replace(\"@\", \"[at]\"),\n\t\t\tprojectPort: simulatorUrl ? new URL(simulatorUrl).port : undefined,\n\t\t\tsliceMachineVersion,\n\t\t\tversionControlSystem,\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAMf,MAAA,iCAAiC,IAC1C,SAC0B;AACtB,SAAA,IAAI,yBAAyB,GAAG,IAAI;AAC5C;MAUa,yBAAwB;AAAA,EAqBpC,YAAY,MAA6C;AAdzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKQ;AAAA;AAAA;AAAA;AAGP,SAAK,uBAAuB;AAEvB,SAAA,OAAO,KAAK,QAAQ;AACpB,SAAA,OAAO,KAAK,QAAQ;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAG;AAGF,UAAA,cAAc,KAAK,oBAAoB;AAG7C,UAAM,aACL,MAAM,KAAK,qBAAqB,SAAS,8BAA6B;AACjE,UAAA,KAAK,qBAAqB,UAAU,cAAc;AAAA,MACvD,SAAS;AAAA,MACT;AAAA,IAAA,CACA;AACD,UAAM,qBACL,MAAM,KAAK,qBAAqB,UAAU,wBAAuB;AAClE,QAAI,o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
|
1
|
+
{"version":3,"file":"StartSliceMachineProcess.js","sources":["../../src/StartSliceMachineProcess.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport type { AddressInfo } from \"node:net\";\nimport chalk from \"chalk\";\nimport open from \"open\";\nimport os from \"node:os\";\n\nimport {\n\tPrismicUserProfile,\n\tSliceMachineManager,\n\tcreateSliceMachineManager,\n} from \"@slicemachine/manager\";\n\nimport { createSliceMachineExpressApp } from \"./lib/createSliceMachineExpressApp\";\nimport { setupSentry } from \"./lib/setupSentry\";\nimport { migrateSMJSON } from \"./legacyMigrations/migrateSMJSON\";\nimport { migrateAssets } from \"./legacyMigrations/migrateAssets\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"./constants\";\nimport { safelyExecute } from \"./lib/safelyExecute\";\n\nconst DEFAULT_SERVER_PORT = 9999;\n\ntype CreateStartSliceMachineProcessArgs = ConstructorParameters<\n\ttypeof StartSliceMachineProcess\n>;\n\nexport const createStartSliceMachineProcess = (\n\t...args: CreateStartSliceMachineProcessArgs\n): StartSliceMachineProcess => {\n\treturn new StartSliceMachineProcess(...args);\n};\n\nexport type StartSliceMachineProcessConstructorArgs = {\n\topen: boolean;\n\tport?: number;\n};\n\n/**\n * Manages the process that runs Slice Machine's server.\n */\nexport class StartSliceMachineProcess {\n\t/**\n\t * Determines if Slice Machine should automatically be opened once the server\n\t * starts.\n\t *\n\t * @defaultValue `false`\n\t */\n\topen: boolean;\n\n\t/**\n\t * The port on which to start the Slice Machine server.\n\t *\n\t * @defaultValue `9999`\n\t */\n\tport: number;\n\n\t/**\n\t * The Slice Machine manager used for the process.\n\t */\n\tprivate _sliceMachineManager: SliceMachineManager;\n\n\tconstructor(args: StartSliceMachineProcessConstructorArgs) {\n\t\tthis._sliceMachineManager = createSliceMachineManager();\n\n\t\tthis.open = args.open ?? false;\n\t\tthis.port = args.port ?? DEFAULT_SERVER_PORT;\n\t}\n\n\t/**\n\t * Runs the process.\n\t */\n\tasync run(): Promise<void> {\n\t\t// This migration needs to run before the plugins are initialised\n\t\t// Nothing can start without the config file\n\t\tawait migrateSMJSON(this._sliceMachineManager);\n\n\t\t// Initialize Segment and Sentry\n\t\tconst appVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\t\tawait this._sliceMachineManager.telemetry.initTelemetry({\n\t\t\tappName: SLICE_MACHINE_NPM_PACKAGE_NAME,\n\t\t\tappVersion,\n\t\t});\n\t\tconst isTelemetryEnabled =\n\t\t\tawait this._sliceMachineManager.telemetry.checkIsTelemetryEnabled();\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tawait setupSentry(this._sliceMachineManager);\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed tracking set up. We probably couldn't determine the\n\t\t\t\t// Sentry environment.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error setting up Sentry:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._sliceMachineManager.plugins.initPlugins();\n\n\t\t// TODO: MIGRATION - Move this to the Migration Manager\n\t\tawait migrateAssets(this._sliceMachineManager);\n\n\t\tawait this._validateProject();\n\n\t\tif (isTelemetryEnabled) {\n\t\t\ttry {\n\t\t\t\tthis._trackStart();\n\t\t\t} catch (error) {\n\t\t\t\t// noop - We don't want to stop the user from using Slice Machine\n\t\t\t\t// because of failed start event tracking.\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tconsole.error(\"Error tracking start event:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst app = await createSliceMachineExpressApp({\n\t\t\tsliceMachineManager: this._sliceMachineManager,\n\t\t});\n\t\tconst server = app.listen(this.port);\n\t\tconst address = server.address() as AddressInfo;\n\t\tconst url = `http://localhost:${address.port}`;\n\n\t\tif (this.open) {\n\t\t\tawait open(url);\n\t\t}\n\n\t\tconsole.log();\n\t\tconsole.log(\n\t\t\tawait this._buildSliceMachineRunningLine(\n\t\t\t\t`Running at ${chalk.magenta(url)}`,\n\t\t\t),\n\t\t);\n\t\tconsole.log();\n\n\t\tconst profile = await this._fetchProfile();\n\n\t\tif (profile) {\n\t\t\tthis._sliceMachineManager.telemetry.identify({\n\t\t\t\tuserID: profile.shortId,\n\t\t\t\tintercomHash: profile.intercomHash,\n\t\t\t});\n\n\t\t\tawait Promise.allSettled([\n\t\t\t\t// noop - We'll try again when needed.\n\t\t\t\tthis._sliceMachineManager.user.refreshAuthenticationToken(),\n\t\t\t\t// noop - We'll try again before uploading a screenshot.\n\t\t\t\tthis._sliceMachineManager.screenshots.initS3ACL(),\n\t\t\t]);\n\t\t}\n\t}\n\n\t/**\n\t * Returns a string with Slice Machine info formatted for the console.\n\t *\n\t * @param value - Info to display.\n\t *\n\t * @returns String to pass to the console.\n\t */\n\tprivate async _buildSliceMachineRunningLine(value: string): Promise<string> {\n\t\tconst currentVersion =\n\t\t\tawait this._sliceMachineManager.versions.getRunningSliceMachineVersion();\n\n\t\treturn `${chalk.bgBlack(\n\t\t\t` ${chalk.bold.white(\"Slice Machine\")} ${chalk.magenta(\n\t\t\t\t`v${currentVersion}`,\n\t\t\t)} `,\n\t\t)} ${chalk.dim(\"→\")} ${value}`;\n\t}\n\n\t/**\n\t * Validates the project's config and content models.\n\t *\n\t * @throws Throws if a Library name is invalid.\n\t * @throws Throws if a Slice model is invalid.\n\t * @throws Throws if a Custom Type model is invalid.\n\t */\n\tprivate async _validateProject(): Promise<void> {\n\t\t// Validate Slice Machine config.\n\t\tconst config =\n\t\t\tawait this._sliceMachineManager.project.loadSliceMachineConfig();\n\n\t\t// Validate Library IDs\n\t\tconst invalidLibraries =\n\t\t\tconfig.libraries?.filter(\n\t\t\t\t(library) => library.startsWith(\"@\") || library.startsWith(\"~\"),\n\t\t\t) || [];\n\t\tif (invalidLibraries.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`The following Slice libraries have invalid names: ${invalidLibraries.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Slice library names must not start with \"@\" nor \"~\".`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Slice models.\n\t\tconst allSlices = await this._sliceMachineManager.slices.readAllSlices();\n\t\tif (allSlices.errors.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Errors occurred while validating your project's slices.\\n\\n${allSlices.errors.join(\n\t\t\t\t\t\"\\n\\n\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// Validate Custom Type models.\n\t\tconst allCustomTypes =\n\t\t\tawait this._sliceMachineManager.customTypes.readAllCustomTypes();\n\t\tif (allCustomTypes.errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new Error(allCustomTypes.errors.join(\", \"));\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the logged in Prismic user's profile. If the user is not logged in,\n\t * `undefined` is returned.\n\t *\n\t * @returns The logged in Prismic user's profile, or `undefined` if not logged\n\t * in.\n\t */\n\tprivate async _fetchProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tconst isLoggedIn = await this._sliceMachineManager.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\treturn await this._sliceMachineManager.user.getProfile();\n\t\t}\n\t}\n\n\t/**\n\t * Tracks the start of Slice Machine.\n\t *\n\t * This method is called after Slice Machine has started and so it will not\n\t * cause the process to wait for the tracking to complete.\n\t */\n\tprivate async _trackStart(): Promise<void> {\n\t\tconst [\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tcustomTypes,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tpackageManager,\n\t\t\tsimulatorUrl,\n\t\t\tsliceMachineVersion,\n\t\t\tslices,\n\t\t\tversionControlSystem,\n\t\t] = await Promise.all([\n\t\t\tsafelyExecute(() => this._sliceMachineManager.project.getAdapterName()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningAdapterVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.customTypes.readAllCustomTypes(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.git.detectGitProvider()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsAdapterUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.user.checkIsLoggedIn()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.checkIsSliceMachineUpdateAvailable(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.checkIsTypeScript(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectPackageManager(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.simulator.getLocalSliceSimulatorURL(),\n\t\t\t),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.versions.getRunningSliceMachineVersion(),\n\t\t\t),\n\t\t\tsafelyExecute(() => this._sliceMachineManager.slices.readAllSlices()),\n\t\t\tsafelyExecute(() =>\n\t\t\t\tthis._sliceMachineManager.project.detectVersionControlSystem(),\n\t\t\t),\n\t\t]);\n\n\t\tthis._sliceMachineManager.telemetry.track({\n\t\t\tevent: \"slice-machine:start\",\n\t\t\t_includeEnvironmentKind: true,\n\t\t\tadapter,\n\t\t\tadapterVersion,\n\t\t\tgitProvider,\n\t\t\tisAdapterUpdateAvailable,\n\t\t\tisLoggedIn,\n\t\t\tisSliceMachineUpdateAvailable,\n\t\t\tisTypeScriptProject,\n\t\t\tnodeVersion: process.versions.node,\n\t\t\tnumberOfCustomTypes: customTypes?.models.length,\n\t\t\tnumberOfSlices: slices?.models.length,\n\t\t\tosPlatform: os.platform(),\n\t\t\t// Ensure we escape the \"@\" character to prevent it from being interpreted\n\t\t\t// as an email address and being considered sensitive and stripped off.\n\t\t\tpackageManager: packageManager?.replace(\"@\", \"[at]\"),\n\t\t\tprojectPort: simulatorUrl ? new URL(simulatorUrl).port : undefined,\n\t\t\tsliceMachineVersion,\n\t\t\tversionControlSystem,\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAMf,MAAA,iCAAiC,IAC1C,SAC0B;AACtB,SAAA,IAAI,yBAAyB,GAAG,IAAI;AAC5C;MAUa,yBAAwB;AAAA,EAqBpC,YAAY,MAA6C;AAdzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKQ;AAAA;AAAA;AAAA;AAGP,SAAK,uBAAuB;AAEvB,SAAA,OAAO,KAAK,QAAQ;AACpB,SAAA,OAAO,KAAK,QAAQ;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAG;AAGF,UAAA,cAAc,KAAK,oBAAoB;AAG7C,UAAM,aACL,MAAM,KAAK,qBAAqB,SAAS,8BAA6B;AACjE,UAAA,KAAK,qBAAqB,UAAU,cAAc;AAAA,MACvD,SAAS;AAAA,MACT;AAAA,IAAA,CACA;AACD,UAAM,qBACL,MAAM,KAAK,qBAAqB,UAAU,wBAAuB;AAClE,QAAI,oBAAoB;AACnB,UAAA;AACG,cAAA,YAAY,KAAK,oBAAoB;AAAA,eACnC,OAAO;AAAA,MAQhB;AAAA,IACD;AAEM,UAAA,KAAK,qBAAqB,QAAQ;AAGlC,UAAA,cAAc,KAAK,oBAAoB;AAE7C,UAAM,KAAK;AAEX,QAAI,oBAAoB;AACnB,UAAA;AACH,aAAK,YAAW;AAAA,eACR,OAAO;AAAA,MAOhB;AAAA,IACD;AAEM,UAAA,MAAM,MAAM,6BAA6B;AAAA,MAC9C,qBAAqB,KAAK;AAAA,IAA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AEzD,cAAc,MACb,KAAK,qBAAqB,UAAU,2BAA2B;AAAA,MAEhE,cAAc,MACb,KAAK,qBAAqB,SAAS,+BAA+B;AAAA,MAEnE,cAAc,MAAM,KAAK,qBAAqB,OAAO,eAAe;AAAA,MACpE,cAAc,MACb,KAAK,qBAAqB,QAAQ,4BAA4B;AAAA,IAAA,CAE/D;AAEI,SAAA,qBAAqB,UAAU,MAAM;AAAA,MACzC,OAAO;AAAA,MACP,yBAAyB;AAAA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,QAAQ,SAAS;AAAA,MAC9B,qBAAqB,2CAAa,OAAO;AAAA,MACzC,gBAAgB,iCAAQ,OAAO;AAAA,MAC/B,YAAY,GAAG,SAAU;AAAA;AAAA;AAAA,MAGzB,gBAAgB,iDAAgB,QAAQ,KAAK;AAAA,MAC7C,aAAa,eAAe,IAAI,IAAI,YAAY,EAAE,OAAO;AAAA,MACzD;AAAA,MACA;AAAA,IAAA,CACA;AAAA,EACF;AACA;"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const manager = require("@slicemachine/manager");
|
|
3
4
|
const checkIsSentryEnabled = require("./checkIsSentryEnabled.cjs");
|
|
4
5
|
const exports$1 = require('./../_node_modules/@sentry/node/_node_modules/@sentry/core/esm/exports.cjs');
|
|
5
6
|
const node = (name, error) => {
|
|
6
7
|
if (checkIsSentryEnabled.checkIsSentryEnabled()) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (error instanceof manager.UnauthenticatedError || error instanceof manager.UnauthorizedError)
|
|
9
|
+
;
|
|
10
|
+
else {
|
|
11
|
+
exports$1.withScope(function(scope) {
|
|
12
|
+
scope.setTransactionName(name);
|
|
13
|
+
exports$1.captureException(error, {
|
|
14
|
+
...error instanceof Error ? { extra: { cause: error.cause } } : {}
|
|
15
|
+
});
|
|
11
16
|
});
|
|
12
|
-
}
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
};
|
|
15
20
|
const server = (error, req, _res, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryErrorHandlers.cjs","sources":["../../../src/lib/sentryErrorHandlers.ts"],"sourcesContent":["import type { ErrorRequestHandler } from \"express\";\nimport * as Sentry from \"@sentry/node\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"sentryErrorHandlers.cjs","sources":["../../../src/lib/sentryErrorHandlers.ts"],"sourcesContent":["import type { ErrorRequestHandler } from \"express\";\nimport * as Sentry from \"@sentry/node\";\n\nimport {\n\tCreateSliceMachineManagerMiddlewareArgs,\n\tUnauthenticatedError,\n\tUnauthorizedError,\n} from \"@slicemachine/manager\";\n\nimport { checkIsSentryEnabled } from \"./checkIsSentryEnabled\";\n\nexport const node = (name: string, error: unknown): void => {\n\tif (checkIsSentryEnabled()) {\n\t\tif (\n\t\t\terror instanceof UnauthenticatedError ||\n\t\t\terror instanceof UnauthorizedError\n\t\t) {\n\t\t\t// noop - User is not logged in or does not have access to the repository, no need to track this error in Sentry.\n\t\t} else {\n\t\t\tSentry.withScope(function (scope) {\n\t\t\t\tscope.setTransactionName(name);\n\t\t\t\tSentry.captureException(error, {\n\t\t\t\t\t...(error instanceof Error ? { extra: { cause: error.cause } } : {}),\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n};\n\nexport const server: ErrorRequestHandler = (error, req, _res, next): void => {\n\tnode(req.path, error);\n\tnext();\n};\n\nexport const rpc: CreateSliceMachineManagerMiddlewareArgs[\"onError\"] = (\n\targs,\n) => {\n\tnode(args.procedurePath.join(\".\"), args.error);\n};\n"],"names":["checkIsSentryEnabled","UnauthenticatedError","UnauthorizedError","Sentry.withScope","Sentry.captureException"],"mappings":";;;;;AAWa,MAAA,OAAO,CAAC,MAAc,UAAwB;AAC1D,MAAIA,6CAAwB;AAE1B,QAAA,iBAAiBC,QACjB,wBAAA,iBAAiBC,QAAAA;AAChB;AAAA,SAEK;AACCC,gBAAA,UAAU,SAAU,OAAK;AAC/B,cAAM,mBAAmB,IAAI;AAC7BC,kBAAAA,iBAAwB,OAAO;AAAA,UAC9B,GAAI,iBAAiB,QAAQ,EAAE,OAAO,EAAE,OAAO,MAAM,YAAY,CAAA;AAAA,QAAA,CACjE;AAAA,MAAA,CACD;AAAA,IACF;AAAA,EACD;AACD;AAEO,MAAM,SAA8B,CAAC,OAAO,KAAK,MAAM,SAAc;AACtE,OAAA,IAAI,MAAM,KAAK;;AAErB;AAEa,MAAA,MAA0D,CACtE,SACG;AACH,OAAK,KAAK,cAAc,KAAK,GAAG,GAAG,KAAK,KAAK;AAC9C;;;;"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { UnauthenticatedError, UnauthorizedError } from "@slicemachine/manager";
|
|
1
2
|
import { checkIsSentryEnabled } from "./checkIsSentryEnabled.js";
|
|
2
3
|
import { withScope, captureException } from './../_node_modules/@sentry/node/_node_modules/@sentry/core/esm/exports.js';
|
|
3
4
|
const node = (name, error) => {
|
|
4
5
|
if (checkIsSentryEnabled()) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (error instanceof UnauthenticatedError || error instanceof UnauthorizedError)
|
|
7
|
+
;
|
|
8
|
+
else {
|
|
9
|
+
withScope(function(scope) {
|
|
10
|
+
scope.setTransactionName(name);
|
|
11
|
+
captureException(error, {
|
|
12
|
+
...error instanceof Error ? { extra: { cause: error.cause } } : {}
|
|
13
|
+
});
|
|
9
14
|
});
|
|
10
|
-
}
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
18
|
const server = (error, req, _res, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryErrorHandlers.js","sources":["../../../src/lib/sentryErrorHandlers.ts"],"sourcesContent":["import type { ErrorRequestHandler } from \"express\";\nimport * as Sentry from \"@sentry/node\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"sentryErrorHandlers.js","sources":["../../../src/lib/sentryErrorHandlers.ts"],"sourcesContent":["import type { ErrorRequestHandler } from \"express\";\nimport * as Sentry from \"@sentry/node\";\n\nimport {\n\tCreateSliceMachineManagerMiddlewareArgs,\n\tUnauthenticatedError,\n\tUnauthorizedError,\n} from \"@slicemachine/manager\";\n\nimport { checkIsSentryEnabled } from \"./checkIsSentryEnabled\";\n\nexport const node = (name: string, error: unknown): void => {\n\tif (checkIsSentryEnabled()) {\n\t\tif (\n\t\t\terror instanceof UnauthenticatedError ||\n\t\t\terror instanceof UnauthorizedError\n\t\t) {\n\t\t\t// noop - User is not logged in or does not have access to the repository, no need to track this error in Sentry.\n\t\t} else {\n\t\t\tSentry.withScope(function (scope) {\n\t\t\t\tscope.setTransactionName(name);\n\t\t\t\tSentry.captureException(error, {\n\t\t\t\t\t...(error instanceof Error ? { extra: { cause: error.cause } } : {}),\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n};\n\nexport const server: ErrorRequestHandler = (error, req, _res, next): void => {\n\tnode(req.path, error);\n\tnext();\n};\n\nexport const rpc: CreateSliceMachineManagerMiddlewareArgs[\"onError\"] = (\n\targs,\n) => {\n\tnode(args.procedurePath.join(\".\"), args.error);\n};\n"],"names":["Sentry.withScope","Sentry.captureException"],"mappings":";;;AAWa,MAAA,OAAO,CAAC,MAAc,UAAwB;AAC1D,MAAI,wBAAwB;AAE1B,QAAA,iBAAiB,wBACjB,iBAAiB;AAChB;AAAA,SAEK;AACCA,gBAAU,SAAU,OAAK;AAC/B,cAAM,mBAAmB,IAAI;AAC7BC,yBAAwB,OAAO;AAAA,UAC9B,GAAI,iBAAiB,QAAQ,EAAE,OAAO,EAAE,OAAO,MAAM,YAAY,CAAA;AAAA,QAAA,CACjE;AAAA,MAAA,CACD;AAAA,IACF;AAAA,EACD;AACD;AAEO,MAAM,SAA8B,CAAC,OAAO,KAAK,MAAM,SAAc;AACtE,OAAA,IAAI,MAAM,KAAK;;AAErB;AAEa,MAAA,MAA0D,CACtE,SACG;AACH,OAAK,KAAK,cAAc,KAAK,GAAG,GAAG,KAAK,KAAK;AAC9C;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const version = "0.12.60-alpha.xru-prevent-sentry-errors.1";
|
|
3
|
+
const version = "0.12.60-alpha.xru-prevent-sentry-errors-2.1";
|
|
4
4
|
exports.version = version;
|
|
5
5
|
//# sourceMappingURL=package.json.cjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "start-slicemachine",
|
|
3
|
-
"version": "0.12.60-alpha.xru-prevent-sentry-errors.1",
|
|
3
|
+
"version": "0.12.60-alpha.xru-prevent-sentry-errors-2.1",
|
|
4
4
|
"description": "Start Slice Machine from within a project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@prismicio/mocks": "2.14.0",
|
|
59
59
|
"@prismicio/types-internal": "3.11.2",
|
|
60
|
-
"@slicemachine/manager": "0.25.2-alpha.xru-prevent-sentry-errors.1",
|
|
60
|
+
"@slicemachine/manager": "0.25.2-alpha.xru-prevent-sentry-errors-2.1",
|
|
61
61
|
"body-parser": "^1.20.3",
|
|
62
62
|
"chalk": "^4.1.2",
|
|
63
63
|
"cors": "^2.8.5",
|
|
@@ -120,19 +120,7 @@ export class StartSliceMachineProcess {
|
|
|
120
120
|
const app = await createSliceMachineExpressApp({
|
|
121
121
|
sliceMachineManager: this._sliceMachineManager,
|
|
122
122
|
});
|
|
123
|
-
|
|
124
123
|
const server = app.listen(this.port);
|
|
125
|
-
server.on("error", (error: NodeJS.ErrnoException) => {
|
|
126
|
-
if (error.code === "EADDRINUSE") {
|
|
127
|
-
console.error(
|
|
128
|
-
`Error starting Slice Machine: Port ${this.port} is already in use. Please try a different port.`,
|
|
129
|
-
);
|
|
130
|
-
} else {
|
|
131
|
-
console.error("Error starting Slice Machine:", error);
|
|
132
|
-
}
|
|
133
|
-
process.exit(1);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
124
|
const address = server.address() as AddressInfo;
|
|
137
125
|
const url = `http://localhost:${address.port}`;
|
|
138
126
|
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import type { ErrorRequestHandler } from "express";
|
|
2
2
|
import * as Sentry from "@sentry/node";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CreateSliceMachineManagerMiddlewareArgs,
|
|
6
|
+
UnauthenticatedError,
|
|
7
|
+
UnauthorizedError,
|
|
8
|
+
} from "@slicemachine/manager";
|
|
5
9
|
|
|
6
10
|
import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
|
|
7
11
|
|
|
8
12
|
export const node = (name: string, error: unknown): void => {
|
|
9
13
|
if (checkIsSentryEnabled()) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
if (
|
|
15
|
+
error instanceof UnauthenticatedError ||
|
|
16
|
+
error instanceof UnauthorizedError
|
|
17
|
+
) {
|
|
18
|
+
// noop - User is not logged in or does not have access to the repository, no need to track this error in Sentry.
|
|
19
|
+
} else {
|
|
20
|
+
Sentry.withScope(function (scope) {
|
|
21
|
+
scope.setTransactionName(name);
|
|
22
|
+
Sentry.captureException(error, {
|
|
23
|
+
...(error instanceof Error ? { extra: { cause: error.cause } } : {}),
|
|
24
|
+
});
|
|
14
25
|
});
|
|
15
|
-
}
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
28
|
};
|
|
18
29
|
|