Skip to content
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

Remove JS SDK installation step #930

Merged
merged 1 commit into from
Jul 19, 2024
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
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.