Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

fix: use ES modules in README.md #978

Merged
merged 5 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = {
'no-magic-numbers': 'off',
},
},
{
files: '*.md/*.js',
parserOptions: {
sourceType: 'module',
},
},
],
ignorePatterns: ['tests/fixtures/**/*'],
}
57 changes: 19 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ npm install @netlify/zip-it-and-ship-it
- _Return value_: `Promise<object[]>`

```js
const { zipFunctions } = require('@netlify/zip-it-and-ship-it')
import { zipFunctions } from '@netlify/zip-it-and-ship-it'

const zipNetlifyFunctions = async function () {
const archives = await zipFunctions('functions', 'functions-dist', {
archiveFormat: 'zip',
})

return archives
}
const archives = await zipFunctions('functions', 'functions-dist', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pure ES modules come with top-level await support too.

archiveFormat: 'zip',
})
```

Creates Zip `archives` from Node.js, Go, and Rust programs. Those `archives` are ready to be uploaded to AWS Lambda.
Expand Down Expand Up @@ -258,13 +254,9 @@ Additionally, the following properties also exist for Node.js functions:
- _Return value_: `object | undefined`

```js
const { zipFunction } = require('@netlify/zip-it-and-ship-it')

const zipNetlifyFunctions = async function () {
const archive = await zipFunctions('functions/function.js', 'functions-dist')
import { zipFunction } from '@netlify/zip-it-and-ship-it'

return archive
}
const archive = await zipFunctions('functions/function.js', 'functions-dist')
```

This is like [`zipFunctions()`](#zipfunctionssrcfolder-destfolder-options) except it bundles a single Function.
Expand All @@ -276,13 +268,9 @@ The return value is `undefined` if the function is invalid.
Returns the list of functions to bundle.

```js
const { listFunctions } = require('@netlify/zip-it-and-ship-it')

const listNetlifyFunctions = async function () {
const functions = await listFunctions('functions/function.js')
import { listFunctions } from '@netlify/zip-it-and-ship-it'

return functions
}
const functions = await listFunctions('functions/function.js')
```

### `srcFolders`
Expand Down Expand Up @@ -326,12 +314,9 @@ Like [`listFunctions()`](#listfunctionssrcfolder), except it returns not only th
their required files. This is much slower.

```js
const { listFunctionsFiles } = require('@netlify/zip-it-and-ship-it')
import { listFunctionsFiles } from '@netlify/zip-it-and-ship-it'

const listNetlifyFunctionsFiles = async function () {
const functions = await listFunctionsFiles('functions/function.js')
return functions
}
const functions = await listFunctionsFiles('functions/function.js')
```

### `srcFolders`
Expand Down Expand Up @@ -400,20 +385,16 @@ included in the bundle.
You can enable esbuild by setting the [`config` option](#config) when calling `zipFunction` or `zipFunctions`:

```js
const { zipFunctions } = require('@netlify/zip-it-and-ship-it')

const zipNetlifyFunctions = async function () {
const archives = await zipFunctions('functions', 'functions-dist', {
config: {
// Applying these settings to all functions.
'*': {
nodeBundler: 'esbuild',
},
},
})
import { zipFunctions } from '@netlify/zip-it-and-ship-it'

return archives
}
const archives = await zipFunctions('functions', 'functions-dist', {
config: {
// Applying these settings to all functions.
'*': {
nodeBundler: 'esbuild',
},
},
})
```

# Feature flags
Expand Down