prettier-plugin-embed 0.5.0 → 0.6.0

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.
@@ -46,7 +46,7 @@ export declare const options: {
46
46
  default: "babel";
47
47
  description: string;
48
48
  choices: {
49
- value: "babel" | "babel-flow" | "acorn" | "espree" | "flow" | "meriyah";
49
+ value: "acorn" | "babel" | "babel-flow" | "espree" | "flow" | "meriyah";
50
50
  description: string;
51
51
  }[];
52
52
  };
@@ -46,7 +46,7 @@ export declare const options: {
46
46
  default: "html";
47
47
  description: string;
48
48
  choices: {
49
- value: "html" | "vue" | "angular" | "lwc";
49
+ value: "angular" | "html" | "lwc" | "vue";
50
50
  description: string;
51
51
  }[];
52
52
  };
@@ -1,3 +1,3 @@
1
1
  export * from "./register.js";
2
- export type { EmbeddedDefaultComment, EmbeddedDefaultTag, EmbeddedEmbedders, EmbeddedLanguage, EmbeddedOptions, EmbeddedParsers, EmbeddedComment, EmbeddedTag, PluginEmbedOptions, } from "./types.js";
3
- export { makeIdentifiersOptionName, makeCommentsOptionName, makeTagsOptionName, fallbackIndicator, type AutocompleteStringList, } from "./utils.js";
2
+ export type { EmbeddedComment, EmbeddedDefaultComment, EmbeddedDefaultTag, EmbeddedEmbedders, EmbeddedLanguage, EmbeddedOptions, EmbeddedParsers, EmbeddedTag, PluginEmbedOptions, } from "./types.js";
3
+ export { type AutocompleteStringList, fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, } from "./utils.js";
@@ -46,7 +46,7 @@ export declare const options: {
46
46
  default: "json";
47
47
  description: string;
48
48
  choices: {
49
- value: "json" | "json5" | "jsonc" | "json-stringify";
49
+ value: "json" | "json-stringify" | "json5" | "jsonc";
50
50
  description: string;
51
51
  }[];
52
52
  };
@@ -4,27 +4,27 @@ export declare const embeddedParsers: EmbeddedParsers;
4
4
  export declare const embeddedEmbedders: EmbeddedEmbedders;
5
5
  export declare const embeddedOptions: EmbeddedOptions;
6
6
  import * as __glob__0_0 from "./css/index.js";
7
- import * as __glob__0_1 from "./glsl/index.js";
8
- import * as __glob__0_2 from "./graphql/index.js";
9
- import * as __glob__0_3 from "./html/index.js";
10
- import * as __glob__0_4 from "./ini/index.js";
11
- import * as __glob__0_5 from "./java/index.js";
12
- import * as __glob__0_6 from "./es/index.js";
13
- import * as __glob__0_7 from "./json/index.js";
7
+ import * as __glob__0_1 from "./es/index.js";
8
+ import * as __glob__0_2 from "./glsl/index.js";
9
+ import * as __glob__0_3 from "./graphql/index.js";
10
+ import * as __glob__0_4 from "./html/index.js";
11
+ import * as __glob__0_5 from "./ini/index.js";
12
+ import * as __glob__0_6 from "./java/index.js";
13
+ import * as __glob__0_7 from "./jsonata/index.js";
14
14
  import * as __glob__0_8 from "./latex/index.js";
15
- import * as __glob__0_9 from "./jsonata/index.js";
16
- import * as __glob__0_10 from "./markdown/index.js";
15
+ import * as __glob__0_9 from "./markdown/index.js";
16
+ import * as __glob__0_10 from "./nginx/index.js";
17
17
  import * as __glob__0_11 from "./noop/index.js";
18
- import * as __glob__0_12 from "./nginx/index.js";
19
- import * as __glob__0_13 from "./pegjs/index.js";
18
+ import * as __glob__0_12 from "./pegjs/index.js";
19
+ import * as __glob__0_13 from "./php/index.js";
20
20
  import * as __glob__0_14 from "./prisma/index.js";
21
- import * as __glob__0_15 from "./php/index.js";
22
- import * as __glob__0_16 from "./properties/index.js";
23
- import * as __glob__0_17 from "./pug/index.js";
24
- import * as __glob__0_18 from "./ruby/index.js";
25
- import * as __glob__0_19 from "./sh/index.js";
26
- import * as __glob__0_20 from "./sql/index.js";
21
+ import * as __glob__0_15 from "./properties/index.js";
22
+ import * as __glob__0_16 from "./pug/index.js";
23
+ import * as __glob__0_17 from "./ruby/index.js";
24
+ import * as __glob__0_18 from "./sh/index.js";
25
+ import * as __glob__0_19 from "./sql/index.js";
26
+ import * as __glob__0_20 from "./toml/index.js";
27
27
  import * as __glob__0_21 from "./ts/index.js";
28
- import * as __glob__0_22 from "./toml/index.js";
29
- import * as __glob__0_23 from "./xml/index.js";
30
- import * as __glob__0_24 from "./yaml/index.js";
28
+ import * as __glob__0_22 from "./xml/index.js";
29
+ import * as __glob__0_23 from "./yaml/index.js";
30
+ import * as __glob__0_24 from "./json/index.js";
@@ -46,7 +46,7 @@ export declare const options: {
46
46
  default: "ruby";
47
47
  description: string;
48
48
  choices: {
49
- value: "ruby" | "rbs" | "haml";
49
+ value: "haml" | "rbs" | "ruby";
50
50
  description: string;
51
51
  }[];
52
52
  };
@@ -1,4 +1,4 @@
1
- import type { PrettierTaploOptions } from "prettier-plugin-toml";
1
+ import type { PrettierOptions } from "prettier-plugin-toml";
2
2
  import type { NormalizeOptions } from "../utils.js";
3
- export interface PluginTomlOptions extends NormalizeOptions<PrettierTaploOptions> {
3
+ export interface PluginTomlOptions extends NormalizeOptions<PrettierOptions> {
4
4
  }
@@ -46,7 +46,7 @@ export declare const options: {
46
46
  default: "typescript";
47
47
  description: string;
48
48
  choices: {
49
- value: "typescript" | "babel-ts";
49
+ value: "babel-ts" | "typescript";
50
50
  description: string;
51
51
  }[];
52
52
  };
@@ -1,5 +1,5 @@
1
1
  import type { Options, Parser, SupportOption } from "prettier";
2
- import type { LiteralUnion } from "type-fest";
2
+ import type { LiteralUnion } from "../type-utils.js";
3
3
  import type { Embedder } from "../types.js";
4
4
  import type { Satisfies } from "./utils.js";
5
5
  type EmbeddedLanguageNamingConvention = `embedded${Capitalize<string>}`;
@@ -1,13 +1,29 @@
1
1
  import type { Comment, Expression, TemplateLiteral } from "estree";
2
- import type { AstPath, Doc } from "prettier";
2
+ import type { AstPath, Doc, Options } from "prettier";
3
3
  import { builders } from "prettier/doc";
4
- import type { LiteralUnion, OmitIndexSignature, UnionToIntersection } from "type-fest";
4
+ import type { LiteralUnion, OmitIndexSignature, UnionToIntersection } from "../type-utils.js";
5
5
  import type { InternalPrintFun } from "../types.js";
6
+ export declare function prepareTemplate(node: TemplateLiteral, createPlaceholder: (index: number) => string): {
7
+ trimmedText: string;
8
+ leadingWhitespaces: string;
9
+ trailingWhitespaces: string;
10
+ };
11
+ export declare function wrapEmbeddedDoc(contentDoc: Doc, options: {
12
+ preserveEmbeddedExteriorWhitespaces?: string[];
13
+ noEmbeddedMultiLineIndentation?: string[];
14
+ }, commentOrTag: string, leadingWhitespaces: string, trailingWhitespaces: string, preserveExteriorWhitespaces?: boolean): Doc;
6
15
  export declare function printTemplateExpression(path: AstPath<Expression & {
7
16
  comments?: Comment[];
8
- }>, print: InternalPrintFun): builders.Doc[];
9
- export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>, print: InternalPrintFun): builders.Doc[][];
10
- export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[], replaceLiteralNewlinesToHardlines?: boolean): builders.Doc[] | builders.DocCommand;
17
+ }>, print: InternalPrintFun, templateLiteral: TemplateLiteral, index: number, tabWidth: number, preserveIndentation?: boolean): builders.Group;
18
+ export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>, print: InternalPrintFun, options?: Options, preserveIndentation?: boolean): builders.Group[];
19
+ export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[],
20
+ /**
21
+ * How to handle newlines in the formatted content:
22
+ * - false: keep newlines as-is (default)
23
+ * - "hardline": replace newlines with hardline (adds indentation)
24
+ * - "literalline": replace newlines with literalline via replaceEndOfLine (preserves original indentation)
25
+ */
26
+ newlineHandling?: false | "hardline" | "literalline", lineBreakBeforeExpressions?: ReadonlySet<number>, interpolationTabWidth?: number): builders.Doc[] | builders.DocCommand;
11
27
  export declare function insertLanguage(languages: string[], language: string, firstLanguage: string): void;
12
28
  export declare const randomUUID: () => string;
13
29
  export declare function preparePlaceholder(leading?: string, trailing?: string): {
@@ -1,10 +1,13 @@
1
- // @ts-nocheck
2
- import type { CstNode } from "chevrotain";
3
- import type { Parser } from "prettier";
1
+ import type { Parser, ParserOptions } from "prettier";
4
2
  import { language } from "./language.js";
5
- export declare const parser: Parser<CstNode>;
3
+ type XmlNode = Record<string, unknown>;
4
+ export declare function parseWithXmlPlugin(text: string, options: ParserOptions<XmlNode>, xmlParser: Parser<XmlNode>): Promise<XmlNode>;
5
+ export declare function loadXmlParser(filepath?: string, loadDirectly?: () => Promise<unknown>, moduleUrl?: string | URL): Promise<Parser<XmlNode>>;
6
+ export declare function parseXml(text: string, options: ParserOptions<XmlNode>, loadParser?: (filepath?: string) => Promise<Parser<XmlNode>>): Promise<XmlNode>;
7
+ export declare const parser: Parser<XmlNode>;
6
8
  declare module "../types.js" {
7
9
  interface EmbeddedParsers {
8
10
  [language]: Parser;
9
11
  }
10
12
  }
13
+ export {};
@@ -0,0 +1,45 @@
1
+ import { pathToFileURL as e } from "node:url";
2
+ import { parentPort as t, workerData as n } from "node:worker_threads";
3
+ //#region scripts/import-module-worker.ts
4
+ async function r(e) {
5
+ try {
6
+ return await import(e.href);
7
+ } catch (t) {
8
+ if (!(t instanceof Error) || !("code" in t) || ![
9
+ "ERR_UNKNOWN_FILE_EXTENSION",
10
+ "ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX",
11
+ "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING"
12
+ ].includes(String(t.code))) throw t;
13
+ let { register: n } = await import("node:module");
14
+ if (!n) throw t;
15
+ n(`data:text/javascript,${encodeURIComponent(`
16
+ export function resolve(specifier, context, nextResolve) {
17
+ return nextResolve(specifier, {
18
+ ...context,
19
+ parentURL: context.parentURL === ${JSON.stringify(import.meta.url)}
20
+ ? ${JSON.stringify(e.href)}
21
+ : context.parentURL,
22
+ });
23
+ }
24
+ `)}`);
25
+ let r;
26
+ try {
27
+ r = await Promise.all(["tsx/cjs/api", "tsx/esm/api"].map((e) => import.meta.resolve(e)));
28
+ } catch {
29
+ throw t;
30
+ }
31
+ let [i, a] = await Promise.all(r.map((e) => import(e)));
32
+ return i.register(), a.register({ namespace: "prettier-plugin-embed" }).import(e.href, e.href);
33
+ }
34
+ }
35
+ (async ({ absolutePath: n }) => {
36
+ try {
37
+ let i = await r(e(n));
38
+ t?.postMessage({ overrides: i.embeddedOverrides ?? i.default });
39
+ } catch (e) {
40
+ t?.postMessage({ error: e instanceof Error ? e : Error(String(e)) });
41
+ } finally {
42
+ t?.close();
43
+ }
44
+ })(n);
45
+ //#endregion
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- export { options } from "./options.js";
2
- export { parsers } from "./parsers.js";
3
- export { printers } from "./printers.js";
4
- export type { PluginEmbedOptions } from "./embedded/index.js";
5
- export type { EmbeddedOverride } from "./types.js";
6
- export type {
1
+ export type { PluginEmbedOptions,
7
2
  /**
8
3
  * @deprecated Renamed to `PluginEmbedOptions`
9
4
  */
10
5
  PluginEmbedOptions as PrettierPluginEmbedOptions, } from "./embedded/index.js";
6
+ export { options } from "./options.js";
7
+ export { parsers } from "./parsers.js";
8
+ export { printers } from "./printers.js";
9
+ export type { EmbeddedOverride } from "./types.js";