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

SVGO v3.0.2 Partially Compiled #1766

Closed
Zemnmez opened this issue May 5, 2023 · 7 comments · Fixed by #1780
Closed

SVGO v3.0.2 Partially Compiled #1766

Zemnmez opened this issue May 5, 2023 · 7 comments · Fixed by #1780
Labels

Comments

@Zemnmez
Copy link

Zemnmez commented May 5, 2023

Describe the bug
V3.0.2 contains a .d.ts ("svgo.d.ts") that imports a .ts ("types.ts") in the NPM package. Some tools, like api-extractor choke on this, because .ts files are not meant to be included in node_modules packages since they are a build input.

Expected behavior
Types.ts should be compiled to types.d.ts

Screenshots
image

Desktop (please complete the following information):

  • SVGO Version 3.0.2
  • NodeJs Version N/A
  • OS: MacOS (via Bazel)

Workaround
Apply a patch deleting types.ts, and replacing it with a types.d.ts:

export type XastDoctype = {
    type: 'doctype';
    name: string;
    data: {
        doctype: string;
    };
};
export type XastInstruction = {
    type: 'instruction';
    name: string;
    value: string;
};
export type XastComment = {
    type: 'comment';
    value: string;
};
export type XastCdata = {
    type: 'cdata';
    value: string;
};
export type XastText = {
    type: 'text';
    value: string;
};
export type XastElement = {
    type: 'element';
    name: string;
    attributes: Record<string, string>;
    children: Array<XastChild>;
};
export type XastChild = XastDoctype | XastInstruction | XastComment | XastCdata | XastText | XastElement;
export type XastRoot = {
    type: 'root';
    children: Array<XastChild>;
};
export type XastParent = XastRoot | XastElement;
export type XastNode = XastRoot | XastChild;
export type StringifyOptions = {
    doctypeStart?: string;
    doctypeEnd?: string;
    procInstStart?: string;
    procInstEnd?: string;
    tagOpenStart?: string;
    tagOpenEnd?: string;
    tagCloseStart?: string;
    tagCloseEnd?: string;
    tagShortStart?: string;
    tagShortEnd?: string;
    attrStart?: string;
    attrEnd?: string;
    commentStart?: string;
    commentEnd?: string;
    cdataStart?: string;
    cdataEnd?: string;
    textStart?: string;
    textEnd?: string;
    indent?: number | string;
    regEntities?: RegExp;
    regValEntities?: RegExp;
    encodeEntity?: (char: string) => string;
    pretty?: boolean;
    useShortTags?: boolean;
    eol?: 'lf' | 'crlf';
    finalNewline?: boolean;
};
type VisitorNode<Node> = {
    enter?: (node: Node, parentNode: XastParent) => void | symbol;
    exit?: (node: Node, parentNode: XastParent) => void;
};
type VisitorRoot = {
    enter?: (node: XastRoot, parentNode: null) => void;
    exit?: (node: XastRoot, parentNode: null) => void;
};
export type Visitor = {
    doctype?: VisitorNode<XastDoctype>;
    instruction?: VisitorNode<XastInstruction>;
    comment?: VisitorNode<XastComment>;
    cdata?: VisitorNode<XastCdata>;
    text?: VisitorNode<XastText>;
    element?: VisitorNode<XastElement>;
    root?: VisitorRoot;
};
export type PluginInfo = {
    path?: string;
    multipassCount: number;
};
export type Plugin<Params> = (root: XastRoot, params: Params, info: PluginInfo) => null | Visitor;
export type Specificity = [number, number, number, number];
export type StylesheetDeclaration = {
    name: string;
    value: string;
    important: boolean;
};
export type StylesheetRule = {
    dynamic: boolean;
    selector: string;
    specificity: Specificity;
    declarations: Array<StylesheetDeclaration>;
};
export type Stylesheet = {
    rules: Array<StylesheetRule>;
    parents: Map<XastElement, XastParent>;
};
type StaticStyle = {
    type: 'static';
    inherited: boolean;
    value: string;
};
type DynamicStyle = {
    type: 'dynamic';
    inherited: boolean;
};
export type ComputedStyles = Record<string, StaticStyle | DynamicStyle>;
export type PathDataCommand = 'M' | 'm' | 'Z' | 'z' | 'L' | 'l' | 'H' | 'h' | 'V' | 'v' | 'C' | 'c' | 'S' | 's' | 'Q' | 'q' | 'T' | 't' | 'A' | 'a';
export type PathDataItem = {
    command: PathDataCommand;
    args: Array<number>;
};
export type DataUri = 'base64' | 'enc' | 'unenc';
export {};

Here is my patch:

diff --git a/lib/types.d.ts b/lib/types.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..88b73182c320e4751e2b5029dffe71d497478294
--- /dev/null
+++ b/lib/types.d.ts
@@ -0,0 +1,120 @@
+export type XastDoctype = {
+    type: 'doctype';
+    name: string;
+    data: {
+        doctype: string;
+    };
+};
+export type XastInstruction = {
+    type: 'instruction';
+    name: string;
+    value: string;
+};
+export type XastComment = {
+    type: 'comment';
+    value: string;
+};
+export type XastCdata = {
+    type: 'cdata';
+    value: string;
+};
+export type XastText = {
+    type: 'text';
+    value: string;
+};
+export type XastElement = {
+    type: 'element';
+    name: string;
+    attributes: Record<string, string>;
+    children: Array<XastChild>;
+};
+export type XastChild = XastDoctype | XastInstruction | XastComment | XastCdata | XastText | XastElement;
+export type XastRoot = {
+    type: 'root';
+    children: Array<XastChild>;
+};
+export type XastParent = XastRoot | XastElement;
+export type XastNode = XastRoot | XastChild;
+export type StringifyOptions = {
+    doctypeStart?: string;
+    doctypeEnd?: string;
+    procInstStart?: string;
+    procInstEnd?: string;
+    tagOpenStart?: string;
+    tagOpenEnd?: string;
+    tagCloseStart?: string;
+    tagCloseEnd?: string;
+    tagShortStart?: string;
+    tagShortEnd?: string;
+    attrStart?: string;
+    attrEnd?: string;
+    commentStart?: string;
+    commentEnd?: string;
+    cdataStart?: string;
+    cdataEnd?: string;
+    textStart?: string;
+    textEnd?: string;
+    indent?: number | string;
+    regEntities?: RegExp;
+    regValEntities?: RegExp;
+    encodeEntity?: (char: string) => string;
+    pretty?: boolean;
+    useShortTags?: boolean;
+    eol?: 'lf' | 'crlf';
+    finalNewline?: boolean;
+};
+type VisitorNode<Node> = {
+    enter?: (node: Node, parentNode: XastParent) => void | symbol;
+    exit?: (node: Node, parentNode: XastParent) => void;
+};
+type VisitorRoot = {
+    enter?: (node: XastRoot, parentNode: null) => void;
+    exit?: (node: XastRoot, parentNode: null) => void;
+};
+export type Visitor = {
+    doctype?: VisitorNode<XastDoctype>;
+    instruction?: VisitorNode<XastInstruction>;
+    comment?: VisitorNode<XastComment>;
+    cdata?: VisitorNode<XastCdata>;
+    text?: VisitorNode<XastText>;
+    element?: VisitorNode<XastElement>;
+    root?: VisitorRoot;
+};
+export type PluginInfo = {
+    path?: string;
+    multipassCount: number;
+};
+export type Plugin<Params> = (root: XastRoot, params: Params, info: PluginInfo) => null | Visitor;
+export type Specificity = [number, number, number, number];
+export type StylesheetDeclaration = {
+    name: string;
+    value: string;
+    important: boolean;
+};
+export type StylesheetRule = {
+    dynamic: boolean;
+    selector: string;
+    specificity: Specificity;
+    declarations: Array<StylesheetDeclaration>;
+};
+export type Stylesheet = {
+    rules: Array<StylesheetRule>;
+    parents: Map<XastElement, XastParent>;
+};
+type StaticStyle = {
+    type: 'static';
+    inherited: boolean;
+    value: string;
+};
+type DynamicStyle = {
+    type: 'dynamic';
+    inherited: boolean;
+};
+export type ComputedStyles = Record<string, StaticStyle | DynamicStyle>;
+export type PathDataCommand = 'M' | 'm' | 'Z' | 'z' | 'L' | 'l' | 'H' | 'h' | 'V' | 'v' | 'C' | 'c' | 'S' | 's' | 'Q' | 'q' | 'T' | 't' | 'A' | 'a';
+export type PathDataItem = {
+    command: PathDataCommand;
+    args: Array<number>;
+};
+export type DataUri = 'base64' | 'enc' | 'unenc';
+export {};
\ No newline at end of file
diff --git a/lib/types.ts b/lib/types.ts
deleted file mode 100644
index f6260c6ab4648a21f41c377e5abb42e4d2004b84..0000000000000000000000000000000000000000
@Zemnmez Zemnmez added the bug label May 5, 2023
Zemnmez added a commit to zemn-me/monorepo that referenced this issue May 5, 2023
@Exotelis
Copy link
Contributor

Exotelis commented Sep 5, 2023

The plugin.ts is also causing issues! Spent couple of hours finding out why my build was no longer working.
Please provide a new release as soon as possible.

@Exotelis
Copy link
Contributor

Exotelis commented Sep 5, 2023

@deepsweet I don't know who is maintaining this package currently. May I ask you to publish a new release with the fix @Zemnmez and I provided? Since this is a critical and blocking issue I would appreciate your help a lot.

@SethFalco
Copy link
Member

No there isn't, but I'd be happy to ping you here once it's released.
I'll do it on Friday (1 December 2023) at the latest, but just reviewing other pull requests and issues at the moment.

@Zemnmez
Copy link
Author

Zemnmez commented Nov 28, 2023 via email

@SethFalco
Copy link
Member

@Zemnmez

v3.0.5 has just been published.

@Zemnmez
Copy link
Author

Zemnmez commented Dec 1, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants