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

Add support for verbatimModuleSyntax #242

Open
JoA-MoS opened this issue Feb 15, 2024 · 4 comments
Open

Add support for verbatimModuleSyntax #242

JoA-MoS opened this issue Feb 15, 2024 · 4 comments

Comments

@JoA-MoS
Copy link
Contributor

JoA-MoS commented Feb 15, 2024

When using verbatim module syntax flag and the included configuration builds will fail because the model import does not have the type keyword.

libs/common-ui/icons-feather/src/icons/index.ts:3:10 - error TS1484: 'FthrIcon' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

  1 | /* 🤖 this file was generated by svg-to-ts */
  2 | 
> 3 | import { FthrIcon } from './build/fthr-icons.model';
    |          ^
  4 | 
  5 | export type FthrIconNameSubset<T extends Readonly<FthrIcon[]>> = T[number]['name'];
  6 | 

.svg-to-tsrc

{
    "delimiter": "KEBAB",
    "generateType": true,
    "interfaceName": "FthrIcon",
    "modelFileName": "fthr-icons.model",
    "namePrefix": "fthr-",
    "optimizeForLazyLoading": true,
    "outputDirectory": "./src/icons",
    "prefix": "fthr",
    "srcFiles": [
        "../../../node_modules/feather-icons/dist/icons/**/*.svg"
    ],
    "typeName": "FthrIcons",
    "svgoConfig": {
        "plugins": [
            {
                "name": "preset-default",
                "params": {
                    "overrides": {
                        "removeViewBox": false
                    }
                }
            }
        ]
    }
}

I am Willing to contribute with a little guidance.

@JoA-MoS
Copy link
Contributor Author

JoA-MoS commented Feb 15, 2024

Ahh... I think I found the issue. The prettier version needs to be updated it is called in the formatContent function

@JoA-MoS
Copy link
Contributor Author

JoA-MoS commented Feb 15, 2024

Here is what I would recommend for a fix

const formatContent = async (fileContent: string, filePath: string) => {
  // get the existing prettier config if it exists
  const prettierConfig = await prettier.resolveConfig(filePath);
  // use the existing prettier config along with the defaults to format the file content
  return await prettier.format(fileContent, { singleQuote: true, ...prettierConfig, parser: 'typescript' });
};

and adjust the write file method to pass the output file as well as await the formatContent function since it is now async.

This has the benefit of using the user's existing prettier config if they have one while still having the defaults if they don't.

This change would require a prettier write across the entire codebase as there have been some changes so it might result in a lot of files touched.

@kreuzerk - let me know if you want a PR as I have made the required changes locally to test.

@JoA-MoS JoA-MoS closed this as completed Feb 15, 2024
@JoA-MoS JoA-MoS reopened this Feb 15, 2024
JoA-MoS added a commit to JoA-MoS/svg-to-ts that referenced this issue Feb 15, 2024
…tier version

* adds support for verbatimModuleSyntax
* adds support for user defined prettier config
* updates prettier and related dependencies to latest versions

BREAKING CHANGE: Typescript < 3.8 is no longer supported, please update to typescript >= 3.8

COMPLETES: nivekcode#242
JoA-MoS added a commit to JoA-MoS/svg-to-ts that referenced this issue Feb 15, 2024
…tier version

* adds support for verbatimModuleSyntax
* adds support for user defined prettier config
* updates prettier and related dependencies to latest versions

BREAKING CHANGE: Typescript < 3.8 is no longer supported, please update to typescript >= 3.8

COMPLETES: nivekcode#242
@JoA-MoS
Copy link
Contributor Author

JoA-MoS commented Feb 15, 2024

@kreuzerk & @felipeplets - I have made the required changes in PR #243. Because this requires a newer version of prettier it did require running prettier --write

The updated prettier version has a different API and no longer uses the parser plugin so that has been removed. I also added support to the tool to grab the existing project's prettier config if it exists if it doesn't exist then we will use the default.

I classified this as a breaking change because it implies a minimum version of typescript of 3.8 which I didn't see documented previously.

@nivekcode
Copy link
Owner

Hey @JoA-MoS thx a lot for the PR and the Issue here, I will take a look at this. 👍

nivekcode pushed a commit that referenced this issue Feb 18, 2024
# [12.0.0](v11.0.1...v12.0.0) (2024-02-18)

### Features

* updates generateTypeHelper to use type keyword and updates prettier version ([2f3d9ee](2f3d9ee)), closes [#242](#242)

### BREAKING CHANGES

* Typescript < 3.8 is no longer supported, please update to typescript >= 3.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants