@changesets/cli
Advanced tools
Comparing version 2.9.2 to 2.10.0
# @changesets/cli | ||
## 2.10.0 | ||
### Minor Changes | ||
- [`dca4a91`](https://github.com/atlassian/changesets/commit/dca4a91506dfca46915f7d4e833205ad3a685aa0) [#357](https://github.com/atlassian/changesets/pull/357) Thanks [@zkochan](https://github.com/zkochan)! - Open an editor when no message is given when creating a changeset | ||
* [`a57d163`](https://github.com/atlassian/changesets/commit/a57d16355ad7d67b18b768c8f79224d80afa507c) [#428](https://github.com/atlassian/changesets/pull/428) Thanks [@dotansimha](https://github.com/dotansimha)! - Added support for publishing from a subdirectory of packages, using `publishConfig.directory` field | ||
### Patch Changes | ||
- [`868eb1e`](https://github.com/atlassian/changesets/commit/868eb1e68ee91aabefa04a9abf13a7fc22eef019) [#434](https://github.com/atlassian/changesets/pull/434) Thanks [@mitchellhamilton](https://github.com/mitchellhamilton)! - Add `--no-git-checks` to `pnpm publish` in `changeset publish` to resolve issues with publishing on CI | ||
- Updated dependencies [[`1dd3117`](https://github.com/atlassian/changesets/commit/1dd311708c65321e1a1c99d36129190f940435ed), [`a57d163`](https://github.com/atlassian/changesets/commit/a57d16355ad7d67b18b768c8f79224d80afa507c)]: | ||
- @changesets/git@1.0.6 | ||
- @changesets/types@3.1.1 | ||
## 2.9.2 | ||
@@ -4,0 +20,0 @@ |
@@ -10,3 +10,4 @@ 'use strict'; | ||
var fs = _interopDefault(require('fs-extra')); | ||
var path = _interopDefault(require('path')); | ||
var path = require('path'); | ||
var path__default = _interopDefault(path); | ||
var getPackages = require('@manypkg/get-packages'); | ||
@@ -18,2 +19,3 @@ var getDependentsGraph = require('@changesets/get-dependents-graph'); | ||
var enquirer = require('enquirer'); | ||
var externalEditor = require('external-editor'); | ||
var git = require('@changesets/git'); | ||
@@ -35,9 +37,9 @@ var writeChangeset = _interopDefault(require('@changesets/write')); | ||
const pkgPath = path.dirname(require.resolve("@changesets/cli/package.json")); | ||
const pkgPath = path__default.dirname(require.resolve("@changesets/cli/package.json")); | ||
async function init(cwd) { | ||
const changesetBase = path.resolve(cwd, ".changeset"); | ||
const changesetBase = path__default.resolve(cwd, ".changeset"); | ||
if (fs.existsSync(changesetBase)) { | ||
if (!fs.existsSync(path.join(changesetBase, "config.json"))) { | ||
if (fs.existsSync(path.join(changesetBase, "config.js"))) { | ||
if (!fs.existsSync(path__default.join(changesetBase, "config.json"))) { | ||
if (fs.existsSync(path__default.join(changesetBase, "config.js"))) { | ||
logger.error("It looks like you're using the version 1 `.changeset/config.js` file"); | ||
@@ -52,3 +54,3 @@ logger.error("The format of the config object has significantly changed in v2 as well"); | ||
await fs.writeFile(path.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)); | ||
await fs.writeFile(path__default.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)); | ||
} else { | ||
@@ -58,4 +60,4 @@ logger.warn("It looks like you already have changesets initialized. You should be able to run changeset commands no problems."); | ||
} else { | ||
await fs.copy(path.resolve(pkgPath, "./default-files"), changesetBase); | ||
await fs.writeFile(path.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)); | ||
await fs.copy(path__default.resolve(pkgPath, "./default-files"), changesetBase); | ||
await fs.writeFile(path__default.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)); | ||
logger.log(chalk`Thanks for choosing {green changesets} to help manage your versioning and publishing\n`); | ||
@@ -70,2 +72,4 @@ logger.log("You should be set up to start using changesets now!\n"); | ||
// @ts-ignore it's not worth writing a TS declaration file in this repo for a tiny module we use once like this | ||
// so we can make type assertions using them because `enquirer` types do no support `prefix` right now | ||
/* Notes on using inquirer: | ||
@@ -76,3 +80,2 @@ * Each question needs a key, as inquirer is assembling an object behind-the-scenes. | ||
*/ | ||
const serialId = function () { | ||
@@ -96,3 +99,2 @@ let id = 0; | ||
message, | ||
// @ts-ignore | ||
prefix: logger.prefix, | ||
@@ -115,3 +117,2 @@ multiple: true, | ||
name, | ||
// @ts-ignore | ||
prefix: logger.prefix, | ||
@@ -124,2 +125,9 @@ onCancel: cancelFlow | ||
function askQuestionWithEditor(message) { | ||
const response = externalEditor.edit(message, { | ||
postfix: ".md" | ||
}); | ||
return response.replace(/^#.*\n?/gm, "").replace(/\n+$/g, "").trim(); | ||
} | ||
async function askConfirm(message) { | ||
@@ -130,3 +138,2 @@ const name = `Confirm-${serialId()}`; | ||
name, | ||
// @ts-ignore | ||
prefix: logger.prefix, | ||
@@ -147,3 +154,2 @@ type: "confirm", | ||
name, | ||
// @ts-ignore | ||
prefix: logger.prefix, | ||
@@ -329,8 +335,17 @@ type: "select", | ||
logger.log("Please enter a summary for this change (this will be in the changelogs)"); | ||
logger.log("Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor"); | ||
let summary = await askQuestion("Summary"); | ||
if (summary.length === 0) summary = askQuestionWithEditor(""); | ||
while (summary.length === 0) { | ||
logger.error("A summary is required for the changelog! 😪"); | ||
summary = await askQuestion("Summary"); | ||
try { | ||
while (summary.length === 0) { | ||
summary = await askQuestionWithEditor("\n\n# A summary is required for the changelog! 😪"); | ||
} | ||
} catch (err) { | ||
logger.log("An error happened using external editor. Please type your summary here:"); | ||
summary = await askQuestion(""); | ||
while (summary.length === 0) { | ||
summary = await askQuestion("\n\n# A summary is required for the changelog! 😪"); | ||
} | ||
} | ||
@@ -373,3 +388,3 @@ | ||
const packages = await getPackages.getPackages(cwd); | ||
const changesetBase = path.resolve(cwd, ".changeset"); | ||
const changesetBase = path__default.resolve(cwd, ".changeset"); | ||
let newChangeset, confirmChangeset; | ||
@@ -398,3 +413,3 @@ | ||
if (config.commit) { | ||
await git.add(path.resolve(changesetBase, `${changesetID}.md`), cwd); | ||
await git.add(path__default.resolve(changesetBase, `${changesetID}.md`), cwd); | ||
await git.commit(`docs(changeset): ${newChangeset.summary}`, cwd); | ||
@@ -417,3 +432,3 @@ logger.log(chalk.green(`${empty ? "Empty " : ""}Changeset added and committed`)); | ||
logger.info(chalk.blue(path.resolve(changesetBase, `${changesetID}.md`))); | ||
logger.info(chalk.blue(path__default.resolve(changesetBase, `${changesetID}.md`))); | ||
} | ||
@@ -428,3 +443,3 @@ } | ||
return Promise.all(dirContents.map(async contentPath => { | ||
const singleChangesetPath = path.resolve(folderPath, contentPath); | ||
const singleChangesetPath = path__default.resolve(folderPath, contentPath); | ||
@@ -451,8 +466,5 @@ try { | ||
async function version(cwd, options, config) { | ||
let [_changesets, _preState] = await Promise.all([readChangesets(cwd), pre$1.readPreState(cwd), removeEmptyFolders(path.resolve(cwd, ".changeset"))]); // temporarily needed because of TS 3.7 regression - https://github.com/microsoft/TypeScript/issues/33752 | ||
const [changesets, preState] = await Promise.all([readChangesets(cwd), pre$1.readPreState(cwd), removeEmptyFolders(path__default.resolve(cwd, ".changeset"))]); | ||
const changesets = _changesets; | ||
const preState = _preState; | ||
if (preState !== undefined && preState.mode === "pre") { | ||
if ((preState === null || preState === void 0 ? void 0 : preState.mode) === "pre") { | ||
logger.warn(importantSeparator); | ||
@@ -480,3 +492,3 @@ | ||
let releasePlan = assembleReleasePlan(changesets, packages, config, preState, options.snapshot); | ||
await applyReleasePlan(releasePlan, packages, _objectSpread({}, config, { | ||
await applyReleasePlan(releasePlan, packages, _objectSpread(_objectSpread({}, config), {}, { | ||
commit: false | ||
@@ -516,4 +528,22 @@ }), options.snapshot); | ||
const pm = await preferredPM(cwd); | ||
if (!pm) return "npm"; | ||
return pm.name === "pnpm" ? "pnpm" : "npm"; | ||
if (!pm || pm.name !== "pnpm") return { | ||
name: "npm" | ||
}; | ||
try { | ||
let result = await spawn("pnpm", ["--version"], { | ||
cwd | ||
}); | ||
let version = result.stdout.toString().trim(); | ||
let parsed = semver.parse(version); | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: (parsed === null || parsed === void 0 ? void 0 : parsed.major) === undefined ? false : parsed.major >= 5 | ||
}; | ||
} catch (e) { | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: false | ||
}; | ||
} | ||
} | ||
@@ -606,2 +636,6 @@ | ||
publishFlags.push("--otp", otpCode); | ||
} | ||
if (publishTool.name === "pnpm" && publishTool.shouldAddNoGitChecks) { | ||
publishFlags.push("--no-git-checks"); | ||
} // Due to a super annoying issue in yarn, we have to manually override this env variable | ||
@@ -616,3 +650,3 @@ // See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633 | ||
stdout | ||
} = await spawn(publishTool, ["publish", "--json", ...publishFlags], { | ||
} = await spawn(publishTool.name, ["publish", "--json", ...publishFlags], { | ||
cwd: opts.cwd, | ||
@@ -708,3 +742,3 @@ env: Object.assign({}, process.env, envOverride) | ||
logger.info(`Publishing ${chalk.cyan(`"${name}"`)} at ${chalk.green(`"${version}"`)}`); | ||
const publishDir = pkg.dir; | ||
const publishDir = publishConfig && publishConfig.directory ? path.join(pkg.dir, publishConfig.directory) : pkg.dir; | ||
const publishConfirmation = await publish(name, { | ||
@@ -875,3 +909,3 @@ cwd: publishDir, | ||
if (output) { | ||
await fs.writeFile(path.join(cwd, output), JSON.stringify(releasePlan, undefined, 2)); | ||
await fs.writeFile(path__default.join(cwd, output), JSON.stringify(releasePlan, undefined, 2)); | ||
return; | ||
@@ -972,3 +1006,3 @@ } | ||
if (!fs.existsSync(path.resolve(cwd, ".changeset"))) { | ||
if (!fs.existsSync(path__default.resolve(cwd, ".changeset"))) { | ||
logger.error("There is no .changeset folder. "); | ||
@@ -986,3 +1020,3 @@ logger.error("If this is the first time `changesets` have been used in this project, run `yarn changeset init` to get set up."); | ||
} catch (e) { | ||
let oldConfigExists = await fs.pathExists(path.resolve(cwd, ".changeset/config.js")); | ||
let oldConfigExists = await fs.pathExists(path__default.resolve(cwd, ".changeset/config.js")); | ||
@@ -989,0 +1023,0 @@ if (oldConfigExists) { |
@@ -7,9 +7,9 @@ "use strict"; | ||
var meow = _interopDefault(require("meow")), errors = require("@changesets/errors"), logger = require("@changesets/logger"), util = require("util"), fs = _interopDefault(require("fs-extra")), path = _interopDefault(require("path")), getPackages = require("@manypkg/get-packages"), getDependentsGraph = require("@changesets/get-dependents-graph"), config = require("@changesets/config"), chalk = _interopDefault(require("chalk")), termSize = _interopDefault(require("term-size")), enquirer = require("enquirer"), git = require("@changesets/git"), writeChangeset = _interopDefault(require("@changesets/write")), semver = _interopDefault(require("semver")), boxen = _interopDefault(require("boxen")), outdent = _interopDefault(require("outdent")), applyReleasePlan = _interopDefault(require("@changesets/apply-release-plan")), readChangesets = _interopDefault(require("@changesets/read")), assembleReleasePlan = _interopDefault(require("@changesets/assemble-release-plan")), pre$1 = require("@changesets/pre"), pLimit = _interopDefault(require("p-limit")), preferredPM = _interopDefault(require("preferred-pm")), spawn = _interopDefault(require("spawndamnit")), isCI$1 = _interopDefault(require("is-ci")), table = _interopDefault(require("tty-table")), getReleasePlan = _interopDefault(require("@changesets/get-release-plan")); | ||
var meow = _interopDefault(require("meow")), errors = require("@changesets/errors"), logger = require("@changesets/logger"), util = require("util"), fs = _interopDefault(require("fs-extra")), path = require("path"), path__default = _interopDefault(path), getPackages = require("@manypkg/get-packages"), getDependentsGraph = require("@changesets/get-dependents-graph"), config = require("@changesets/config"), chalk = _interopDefault(require("chalk")), termSize = _interopDefault(require("term-size")), enquirer = require("enquirer"), externalEditor = require("external-editor"), git = require("@changesets/git"), writeChangeset = _interopDefault(require("@changesets/write")), semver = _interopDefault(require("semver")), boxen = _interopDefault(require("boxen")), outdent = _interopDefault(require("outdent")), applyReleasePlan = _interopDefault(require("@changesets/apply-release-plan")), readChangesets = _interopDefault(require("@changesets/read")), assembleReleasePlan = _interopDefault(require("@changesets/assemble-release-plan")), pre$1 = require("@changesets/pre"), pLimit = _interopDefault(require("p-limit")), preferredPM = _interopDefault(require("preferred-pm")), spawn = _interopDefault(require("spawndamnit")), isCI$1 = _interopDefault(require("is-ci")), table = _interopDefault(require("tty-table")), getReleasePlan = _interopDefault(require("@changesets/get-release-plan")); | ||
const pkgPath = path.dirname(require.resolve("@changesets/cli/package.json")); | ||
const pkgPath = path__default.dirname(require.resolve("@changesets/cli/package.json")); | ||
async function init(cwd) { | ||
const changesetBase = path.resolve(cwd, ".changeset"); | ||
fs.existsSync(changesetBase) ? fs.existsSync(path.join(changesetBase, "config.json")) ? logger.warn("It looks like you already have changesets initialized. You should be able to run changeset commands no problems.") : (fs.existsSync(path.join(changesetBase, "config.js")) ? (logger.error("It looks like you're using the version 1 `.changeset/config.js` file"), | ||
const changesetBase = path__default.resolve(cwd, ".changeset"); | ||
fs.existsSync(changesetBase) ? fs.existsSync(path__default.join(changesetBase, "config.json")) ? logger.warn("It looks like you already have changesets initialized. You should be able to run changeset commands no problems.") : (fs.existsSync(path__default.join(changesetBase, "config.js")) ? (logger.error("It looks like you're using the version 1 `.changeset/config.js` file"), | ||
logger.error("The format of the config object has significantly changed in v2 as well"), | ||
@@ -19,4 +19,4 @@ logger.error(" - we thoroughly recommend looking at the changelog for this package for what has changed"), | ||
logger.info("The default config file will be written at `.changeset/config.json`")), | ||
await fs.writeFile(path.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2))) : (await fs.copy(path.resolve(pkgPath, "./default-files"), changesetBase), | ||
await fs.writeFile(path.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)), | ||
await fs.writeFile(path__default.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2))) : (await fs.copy(path__default.resolve(pkgPath, "./default-files"), changesetBase), | ||
await fs.writeFile(path__default.resolve(changesetBase, "config.json"), JSON.stringify(config.defaultWrittenConfig, null, 2)), | ||
logger.log(chalk`Thanks for choosing {green changesets} to help manage your versioning and publishing\n`), | ||
@@ -67,2 +67,8 @@ logger.log("You should be set up to start using changesets now!\n"), logger.info("We have added a `.changeset` folder, and a couple of files to help you out:"), | ||
function askQuestionWithEditor(message) { | ||
return externalEditor.edit(message, { | ||
postfix: ".md" | ||
}).replace(/^#.*\n?/gm, "").replace(/\n+$/g, "").trim(); | ||
} | ||
async function askConfirm(message) { | ||
@@ -185,6 +191,11 @@ const name = `Confirm-${serialId()}`; | ||
} | ||
logger.log("Please enter a summary for this change (this will be in the changelogs)"); | ||
logger.log("Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor"); | ||
let summary = await askQuestion("Summary"); | ||
for (;0 === summary.length; ) logger.error("A summary is required for the changelog! 😪"), | ||
summary = await askQuestion("Summary"); | ||
0 === summary.length && (summary = askQuestionWithEditor("")); | ||
try { | ||
for (;0 === summary.length; ) summary = await askQuestionWithEditor("\n\n# A summary is required for the changelog! 😪"); | ||
} catch (err) { | ||
for (logger.log("An error happened using external editor. Please type your summary here:"), | ||
summary = await askQuestion(""); 0 === summary.length; ) summary = await askQuestion("\n\n# A summary is required for the changelog! 😪"); | ||
} | ||
return { | ||
@@ -217,3 +228,3 @@ summary: summary, | ||
async function add(cwd, {empty: empty}, config) { | ||
const packages = await getPackages.getPackages(cwd), changesetBase = path.resolve(cwd, ".changeset"); | ||
const packages = await getPackages.getPackages(cwd), changesetBase = path__default.resolve(cwd, ".changeset"); | ||
let newChangeset, confirmChangeset; | ||
@@ -233,3 +244,3 @@ if (empty) newChangeset = { | ||
const changesetID = await writeChangeset(newChangeset, cwd); | ||
config.commit ? (await git.add(path.resolve(changesetBase, `${changesetID}.md`), cwd), | ||
config.commit ? (await git.add(path__default.resolve(changesetBase, `${changesetID}.md`), cwd), | ||
await git.commit(`docs(changeset): ${newChangeset.summary}`, cwd), logger.log(chalk.green(`${empty ? "Empty " : ""}Changeset added and committed`))) : logger.log(chalk.green(`${empty ? "Empty " : ""}Changeset added! - you can now commit it\n`)), | ||
@@ -239,3 +250,3 @@ [ ...newChangeset.releases ].find(c => "major" === c.type) ? (logger.warn("This Changeset includes a major change and we STRONGLY recommend adding more information to the changeset:"), | ||
logger.warn("HOW a consumer should update their code")) : logger.log(chalk.green("If you want to modify or expand on the changeset summary, you can find it here")), | ||
logger.info(chalk.blue(path.resolve(changesetBase, `${changesetID}.md`))); | ||
logger.info(chalk.blue(path__default.resolve(changesetBase, `${changesetID}.md`))); | ||
} | ||
@@ -247,3 +258,3 @@ } | ||
return Promise.all(dirContents.map(async contentPath => { | ||
const singleChangesetPath = path.resolve(folderPath, contentPath); | ||
const singleChangesetPath = path__default.resolve(folderPath, contentPath); | ||
try { | ||
@@ -292,5 +303,4 @@ (await fs.readdir(singleChangesetPath)).length < 1 && await fs.rmdir(singleChangesetPath); | ||
async function version(cwd, options, config) { | ||
let [_changesets, _preState] = await Promise.all([ readChangesets(cwd), pre$1.readPreState(cwd), removeEmptyFolders(path.resolve(cwd, ".changeset")) ]); | ||
const changesets = _changesets, preState = _preState; | ||
if (void 0 !== preState && "pre" === preState.mode) { | ||
const [changesets, preState] = await Promise.all([ readChangesets(cwd), pre$1.readPreState(cwd), removeEmptyFolders(path__default.resolve(cwd, ".changeset")) ]); | ||
if ("pre" === (null == preState ? void 0 : preState.mode)) { | ||
if (logger.warn(importantSeparator), void 0 !== options.snapshot) throw logger.error("Snapshot release is not allowed in pre mode"), | ||
@@ -305,3 +315,3 @@ logger.log("To resolve this exit the pre mode by running `changeset pre exit`"), | ||
let packages = await getPackages.getPackages(cwd), releasePlan = assembleReleasePlan(changesets, packages, config, preState, options.snapshot); | ||
await applyReleasePlan(releasePlan, packages, _objectSpread({}, config, { | ||
await applyReleasePlan(releasePlan, packages, _objectSpread(_objectSpread({}, config), {}, { | ||
commit: !1 | ||
@@ -330,3 +340,19 @@ }), options.snapshot), void 0 !== options.snapshot && config.commit ? logger.log("All files have been updated and committed. You're ready to publish!") : logger.log("All files have been updated. Review them and commit at your leisure"); | ||
const pm = await preferredPM(cwd); | ||
return pm && "pnpm" === pm.name ? "pnpm" : "npm"; | ||
if (!pm || "pnpm" !== pm.name) return { | ||
name: "npm" | ||
}; | ||
try { | ||
let version = (await spawn("pnpm", [ "--version" ], { | ||
cwd: cwd | ||
})).stdout.toString().trim(), parsed = semver.parse(version); | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: void 0 !== (null == parsed ? void 0 : parsed.major) && parsed.major >= 5 | ||
}; | ||
} catch (e) { | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: !1 | ||
}; | ||
} | ||
} | ||
@@ -385,6 +411,7 @@ | ||
} | ||
"pnpm" === publishTool.name && publishTool.shouldAddNoGitChecks && publishFlags.push("--no-git-checks"); | ||
const envOverride = { | ||
npm_config_registry: getCorrectRegistry() | ||
}; | ||
let {stdout: stdout} = await spawn(publishTool, [ "publish", "--json", ...publishFlags ], { | ||
let {stdout: stdout} = await spawn(publishTool.name, [ "publish", "--json", ...publishFlags ], { | ||
cwd: opts.cwd, | ||
@@ -432,3 +459,3 @@ env: Object.assign({}, process.env, envOverride) | ||
logger.info(`Publishing ${chalk.cyan(`"${name}"`)} at ${chalk.green(`"${version}"`)}`); | ||
const publishDir = pkg.dir; | ||
const publishDir = publishConfig && publishConfig.directory ? path.join(pkg.dir, publishConfig.directory) : pkg.dir; | ||
return { | ||
@@ -510,3 +537,3 @@ name: name, | ||
if (changesets.length < 1 && (logger.error("No changesets present"), process.exit(1)), | ||
output) return void await fs.writeFile(path.join(cwd, output), JSON.stringify(releasePlan, void 0, 2)); | ||
output) return void await fs.writeFile(path__default.join(cwd, output), JSON.stringify(releasePlan, void 0, 2)); | ||
const print = verbose ? verbosePrint : SimplePrint; | ||
@@ -568,3 +595,3 @@ return print("patch", releases), logger.log("---"), print("minor", releases), logger.log("---"), | ||
if ("init" === input[0]) return void await init(cwd); | ||
if (!fs.existsSync(path.resolve(cwd, ".changeset"))) throw logger.error("There is no .changeset folder. "), | ||
if (!fs.existsSync(path__default.resolve(cwd, ".changeset"))) throw logger.error("There is no .changeset folder. "), | ||
logger.error("If this is the first time `changesets` have been used in this project, run `yarn changeset init` to get set up."), | ||
@@ -578,3 +605,3 @@ logger.error("If you expected there to be changesets, you should check git history for when the folder was removed to ensure you do not lose any configuration."), | ||
} catch (e) { | ||
throw await fs.pathExists(path.resolve(cwd, ".changeset/config.js")) ? (logger.error("It looks like you're using the version 1 `.changeset/config.js` file"), | ||
throw await fs.pathExists(path__default.resolve(cwd, ".changeset/config.js")) ? (logger.error("It looks like you're using the version 1 `.changeset/config.js` file"), | ||
logger.error("You'll need to convert it to a `.changeset/config.json` file"), logger.error("The format of the config object has significantly changed in v2 as well"), | ||
@@ -581,0 +608,0 @@ logger.error(" - we thoroughly recommend looking at the changelog for this package for what has changed"), |
@@ -6,3 +6,3 @@ import meow from 'meow'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import path, { join } from 'path'; | ||
import { getPackages } from '@manypkg/get-packages'; | ||
@@ -14,2 +14,3 @@ import { getDependentsGraph } from '@changesets/get-dependents-graph'; | ||
import { prompt } from 'enquirer'; | ||
import { edit } from 'external-editor'; | ||
import { getChangedPackagesSinceRef, add as add$1, commit, tag } from '@changesets/git'; | ||
@@ -63,2 +64,4 @@ import writeChangeset from '@changesets/write'; | ||
// @ts-ignore it's not worth writing a TS declaration file in this repo for a tiny module we use once like this | ||
// so we can make type assertions using them because `enquirer` types do no support `prefix` right now | ||
/* Notes on using inquirer: | ||
@@ -69,3 +72,2 @@ * Each question needs a key, as inquirer is assembling an object behind-the-scenes. | ||
*/ | ||
const serialId = function () { | ||
@@ -89,3 +91,2 @@ let id = 0; | ||
message, | ||
// @ts-ignore | ||
prefix, | ||
@@ -108,3 +109,2 @@ multiple: true, | ||
name, | ||
// @ts-ignore | ||
prefix, | ||
@@ -117,2 +117,9 @@ onCancel: cancelFlow | ||
function askQuestionWithEditor(message) { | ||
const response = edit(message, { | ||
postfix: ".md" | ||
}); | ||
return response.replace(/^#.*\n?/gm, "").replace(/\n+$/g, "").trim(); | ||
} | ||
async function askConfirm(message) { | ||
@@ -123,3 +130,2 @@ const name = `Confirm-${serialId()}`; | ||
name, | ||
// @ts-ignore | ||
prefix, | ||
@@ -140,3 +146,2 @@ type: "confirm", | ||
name, | ||
// @ts-ignore | ||
prefix, | ||
@@ -322,8 +327,17 @@ type: "select", | ||
log("Please enter a summary for this change (this will be in the changelogs)"); | ||
log("Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor"); | ||
let summary = await askQuestion("Summary"); | ||
if (summary.length === 0) summary = askQuestionWithEditor(""); | ||
while (summary.length === 0) { | ||
error("A summary is required for the changelog! 😪"); | ||
summary = await askQuestion("Summary"); | ||
try { | ||
while (summary.length === 0) { | ||
summary = await askQuestionWithEditor("\n\n# A summary is required for the changelog! 😪"); | ||
} | ||
} catch (err) { | ||
log("An error happened using external editor. Please type your summary here:"); | ||
summary = await askQuestion(""); | ||
while (summary.length === 0) { | ||
summary = await askQuestion("\n\n# A summary is required for the changelog! 😪"); | ||
} | ||
} | ||
@@ -440,8 +454,5 @@ | ||
async function version(cwd, options, config) { | ||
let [_changesets, _preState] = await Promise.all([readChangesets(cwd), readPreState(cwd), removeEmptyFolders(path.resolve(cwd, ".changeset"))]); // temporarily needed because of TS 3.7 regression - https://github.com/microsoft/TypeScript/issues/33752 | ||
const [changesets, preState] = await Promise.all([readChangesets(cwd), readPreState(cwd), removeEmptyFolders(path.resolve(cwd, ".changeset"))]); | ||
const changesets = _changesets; | ||
const preState = _preState; | ||
if (preState !== undefined && preState.mode === "pre") { | ||
if ((preState === null || preState === void 0 ? void 0 : preState.mode) === "pre") { | ||
warn(importantSeparator); | ||
@@ -469,3 +480,3 @@ | ||
let releasePlan = assembleReleasePlan(changesets, packages, config, preState, options.snapshot); | ||
await applyReleasePlan(releasePlan, packages, _objectSpread({}, config, { | ||
await applyReleasePlan(releasePlan, packages, _objectSpread(_objectSpread({}, config), {}, { | ||
commit: false | ||
@@ -505,4 +516,22 @@ }), options.snapshot); | ||
const pm = await preferredPM(cwd); | ||
if (!pm) return "npm"; | ||
return pm.name === "pnpm" ? "pnpm" : "npm"; | ||
if (!pm || pm.name !== "pnpm") return { | ||
name: "npm" | ||
}; | ||
try { | ||
let result = await spawn("pnpm", ["--version"], { | ||
cwd | ||
}); | ||
let version = result.stdout.toString().trim(); | ||
let parsed = semver.parse(version); | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: (parsed === null || parsed === void 0 ? void 0 : parsed.major) === undefined ? false : parsed.major >= 5 | ||
}; | ||
} catch (e) { | ||
return { | ||
name: "pnpm", | ||
shouldAddNoGitChecks: false | ||
}; | ||
} | ||
} | ||
@@ -595,2 +624,6 @@ | ||
publishFlags.push("--otp", otpCode); | ||
} | ||
if (publishTool.name === "pnpm" && publishTool.shouldAddNoGitChecks) { | ||
publishFlags.push("--no-git-checks"); | ||
} // Due to a super annoying issue in yarn, we have to manually override this env variable | ||
@@ -605,3 +638,3 @@ // See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633 | ||
stdout | ||
} = await spawn(publishTool, ["publish", "--json", ...publishFlags], { | ||
} = await spawn(publishTool.name, ["publish", "--json", ...publishFlags], { | ||
cwd: opts.cwd, | ||
@@ -697,3 +730,3 @@ env: Object.assign({}, process.env, envOverride) | ||
info(`Publishing ${chalk.cyan(`"${name}"`)} at ${chalk.green(`"${version}"`)}`); | ||
const publishDir = pkg.dir; | ||
const publishDir = publishConfig && publishConfig.directory ? join(pkg.dir, publishConfig.directory) : pkg.dir; | ||
const publishConfirmation = await publish(name, { | ||
@@ -700,0 +733,0 @@ cwd: publishDir, |
declare function askCheckboxPlus(message: string, choices: Array<any>, format?: (arg: any) => any): Promise<Array<string>>; | ||
declare function askQuestion(message: string): Promise<string>; | ||
declare function askQuestionWithEditor(message: string): string; | ||
declare function askConfirm(message: string): Promise<boolean>; | ||
declare function askList<Choice extends string>(message: string, choices: readonly Choice[]): Promise<Choice>; | ||
export { askCheckboxPlus, askQuestion, askConfirm, askList }; | ||
declare function askList<Choice extends string>(message: string, choices: Choice[]): Promise<Choice>; | ||
export { askCheckboxPlus, askQuestion, askQuestionWithEditor, askConfirm, askList }; |
{ | ||
"name": "@changesets/cli", | ||
"version": "2.9.2", | ||
"version": "2.10.0", | ||
"description": "Organise your package versioning and publishing to make both contributors and maintainers happy", | ||
@@ -26,3 +26,3 @@ "bin": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.4", | ||
"@babel/runtime": "^7.10.4", | ||
"@changesets/apply-release-plan": "^4.0.0", | ||
@@ -34,7 +34,7 @@ "@changesets/assemble-release-plan": "^3.0.0", | ||
"@changesets/get-release-plan": "^2.0.0", | ||
"@changesets/git": "^1.0.5", | ||
"@changesets/git": "^1.0.6", | ||
"@changesets/logger": "^0.0.5", | ||
"@changesets/pre": "^1.0.4", | ||
"@changesets/read": "^0.4.6", | ||
"@changesets/types": "^3.1.0", | ||
"@changesets/types": "^3.1.1", | ||
"@changesets/write": "^0.1.3", | ||
@@ -46,2 +46,3 @@ "@manypkg/get-packages": "^1.0.1", | ||
"enquirer": "^2.3.0", | ||
"external-editor": "^3.1.0", | ||
"fs-extra": "^7.0.1", | ||
@@ -48,0 +49,0 @@ "human-id": "^1.0.2", |
@@ -1,2 +0,2 @@ | ||
## @changeset/cli 🦋 | ||
## @changesets/cli 🦋 | ||
@@ -3,0 +3,0 @@ [![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/@changesets/cli) |
191391
3011
30
+ Addedexternal-editor@^3.1.0
+ Addedchardet@0.7.0(transitive)
+ Addedexternal-editor@3.1.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedtmp@0.0.33(transitive)
Updated@babel/runtime@^7.10.4
Updated@changesets/git@^1.0.6
Updated@changesets/types@^3.1.1