diff --git a/README.md b/README.md index 211f8b1..49a9667 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,12 @@ arguments will be provided: - `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package - `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package - `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package -- `require` Is available, with some caveats: - - The location of the module that runs this action is where the Actions - runner downloads the github-script action to, so the `require` passed to - your script is actually a proxy that intercepts calls to require relative - paths and transforms them into an absolute path in the working directory, - instead. - - If you want to require an npm module in your working directory, you still - need to specify the relative path, including `node_modules`, such as - `./node_modules/lodash`. - - If for some reason you need the non-wrapped `require`, there is an escape - hatch available: `__original_require__` is the original value of `require` - without our wrapping applied. +- `require` A proxy wrapper around the normal Node.js `require` to enable + requiring relative paths (relative to the current working directory) and + requiring npm packages installed in the current working directory. If for + some reason you need the non-wrapped `require`, there is an escape hatch + available: `__original_require__` is the original value of `require` without + our wrapping applied. Since the `script` is just a function body, these values will already be defined, so you don't have to (see examples below). @@ -255,7 +249,7 @@ jobs: - uses: actions/github-script@v3 with: script: | - const script = require(`./path/to/script.js`) + const script = require('./path/to/script.js') console.log(script({github, context})) ``` @@ -295,7 +289,7 @@ jobs: SHA: '${{env.parentSHA}}' with: script: | - const script = require(`./path/to/script.js`) + const script = require('./path/to/script.js') await script({github, context, core}) ``` @@ -334,18 +328,13 @@ jobs: - uses: actions/github-script@v3 with: script: | - const execa = require(`./node_modules/execa`) + const execa = require('execa') const { stdout } = await execa('echo', ['hello', 'world']) console.log(stdout) ``` -_(Note that at this time, one still has to specify `node_modules` in the -require path for modules in the working directory of the step that is -running. Hopefully we will have a solution for this in the future, but not -quite, yet.)_ - ### Use env as input You can set env vars to use them in your script: