Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg): handle bundledDependencies correctly #343

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)

Check warning on line 18 in packages/pkg/src/rules/object.ts

View check run for this annotation

Codecov / codecov/patch

packages/pkg/src/rules/object.ts#L18

Added line #L18 was not covered by tests
} 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