| 230 | } |
| 231 | |
| 232 | export async function updatePackageJSON(indexes: PackageIndexes) { |
| 233 | const { version } = JSON.parse(await fs.readFile('package.json', { encoding: 'utf8' })) |
| 234 | |
| 235 | for (const { name, description, author, submodules, iife } of packages) { |
| 236 | const packageDir = join(DIR_SRC, name) |
| 237 | const packageJSONPath = join(packageDir, 'package.json') |
| 238 | const packageJSON = JSON.parse(await fs.readFile(packageJSONPath, { encoding: 'utf8' })) |
| 239 | |
| 240 | packageJSON.version = version |
| 241 | packageJSON.description = description || packageJSON.description |
| 242 | packageJSON.author = author || 'Anthony Fu <https://github.com/antfu>' |
| 243 | packageJSON.bugs = { |
| 244 | url: 'https://github.com/vueuse/vueuse/issues', |
| 245 | } |
| 246 | packageJSON.type = 'module' |
| 247 | packageJSON.homepage = name === 'core' |
| 248 | ? 'https://github.com/vueuse/vueuse#readme' |
| 249 | : `https://github.com/vueuse/vueuse/tree/main/packages/${name}#readme` |
| 250 | packageJSON.repository = { |
| 251 | type: 'git', |
| 252 | url: 'git+https://github.com/vueuse/vueuse.git', |
| 253 | directory: `packages/${name}`, |
| 254 | } |
| 255 | packageJSON.main = './index.mjs' |
| 256 | packageJSON.types = './index.d.mts' |
| 257 | packageJSON.module = './index.mjs' |
| 258 | if (iife !== false) { |
| 259 | packageJSON.unpkg = './index.iife.min.js' |
| 260 | packageJSON.jsdelivr = './index.iife.min.js' |
| 261 | } |
| 262 | packageJSON.files = [ |
| 263 | '*.d.mts', |
| 264 | '*.js', |
| 265 | '*.mjs', |
| 266 | ] |
| 267 | |
| 268 | if (submodules) { |
| 269 | packageJSON.files = packageJSON.files.map((i: string) => `**/${i}`) |
| 270 | } |
| 271 | |
| 272 | if (name === 'metadata') { |
| 273 | packageJSON.files.push('index.json') |
| 274 | } |
| 275 | |
| 276 | packageJSON.exports = { |
| 277 | '.': './index.mjs', |
| 278 | ...packageJSON.exports, |
| 279 | './*': './*', |
| 280 | } |
| 281 | |
| 282 | if (submodules) { |
| 283 | indexes.functions |
| 284 | .filter(i => i.package === name) |
| 285 | .forEach((i) => { |
| 286 | packageJSON.exports[`./${i.name}`] = `./${i.name}.mjs` |
| 287 | if (i.component) { |
| 288 | packageJSON.exports[`./${i.name}/component`] = `./${i.name}/component.mjs` |
| 289 | } |