netlify-cli 12.2.9 → 12.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +255 -1458
- package/package.json +3 -7
- package/src/commands/addons/addons-auth.mjs +2 -3
- package/src/commands/addons/addons-config.mjs +2 -3
- package/src/commands/addons/addons-create.mjs +2 -3
- package/src/commands/addons/addons-delete.mjs +1 -3
- package/src/commands/addons/addons-list.mjs +1 -3
- package/src/commands/api/api.mjs +1 -3
- package/src/commands/base-command.mjs +3 -3
- package/src/commands/build/build.mjs +3 -3
- package/src/commands/deploy/deploy.mjs +13 -16
- package/src/commands/dev/dev-exec.mjs +2 -3
- package/src/commands/dev/dev.mjs +15 -21
- package/src/commands/env/env-clone.mjs +2 -3
- package/src/commands/env/env-get.mjs +2 -3
- package/src/commands/env/env-import.mjs +2 -3
- package/src/commands/env/env-list.mjs +2 -4
- package/src/commands/env/env-set.mjs +3 -8
- package/src/commands/env/env-unset.mjs +2 -3
- package/src/commands/functions/functions-build.mjs +1 -3
- package/src/commands/functions/functions-create.mjs +3 -3
- package/src/commands/functions/functions-invoke.mjs +1 -3
- package/src/commands/functions/functions-list.mjs +1 -3
- package/src/commands/functions/functions-serve.mjs +1 -2
- package/src/commands/functions/functions.mjs +1 -1
- package/src/commands/graph/graph-config-write.mjs +1 -3
- package/src/commands/graph/graph-edit.mjs +2 -3
- package/src/commands/graph/graph-handler.mjs +1 -3
- package/src/commands/graph/graph-init.mjs +2 -3
- package/src/commands/graph/graph-library.mjs +1 -3
- package/src/commands/graph/graph-operations.mjs +1 -3
- package/src/commands/graph/graph-pull.mjs +1 -3
- package/src/commands/init/init.mjs +2 -4
- package/src/commands/link/link.mjs +1 -3
- package/src/commands/lm/lm-setup.mjs +2 -3
- package/src/commands/login/login.mjs +1 -3
- package/src/commands/logout/logout.mjs +1 -3
- package/src/commands/main.mjs +3 -3
- package/src/commands/open/open-admin.mjs +2 -3
- package/src/commands/open/open-site.mjs +2 -3
- package/src/commands/open/open.mjs +1 -3
- package/src/commands/recipes/recipes.mjs +3 -3
- package/src/commands/sites/sites-create-template.mjs +7 -8
- package/src/commands/sites/sites-create.mjs +2 -4
- package/src/commands/sites/sites-delete.mjs +1 -3
- package/src/commands/sites/sites-list.mjs +1 -3
- package/src/commands/status/status-hooks.mjs +1 -3
- package/src/commands/status/status.mjs +1 -3
- package/src/commands/switch/switch.mjs +1 -3
- package/src/commands/unlink/unlink.mjs +1 -3
- package/src/commands/watch/watch.mjs +1 -3
- package/src/lib/account.mjs +14 -0
- package/src/lib/api.mjs +1 -1
- package/src/lib/completion/generate-autocompletion.mjs +1 -1
- package/src/lib/edge-functions/consts.mjs +4 -0
- package/src/lib/edge-functions/{deploy.cjs → deploy.mjs} +7 -13
- package/src/lib/edge-functions/{headers.cjs → headers.mjs} +3 -1
- package/src/lib/edge-functions/{internal.cjs → internal.mjs} +24 -20
- package/src/lib/edge-functions/{proxy.cjs → proxy.mjs} +18 -20
- package/src/lib/edge-functions/{registry.cjs → registry.mjs} +16 -7
- package/src/lib/{exec-fetcher.cjs → exec-fetcher.mjs} +17 -12
- package/src/lib/functions/{background.cjs → background.mjs} +4 -6
- package/src/lib/functions/{config.cjs → config.mjs} +1 -3
- package/src/lib/functions/form-submissions-handler.mjs +2 -2
- package/src/lib/functions/{local-proxy.cjs → local-proxy.mjs} +4 -6
- package/src/lib/functions/{memoized-build.cjs → memoized-build.mjs} +1 -3
- package/src/lib/functions/{netlify-function.cjs → netlify-function.mjs} +5 -8
- package/src/lib/functions/{registry.cjs → registry.mjs} +12 -14
- package/src/lib/functions/runtimes/go/{index.cjs → index.mjs} +10 -10
- package/src/lib/functions/runtimes/{index.cjs → index.mjs} +12 -7
- package/src/lib/functions/runtimes/js/builders/{netlify-lambda.cjs → netlify-lambda.mjs} +13 -10
- package/src/lib/functions/runtimes/js/builders/{zisi.cjs → zisi.mjs} +15 -13
- package/src/lib/functions/runtimes/js/{index.cjs → index.mjs} +12 -12
- package/src/lib/functions/runtimes/rust/{index.cjs → index.mjs} +15 -15
- package/src/lib/functions/scheduled.mjs +1 -1
- package/src/lib/functions/server.mjs +6 -7
- package/src/lib/functions/{synchronous.cjs → synchronous.mjs} +5 -7
- package/src/lib/functions/{utils.cjs → utils.mjs} +6 -21
- package/src/lib/{geo-location.cjs → geo-location.mjs} +3 -5
- package/src/lib/http-agent.mjs +1 -1
- package/src/lib/{log.cjs → log.mjs} +3 -7
- package/src/lib/one-graph/cli-client.mjs +2 -2
- package/src/lib/one-graph/cli-netlify-graph.mjs +2 -3
- package/src/lib/path.mjs +1 -0
- package/src/lib/{render-error-remplate.cjs → render-error-template.mjs} +8 -4
- package/src/lib/{string.cjs → string.mjs} +1 -3
- package/src/recipes/vscode/index.mjs +1 -1
- package/src/utils/addons/diffs/options.mjs +1 -1
- package/src/utils/addons/prepare.mjs +1 -1
- package/src/utils/addons/prompts.mjs +1 -1
- package/src/utils/addons/render.mjs +1 -1
- package/src/utils/{command-helpers.cjs → command-helpers.mjs} +45 -64
- package/src/utils/{deferred.cjs → create-deferred.mjs} +1 -1
- package/src/utils/deploy/constants.mjs +19 -0
- package/src/utils/deploy/{deploy-site.cjs → deploy-site.mjs} +15 -17
- package/src/utils/deploy/{hash-files.cjs → hash-files.mjs} +7 -5
- package/src/utils/deploy/{hash-fns.cjs → hash-fns.mjs} +11 -8
- package/src/utils/deploy/{hasher-segments.cjs → hasher-segments.mjs} +10 -17
- package/src/utils/deploy/{upload-files.cjs → upload-files.mjs} +5 -5
- package/src/utils/deploy/{util.cjs → util.mjs} +8 -20
- package/src/utils/detect-server-settings.mjs +2 -2
- package/src/utils/{dev.cjs → dev.mjs} +13 -21
- package/src/utils/{dot-env.cjs → dot-env.mjs} +7 -9
- package/src/utils/env/{index.cjs → index.mjs} +11 -24
- package/src/utils/execa.mjs +17 -0
- package/src/utils/get-global-config.mjs +40 -0
- package/src/utils/get-repo-data.mjs +1 -1
- package/src/utils/{gh-auth.cjs → gh-auth.mjs} +10 -12
- package/src/utils/gitignore.mjs +1 -1
- package/src/utils/{headers.cjs → headers.mjs} +4 -11
- package/src/utils/init/{config-github.cjs → config-github.mjs} +6 -8
- package/src/utils/init/{config-manual.cjs → config-manual.mjs} +4 -4
- package/src/utils/init/{config.cjs → config.mjs} +4 -5
- package/src/utils/init/{frameworks.cjs → frameworks.mjs} +2 -5
- package/src/utils/init/{node-version.cjs → node-version.mjs} +6 -8
- package/src/utils/init/{plugins.cjs → plugins.mjs} +3 -5
- package/src/utils/init/{utils.cjs → utils.mjs} +27 -23
- package/src/utils/live-tunnel.mjs +3 -3
- package/src/utils/lm/install.mjs +3 -3
- package/src/utils/lm/requirements.mjs +1 -1
- package/src/utils/lm/steps.mjs +1 -1
- package/src/utils/lm/ui.mjs +1 -1
- package/src/utils/{open-browser.cjs → open-browser.mjs} +5 -5
- package/src/utils/{parse-raw-flags.cjs → parse-raw-flags.mjs} +2 -7
- package/src/utils/proxy.mjs +14 -10
- package/src/utils/{redirects.cjs → redirects.mjs} +3 -7
- package/src/utils/{rules-proxy.cjs → rules-proxy.mjs} +19 -19
- package/src/utils/sites/{utils.cjs → utils.mjs} +6 -6
- package/src/utils/telemetry/telemetry.mjs +2 -2
- package/src/utils/telemetry/validation.mjs +1 -1
- package/src/lib/account.cjs +0 -9
- package/src/lib/edge-functions/consts.cjs +0 -11
- package/src/lib/edge-functions/index.cjs +0 -6
- package/src/lib/path.cjs +0 -3
- package/src/utils/deploy/constants.cjs +0 -31
- package/src/utils/deploy/index.cjs +0 -4
- package/src/utils/execa.cjs +0 -12
- package/src/utils/get-global-config.cjs +0 -47
- package/src/utils/index.cjs +0 -22
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { log } from '../../utils/command-helpers.mjs'
|
|
2
2
|
|
|
3
3
|
import { createOpenAdminCommand, openAdmin } from './open-admin.mjs'
|
|
4
4
|
import { createOpenSiteCommand, openSite } from './open-site.mjs'
|
|
5
5
|
|
|
6
|
-
const { log } = utils
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* The open command
|
|
10
8
|
* @param {import('commander').OptionValues} options
|
|
@@ -4,7 +4,7 @@ import { basename } from 'path'
|
|
|
4
4
|
import inquirer from 'inquirer'
|
|
5
5
|
import { findBestMatch } from 'string-similarity'
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { NETLIFYDEVERR, chalk, log } from '../../utils/command-helpers.mjs'
|
|
8
8
|
|
|
9
9
|
import { getRecipe, listRecipes } from './common.mjs'
|
|
10
10
|
import { createRecipesListCommand } from './recipes-list.mjs'
|
|
@@ -32,7 +32,7 @@ const recipesCommand = async (recipeName, options, command) => {
|
|
|
32
32
|
throw error
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
log(`${NETLIFYDEVERR} ${chalk.yellow(recipeName)} is not a valid recipe name.`)
|
|
36
36
|
|
|
37
37
|
const recipes = await listRecipes()
|
|
38
38
|
const recipeNames = recipes.map(({ name }) => name)
|
|
@@ -43,7 +43,7 @@ const recipesCommand = async (recipeName, options, command) => {
|
|
|
43
43
|
const prompt = inquirer.prompt({
|
|
44
44
|
type: 'confirm',
|
|
45
45
|
name: 'suggestion',
|
|
46
|
-
message: `Did you mean ${
|
|
46
|
+
message: `Did you mean ${chalk.blue(suggestion)}`,
|
|
47
47
|
default: false,
|
|
48
48
|
})
|
|
49
49
|
|
|
@@ -3,19 +3,18 @@
|
|
|
3
3
|
import inquirer from 'inquirer'
|
|
4
4
|
import pick from 'lodash/pick.js'
|
|
5
5
|
import parseGitHubUrl from 'parse-github-url'
|
|
6
|
-
import
|
|
6
|
+
import { render } from 'prettyjson'
|
|
7
7
|
|
|
8
|
+
import { chalk, error, getTerminalLink, log, logJson, warn } from '../../utils/command-helpers.mjs'
|
|
9
|
+
import execa from '../../utils/execa.mjs'
|
|
8
10
|
import getRepoData from '../../utils/get-repo-data.mjs'
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { createRepo, getTemplatesFromGitHub, validateTemplate } from '../../utils/sites/utils.cjs'
|
|
11
|
+
import { getGitHubToken } from '../../utils/init/config-github.mjs'
|
|
12
|
+
import { configureRepo } from '../../utils/init/config.mjs'
|
|
13
|
+
import { createRepo, getTemplatesFromGitHub, validateTemplate } from '../../utils/sites/utils.mjs'
|
|
13
14
|
import { track } from '../../utils/telemetry/index.mjs'
|
|
14
15
|
|
|
15
16
|
import { getSiteNameInput } from './sites-create.mjs'
|
|
16
17
|
|
|
17
|
-
const { chalk, error, execa, getTerminalLink, log, logJson, warn } = utils
|
|
18
|
-
|
|
19
18
|
export const fetchTemplates = async (token) => {
|
|
20
19
|
const templatesFromGithubOrg = await getTemplatesFromGitHub(token)
|
|
21
20
|
|
|
@@ -170,7 +169,7 @@ const sitesCreateTemplate = async (repository, options, command) => {
|
|
|
170
169
|
|
|
171
170
|
const siteUrl = site.ssl_url || site.url
|
|
172
171
|
log(
|
|
173
|
-
|
|
172
|
+
render({
|
|
174
173
|
'Admin URL': site.admin_url,
|
|
175
174
|
URL: siteUrl,
|
|
176
175
|
'Site ID': site.id,
|
|
@@ -4,14 +4,12 @@ import inquirer from 'inquirer'
|
|
|
4
4
|
import pick from 'lodash/pick.js'
|
|
5
5
|
import prettyjson from 'prettyjson'
|
|
6
6
|
|
|
7
|
+
import { chalk, error, log, logJson, warn } from '../../utils/command-helpers.mjs'
|
|
7
8
|
import getRepoData from '../../utils/get-repo-data.mjs'
|
|
8
|
-
import
|
|
9
|
-
import { configureRepo } from '../../utils/init/config.cjs'
|
|
9
|
+
import { configureRepo } from '../../utils/init/config.mjs'
|
|
10
10
|
import { track } from '../../utils/telemetry/index.mjs'
|
|
11
11
|
import { link } from '../link/index.mjs'
|
|
12
12
|
|
|
13
|
-
const { chalk, error, log, logJson, warn } = utils
|
|
14
|
-
|
|
15
13
|
export const getSiteNameInput = async (name) => {
|
|
16
14
|
if (!name) {
|
|
17
15
|
const { name: nameInput } = await inquirer.prompt([
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { listSites } from '../../lib/api.mjs'
|
|
3
3
|
import { startSpinner, stopSpinner } from '../../lib/spinner.cjs'
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
const { chalk, log, logJson } = utils
|
|
4
|
+
import { chalk, log, logJson } from '../../utils/command-helpers.mjs'
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* The sites:list command
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
import clean from 'clean-deep'
|
|
3
3
|
import prettyjson from 'prettyjson'
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { chalk, error, exit, getToken, log, logJson, warn } from '../../utils/command-helpers.mjs'
|
|
6
6
|
|
|
7
7
|
import { createStatusHooksCommand } from './status-hooks.mjs'
|
|
8
8
|
|
|
9
|
-
const { chalk, error, exit, getToken, log, logJson, warn } = utils
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* The status command
|
|
13
11
|
* @param {import('commander').OptionValues} options
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import inquirer from 'inquirer'
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { chalk, log } from '../../utils/command-helpers.mjs'
|
|
5
5
|
import { login } from '../login/index.mjs'
|
|
6
6
|
|
|
7
|
-
const { chalk, log } = utils
|
|
8
|
-
|
|
9
7
|
const LOGIN_NEW = 'I would like to login to a new account'
|
|
10
8
|
|
|
11
9
|
/**
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import
|
|
2
|
+
import { exit, log } from '../../utils/command-helpers.mjs'
|
|
3
3
|
import { track } from '../../utils/telemetry/index.mjs'
|
|
4
4
|
|
|
5
|
-
const { exit, log } = utils
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* The unlink command
|
|
9
7
|
* @param {import('commander').OptionValues} options
|
|
@@ -3,11 +3,9 @@ import pWaitFor from 'p-wait-for'
|
|
|
3
3
|
import prettyjson from 'prettyjson'
|
|
4
4
|
|
|
5
5
|
import { startSpinner, stopSpinner } from '../../lib/spinner.cjs'
|
|
6
|
-
import
|
|
6
|
+
import { chalk, error, log } from '../../utils/command-helpers.mjs'
|
|
7
7
|
import { init } from '../init/index.mjs'
|
|
8
8
|
|
|
9
|
-
const { chalk, error, log } = utils
|
|
10
|
-
|
|
11
9
|
// 1 second
|
|
12
10
|
const INIT_WAIT = 1e3
|
|
13
11
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {any} account
|
|
5
|
+
* @param {string} capability
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
const supportsBooleanCapability = (account, capability) => Boolean(account?.capabilities?.[capability]?.included)
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {any} account
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
export const supportsBackgroundFunctions = (account) => supportsBooleanCapability(account, 'background_functions')
|
package/src/lib/api.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync } from 'fs'
|
|
3
3
|
import { dirname } from 'path'
|
|
4
4
|
|
|
5
|
-
import { sortOptions, warn } from '../../utils/command-helpers.
|
|
5
|
+
import { sortOptions, warn } from '../../utils/command-helpers.mjs'
|
|
6
6
|
|
|
7
7
|
import { AUTOCOMPLETION_FILE } from './constants.mjs'
|
|
8
8
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { stat } from 'fs/promises'
|
|
3
|
+
import { join } from 'path'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { getPathInProject } from '../settings.cjs'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { EDGE_FUNCTIONS_FOLDER, PUBLIC_URL_PATH } from './consts.mjs'
|
|
8
8
|
|
|
9
9
|
const distPath = getPathInProject([EDGE_FUNCTIONS_FOLDER])
|
|
10
10
|
|
|
11
|
-
const deployFileNormalizer = (rootDir, file) => {
|
|
11
|
+
export const deployFileNormalizer = (rootDir, file) => {
|
|
12
12
|
const absoluteDistPath = join(rootDir, distPath)
|
|
13
13
|
const isEdgeFunction = file.root === absoluteDistPath
|
|
14
14
|
const normalizedPath = isEdgeFunction ? `${PUBLIC_URL_PATH}/${file.normalizedPath}` : file.normalizedPath
|
|
@@ -19,7 +19,7 @@ const deployFileNormalizer = (rootDir, file) => {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const getDistPathIfExists = async ({ rootDir }) => {
|
|
22
|
+
export const getDistPathIfExists = async ({ rootDir }) => {
|
|
23
23
|
try {
|
|
24
24
|
const absoluteDistPath = join(rootDir, distPath)
|
|
25
25
|
const stats = await stat(absoluteDistPath)
|
|
@@ -34,10 +34,4 @@ const getDistPathIfExists = async ({ rootDir }) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const isEdgeFunctionFile = (filePath) => filePath.startsWith(`${PUBLIC_URL_PATH}/`)
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
deployFileNormalizer,
|
|
41
|
-
getDistPathIfExists,
|
|
42
|
-
isEdgeFunctionFile,
|
|
43
|
-
}
|
|
37
|
+
export const isEdgeFunctionFile = (filePath) => filePath.startsWith(`${PUBLIC_URL_PATH}/`)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const headers = {
|
|
2
2
|
ForwardedHost: 'x-forwarded-host',
|
|
3
3
|
ForwardedProtocol: 'x-forwarded-proto',
|
|
4
4
|
Functions: 'x-deno-functions',
|
|
@@ -8,3 +8,5 @@ module.exports = {
|
|
|
8
8
|
IP: 'x-nf-client-connection-ip',
|
|
9
9
|
Site: 'X-NF-Site-Info',
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export default headers
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { readFile, stat } from 'fs/promises'
|
|
3
|
+
import { dirname, join, resolve } from 'path'
|
|
4
|
+
import { cwd } from 'process'
|
|
5
|
+
import { pathToFileURL } from 'url'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { warn } from '../../utils/command-helpers.mjs'
|
|
8
|
+
import { getPathInProject } from '../settings.cjs'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.mjs'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Reads an import map from a path and returns the parsed data, if it exists
|
|
@@ -18,7 +18,7 @@ const { INTERNAL_EDGE_FUNCTIONS_FOLDER } = require('./consts.cjs')
|
|
|
18
18
|
*/
|
|
19
19
|
const getImportMap = async (importMapPath) => {
|
|
20
20
|
try {
|
|
21
|
-
const data = await
|
|
21
|
+
const data = await readFile(importMapPath)
|
|
22
22
|
const importMap = JSON.parse(data)
|
|
23
23
|
|
|
24
24
|
return importMap
|
|
@@ -29,19 +29,25 @@ const getImportMap = async (importMapPath) => {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const getInternalFunctions = async () => {
|
|
33
|
-
const
|
|
32
|
+
export const getInternalFunctions = async () => {
|
|
33
|
+
const path = join(cwd(), getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER]))
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
const stats = await
|
|
36
|
+
const stats = await stat(path)
|
|
37
37
|
|
|
38
38
|
if (!stats.isDirectory()) {
|
|
39
|
-
throw new Error('
|
|
39
|
+
throw new Error('Internal edge functions directory expected')
|
|
40
40
|
}
|
|
41
|
+
} catch {
|
|
42
|
+
return {
|
|
43
|
+
functions: [],
|
|
44
|
+
path: null,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const manifest =
|
|
48
|
+
try {
|
|
49
|
+
const manifestPath = join(path, 'manifest.json')
|
|
50
|
+
const manifest = JSON.parse(await readFile(manifestPath))
|
|
45
51
|
|
|
46
52
|
if (manifest.version !== 1) {
|
|
47
53
|
throw new Error('Unsupported manifest format')
|
|
@@ -49,11 +55,11 @@ const getInternalFunctions = async () => {
|
|
|
49
55
|
|
|
50
56
|
const data = {
|
|
51
57
|
functions: manifest.functions,
|
|
52
|
-
path
|
|
58
|
+
path,
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
if (manifest.import_map) {
|
|
56
|
-
const importMapPath =
|
|
62
|
+
const importMapPath = resolve(dirname(manifestPath), manifest.import_map)
|
|
57
63
|
const importMap = await getImportMap(importMapPath)
|
|
58
64
|
|
|
59
65
|
if (importMap !== null) {
|
|
@@ -71,9 +77,7 @@ const getInternalFunctions = async () => {
|
|
|
71
77
|
} catch {
|
|
72
78
|
return {
|
|
73
79
|
functions: [],
|
|
74
|
-
path
|
|
80
|
+
path,
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
|
-
|
|
79
|
-
module.exports = { getInternalFunctions }
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { Buffer } from 'buffer'
|
|
3
|
+
import { relative } from 'path'
|
|
4
|
+
import { cwd, env } from 'process'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import getAvailablePort from 'get-port'
|
|
7
|
+
import { v4 as generateUUID } from 'uuid'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
|
|
10
|
+
import { getGeoLocation } from '../geo-location.mjs'
|
|
11
|
+
import { getPathInProject } from '../settings.cjs'
|
|
12
|
+
import { startSpinner, stopSpinner } from '../spinner.cjs'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import { DIST_IMPORT_MAP_PATH } from './consts.mjs'
|
|
15
|
+
import headers from './headers.mjs'
|
|
16
|
+
import { getInternalFunctions } from './internal.mjs'
|
|
17
|
+
import { EdgeFunctionsRegistry } from './registry.mjs'
|
|
18
18
|
|
|
19
19
|
const headersSymbol = Symbol('Edge Functions Headers')
|
|
20
20
|
|
|
@@ -40,20 +40,20 @@ const getDownloadUpdateFunctions = () => {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const handleProxyRequest = (req, proxyReq) => {
|
|
43
|
+
export const handleProxyRequest = (req, proxyReq) => {
|
|
44
44
|
Object.entries(req[headersSymbol]).forEach(([header, value]) => {
|
|
45
45
|
proxyReq.setHeader(header, value)
|
|
46
46
|
})
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const createSiteInfoHeader = (siteInfo = {}) => {
|
|
49
|
+
export const createSiteInfoHeader = (siteInfo = {}) => {
|
|
50
50
|
const { id, name, url } = siteInfo
|
|
51
51
|
const site = { id, name, url }
|
|
52
52
|
const siteString = JSON.stringify(site)
|
|
53
53
|
return Buffer.from(siteString).toString('base64')
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const initializeProxy = async ({
|
|
56
|
+
export const initializeProxy = async ({
|
|
57
57
|
config,
|
|
58
58
|
configPath,
|
|
59
59
|
env: configEnv,
|
|
@@ -88,7 +88,7 @@ const initializeProxy = async ({
|
|
|
88
88
|
port: isolatePort,
|
|
89
89
|
projectDir,
|
|
90
90
|
})
|
|
91
|
-
const hasEdgeFunctions = userFunctionsPath !== undefined ||
|
|
91
|
+
const hasEdgeFunctions = userFunctionsPath !== undefined || internalFunctionsPath
|
|
92
92
|
|
|
93
93
|
return async (req) => {
|
|
94
94
|
if (req.headers[headers.Passthrough] !== undefined || !hasEdgeFunctions) {
|
|
@@ -145,7 +145,7 @@ const initializeProxy = async ({
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const isEdgeFunctionsRequest = (req) => req[headersSymbol] !== undefined
|
|
148
|
+
export const isEdgeFunctionsRequest = (req) => req[headersSymbol] !== undefined
|
|
149
149
|
|
|
150
150
|
const prepareServer = async ({
|
|
151
151
|
certificatePath,
|
|
@@ -195,5 +195,3 @@ const prepareServer = async ({
|
|
|
195
195
|
printError(error.message, { exit: false })
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
|
|
199
|
-
module.exports = { handleProxyRequest, initializeProxy, isEdgeFunctionsRequest, createSiteInfoHeader }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } from '../../utils/command-helpers.mjs'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @typedef EdgeFunction
|
|
@@ -11,13 +11,22 @@ const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } = requi
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @typedef
|
|
14
|
+
* @typedef EdgeFunctionDeclarationWithPath
|
|
15
15
|
* @type {object}
|
|
16
16
|
* @property {string} function
|
|
17
17
|
* @property {string} path
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @typedef EdgeFunctionDeclarationWithPattern
|
|
22
|
+
* @type {object}
|
|
23
|
+
* @property {string} function
|
|
24
|
+
* @property {RegExp} pattern
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** @typedef {(EdgeFunctionDeclarationWithPath | EdgeFunctionDeclarationWithPattern) } EdgeFunctionDeclaration */
|
|
28
|
+
|
|
29
|
+
export class EdgeFunctionsRegistry {
|
|
21
30
|
/**
|
|
22
31
|
* @param {Object} opts
|
|
23
32
|
* @param {import('@netlify/edge-bundler')} opts.bundler
|
|
@@ -341,7 +350,9 @@ class EdgeFunctionsRegistry {
|
|
|
341
350
|
}
|
|
342
351
|
})
|
|
343
352
|
|
|
344
|
-
|
|
353
|
+
const filteredDeclarations = declarations.filter((declaration) => 'path' in declaration || 'pattern' in declaration)
|
|
354
|
+
|
|
355
|
+
return filteredDeclarations
|
|
345
356
|
}
|
|
346
357
|
|
|
347
358
|
processGraph(graph) {
|
|
@@ -437,5 +448,3 @@ class EdgeFunctionsRegistry {
|
|
|
437
448
|
this.directoryWatchers.set(directory, watcher)
|
|
438
449
|
}
|
|
439
450
|
}
|
|
440
|
-
|
|
441
|
-
module.exports = { EdgeFunctionsRegistry }
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import process from 'process'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { fetchLatest, fetchVersion, newerVersion, updateAvailable } from 'gh-release-fetch'
|
|
6
|
+
import isExe from 'isexe'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import { NETLIFYDEVWARN, error, getTerminalLink, log } from '../utils/command-helpers.mjs'
|
|
9
|
+
import execa from '../utils/execa.mjs'
|
|
10
10
|
|
|
11
11
|
const isWindows = () => process.platform === 'win32'
|
|
12
12
|
|
|
13
13
|
const getRepository = ({ packageName }) => `netlify/${packageName}`
|
|
14
14
|
|
|
15
|
-
const getExecName = ({ execName }) => (isWindows() ? `${execName}.exe` : execName)
|
|
15
|
+
export const getExecName = ({ execName }) => (isWindows() ? `${execName}.exe` : execName)
|
|
16
16
|
|
|
17
17
|
const getOptions = () => {
|
|
18
18
|
// this is used in out CI tests to avoid hitting GitHub API limit
|
|
@@ -33,7 +33,14 @@ const isVersionOutdated = async ({ currentVersion, latestVersion, packageName })
|
|
|
33
33
|
return outdated
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const shouldFetchLatestVersion = async ({
|
|
36
|
+
export const shouldFetchLatestVersion = async ({
|
|
37
|
+
binPath,
|
|
38
|
+
execArgs,
|
|
39
|
+
execName,
|
|
40
|
+
latestVersion,
|
|
41
|
+
packageName,
|
|
42
|
+
pattern,
|
|
43
|
+
}) => {
|
|
37
44
|
const execPath = path.join(binPath, getExecName({ execName }))
|
|
38
45
|
|
|
39
46
|
const exists = await isExe(execPath, { ignoreErrors: true })
|
|
@@ -69,7 +76,7 @@ const shouldFetchLatestVersion = async ({ binPath, execArgs, execName, latestVer
|
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
|
72
|
-
const getArch = () => {
|
|
79
|
+
export const getArch = () => {
|
|
73
80
|
switch (process.arch) {
|
|
74
81
|
case 'x64':
|
|
75
82
|
return 'amd64'
|
|
@@ -91,7 +98,7 @@ const getArch = () => {
|
|
|
91
98
|
* @param {string} config.packageName
|
|
92
99
|
* @param {string} [config.latestVersion ]
|
|
93
100
|
*/
|
|
94
|
-
const fetchLatestVersion = async ({ destination, execName, extension, latestVersion, packageName }) => {
|
|
101
|
+
export const fetchLatestVersion = async ({ destination, execName, extension, latestVersion, packageName }) => {
|
|
95
102
|
const win = isWindows()
|
|
96
103
|
const arch = getArch()
|
|
97
104
|
const platform = win ? 'windows' : process.platform
|
|
@@ -133,5 +140,3 @@ ${issueLink}`)
|
|
|
133
140
|
error(error_)
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
|
-
|
|
137
|
-
module.exports = { getArch, getExecName, shouldFetchLatestVersion, fetchLatestVersion }
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { NETLIFYDEVERR, NETLIFYDEVLOG } from '../../utils/command-helpers.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { formatLambdaError, styleFunctionName } from './utils.mjs'
|
|
4
4
|
|
|
5
5
|
const BACKGROUND_FUNCTION_STATUS_CODE = 202
|
|
6
6
|
|
|
7
|
-
const handleBackgroundFunction = (functionName, response) => {
|
|
7
|
+
export const handleBackgroundFunction = (functionName, response) => {
|
|
8
8
|
console.log(`${NETLIFYDEVLOG} Queueing background function ${styleFunctionName(functionName)} for execution`)
|
|
9
9
|
response.status(BACKGROUND_FUNCTION_STATUS_CODE)
|
|
10
10
|
response.end()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const handleBackgroundFunctionResult = (functionName, err) => {
|
|
13
|
+
export const handleBackgroundFunctionResult = (functionName, err) => {
|
|
14
14
|
if (err) {
|
|
15
15
|
console.log(
|
|
16
16
|
`${NETLIFYDEVERR} Error during background function ${styleFunctionName(functionName)} execution:`,
|
|
@@ -20,5 +20,3 @@ const handleBackgroundFunctionResult = (functionName, err) => {
|
|
|
20
20
|
console.log(`${NETLIFYDEVLOG} Done executing background function ${styleFunctionName(functionName)}`)
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
module.exports = { handleBackgroundFunction, handleBackgroundFunctionResult }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The function configuration keys returned by @netlify/config are not an exact
|
|
2
2
|
// match to the properties that @netlify/zip-it-and-ship-it expects. We do that
|
|
3
3
|
// translation here.
|
|
4
|
-
const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv = {} }) =>
|
|
4
|
+
export const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv = {} }) =>
|
|
5
5
|
Object.entries(functionsConfig).reduce(
|
|
6
6
|
(result, [pattern, config]) => ({
|
|
7
7
|
...result,
|
|
@@ -19,5 +19,3 @@ const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv =
|
|
|
19
19
|
}),
|
|
20
20
|
{},
|
|
21
21
|
)
|
|
22
|
-
|
|
23
|
-
module.exports = { normalizeFunctionsConfig }
|
|
@@ -5,9 +5,9 @@ import { parse as parseContentType } from 'content-type'
|
|
|
5
5
|
import multiparty from 'multiparty'
|
|
6
6
|
import getRawBody from 'raw-body'
|
|
7
7
|
|
|
8
|
-
import { warn } from '../../utils/command-helpers.
|
|
8
|
+
import { warn } from '../../utils/command-helpers.mjs'
|
|
9
9
|
import { BACKGROUND } from '../../utils/functions/index.mjs'
|
|
10
|
-
import { capitalize } from '../string.
|
|
10
|
+
import { capitalize } from '../string.mjs'
|
|
11
11
|
|
|
12
12
|
const getFormHandler = function ({ functionsRegistry }) {
|
|
13
13
|
const handlers = ['submission-created', `submission-created${BACKGROUND}`]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
2
|
+
import { stdout } from 'process'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import execa from '../../utils/execa.mjs'
|
|
7
7
|
|
|
8
|
-
const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
|
|
8
|
+
export const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
|
|
9
9
|
const functionsProxyPath = getFunctionsProxyPath()
|
|
10
10
|
const requestData = {
|
|
11
11
|
resource: '',
|
|
@@ -43,5 +43,3 @@ const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeou
|
|
|
43
43
|
|
|
44
44
|
return proxyProcess
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
module.exports = { runFunctionsProxy }
|