@ohos-ports/bugsnag-cli 3.10.6-beta.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.
Binary file
@@ -0,0 +1,30 @@
1
+ import { BugsnagCreateBuildOptions, BugsnagUploadiOSOptions, BugsnagUploadJsOptions, BugsnagUploadAndroidOptions, BugsnagUploadReactNativeOptions } from './types';
2
+ /**
3
+ * Wrapper for Bugsnag CLI
4
+ */
5
+ declare class BugsnagCLI {
6
+ /**
7
+ * Convert camelCase to kebab-case
8
+ */
9
+ static camelToKebab(str: string): string;
10
+ /**
11
+ * Execute a Bugsnag CLI command
12
+ */
13
+ static run(command: string, options?: {}, target?: string): Promise<string>;
14
+ /**
15
+ * Upload sourcemaps to Bugsnag
16
+ * Provides nested methods for specific upload types.
17
+ */
18
+ static Upload: {
19
+ ReactNative: ((options?: BugsnagUploadReactNativeOptions, target?: string) => Promise<string>) & {
20
+ iOS: (options?: BugsnagUploadiOSOptions, target?: string) => Promise<string>;
21
+ Android: (options?: BugsnagUploadAndroidOptions, target?: string) => Promise<string>;
22
+ };
23
+ Js: (options?: BugsnagUploadJsOptions, target?: string) => Promise<string>;
24
+ };
25
+ /**
26
+ * Send build information to Bugsnag
27
+ */
28
+ static CreateBuild(options?: BugsnagCreateBuildOptions, target?: string): Promise<string>;
29
+ }
30
+ export = BugsnagCLI;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const child_process_1 = require("child_process");
36
+ const path = __importStar(require("path"));
37
+ /**
38
+ * Wrapper for Bugsnag CLI
39
+ */
40
+ class BugsnagCLI {
41
+ /**
42
+ * Convert camelCase to kebab-case
43
+ */
44
+ static camelToKebab(str) {
45
+ return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
46
+ }
47
+ /**
48
+ * Execute a Bugsnag CLI command
49
+ */
50
+ static run(command, options = {}, target = '') {
51
+ return new Promise((resolve, reject) => {
52
+ // Convert the options keys from camelCase to kebab-case
53
+ const kebabCaseOptions = Object.entries(options)
54
+ .map(([key, value]) => {
55
+ const kebabKey = BugsnagCLI.camelToKebab(key);
56
+ if (typeof value === 'boolean' && value === true) {
57
+ return [`--${kebabKey}`];
58
+ }
59
+ else if (typeof value !== 'boolean') {
60
+ return [`--${kebabKey}=${String(value)}`];
61
+ }
62
+ return [];
63
+ })
64
+ .flat();
65
+ const binPath = path.resolve(__dirname, path.join('..', 'bin', 'bugsnag-cli'));
66
+ // Prepare CLI arguments
67
+ const args = [
68
+ ...command.split(' ').filter(Boolean),
69
+ ...kebabCaseOptions,
70
+ ...(target.trim() ? [target.trim()] : [])
71
+ ];
72
+ // Execute the command
73
+ (0, child_process_1.execFile)(binPath, args, (error, stdout, stderr) => {
74
+ if (error) {
75
+ const errorMessage = `Command failed: ${binPath}\n` +
76
+ `Error: ${error.message}\n` +
77
+ `${stdout.trim()}`;
78
+ reject(errorMessage);
79
+ }
80
+ else {
81
+ resolve(stdout.trim());
82
+ }
83
+ });
84
+ });
85
+ }
86
+ /**
87
+ * Send build information to Bugsnag
88
+ */
89
+ static CreateBuild(options = {}, target = '') {
90
+ return new Promise((resolve, reject) => {
91
+ try {
92
+ const output = BugsnagCLI.run('create-build', options, target);
93
+ if (output instanceof Promise) {
94
+ output.then(resolve).catch(reject);
95
+ }
96
+ else {
97
+ resolve(output);
98
+ }
99
+ }
100
+ catch (error) {
101
+ reject(error);
102
+ }
103
+ });
104
+ }
105
+ }
106
+ /**
107
+ * Upload sourcemaps to Bugsnag
108
+ * Provides nested methods for specific upload types.
109
+ */
110
+ BugsnagCLI.Upload = {
111
+ ReactNative: Object.assign((options = {}, target = '') => BugsnagCLI.run('upload react-native', options, target), // Default ReactNative command
112
+ {
113
+ iOS: (options = {}, target = '') => BugsnagCLI.run('upload react-native-ios', options, target),
114
+ Android: (options = {}, target = '') => BugsnagCLI.run('upload react-native-android', options, target),
115
+ }),
116
+ Js: (options = {}, target = '') => BugsnagCLI.run('upload js', options, target),
117
+ };
118
+ module.exports = BugsnagCLI;
@@ -0,0 +1,62 @@
1
+ interface BaseOptions {
2
+ apiKey?: string;
3
+ dryRun?: boolean;
4
+ logLevel?: string;
5
+ port?: number;
6
+ failOnUploadError?: boolean;
7
+ verbose?: boolean;
8
+ overwrite?: boolean;
9
+ retries?: number;
10
+ timeout?: number;
11
+ }
12
+ export interface BugsnagCreateBuildOptions extends BaseOptions {
13
+ autoAssignRelease?: boolean;
14
+ buildApiRootUrl?: string;
15
+ builderName?: string;
16
+ metadata?: object;
17
+ provider?: string;
18
+ releaseStage?: string;
19
+ repository?: string;
20
+ revision?: string;
21
+ versionName?: string;
22
+ androidAab?: string;
23
+ appManifest?: string;
24
+ versionCode?: string;
25
+ bundleVersion?: string;
26
+ }
27
+ interface UploadOptions extends BaseOptions {
28
+ uploadApiRootUrl?: string;
29
+ projectRoot?: string;
30
+ dev?: boolean;
31
+ bundle?: string;
32
+ versionName?: string;
33
+ sourceMap?: string;
34
+ codeBundleId?: string;
35
+ }
36
+ export interface BugsnagUploadReactNativeOptions extends UploadOptions {
37
+ androidAppManifest?: string;
38
+ androidVariant?: string;
39
+ androidVersionCode?: string;
40
+ iosBundleVersion?: string;
41
+ iosPlist?: string;
42
+ iosScheme?: string;
43
+ iosXcodeProject?: string;
44
+ }
45
+ export interface BugsnagUploadiOSOptions extends UploadOptions {
46
+ sourceMap?: string;
47
+ bundleVersion?: string;
48
+ plist?: string;
49
+ scheme?: string;
50
+ xcodeProject?: string;
51
+ }
52
+ export interface BugsnagUploadAndroidOptions extends UploadOptions {
53
+ appManifest?: string;
54
+ variant?: string;
55
+ versionCode?: string;
56
+ }
57
+ export interface BugsnagUploadJsOptions extends UploadOptions {
58
+ baseUrl?: string;
59
+ bundleUrl?: string;
60
+ projectRoot?: string;
61
+ }
62
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@ohos-ports/bugsnag-cli",
3
+ "version": "3.10.6-beta.1",
4
+ "description": "BugSnag CLI (OpenHarmony port with prebuilt aarch64 binary)",
5
+ "main": "dist/bugsnag-cli-wrapper.js",
6
+ "types": "dist/bugsnag-cli-wrapper.d.ts",
7
+ "engines": {
8
+ "node": ">=18.0.0"
9
+ },
10
+ "bin": {
11
+ "bugsnag-cli": "bin/bugsnag-cli"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ohos-ports/ohos-ports.git",
16
+ "directory": "ports/bugsnag-cli/3.10.6"
17
+ },
18
+ "author": "BugSnag",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "homepage": "https://github.com/ohos-ports/ohos-ports/tree/main/ports/bugsnag-cli/3.10.6",
27
+ "dependencies": {
28
+ "undici": "^6.23.0",
29
+ "yaml": "^2.7.0"
30
+ },
31
+ "files": [
32
+ "bin/bugsnag-cli",
33
+ "dist",
34
+ "postinstall.js",
35
+ "supported-platforms.yml"
36
+ ],
37
+ "scripts": {
38
+ "postinstall": "node postinstall.js"
39
+ },
40
+ "os": [
41
+ "openharmony",
42
+ "linux"
43
+ ],
44
+ "cpu": [
45
+ "arm64"
46
+ ]
47
+ }
package/postinstall.js ADDED
@@ -0,0 +1,112 @@
1
+ const fs = require('fs')
2
+ const { Readable } = require('stream')
3
+ const { createWriteStream } = require('fs')
4
+ const path = require('path')
5
+ const os = require('os')
6
+ const YAML = require('yaml')
7
+ const { ProxyAgent, fetch } = require('undici')
8
+ const packageJson = require('./package.json')
9
+
10
+ const supportedPlatformsConfig = fs.readFileSync(
11
+ path.join(__dirname, 'supported-platforms.yml'),
12
+ 'utf8'
13
+ )
14
+
15
+ const supportedPlatforms = YAML.parse(supportedPlatformsConfig)
16
+ const { name, repository, version } = packageJson
17
+
18
+ const handleError = (msg) => {
19
+ console.error(msg)
20
+ process.exit(1)
21
+ }
22
+
23
+ const removeGitPrefixAndSuffix = (input) => {
24
+ let result = input.replace(/^git\+/, '')
25
+ result = result.replace(/\.git$/, '')
26
+ return result
27
+ }
28
+
29
+ const getPlatformMetadata = () => {
30
+ const type = os.type()
31
+ const architecture = os.arch()
32
+
33
+ for (const supportedPlatform of supportedPlatforms) {
34
+ if (type === supportedPlatform.TYPE && architecture === supportedPlatform.ARCHITECTURE) {
35
+ return supportedPlatform
36
+ }
37
+ }
38
+
39
+ const supportedPlatformsTable = supportedPlatforms.map((platform) => ({
40
+ Type: platform.TYPE,
41
+ Architecture: platform.ARCHITECTURE,
42
+ Artifact: platform.ARTIFACT_NAME
43
+ }))
44
+
45
+ handleError(
46
+ `Platform with type "${type}" and architecture "${architecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${JSON.stringify(
47
+ supportedPlatformsTable,
48
+ null,
49
+ 2
50
+ )}`
51
+ )
52
+ }
53
+
54
+ // Detect whether the binary at the given path is the npm placeholder script
55
+ // ("bugsnag-cli binary has not been installed successfully") rather than a
56
+ // real executable.
57
+ const isPlaceholderBinary = (filePath) => {
58
+ try {
59
+ const fd = fs.openSync(filePath, 'r')
60
+ const buf = Buffer.alloc(256)
61
+ const bytesRead = fs.readSync(fd, buf, 0, 256, 0)
62
+ fs.closeSync(fd)
63
+ const head = buf.slice(0, bytesRead).toString('utf8')
64
+ return head.startsWith('#!/usr/bin/env node') && head.includes('has not been installed successfully')
65
+ } catch (err) {
66
+ return false
67
+ }
68
+ }
69
+
70
+ const downloadBinaryFromGitHub = async (downloadUrl, outputPath) => {
71
+ try {
72
+ const binDir = path.resolve(process.cwd(), 'bin')
73
+ if (!fs.existsSync(binDir)) {
74
+ fs.mkdirSync(binDir, { recursive: true })
75
+ }
76
+
77
+ const proxy =
78
+ process.env.HTTPS_PROXY ||
79
+ process.env.HTTP_PROXY ||
80
+ process.env.https_proxy ||
81
+ process.env.http_proxy
82
+ const options = proxy ? { dispatcher: new ProxyAgent(proxy) } : {}
83
+
84
+ const resp = await fetch(downloadUrl, options)
85
+
86
+ if (resp.ok && resp.body) {
87
+ const writer = createWriteStream(outputPath)
88
+ Readable.fromWeb(resp.body).pipe(writer)
89
+ } else {
90
+ throw new Error(`Failed to download. Status: ${resp.status}`)
91
+ }
92
+
93
+ fs.chmodSync(outputPath, 0o755)
94
+ console.log('Binary downloaded successfully!')
95
+ } catch (err) {
96
+ console.error('Error downloading binary:', err.message)
97
+ }
98
+ }
99
+
100
+ const platformMetadata = getPlatformMetadata()
101
+ const repoUrl = removeGitPrefixAndSuffix(repository.url)
102
+ const binaryUrl = `${repoUrl}/releases/download/v${version}/${platformMetadata.ARTIFACT_NAME}`
103
+ const binaryOutputPath = path.join(process.cwd(), 'bin', platformMetadata.BINARY_NAME)
104
+
105
+ // On HarmonyOS (and any environment where a working bugsnag-cli binary has
106
+ // already been shipped in bin/), skip the GitHub release download and keep
107
+ // the locally provided binary.
108
+ if (fs.existsSync(binaryOutputPath) && !isPlaceholderBinary(binaryOutputPath)) {
109
+ console.log(`bugsnag-cli binary already present at ${binaryOutputPath}, skipping download.`)
110
+ } else {
111
+ downloadBinaryFromGitHub(binaryUrl, binaryOutputPath)
112
+ }
@@ -0,0 +1,64 @@
1
+ - TYPE: 'Windows'
2
+ ARCHITECTURE: 'x64'
3
+ ARTIFACT_NAME: 'x86_64-windows-bugsnag-cli.exe'
4
+ BINARY_NAME: 'bugsnag-cli.exe'
5
+
6
+ - TYPE: 'Windows'
7
+ ARCHITECTURE: 'i386'
8
+ ARTIFACT_NAME: 'i386-windows-bugsnag-cli.exe'
9
+ BINARY_NAME: 'bugsnag-cli.exe'
10
+
11
+ - TYPE: 'Windows_NT'
12
+ ARCHITECTURE: 'x64'
13
+ ARTIFACT_NAME: 'x86_64-windows-bugsnag-cli.exe'
14
+ BINARY_NAME: 'bugsnag-cli.exe'
15
+
16
+ - TYPE: 'Windows_NT'
17
+ ARCHITECTURE: 'i386'
18
+ ARTIFACT_NAME: 'i386-windows-bugsnag-cli.exe'
19
+ BINARY_NAME: 'bugsnag-cli.exe'
20
+
21
+ - TYPE: 'Linux'
22
+ ARCHITECTURE: 'x64'
23
+ ARTIFACT_NAME: 'x86_64-linux-bugsnag-cli'
24
+ BINARY_NAME: 'bugsnag-cli'
25
+
26
+ - TYPE: 'Linux'
27
+ ARCHITECTURE: 'arm64'
28
+ ARTIFACT_NAME: 'arm64-linux-bugsnag-cli'
29
+ BINARY_NAME: 'bugsnag-cli'
30
+
31
+ - TYPE: 'Linux'
32
+ ARCHITECTURE: 'aarch64'
33
+ ARTIFACT_NAME: 'arm64-linux-bugsnag-cli'
34
+ BINARY_NAME: 'bugsnag-cli'
35
+
36
+ - TYPE: 'Linux'
37
+ ARCHITECTURE: 'i386'
38
+ ARTIFACT_NAME: 'i386-linux-bugsnag-cli'
39
+ BINARY_NAME: 'bugsnag-cli'
40
+
41
+ - TYPE: 'Darwin'
42
+ ARCHITECTURE: 'x64'
43
+ ARTIFACT_NAME: 'x86_64-macos-bugsnag-cli'
44
+ BINARY_NAME: 'bugsnag-cli'
45
+
46
+ - TYPE: 'Darwin'
47
+ ARCHITECTURE: 'arm64'
48
+ ARTIFACT_NAME: 'arm64-macos-bugsnag-cli'
49
+ BINARY_NAME: 'bugsnag-cli'
50
+
51
+ # HarmonyOS support: the bugsnag-cli binary is a static aarch64 Go binary
52
+ # (GOOS=linux GOARCH=arm64 CGO_ENABLED=0) compiled from the upstream source
53
+ # repo and shipped locally in bin/bugsnag-cli by the HarmonyOS port.
54
+ # postinstall.js detects the already-present local binary and skips the
55
+ # GitHub release download, so no remote artifact is required here.
56
+ - TYPE: 'HarmonyOS'
57
+ ARCHITECTURE: 'arm64'
58
+ ARTIFACT_NAME: 'bugsnag-cli-ohos-arm64'
59
+ BINARY_NAME: 'bugsnag-cli'
60
+
61
+ - TYPE: 'OpenHarmony'
62
+ ARCHITECTURE: 'arm64'
63
+ ARTIFACT_NAME: 'bugsnag-cli-ohos-arm64'
64
+ BINARY_NAME: 'bugsnag-cli'