netlify-cli 15.8.1 → 15.9.1-rc.0
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 +512 -414
- package/package.json +9 -10
- package/scripts/postinstall.mjs +8 -8
- package/src/commands/base-command.mjs +195 -59
- package/src/commands/deploy/deploy.mjs +21 -9
- package/src/commands/dev/dev.mjs +24 -16
- package/src/commands/functions/functions-build.mjs +2 -2
- package/src/commands/functions/functions-create.mjs +0 -3
- package/src/commands/functions/functions-invoke.mjs +8 -5
- package/src/commands/functions/functions-serve.mjs +2 -1
- package/src/commands/init/init.mjs +1 -1
- package/src/commands/link/link.mjs +5 -5
- package/src/commands/main.mjs +1 -1
- package/src/commands/serve/serve.mjs +14 -6
- package/src/commands/sites/sites-create-template.mjs +1 -1
- package/src/commands/sites/sites-create.mjs +1 -1
- package/src/functions-templates/javascript/auth-fetch/package-lock.json +6 -6
- package/src/functions-templates/javascript/google-analytics/package-lock.json +6 -6
- package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
- package/src/functions-templates/typescript/transform-response/{{name}}.ts +0 -1
- package/src/lib/completion/generate-autocompletion.mjs +4 -4
- package/src/lib/edge-functions/bootstrap.mjs +1 -1
- package/src/lib/edge-functions/headers.mjs +1 -0
- package/src/lib/edge-functions/internal.mjs +5 -3
- package/src/lib/edge-functions/proxy.mjs +39 -5
- package/src/lib/edge-functions/registry.mjs +11 -9
- package/src/lib/functions/registry.mjs +1 -3
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +3 -8
- package/src/lib/functions/server.mjs +7 -6
- package/src/lib/spinner.mjs +1 -1
- package/src/recipes/vscode/index.mjs +1 -1
- package/src/utils/build-info.mjs +19 -0
- package/src/utils/command-helpers.mjs +16 -7
- package/src/utils/deploy/hash-fns.mjs +1 -2
- package/src/utils/detect-server-settings.mjs +148 -200
- package/src/utils/dev.mjs +1 -0
- package/src/utils/execa.mjs +4 -2
- package/src/utils/framework-server.mjs +2 -2
- package/src/utils/functions/functions.mjs +7 -0
- package/src/utils/functions/get-functions.mjs +2 -2
- package/src/utils/get-repo-data.mjs +5 -6
- package/src/utils/init/config-github.mjs +2 -2
- package/src/utils/init/config-manual.mjs +24 -7
- package/src/utils/init/utils.mjs +62 -63
- package/src/utils/proxy-server.mjs +9 -4
- package/src/utils/proxy.mjs +6 -0
- package/src/utils/run-build.mjs +58 -7
- package/src/utils/shell.mjs +14 -3
- package/src/utils/state-config.mjs +5 -1
- package/src/utils/static-server.mjs +4 -0
- package/src/utils/telemetry/report-error.mjs +8 -4
- package/src/utils/init/frameworks.mjs +0 -23
package/src/commands/dev/dev.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import { printBanner } from '../../utils/banner.mjs'
|
|
|
9
9
|
import {
|
|
10
10
|
BANG,
|
|
11
11
|
chalk,
|
|
12
|
-
exit,
|
|
13
12
|
log,
|
|
14
13
|
NETLIFYDEV,
|
|
15
14
|
NETLIFYDEVERR,
|
|
@@ -35,7 +34,7 @@ import { createDevExecCommand } from './dev-exec.mjs'
|
|
|
35
34
|
* @param {object} config
|
|
36
35
|
* @param {*} config.api
|
|
37
36
|
* @param {import('commander').OptionValues} config.options
|
|
38
|
-
* @param {
|
|
37
|
+
* @param {import('../../utils/types.js').ServerSettings} config.settings
|
|
39
38
|
* @param {*} config.site
|
|
40
39
|
* @param {*} config.state
|
|
41
40
|
* @returns
|
|
@@ -68,6 +67,9 @@ const handleLiveTunnel = async ({ api, options, settings, site, state }) => {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} args
|
|
72
|
+
*/
|
|
71
73
|
const validateShortFlagArgs = (args) => {
|
|
72
74
|
if (args.startsWith('=')) {
|
|
73
75
|
throw new Error(
|
|
@@ -94,9 +96,10 @@ const dev = async (options, command) => {
|
|
|
94
96
|
const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify
|
|
95
97
|
config.dev = { ...config.dev }
|
|
96
98
|
config.build = { ...config.build }
|
|
97
|
-
/** @type {import('./types').DevConfig} */
|
|
99
|
+
/** @type {import('./types.js').DevConfig} */
|
|
98
100
|
const devConfig = {
|
|
99
101
|
framework: '#auto',
|
|
102
|
+
autoLaunch: Boolean(options.open),
|
|
100
103
|
...(config.functionsDirectory && { functions: config.functionsDirectory }),
|
|
101
104
|
...(config.build.publish && { publish: config.build.publish }),
|
|
102
105
|
...config.dev,
|
|
@@ -116,7 +119,7 @@ const dev = async (options, command) => {
|
|
|
116
119
|
injectEnvVariables(env)
|
|
117
120
|
await promptEditorHelper({ chalk, config, log, NETLIFYDEVLOG, repositoryRoot, state })
|
|
118
121
|
|
|
119
|
-
const { addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
122
|
+
const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
120
123
|
// inherited from base command --offline
|
|
121
124
|
offline: options.offline,
|
|
122
125
|
api,
|
|
@@ -124,20 +127,17 @@ const dev = async (options, command) => {
|
|
|
124
127
|
siteInfo,
|
|
125
128
|
})
|
|
126
129
|
|
|
127
|
-
/** @type {
|
|
128
|
-
let settings
|
|
130
|
+
/** @type {import('../../utils/types.js').ServerSettings} */
|
|
131
|
+
let settings
|
|
129
132
|
try {
|
|
130
|
-
settings = await detectServerSettings(devConfig, options,
|
|
131
|
-
site: {
|
|
132
|
-
id: site.id,
|
|
133
|
-
url: siteUrl,
|
|
134
|
-
},
|
|
135
|
-
})
|
|
133
|
+
settings = await detectServerSettings(devConfig, options, command)
|
|
136
134
|
|
|
137
135
|
cachedConfig.config = getConfigWithPlugins(cachedConfig.config, settings)
|
|
138
136
|
} catch (error_) {
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
if (error_ && typeof error_ === 'object' && 'message' in error_) {
|
|
138
|
+
log(NETLIFYDEVERR, error_.message)
|
|
139
|
+
}
|
|
140
|
+
process.exit(1)
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
command.setAnalyticsPayload({ live: options.live })
|
|
@@ -154,6 +154,7 @@ const dev = async (options, command) => {
|
|
|
154
154
|
cachedConfig,
|
|
155
155
|
options,
|
|
156
156
|
settings,
|
|
157
|
+
projectDir: command.workingDir,
|
|
157
158
|
site,
|
|
158
159
|
env: {
|
|
159
160
|
URL: url,
|
|
@@ -176,6 +177,7 @@ const dev = async (options, command) => {
|
|
|
176
177
|
geoCountry: options.country,
|
|
177
178
|
offline: options.offline,
|
|
178
179
|
state,
|
|
180
|
+
accountId,
|
|
179
181
|
})
|
|
180
182
|
|
|
181
183
|
// Try to add `.netlify` to `.gitignore`.
|
|
@@ -187,8 +189,11 @@ const dev = async (options, command) => {
|
|
|
187
189
|
|
|
188
190
|
// TODO: We should consolidate this with the existing config watcher.
|
|
189
191
|
const getUpdatedConfig = async () => {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
+
const { config: newConfig } = await command.getConfig({
|
|
193
|
+
cwd: command.workingDir,
|
|
194
|
+
offline: true,
|
|
195
|
+
state,
|
|
196
|
+
})
|
|
192
197
|
const normalizedNewConfig = normalizeConfig(newConfig)
|
|
193
198
|
|
|
194
199
|
return normalizedNewConfig
|
|
@@ -201,6 +206,7 @@ const dev = async (options, command) => {
|
|
|
201
206
|
config,
|
|
202
207
|
configPath: configPathOverride,
|
|
203
208
|
debug: options.debug,
|
|
209
|
+
projectDir: command.workingDir,
|
|
204
210
|
env,
|
|
205
211
|
getUpdatedConfig,
|
|
206
212
|
inspectSettings,
|
|
@@ -211,6 +217,7 @@ const dev = async (options, command) => {
|
|
|
211
217
|
state,
|
|
212
218
|
geolocationMode: options.geo,
|
|
213
219
|
geoCountry: options.country,
|
|
220
|
+
accountId,
|
|
214
221
|
})
|
|
215
222
|
|
|
216
223
|
if (devConfig.autoLaunch !== false) {
|
|
@@ -246,6 +253,7 @@ export const createDevCommand = (program) => {
|
|
|
246
253
|
.argParser((value) => Number.parseInt(value))
|
|
247
254
|
.hideHelp(true),
|
|
248
255
|
)
|
|
256
|
+
.addOption(new Option('--no-open', 'disables the automatic opening of a browser window'))
|
|
249
257
|
.option('--target-port <port>', 'port of target app server', (value) => Number.parseInt(value))
|
|
250
258
|
.option('--framework <name>', 'framework to use. Defaults to #auto which automatically detects a framework')
|
|
251
259
|
.option('-d ,--dir <path>', 'dir with static files')
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { mkdir } from 'fs/promises'
|
|
3
3
|
|
|
4
|
+
import { zipFunctions } from '@netlify/zip-it-and-ship-it'
|
|
5
|
+
|
|
4
6
|
import { NETLIFYDEVERR, NETLIFYDEVLOG, exit, log } from '../../utils/command-helpers.mjs'
|
|
5
7
|
import { getFunctionsDir } from '../../utils/functions/index.mjs'
|
|
6
8
|
|
|
@@ -36,8 +38,6 @@ const functionsBuild = async (options, command) => {
|
|
|
36
38
|
|
|
37
39
|
log(`${NETLIFYDEVLOG} Building functions`)
|
|
38
40
|
|
|
39
|
-
const { zipFunctions } = await import('@netlify/zip-it-and-ship-it')
|
|
40
|
-
|
|
41
41
|
zipFunctions(src, dst, { skipGo: true })
|
|
42
42
|
log(`${NETLIFYDEVLOG} Functions built to `, dst)
|
|
43
43
|
}
|
|
@@ -12,7 +12,6 @@ import copyTemplateDirOriginal from 'copy-template-dir'
|
|
|
12
12
|
import { findUp } from 'find-up'
|
|
13
13
|
import fuzzy from 'fuzzy'
|
|
14
14
|
import inquirer from 'inquirer'
|
|
15
|
-
import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt'
|
|
16
15
|
import fetch from 'node-fetch'
|
|
17
16
|
import ora from 'ora'
|
|
18
17
|
|
|
@@ -172,8 +171,6 @@ const pickTemplate = async function ({ language: languageFromFlag }, funcType) {
|
|
|
172
171
|
language = languageFromPrompt
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
inquirer.registerPrompt('autocomplete', inquirerAutocompletePrompt)
|
|
176
|
-
|
|
177
174
|
let templatesForLanguage
|
|
178
175
|
|
|
179
176
|
try {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import { createRequire } from 'module'
|
|
4
4
|
import path from 'path'
|
|
5
|
-
import process from 'process'
|
|
6
5
|
|
|
7
6
|
import inquirer from 'inquirer'
|
|
8
7
|
import fetch from 'node-fetch'
|
|
@@ -56,14 +55,18 @@ const formatQstring = function (querystring) {
|
|
|
56
55
|
return ''
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
58
|
+
/**
|
|
59
|
+
* process payloads from flag
|
|
60
|
+
* @param {string} payloadString
|
|
61
|
+
* @param {string} workingDir
|
|
62
|
+
*/
|
|
63
|
+
const processPayloadFromFlag = function (payloadString, workingDir) {
|
|
61
64
|
if (payloadString) {
|
|
62
65
|
// case 1: jsonstring
|
|
63
66
|
let payload = tryParseJSON(payloadString)
|
|
64
67
|
if (payload) return payload
|
|
65
68
|
// case 2: jsonpath
|
|
66
|
-
const payloadpath = path.join(
|
|
69
|
+
const payloadpath = path.join(workingDir, payloadString)
|
|
67
70
|
const pathexists = fs.existsSync(payloadpath)
|
|
68
71
|
if (pathexists) {
|
|
69
72
|
try {
|
|
@@ -210,7 +213,7 @@ const functionsInvoke = async (nameArgument, options, command) => {
|
|
|
210
213
|
// }
|
|
211
214
|
}
|
|
212
215
|
}
|
|
213
|
-
const payload = processPayloadFromFlag(options.payload)
|
|
216
|
+
const payload = processPayloadFromFlag(options.payload, command.workingDir)
|
|
214
217
|
body = { ...body, ...payload }
|
|
215
218
|
|
|
216
219
|
try {
|
|
@@ -23,7 +23,7 @@ const functionsServe = async (options, command) => {
|
|
|
23
23
|
env = await getDotEnvVariables({ devConfig: { ...config.dev }, env, site })
|
|
24
24
|
injectEnvVariables(env)
|
|
25
25
|
|
|
26
|
-
const { capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
26
|
+
const { accountId, capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
27
27
|
offline: options.offline,
|
|
28
28
|
api,
|
|
29
29
|
site,
|
|
@@ -52,6 +52,7 @@ const functionsServe = async (options, command) => {
|
|
|
52
52
|
geoCountry: options.country,
|
|
53
53
|
offline: options.offline,
|
|
54
54
|
state,
|
|
55
|
+
accountId,
|
|
55
56
|
})
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -196,7 +196,7 @@ export const init = async (options, command) => {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
// Look for local repo
|
|
199
|
-
const repoData = await getRepoData({ remoteName: options.gitRemoteName })
|
|
199
|
+
const repoData = await getRepoData({ workingDir: command.workingDir, remoteName: options.gitRemoteName })
|
|
200
200
|
if (repoData.error) {
|
|
201
201
|
await handleNoGitRemoteAndExit({ command, error: repoData.error, state })
|
|
202
202
|
}
|
|
@@ -11,11 +11,11 @@ import { track } from '../../utils/telemetry/index.mjs'
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
*
|
|
14
|
-
* @param {import('../base-command.mjs').
|
|
14
|
+
* @param {import('../base-command.mjs').default} command
|
|
15
15
|
* @param {import('commander').OptionValues} options
|
|
16
16
|
*/
|
|
17
|
-
const linkPrompt = async (
|
|
18
|
-
const { api, state } = netlify
|
|
17
|
+
const linkPrompt = async (command, options) => {
|
|
18
|
+
const { api, state } = command.netlify
|
|
19
19
|
|
|
20
20
|
const SITE_NAME_PROMPT = 'Search by full or partial site name'
|
|
21
21
|
const SITE_LIST_PROMPT = 'Choose from a list of your recently updated sites'
|
|
@@ -24,7 +24,7 @@ const linkPrompt = async (netlify, options) => {
|
|
|
24
24
|
let GIT_REMOTE_PROMPT = 'Use the current git remote origin URL'
|
|
25
25
|
let site
|
|
26
26
|
// Get git remote data if exists
|
|
27
|
-
const repoData = await getRepoData({ remoteName: options.gitRemoteName })
|
|
27
|
+
const repoData = await getRepoData({ workingDir: command.workingDir, remoteName: options.gitRemoteName })
|
|
28
28
|
|
|
29
29
|
let linkChoices = [SITE_NAME_PROMPT, SITE_LIST_PROMPT, SITE_ID_PROMPT]
|
|
30
30
|
|
|
@@ -326,7 +326,7 @@ export const link = async (options, command) => {
|
|
|
326
326
|
kind: 'byName',
|
|
327
327
|
})
|
|
328
328
|
} else {
|
|
329
|
-
siteData = await linkPrompt(command
|
|
329
|
+
siteData = await linkPrompt(command, options)
|
|
330
330
|
}
|
|
331
331
|
return siteData
|
|
332
332
|
}
|
package/src/commands/main.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import process from 'process'
|
|
3
3
|
|
|
4
4
|
import { Option } from 'commander'
|
|
5
|
+
import envinfo from 'envinfo'
|
|
5
6
|
import { closest } from 'fastest-levenshtein'
|
|
6
7
|
import inquirer from 'inquirer'
|
|
7
8
|
|
|
@@ -39,7 +40,6 @@ const SUGGESTION_TIMEOUT = 1e4
|
|
|
39
40
|
const getVersionPage = async () => {
|
|
40
41
|
// performance optimization - load envinfo on demand
|
|
41
42
|
|
|
42
|
-
const envinfo = await import('envinfo')
|
|
43
43
|
const data = await envinfo.run({
|
|
44
44
|
System: ['OS', 'CPU'],
|
|
45
45
|
Binaries: ['Node', 'Yarn', 'npm'],
|
|
@@ -56,7 +56,7 @@ const serve = async (options, command) => {
|
|
|
56
56
|
injectEnvVariables(env)
|
|
57
57
|
await promptEditorHelper({ chalk, config, log, NETLIFYDEVLOG, repositoryRoot, state })
|
|
58
58
|
|
|
59
|
-
const { addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
59
|
+
const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
|
|
60
60
|
// inherited from base command --offline
|
|
61
61
|
offline: options.offline,
|
|
62
62
|
api,
|
|
@@ -69,10 +69,10 @@ const serve = async (options, command) => {
|
|
|
69
69
|
// Netlify Build are loaded.
|
|
70
70
|
await getInternalFunctionsDir({ base: site.root, ensureExists: true })
|
|
71
71
|
|
|
72
|
-
/** @type {Partial<import('../../utils/types').ServerSettings>} */
|
|
72
|
+
/** @type {Partial<import('../../utils/types.js').ServerSettings>} */
|
|
73
73
|
let settings = {}
|
|
74
74
|
try {
|
|
75
|
-
settings = await detectServerSettings(devConfig, options,
|
|
75
|
+
settings = await detectServerSettings(devConfig, options, command)
|
|
76
76
|
|
|
77
77
|
cachedConfig.config = getConfigWithPlugins(cachedConfig.config, settings)
|
|
78
78
|
} catch (error_) {
|
|
@@ -87,7 +87,13 @@ const serve = async (options, command) => {
|
|
|
87
87
|
`${NETLIFYDEVWARN} Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again`,
|
|
88
88
|
)
|
|
89
89
|
|
|
90
|
-
const { configPath: configPathOverride } = await runBuildTimeline({
|
|
90
|
+
const { configPath: configPathOverride } = await runBuildTimeline({
|
|
91
|
+
cachedConfig,
|
|
92
|
+
options,
|
|
93
|
+
settings,
|
|
94
|
+
projectDir: command.workingDir,
|
|
95
|
+
site,
|
|
96
|
+
})
|
|
91
97
|
|
|
92
98
|
await startFunctionsServer({
|
|
93
99
|
api,
|
|
@@ -105,6 +111,7 @@ const serve = async (options, command) => {
|
|
|
105
111
|
geoCountry: options.country,
|
|
106
112
|
offline: options.offline,
|
|
107
113
|
state,
|
|
114
|
+
accountId,
|
|
108
115
|
})
|
|
109
116
|
|
|
110
117
|
// Try to add `.netlify` to `.gitignore`.
|
|
@@ -116,8 +123,7 @@ const serve = async (options, command) => {
|
|
|
116
123
|
|
|
117
124
|
// TODO: We should consolidate this with the existing config watcher.
|
|
118
125
|
const getUpdatedConfig = async () => {
|
|
119
|
-
const
|
|
120
|
-
const { config: newConfig } = await command.getConfig({ cwd, offline: true, state })
|
|
126
|
+
const { config: newConfig } = await command.getConfig({ cwd: command.workingDir, offline: true, state })
|
|
121
127
|
const normalizedNewConfig = normalizeConfig(newConfig)
|
|
122
128
|
|
|
123
129
|
return normalizedNewConfig
|
|
@@ -134,10 +140,12 @@ const serve = async (options, command) => {
|
|
|
134
140
|
getUpdatedConfig,
|
|
135
141
|
inspectSettings,
|
|
136
142
|
offline: options.offline,
|
|
143
|
+
projectDir: command.workingDir,
|
|
137
144
|
settings,
|
|
138
145
|
site,
|
|
139
146
|
siteInfo,
|
|
140
147
|
state,
|
|
148
|
+
accountId,
|
|
141
149
|
})
|
|
142
150
|
|
|
143
151
|
if (devConfig.autoLaunch !== false) {
|
|
@@ -197,7 +197,7 @@ const sitesCreateTemplate = async (repository, options, command) => {
|
|
|
197
197
|
|
|
198
198
|
if (options.withCi) {
|
|
199
199
|
log('Configuring CI')
|
|
200
|
-
const repoData = await getRepoData()
|
|
200
|
+
const repoData = await getRepoData({ workingDir: command.workingDir })
|
|
201
201
|
await configureRepo({ command, siteId: site.id, repoData, manual: options.manual })
|
|
202
202
|
}
|
|
203
203
|
|
|
@@ -102,7 +102,7 @@ export const sitesCreate = async (options, command) => {
|
|
|
102
102
|
|
|
103
103
|
if (options.withCi) {
|
|
104
104
|
log('Configuring CI')
|
|
105
|
-
const repoData = await getRepoData()
|
|
105
|
+
const repoData = await getRepoData({ workingDir: command.workingDir })
|
|
106
106
|
await configureRepo({ command, siteId: site.id, repoData, manual: options.manual })
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"node_modules/node-fetch": {
|
|
16
|
-
"version": "2.6.
|
|
17
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.
|
|
18
|
-
"integrity": "sha512-
|
|
16
|
+
"version": "2.6.12",
|
|
17
|
+
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
18
|
+
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"whatwg-url": "^5.0.0"
|
|
21
21
|
},
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"node-fetch": {
|
|
56
|
-
"version": "2.6.
|
|
57
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.
|
|
58
|
-
"integrity": "sha512-
|
|
56
|
+
"version": "2.6.12",
|
|
57
|
+
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
58
|
+
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
59
59
|
"requires": {
|
|
60
60
|
"whatwg-url": "^5.0.0"
|
|
61
61
|
}
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"node_modules/node-fetch": {
|
|
20
|
-
"version": "2.6.
|
|
21
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.
|
|
22
|
-
"integrity": "sha512-
|
|
20
|
+
"version": "2.6.12",
|
|
21
|
+
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
22
|
+
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"whatwg-url": "^5.0.0"
|
|
25
25
|
},
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"node-fetch": {
|
|
68
|
-
"version": "2.6.
|
|
69
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.
|
|
70
|
-
"integrity": "sha512-
|
|
68
|
+
"version": "2.6.12",
|
|
69
|
+
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
70
|
+
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
71
71
|
"requires": {
|
|
72
72
|
"whatwg-url": "^5.0.0"
|
|
73
73
|
}
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"node_modules/@types/node": {
|
|
29
|
-
"version": "14.18.
|
|
30
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.
|
|
31
|
-
"integrity": "sha512-
|
|
29
|
+
"version": "14.18.53",
|
|
30
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.53.tgz",
|
|
31
|
+
"integrity": "sha512-soGmOpVBUq+gaBMwom1M+krC/NNbWlosh4AtGA03SyWNDiqSKtwp7OulO1M6+mg8YkHMvJ/y0AkCeO8d1hNb7A=="
|
|
32
32
|
},
|
|
33
33
|
"node_modules/is-promise": {
|
|
34
34
|
"version": "4.0.0",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"@types/node": {
|
|
61
|
-
"version": "14.18.
|
|
62
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.
|
|
63
|
-
"integrity": "sha512-
|
|
61
|
+
"version": "14.18.53",
|
|
62
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.53.tgz",
|
|
63
|
+
"integrity": "sha512-soGmOpVBUq+gaBMwom1M+krC/NNbWlosh4AtGA03SyWNDiqSKtwp7OulO1M6+mg8YkHMvJ/y0AkCeO8d1hNb7A=="
|
|
64
64
|
},
|
|
65
65
|
"is-promise": {
|
|
66
66
|
"version": "4.0.0",
|
|
@@ -7,7 +7,6 @@ export default async (request: Request, context: Context) => {
|
|
|
7
7
|
if (url.searchParams.get("method") !== "transform") {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
const response = await context.next();
|
|
12
11
|
const text = await response.text();
|
|
13
12
|
return new Response(text.toUpperCase(), response);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs'
|
|
3
3
|
import { dirname } from 'path'
|
|
4
4
|
|
|
5
5
|
import { sortOptions, warn } from '../../utils/command-helpers.mjs'
|
|
@@ -28,10 +28,10 @@ const generateAutocompletion = (program) => {
|
|
|
28
28
|
{},
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
if (!existsSync(dirname(AUTOCOMPLETION_FILE))) {
|
|
32
|
-
mkdirSync(dirname(AUTOCOMPLETION_FILE), { recursive: true })
|
|
31
|
+
if (!fs.existsSync(dirname(AUTOCOMPLETION_FILE))) {
|
|
32
|
+
fs.mkdirSync(dirname(AUTOCOMPLETION_FILE), { recursive: true })
|
|
33
33
|
}
|
|
34
|
-
writeFileSync(AUTOCOMPLETION_FILE, JSON.stringify(autocomplete), 'utf-8')
|
|
34
|
+
fs.writeFileSync(AUTOCOMPLETION_FILE, JSON.stringify(autocomplete), 'utf-8')
|
|
35
35
|
} catch (error_) {
|
|
36
36
|
// Sometimes it can happen that the autocomplete generation in the postinstall script lacks permissions
|
|
37
37
|
// to write files to the home directory of the user. Therefore just warn with the error and don't break install.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { env } from 'process'
|
|
2
2
|
|
|
3
|
-
const latestBootstrapURL = 'https://
|
|
3
|
+
const latestBootstrapURL = 'https://64ae60d920fd0f000865bcfc--edge.netlify.com/bootstrap/index-combined.ts'
|
|
4
4
|
|
|
5
5
|
export const getBootstrapURL = () => env.NETLIFY_EDGE_BOOTSTRAP || latestBootstrapURL
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { readFile, stat } from 'fs/promises'
|
|
3
3
|
import { dirname, join, resolve } from 'path'
|
|
4
|
-
import { cwd } from 'process'
|
|
5
4
|
|
|
6
5
|
import { getPathInProject } from '../settings.mjs'
|
|
7
6
|
|
|
8
7
|
import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.mjs'
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} workingDir
|
|
11
|
+
*/
|
|
12
|
+
export const getInternalFunctions = async (workingDir) => {
|
|
13
|
+
const path = join(workingDir, getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER]))
|
|
12
14
|
|
|
13
15
|
try {
|
|
14
16
|
const stats = await stat(path)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { Buffer } from 'buffer'
|
|
3
3
|
import { relative } from 'path'
|
|
4
|
-
import {
|
|
4
|
+
import { env } from 'process'
|
|
5
5
|
|
|
6
|
+
// eslint-disable-next-line import/no-namespace
|
|
7
|
+
import * as bundler from '@netlify/edge-bundler'
|
|
6
8
|
import getAvailablePort from 'get-port'
|
|
7
9
|
|
|
8
10
|
import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
|
|
@@ -53,7 +55,35 @@ export const createSiteInfoHeader = (siteInfo = {}) => {
|
|
|
53
55
|
return Buffer.from(siteString).toString('base64')
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
export const createAccountInfoHeader = (accountInfo = {}) => {
|
|
59
|
+
const { id } = accountInfo
|
|
60
|
+
const account = { id }
|
|
61
|
+
const accountString = JSON.stringify(account)
|
|
62
|
+
return Buffer.from(accountString).toString('base64')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {object} config
|
|
68
|
+
* @param {*} config.accountId
|
|
69
|
+
* @param {*} config.config
|
|
70
|
+
* @param {*} config.configPath
|
|
71
|
+
* @param {*} config.debug
|
|
72
|
+
* @param {*} config.env
|
|
73
|
+
* @param {*} config.geoCountry
|
|
74
|
+
* @param {*} config.geolocationMode
|
|
75
|
+
* @param {*} config.getUpdatedConfig
|
|
76
|
+
* @param {*} config.inspectSettings
|
|
77
|
+
* @param {*} config.mainPort
|
|
78
|
+
* @param {boolean=} config.offline
|
|
79
|
+
* @param {*} config.passthroughPort
|
|
80
|
+
* @param {*} config.projectDir
|
|
81
|
+
* @param {*} config.siteInfo
|
|
82
|
+
* @param {*} config.state
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
56
85
|
export const initializeProxy = async ({
|
|
86
|
+
accountId,
|
|
57
87
|
config,
|
|
58
88
|
configPath,
|
|
59
89
|
debug,
|
|
@@ -69,7 +99,11 @@ export const initializeProxy = async ({
|
|
|
69
99
|
siteInfo,
|
|
70
100
|
state,
|
|
71
101
|
}) => {
|
|
72
|
-
const {
|
|
102
|
+
const {
|
|
103
|
+
functions: internalFunctions,
|
|
104
|
+
importMap,
|
|
105
|
+
path: internalFunctionsPath,
|
|
106
|
+
} = await getInternalFunctions(projectDir)
|
|
73
107
|
const userFunctionsPath = config.build.edge_functions
|
|
74
108
|
const isolatePort = await getAvailablePort()
|
|
75
109
|
|
|
@@ -104,8 +138,9 @@ export const initializeProxy = async ({
|
|
|
104
138
|
if (!registry) return
|
|
105
139
|
|
|
106
140
|
// Setting header with geolocation and site info.
|
|
107
|
-
req.headers[headers.Geo] = JSON.stringify(geoLocation)
|
|
141
|
+
req.headers[headers.Geo] = Buffer.from(JSON.stringify(geoLocation)).toString('base64')
|
|
108
142
|
req.headers[headers.Site] = createSiteInfoHeader(siteInfo)
|
|
143
|
+
req.headers[headers.Account] = createAccountInfoHeader({ id: accountId })
|
|
109
144
|
|
|
110
145
|
await registry.initialize()
|
|
111
146
|
|
|
@@ -121,7 +156,7 @@ export const initializeProxy = async ({
|
|
|
121
156
|
)} matches declaration for edge function ${chalk.yellow(
|
|
122
157
|
functionName,
|
|
123
158
|
)}, but there's no matching function file in ${chalk.yellow(
|
|
124
|
-
relative(
|
|
159
|
+
relative(projectDir, userFunctionsPath),
|
|
125
160
|
)}. Please visit ${chalk.blue('https://ntl.fyi/edge-create')} for more information.`,
|
|
126
161
|
)
|
|
127
162
|
})
|
|
@@ -176,7 +211,6 @@ const prepareServer = async ({
|
|
|
176
211
|
const importMapPaths = [...importMaps, config.functions['*'].deno_import_map]
|
|
177
212
|
|
|
178
213
|
try {
|
|
179
|
-
const bundler = await import('@netlify/edge-bundler')
|
|
180
214
|
const distImportMapPath = getPathInProject([DIST_IMPORT_MAP_PATH])
|
|
181
215
|
const runIsolate = await bundler.serve({
|
|
182
216
|
...getDownloadUpdateFunctions(),
|
|
@@ -467,17 +467,19 @@ export class EdgeFunctionsRegistry {
|
|
|
467
467
|
* @param {string} projectDir
|
|
468
468
|
*/
|
|
469
469
|
async #setupWatchers(projectDir) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
470
|
+
if (this.#configPath) {
|
|
471
|
+
// Creating a watcher for the config file. When it changes, we update the
|
|
472
|
+
// declarations and see if we need to register or unregister any functions.
|
|
473
|
+
this.#configWatcher = await watchDebounced(this.#configPath, {
|
|
474
|
+
onChange: async () => {
|
|
475
|
+
const newConfig = await this.#getUpdatedConfig()
|
|
475
476
|
|
|
476
|
-
|
|
477
|
+
this.#declarationsFromTOML = EdgeFunctionsRegistry.#getDeclarationsFromTOML(newConfig)
|
|
477
478
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
await this.#checkForAddedOrDeletedFunctions()
|
|
480
|
+
},
|
|
481
|
+
})
|
|
482
|
+
}
|
|
481
483
|
|
|
482
484
|
// While functions are guaranteed to be inside one of the configured
|
|
483
485
|
// directories, they might be importing files that are located in
|
|
@@ -3,6 +3,7 @@ import { mkdir } from 'fs/promises'
|
|
|
3
3
|
import { extname, isAbsolute, join, resolve } from 'path'
|
|
4
4
|
import { env } from 'process'
|
|
5
5
|
|
|
6
|
+
import { listFunctions } from '@netlify/zip-it-and-ship-it'
|
|
6
7
|
import extractZip from 'extract-zip'
|
|
7
8
|
|
|
8
9
|
import {
|
|
@@ -175,9 +176,6 @@ export class FunctionsRegistry {
|
|
|
175
176
|
// This function is here so we can mock it in tests
|
|
176
177
|
// eslint-disable-next-line class-methods-use-this
|
|
177
178
|
async listFunctions(...args) {
|
|
178
|
-
// Performance optimization: load '@netlify/zip-it-and-ship-it' on demand.
|
|
179
|
-
const { listFunctions } = await import('@netlify/zip-it-and-ship-it')
|
|
180
|
-
|
|
181
179
|
return await listFunctions(...args)
|
|
182
180
|
}
|
|
183
181
|
|