@sentry/wizard
Version:
Sentry wizard helping you to configure your project
405 lines (372 loc) • 17.1 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-useless-escape */
const vitest_1 = require("vitest");
const xcode_1 = require("../../src/react-native/xcode");
const chalk_1 = __importDefault(require("chalk"));
const clack_1 = require("../../src/utils/clack");
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const clack = __importStar(require("@clack/prompts"));
vitest_1.vi.mock('@clack/prompts', async () => ({
__esModule: true,
...(await vitest_1.vi.importActual('@clack/prompts')),
}));
const rnVersionWithQuotes = '0.81.0';
const rnVersionWithoutQuotes = '0.81.1';
(0, vitest_1.describe)('react-native xcode', () => {
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.spyOn(clack.log, 'error').mockImplementation(() => {
/* empty */
});
});
(0, vitest_1.afterEach)(() => {
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.describe)('addSentryBundledScriptsToBundleShellScript', () => {
(0, vitest_1.it)('adds sentry cli to rn bundle build phase', () => {
const input = `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"`;
// actual shell script looks like this:
// /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
// but during parsing xcode library removes the quotes
const expectedOutput = `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT \\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\\""`;
(0, vitest_1.expect)((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input, rnVersionWithQuotes)).toBe(expectedOutput);
});
(0, vitest_1.it)('does not add with-environment.sh parameter quotes for RN version >= 0.81.1 to rn bundle build phase', () => {
const input = `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"`;
const expectedOutput = `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT /bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE"`;
(0, vitest_1.expect)((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input, rnVersionWithoutQuotes)).toBe(expectedOutput);
});
(0, vitest_1.it)('does not add sentry cli to rn bundle build phase if $REACT_NATIVE_XCODE is not present and shows code snippet', () => {
const input = `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT $NOT_REACT_NATIVE_XCODE"`;
(0, vitest_1.expect)((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input, rnVersionWithQuotes)).toEqual(new xcode_1.ErrorPatchSnippet((0, clack_1.makeCodeSnippet)(true, (unchanged, plus, _minus) => {
return unchanged(`WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT ${plus(`\\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh `)}$REACT_NATIVE_XCODE${plus(`\\"`)}"
`);
})));
(0, vitest_1.expect)(clack.log.error).toHaveBeenCalledWith(`Failed to patch ${chalk_1.default.cyan('Bundle React Native code and images')} build phase.`);
});
(0, vitest_1.it)('adds sentry cli to expo bundle build phase', () => {
const input = `
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
# The project root by default is one level up from the ios directory
export PROJECT_ROOT="$PROJECT_DIR"/..
if [[ "$CONFIGURATION" = *Debug* ]]; then
export SKIP_BUNDLING=1
fi
if [[ -z "$ENTRY_FILE" ]]; then
# Set the entry JS file using the bundler's entry resolution.
export ENTRY_FILE="$("$NODE_BINARY" -e "require('expo/scripts/resolveAppEntry')" "$PROJECT_ROOT" ios absolute | tail -n 1)"
fi
if [[ -z "$CLI_PATH" ]]; then
# Use Expo CLI
export CLI_PATH="$("$NODE_BINARY" --print "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })")"
fi
if [[ -z "$BUNDLE_COMMAND" ]]; then
# Default Expo CLI command for bundling
export BUNDLE_COMMAND="export:embed"
fi
# Source .xcode.env.updates if it exists to allow
# SKIP_BUNDLING to be unset if needed
if [[ -f "$PODS_ROOT/../.xcode.env.updates" ]]; then
source "$PODS_ROOT/../.xcode.env.updates"
fi
# Source local changes to allow overrides
# if needed
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
\`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"\`
`;
const expectedOutput = `
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
# The project root by default is one level up from the ios directory
export PROJECT_ROOT="$PROJECT_DIR"/..
if [[ "$CONFIGURATION" = *Debug* ]]; then
export SKIP_BUNDLING=1
fi
if [[ -z "$ENTRY_FILE" ]]; then
# Set the entry JS file using the bundler's entry resolution.
export ENTRY_FILE="$("$NODE_BINARY" -e "require('expo/scripts/resolveAppEntry')" "$PROJECT_ROOT" ios absolute | tail -n 1)"
fi
if [[ -z "$CLI_PATH" ]]; then
# Use Expo CLI
export CLI_PATH="$("$NODE_BINARY" --print "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })")"
fi
if [[ -z "$BUNDLE_COMMAND" ]]; then
# Default Expo CLI command for bundling
export BUNDLE_COMMAND="export:embed"
fi
# Source .xcode.env.updates if it exists to allow
# SKIP_BUNDLING to be unset if needed
if [[ -f "$PODS_ROOT/../.xcode.env.updates" ]]; then
source "$PODS_ROOT/../.xcode.env.updates"
fi
# Source local changes to allow overrides
# if needed
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
/bin/sh \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/react-native/package.json')) + '/scripts/sentry-xcode.sh'"\` \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"\`
`;
(0, vitest_1.expect)((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input, rnVersionWithQuotes)).toBe(expectedOutput);
});
(0, vitest_1.it)('if patching fails it does not add sentry cli to expo bundle build phase and shows code snippet', () => {
const input = `
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
# The project root by default is one level up from the ios directory
export PROJECT_ROOT="$PROJECT_DIR"/..
if [[ "$CONFIGURATION" = *Debug* ]]; then
export SKIP_BUNDLING=1
fi
if [[ -z "$ENTRY_FILE" ]]; then
# Set the entry JS file using the bundler's entry resolution.
export ENTRY_FILE="$("$NODE_BINARY" -e "require('expo/scripts/resolveAppEntry')" "$PROJECT_ROOT" ios absolute | tail -n 1)"
fi
`;
(0, vitest_1.expect)((0, xcode_1.addSentryWithBundledScriptsToBundleShellScript)(input, rnVersionWithQuotes)).toEqual(new xcode_1.ErrorPatchSnippet((0, clack_1.makeCodeSnippet)(true, (unchanged, plus, _minus) => {
return unchanged(`${plus(`/bin/sh \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/react-native/package.json')) + '/scripts/sentry-xcode.sh'"\``)} \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"\``);
})));
(0, vitest_1.expect)(clack.log.error).toHaveBeenCalledWith(`Failed to patch ${chalk_1.default.cyan('Bundle React Native code and images')} build phase.`);
});
});
(0, vitest_1.describe)('findBundlePhase', () => {
(0, vitest_1.it)('returns build phase with react native xcode shell script', () => {
const inputMap = {
1: {
shellScript: 'foo',
},
2: {
shellScript: 'bar',
},
3: {
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
`,
},
4: {
shellScript: 'qux',
},
};
const expected = {
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
`,
};
(0, vitest_1.expect)((0, xcode_1.findBundlePhase)(inputMap)).toEqual(expected);
});
(0, vitest_1.it)('returns undefined if bundle phase not present', () => {
const inputMap = {
1: {
shellScript: 'foo',
},
2: {
shellScript: 'bar',
},
3: {
// note different path to the script
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/unknown/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
`,
},
4: {
shellScript: 'qux',
},
};
(0, vitest_1.expect)((0, xcode_1.findBundlePhase)(inputMap)).toBeUndefined();
});
});
(0, vitest_1.describe)('doesBundlePhaseIncludeSentry', () => {
(0, vitest_1.it)('returns true for script containing sentry cli calling react native xcode command', () => {
const input = {
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
SENTRY_CLI="sentry-cli react-native xcode"
/bin/sh -c "$WITH_ENVIRONMENT \"$SENTRY_CLI $REACT_NATIVE_XCODE\""
`,
};
(0, vitest_1.expect)((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeTruthy();
});
(0, vitest_1.it)('returns true for script containing sentry bundled script', () => {
const input = {
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
SENTRY_CLI="sentry-cli react-native xcode"
/bin/sh -c "$WITH_ENVIRONMENT \\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE"\\"
`,
};
(0, vitest_1.expect)((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeTruthy();
});
(0, vitest_1.it)('returns false', () => {
const input = {
// note sentry-cli can be part of the script but doesn't call react native xcode script
shellScript: `set -e
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
sentry-cli --version
`,
};
(0, vitest_1.expect)((0, xcode_1.doesBundlePhaseIncludeSentry)(input)).toBeFalsy();
});
});
(0, vitest_1.describe)('findDebugFilesUploadPhase', () => {
(0, vitest_1.it)('returns debug files build phase using debug files command', () => {
const input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: `set -e
sentry-cli debug-files upload path/to/dsym --include-sources
`,
},
};
const expected = [
'2',
{
shellScript: `set -e
sentry-cli debug-files upload path/to/dsym --include-sources
`,
},
];
(0, vitest_1.expect)((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
(0, vitest_1.it)('returns debug files build phase with sentry-cli absolute path', () => {
const input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: `set -e
/path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources
`,
},
};
const expected = [
'2',
{
shellScript: `set -e
/path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources
`,
},
];
(0, vitest_1.expect)((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
(0, vitest_1.it)('returns debug files build phase using dsym command', () => {
const input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: `set -e
sentry-cli upload-dsym path/to/dsym --include-sources
`,
},
};
const expected = [
'2',
{
shellScript: `set -e
sentry-cli upload-dsym path/to/dsym --include-sources
`,
},
];
(0, vitest_1.expect)((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
(0, vitest_1.it)('returns debug files build phase using bundled scripts', () => {
const input = {
1: {
shellScript: 'foo',
},
2: {
shellScript: `/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh`,
},
};
const expected = [
'2',
{
shellScript: `/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh`,
},
];
(0, vitest_1.expect)((0, xcode_1.findDebugFilesUploadPhase)(input)).toEqual(expected);
});
(0, vitest_1.it)('returns undefined if build phase not present', () => {
const input = {
1: {
shellScript: 'foo',
},
2: {
// sentry-cli present but with different command
shellScript: 'sentry-cli sourcempas upload',
},
};
(0, vitest_1.expect)((0, xcode_1.findDebugFilesUploadPhase)(input)).toBeUndefined();
});
});
});
//# sourceMappingURL=xcode.test.js.map