Skip to content

Commit

Permalink
refactor: migrate to esm and update dependencies (#269)
Browse files Browse the repository at this point in the history
BODY?

BREAKING CHANGE: This module is now a pure ESM module
  • Loading branch information
fisker authored Sep 29, 2022
1 parent 50f9102 commit 8b92375
Show file tree
Hide file tree
Showing 19 changed files with 11,342 additions and 13,445 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
with:
node-version: ${{ matrix.node_version }}

# https://github.com/bahmutov/npm-install/issues/103#issuecomment-931226602
- name: Update NPM
run: npm install --global npm

- name: Install Dependencies
run: npm ci

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
# https://github.com/bahmutov/npm-install/issues/103#issuecomment-931226602
- name: Update NPM
run: npm install --global npm
- name: Install dependencies
run: npm ci
- name: Release
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm t && lint-staged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Pass a JSON string, return a new sorted JSON string.\
Pass a JSON object, return a new sorted JSON object.
```js
const sortPackageJson = require('sort-package-json')
import sortPackageJson from 'sort-package-json'

const packageJsonString = `{
"dependencies": {
Expand Down Expand Up @@ -228,7 +228,7 @@ Could be. I wanted this one because at the time of writing, nothing is:
### I would like this tool to be configurable with a config file or command line arguments.
The lack of configuration here is a feature, not a bug. The intent of this tool is that a user can open a package json and always expect to see keys in a particular order. If we add a configuration for this tool, then that promise is broken, as users will first need to look at the configuration for each project to learn the ways in which this tool will change the `package.json`. The structure of the `package.json` should always be predictable & deterministic from project to project. I think the _reason_ why this project is well used is because it is not another "tool" you have to set up with yet another JSON file and more cruft in your project to support it. You run a command and it does what it says on the tin.
The lack of configuration here is a feature, not a bug. The intent of this tool is that a user can open a package json and always expect to see keys in a particular order. If we add a configuration for this tool, then that promise is broken, as users will first need to look at the configuration for each project to learn the ways in which this tool will change the `package.json`. The structure of the `package.json` should always be predictable & deterministic from project to project. I think the _reason_ why this project is well used is because it is not another "tool" you have to set up with yet another JSON file and more cruft in your project to support it. You run a command and it does what it says on the tin.
A lot of people who ask for configuration cite the use case that they simply don't like the given order that exists and want to make sweeping changes. To me this seems far better suited to simply making a fork of this project as then you can go far further than specifying configuration.
Expand Down
8 changes: 4 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const fs = require('fs')
const globby = require('globby')
const sortPackageJson = require('.')
import fs from 'node:fs'
import { globbySync } from 'globby'
import sortPackageJson from './index.js'

const isCheckFlag = (argument) => argument === '--check' || argument === '-c'

Expand All @@ -14,7 +14,7 @@ if (!patterns.length) {
patterns[0] = 'package.json'
}

const files = globby.sync(patterns)
const files = globbySync(patterns)

if (files.length === 0) {
console.log('No matching files.')
Expand Down
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const sortObjectKeys = require('sort-object-keys')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline').graceful
const gitHooks = require('git-hooks-list')
const isPlainObject = require('is-plain-obj')
import sortObjectKeys from 'sort-object-keys'
import detectIndent from 'detect-indent'
import { detectNewlineGraceful as detectNewline } from 'detect-newline'
import gitHooks from 'git-hooks-list'
import isPlainObject from 'is-plain-obj'

const hasOwnProperty = (object, property) =>
Object.prototype.hasOwnProperty.call(object, property)
Expand Down Expand Up @@ -367,7 +367,5 @@ function sortPackageJson(jsonIsh, options = {}) {
)
}

module.exports = sortPackageJson
module.exports.sortPackageJson = sortPackageJson
module.exports.sortOrder = defaultSortOrder
module.exports.default = sortPackageJson
export default sortPackageJson
export { defaultSortOrder as sortOrder }
Loading

0 comments on commit 8b92375

Please sign in to comment.