qmhc / vite-plugin-dts

A Vite plugin for generating `.d.ts` files.
MIT License
1.31k stars 90 forks source link

Error: File not found: commonjsHelpers.js #36

Closed skimhugo closed 2 years ago

skimhugo commented 3 years ago

at DirectoryCoordinator.addSourceFileAtPath (./node_modules/ts-morph/dist/ts-morph.js:18117:19) at Project.addSourceFileAtPath (./node_modules/ts-morph/dist/ts-morph.js:19567:51) at Object.transform (./node_modules/vite-plugin-dts/dist/index.js:138846:17) at ./node_modules/rollup/dist/shared/rollup.js:22620:25

qmhc commented 3 years ago

Would you provide a test project to reproduce this issue?

skimhugo commented 3 years ago

`import { encrypt, decrypt } from 'crypto-js/aes'; import UTF8, { parse } from 'crypto-js/enc-utf8'; import pkcs7 from 'crypto-js/pad-pkcs7'; import ECB from 'crypto-js/mode-ecb'; import md5 from 'crypto-js/md5'; // import UTF8 from 'crypto-js/enc-utf8'; import Base64 from 'crypto-js/enc-base64'; import type WordArray from 'crypto-js/lib-typedarrays'; import type crypto from 'crypto-js'; type CipherParams = crypto.lib.CipherParams;

// type WordArray = lib.WordArray; // aes encryption key export const cacheCipher = { key: '11111000001111@', iv: '@11111000001111', };

// 加密参数 export interface EncryptionParams { key: string; iv: string; }

interface Format { stringify: (cipherParams: CipherParams) => string; parse: (str: string) => CipherParams; }

interface CipherOption { iv?: WordArray | undefined; format?: Format | undefined;

} // interface CipherOptionCopy { // /* // The IV to use for this operation. // */ // iv?: WordArray | undefined; // format?: Format | undefined; // key: string: any; // }

// export interface CipherOptions { // mode: typeof ECB; // padding: typeof pkcs7; // key: WordArray | null; // iv: WordArray | null; // }

// JSON.stringify() // JSON.parse() // usage const encryption = new AesEncryption({ key, iv }); // const stringifyValue = this.hasEncrypt // ? this.encryption.encryptByAES(stringData) // : stringData; // const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val; // const data = JSON.parse(decVal); //

// aes加密器 export class AesEncryption { private readonly key: WordArray | undefined = undefined; private readonly iv: WordArray | undefined = undefined;

public constructor(opt: Partial = {}) { const { key, iv } = opt; if (!key || !iv) { throw new Error('the key or iv can not be empty!'); } else if ([key.length, iv.length].some((item) => item !== 16)) { throw new Error('the key or iv must be 16 bits!'); } if (key) { this.key = parse(key); } if (iv) { this.iv = parse(iv); } }

public get getOptions(): CipherOption { return { mode: ECB, padding: pkcs7, key: this.key, iv: this.iv, }; }

// 加密 public encryptByAES(cipherText: string) { return encrypt(cipherText, this.key as WordArray, this.getOptions).toString(); }

// 解密 public decryptByAES(cipherText: string) { return decrypt(cipherText, this.key as WordArray, this.getOptions).toString(UTF8); } }

export function encryptByBase64(cipherText: string) { return UTF8.parse(cipherText).toString(Base64); }

export function decodeByBase64(cipherText: string) { return Base64.parse(cipherText).toString(UTF8); }

export function encryptByMd5(password: string) { return md5(password).toString(); } `

index.ts: export * from '@/cipher'; dependency "crypto-js": "^4.1.1",

skimhugo commented 3 years ago

@qmhc I think this problem is because crypto-js is a umd package. I'm trying rewrite crypto-js to ts project. but I think if there are common solution is good

luozhihua commented 3 years ago

commonjsHelpers.js 是 Vite 中生成的一个虚拟文件名,本身就不存在,看有没有办法直接判断一下这个文件名,将它忽略掉

skimhugo commented 2 years ago

@luozhihua 没有继续深挖这个问题,目前用 tsup 和 tsc 进行 type 的打包。由于 type 实际只存在于运行态,目前我计划后续研究下 esbuild 在这方面的问题。依赖 rollup 进行对 ts 的类型打包有一些问题,尤其因为我还用了 pnpm,尤其麻烦。只好先作罢了。

CaiWenlie commented 2 years ago

commonjsHelpers.js 是 Vite 中生成的一个虚拟文件名,本身就不存在,看有没有办法直接判断一下这个文件名,将它忽略掉

额,打包之后还是有这个文件是咋回事 image

LLwyct commented 1 week ago

请问问题解决了吗,我打包也有一个 _commonjsHelpers-DaMA6jEr.js 不知道是干嘛的