conventional-changelog-writer
Advanced tools
Comparing version 7.0.0 to 7.0.1
170
index.js
@@ -5,3 +5,3 @@ 'use strict' | ||
const { join } = require('path') | ||
const { readFileSync } = require('fs') | ||
const { readFile } = require('fs/promises') | ||
const { valid: semverValid } = require('semver') | ||
@@ -19,3 +19,7 @@ const { | ||
function conventionalChangelogWriterInit (context, options) { | ||
function immediate () { | ||
return new Promise(resolve => setImmediate(resolve)) | ||
} | ||
async function conventionalChangelogWriterInit (context, options) { | ||
context = { | ||
@@ -32,2 +36,14 @@ commit: 'commits', | ||
const [ | ||
mainTemplate, | ||
headerPartial, | ||
commitPartial, | ||
footerPartial | ||
] = await Promise.all([ | ||
readFile(join(__dirname, 'templates/template.hbs'), 'utf-8'), | ||
readFile(join(__dirname, 'templates/header.hbs'), 'utf-8'), | ||
readFile(join(__dirname, 'templates/commit.hbs'), 'utf-8'), | ||
readFile(join(__dirname, 'templates/footer.hbs'), 'utf-8') | ||
]) | ||
options = { | ||
@@ -45,6 +61,6 @@ groupBy: 'type', | ||
doFlush: true, | ||
mainTemplate: readFileSync(join(__dirname, 'templates/template.hbs'), 'utf-8'), | ||
headerPartial: readFileSync(join(__dirname, 'templates/header.hbs'), 'utf-8'), | ||
commitPartial: readFileSync(join(__dirname, 'templates/commit.hbs'), 'utf-8'), | ||
footerPartial: readFileSync(join(__dirname, 'templates/footer.hbs'), 'utf-8'), | ||
mainTemplate, | ||
headerPartial, | ||
commitPartial, | ||
footerPartial, | ||
...options | ||
@@ -93,5 +109,4 @@ } | ||
function conventionalChangelogWriterParseStream (context, options) { | ||
let generateOn | ||
({ context, options, generateOn } = conventionalChangelogWriterInit(context, options)) | ||
function conventionalChangelogWriterParseStream (inputContext, inputOptions) { | ||
const initPromise = conventionalChangelogWriterInit(inputContext, inputOptions) | ||
let commits = [] | ||
@@ -105,38 +120,29 @@ let neverGenerated = true | ||
highWaterMark: 16, | ||
async transform (chunk, _enc, cb) { | ||
try { | ||
let result | ||
const commit = await processCommit(chunk, options.transform, context) | ||
const keyCommit = commit || chunk | ||
// `transform` option should not return Promises. | ||
// It cause a bug in Node.js 16, because it interprets the Promise resolve as a callback call. | ||
// In Node 20 it handle only callback call, Promises is not handled. | ||
transform (chunk, _enc, cb) { | ||
(async () => { | ||
try { | ||
const { context, options, generateOn } = await initPromise | ||
let result | ||
const commit = await processCommit(chunk, options.transform, context) | ||
const keyCommit = commit || chunk | ||
// previous blocks of logs | ||
if (options.reverse) { | ||
if (commit) { | ||
commits.push(commit) | ||
} | ||
if (generateOn(keyCommit, commits, context, options)) { | ||
neverGenerated = false | ||
result = await generate(options, commits, context, keyCommit) | ||
if (options.includeDetails) { | ||
this.push({ | ||
log: result, | ||
keyCommit | ||
}) | ||
} else { | ||
this.push(result) | ||
// previous blocks of logs | ||
if (options.reverse) { | ||
if (commit) { | ||
commits.push(commit) | ||
} | ||
commits = [] | ||
} | ||
} else { | ||
if (generateOn(keyCommit, commits, context, options)) { | ||
neverGenerated = false | ||
result = await generate(options, commits, context, savedKeyCommit) | ||
if (generateOn(keyCommit, commits, context, options)) { | ||
neverGenerated = false | ||
result = await generate(options, commits, context, keyCommit) | ||
if (!firstRelease || options.doFlush) { | ||
await immediate() | ||
if (options.includeDetails) { | ||
this.push({ | ||
log: result, | ||
keyCommit: savedKeyCommit | ||
keyCommit | ||
}) | ||
@@ -146,41 +152,67 @@ } else { | ||
} | ||
commits = [] | ||
} | ||
} else { | ||
if (generateOn(keyCommit, commits, context, options)) { | ||
neverGenerated = false | ||
result = await generate(options, commits, context, savedKeyCommit) | ||
firstRelease = false | ||
commits = [] | ||
savedKeyCommit = keyCommit | ||
if (!firstRelease || options.doFlush) { | ||
await immediate() | ||
if (options.includeDetails) { | ||
this.push({ | ||
log: result, | ||
keyCommit: savedKeyCommit | ||
}) | ||
} else { | ||
this.push(result) | ||
} | ||
} | ||
firstRelease = false | ||
commits = [] | ||
savedKeyCommit = keyCommit | ||
} | ||
if (commit) { | ||
commits.push(commit) | ||
} | ||
} | ||
if (commit) { | ||
commits.push(commit) | ||
} | ||
cb() | ||
} catch (err) { | ||
cb(err) | ||
} | ||
cb() | ||
} catch (err) { | ||
cb(err) | ||
} | ||
})() | ||
}, | ||
async flush (cb) { | ||
if (!options.doFlush && (options.reverse || neverGenerated)) { | ||
cb(null) | ||
return | ||
} | ||
flush (cb) { | ||
(async () => { | ||
try { | ||
const { context, options } = await initPromise | ||
try { | ||
const result = await generate(options, commits, context, savedKeyCommit) | ||
if (!options.doFlush && (options.reverse || neverGenerated)) { | ||
cb(null) | ||
return | ||
} | ||
if (options.includeDetails) { | ||
this.push({ | ||
log: result, | ||
keyCommit: savedKeyCommit | ||
}) | ||
} else { | ||
this.push(result) | ||
const result = await generate(options, commits, context, savedKeyCommit) | ||
await immediate() | ||
if (options.includeDetails) { | ||
this.push({ | ||
log: result, | ||
keyCommit: savedKeyCommit | ||
}) | ||
} else { | ||
this.push(result) | ||
} | ||
cb() | ||
} catch (err) { | ||
cb(err) | ||
} | ||
cb() | ||
} catch (err) { | ||
cb(err) | ||
} | ||
})() | ||
} | ||
@@ -196,3 +228,3 @@ }) | ||
rawCommits = [...rawCommits]; | ||
({ context, options, generateOn } = conventionalChangelogWriterInit(context, options)) | ||
({ context, options, generateOn } = await conventionalChangelogWriterInit(context, options)) | ||
let commits = [] | ||
@@ -199,0 +231,0 @@ let savedKeyCommit |
@@ -158,5 +158,5 @@ 'use strict' | ||
} else | ||
if (Array.isArray(commit)) { | ||
return commit.map(cloneCommit) | ||
} | ||
if (Array.isArray(commit)) { | ||
return commit.map(cloneCommit) | ||
} | ||
@@ -163,0 +163,0 @@ const commitClone = {} |
{ | ||
"name": "conventional-changelog-writer", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Write logs based on conventional commits and templates", | ||
@@ -5,0 +5,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32262
552