Skip to content

Commit

Permalink
fix(sourcemaps): Re-read package.json after CLI install (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 authored Nov 3, 2023
1 parent 2431343 commit 000d96a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- fix(sourcemaps): Re-read package.json after CLI install (#489)
- fix(nextjs): Set created test route handler to always be dynamic (#486)

## 3.16.1
Expand Down
11 changes: 3 additions & 8 deletions src/remix/sdk-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getInitCallInsertionIndex, hasSentryContent } from './utils';
import { instrumentRootRouteV1 } from './codemods/root-v1';
import { instrumentRootRouteV2 } from './codemods/root-v2';
import { instrumentHandleError } from './codemods/handle-error';
import { getPackageDotJson } from '../utils/clack-utils';

export type PartialRemixConfig = {
unstable_dev?: boolean;
Expand Down Expand Up @@ -166,13 +167,7 @@ export async function updateBuildScript(args: {
url?: string;
isHydrogen: boolean;
}): Promise<void> {
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// Add sourcemaps option to build script
const packageJsonPath = path.join(process.cwd(), 'package.json');
const packageJsonString = (
await fs.promises.readFile(packageJsonPath)
).toString();
const packageJson = JSON.parse(packageJsonString);
const packageJson = await getPackageDotJson();

if (!packageJson.scripts) {
packageJson.scripts = {};
Expand Down Expand Up @@ -200,7 +195,7 @@ export async function updateBuildScript(args: {
}

await fs.promises.writeFile(
packageJsonPath,
path.join(process.cwd(), 'package.json'),
JSON.stringify(packageJson, null, 2),
);

Expand Down
9 changes: 3 additions & 6 deletions src/sourcemaps/tools/sentry-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ export async function configureSentryCLI(

await configureSourcemapGenerationFlow();

await createAndAddNpmScript(
packageDotJson,
options,
relativePosixArtifactPath,
);
await createAndAddNpmScript(options, relativePosixArtifactPath);

if (await askShouldAddToBuildCommand()) {
await traceStep('sentry-cli-add-to-build-cmd', () =>
Expand Down Expand Up @@ -135,7 +131,6 @@ export async function setupNpmScriptInCI(): Promise<void> {
}

async function createAndAddNpmScript(
packageDotJson: PackageDotJson,
options: SourceMapUploadToolConfigurationOptions,
relativePosixArtifactPath: string,
): Promise<void> {
Expand All @@ -149,6 +144,8 @@ async function createAndAddNpmScript(
options.projectSlug
} ${relativePosixArtifactPath}`;

const packageDotJson = await getPackageDotJson();

packageDotJson.scripts = packageDotJson.scripts || {};
packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;

Expand Down
6 changes: 6 additions & 0 deletions src/utils/clack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ Or setup using ${chalk.cyan(
});
}

/**
* Installs or updates a package with the user's package manager.
*
* IMPORTANT: This function modifies the `package.json`! Be sure to re-read
* it if you make additional modifications to it after calling this function!
*/
export async function installPackage({
packageName,
alreadyInstalled,
Expand Down

0 comments on commit 000d96a

Please sign in to comment.