Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specify path for changelog WIP #673

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.22.0",
"scripts": {
"postinstall": "patch-package",
"prepare": "yarn build",
"build": "yarn workspace shipjs-lib build",
"lint": "lerna run lint --stream",
Expand Down Expand Up @@ -29,5 +30,9 @@
"devDependencies": {
"all-contributors-cli": "6.15.0",
"lerna": "3.22.0"
},
"dependencies": {
"patch-package": "^6.2.2",
"postinstall-postinstall": "^2.1.0"
}
}
}
2 changes: 0 additions & 2 deletions packages/shipjs-lib/src/lib/config/loadConfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import dotenv from 'dotenv';
import { resolve } from 'path';
import { promises as fs, constants } from 'fs';

import defaultConfig from './defaultConfig';
import mergeConfig from './mergeConfig';
dotenv.config();

const exist = (path) =>
fs
Expand Down
7 changes: 5 additions & 2 deletions packages/shipjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
"arg": "4.1.3",
"chalk": "4.0.0",
"change-case": "4.1.1",
"conventional-changelog": "^3.1.15",
"conventional-changelog-angular": "^5.0.6",
"conventional-changelog-core": "^4.1.4",
"conventional-changelog-preset-loader": "^2.3.0",
"deepmerge": "^4.2.2",
"dotenv": "^8.2.0",
"ejs": "^3.0.0",
"esm": "3.2.25",
Expand Down Expand Up @@ -76,4 +79,4 @@
"jest": "26.0.1",
"jest-watch-typeahead": "0.6.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseArgs } from '../../../util';
import tempWrite from 'temp-write';

describe('prepareParams', () => {
it('loads configuration from --config option', () => {
it('loads configuration from --config option', async () => {
parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs);
const config = {
writerOpts: {
Expand All @@ -15,7 +15,7 @@ describe('prepareParams', () => {
const configPath = tempWrite.sync(configString);
const configDir = path.basename(path.dirname(configPath));

const { args } = prepareParams({
const { args } = await prepareParams({
dir: configDir,
conventionalChangelogArgs: `-i CHANGELOG.md -s --config ${configPath}`,
revisionRange: '1.0.0..1.0.1',
Expand Down
51 changes: 37 additions & 14 deletions packages/shipjs/src/step/prepare/updateChangelog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import path from 'path';
import fs from 'fs';
import conventionalChangelog from 'conventional-changelog';
import conventionalChangelogCore from 'conventional-changelog-core';
import conventionalChangelogPresetLoader from 'conventional-changelog-preset-loader';
import tempfile from 'tempfile';
import addStream from 'add-stream';
import merge from 'deepmerge';
import runStep from '../runStep';
import { parseArgs } from '../../util';

Expand All @@ -25,20 +27,22 @@ export default ({
}
return new Promise((resolve, reject) => {
const { conventionalChangelogArgs } = config;
const { args, gitRawCommitsOpts, templateContext } = prepareParams({
prepareParams({
dir,
conventionalChangelogArgs,
releaseCount,
firstRelease,
revisionRange,
reject,
});
runConventionalChangelog({
args,
templateContext,
gitRawCommitsOpts,
resolve,
reject,
}).then(({ args, gitRawCommitsOpts, templateContext }) => {
runConventionalChangelog({
args,
templateContext,
gitRawCommitsOpts,
resolve,
reject,
dir,
});
});
});
}
Expand Down Expand Up @@ -78,7 +82,7 @@ const argSpec = {
'-t': '--tag-prefix',
};

export function prepareParams({
export async function prepareParams({
dir,
conventionalChangelogArgs,
releaseCount,
Expand Down Expand Up @@ -118,9 +122,24 @@ export function prepareParams({
}
const templateContext =
args.context && require(path.resolve(dir, args.context));
if (args.config) {
args.config = require(path.resolve(dir, args.config));
args.config = args.config ? require(path.resolve(dir, args.config)) : {};
if (args.preset) {
try {
args.config = merge(
await conventionalChangelogPresetLoader(args.preset),
args.config
);
} catch (err) {
if (typeof args.preset === 'object') {
args.warn(`Preset: "${args.preset.name}" ${err.message}`);
} else if (typeof args.preset === 'string') {
args.warn(`Preset: "${args.preset}" ${err.message}`);
} else {
args.warn(`Preset: ${err.message}`);
}
}
}

return { args, gitRawCommitsOpts, templateContext };
}

Expand All @@ -130,15 +149,19 @@ function runConventionalChangelog({
gitRawCommitsOpts,
resolve,
reject,
dir,
}) {
if (!fs.existsSync(args.outfile)) {
fs.writeFileSync(args.outfile, '');
}

const changelogStream = conventionalChangelog(
const changelogStream = conventionalChangelogCore(
args,
templateContext,
gitRawCommitsOpts
{ ...gitRawCommitsOpts, path: dir },
undefined,
undefined,
{ path: dir, cwd: dir }
).on('error', reject);

const readStream = fs.createReadStream(args.infile).on('error', reject);
Expand Down
26 changes: 26 additions & 0 deletions patches/conventional-changelog-core+4.2.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/node_modules/conventional-changelog-core/index.js b/node_modules/conventional-changelog-core/index.js
index a7eb756..f095452 100644
--- a/node_modules/conventional-changelog-core/index.js
+++ b/node_modules/conventional-changelog-core/index.js
@@ -29,7 +29,7 @@ function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts,
return gitRawCommits(_.merge({}, gitRawCommitsOpts, {
from: from,
to: to
- }))
+ }), gitRawExecOpts)
.on('error', function (err) {
if (!commitsErrorThrown) {
setImmediate(commitsStream.emit.bind(commitsStream), 'error', err)
diff --git a/node_modules/conventional-changelog-core/lib/merge-config.js b/node_modules/conventional-changelog-core/lib/merge-config.js
index 8428bf4..72699b8 100644
--- a/node_modules/conventional-changelog-core/lib/merge-config.js
+++ b/node_modules/conventional-changelog-core/lib/merge-config.js
@@ -21,7 +21,7 @@ const rhosts = /github|bitbucket|gitlab/i

function semverTagsPromise (options) {
return Q.Promise(function (resolve, reject) {
- gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix, skipUnstable: options.skipUnstable }, function (err, result) {
+ gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix, skipUnstable: options.skipUnstable, cwd: options.pkg.path }, function (err, result) {
if (err) {
reject(err)
} else {
23 changes: 23 additions & 0 deletions patches/conventional-recommended-bump+5.0.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/node_modules/conventional-recommended-bump/index.js b/node_modules/conventional-recommended-bump/index.js
index 51c8a8a..c4cdc77 100644
--- a/node_modules/conventional-recommended-bump/index.js
+++ b/node_modules/conventional-recommended-bump/index.js
@@ -69,7 +69,7 @@ function conventionalRecommendedBump (optionsArgument, parserOptsArgument, cbArg
format: `%B%n-hash-%n%H`,
from: tags[0] || ``,
path: options.path
- })
+ }, { cwd: options.path })
.pipe(conventionalCommitsParser(parserOpts))
.pipe(concat(data => {
const commits = options.ignoreReverted ? conventionalCommitsFilter(data) : data
@@ -92,7 +92,8 @@ function conventionalRecommendedBump (optionsArgument, parserOptsArgument, cbArg
{
lernaTags: !!options.lernaPackage,
package: options.lernaPackage,
- tagPrefix: options.tagPrefix
+ tagPrefix: options.tagPrefix,
+ cwd: options.path
})
}).catch(err => cb(err))
}
Loading