|
1 | | -import{existsSync}from'node:fs' |
2 | | -import{readdir,readFile}from'node:fs/promises' |
| 1 | +import{access,readdir,readFile,writeFile}from'node:fs/promises' |
3 | 2 | importpathfrom'node:path' |
4 | 3 | importfgfrom'fast-glob' |
5 | 4 | import{dedupeDeps,defineConfig}from'monoman' |
6 | 5 | import{docsLink,githubLink}from'./macros/repo' |
7 | 6 | importtype{PackageJson}from'pkg-types' |
8 | 7 | importtype{Options}from'tsup' |
9 | 8 |
|
| 9 | +functionexists(filePath:string){ |
| 10 | +returnaccess(filePath).then( |
| 11 | +()=>true, |
| 12 | +()=>false, |
| 13 | +) |
| 14 | +} |
| 15 | + |
10 | 16 | functiongetPkgName(filePath:string){ |
11 | 17 | constrelative=path.relative(import.meta.dirname,filePath) |
12 | 18 | const[,pkgName]=relative.split(path.sep) |
@@ -67,8 +73,35 @@ export default defineConfig([ |
67 | 73 | if(hasRootDts)data.files.push('*.d.ts') |
68 | 74 | data.files.sort() |
69 | 75 |
|
| 76 | +if( |
| 77 | +Object.keys(data.dependencies||{}).includes('unplugin')|| |
| 78 | +data?.meta?.plugin |
| 79 | +){ |
| 80 | +data.keywords!.push('unplugin') |
| 81 | + |
| 82 | +// write unplugin entries |
| 83 | +constentries=[ |
| 84 | +'vite', |
| 85 | +'webpack', |
| 86 | +'rollup', |
| 87 | +'esbuild', |
| 88 | +'rspack', |
| 89 | +'rolldown', |
| 90 | +] |
| 91 | +Promise.all( |
| 92 | +entries.map((entry)=> |
| 93 | +writeFile( |
| 94 | +path.resolve(pkgSrc,`${entry}.ts`), |
| 95 | +`import unplugin from '.'\n |
| 96 | +export default unplugin.${entry} as typeof unplugin.${entry}\n`, |
| 97 | +'utf8', |
| 98 | +), |
| 99 | +), |
| 100 | +) |
| 101 | +} |
| 102 | + |
70 | 103 | consttsupFile=path.resolve(pkgRoot,'tsup.config.ts') |
71 | | -if(!data.meta?.skipExports&&existsSync(tsupFile)){ |
| 104 | +if(!data.meta?.skipExports&&(awaitexists(tsupFile))){ |
72 | 105 | consttsupConfig:Options=(awaitimport(tsupFile)).default |
73 | 106 | constformat=tsupConfig.format||[] |
74 | 107 | consthasCJS=format.includes('cjs') |
@@ -116,13 +149,6 @@ export default defineConfig([ |
116 | 149 | } |
117 | 150 | } |
118 | 151 |
|
119 | | -if( |
120 | | -Object.keys(data.dependencies||{}).includes('unplugin')|| |
121 | | -data?.meta?.plugin |
122 | | -){ |
123 | | -data.keywords!.push('unplugin') |
124 | | -} |
125 | | - |
126 | 152 | returndata |
127 | 153 | }, |
128 | 154 | }, |
|