dhoulb / multi-semantic-release

Proof of concept that wraps semantic-release to work with monorepos.
BSD Zero Clause License
203 stars 36 forks source link

Preserve trailing newline and don't include unnecessary dependency fields in package.json #31

Closed cherryblossom000 closed 4 years ago

cherryblossom000 commented 4 years ago

I had a package.json like this:

{
  "name": "test",
  "version": "1.1.0",
  "dependencies": {
    "foo": "*"
  },
  "devDependencies": {
    "bar": "*"
  }
}

The file had a trailing newline.

After triggering a release, multi-semantic-release converted package.json to:

{
  "name": "test",
  "version": "1.1.0",
  "dependencies": {
    "foo": "*"
  },
  "devDependencies": {
    "bar": "*"
  },
  "peerDependencies": {},
  "optionalDependencies": {}
}

without a trailing newline.

I know this isn't that important — I could always make a plugin that removes these fields and adds the trailing newline — but it would be nice for multi-semantic-release to preserve trailing newlines and remove empty dependency fields before writing package.json because I commit the updated package.json using @semantic-release/git.

antongolub commented 4 years ago

@cherryblossom000

It's reasonable and doesn't look complicated. Should we implement this proposal or you'd like to make a pull request?

antongolub commented 4 years ago

I suggest to create a separate file and also to move indent resolver into it.

recognizeFormat = (content) => {
  const indent = ...
  const eofTrailing = ...

  return {
    indent,
    eofTrailing
  }
}
cherryblossom000 commented 4 years ago

@antongolub I'll work on this.

antongolub commented 4 years ago

Great. I'm going to make a small fix: msr doesn't seem to update optional dependencies.

antongolub commented 4 years ago

@cherryblossom000

I fixed the manifest patching: now scopes are not added to package.json if they were not there initially.

dhoulb commented 4 years ago

:tada: This issue has been resolved in version 2.4.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: