Skip to content

Commit 2d38e69

Browse files
authored
Fix TSConfig Paths Registration Error on Node 23+ (#208)
This pull request introduces several updates to improve project configuration, enhance developer guidelines, and refactor code for better modularity and maintainability. Key changes include the addition of a CodeQL configuration file, comprehensive Copilot usage instructions, new VS Code settings for Copilot, and the refactoring of module imports in `src/bootstrap.ts`. Closes #207
2 parents 3b8c548 + 09b333f commit 2d38e69

File tree

10 files changed

+159
-27
lines changed

10 files changed

+159
-27
lines changed

.github/codeql/codeql-config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: JavaScript CodeQL Configuration
2+
3+
paths-ignore:
4+
- coverage
5+
- megalinter-reports
6+
- node_modules
7+
- reports

.github/copilot-instructions.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copilot Instructions
2+
3+
## Environment Setup
4+
5+
Install dependencies by running:
6+
7+
```bash
8+
npm install
9+
```
10+
11+
## Testing
12+
13+
Ensure all unit tests pass by running:
14+
15+
```bash
16+
npm run test
17+
```
18+
19+
Unit tests should exist in the `__tests__` directory. They are powered by
20+
`jest`. Fixtures should be placed in the `__fixtures__` directory.
21+
22+
## General Coding Guidelines
23+
24+
- Follow standard TypeScript and JavaScript coding conventions and best
25+
practices
26+
- Changes should maintain consistency with existing patterns and style
27+
- Document changes clearly and thoroughly, including updates to existing
28+
comments when appropriate
29+
- Do not include basic, unnecessary comments that simply restate what the code
30+
is doing (focus on explaining _why_, not _what_)
31+
- Use consistent error handling patterns throughout the codebase
32+
- Use TypeScript's type system to ensure type safety and clarity
33+
- Keep functions focused and manageable
34+
- Use descriptive variable and function names that clearly convey their purpose
35+
- Use JSDoc comments to document functions, classes, and complex logic
36+
- After doing any refactoring, ensure to run `npm run test` to ensure that all
37+
tests still pass and coverage requirements are met
38+
- When suggesting code changes, always opt for the most maintainable approach.
39+
Try your best to keep the code clean and follow "Don't Repeat Yourself" (DRY)
40+
principles
41+
- Avoid unnecessary complexity and always consider the long-term maintainability
42+
of the code
43+
- When writing unit tests, try to consider edge cases as well as the main path
44+
of success. This will help ensure that the code is robust and can handle
45+
unexpected inputs or situations
46+
47+
### Versioning
48+
49+
GitHub Actions are versioned using branch and tag names. Please ensure the
50+
version in the project's `package.json` is updated to reflect the changes made
51+
in the codebase. The version should follow
52+
[Semantic Versioning](https://semver.org/) principles.
53+
54+
## Pull Request Guidelines
55+
56+
When creating a pull request (PR), please ensure that:
57+
58+
- Keep changes focused and minimal (avoid large changes, or consider breaking
59+
them into separate, smaller PRs)
60+
- Formatting checks pass
61+
- Linting checks pass
62+
- Unit tests pass and coverage requirements are met
63+
- If necessary, the `README.md` file is updated to reflect any changes in
64+
functionality or usage
65+
66+
The body of the PR should include:
67+
68+
- A summary of the changes
69+
- A special note of any changes to dependencies
70+
- A link to any relevant issues or discussions
71+
- Any additional context that may be helpful for reviewers
72+
73+
## Code Review Guidelines
74+
75+
When performing a code review, please follow these guidelines:
76+
77+
- If there are changes that modify the functionality/usage of the action,
78+
validate that there are changes in the `README.md` file that document the new
79+
or modified functionality

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
with:
4343
languages: ${{ matrix.language }}
4444
source-root: src
45+
config-file: .github/codeql/codeql-config.yml
4546

4647
- name: Autobuild
4748
id: autobuild

.vscode/mcp.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"servers": {
3+
"github": {
4+
"url": "https://api.githubcopilot.com/mcp/",
5+
"type": "http"
6+
}
7+
},
8+
"inputs": []
9+
}

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"github.copilot.chat.reviewSelection.instructions": [
3+
{
4+
"text": "Review the code changes carefully before accepting them."
5+
}
6+
],
7+
"github.copilot.chat.commitMessageGeneration.instructions": [
8+
{
9+
"text": "Use conventional commit message format."
10+
}
11+
],
12+
"github.copilot.chat.pullRequestDescriptionGeneration.instructions": [
13+
{ "text": "Always include a list of key changes." }
14+
]
15+
}

bin/local-action.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ function entrypoint() {
3232
? path.join(packagePath, 'src', 'bootstrap.ts').replaceAll('\\', '\\\\')
3333
: path.join(packagePath, 'src', 'bootstrap.ts')
3434

35+
// Require the bootstrap script in NODE_OPTIONS.
36+
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS
37+
? `${process.env.NODE_OPTIONS} --require "${bootstrapPath}"`
38+
: `--require "${bootstrapPath}"`
39+
3540
// Disable experimental warnings.
3641
process.env.NODE_NO_WARNINGS = 1
3742

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@github/local-action",
33
"description": "Local Debugging for GitHub Actions",
4-
"version": "5.0.1",
4+
"version": "5.1.0",
55
"type": "module",
66
"author": "Nick Alteen <ncalteen@github.com>",
77
"private": false,

src/bootstrap.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,46 @@
99
* will parse them and register them so that modules can be resolved correctly.
1010
*/
1111

12-
const { existsSync, readFileSync } = require('fs')
13-
const { loadConfig, register } = require('tsconfig-paths')
14-
const { parse } = require('comment-json')
12+
import('fs').then(({ existsSync, readFileSync }) => {
13+
import('tsconfig-paths').then(({ loadConfig, register }) => {
14+
import('comment-json').then(({ parse }) => {
15+
import('path').then(({ dirname }) => {
16+
import('url').then(({ fileURLToPath }) => {
17+
if (
18+
process.env.TARGET_ACTION_PATH &&
19+
process.env.TARGET_ACTION_PATH !== ''
20+
) {
21+
// Check if the action has a `tsconfig.json` file.
22+
if (existsSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`)) {
23+
const __dirname = dirname(fileURLToPath(import.meta.url))
1524

16-
if (process.env.TARGET_ACTION_PATH && process.env.TARGET_ACTION_PATH !== '') {
17-
// Check if the action has a `tsconfig.json` file.
18-
if (existsSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`)) {
19-
// Load the `tsconfig.json` from the action directory.
20-
const actionTsConfig = parse(
21-
readFileSync(`${process.env.TARGET_ACTION_PATH}/tsconfig.json`, 'utf-8')
22-
)
25+
// Load the `tsconfig.json` from the action directory.
26+
const actionTsConfig = parse(
27+
readFileSync(
28+
`${process.env.TARGET_ACTION_PATH}/tsconfig.json`,
29+
'utf-8'
30+
)
31+
)
2332

24-
// Load the current `tsconfig.json` from the root of this directory.
25-
loadConfig(__dirname)
33+
// Load the current `tsconfig.json` from the root of this directory.
34+
loadConfig(__dirname)
2635

27-
// Get the paths from the action's `tsconfig.json`, if any.
28-
const paths = actionTsConfig.compilerOptions?.paths ?? {}
36+
// Get the paths from the action's `tsconfig.json`, if any.
37+
// @ts-expect-error comment-json type mismatch
38+
const paths = actionTsConfig?.compilerOptions?.paths ?? {}
2939

30-
// Add any path mappings from the imported action. Replace the base URL with
31-
// the target action path.
32-
// @todo Should this take into account the previous `baseUrl` value?
33-
register({
34-
baseUrl: process.env.TARGET_ACTION_PATH,
35-
paths,
36-
addMatchAll: true
40+
// Add any path mappings from the imported action. Replace the base URL with
41+
// the target action path.
42+
// @todo Should this take into account the previous `baseUrl` value?
43+
register({
44+
baseUrl: process.env.TARGET_ACTION_PATH,
45+
paths,
46+
addMatchAll: true
47+
})
48+
}
49+
}
50+
})
51+
})
3752
})
38-
}
39-
}
53+
})
54+
})

src/commands/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export async function action(
8181
// @todo Load this into EnvMeta directly? What about secrets...
8282
config({
8383
path: path.resolve(process.cwd(), dotenvFile),
84-
override: true
84+
override: true,
85+
quiet: true
8586
})
8687

8788
// Load action settings

0 commit comments

Comments
 (0)