Skip to content

Commit

Permalink
feat(deps): bump prettier from 1.19.1 to 2.0.4 (#593)
Browse files Browse the repository at this point in the history
See the [Prettier v2 release note](https://prettier.io/blog/2020/03/21/2.0.0.html).

BREAKING CHANGE: Prettier v2; change defaults and use `.` instead of `**.{ext1,ext2}`.
  • Loading branch information
ybiquitous authored Apr 13, 2020
1 parent 8e9810c commit 375a6ef
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 49 deletions.
12 changes: 6 additions & 6 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const packagePath = (...pathElements) => path.join(...[__dirname, "..", ...pathE
const initCommand = (baseDir, logger) => {
const currentPath = (...pathElems) => path.join(...[baseDir, ...pathElems]);

const readFile = fileName => read(currentPath(fileName), "utf8");
const readFile = (fileName) => read(currentPath(fileName), "utf8");

const copyFile = async (src, dest) => {
await copy(src, dest);
Expand Down Expand Up @@ -43,14 +43,14 @@ const initCommand = (baseDir, logger) => {
scripts["test:watch"] = `${scripts.test} --watch`;
scripts["test:coverage"] = 'echo "unsupported." && exit 1';
Object.keys(originalPackage.scripts)
.filter(key => !(key === "test" || key.startsWith("test:")))
.forEach(key => {
.filter((key) => !(key === "test" || key.startsWith("test:")))
.forEach((key) => {
scripts[key] = originalPackage.scripts[key];
});

// update other keys
const keys = ["husky", "lint-staged", "standard-version", "prettier", "remarkConfig"];
keys.forEach(key => {
const keys = ["husky", "lint-staged", "standard-version", "remarkConfig"];
keys.forEach((key) => {
if (!(key in packageInfo)) {
packageInfo[key] = {};
}
Expand All @@ -72,7 +72,7 @@ const initCommand = (baseDir, logger) => {
};
};

const defaultLogger = msg => process.stdout.write(`${msg}${EOL}`);
const defaultLogger = (msg) => process.stdout.write(`${msg}${EOL}`);

module.exports = async function init({ cwd = process.cwd(), logger = defaultLogger } = {}) {
const cmd = initCommand(cwd, logger);
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"husky": "^4.2.5",
"lint-staged": "^10.1.3",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier": "^2.0.4",
"remark-cli": "^8.0.0",
"remark-lint-no-heading-punctuation": "^2.0.0",
"remark-preset-lint-recommended": "^4.0.0",
Expand All @@ -53,7 +53,7 @@
"lint:md": "remark . --frail",
"lint:md:fix": "remark . --output",
"lint": "npm-run-all --print-label --parallel lint:*",
"prettier": "prettier --ignore-path .gitignore \"**/*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}\"",
"prettier": "prettier --ignore-path .gitignore .",
"prettier:check": "npm run prettier -- --check",
"prettier:write": "npm run prettier -- --write",
"format": "npm-run-all --print-label --parallel lint:*:fix prettier:write",
Expand All @@ -69,12 +69,9 @@
},
"lint-staged": {
"*.{js,jsx,mjs,ts,tsx}": "eslint --fix --no-ignore",
"*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}": "prettier --write",
"*": "prettier --write",
"!(CHANGELOG).md": "remark --frail"
},
"prettier": {
"trailingComma": "es5"
},
"standard-version": {
"sign": true,
"scripts": {
Expand Down
7 changes: 2 additions & 5 deletions test/fixtures/package-empty_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint:md": "remark . --frail",
"lint:md:fix": "remark . --output",
"lint": "npm-run-all --print-label --parallel lint:*",
"prettier": "prettier --ignore-path .gitignore \"**/*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}\"",
"prettier": "prettier --ignore-path .gitignore .",
"prettier:check": "npm run prettier -- --check",
"prettier:write": "npm run prettier -- --write",
"format": "npm-run-all --print-label --parallel lint:*:fix prettier:write",
Expand All @@ -24,7 +24,7 @@
},
"lint-staged": {
"*.{js,jsx,mjs,ts,tsx}": "eslint --fix --no-ignore",
"*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}": "prettier --write",
"*": "prettier --write",
"!(CHANGELOG).md": "remark --frail"
},
"standard-version": {
Expand All @@ -33,9 +33,6 @@
"postchangelog": "prettier --write CHANGELOG.md"
}
},
"prettier": {
"trailingComma": "es5"
},
"remarkConfig": {
"plugins": [
"preset-lint-recommended",
Expand Down
7 changes: 2 additions & 5 deletions test/fixtures/package-normal_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint:md": "remark . --frail",
"lint:md:fix": "remark . --output",
"lint": "npm-run-all --print-label --parallel lint:*",
"prettier": "prettier --ignore-path .gitignore \"**/*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}\"",
"prettier": "prettier --ignore-path .gitignore .",
"prettier:check": "npm run prettier -- --check",
"prettier:write": "npm run prettier -- --write",
"format": "npm-run-all --print-label --parallel lint:*:fix prettier:write",
Expand All @@ -25,7 +25,7 @@
"lint-staged": {
"*.css": "xyz",
"*.{js,jsx,mjs,ts,tsx}": "eslint --fix --no-ignore",
"*.{css,html,js,json,jsx,md,mdx,mjs,scss,ts,tsx,yaml,yml}": "prettier --write",
"*": "prettier --write",
"!(CHANGELOG).md": "remark --frail"
},
"standard-version": {
Expand All @@ -34,9 +34,6 @@
"postchangelog": "prettier --write CHANGELOG.md"
}
},
"prettier": {
"trailingComma": "es5"
},
"remarkConfig": {
"plugins": [
"preset-lint-recommended",
Expand Down
12 changes: 6 additions & 6 deletions test/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Options:
--version, -v Show version number [boolean]
`.trim();

test("help", t => {
[[], ["unknown"], ["unknown", "xyz"]].forEach(args => {
t.test(`with arguments [${args.join(", ")}]`, async t => {
const error = await exec(...args).catch(err => err);
test("help", (t) => {
[[], ["unknown"], ["unknown", "xyz"]].forEach((args) => {
t.test(`with arguments [${args.join(", ")}]`, async (t) => {
const error = await exec(...args).catch((err) => err);
const { code, stdout, stderr } = error;
t.ok(error instanceof Error);
t.is(code, 1);
Expand All @@ -26,8 +26,8 @@ test("help", t => {
t.end();
});
});
["--help", "-h"].forEach(option => {
t.test(`with "${option}" option`, async t => {
["--help", "-h"].forEach((option) => {
t.test(`with "${option}" option`, async (t) => {
const { stdout, stderr } = await exec(option);
t.ok(stdout.includes(HELP));
t.is(stderr, "");
Expand Down
26 changes: 13 additions & 13 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const pkg = require("../package.json");
const init = require("../lib/init");
const exec = require("./helpers/exec");

const readFile = file => fse.readFile(file, "utf8");
const readJSON = file => fse.readJSON(file, "utf8");
const readFile = (file) => fse.readFile(file, "utf8");
const readJSON = (file) => fse.readJSON(file, "utf8");

const sandbox = async (fn, t) => {
const workDir = path.join(os.tmpdir(), `${pkg.name}${Date.now()}`);
await fse.mkdirs(workDir);

const logMsgs = [];
const logger = msg => logMsgs.push(msg);
const logger = (msg) => logMsgs.push(msg);

try {
const cwd = process.cwd();
const fixturePath = name => path.join(cwd, "test", "fixtures", name);
const fixture = async name => {
const fixturePath = (name) => path.join(cwd, "test", "fixtures", name);
const fixture = async (name) => {
const src = fixturePath(name);
const dest = path.join(workDir, "package.json");
await fse.copy(src, dest);
Expand All @@ -29,10 +29,10 @@ const sandbox = async (fn, t) => {
return await fn(t, {
fixturePath,
fixture,
readFixture: name => readFile(fixturePath(name)),
readFixtureJSON: name => readJSON(fixturePath(name)),
readOrigFile: name => readFile(path.join(cwd, name)),
readWorkFile: name => readFile(path.join(workDir, name)),
readFixture: (name) => readFile(fixturePath(name)),
readFixtureJSON: (name) => readJSON(fixturePath(name)),
readOrigFile: (name) => readFile(path.join(cwd, name)),
readWorkFile: (name) => readFile(path.join(workDir, name)),
logMessage: () => logMsgs.join(""),
initArgs: { cwd: workDir, logger },
});
Expand All @@ -41,9 +41,9 @@ const sandbox = async (fn, t) => {
}
};

test("init", t => {
test("init", (t) => {
const testInSandbox = (name, fn) => {
t.test(name, t => sandbox(fn, t));
t.test(name, (t) => sandbox(fn, t));
};

testInSandbox('update "package.json"', async (t, ctx) => {
Expand All @@ -64,7 +64,7 @@ test("init", t => {
t.end();
});

[".editorconfig", ".remarkignore"].forEach(file => {
[".editorconfig", ".remarkignore"].forEach((file) => {
testInSandbox(`write "${file}"`, async (t, ctx) => {
await ctx.fixture("package-normal.json");
await init(ctx.initArgs);
Expand All @@ -80,7 +80,7 @@ test("init", t => {
});

testInSandbox("throw error if no package.json", async (t, ctx) => {
const error = await init(ctx.initArgs).catch(err => err);
const error = await init(ctx.initArgs).catch((err) => err);
t.ok(error instanceof Error);
t.is(error.code, "ENOENT");
t.end();
Expand Down
4 changes: 2 additions & 2 deletions test/main.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const test = require("tape");
const main = require("..");

test("main", t => {
t.test("init", t => {
test("main", (t) => {
t.test("init", (t) => {
const { init } = main;
t.is(typeof init, "function");
t.is(init.name, "init");
Expand Down
6 changes: 3 additions & 3 deletions test/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const test = require("tape");
const pkg = require("../package.json");
const exec = require("./helpers/exec");

test("version", t => {
["--version", "-v"].forEach(option => {
t.test(`with "${option}" option`, async t => {
test("version", (t) => {
["--version", "-v"].forEach((option) => {
t.test(`with "${option}" option`, async (t) => {
const { stdout, stderr } = await exec(option);
t.is(stdout.trim(), pkg.version);
t.is(stderr, "");
Expand Down

0 comments on commit 375a6ef

Please sign in to comment.