Skip to content

Commit

Permalink
updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Arsenev committed Nov 10, 2024
1 parent 61d0697 commit 9c0b1d2
Show file tree
Hide file tree
Showing 14 changed files with 3,778 additions and 3,828 deletions.
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
33 changes: 18 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"compile": "tsc",
"preexample": "yarn run compile",
"example": "prettier --config ./examples/.prettierrc --plugin lib/src/index.js",
"test": "jest -i",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest -i",
"type-check": "tsc --noEmit",
"prepublishOnly": "npm run compile && npm run test"
},
Expand All @@ -33,29 +33,32 @@
},
"license": "Apache-2.0",
"dependencies": {
"@babel/generator": "7.17.7",
"@babel/parser": "^7.20.5",
"@babel/traverse": "7.23.2",
"@babel/types": "7.17.0",
"@babel/generator": "7.26.2",
"@babel/parser": "7.26.2",
"@babel/traverse": "7.25.9",
"@babel/types": "7.26.0",
"javascript-natural-sort": "0.7.1",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/core": "^7.20.7",
"@types/chai": "4.2.15",
"@types/jest": "26.0.20",
"@types/lodash": "4.14.168",
"@types/node": "20.8.6",
"@vue/compiler-sfc": "^3.2.41",
"jest": "26.6.3",
"prettier": "2.8",
"ts-jest": "26.5.3",
"typescript": "4.9.4"
"@babel/core": "7.26.0",
"@types/chai": "5.0.1",
"@types/jest": "29.5.14",
"@types/lodash": "4.17.13",
"@types/node": "22.9.0",
"@vue/compiler-sfc": "^3.5.12",
"jest": "29.7.0",
"prettier": "3.3.3",
"ts-jest": "29.2.5",
"typescript": "5.6.3"
},
"peerDependencies": {
"@vue/compiler-sfc": "3.x",
"prettier": "2.x - 3.x"
},
"engines": {
"node": "20"
},
"peerDependenciesMeta": {
"@vue/compiler-sfc": {
"optional": true
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { parsers as babelParsers } from 'prettier/parser-babel';
import { parsers as flowParsers } from 'prettier/parser-flow';
import { parsers as htmlParsers } from 'prettier/parser-html';
import { parsers as typescriptParsers } from 'prettier/parser-typescript';

import { parsers as babelParsers } from 'prettier/plugins/babel';
import { parsers as flowParsers } from 'prettier/plugins/flow';
import { parsers as htmlParsers } from 'prettier/plugins/html';
import { parsers as typescriptParsers } from 'prettier/plugins/typescript';
import { defaultPreprocessor } from './preprocessors/default-processor';
import { vuePreprocessor } from './preprocessors/vue-preprocessor';

Expand Down
8 changes: 4 additions & 4 deletions src/utils/__tests__/get-code-from-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getExperimentalParserPlugins } from '../get-experimental-parser-plugins
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';

test('it sorts imports correctly', () => {
test('it sorts imports correctly', async () => {
const code = `// first comment
// second comment
import z from 'z';
Expand All @@ -27,7 +27,7 @@ import a from 'a';
importOrderSortSpecifiers: false,
});
const formatted = getCodeFromAst(sortedNodes, [], code, null);
expect(format(formatted, { parser: 'babel' })).toEqual(
expect(await format(formatted, { parser: 'babel' })).toEqual(
`// first comment
// second comment
import a from "a";
Expand All @@ -40,7 +40,7 @@ import z from "z";
);
});

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

const formatted = getCodeFromAst(importNodes, directives, code, null);
expect(format(formatted, { parser: 'babel' })).toEqual(
expect(await format(formatted, { parser: 'babel' })).toEqual(
`"use client";
// first comment
Expand Down
4 changes: 2 additions & 2 deletions src/utils/__tests__/remove-nodes-from-original-code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import k from 'k';
import a from 'a';
`;

test('it should remove nodes from the original code', () => {
test('it should remove nodes from the original code', async () => {
const importNodes = getImportNodes(code);
const sortedNodes = getSortedNodes(importNodes, {
importOrder: [],
Expand All @@ -36,6 +36,6 @@ test('it should remove nodes from the original code', () => {
code,
commentAndImportsToRemoveFromCode,
);
const result = format(codeWithoutImportDeclarations, { parser: 'babel' });
const result = await format(codeWithoutImportDeclarations, { parser: 'babel' });
expect(result).toEqual('');
});
2 changes: 1 addition & 1 deletion src/utils/extract-ast-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function extractASTNodes(ast: ParseResult<File>) {

ImportDeclaration(path: NodePath<ImportDeclaration>) {
const tsModuleParent = path.findParent((p) =>
isTSModuleDeclaration(p),
p.isTSModuleDeclaration(),
);
if (!tsModuleParent) {
importNodes.push(path.node);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/get-code-from-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ export const getCodeFromAst = (
directives,
sourceType: 'module',
interpreter: interpreter,
sourceFile: '',
leadingComments: [],
innerComments: [],
trailingComments: [],
start: 0,
end: 0,
loc: {
start: { line: 0, column: 0 },
end: { line: 0, column: 0 },
filename: '',
identifierName: '',
start: { line: 0, column: 0, index: 0 },
end: { line: 0, column: 0, index: 0 },
},
});

Expand Down
8 changes: 4 additions & 4 deletions src/utils/get-import-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ParserOptions, parse as babelParser } from '@babel/parser';
import traverse, { NodePath } from '@babel/traverse';
import { ImportDeclaration, isTSModuleDeclaration } from '@babel/types';
import traverse from '@babel/traverse';
import { ImportDeclaration } from '@babel/types';

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

traverse(ast, {
ImportDeclaration(path: NodePath<ImportDeclaration>) {
ImportDeclaration(path) {
const tsModuleParent = path.findParent((p) =>
isTSModuleDeclaration(p),
p.isTSModuleDeclaration(),
);
if (!tsModuleParent) {
importNodes.push(path.node);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/get-sorted-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export const getSortedNodes: GetSortedNodes = (nodes, options) => {
});

if (firstNodesComments) {
// remove comments location to not confuse printe
firstNodesComments.forEach((comment) => {
delete comment.loc;
});
addComments(finalNodes[0], 'leading', firstNodesComments);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-sort-imports-ignored.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { getAllCommentsFromNodes } from './get-all-comments-from-nodes';
export const isSortImportsIgnored = (nodes: Statement[]) =>
getAllCommentsFromNodes(nodes).some(
(comment) =>
comment.loc.start.line === 1 &&
comment.loc?.start.line === 1 &&
comment.value.includes(sortImportsIgnoredComment),
);
8 changes: 4 additions & 4 deletions test-setup/run_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ function run_spec(dirname, parsers, options) {
parser: parsers[0],
});
const output = prettyprint(source, path, mergedOptions);
test(`${filename} - ${mergedOptions.parser}-verify`, () => {
test(`${filename} - ${mergedOptions.parser}-verify`, async () => {
try {
expect(
raw(source + '~'.repeat(80) + '\n' + output),
raw(source + '~'.repeat(80) + '\n' + await output),
).toMatchSnapshot(filename);
} catch (e) {
console.error(e, path);
}
});

parsers.slice(1).forEach((parserName) => {
test(`${filename} - ${parserName}-verify`, () => {
test(`${filename} - ${parserName}-verify`, async () => {
const verifyOptions = Object.assign(mergedOptions, {
parser: parserName,
});
const verifyOutput = prettyprint(
const verifyOutput = await prettyprint(
source,
path,
verifyOptions,
Expand Down
26 changes: 15 additions & 11 deletions tests/Angular/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,25 @@ export class TemplateController {
constructor(
private templateService: TemplateService,
private _httpService: HttpService,
private _canvaskitService: CanvasKitService
private _canvaskitService: CanvasKitService,
) {
this.CanvasKit = this._canvaskitService.canvasKit;
this.requestFile = (url) => {
const req = this._httpService
.get<ArrayBuffer>(\`http:\${url}\`, {
responseType: "arraybuffer",
const req =
this._httpService.get <
ArrayBuffer >
(\`http:\${url}\`, { responseType: "arraybuffer" })
.pipe(retry(3))
.toPromise();
return (
new Promise() <
ArrayBuffer >
((resolve, reject) => {
req.then((resp) => {
resolve(resp.data);
}).catch(reject);
})
.pipe(retry(3))
.toPromise();
return new Promise<ArrayBuffer>((resolve, reject) => {
req.then((resp) => {
resolve(resp.data);
}).catch(reject);
});
);
};
}
}
Expand Down
Loading

0 comments on commit 9c0b1d2

Please sign in to comment.