Skip to content

Commit

Permalink
fix(pkg): handle bundledDependencies correctly (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 19, 2024
1 parent 2c3ebb3 commit cd94a16
Show file tree
Hide file tree
Showing 9 changed files with 1,058 additions and 1,049 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-gifts-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-plugin-pkg": patch
---

fix: handle `bundledDependencies` correctly
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"github-markdown-css": "^5.4.0",
"linguist-languages": "^7.27.0",
"lodash": "^4.17.21",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"prettier-plugin-autocorrect": "workspace:*",
"prettier-plugin-pkg": "workspace:*",
"prettier-plugin-sh": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Keys in `scripts` are ordered alphabetically. Use prefixes wisely to properly or

Top-level keys are sorted according to a style commonly seen in the packages of [@JounQin](https://github.com/JounQin), [@1stG](https://github.com/1stG) and [@unts](https://github.com/un-ts). Known keys, and their order are

<!-- prettier-ignore -->
```jsonc
[
// schema definition
Expand Down
10 changes: 7 additions & 3 deletions packages/pkg/src/rules/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
included in all copies or substantial portions of this Source Code Form.
*/

import type { ObjectExpression, ObjectProperty } from '../types.js'
import { sortObject } from '../utils.js'
import type { ObjectProperty, StringLiteral } from '../types.js'
import { sortObject, sortStringArray } from '../utils.js'

const process = (props: ObjectProperty[], key: string) => {
const item = props.find(prop => prop.key.value === key)

if (item) {
;(item.value as ObjectExpression).properties.sort(sortObject)
if ('elements' in item.value) {
;(item.value.elements as StringLiteral[]).sort(sortStringArray)
} else if ('properties' in item.value) {
item.value.properties.sort(sortObject)
}
}

return props
Expand Down
22 changes: 22 additions & 0 deletions packages/pkg/test/fixtures/fixture3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"dummy": true,
"devDependencies": {
"glob": "1.0.0",
"eslint": "2.x"
},
"peerDependencies": {
"eslint": "2.x"
},
"dependencies": {
"@org/package": "^1.0.0",
"esm-package": "^1.0.0",
"jquery": "^3.1.0",
"lodash.cond": "^4.3.0",
"find-up": "^1.0.0",
"rxjs": "^1.0.0"
},
"optionalDependencies": {
"lodash.isarray": "^4.0.0"
},
"bundledDependencies": ["@generated/foo"]
}
3 changes: 2 additions & 1 deletion packages/pkg/test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { type Options, format } from 'prettier'

import pkg1 from './fixtures/fixture1.json'
import pkg2 from './fixtures/fixture2.json'
import pkg3 from './fixtures/fixture3.json'

import PkgPlugin from 'prettier-plugin-pkg'

const pkgs = [pkg1, pkg2]
const pkgs = [pkg1, pkg2, pkg3]

const createFixture = (index: 0 | 1 = 0) => {
const pkg: Record<string, unknown> = pkgs[index]
Expand Down
1 change: 0 additions & 1 deletion packages/sh/test/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('parser and printer', () => {
filepath,
parser: 'sh',
plugins: [ShPlugin],
// @ts-expect-error
experimentalWasm: true,
})

Expand Down
1 change: 0 additions & 1 deletion packages/sh/test/shellscript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ test('fatal parse error with meaningful message', async () => {
filepath: 'broken.sh',
parser: 'sh',
plugins: [ShPlugin],
// @ts-expect-error
experimentalWasm: true,
})
} catch (err: unknown) {
Expand Down

0 comments on commit cd94a16

Please sign in to comment.