Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
fix(package-json): parsed the file properly
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Apr 25, 2020
1 parent 0e62c55 commit e4a5e94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/scripts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ suite('scripts lifter', () => {
const scripts = any.simpleObject();
const originalScripts = any.simpleObject();
const packageJsonContents = any.simpleObject();
fs.readFile.withArgs(pathToPackageJson, 'utf8').resolves({...packageJsonContents, scripts: originalScripts});
fs.readFile
.withArgs(pathToPackageJson, 'utf8')
.resolves(JSON.stringify({...packageJsonContents, scripts: originalScripts}));

await liftScripts({projectRoot, scripts});

assert.calledWith(
fs.writeFile,
pathToPackageJson,
{...packageJsonContents, scripts: {...originalScripts, ...scripts}}
JSON.stringify({...packageJsonContents, scripts: {...originalScripts, ...scripts}})
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export default async function ({projectRoot, scripts}) {
if (scripts) {
const pathToPackageJson = `${projectRoot}/package.json`;

const existingPackageJsonContents = await fs.readFile(pathToPackageJson, 'utf8');
const existingPackageJsonContents = JSON.parse(await fs.readFile(pathToPackageJson, 'utf8'));

await fs.writeFile(
pathToPackageJson,
{...existingPackageJsonContents, scripts: {...existingPackageJsonContents.scripts, ...scripts}}
JSON.stringify({...existingPackageJsonContents, scripts: {...existingPackageJsonContents.scripts, ...scripts}})
);
}
}

0 comments on commit e4a5e94

Please sign in to comment.