samonxian / vite-plugin-build

Vite library mode plugin,which support transfom the whole folder and emit dceclaration files. Vite 库模式插件,支持整个文件夹的转换和声明文件生成。(支持 vanilla、react、vue3 和 svelte)
60 stars 6 forks source link

emitDeclaration: true is not work #1

Closed linxiaowu66 closed 2 years ago

linxiaowu66 commented 2 years ago

Hi, I use this plugin for generate my .d.ts, but is not work.

Node: v18.4.0

config:

buildPlugin({
      libBuild: {
        buildOptions: {
          rollupOptions: {
            external: ['react', 'react-dom'],
            output: {
              globals: {
                react: 'React',
                'react-dom': 'ReactDOM',
              },
            },
          },
          lib: {
            entry: path.resolve(__dirname, 'src/index.ts'),
            name: 'cp-common',
            formats: ['es', 'umd'],
            fileName: (format) => `cp-common.${format}.js`,
          },
        },
      },
      fileBuild: { emitDeclaration: true },
    }),

I debug the source code ,found this plugin report error when emit the types file:

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list

this error report from ./bin/tsc shell script.

If I modify this line of code in the emitDeclaration.ts to:

spawn.sync(
        isVue ? vueTscPath : tscPath,
        [
          '--rootDir',
          rootDir,
          '--declaration',
          '--emitDeclarationOnly',
          '--declarationDir',
          outputDir,
        ],
        {
          stdio: 'ignore',
        },
      );

It will be ok.

So this is bug or not ?

samonxian commented 2 years ago

tsc is a bin file, you are right, i should use the code below.

spawn.sync(
  isVue ? vueTscPath : tscPath,
  [
    '--rootDir',
    rootDir,
    '--declaration',
    '--emitDeclarationOnly',
    '--declarationDir',
    outputDir,
  ],
  {
    stdio: 'ignore',
  },
);
samonxian commented 2 years ago

我这边 Mac 验证了没问题,你用的是 Windows、Linux 或者 Mac? Linux 我这边 nvm 安装不了 node v18 版本,验证不了, 理论上 node 运行 bin 文件和直接运行 bin 文件都没有问题才对。 但是如果你那边有问题,运行 bin 没问题的话,改为直接使用 bin 的方式兼容性更好。

lance-li commented 1 year ago
image

node:18.14.0

没有生成声明文件(*.d.ts),

mac iterm zsh