Skip to content

Commit

Permalink
Merge branch 'main' into use-aws-codedeploy-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelius0523 committed Sep 3, 2024
2 parents 662f693 + 72e448d commit b711f63
Show file tree
Hide file tree
Showing 16 changed files with 3,303 additions and 2,317 deletions.
14 changes: 14 additions & 0 deletions .changeset/empty-cherries-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'skuba': major
---

node, start: Replace `ts-node` with `tsx`

`skuba start` and `skuba node` now use `tsx` instead of `ts-node` for running TypeScript files. `tsx` has better ESM interoperability, like support for dynamic imports (`await import()`), than `ts-node`.

There are some downsides for the REPL (which is what `skuba node` without any file is):

- `import` statements in the REPL are not supported; `require` and `await import()` are still supported.
- Pasting code into the REPL may not work as well as `ts-node`. If encountering issues, a workaround could be to use [`.editor`](https://nodejs.org/en/learn/command-line/how-to-use-the-nodejs-repl#dot-commands)

Otherwise, `skuba start` and `skuba node <file>` _should_ work as expected. However, it is difficult to comprehensively test every scenario, so this has been released as a major version. It is recommended to test your use-cases of `skuba start` and `skuba node` after upgrading.
5 changes: 5 additions & 0 deletions .changeset/heavy-scissors-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

template/koa-rest-api: Enable secure headers middleware by default
13 changes: 12 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
prPriority: 99,
schedule: 'before 3:00 am every weekday',
},
{
matchDepTypes: ['devDependencies'],
matchManagers: ['npm'],
semanticCommitType: 'devDeps',
},
{
matchDepTypes: ['dependencies', 'peerDependencies'],
matchManagers: ['npm'],
semanticCommitType: 'deps',
},
{
matchPaths: ['template/**'],

Expand All @@ -102,13 +112,14 @@
],
branchPrefix: 'renovate-',
commitMessageAction: '',
gitIgnoredAuthors: ['[email protected]'],
postUpdateOptions: [],
prConcurrentLimit: 3,
prNotPendingHours: 1,
rangeStrategy: 'replace',
schedule: 'after 3:00 am and before 6:00 am every weekday',
semanticCommitScope: '',
semanticCommitType: 'deps',
semanticCommitType: 'update',
customManagers: [
{
customType: 'regex',
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/renovate-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Modelled on https://github.com/backstage/backstage/blob/5083c8024deffbdf454983900f02780d14b55a0b/.github/workflows/sync_renovate-changesets.yml#L6

name: Sync Renovate changeset
on:
pull_request_target:
paths:
- '.github/workflows/renovate-changeset.yml'
- 'pnpm-lock.yaml'

jobs:
generate-changeset:
runs-on: ubuntu-latest
if: github.actor == 'renovate[bot]' && github.repository == 'seek-oss/skuba'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.head_ref }}
token: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }}
- name: Configure Git
run: |
git config --global user.email [email protected]
git config --global user.name 'Github changeset workflow'
- name: Generate changeset
uses: actions/github-script@v7
env:
PR_TITLE: ${{ github.event.pull_request.title }}
with:
script: |
const { promises: fs } = require('fs');
async function getPackagesNames(files) {
const packageJsons = await Promise.all(
files.map(async (file) => JSON.parse(await fs.readFile(file, 'utf8'))),
);
return packageJsons.flatMap((d) => (d.private ? [] : [d.name]));
}
async function createChangeset(fileName, message, packages) {
const header = packages.map((pkg) => `'${pkg}': patch`).join('\n');
const body = `---\n${header}\n---\n\n${message.trim()}\n`;
await fs.writeFile(fileName, body);
}
const prTitle = process.env.PR_TITLE;
if (!prTitle) {
console.log('No PR title found, skipping');
return;
}
const prefix = prTitle.split(':')[0];
if (prefix !== 'deps' && prefix !== 'template') {
console.log('Not a prod/template update PR, skipping');
return;
}
const branch = await exec.getExecOutput('git branch --show-current');
if (!branch.stdout.startsWith('renovate-')) {
console.log('Not a renovate branch, skipping');
return;
}
const diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
const diffFiles = diffOutput.stdout.split('\n');
if (diffFiles.find((f) => f.startsWith('.changeset'))) {
console.log('Changeset already exists, skipping');
return;
}
const files = diffFiles.filter((file) => file.includes('package.json'));
const packageNames = await getPackagesNames(files);
if (!packageNames.length) {
console.log('No package.json changes to published packages, skipping');
return;
}
const { stdout: shortHash } = await exec.getExecOutput(
'git rev-parse --short HEAD',
);
const fileName = `.changeset/renovate-${shortHash.trim()}.md`;
await createChangeset(fileName, prTitle, packageNames);
await exec.exec('git', ['add', fileName]);
await exec.exec('git commit -C HEAD --amend --no-edit');
await exec.exec('git push --force');
8 changes: 3 additions & 5 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ nav_order: 3

---

**skuba** lets you interactively run your TypeScript source code during development.
The following commands are powered by [`ts-node`] and [`ts-node-dev`].
**skuba** lets you interactively run your TypeScript source code during development, powered by [`tsx`].

These commands are only intended to serve local development and simple scripting scenarios,
as a TypeScript process can present substantial overhead at runtime.
Expand All @@ -26,7 +25,7 @@ skuba node src/some-cli-script.ts
# ...
```

or launches a [`ts-node`] REPL if a file is not provided:
or launches a [`tsx`] REPL if a file is not provided:

```shell
skuba node src/some-cli-script.ts
Expand Down Expand Up @@ -217,9 +216,8 @@ Execution should pause on the breakpoint until we hit `F5` or the `▶️` butto
[`skuba build`]: ./build.md
[`skuba-dive/register`]: https://github.com/seek-oss/skuba-dive#register
[`ts-node-dev`]: https://github.com/whitecolor/ts-node-dev
[`ts-node`]: https://github.com/typestrong/ts-node
[`tsconfig-paths`]: https://github.com/dividab/tsconfig-paths
[`tsx`]: https://github.com/privatenumber/tsx
[express]: https://expressjs.com/
[fastify]: https://www.fastify.io/
[http server]: https://nodejs.org/docs/latest-v20.x/api/http.html#class-httpserver
Expand Down
2 changes: 1 addition & 1 deletion docs/deep-dives/esbuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ There are a couple of gotchas when evaluating alternative build tools like esbui

esbuild is not fully compatible with all existing `tsc` configurations,
may lag behind TypeScript in language features,
and lacks rich interoperability with tooling like Jest (via `ts-jest`) and `ts-node`.
and lacks rich interoperability with tooling like Jest (via `ts-jest`).

These issues can be mostly contained within a centralised toolkit like skuba,
but it makes it more difficult to duct tape tools together on an ad-hoc basis,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@
"ts-dedent": "^2.2.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.0.0",
"tsconfig-seek": "2.0.0",
"tsx": "^4.16.2",
"typescript": "~5.5.0",
"validate-npm-package-name": "^5.0.0",
"zod": "^3.22.4"
Expand Down
Loading

0 comments on commit b711f63

Please sign in to comment.