@stacksjs/iconify-generator 0.2.21 → 0.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.ts +44 -13
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/iconify-generator",
3
3
  "type": "module",
4
- "version": "0.2.21",
4
+ "version": "0.2.24",
5
5
  "description": "Generator for Iconify icon packages",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "dev": "bun build.ts --watch"
34
34
  },
35
35
  "dependencies": {
36
- "@stacksjs/iconify-core": "0.2.21"
36
+ "@stacksjs/iconify-core": "0.2.24"
37
37
  }
38
38
  }
package/src/index.ts CHANGED
@@ -292,24 +292,55 @@ export function generatePackageJson(
292
292
  * Generate build.ts file for a collection
293
293
  */
294
294
  export function generateBuildFile(prefix: string): string {
295
- return `import { join, dirname } from 'node:path'
295
+ return `import { existsSync, readdirSync, statSync } from 'node:fs'
296
+ import { dirname, join } from 'node:path'
296
297
  import { fileURLToPath } from 'node:url'
297
298
  import dts from 'bun-plugin-dtsx'
298
299
 
299
300
  const __dirname = dirname(fileURLToPath(import.meta.url))
301
+ const srcDir = join(__dirname, 'src')
302
+ const distDir = join(__dirname, 'dist')
303
+ const distEntry = join(distDir, 'index.js')
304
+
305
+ // Skip rebuild when dist is already up to date. Makes prepublishOnly a
306
+ // no-op when CI pre-built the package in parallel earlier in the
307
+ // pipeline — and a no-op for local re-runs that didn't touch src/.
308
+ //
309
+ // Walks src/ recursively so changes inside subdirectories (if we ever
310
+ // add them) properly invalidate the cached dist.
311
+ function isDistFresh() {
312
+ if (!existsSync(distEntry)) return false
313
+ const distMtime = statSync(distEntry).mtimeMs
314
+ function newer(dir) {
315
+ for (const name of readdirSync(dir)) {
316
+ const p = join(dir, name)
317
+ const s = statSync(p)
318
+ if (s.isDirectory()) {
319
+ if (newer(p)) return true
320
+ } else if (s.mtimeMs > distMtime) {
321
+ return true
322
+ }
323
+ }
324
+ return false
325
+ }
326
+ return !newer(srcDir)
327
+ }
300
328
 
301
- await Bun.build({
302
- entrypoints: [join(__dirname, 'src/index.ts')],
303
- outdir: join(__dirname, 'dist'),
304
- target: 'bun',
305
- format: 'esm',
306
- plugins: [dts()],
307
- minify: false,
308
- sourcemap: 'external',
309
- splitting: true,
310
- })
311
-
312
- console.log('✓ Built @stacksjs/iconify-${prefix}')
329
+ if (isDistFresh()) {
330
+ console.log('✓ @stacksjs/iconify-${prefix} dist is fresh, skipping rebuild')
331
+ } else {
332
+ await Bun.build({
333
+ entrypoints: [join(srcDir, 'index.ts')],
334
+ outdir: distDir,
335
+ target: 'bun',
336
+ format: 'esm',
337
+ plugins: [dts()],
338
+ minify: false,
339
+ sourcemap: 'external',
340
+ splitting: true,
341
+ })
342
+ console.log('✓ Built @stacksjs/iconify-${prefix}')
343
+ }
313
344
  `
314
345
  }
315
346