Skip to content

Commit

Permalink
fix(sourcemaps): Re-read package.json when modifying build command (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 authored Nov 10, 2023
1 parent e1352ce commit 7063fb8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- fix(sourcemaps): Re-read package.json when modifying build command #493

## 3.16.2

- fix(sourcemaps): Re-read package.json after CLI install (#489)
Expand Down
9 changes: 4 additions & 5 deletions src/sourcemaps/tools/sentry-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../utils/clack-utils';

import { SourceMapUploadToolConfigurationOptions } from './types';
import { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';
import { hasPackageInstalled } from '../../utils/package-json';
import { traceStep } from '../../telemetry';
import { detectPackageManger, NPM } from '../../utils/package-manager';

Expand Down Expand Up @@ -82,7 +82,7 @@ export async function configureSentryCLI(

if (await askShouldAddToBuildCommand()) {
await traceStep('sentry-cli-add-to-build-cmd', () =>
addSentryCommandToBuildCommand(packageDotJson),
addSentryCommandToBuildCommand(),
);
} else {
clack.log.info(
Expand Down Expand Up @@ -191,9 +191,8 @@ async function askShouldAddToBuildCommand(): Promise<boolean> {
*
* @param packageDotJson The package.json which will be modified.
*/
export async function addSentryCommandToBuildCommand(
packageDotJson: PackageDotJson,
): Promise<void> {
export async function addSentryCommandToBuildCommand(): Promise<void> {
const packageDotJson = await getPackageDotJson();
// This usually shouldn't happen because earlier we added the
// SENTRY_NPM_SCRIPT_NAME script but just to be sure
packageDotJson.scripts = packageDotJson.scripts || {};
Expand Down
19 changes: 12 additions & 7 deletions test/sourcemaps/tools/sentry-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ jest.mock('@clack/prompts', () => {
};
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
jest.mock('../../../src/utils/clack-utils', () => ({
...jest.requireActual('../../../src/utils/clack-utils'),
getPackageDotJson: jest.fn().mockResolvedValue({
scripts: {
build: 'tsc',
},
version: '1.0.0',
}),
}));

describe('addSentryCommandToBuildCommand', () => {
afterEach(() => {
jest.clearAllMocks();
Expand All @@ -34,13 +45,7 @@ describe('addSentryCommandToBuildCommand', () => {
jest
.spyOn(packageManagerHelpers, 'detectPackageManger')
.mockReturnValue(pacMan);
const packageJson = {
scripts: {
build: 'tsc',
},
version: '1.0.0',
};
await addSentryCommandToBuildCommand(packageJson);
await addSentryCommandToBuildCommand();
expect(writeFileSpy).toHaveBeenCalledWith(
expect.stringContaining('package.json'),
expect.stringContaining(
Expand Down

0 comments on commit 7063fb8

Please sign in to comment.