Skip to content

Commit 27a389d

Browse files
Merge branch 'main' into fix-tsconfig
2 parents 4bff43f + b1e9a9d commit 27a389d

File tree

139 files changed

+3012
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+3012
-286
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ on:
2525
- reopened
2626
- synchronize
2727

28+
permissions:
29+
contents: read
30+
2831
jobs:
2932
get-matrix:
3033
name: Configure Node LTS environment matrix
@@ -33,7 +36,12 @@ jobs:
3336
outputs:
3437
latest: ${{ steps.set-matrix.outputs.requireds }}
3538
steps:
36-
- uses: ljharb/actions/node/matrix@main
39+
- name: Harden the runner (Audit all outbound calls)
40+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
41+
with:
42+
egress-policy: audit
43+
44+
- uses: ljharb/actions/node/matrix@7f214d8efdbdcefc96ad9689663ef387a195deec # main
3745
id: set-matrix
3846
with:
3947
versionsAsRoot: true
@@ -48,12 +56,17 @@ jobs:
4856
runs-on: ubuntu-latest
4957

5058
steps:
51-
- uses: actions/checkout@v4
59+
- name: Harden the runner (Audit all outbound calls)
60+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
61+
with:
62+
egress-policy: audit
63+
64+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5265
with:
5366
persist-credentials: false
5467
show-progress: false
5568
- name: Set up Node.js LTS
56-
uses: actions/setup-node@v4
69+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
5770
with:
5871
cache: "npm"
5972
check-latest: true
@@ -62,6 +75,23 @@ jobs:
6275
- run: node --run lint
6376
- run: node --run type-check
6477

78+
validate-yaml:
79+
name: Validate YAML files
80+
81+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
82+
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- name: Harden the runner (Audit all outbound calls)
87+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
88+
with:
89+
egress-policy: audit
90+
91+
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
92+
- name: Validate YAML files
93+
run: yamllint -c .yamllint.yaml -f github ./
94+
6595
tests:
6696
name: Unit, e2e, coverage
6797

@@ -80,12 +110,17 @@ jobs:
80110
- windows-latest
81111

82112
steps:
83-
- uses: actions/checkout@v4
113+
- name: Harden the runner (Audit all outbound calls)
114+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
115+
with:
116+
egress-policy: audit
117+
118+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84119
with:
85120
persist-credentials: false
86121
show-progress: false
87122
- name: Set up Node.js ${{ matrix.node-version }}
88-
uses: actions/setup-node@v4
123+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
89124
with:
90125
cache: "npm"
91126
check-latest: true

.github/workflows/codemod_publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ jobs:
106106
- name: Authenticate with Codemod registry
107107
env:
108108
CODEMOD_TOKEN: ${{ secrets.CODEMOD_TOKEN }}
109-
run: npx codemod@next login --token "$CODEMOD_TOKEN"
109+
run: npx codemod login --api-key "$CODEMOD_TOKEN"
110110

111111
- name: Publish codemod
112112
working-directory: ${{ steps.parse-tag.outputs.codemod-path }}
113-
run: npx codemod@next publish
113+
run: npx codemod publish
114114

115115
- name: Create release summary
116116
env:

.yamllint.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# We use yamllint to ensure our YAML files are well-formed and follow best practices.
2+
# In future, I (@AugustinMauroy) want to use `codemod validate` to validate YAML files.
3+
# But this feature only check `workflow.yaml` and not `codemod.yaml`.
4+
5+
yaml-files:
6+
- '*.yaml'
7+
- '*.yml'
8+
9+
rules:
10+
anchors: enable
11+
braces: enable
12+
brackets: enable
13+
colons: enable
14+
commas: enable
15+
comments:
16+
level: warning
17+
comments-indentation:
18+
level: warning
19+
document-end: disable
20+
document-start: disable
21+
empty-lines: enable
22+
empty-values: disable
23+
float-values: disable
24+
hyphens: enable
25+
indentation: enable
26+
key-duplicates: enable
27+
key-ordering: disable
28+
line-length:
29+
level: warning
30+
new-line-at-end-of-file: enable
31+
new-lines: enable
32+
octal-values: disable
33+
quoted-strings: disable
34+
trailing-spaces: enable
35+
truthy:
36+
level: warning

CONTRIBUTING.md

Lines changed: 164 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,172 @@
1-
# Contributing
1+
# Contributing to Node.js Userland Migration
22

3-
A recipe generally has a few things:
3+
Thank you for your interest in contributing to this project! We value contributions from the community and want to make the process as smooth as possible.
44

5-
* A `README.md` explaining its purpose and use (including any options, and required and optional
6-
files).
7-
* Tests via node's test runner (min coverage: 80%)
8-
* unit tests
9-
* end-to-end test(s) for accepted use-cases
10-
* a `test` command in `package.json`; there may be sub-commands like `test:unit` & `test:e2e`, but there must be a parent that combines them.
11-
* Include `--import='@nodejs/codemod-utils/snapshots` to standardise the filename (`${original_base_name}.snap.cjs`) across recipes.
12-
* Ensure `--test-coverage-include` and `--test-coverage-exclude` are set correctly for the recipe's workspace. The root repo handles setting coverage rules like minimum line coverage.
13-
* Code comments (js docs, etc)
14-
* Types (either via typescript or jsdoc)
5+
## Getting Started
156

16-
CI will run lint & type checking and all included test files against all PRs.
7+
### Prerequisites
178

18-
New recipes are added under `./recipes` in their own folder, succinctly named for what they do. General-purpose recipes have simple names like `correct-ts-specifiers`. A suite of migrations has a name like `migrate from 18 to 20`, and more specific migrations are named like `migrate-fs-readFile-from-18-to-20`.
9+
Before you begin, ensure you have the current versions of the following installed:
1910

20-
## Before pushing a commit
11+
- node
12+
- npm
2113

22-
A convenient superset of checks is available via `node --run pre-commit`, which automatically fixes formatting and linting issues (that are safe to fix), checks types, and runs tests. Changes resulting from this should be committed.
14+
### Project Overview
15+
16+
Our codebase is organized as follows:
17+
18+
- `.github/`: Contains GitHub files like issue templates and workflows
19+
- `recipes/`: Contains all the codemods
20+
- `utils/`: An npm workspace with utility functions used by the codemods (including [ast-grep](https://ast-grep.github.io/) utilities)
21+
22+
## Codemod Development
23+
24+
### Structure of a Codemod
25+
26+
Each codemod resides in its own directory under `recipes/` and should include:
27+
28+
| File | Purpose |
29+
|------|---------|
30+
| `README.md` | Description, purpose, and usage instructions |
31+
| `package.json` | Package manifest |
32+
| `src/workflow.ts` | Main entry point using the `jssg` codemod API |
33+
| `codemod.yml` | Codemod manifest file |
34+
| `workflow.yml` | Workflow definition file |
35+
| `tests/` | Test suite using `jssg` testing utilities |
36+
| `tsconfig.json` | TypeScript configuration |
37+
38+
### Example Files
39+
40+
**`src/workflow.ts` example:**
41+
```ts
42+
import type { SgRoot, Edit } from "@codemod.com/jssg-types/main";
43+
/**
44+
* Transform function that converts deprecated api.fn calls
45+
* to the new api.fn syntax.
46+
*
47+
* Handles:
48+
* 1. api.fn(<args>)
49+
* 2. api.fn(<args>, { recursive: true })
50+
* ...
51+
*/
52+
export default function transform(root: SgRoot): string | null {
53+
const rootNode = root.root();
54+
let hasChanges = false;
55+
const edits: Edit[] = [];
56+
// do some transformation
57+
if (!hasChanges) return null;
58+
return rootNode.commitEdits(edits);
59+
}
60+
```
61+
62+
**`codemod.yml` example:**
63+
```yaml
64+
schema_version: "1.0"
65+
name: "@nodejs/<codemod-name>"
66+
version: 1.0.0
67+
description: <Your codemod description>
68+
author: <Your Name>
69+
license: MIT
70+
workflow: workflow.yaml
71+
category: migration
72+
73+
targets:
74+
languages:
75+
- javascript
76+
- typescript
77+
78+
keywords:
79+
- transformation
80+
- migration
81+
82+
registry:
83+
access: public
84+
visibility: public
85+
```
86+
87+
## Useful Resources
88+
89+
- [Codemod CLI Reference](https://docs.codemod.com/cli/cli-reference)
90+
- [Codemod Workflow Documentation](https://docs.codemod.com/cli/workflows)
91+
- [Codemod Studio Documentation](https://docs.codemod.com/codemod-studio)
92+
- [JS ast-grep (jssg) API reference](https://docs.codemod.com/cli/cli-reference#cli-command-reference)
93+
- [ast-grep Documentation](https://ast-grep.github.io/)
94+
95+
## Development Workflow
96+
97+
### Before Pushing a Commit
98+
99+
Run our comprehensive check suite:
100+
101+
```bash
102+
node --run pre-commit
103+
```
104+
105+
This will:
106+
- Fix formatting and safe linting issues automatically
107+
- Check types
108+
- Run tests
109+
Be sure to commit any changes resulting from these automated fixes.
23110

24111
> [!WARNING]
25-
> Some integration tests modify fixtures because they run the entire codemod. Remember to use the `git restore` command to restore these files before pushing a commit.
112+
> Some integration tests modify fixtures as they run the entire codemod. Remember to use `git restore` to revert these files before committing.
113+
114+
### Commit Messages
115+
116+
Please follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification for your commit messages. This helps with:
117+
118+
- Automatic changelog generation
119+
- Understanding the history of changes
120+
- Semantic versioning
121+
122+
Format:
123+
```
124+
<type>(<scope>): <description>
125+
```
126+
127+
- **`type`**: The type of change (e.g., `feat`, `fix`, `docs`, `chore`, etc.)
128+
- **`scope`**: A short, lowercase description of the section of the codebase affected (e.g., `tmpDir-to-tmpdir`, `esm-migration`)
129+
- **`description`**: A concise summary of the change
130+
131+
Examples:
132+
- `feat(tmpDir-to-tmpdir): add new node.js 18 migration codemod`
133+
- `fix(esm-migration): correct type checking in ESM migration`
134+
- `docs(codemod-usage): improve usage examples`
135+
136+
## Pull Request Process
137+
138+
When submitting a pull request:
139+
1. Ensure your changes are well-documented
140+
2. Run all tests (`node --run pre-commit`)
141+
3. Follow the project's coding standards
142+
4. Use the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format in your PR title and description
143+
5. Link to any related issues, using [GitHub keywords](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests) where applicable.
144+
145+
### Acceptance Criteria
146+
147+
For a pull request to be merged, it must:
148+
- Receive approval from at least 2 reviewers
149+
- Pass all tests
150+
- Be open for at least 48 hours to allow for review and discussion
151+
- except hotfixes and trivial corrections (like typos)
152+
153+
### Developer's Certificate of Origin 1.1
154+
155+
```
156+
By contributing to this project, I certify that:
157+
158+
- (a) The contribution was created in whole or in part by me and I have the right to
159+
submit it under the open source license indicated in the file; or
160+
- (b) The contribution is based upon previous work that, to the best of my knowledge,
161+
is covered under an appropriate open source license and I have the right under that
162+
license to submit that work with modifications, whether created in whole or in part
163+
by me, under the same open source license (unless I am permitted to submit under a
164+
different license), as indicated in the file; or
165+
- (c) The contribution was provided directly to me by some other person who certified
166+
(a), (b) or (c) and I have not modified it.
167+
- (d) I understand and agree that this project and the contribution are public and that
168+
a record of the contribution (including all personal information I submit with it,
169+
including my sign-off) is maintained indefinitely and may be redistributed consistent
170+
with this project or the open source license(s) involved.
171+
172+
```

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ This repository contains codemods (automated migrations) for "userland" code. Th
1313
To run the transform scripts use [`codemod`](https://go.codemod.com/github) command below:
1414

1515
```console
16-
$ npx codemod <transform> --target <path> [...options]
16+
npx codemod @nodejs/<recipe>
1717
```
1818

19-
* `transform` - name of transform. see available transforms below.
20-
* `path` - directory to transform. defaults to the current directory.
21-
2219
See the [codemod CLI doc](https://go.codemod.com/cli-docs) for a full list of available commands.
2320

2421
## Available codemods
2522

26-
You can find official Node.js codemods in the [Codemod Registry](https://codemod.com/registry?author=nodejs). Additionally, community-contributed Node.js codemods are available in the [Codemod Registry](https://codemod.link/nodejs-official).
23+
You can find official Node.js codemods in the [Codemod Registry](https://codemod.link/nodejs-official).
2724

2825
## Acknowledgments
2926

0 commit comments

Comments
 (0)