Skip to content

Commit

Permalink
Remove JS SDK installation step (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Jul 19, 2024
1 parent d8ebad3 commit 75137a9
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 147 deletions.
122 changes: 0 additions & 122 deletions src/Sentry/Laravel/Console/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use RuntimeException;
use Sentry\Dsn;
use Sentry\Laravel\ServiceProvider;
use Symfony\Component\Process\Process;

class PublishCommand extends Command
{
Expand Down Expand Up @@ -90,9 +88,6 @@ public function handle(): int
if (!$this->setEnvValues($env)) {
return 1;
}
if ($this->confirm('Do you want to install one of our JavaScript SDKs?', !$this->option('without-javascript-sdk'))) {
$this->installJavaScriptSdk();
}

return 0;
}
Expand Down Expand Up @@ -165,121 +160,4 @@ private function askForDsnInput(): string
}
}
}

private function installJavaScriptSdk(): void
{
$framework = $this->choice(
'Which frontend framework are you using?',
[
self::SDK_CHOICE_BROWSER,
self::SDK_CHOICE_VUE,
self::SDK_CHOICE_REACT,
self::SDK_CHOICE_ANGULAR,
self::SDK_CHOICE_SVELTE,
],
self::SDK_CHOICE_BROWSER
);

$snippet = '';

switch ($framework) {
case self::SDK_CHOICE_BROWSER:
$this->updateNodePackages(function ($packages) {
return [
'@sentry/browser' => '^7.40.0',
] + $packages;
});
$snippet = file_get_contents(__DIR__ . '/../../../../stubs/sentry-javascript/browser.js');
break;
case self::SDK_CHOICE_VUE:
$this->updateNodePackages(function ($packages) {
return [
'@sentry/vue' => '^7.40.0',
] + $packages;
});
$snippet = file_get_contents(__DIR__ . '/../../../../stubs/sentry-javascript/vue.js');
break;
case self::SDK_CHOICE_REACT:
$this->updateNodePackages(function ($packages) {
return [
'@sentry/react' => '^7.40.0',
] + $packages;
});
$snippet = file_get_contents(__DIR__ . '/../../../../stubs/sentry-javascript/react.js');
break;
case self::SDK_CHOICE_ANGULAR:
$this->updateNodePackages(function ($packages) {
return [
'@sentry/angular' => '^7.40.0',
] + $packages;
});
$snippet = file_get_contents(__DIR__ . '/../../../../stubs/sentry-javascript/angular.js');
break;
case self::SDK_CHOICE_SVELTE:
$this->updateNodePackages(function ($packages) {
return [
'@sentry/svelte' => '^7.40.0',
] + $packages;
});
$snippet = file_get_contents(__DIR__ . '/../../../../stubs/sentry-javascript/svelte.js');
break;
}

$env['VITE_SENTRY_DSN_PUBLIC'] ='"${SENTRY_LARAVEL_DSN}"';
$this->setEnvValues($env);

if (file_exists(base_path('pnpm-lock.yaml'))) {
$this->runCommands(['pnpm install']);
} elseif (file_exists(base_path('yarn.lock'))) {
$this->runCommands(['yarn install']);
} else {
$this->runCommands(['npm install']);
}

$this->newLine();
$this->components->info('Sentry JavaScript SDK installed successfully.');
$this->line('Put the following snippet into your JavaScript entry file:');
$this->newLine();
$this->line('<bg=blue>' . $snippet . '</>');
$this->newLine();
$this->line('For the best Sentry experience, we recommend you to set up dedicated projects for your Laravel and JavaScript applications.');
}

private function updateNodePackages(callable $callback)
{
if (! file_exists(base_path('package.json'))) {
return;
}

$packages = json_decode(file_get_contents(base_path('package.json')), true);

$packages['dependencies'] = $callback(
array_key_exists('dependencies', $packages) ? $packages['dependencies'] : [],
'dependencies'
);

ksort($packages['dependencies']);

file_put_contents(
base_path('package.json'),
json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL
);
}

private function runCommands($commands)
{
$process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null);

if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
$this->output->writeln(' <bg=yellow;fg=black> WARN </> '.$e->getMessage().PHP_EOL);
}
}

$process->run(function ($type, $line) {
$this->output->write(' '.$line);
});
}
}
5 changes: 0 additions & 5 deletions stubs/sentry-javascript/angular.js

This file was deleted.

5 changes: 0 additions & 5 deletions stubs/sentry-javascript/browser.js

This file was deleted.

5 changes: 0 additions & 5 deletions stubs/sentry-javascript/react.js

This file was deleted.

5 changes: 0 additions & 5 deletions stubs/sentry-javascript/svelte.js

This file was deleted.

5 changes: 0 additions & 5 deletions stubs/sentry-javascript/vue.js

This file was deleted.

0 comments on commit 75137a9

Please sign in to comment.