itty-packager 1.6.11 → 1.6.13

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.
package/lib/builder.js CHANGED
@@ -36,7 +36,7 @@ export async function build(options = {}) {
36
36
  name: path.basename(filePath, '.ts'),
37
37
  shortPath: filePath.replace(new RegExp(`(/${from})|(\.ts)`, 'g'), '').replace('./index', '.'),
38
38
  esm: path.join(out, path.basename(filePath, '.ts') + '.mjs'),
39
- cjs: path.join(out, path.basename(filePath, '.ts') + '.cjs'),
39
+ cjs: path.join(out, path.basename(filePath, '.ts') + '.js'),
40
40
  types: path.join(out, path.basename(filePath, '.ts') + '.d.ts'),
41
41
  })).sort((a, b) => a.shortPath.toLowerCase() < b.shortPath.toLowerCase() ? -1 : 1)
42
42
 
@@ -205,6 +205,15 @@ async function injectSnippet(snippetName, outDir) {
205
205
 
206
206
  const exportedVar = exportMatch[1]
207
207
 
208
+ // Check if this is a function declaration
209
+ const functionDeclRegex = new RegExp(`function\\s+${exportedVar}\\s*\\(`)
210
+ if (functionDeclRegex.test(code)) {
211
+ // Replace function name and strip export
212
+ return code
213
+ .replace(functionDeclRegex, `function ${snippetName}(`)
214
+ .replace(/;export\s*{[^}]+};?\s*$/, ';')
215
+ }
216
+
208
217
  // Find the final assignment to the exported variable (usually at module level)
209
218
  // Look for patterns like "exportedVar=someFunction()" at the end before export
210
219
  const finalAssignmentRegex = new RegExp(`(\\b${exportedVar}\\s*=\\s*[^;]+);export`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-packager",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "description": "Universal build tool for itty libraries",
5
5
  "type": "module",
6
6
  "bin": {
@@ -137,7 +137,7 @@ export default function main() {
137
137
 
138
138
  // Should have both ESM and CJS outputs
139
139
  await expectFile(path.join(project.dir, 'dist/main.mjs')).toExist()
140
- await expectFile(path.join(project.dir, 'dist/main.cjs')).toExist()
140
+ await expectFile(path.join(project.dir, 'dist/main.js')).toExist()
141
141
 
142
142
  // Release should work with hybrid build
143
143
  const releaseResult = await cli.run([