Skip to content

Commit

Permalink
fix(bootstrap): preserve indentation style in package-lock.json when …
Browse files Browse the repository at this point in the history
…running bootstrap (#2955)
  • Loading branch information
richardkazuomiller committed Jun 17, 2022
1 parent 72d7af8 commit 04cfa52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions utils/npm-install/__tests__/npm-install.test.js
Expand Up @@ -20,6 +20,7 @@ const { npmInstall, npmInstallDependencies } = require("..");
describe("npm-install", () => {
childProcess.exec.mockResolvedValue();
fs.rename.mockResolvedValue();
fs.copy.mockResolvedValue();
writePkg.mockResolvedValue();

describe("npmInstall()", () => {
Expand Down Expand Up @@ -141,7 +142,7 @@ describe("npm-install", () => {

await npmInstallDependencies(pkg, dependencies, {});

expect(fs.rename).toHaveBeenLastCalledWith(pkg.manifestLocation, backupManifest);
expect(fs.copy).toHaveBeenLastCalledWith(pkg.manifestLocation, backupManifest);
expect(fs.renameSync).toHaveBeenLastCalledWith(backupManifest, pkg.manifestLocation);
expect(writePkg).toHaveBeenLastCalledWith(pkg.manifestLocation, {
name: "npm-install-deps",
Expand Down Expand Up @@ -463,19 +464,19 @@ describe("npm-install", () => {
});
});

it("rejects with rename error", async () => {
it("rejects with copy error", async () => {
const pkg = new Package(
{
name: "npm-install-deps-rename-error",
name: "npm-install-deps-copy-error",
version: "1.0.0",
},
path.normalize("/test/npm-install-deps/renameError")
path.normalize("/test/npm-install-deps/copyError")
);
const dependencies = ["I'm just here so we don't exit early"];

fs.rename.mockRejectedValueOnce(new Error("Unable to rename file"));
fs.copy.mockRejectedValueOnce(new Error("Unable to copy file"));

await expect(npmInstallDependencies(pkg, dependencies, {})).rejects.toThrow("Unable to rename file");
await expect(npmInstallDependencies(pkg, dependencies, {})).rejects.toThrow("Unable to copy file");
});

it("cleans up synchronously after writeFile error", async () => {
Expand Down
2 changes: 1 addition & 1 deletion utils/npm-install/npm-install.js
Expand Up @@ -63,7 +63,7 @@ function npmInstallDependencies(pkg, dependencies, config) {

log.silly("npmInstallDependencies", "backup", pkg.manifestLocation);

return fs.rename(pkg.manifestLocation, packageJsonBkp).then(() => {
return fs.copy(pkg.manifestLocation, packageJsonBkp).then(() => {
const cleanup = () => {
log.silly("npmInstallDependencies", "cleanup", pkg.manifestLocation);
// Need to do this one synchronously because we might be doing it on exit.
Expand Down

0 comments on commit 04cfa52

Please sign in to comment.