ryoppippi / unplugin-typia

unplugin for Typia with an extra Bun plugin ๐Ÿซถ
https://jsr.io/@ryoppippi/unplugin-typia
Other
37 stars 6 forks source link

The official documentation for Typia provides installation instructions for unplugin-typia using npm, but in reality, the latest version is only available on JSR. #170

Closed HenryWu01 closed 2 months ago

HenryWu01 commented 2 months ago

I have first configured type following the instructions on documentation, and then installed unplugin-typia. My config are listed below:

preload.ts

import UnpluginTypia from '@ryoppippi/unplugin-typia/bun';

import { plugin } from 'bun';

plugin(UnpluginTypia({ /* options */ }));

bunfig.toml

preload = ["./preload.ts"]

[test]
preload = ["./preload.ts"]

tsconfig.json

{
  "compilerOptions": {
    // Enable latest features
    "lib": ["ESNext", "DOM"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleDetection": "force",
    "jsx": "react-jsx",
    "allowJs": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,

    // Bundler mode
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,

    // Best practices
    "strict": true,
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": true,

    // Some stricter flags (disabled by default)
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noPropertyAccessFromIndexSignature": false,
    "strictNullChecks": true,
    "plugins": [
      {
        "transform": "typia/lib/transform"
      }
    ]
  }
}

When I use the command bun run src\index.ts, this error appears:


 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                   โ”‚
 โ”‚  [unplugin-typia] Cache disabled  โ”‚
 โ”‚                                   โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

124612 |       const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion3 } = createProgramOptions;
124613 |       let { oldProgram } = createProgramOptions;
124614 |       for (const option of commandLineOptionOfCustomType) {
124615 |           if (hasProperty(options, option.name)) {
124616 |               if (typeof options[option.name] === "string") {
124617 |                   throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);
                                 ^
error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
      at originalCreateProgram (/Users/henry/Documents/Ticket/node_modules/typescript/lib/typescript.js:124617:25)
      at createProgram (/Users/henry/Documents/Ticket/node_modules/typescript/lib/typescript.js:579:28)
      at createProgram (/Users/henry/Documents/Ticket/node_modules/typescript/lib/typescript.js:124608:41)
      at /Users/henry/Documents/Ticket/node_modules/@ryoppippi/unplugin-typia/src/core/typia.ts:124:21
      at getProgramAndSource (/Users/henry/Documents/Ticket/node_modules/@ryoppippi/unplugin-typia/src/core/typia.ts:88:2)
      at /Users/henry/Documents/Ticket/node_modules/@ryoppippi/unplugin-typia/src/core/typia.ts:43:38

Bun v1.1.18 (macOS arm64)
risen228 commented 2 months ago

I encountered the same error when trying to use the webpack plugin

ryoppippi commented 2 months ago

Thank you guys for reporting this I got this error when we upgraded typescript 5.5.x. I fixed the implementation here: https://github.com/ryoppippi/unplugin-typia/commit/8049001f4968acf187bb16a65b60a406cc2ef3e4

I thought this should be fixed in the latest version of unplugin-typia

So maybe something failed to parse options correctly. I would like you to fix it!

PRs are welcome

ryoppippi commented 2 months ago

I tested this repository (https://github.com/ryoppippi/bun-typia-template) using your provided tsconfig settings, and it worked fine.

I need a reproduction repository
@risen228 @HenryWu01

HenryWu01 commented 2 months ago

Hi, thank you for the response. It's strange, it is still reproducible even with the given repository.

I am using macOS Sonoma 14.5 on Mac Mini M2 with Bun v1.1.18

henry@Henrys-Mac-mini bun-typia-template % bun run index.ts 

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                  โ”‚
 โ”‚  [unplugin-typia] Cache enabled  โ”‚
 โ”‚                                  โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

123992 |   const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion3 } = createProgramOptions;
123993 |   let { oldProgram } = createProgramOptions;
123994 |   for (const option of commandLineOptionOfCustomType) {
123995 |     if (hasProperty(options, option.name)) {
123996 |       if (typeof options[option.name] === "string") {
123997 |         throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);
                       ^
error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
      at createProgram (/Users/henry/.bun/install/cache/typescript@5.5.3@@@1/lib/typescript.js:123997:15)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:124:21
      at getProgramAndSource (/Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:88:2)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:43:38

Bun v1.1.18 (macOS arm64)

To be more specific, using the repository's tsconfig or my tsconfig does not affect this error.

risen228 commented 2 months ago

Unfortunately, I canโ€™t give an example of reproduction now, maybe Iโ€™ll do it later.

But I can say that I use macos sonoma 14.1 (Macbook M3 Max), Node.js platform (so I don't think it's something Bun-specific)

To be more precise, this happened in one of the applications in a monorepo based on Nx, and tsconfig was inherited from the root tsconfig via extends

HenryWu01 commented 2 months ago

Hi, thank you for the response. It's strange, it is still reproducible even with the given repository.

I am using macOS Sonoma 14.5 on Mac Mini M2 with Bun v1.1.18

henry@Henrys-Mac-mini bun-typia-template % bun run index.ts 

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                  โ”‚
 โ”‚  [unplugin-typia] Cache enabled  โ”‚
 โ”‚                                  โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

123992 |   const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion3 } = createProgramOptions;
123993 |   let { oldProgram } = createProgramOptions;
123994 |   for (const option of commandLineOptionOfCustomType) {
123995 |     if (hasProperty(options, option.name)) {
123996 |       if (typeof options[option.name] === "string") {
123997 |         throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);
                       ^
error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
      at createProgram (/Users/henry/.bun/install/cache/typescript@5.5.3@@@1/lib/typescript.js:123997:15)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:124:21
      at getProgramAndSource (/Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:88:2)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:43:38

Bun v1.1.18 (macOS arm64)

To be more specific, using the repository's tsconfig or my tsconfig does not affect this error.

I found the issue, my bun is sticking with version 0.3.8 for some unknown reason, running bunx jsr add @ryoppippi/unplugin-typia again fixes this issue with the given repository.

henry@Henrys-Mac-mini bun-typia-template % bunx jsr add @ryoppippi/unplugin-typia
Installing @ryoppippi/unplugin-typia...
$ bun add @ryoppippi/unplugin-typia@npm:@jsr/ryoppippi__unplugin-typia
bun add v1.1.18 (5a0b9352)

$ ts-patch install && typia patch
[+] ts-patch installed!
----------------------------------------
 Typia Setup Wizard
----------------------------------------
Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments.

Therefore, "typia" revives the JSDoc parsing feature by patching "tsc".

This is a temporary feature of "typia", and it would be removed when "ts-patch" being updated.

+ @types/bun@1.1.6
+ ts-patch@3.2.1
+ typescript@5.5.3
+ typia@6.4.3

installed @ryoppippi/unplugin-typia@0.5.4

126 packages installed [4.65s]

Completed in 4s
henry@Henrys-Mac-mini bun-typia-template % bun run index.ts

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                  โ”‚
 โ”‚  [unplugin-typia] Cache enabled  โ”‚
 โ”‚                                  โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

{
  member: {
    email: "example@example.com",
    age: 25,
  },
  is: true,
}
{
  random: {
    email: "fokssgbfhg@fndrzrzgba.rky",
    age: 89.63818943976189,
  },
}
HenryWu01 commented 2 months ago

Hi, thank you for the response. It's strange, it is still reproducible even with the given repository. I am using macOS Sonoma 14.5 on Mac Mini M2 with Bun v1.1.18

henry@Henrys-Mac-mini bun-typia-template % bun run index.ts 

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                  โ”‚
 โ”‚  [unplugin-typia] Cache enabled  โ”‚
 โ”‚                                  โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

123992 |   const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion3 } = createProgramOptions;
123993 |   let { oldProgram } = createProgramOptions;
123994 |   for (const option of commandLineOptionOfCustomType) {
123995 |     if (hasProperty(options, option.name)) {
123996 |       if (typeof options[option.name] === "string") {
123997 |         throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);
                       ^
error: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram
      at createProgram (/Users/henry/.bun/install/cache/typescript@5.5.3@@@1/lib/typescript.js:123997:15)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:124:21
      at getProgramAndSource (/Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:88:2)
      at /Users/henry/.bun/install/cache/@ryoppippi/unplugin-typia@0.3.8@@@1/src/core/typia.ts:43:38

Bun v1.1.18 (macOS arm64)

To be more specific, using the repository's tsconfig or my tsconfig does not affect this error.

I found the issue, my bun is sticking with version 0.3.8 for some unknown reason, running bunx jsr add @ryoppippi/unplugin-typia again fixes this issue with the given repository.

henry@Henrys-Mac-mini bun-typia-template % bunx jsr add @ryoppippi/unplugin-typia
Installing @ryoppippi/unplugin-typia...
$ bun add @ryoppippi/unplugin-typia@npm:@jsr/ryoppippi__unplugin-typia
bun add v1.1.18 (5a0b9352)

$ ts-patch install && typia patch
[+] ts-patch installed!
----------------------------------------
 Typia Setup Wizard
----------------------------------------
Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments.

Therefore, "typia" revives the JSDoc parsing feature by patching "tsc".

This is a temporary feature of "typia", and it would be removed when "ts-patch" being updated.

+ @types/bun@1.1.6
+ ts-patch@3.2.1
+ typescript@5.5.3
+ typia@6.4.3

installed @ryoppippi/unplugin-typia@0.5.4

126 packages installed [4.65s]

Completed in 4s
henry@Henrys-Mac-mini bun-typia-template % bun run index.ts

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                  โ”‚
 โ”‚  [unplugin-typia] Cache enabled  โ”‚
 โ”‚                                  โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

{
  member: {
    email: "example@example.com",
    age: 25,
  },
  is: true,
}
{
  random: {
    email: "fokssgbfhg@fndrzrzgba.rky",
    age: 89.63818943976189,
  },
}

Can you confirm running bunx jsr add @ryoppippi/unplugin-typia fixes this issue @risen228?

HenryWu01 commented 2 months ago

I think I have figured out what's happening @ryoppippi @risen228.
Let me explain it.
The main problem was the typia documentation. It is OUTDATED.

On typia documentation, it says:

bun add @ryoppippi/unplugin-typia
bun add typia
bun typia setup

This bun add command does not contain jsr which means bun will search the package on npmjs instead of jsr.

Screenshot 2024-07-09 at 1 00 58โ€ฏAM

You can see exactly the version of @ryoppippi/unplugin-typia on npmjs is 0.3.8, not 0.5.4 which contains the bug fixes.

Screenshot 2024-07-09 at 1 02 05โ€ฏAM
ryoppippi commented 2 months ago

Ohhhhh, OKay. Actually, I wrote this doc. So could you create a PR to typia?

HenryWu01 commented 2 months ago

Ohhhhh, OKay. Actually, I wrote this doc. So could you create a PR to typia?

Sure, I will create it now.

ryoppippi commented 2 months ago

@HenryWu01 @risen228 Sorry guys, I forgot that I uploaded it to npm!!

I'll deprecate it.

ryoppippi commented 2 months ago

Okay, I deleted the package on npm rn

HenryWu01 commented 2 months ago

I have created a pull request, waiting for typia to merge. Thank you so much for investigating @ryoppippi!

risen228 commented 2 months ago

Thank you for sorting out the situation so quickly =)

HenryWu01 commented 2 months ago

You're welcome. We can close this issue after typia have merge the pull request. :D Thanks @ryoppippi for developing this awesome plugin!

ryoppippi commented 2 months ago

@HenryWu01 @risen228 Thank you so much and sorry for made you confused!

Cheers!!

@HenryWu01 Ok, after merged https://github.com/samchon/typia/pull/1154 , please close this issue!

HenryWu01 commented 2 months ago

@HenryWu01 @risen228 Thank you so much and sorry for made you confused!

Cheers!!

@HenryWu01 Ok, after merged samchon/typia#1154 , please close this issue!

Not problem at all. Thank you so much for your effort not only on debugging this issue but also developing the awesome plugin.

HenryWu01 commented 2 months ago

Close this issue since correction has been merged into typia documentation.