Skip to content

Commit 1a1f130

Browse files
authored
Merge pull request #316 from vladislavarsenev/v5
Updated dependencies
2 parents 7067f2a + c99ddcf commit 1a1f130

File tree

15 files changed

+3785
-3832
lines changed

15 files changed

+3785
-3832
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
node: [12.x, 14.x, 16.x, 18.x, 20.x]
8+
node: [18.x, 20.x, 22.x]
99
steps:
10-
- uses: actions/checkout@v2
11-
- uses: actions/setup-node@v2
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
1212
with:
1313
node-version: ${{ matrix.node }}
14-
- run: yarn --frozen-lockfile
14+
- run: npm i -g yarn
15+
- run: yarn set version stable
16+
- run: yarn --immutable
1517
- run: yarn test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7+
.yarn/install-state.gz
78
lerna-debug.log*
89

910
# Diagnostic reports (https://nodejs.org/api/report.html)

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

package.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"compile": "tsc",
1515
"preexample": "yarn run compile",
1616
"example": "prettier --config ./examples/.prettierrc --plugin lib/src/index.js",
17-
"test": "jest -i",
17+
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
1818
"type-check": "tsc --noEmit",
1919
"prepublishOnly": "npm run compile && npm run test"
2020
},
@@ -33,29 +33,32 @@
3333
},
3434
"license": "Apache-2.0",
3535
"dependencies": {
36-
"@babel/generator": "7.17.7",
37-
"@babel/parser": "^7.20.5",
38-
"@babel/traverse": "7.23.2",
39-
"@babel/types": "7.17.0",
36+
"@babel/generator": "7.26.2",
37+
"@babel/parser": "7.26.2",
38+
"@babel/traverse": "7.25.9",
39+
"@babel/types": "7.26.0",
4040
"javascript-natural-sort": "0.7.1",
4141
"lodash": "^4.17.21"
4242
},
4343
"devDependencies": {
44-
"@babel/core": "^7.20.7",
45-
"@types/chai": "4.2.15",
46-
"@types/jest": "26.0.20",
47-
"@types/lodash": "4.14.168",
48-
"@types/node": "20.8.6",
49-
"@vue/compiler-sfc": "^3.2.41",
50-
"jest": "26.6.3",
51-
"prettier": "2.8",
52-
"ts-jest": "26.5.3",
53-
"typescript": "4.9.4"
44+
"@babel/core": "7.26.0",
45+
"@types/chai": "5.0.1",
46+
"@types/jest": "29.5.14",
47+
"@types/lodash": "4.17.13",
48+
"@types/node": "22.9.0",
49+
"@vue/compiler-sfc": "^3.5.12",
50+
"jest": "29.7.0",
51+
"prettier": "3.3.3",
52+
"ts-jest": "29.2.5",
53+
"typescript": "5.6.3"
5454
},
5555
"peerDependencies": {
5656
"@vue/compiler-sfc": "3.x",
5757
"prettier": "2.x - 3.x"
5858
},
59+
"engines": {
60+
"node": ">18.12"
61+
},
5962
"peerDependenciesMeta": {
6063
"@vue/compiler-sfc": {
6164
"optional": true

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { parsers as babelParsers } from 'prettier/parser-babel';
2-
import { parsers as flowParsers } from 'prettier/parser-flow';
3-
import { parsers as htmlParsers } from 'prettier/parser-html';
4-
import { parsers as typescriptParsers } from 'prettier/parser-typescript';
5-
1+
import { parsers as babelParsers } from 'prettier/plugins/babel';
2+
import { parsers as flowParsers } from 'prettier/plugins/flow';
3+
import { parsers as htmlParsers } from 'prettier/plugins/html';
4+
import { parsers as typescriptParsers } from 'prettier/plugins/typescript';
65
import { defaultPreprocessor } from './preprocessors/default-processor';
76
import { vuePreprocessor } from './preprocessors/vue-preprocessor';
87

src/utils/__tests__/get-code-from-ast.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getExperimentalParserPlugins } from '../get-experimental-parser-plugins
88
import { getImportNodes } from '../get-import-nodes';
99
import { getSortedNodes } from '../get-sorted-nodes';
1010

11-
test('it sorts imports correctly', () => {
11+
test('it sorts imports correctly', async () => {
1212
const code = `// first comment
1313
// second comment
1414
import z from 'z';
@@ -27,7 +27,7 @@ import a from 'a';
2727
importOrderSortSpecifiers: false,
2828
});
2929
const formatted = getCodeFromAst(sortedNodes, [], code, null);
30-
expect(format(formatted, { parser: 'babel' })).toEqual(
30+
expect(await format(formatted, { parser: 'babel' })).toEqual(
3131
`// first comment
3232
// second comment
3333
import a from "a";
@@ -40,7 +40,7 @@ import z from "z";
4040
);
4141
});
4242

43-
test('it renders directives correctly', () => {
43+
test('it renders directives correctly', async () => {
4444
const code = `
4545
"use client";
4646
// first comment
@@ -56,7 +56,7 @@ import a from 'a';`;
5656
const { directives, importNodes } = extractASTNodes(ast);
5757

5858
const formatted = getCodeFromAst(importNodes, directives, code, null);
59-
expect(format(formatted, { parser: 'babel' })).toEqual(
59+
expect(await format(formatted, { parser: 'babel' })).toEqual(
6060
`"use client";
6161
6262
// first comment

src/utils/__tests__/remove-nodes-from-original-code.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import k from 'k';
1717
import a from 'a';
1818
`;
1919

20-
test('it should remove nodes from the original code', () => {
20+
test('it should remove nodes from the original code', async () => {
2121
const importNodes = getImportNodes(code);
2222
const sortedNodes = getSortedNodes(importNodes, {
2323
importOrder: [],
@@ -36,6 +36,6 @@ test('it should remove nodes from the original code', () => {
3636
code,
3737
commentAndImportsToRemoveFromCode,
3838
);
39-
const result = format(codeWithoutImportDeclarations, { parser: 'babel' });
39+
const result = await format(codeWithoutImportDeclarations, { parser: 'babel' });
4040
expect(result).toEqual('');
4141
});

src/utils/extract-ast-nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function extractASTNodes(ast: ParseResult<File>) {
2929

3030
ImportDeclaration(path: NodePath<ImportDeclaration>) {
3131
const tsModuleParent = path.findParent((p) =>
32-
isTSModuleDeclaration(p),
32+
p.isTSModuleDeclaration(),
3333
);
3434
if (!tsModuleParent) {
3535
importNodes.push(path.node);

src/utils/get-code-from-ast.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ export const getCodeFromAst = (
3636
directives,
3737
sourceType: 'module',
3838
interpreter: interpreter,
39-
sourceFile: '',
4039
leadingComments: [],
4140
innerComments: [],
4241
trailingComments: [],
4342
start: 0,
4443
end: 0,
4544
loc: {
46-
start: { line: 0, column: 0 },
47-
end: { line: 0, column: 0 },
45+
filename: '',
46+
identifierName: '',
47+
start: { line: 0, column: 0, index: 0 },
48+
end: { line: 0, column: 0, index: 0 },
4849
},
4950
});
5051

src/utils/get-import-nodes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ParserOptions, parse as babelParser } from '@babel/parser';
2-
import traverse, { NodePath } from '@babel/traverse';
3-
import { ImportDeclaration, isTSModuleDeclaration } from '@babel/types';
2+
import traverse from '@babel/traverse';
3+
import { ImportDeclaration } from '@babel/types';
44

55
export const getImportNodes = (code: string, options?: ParserOptions) => {
66
const importNodes: ImportDeclaration[] = [];
@@ -10,9 +10,9 @@ export const getImportNodes = (code: string, options?: ParserOptions) => {
1010
});
1111

1212
traverse(ast, {
13-
ImportDeclaration(path: NodePath<ImportDeclaration>) {
13+
ImportDeclaration(path) {
1414
const tsModuleParent = path.findParent((p) =>
15-
isTSModuleDeclaration(p),
15+
p.isTSModuleDeclaration(),
1616
);
1717
if (!tsModuleParent) {
1818
importNodes.push(path.node);

0 commit comments

Comments
 (0)