Skip to content

Commit 9ac0880

Browse files
authored
Merge pull request #240 from actions/joshmgross/document-esm
Add an example using ESM `import`
2 parents 53cdbb4 + 5541733 commit 9ac0880

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: README.md

+25
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,31 @@ jobs:
346346
console.log(stdout)
347347
```
348348
349+
### Use ESM `import`
350+
351+
To import an ESM file, you'll need to reference your script by an absolute path and ensure you have a `package.json` file with `"type": "module"` specified.
352+
353+
For a script in your repository `src/print-stuff.js`:
354+
```js
355+
export default function printStuff() { console.log('stuff') }
356+
```
357+
358+
```yaml
359+
on: push
360+
361+
jobs:
362+
print-stuff:
363+
runs-on: ubuntu-latest
364+
steps:
365+
- uses: actions/checkout@v2
366+
- uses: actions/github-script@v6
367+
with:
368+
script: |
369+
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
370+
371+
await printStuff()
372+
```
373+
349374
### Use env as input
350375

351376
You can set env vars to use them in your script:

0 commit comments

Comments
 (0)