@stacksjs/iconify-generator 0.2.20 → 0.2.22

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 +52 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/iconify-generator",
3
3
  "type": "module",
4
- "version": "0.2.20",
4
+ "version": "0.2.22",
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.20"
36
+ "@stacksjs/iconify-core": "0.2.21"
37
37
  }
38
38
  }
package/src/index.ts CHANGED
@@ -192,9 +192,27 @@ const svg = \`<svg xmlns="http://www.w3.org/2000/svg" width="\${iconWidth}" heig
192
192
  * Generate index file for a collection
193
193
  */
194
194
  export function generateIndexFile(iconNames: string[]): string {
195
+ // toCamelCase can produce collisions across distinct kebab names
196
+ // (e.g. "mp-401" and "mp-4-01" both → "mp401"). Track used identifiers
197
+ // and disambiguate later occurrences with a fully-sanitized form of the
198
+ // original kebab name, then a numeric suffix as a final fallback.
199
+ const used = new Set<string>()
195
200
  const dataExports = iconNames.map((name) => {
196
- const camelCaseName = toCamelCase(name)
197
- return `export { default as ${camelCaseName} } from './${name}.js'`
201
+ const primary = toCamelCase(name)
202
+ let id = primary
203
+ if (used.has(id)) {
204
+ let candidate = name.replace(/[^a-zA-Z0-9]/g, '_')
205
+ if (/^[0-9]/.test(candidate))
206
+ candidate = `_${candidate}`
207
+ id = candidate
208
+ let n = 2
209
+ while (used.has(id)) {
210
+ id = `${candidate}_${n}`
211
+ n++
212
+ }
213
+ }
214
+ used.add(id)
215
+ return `export { default as ${id} } from './${name}.js'`
198
216
  }).join('\n')
199
217
 
200
218
  return `// Icon data exports
@@ -274,24 +292,43 @@ export function generatePackageJson(
274
292
  * Generate build.ts file for a collection
275
293
  */
276
294
  export function generateBuildFile(prefix: string): string {
277
- return `import { join, dirname } from 'node:path'
295
+ return `import { existsSync, readdirSync, statSync } from 'node:fs'
296
+ import { dirname, join } from 'node:path'
278
297
  import { fileURLToPath } from 'node:url'
279
298
  import dts from 'bun-plugin-dtsx'
280
299
 
281
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
+ function isDistFresh() {
309
+ if (!existsSync(distEntry)) return false
310
+ const distMtime = statSync(distEntry).mtimeMs
311
+ for (const name of readdirSync(srcDir)) {
312
+ if (statSync(join(srcDir, name)).mtimeMs > distMtime) return false
313
+ }
314
+ return true
315
+ }
282
316
 
283
- await Bun.build({
284
- entrypoints: [join(__dirname, 'src/index.ts')],
285
- outdir: join(__dirname, 'dist'),
286
- target: 'bun',
287
- format: 'esm',
288
- plugins: [dts()],
289
- minify: false,
290
- sourcemap: 'external',
291
- splitting: true,
292
- })
293
-
294
- console.log('✓ Built @stacksjs/iconify-${prefix}')
317
+ if (isDistFresh()) {
318
+ console.log('✓ @stacksjs/iconify-${prefix} dist is fresh, skipping rebuild')
319
+ } else {
320
+ await Bun.build({
321
+ entrypoints: [join(srcDir, 'index.ts')],
322
+ outdir: distDir,
323
+ target: 'bun',
324
+ format: 'esm',
325
+ plugins: [dts()],
326
+ minify: false,
327
+ sourcemap: 'external',
328
+ splitting: true,
329
+ })
330
+ console.log('✓ Built @stacksjs/iconify-${prefix}')
331
+ }
295
332
  `
296
333
  }
297
334