Skip to content

Commit

Permalink
Merge branch 'master' into user-level-npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c authored Oct 9, 2023
2 parents 2038308 + d4ca032 commit 37f914d
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 60 deletions.
12 changes: 12 additions & 0 deletions .changeset/calm-tips-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'skuba': patch
---

template/koa-rest-api: Fix `app.test.ts` assertions

Previously, [custom `.expect((res) => {})` assertions](https://github.com/ladjs/supertest#expectfunctionres-) were incorrectly defined to return false rather than throw an error. The template has been updated to avoid this syntax, but the most straightforward diff to demonstrate the fix is as follows:

```diff
- await agent.get('/').expect(({ status }) => status !== 404);
+ await agent.get('/').expect(({ status }) => expect(status).not.toBe(404));
```
7 changes: 7 additions & 0 deletions .changeset/chilly-chairs-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skuba': minor
---

Net.waitFor: Use Docker Compose V2

This function now executes `docker compose` under the hood as `docker-compose` stopped receiving updates in July 2023. See the [Docker manual](https://docs.docker.com/compose/migrate/) for more information.
7 changes: 7 additions & 0 deletions .changeset/nasty-bees-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skuba': minor
---

lint: Add `prettier-plugin-packagejson`

This Prettier plugin sorts and formats your `package.json` file.
1 change: 1 addition & 0 deletions config/prettier.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const singleQuote: boolean;
export const tabWidth: number;
export const trailingComma: 'all';
export const plugins: ['prettier-plugin-packagejson'];
1 change: 1 addition & 0 deletions config/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
plugins: [require.resolve('prettier-plugin-packagejson')],
};
4 changes: 3 additions & 1 deletion docs/deep-dives/editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ parent: Deep dives
```json
{
"[typescript]": {
"editor.codeActionsOnSave": ["source.fixAll.eslint"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Expand Down
3 changes: 1 addition & 2 deletions docs/development-api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ parent: Development API

Waits for a resource to start listening on a socket address.

This can be used to wait for a Docker container to start listening on its port,
as described in <https://docs.docker.com/compose/startup-order/>.
This can be used to wait for a Docker container to start listening on its port.

```js
// jest.config.int.ts
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@
"npm-which": "^3.0.1",
"picomatch": "^2.2.2",
"prettier": "~3.0.3",
"prettier-plugin-packagejson": "^2.4.6",
"read-pkg-up": "^7.0.1",
"runtypes": "^6.0.0",
"semantic-release": "^21.0.0",
"serialize-error": "^8.0.1",
"simple-git": "^3.5.0",
"sort-package-json": "^2.5.1",
"strip-ansi": "^6.0.1",
"ts-dedent": "^2.2.0",
"ts-jest": "^29.1.0",
Expand Down
4 changes: 4 additions & 0 deletions scripts/test-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
set -e

template="${1}"
if [ -z "$template" ]; then
echo "Usage: yarn test:template <template_name>"
exit 1
fi

directory="tmp-${template}"

Expand Down
32 changes: 32 additions & 0 deletions src/api/git/commitAllChanges.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,35 @@ it('should no-op on clean directory', async () => {

expect(statuses).toStrictEqual(['absent', 'absent']);
});

it('should work in a directory which is not relative with a gitIgnore file', async () => {
const gitIgnoreFilename = '.gitignore';
const gitIgnoreContent = `/${newFileName2}`;

await Promise.all([
fs.promises.writeFile(gitIgnoreFilename, gitIgnoreContent),
fs.promises.writeFile(newFileName, ''),
fs.promises.writeFile(newFileName2, ''),
]);

await Promise.all([
git.add({ fs, dir, filepath: gitIgnoreFilename }),
git.add({ fs, dir, filepath: newFileName }),
git.add({ fs, dir, filepath: newFileName2 }),
]);

await expect(
commitAllChanges({
dir: process.cwd(),
message: 'remove commit',
author,
}),
).resolves.toMatch(/^[0-9a-f]{40}$/);

const statuses = await Promise.all([
git.status({ fs, dir, filepath: newFileName }),
git.status({ fs, dir, filepath: newFileName2 }),
]);

expect(statuses).toStrictEqual(['unmodified', 'ignored']);
});
12 changes: 10 additions & 2 deletions src/api/git/commitAllChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ export const commitAllChanges = async ({
await Promise.all(
changedFiles.map((file) =>
file.state === 'deleted'
? git.remove({ fs, dir: gitRoot, filepath: path.join(dir, file.path) })
: git.add({ fs, dir: gitRoot, filepath: path.join(dir, file.path) }),
? git.remove({
fs,
dir: gitRoot,
filepath: path.relative(gitRoot, path.join(dir, file.path)),
})
: git.add({
fs,
dir: gitRoot,
filepath: path.relative(gitRoot, path.join(dir, file.path)),
}),
),
);

Expand Down
3 changes: 2 additions & 1 deletion src/api/net/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const resolveComposeAddress = async (
const exec = createExec({ stdio: 'pipe' });

const { stdout } = await exec(
'docker-compose',
'docker',
'compose',
'port',
privateHost,
String(privatePort),
Expand Down
3 changes: 2 additions & 1 deletion src/cli/__snapshots__/format.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ Processed 4 files in <random>s.
Prettier
Processed 8 files in <random>s.
Formatted 3 files:
Formatted 4 files:
b.md
c.json
d.js
package.json
"
`;
Expand Down
4 changes: 3 additions & 1 deletion src/cli/__snapshots__/lint.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ ESLint │
3 errors and 0 warnings potentially fixable with the \`--fix\` option.
Prettier │ Processed 8 files in <random>s.
Prettier │ Flagged 3 files:
Prettier │ Flagged 4 files:
Prettier │ b.md
Prettier │ c.json
Prettier │ d.js
Prettier │ package.json
tsc │ TSFILE: <random>/lib/tsconfig.tsbuildinfo
tsc │ tsc --noEmit exited with code 0
Expand Down Expand Up @@ -61,6 +62,7 @@ Options: {
b.md
c.json
d.js
package.json
\`\`\`
",
]
Expand Down
6 changes: 3 additions & 3 deletions src/cli/configure/analysis/__snapshots__/project.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export {};
},
"package.json": {
"data": "{
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "skuba build",
"format": "skuba format",
Expand All @@ -141,9 +143,7 @@ export {};
"template": null,
"type": "application",
"version": "0.0.0-semantically-released"
},
"license": "UNLICENSED",
"private": true
}
}
",
"operation": "A",
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/analysis/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { defaultOpts } from '../testing/module';
import * as project from './project';
import { diffFiles } from './project';

jest.mock('sort-package-json');

describe('diffFiles', () => {
it('works from scratch', async () => {
jest
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { defaultOpts, executeModule } from '../testing/module';

import { jestModule } from './jest';

jest.mock('sort-package-json');

describe('jestModule', () => {
it('works from scratch', async () => {
const inputFiles = {};
Expand Down
46 changes: 23 additions & 23 deletions src/cli/configure/processing/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ describe('withPackage', () => {
),
).resolves.toMatchInlineSnapshot(`
"{
"description": "My Package",
"readme": "https://github.com/my-org/my-package#readme",
"version": "0.1.0",
"name": "my-package",
"$name": "unit-test"
"version": "0.1.0",
"description": "My Package",
"$name": "unit-test",
"readme": "https://github.com/my-org/my-package#readme"
}
"
`));
Expand Down Expand Up @@ -140,32 +140,32 @@ describe('withPackage', () => {
),
).resolves.toMatchInlineSnapshot(`
"{
"devDependencies": {
"c": "3",
"e": "5",
"d": "4",
"@types/koa__router": "^8.0.8",
"@types/koa-bodyparser": "^5.0.2",
"@types/koa": "^2.13.4"
"files": [
"b",
"a"
],
"scripts": {
"prebuild": "rm -rf system32",
"build": "npm install freebsd",
"prelint": "echo Prepare for lint-off",
"lint": "echo Linting"
},
"dependencies": {
"b": "2",
"a": "1"
"a": "1",
"b": "2"
},
"scripts": {
"lint": "echo Linting",
"prelint": "echo Prepare for lint-off",
"prebuild": "rm -rf system32",
"build": "npm install freebsd"
"devDependencies": {
"@types/koa": "^2.13.4",
"@types/koa-bodyparser": "^5.0.2",
"@types/koa__router": "^8.0.8",
"c": "3",
"d": "4",
"e": "5"
},
"skuba": {
"version": "1.0.0",
"type": "application"
},
"files": [
"b",
"a"
]
}
}
"
`));
Expand Down
20 changes: 8 additions & 12 deletions src/cli/configure/processing/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ import { parseObject } from './json';
import { formatPrettier } from './prettier';

export const formatPackage = async (rawData: PackageJson) => {
const sortPackageJson = await import('sort-package-json');

normalizeData(rawData);

const data = sortPackageJson.sortPackageJson(rawData);

// normalize-package-data fields that aren't useful for applications

delete data._id;
delete rawData._id;

if (data.name === '') {
delete data.name;
if (rawData.name === '') {
delete rawData.name;
}

if (data.readme === 'ERROR: No README data found!') {
delete data.readme;
if (rawData.readme === 'ERROR: No README data found!') {
delete rawData.readme;
}

if (data.version === '') {
delete data.version;
if (rawData.version === '') {
delete rawData.version;
}

return formatPrettier(JSON.stringify(data), {
return formatPrettier(JSON.stringify(rawData), {
filepath: 'package.json',
});
};
Expand Down
12 changes: 8 additions & 4 deletions template/koa-rest-api/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ describe('app', () => {

it('has a happy health check', () => agent.get('/health').expect(200, ''));

it('has a reachable smoke test', () =>
agent.get('/smoke').expect(({ status }) => status !== 404));
it('has a reachable smoke test', async () => {
const response = await agent.get('/smoke');
expect(response.status).not.toBe(404);
});

it('has a reachable nested route', () =>
agent.get('/jobs').expect(({ status }) => status !== 404));
it('has a reachable nested route', async () => {
const response = await agent.get('/jobs');
expect(response.status).not.toBe(404);
});

it('has OPTIONS for a nested route', () =>
agent.options('/jobs').expect(200).expect('allow', /HEAD/));
Expand Down
18 changes: 13 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8466,6 +8466,14 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier-plugin-packagejson@^2.4.6:
version "2.4.6"
resolved "https://registry.yarnpkg.com/prettier-plugin-packagejson/-/prettier-plugin-packagejson-2.4.6.tgz#b1d46b67fd4d80dd6b352d1f5cb472344e6db9be"
integrity sha512-5JGfzkJRL0DLNyhwmiAV9mV0hZLHDwddFCs2lc9CNxOChpoWUQVe8K4qTMktmevmDlMpok2uT10nvHUyU59sNw==
dependencies:
sort-package-json "2.6.0"
synckit "0.8.5"

prettier@^2.7.1:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
Expand Down Expand Up @@ -9574,10 +9582,10 @@ sort-object-keys@^1.1.3:
resolved "https://registry.yarnpkg.com/sort-object-keys/-/sort-object-keys-1.1.3.tgz#bff833fe85cab147b34742e45863453c1e190b45"
integrity sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==

sort-package-json@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/sort-package-json/-/sort-package-json-2.5.1.tgz#5c0f2ce8cc8851988e5039f76b8978439439039d"
integrity sha512-vx/KoZxm8YNMUqdlw7SGTfqR5pqZ/sUfgOuRtDILiOy/3AvzhAibyUe2cY3OpLs3oRSow9up4yLVtQaM24rbDQ==
sort-package-json@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/sort-package-json/-/sort-package-json-2.6.0.tgz#68337dbbd267971add856308a9b454a7d6cbfc0a"
integrity sha512-XSQ+lY9bAYA8ZsoChcEoPlgcSMaheziEp1beox1JVxy1SV4F2jSq9+h2rJ+3mC/Dhu9Ius1DLnInD5AWcsDXZw==
dependencies:
detect-indent "^7.0.1"
detect-newline "^4.0.0"
Expand Down Expand Up @@ -9928,7 +9936,7 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

synckit@^0.8.5:
synckit@0.8.5, synckit@^0.8.5:
version "0.8.5"
resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.8.5.tgz#b7f4358f9bb559437f9f167eb6bc46b3c9818fa3"
integrity sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==
Expand Down

0 comments on commit 37f914d

Please sign in to comment.