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

[Breaking] Update dependencies, jest -> vitest, build for Node 16+ #59

Merged
merged 6 commits into from
Apr 21, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .npmignore

This file was deleted.

4 changes: 2 additions & 2 deletions docs/DEBUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ yarn run compile && node --inspect-brk ./node_modules/.bin/prettier --config exa
You can set a `debugger` anywhere in the code and then use following command:

```shell
node --inspect-brk ./node_modules/.bin/jest -i
node --inspect-brk ./node_modules/.bin/vitest --run
```

Or, to debug a single unit test file

```shell
node --inspect-brk ./node_modules/.bin/jest -i <name-or-relative-path-of-the-file-file>
node --inspect-brk ./node_modules/.bin/vitest --run <name-or-relative-path-of-the-file-file>
```

### How to run prettier in any codebase using the plugin ?
Expand Down
14 changes: 0 additions & 14 deletions jest.config.js

This file was deleted.

23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
"type": "git"
},
"homepage": "https://github.com/ianvs/prettier-plugin-sort-imports#readme",
"files": [
"CHANGELOG.md",
"lib/**",
"!lib/**/__tests__/**",
"types"
],
"scripts": {
"prepare": "yarn run compile",
"compile": "tsc",
"preexample": "yarn run compile",
"example": "prettier --config ./examples/.prettierrc --plugin lib/src/index.js",
"test": "jest -i",
"test": "vitest --run",
"type-check": "tsc --noEmit",
"prepublishOnly": "npm run compile && npm run test"
},
Expand Down Expand Up @@ -55,15 +61,16 @@
"lodash.isequal": "^4.5.0"
},
"devDependencies": {
"@types/jest": "^29.2.0",
"@types/babel__generator": "^7.6.4",
"@types/babel__traverse": "^7.18.3",
"@types/lodash.clone": "4.5.7",
"@types/lodash.isequal": "4.5.6",
"@types/node": "^17.0.21",
"@vue/compiler-sfc": "3.2.40",
"jest": "^29.2.2",
"prettier": "2.7.1",
"ts-jest": "^29.0.3",
"typescript": "4.8.4"
"@types/node": "^18.15.13",
"@types/prettier": "^2.7.2",
"@vue/compiler-sfc": "3.2.47",
"prettier": "2.8.7",
"typescript": "5.0.4",
"vitest": "^0.30.1"
},
"peerDependencies": {
"@vue/compiler-sfc": ">=3.0.0",
Expand Down
37 changes: 17 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface PrettierOptionSchema {
description: string;
}

const options: Record<
export const options: Record<
Exclude<keyof PrettierOptions, keyof PrettierRequiredOptions>,
PrettierOptionSchema
> = {
Expand Down Expand Up @@ -83,24 +83,21 @@ const options: Record<
},
};

module.exports = {
parsers: {
babel: {
...babelParsers.babel,
preprocess: defaultPreprocessor,
},
flow: {
...flowParsers.flow,
preprocess: defaultPreprocessor,
},
typescript: {
...typescriptParsers.typescript,
preprocess: defaultPreprocessor,
},
vue: {
...htmlParsers.vue,
preprocess: vuePreprocessor,
},
export const parsers = {
babel: {
...babelParsers.babel,
preprocess: defaultPreprocessor,
},
flow: {
...flowParsers.flow,
preprocess: defaultPreprocessor,
},
typescript: {
...typescriptParsers.typescript,
preprocess: defaultPreprocessor,
},
vue: {
...htmlParsers.vue,
preprocess: vuePreprocessor,
},
options,
};
2 changes: 2 additions & 0 deletions src/utils/__tests__/adjust-comments-on-sorted-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import type { ImportOrLine } from '../../types';
import { adjustCommentsOnSortedNodes } from '../adjust-comments-on-sorted-nodes';
import { getImportNodes } from '../get-import-nodes';
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/explode-type-and-value-specifiers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { explodeTypeAndValueSpecifiers } from '../explode-type-and-value-specifiers';
import { getCodeFromAst } from '../get-code-from-ast';
import { getImportNodes } from '../get-import-nodes';
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/get-all-comments-from-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ParserOptions } from '@babel/parser';
import { CommentBlock, CommentLine, ImportDeclaration } from '@babel/types';
import { expect, test } from 'vitest';

import { getAllCommentsFromNodes } from '../get-all-comments-from-nodes';
import { getImportNodes } from '../get-import-nodes';
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/get-chunk-type-of-node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { chunkTypeOther, chunkTypeUnsortable } from '../../constants';
import { getChunkTypeOfNode } from '../get-chunk-type-of-node';
import { getImportNodes } from '../get-import-nodes';
Expand Down
5 changes: 3 additions & 2 deletions src/utils/__tests__/get-code-from-ast.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { format } from 'prettier';
import { expect, test } from 'vitest';

import { getCodeFromAst } from '../get-code-from-ast';
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';

it('sorts imports correctly', () => {
test('sorts imports correctly', () => {
const code = `// first comment
// second comment
import z from 'z';
Expand Down Expand Up @@ -43,7 +44,7 @@ import z from "z";
);
});

it('merges duplicate imports correctly', () => {
test('merges duplicate imports correctly', () => {
const code = `// first comment
// second comment
import z from 'z';
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/get-experimental-parser-plugins.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { getExperimentalParserPlugins } from '../get-experimental-parser-plugins';

test('it should return empty list', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/__tests__/get-import-flavor-of-node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect, test } from 'vitest';

import { getImportFlavorOfNode } from '../get-import-flavor-of-node';
import { getImportNodes } from '../get-import-nodes';

it('should correctly classify a bunch of import expressions', () => {
test('should correctly classify a bunch of import expressions', () => {
expect(
getImportNodes(
`
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/get-import-nodes-matched-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { getImportNodes } from '../get-import-nodes';
import { getImportNodesMatchedGroup } from '../get-import-nodes-matched-group';

Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/get-sorted-import-specifiers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import { getImportNodes } from '../get-import-nodes';
import { getSortedImportSpecifiers } from '../get-sorted-import-specifiers';
import { getSortedNodesModulesNames } from '../get-sorted-nodes-modules-names';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ImportDeclaration } from '@babel/types';
import { expect, test } from 'vitest';

import { getImportNodes } from '../get-import-nodes';
import { getSortedNodesByImportOrder } from '../get-sorted-nodes-by-import-order';
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/get-sorted-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ImportDeclaration } from '@babel/types';
import { expect, test } from 'vitest';

import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';
Expand Down
23 changes: 12 additions & 11 deletions src/utils/__tests__/merge-nodes-with-matching-flavors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format } from 'prettier';
import { expect, test } from 'vitest';

import { getCodeFromAst } from '../get-code-from-ast';
import { getImportNodes } from '../get-import-nodes';
Expand All @@ -15,7 +16,7 @@ const defaultOptions = {
importOrderSortSpecifiers: true,
};

it('should merge duplicate imports within a given chunk', () => {
test('should merge duplicate imports within a given chunk', () => {
const code = `
import type { A } from 'a';
import { Junk } from 'junk-group-1'
Expand Down Expand Up @@ -89,7 +90,7 @@ import { Junk2 } from "junk-group-2";
`);
});

it('should merge type imports into regular imports', () => {
test('should merge type imports into regular imports', () => {
const code = `
// Preserves 'import type'
import type { A1 } from 'a';
Expand Down Expand Up @@ -132,7 +133,7 @@ import { D1, type D2 } from "d";
`);
});

it('should combine type import and default import', () => {
test('should combine type import and default import', () => {
const code = `
import type {MyType} from './source';
import defaultValue from './source';
Expand All @@ -158,7 +159,7 @@ import defaultValue from './source';
`);
});

it('should not combine type import and namespace import', () => {
test('should not combine type import and namespace import', () => {
const code = `
import type {MyType} from './source';
import * as Namespace from './source';
Expand All @@ -185,7 +186,7 @@ import * as Namespace from "./source";
`);
});

it('should support aliased named imports', () => {
test('should support aliased named imports', () => {
const code = `
import type {MyType} from './source';
import {value as alias} from './source';
Expand All @@ -211,7 +212,7 @@ import {value as alias} from './source';
`);
});

it('should combine multiple imports from the same source', () => {
test('should combine multiple imports from the same source', () => {
const code = `
import type {MyType, SecondType} from './source';
import {value, SecondValue} from './source';
Expand All @@ -237,7 +238,7 @@ import {value, SecondValue} from './source';
`);
});

it('should combine multiple groups of imports', () => {
test('should combine multiple groups of imports', () => {
const code = `
import type {MyType} from './source';
import type {OtherType} from './other';
Expand Down Expand Up @@ -266,7 +267,7 @@ import { value, type MyType } from "./source";
`);
});

it('should combine multiple imports statements from the same source', () => {
test('should combine multiple imports statements from the same source', () => {
const code = `
import type {MyType} from './source';
import type {SecondType} from './source';
Expand Down Expand Up @@ -294,7 +295,7 @@ import {SecondValue} from './source';
`);
});

it('should not impact imports from different sources', () => {
test('should not impact imports from different sources', () => {
const code = `
import type {MyType} from './source';
import type {OtherType} from './other';
Expand Down Expand Up @@ -324,7 +325,7 @@ import { thirdValue } from "./third";
`);
});

it("doesn't merge duplicate imports if option disabled", () => {
test("doesn't merge duplicate imports if option disabled", () => {
const code = `
import type { A } from 'a';
import { Junk } from 'junk-group-1'
Expand Down Expand Up @@ -401,7 +402,7 @@ import { Junk2 } from "junk-group-2";
`);
});

it('should not combine default type imports', () => {
test('should not combine default type imports', () => {
const code = `
import { ComponentProps, useEffect } from "react";
import type React from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parse as babelParser } from '@babel/parser';
import { format } from 'prettier';
import { expect, test } from 'vitest';

import { getAllCommentsFromNodes } from '../get-all-comments-from-nodes';
import { getImportNodes } from '../get-import-nodes';
Expand Down
6 changes: 4 additions & 2 deletions test-setup/raw-serializer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

import { expect } from 'vitest';

const RAW = Symbol.for('raw');

module.exports = {
expect.addSnapshotSerializer({
print(val) {
return val[RAW];
},
Expand All @@ -13,4 +15,4 @@ module.exports = {
typeof val[RAW] === 'string'
);
},
};
});
Loading