Skip to content

fix: locate sentry-cli when working with a mono-repo #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const { execSync } = require('child_process');
const BasePlugin = require('ember-cli-deploy-plugin');
const packageJson = require("./package.json");

// Dynamically resolve `sentry-cli` location
const sentryCliPackagePath = require.resolve("@sentry/cli/package.json");
const { dir: sentryCliDirectory } = path.parse(sentryCliPackagePath);
const sentryCliRelativeBinLocation =
require(sentryCliPackagePath).bin["sentry-cli"];
const sentryCliAbsoluteBinLocation = path.join(
sentryCliDirectory,
sentryCliRelativeBinLocation
);

module.exports = {
name: packageJson.name,

Expand Down Expand Up @@ -93,7 +103,7 @@ module.exports = {

return this._exec(
[
path.join("node_modules", ".bin", "sentry-cli"),
sentryCliAbsoluteBinLocation,
url ? `--url ${url}` : "",
`--auth-token ${authToken}`,
command,
Expand Down
45 changes: 10 additions & 35 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const sinon = require('sinon');
const path = require('path');
const Plugin = require('../../index');

const { dir: PROJECT_ROOT } = path.parse(require.resolve('../../package.json'));
const SENTRY_BIN_PATH = path.join(PROJECT_ROOT, 'node_modules/@sentry/cli/bin/sentry-cli');

function setupSinon() {
before(function () {
this.sinon = sinon.createSandbox();
Expand Down Expand Up @@ -162,11 +165,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project new my-project@v1.0.0@1234567`
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project new my-project@v1.0.0@1234567`
);
});

Expand All @@ -180,11 +179,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project set-commits my-project@v1.0.0@1234567 --auto --ignore-missing`
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project set-commits my-project@v1.0.0@1234567 --auto --ignore-missing`
);
});

Expand All @@ -198,11 +193,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project files my-project@v1.0.0@1234567 upload-sourcemaps --rewrite ${path.join(
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project files my-project@v1.0.0@1234567 upload-sourcemaps --rewrite ${path.join(
'my-dest-dir',
'assets'
)} `
Expand All @@ -221,11 +212,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project files my-project@v1.0.0@1234567 upload-sourcemaps --rewrite ${path.join(
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project files my-project@v1.0.0@1234567 upload-sourcemaps --rewrite ${path.join(
'my-dest-dir',
'assets'
)} --url-prefix ~/assets`
Expand All @@ -242,11 +229,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project finalize my-project@v1.0.0@1234567`
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project finalize my-project@v1.0.0@1234567`
);
});
});
Expand All @@ -262,11 +245,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project deploys my-project@v1.0.0@1234567 new -e my-production`
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project deploys my-project@v1.0.0@1234567 new -e my-production`
);
});
});
Expand All @@ -282,11 +261,7 @@ describe('sentry-cli', function () {

this.sinon.assert.calledWithExactly(
stub,
`${path.join(
'node_modules',
'.bin',
'sentry-cli'
)} --auth-token my-auth-token releases --org my-org --project my-project delete my-project@v1.0.0@1234567`
`${SENTRY_BIN_PATH} --auth-token my-auth-token releases --org my-org --project my-project delete my-project@v1.0.0@1234567`
);
});
});
Expand Down