itty-packager 1.6.7 โ 1.6.9
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/commands/release.js +43 -45
- package/package.json +1 -1
package/lib/commands/release.js
CHANGED
|
@@ -20,7 +20,7 @@ function transformPackageExports(pkg, srcDir) {
|
|
|
20
20
|
if (typeof exportObj === 'string') {
|
|
21
21
|
return transformPath(exportObj)
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
if (typeof exportObj === 'object' && exportObj !== null) {
|
|
25
25
|
const transformed = {}
|
|
26
26
|
for (const [key, value] of Object.entries(exportObj)) {
|
|
@@ -34,7 +34,7 @@ function transformPackageExports(pkg, srcDir) {
|
|
|
34
34
|
}
|
|
35
35
|
return transformed
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
return exportObj
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -42,16 +42,16 @@ function transformPackageExports(pkg, srcDir) {
|
|
|
42
42
|
for (const [key, value] of Object.entries(pkg.exports)) {
|
|
43
43
|
transformedExports[key] = transformExportObj(value)
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
return { ...pkg, exports: transformedExports }
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
return pkg
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function versionBump(currentVersion, type) {
|
|
53
53
|
const parts = currentVersion.split('.').map(Number)
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
switch (type) {
|
|
56
56
|
case 'major':
|
|
57
57
|
return `${parts[0] + 1}.0.0`
|
|
@@ -82,7 +82,7 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
82
82
|
// Show placeholder with hidden cursor
|
|
83
83
|
const placeholderText = '\x1b[90mpress enter to skip\x1b[0m'
|
|
84
84
|
process.stdout.write(`๐ฌ Commit message: ${placeholderText}\x1b[?25l`) // Hide cursor
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
let inputLines = []
|
|
87
87
|
let firstInput = true
|
|
88
88
|
let placeholderCleared = false
|
|
@@ -102,7 +102,7 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
102
102
|
|
|
103
103
|
const handleInput = (chunk) => {
|
|
104
104
|
const key = chunk.toString()
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
// Check for escape sequences
|
|
107
107
|
if (key === '\x1b') {
|
|
108
108
|
// Wait for potential escape sequence completion
|
|
@@ -113,7 +113,7 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
113
113
|
}, 10)
|
|
114
114
|
return
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
// Handle Ctrl+C
|
|
118
118
|
if (key === '\x03') {
|
|
119
119
|
process.stdout.write('\r\x1b[K๐ฌ Commit message: cancelled\x1b[?25h\n')
|
|
@@ -121,7 +121,7 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
121
121
|
reject(new Error('User cancelled with Ctrl+C'))
|
|
122
122
|
return
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
// Handle Enter
|
|
126
126
|
if (key === '\r' || key === '\n') {
|
|
127
127
|
if (!placeholderCleared && inputBuffer === '') {
|
|
@@ -131,13 +131,13 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
131
131
|
resolve(`released v${newVersion}`)
|
|
132
132
|
return
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
// Single line input - finish immediately
|
|
136
136
|
if (firstInput) {
|
|
137
137
|
const customMessage = inputBuffer.trim()
|
|
138
138
|
process.stdout.write('\x1b[?25h\n')
|
|
139
139
|
cleanup()
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
if (!customMessage) {
|
|
142
142
|
process.stdout.write('\r๐ฌ Commit message: \x1b[90mskipped\x1b[0m\n')
|
|
143
143
|
resolve(`released v${newVersion}`)
|
|
@@ -147,13 +147,13 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
147
147
|
}
|
|
148
148
|
return
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
// Multi-line: empty line finishes input
|
|
152
152
|
if (inputBuffer.trim() === '') {
|
|
153
153
|
finishInput()
|
|
154
154
|
return
|
|
155
155
|
}
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
// Add line and continue
|
|
158
158
|
inputLines.push(inputBuffer)
|
|
159
159
|
inputBuffer = ''
|
|
@@ -161,24 +161,24 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
161
161
|
process.stdout.write('\n')
|
|
162
162
|
return
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
// Handle backspace
|
|
166
166
|
if (key === '\x7f' || key === '\x08') {
|
|
167
167
|
if (!placeholderCleared) return // Can't backspace in placeholder
|
|
168
|
-
|
|
168
|
+
|
|
169
169
|
if (inputBuffer.length > 0) {
|
|
170
170
|
inputBuffer = inputBuffer.slice(0, -1)
|
|
171
171
|
process.stdout.write('\b \b')
|
|
172
172
|
}
|
|
173
173
|
return
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
// Handle printable characters
|
|
177
177
|
if (key.length === 1 && key >= ' ' && key <= '~') {
|
|
178
178
|
if (!placeholderCleared) {
|
|
179
179
|
clearPlaceholder()
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
inputBuffer += key
|
|
183
183
|
process.stdout.write(key)
|
|
184
184
|
return
|
|
@@ -195,7 +195,7 @@ async function getCommitMessage(newVersion, silent = false) {
|
|
|
195
195
|
const customMessage = inputLines.join('\n').trim()
|
|
196
196
|
process.stdout.write('\x1b[?25h\n') // Show cursor and newline
|
|
197
197
|
cleanup()
|
|
198
|
-
|
|
198
|
+
|
|
199
199
|
if (!customMessage) {
|
|
200
200
|
resolve(`released v${newVersion}`)
|
|
201
201
|
} else {
|
|
@@ -340,7 +340,7 @@ Usage: itty release [options]
|
|
|
340
340
|
|
|
341
341
|
Version Options (default: patch):
|
|
342
342
|
--major Major release X.#.# for breaking changes
|
|
343
|
-
--minor Minor release #.X.# for feature additions
|
|
343
|
+
--minor Minor release #.X.# for feature additions
|
|
344
344
|
--patch Patch release #.#.X for bug fixes (default)
|
|
345
345
|
--type <type> Custom release type (alpha, beta, rc, etc.)
|
|
346
346
|
|
|
@@ -382,7 +382,7 @@ This creates a clean, flat package structure in node_modules.
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
// Determine release type (default to patch)
|
|
385
|
-
const releaseType = releaseArgs.major ? 'major'
|
|
385
|
+
const releaseType = releaseArgs.major ? 'major'
|
|
386
386
|
: releaseArgs.minor ? 'minor'
|
|
387
387
|
: releaseArgs.patch ? 'patch'
|
|
388
388
|
: releaseArgs.type ? releaseArgs.type
|
|
@@ -393,10 +393,10 @@ This creates a clean, flat package structure in node_modules.
|
|
|
393
393
|
|
|
394
394
|
const rootPath = process.cwd()
|
|
395
395
|
const srcDir = path.join(rootPath, sourceDir)
|
|
396
|
-
|
|
396
|
+
|
|
397
397
|
// Handle root publishing (src=.) by using a different temp directory structure
|
|
398
398
|
const isRootPublish = sourceDir === '.'
|
|
399
|
-
const tempDir = isRootPublish
|
|
399
|
+
const tempDir = isRootPublish
|
|
400
400
|
? path.join(path.dirname(rootPath), `.${path.basename(rootPath)}-dist`)
|
|
401
401
|
: path.join(rootPath, releaseArgs.dest)
|
|
402
402
|
const dryRun = releaseArgs['dry-run']
|
|
@@ -419,9 +419,7 @@ This creates a clean, flat package structure in node_modules.
|
|
|
419
419
|
try {
|
|
420
420
|
// Run prepare if requested
|
|
421
421
|
if (shouldPrepare) {
|
|
422
|
-
console.log('๐ Running prepare sequence before publishing...')
|
|
423
422
|
await prepareCommand(verbose ? ['--verbose'] : [])
|
|
424
|
-
console.log('โ
Prepare completed successfully\n')
|
|
425
423
|
}
|
|
426
424
|
|
|
427
425
|
console.log(`๐ฆ Releasing ${originalPkg.name} v${originalVersion} โ v${newVersion}`)
|
|
@@ -440,23 +438,23 @@ This creates a clean, flat package structure in node_modules.
|
|
|
440
438
|
// Copy source files to temp directory
|
|
441
439
|
console.log(`๐ Copying files...`)
|
|
442
440
|
if (verbose) console.log(`๐ Copying ${sourceDir}/ to ${path.relative(rootPath, tempDir)}/`)
|
|
443
|
-
|
|
441
|
+
|
|
444
442
|
const filter = (src) => {
|
|
445
443
|
// Always exclude node_modules
|
|
446
444
|
if (src.includes('node_modules')) return false
|
|
447
|
-
|
|
445
|
+
|
|
448
446
|
// For root publishing, exclude additional files
|
|
449
447
|
if (isRootPublish) {
|
|
450
448
|
const relativePath = path.relative(srcDir, src)
|
|
451
|
-
return !relativePath.startsWith('.git') &&
|
|
449
|
+
return !relativePath.startsWith('.git') &&
|
|
452
450
|
!relativePath.includes('.DS_Store') &&
|
|
453
451
|
!relativePath.includes('coverage/') &&
|
|
454
452
|
!relativePath.includes('.nyc_output/')
|
|
455
453
|
}
|
|
456
|
-
|
|
454
|
+
|
|
457
455
|
return true
|
|
458
456
|
}
|
|
459
|
-
|
|
457
|
+
|
|
460
458
|
await fs.copy(srcDir, tempDir, { filter })
|
|
461
459
|
|
|
462
460
|
// Copy root files that should be included in the package (only for non-root publishing)
|
|
@@ -465,14 +463,14 @@ This creates a clean, flat package structure in node_modules.
|
|
|
465
463
|
'README.md', // Always copy README
|
|
466
464
|
'.npmrc' // Always copy .npmrc if it exists
|
|
467
465
|
]
|
|
468
|
-
|
|
466
|
+
|
|
469
467
|
// Add optional files based on flags
|
|
470
468
|
if (!noLicense) rootFiles.push('LICENSE')
|
|
471
|
-
|
|
469
|
+
|
|
472
470
|
for (const file of rootFiles) {
|
|
473
471
|
const srcFile = path.join(rootPath, file)
|
|
474
472
|
const destFile = path.join(tempDir, file)
|
|
475
|
-
|
|
473
|
+
|
|
476
474
|
if (await fs.pathExists(srcFile)) {
|
|
477
475
|
if (verbose) console.log(`๐ Copying ${file}`)
|
|
478
476
|
await fs.copy(srcFile, destFile)
|
|
@@ -481,11 +479,11 @@ This creates a clean, flat package structure in node_modules.
|
|
|
481
479
|
}
|
|
482
480
|
|
|
483
481
|
// Update package.json in temp directory with transformed paths
|
|
484
|
-
const updatedPkg = isRootPublish
|
|
482
|
+
const updatedPkg = isRootPublish
|
|
485
483
|
? { ...originalPkg, version: newVersion } // No path transformation for root publishing
|
|
486
484
|
: transformPackageExports({ ...originalPkg, version: newVersion }, sourceDir)
|
|
487
485
|
const tempPkgPath = path.join(tempDir, 'package.json')
|
|
488
|
-
|
|
486
|
+
|
|
489
487
|
const transformMessage = isRootPublish ? '' : ' (transforming paths)'
|
|
490
488
|
if (verbose) console.log(`๐ Updating package.json to v${newVersion}${transformMessage}`)
|
|
491
489
|
await fs.writeJSON(tempPkgPath, updatedPkg, { spaces: 2 })
|
|
@@ -499,19 +497,19 @@ This creates a clean, flat package structure in node_modules.
|
|
|
499
497
|
// Git operations (before publishing)
|
|
500
498
|
if (!noGit && !dryRun) {
|
|
501
499
|
let commitMessage = `released v${newVersion}` // Default message
|
|
502
|
-
|
|
500
|
+
|
|
503
501
|
if (shouldPush || shouldTag) {
|
|
504
502
|
try {
|
|
505
503
|
// Get commit message (interactive or default)
|
|
506
504
|
commitMessage = await getCommitMessage(newVersion, silent)
|
|
507
|
-
|
|
505
|
+
|
|
508
506
|
console.log(`๐ Committing changes...`)
|
|
509
507
|
if (verbose) console.log(`Running: git add . && git commit`)
|
|
510
508
|
await runCommand('git add .', rootPath, verbose)
|
|
511
509
|
await runCommand(`git commit -m "${commitMessage}"`, rootPath, verbose)
|
|
512
510
|
} catch (error) {
|
|
513
511
|
if (error.message.includes('cancelled')) {
|
|
514
|
-
console.log('
|
|
512
|
+
console.log('โ Commit cancelled - reverting version and exiting')
|
|
515
513
|
// Revert the version we just updated
|
|
516
514
|
await fs.writeJSON(pkgPath, originalPkg, { spaces: 2 })
|
|
517
515
|
// Don't rethrow - exit cleanly since this is user-initiated
|
|
@@ -529,7 +527,7 @@ This creates a clean, flat package structure in node_modules.
|
|
|
529
527
|
if (shouldPush) {
|
|
530
528
|
console.log(`๐ค Pushing to remote...`)
|
|
531
529
|
await runCommand('git push', rootPath, verbose)
|
|
532
|
-
|
|
530
|
+
|
|
533
531
|
if (shouldTag) {
|
|
534
532
|
console.log(`๐ Pushing tags...`)
|
|
535
533
|
await runCommand('git push --tags', rootPath, verbose)
|
|
@@ -539,11 +537,11 @@ This creates a clean, flat package structure in node_modules.
|
|
|
539
537
|
|
|
540
538
|
// NPM publish as final step
|
|
541
539
|
if (dryRun) {
|
|
542
|
-
console.log('
|
|
540
|
+
console.log('๐ธ Dry run - skipping publish')
|
|
543
541
|
} else {
|
|
544
542
|
// Publish from temp directory
|
|
545
543
|
console.log(`๐ Publishing to npm...`)
|
|
546
|
-
|
|
544
|
+
|
|
547
545
|
const publishCmd = [
|
|
548
546
|
'npm publish',
|
|
549
547
|
'--registry=https://registry.npmjs.org',
|
|
@@ -561,11 +559,11 @@ This creates a clean, flat package structure in node_modules.
|
|
|
561
559
|
await fs.remove(tempDir)
|
|
562
560
|
}
|
|
563
561
|
|
|
564
|
-
console.log(
|
|
565
|
-
|
|
562
|
+
console.log(`๐ Successfully released ${originalPkg.name}@${newVersion}`)
|
|
563
|
+
|
|
566
564
|
} catch (error) {
|
|
567
565
|
console.error(`โ Release failed: ${error.message}`)
|
|
568
|
-
|
|
566
|
+
|
|
569
567
|
// Revert version in root package.json if it was changed
|
|
570
568
|
if (!dryRun) {
|
|
571
569
|
try {
|
|
@@ -579,12 +577,12 @@ This creates a clean, flat package structure in node_modules.
|
|
|
579
577
|
console.error(`โ Failed to revert version: ${revertError.message}`)
|
|
580
578
|
}
|
|
581
579
|
}
|
|
582
|
-
|
|
580
|
+
|
|
583
581
|
// Cleanup on error
|
|
584
582
|
if (await fs.pathExists(tempDir) && !noCleanup) {
|
|
585
583
|
await fs.remove(tempDir)
|
|
586
584
|
}
|
|
587
|
-
|
|
585
|
+
|
|
588
586
|
throw error
|
|
589
587
|
}
|
|
590
588
|
}
|