@1adybug/prettier-plugin-sort-imports 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +7 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -558,6 +558,13 @@ function mergeImports(imports) {
558
558
  const src_require = createRequire(import.meta.url);
559
559
  function preprocessImports(text, options, config = {}) {
560
560
  try {
561
+ const parser = options.parser;
562
+ const supportedParsers = [
563
+ "babel",
564
+ "typescript",
565
+ "babel-ts"
566
+ ];
567
+ if (!parser || !supportedParsers.includes(parser)) return text;
561
568
  const imports = parseImports(text);
562
569
  if (0 === imports.length) return text;
563
570
  const optionsConfig = options;
@@ -594,7 +601,6 @@ function preprocessImports(text, options, config = {}) {
594
601
  const separator = needsExtraNewline ? "\n\n" : "\n";
595
602
  return beforeImports + formattedImports + separator + afterImports;
596
603
  } catch (error) {
597
- console.error("Failed to sort imports:", error);
598
604
  return text;
599
605
  }
600
606
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1adybug/prettier-plugin-sort-imports",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
5
5
  "description": "一个 Prettier 插件,用于对 JavaScript/TypeScript 文件的导入语句进行分组和排序",
6
6
  "keywords": [
7
7
  "prettier",