netlify-cli 17.3.1 → 17.4.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.
Files changed (210) hide show
  1. package/README.md +3 -139
  2. package/npm-shrinkwrap.json +82 -82
  3. package/package.json +16 -15
  4. package/src/commands/addons/addons-auth.mjs +27 -30
  5. package/src/commands/addons/addons-config.mjs +145 -154
  6. package/src/commands/addons/addons-create.mjs +94 -108
  7. package/src/commands/addons/addons-delete.mjs +36 -41
  8. package/src/commands/addons/addons-list.mjs +38 -42
  9. package/src/commands/addons/addons.mjs +26 -28
  10. package/src/commands/addons/index.mjs +1 -1
  11. package/src/commands/api/api.mjs +45 -53
  12. package/src/commands/api/index.mjs +1 -1
  13. package/src/commands/base-command.mjs +597 -684
  14. package/src/commands/blobs/blobs-delete.mjs +35 -0
  15. package/src/commands/blobs/blobs-get.mjs +44 -0
  16. package/src/commands/blobs/blobs-list.mjs +48 -0
  17. package/src/commands/blobs/blobs-set.mjs +54 -0
  18. package/src/commands/blobs/blobs.mjs +32 -0
  19. package/src/commands/blobs/index.mjs +1 -0
  20. package/src/commands/build/build.mjs +55 -67
  21. package/src/commands/build/index.mjs +1 -1
  22. package/src/commands/completion/completion.mjs +41 -46
  23. package/src/commands/completion/index.mjs +1 -1
  24. package/src/commands/deploy/deploy.mjs +675 -710
  25. package/src/commands/deploy/index.mjs +1 -1
  26. package/src/commands/dev/dev-exec.mjs +20 -32
  27. package/src/commands/dev/dev.mjs +217 -302
  28. package/src/commands/dev/index.mjs +1 -1
  29. package/src/commands/dev/types.d.ts +30 -0
  30. package/src/commands/env/env-clone.mjs +157 -184
  31. package/src/commands/env/env-get.mjs +49 -68
  32. package/src/commands/env/env-import.mjs +100 -119
  33. package/src/commands/env/env-list.mjs +104 -129
  34. package/src/commands/env/env-set.mjs +160 -185
  35. package/src/commands/env/env-unset.mjs +104 -122
  36. package/src/commands/env/env.mjs +28 -30
  37. package/src/commands/env/index.mjs +1 -1
  38. package/src/commands/functions/functions-build.mjs +29 -41
  39. package/src/commands/functions/functions-create.mjs +533 -601
  40. package/src/commands/functions/functions-invoke.mjs +193 -216
  41. package/src/commands/functions/functions-list.mjs +45 -55
  42. package/src/commands/functions/functions-serve.mjs +51 -61
  43. package/src/commands/functions/functions.mjs +26 -32
  44. package/src/commands/functions/index.mjs +1 -1
  45. package/src/commands/index.mjs +2 -2
  46. package/src/commands/init/index.mjs +1 -1
  47. package/src/commands/init/init.mjs +138 -167
  48. package/src/commands/integration/deploy.mjs +337 -399
  49. package/src/commands/integration/index.mjs +12 -13
  50. package/src/commands/link/index.mjs +1 -1
  51. package/src/commands/link/link.mjs +298 -317
  52. package/src/commands/lm/index.mjs +1 -1
  53. package/src/commands/lm/lm-info.mjs +23 -31
  54. package/src/commands/lm/lm-install.mjs +13 -17
  55. package/src/commands/lm/lm-setup.mjs +80 -84
  56. package/src/commands/lm/lm-uninstall.mjs +7 -12
  57. package/src/commands/lm/lm.mjs +18 -22
  58. package/src/commands/login/index.mjs +1 -1
  59. package/src/commands/login/login.mjs +35 -41
  60. package/src/commands/logout/index.mjs +1 -1
  61. package/src/commands/logout/logout.mjs +25 -31
  62. package/src/commands/main.mjs +166 -201
  63. package/src/commands/open/index.mjs +1 -1
  64. package/src/commands/open/open-admin.mjs +15 -18
  65. package/src/commands/open/open-site.mjs +16 -19
  66. package/src/commands/open/open.mjs +24 -27
  67. package/src/commands/recipes/common.mjs +23 -34
  68. package/src/commands/recipes/index.mjs +1 -1
  69. package/src/commands/recipes/recipes-list.mjs +13 -20
  70. package/src/commands/recipes/recipes.mjs +59 -72
  71. package/src/commands/serve/index.mjs +1 -1
  72. package/src/commands/serve/serve.mjs +142 -189
  73. package/src/commands/sites/index.mjs +2 -2
  74. package/src/commands/sites/sites-create-template.mjs +214 -236
  75. package/src/commands/sites/sites-create.mjs +145 -157
  76. package/src/commands/sites/sites-delete.mjs +75 -81
  77. package/src/commands/sites/sites-list.mjs +63 -66
  78. package/src/commands/sites/sites.mjs +18 -20
  79. package/src/commands/status/index.mjs +1 -1
  80. package/src/commands/status/status-hooks.mjs +32 -34
  81. package/src/commands/status/status.mjs +99 -106
  82. package/src/commands/switch/index.mjs +1 -1
  83. package/src/commands/switch/switch.mjs +32 -37
  84. package/src/commands/types.d.ts +31 -0
  85. package/src/commands/unlink/index.mjs +1 -1
  86. package/src/commands/unlink/unlink.mjs +23 -29
  87. package/src/commands/watch/index.mjs +1 -1
  88. package/src/commands/watch/watch.mjs +91 -105
  89. package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
  90. package/src/lib/account.mjs +4 -5
  91. package/src/lib/api.mjs +22 -20
  92. package/src/lib/blobs/blobs.mjs +36 -45
  93. package/src/lib/build.mjs +82 -85
  94. package/src/lib/completion/constants.mjs +2 -4
  95. package/src/lib/completion/generate-autocompletion.mjs +33 -36
  96. package/src/lib/completion/get-autocompletion.mjs +31 -35
  97. package/src/lib/completion/index.mjs +1 -1
  98. package/src/lib/completion/script.mjs +12 -19
  99. package/src/lib/edge-functions/bootstrap.mjs +3 -5
  100. package/src/lib/edge-functions/consts.mjs +9 -10
  101. package/src/lib/edge-functions/deploy.mjs +28 -34
  102. package/src/lib/edge-functions/editor-helper.mjs +29 -42
  103. package/src/lib/edge-functions/headers.mjs +24 -26
  104. package/src/lib/edge-functions/internal.mjs +38 -44
  105. package/src/lib/edge-functions/proxy.mjs +229 -228
  106. package/src/lib/edge-functions/registry.mjs +473 -574
  107. package/src/lib/exec-fetcher.mjs +115 -122
  108. package/src/lib/fs.mjs +28 -27
  109. package/src/lib/functions/background.mjs +16 -20
  110. package/src/lib/functions/config.mjs +12 -9
  111. package/src/lib/functions/form-submissions-handler.mjs +143 -149
  112. package/src/lib/functions/local-proxy.mjs +40 -44
  113. package/src/lib/functions/memoized-build.mjs +19 -21
  114. package/src/lib/functions/netlify-function.mjs +269 -249
  115. package/src/lib/functions/registry.mjs +509 -568
  116. package/src/lib/functions/runtimes/go/index.mjs +62 -71
  117. package/src/lib/functions/runtimes/index.mjs +8 -15
  118. package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
  119. package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
  120. package/src/lib/functions/runtimes/js/constants.mjs +1 -1
  121. package/src/lib/functions/runtimes/js/index.mjs +92 -109
  122. package/src/lib/functions/runtimes/js/worker.mjs +43 -45
  123. package/src/lib/functions/runtimes/rust/index.mjs +64 -73
  124. package/src/lib/functions/scheduled.mjs +70 -88
  125. package/src/lib/functions/server.mjs +269 -327
  126. package/src/lib/functions/synchronous.mjs +118 -147
  127. package/src/lib/functions/utils.mjs +38 -46
  128. package/src/lib/geo-location.mjs +69 -81
  129. package/src/lib/http-agent.mjs +87 -90
  130. package/src/lib/images/proxy.mjs +97 -89
  131. package/src/lib/log.mjs +6 -9
  132. package/src/lib/path.mjs +2 -1
  133. package/src/lib/render-error-template.mjs +19 -20
  134. package/src/lib/settings.mjs +17 -19
  135. package/src/lib/spinner.mjs +21 -23
  136. package/src/lib/string.mjs +4 -2
  137. package/src/recipes/vscode/index.mjs +69 -85
  138. package/src/recipes/vscode/settings.mjs +53 -58
  139. package/src/utils/addons/compare.mjs +31 -32
  140. package/src/utils/addons/diffs/index.mjs +16 -17
  141. package/src/utils/addons/diffs/options.mjs +99 -101
  142. package/src/utils/addons/prepare.mjs +100 -97
  143. package/src/utils/addons/prompts.mjs +73 -76
  144. package/src/utils/addons/render.mjs +33 -36
  145. package/src/utils/addons/validation.mjs +19 -15
  146. package/src/utils/banner.mjs +11 -16
  147. package/src/utils/build-info.mjs +65 -66
  148. package/src/utils/command-helpers.mjs +185 -199
  149. package/src/utils/create-deferred.mjs +9 -12
  150. package/src/utils/create-stream-promise.mjs +54 -47
  151. package/src/utils/deploy/constants.mjs +9 -11
  152. package/src/utils/deploy/deploy-site.mjs +162 -182
  153. package/src/utils/deploy/hash-config.mjs +21 -21
  154. package/src/utils/deploy/hash-files.mjs +34 -38
  155. package/src/utils/deploy/hash-fns.mjs +149 -154
  156. package/src/utils/deploy/hasher-segments.mjs +58 -52
  157. package/src/utils/deploy/upload-files.mjs +99 -113
  158. package/src/utils/deploy/util.mjs +85 -91
  159. package/src/utils/detect-server-settings.mjs +236 -268
  160. package/src/utils/dev.mjs +163 -178
  161. package/src/utils/dot-env.mjs +37 -42
  162. package/src/utils/env/index.mjs +148 -148
  163. package/src/utils/execa.mjs +9 -13
  164. package/src/utils/feature-flags.mjs +6 -5
  165. package/src/utils/framework-server.mjs +43 -52
  166. package/src/utils/functions/constants.mjs +1 -1
  167. package/src/utils/functions/functions.mjs +30 -40
  168. package/src/utils/functions/get-functions.mjs +28 -29
  169. package/src/utils/functions/index.mjs +3 -3
  170. package/src/utils/get-global-config.mjs +33 -36
  171. package/src/utils/get-package-json.mjs +14 -15
  172. package/src/utils/get-repo-data.mjs +54 -64
  173. package/src/utils/get-site.mjs +14 -14
  174. package/src/utils/gh-auth.mjs +79 -100
  175. package/src/utils/gitignore.mjs +37 -40
  176. package/src/utils/headers.mjs +33 -35
  177. package/src/utils/hooks/requires-site-info.mjs +26 -22
  178. package/src/utils/init/config-github.mjs +207 -219
  179. package/src/utils/init/config-manual.mjs +83 -100
  180. package/src/utils/init/config.mjs +25 -26
  181. package/src/utils/init/node-version.mjs +23 -30
  182. package/src/utils/init/plugins.mjs +12 -8
  183. package/src/utils/init/utils.mjs +152 -172
  184. package/src/utils/live-tunnel.mjs +118 -141
  185. package/src/utils/lm/install.mjs +220 -259
  186. package/src/utils/lm/requirements.mjs +54 -63
  187. package/src/utils/lm/steps.mjs +31 -31
  188. package/src/utils/lm/ui.mjs +13 -20
  189. package/src/utils/open-browser.mjs +31 -32
  190. package/src/utils/parse-raw-flags.mjs +39 -35
  191. package/src/utils/proxy-server.mjs +84 -71
  192. package/src/utils/proxy.mjs +696 -750
  193. package/src/utils/read-repo-url.mjs +48 -47
  194. package/src/utils/redirects.mjs +49 -49
  195. package/src/utils/request-id.mjs +2 -4
  196. package/src/utils/rules-proxy.mjs +96 -100
  197. package/src/utils/run-build.mjs +109 -132
  198. package/src/utils/shell.mjs +99 -106
  199. package/src/utils/sign-redirect.mjs +14 -14
  200. package/src/utils/sites/utils.mjs +48 -55
  201. package/src/utils/state-config.mjs +101 -101
  202. package/src/utils/static-server.mjs +28 -34
  203. package/src/utils/telemetry/index.mjs +2 -2
  204. package/src/utils/telemetry/report-error.mjs +45 -49
  205. package/src/utils/telemetry/request.mjs +36 -43
  206. package/src/utils/telemetry/telemetry.mjs +90 -105
  207. package/src/utils/telemetry/utils.mjs +5 -6
  208. package/src/utils/telemetry/validation.mjs +55 -53
  209. package/src/utils/types.d.ts +46 -0
  210. package/src/utils/validation.mjs +10 -13
@@ -1,113 +1,102 @@
1
- import { mkdir, writeFile } from 'fs/promises'
2
- import { createRequire } from 'module'
3
- import path from 'path'
4
-
5
- import { zipFunction, listFunction } from '@netlify/zip-it-and-ship-it'
6
- import decache from 'decache'
7
- import { readPackageUp } from 'read-pkg-up'
8
- import sourceMapSupport from 'source-map-support'
9
-
10
- import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.mjs'
11
- import { SERVE_FUNCTIONS_FOLDER } from '../../../../../utils/functions/functions.mjs'
12
- import { getPathInProject } from '../../../../settings.mjs'
13
- import { normalizeFunctionsConfig } from '../../../config.mjs'
14
- import { memoizedBuild } from '../../../memoized-build.mjs'
15
-
16
- const require = createRequire(import.meta.url)
17
-
1
+ import { mkdir, writeFile } from 'fs/promises';
2
+ import { createRequire } from 'module';
3
+ import path from 'path';
4
+ import { zipFunction, listFunction } from '@netlify/zip-it-and-ship-it';
5
+ import decache from 'decache';
6
+ import { readPackageUp } from 'read-pkg-up';
7
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'sour... Remove this comment to see the full error message
8
+ import sourceMapSupport from 'source-map-support';
9
+ import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.mjs';
10
+ import { SERVE_FUNCTIONS_FOLDER } from '../../../../../utils/functions/functions.mjs';
11
+ import { getPathInProject } from '../../../../settings.mjs';
12
+ import { normalizeFunctionsConfig } from '../../../config.mjs';
13
+ import { memoizedBuild } from '../../../memoized-build.mjs';
14
+ const require = createRequire(import.meta.url);
15
+ // @ts-expect-error TS(7006) FIXME: Parameter 'config' implicitly has an 'any' type.
18
16
  const addFunctionsConfigDefaults = (config) => ({
19
- ...config,
20
- '*': {
21
- nodeSourcemap: true,
22
- ...config['*'],
23
- },
24
- })
25
-
17
+ ...config,
18
+ '*': {
19
+ nodeSourcemap: true,
20
+ ...config['*'],
21
+ },
22
+ });
26
23
  /**
27
24
  * @param {object} params
28
25
  * @param {import("@netlify/zip-it-and-ship-it/dist/feature_flags.js").FeatureFlags} params.featureFlags
29
26
  */
30
- const buildFunction = async ({
31
- cache,
32
- config,
33
- directory,
34
- featureFlags,
35
- func,
36
- hasTypeModule,
37
- projectRoot,
38
- targetDirectory,
39
- }) => {
40
- const zipOptions = {
41
- archiveFormat: 'none',
42
- basePath: projectRoot,
43
- config,
44
- featureFlags: { ...featureFlags, zisi_functions_api_v2: true },
45
- }
46
- const functionDirectory = path.dirname(func.mainFile)
47
-
48
- // If we have a function at `functions/my-func/index.js` and we pass
49
- // that path to `zipFunction`, it will lack the context of the whole
50
- // functions directory and will infer the name of the function to be
51
- // `index`, not `my-func`. Instead, we need to pass the directory of
52
- // the function. The exception is when the function is a file at the
53
- // root of the functions directory (e.g. `functions/my-func.js`). In
54
- // this case, we use `mainFile` as the function path of `zipFunction`.
55
- const entryPath = functionDirectory === directory ? func.mainFile : functionDirectory
56
- const {
57
- entryFilename,
58
- includedFiles,
59
- inputs,
60
- mainFile,
61
- outputModuleFormat,
62
- path: functionPath,
63
- routes,
64
- runtimeAPIVersion,
65
- schedule,
66
- } = await memoizedBuild({
67
- cache,
68
- cacheKey: `zisi-${entryPath}`,
69
- command: () => zipFunction(entryPath, targetDirectory, zipOptions),
70
- })
71
- const srcFiles = inputs.filter((inputPath) => !inputPath.includes(`${path.sep}node_modules${path.sep}`))
72
- const buildPath = path.join(functionPath, entryFilename)
73
-
74
- // some projects include a package.json with "type=module", forcing Node to interpret every descending file
75
- // as ESM. ZISI outputs CJS, so we emit an overriding directive into the output directory.
76
- if (hasTypeModule) {
77
- await writeFile(
78
- path.join(functionPath, `package.json`),
79
- JSON.stringify({
80
- type: 'commonjs',
81
- }),
82
- )
83
- }
84
-
85
- clearFunctionsCache(targetDirectory)
86
-
87
- return { buildPath, includedFiles, outputModuleFormat, mainFile, routes, runtimeAPIVersion, srcFiles, schedule }
88
- }
89
-
27
+ const buildFunction = async ({
28
+ // @ts-expect-error TS(7031) FIXME: Binding element 'cache' implicitly has an 'any' ty... Remove this comment to see the full error message
29
+ cache,
30
+ // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
31
+ config,
32
+ // @ts-expect-error TS(7031) FIXME: Binding element 'directory' implicitly has an 'any... Remove this comment to see the full error message
33
+ directory,
34
+ // @ts-expect-error TS(7031) FIXME: Binding element 'featureFlags' implicitly has an '... Remove this comment to see the full error message
35
+ featureFlags,
36
+ // @ts-expect-error TS(7031) FIXME: Binding element 'func' implicitly has an 'any' typ... Remove this comment to see the full error message
37
+ func,
38
+ // @ts-expect-error TS(7031) FIXME: Binding element 'hasTypeModule' implicitly has an ... Remove this comment to see the full error message
39
+ hasTypeModule,
40
+ // @ts-expect-error TS(7031) FIXME: Binding element 'projectRoot' implicitly has an 'a... Remove this comment to see the full error message
41
+ projectRoot,
42
+ // @ts-expect-error TS(7031) FIXME: Binding element 'targetDirectory' implicitly has a... Remove this comment to see the full error message
43
+ targetDirectory, }) => {
44
+ const zipOptions = {
45
+ archiveFormat: 'none',
46
+ basePath: projectRoot,
47
+ config,
48
+ featureFlags: { ...featureFlags, zisi_functions_api_v2: true },
49
+ };
50
+ const functionDirectory = path.dirname(func.mainFile);
51
+ // If we have a function at `functions/my-func/index.js` and we pass
52
+ // that path to `zipFunction`, it will lack the context of the whole
53
+ // functions directory and will infer the name of the function to be
54
+ // `index`, not `my-func`. Instead, we need to pass the directory of
55
+ // the function. The exception is when the function is a file at the
56
+ // root of the functions directory (e.g. `functions/my-func.js`). In
57
+ // this case, we use `mainFile` as the function path of `zipFunction`.
58
+ const entryPath = functionDirectory === directory ? func.mainFile : functionDirectory;
59
+ const { entryFilename, includedFiles, inputs, mainFile, outputModuleFormat, path: functionPath, routes, runtimeAPIVersion, schedule, } = await memoizedBuild({
60
+ cache,
61
+ cacheKey: `zisi-${entryPath}`,
62
+ // @ts-expect-error TS(2345) FIXME: Argument of type '{ archiveFormat: string; basePat... Remove this comment to see the full error message
63
+ command: () => zipFunction(entryPath, targetDirectory, zipOptions),
64
+ });
65
+ // @ts-expect-error TS(7006) FIXME: Parameter 'inputPath' implicitly has an 'any' type... Remove this comment to see the full error message
66
+ const srcFiles = inputs.filter((inputPath) => !inputPath.includes(`${path.sep}node_modules${path.sep}`));
67
+ const buildPath = path.join(functionPath, entryFilename);
68
+ // some projects include a package.json with "type=module", forcing Node to interpret every descending file
69
+ // as ESM. ZISI outputs CJS, so we emit an overriding directive into the output directory.
70
+ if (hasTypeModule) {
71
+ await writeFile(path.join(functionPath, `package.json`), JSON.stringify({
72
+ type: 'commonjs',
73
+ }));
74
+ }
75
+ clearFunctionsCache(targetDirectory);
76
+ return { buildPath, includedFiles, outputModuleFormat, mainFile, routes, runtimeAPIVersion, srcFiles, schedule };
77
+ };
90
78
  /**
91
79
  * @param {object} params
92
80
  * @param {unknown} params.config
93
81
  * @param {string} params.mainFile
94
82
  * @param {string} params.projectRoot
95
83
  */
96
- export const parseFunctionForMetadata = async ({ config, mainFile, projectRoot }) =>
97
- await listFunction(mainFile, {
84
+ // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
85
+ export const parseFunctionForMetadata = async ({ config, mainFile, projectRoot }) => await listFunction(mainFile, {
98
86
  config: netlifyConfigToZisiConfig({ config, projectRoot }),
87
+ // @ts-expect-error TS(2322) FIXME: Type '{ zisi_functions_api_v2: true; }' is not ass... Remove this comment to see the full error message
99
88
  featureFlags: { zisi_functions_api_v2: true },
100
89
  parseISC: true,
101
- })
102
-
90
+ });
103
91
  // Clears the cache for any files inside the directory from which functions are
104
92
  // served.
93
+ // @ts-expect-error TS(7006) FIXME: Parameter 'functionsPath' implicitly has an 'any' ... Remove this comment to see the full error message
105
94
  const clearFunctionsCache = (functionsPath) => {
106
- Object.keys(require.cache)
107
- .filter((key) => key.startsWith(functionsPath))
108
- .forEach(decache)
109
- }
110
-
95
+ Object.keys(require.cache)
96
+ .filter((key) => key.startsWith(functionsPath))
97
+ // @ts-expect-error
98
+ .forEach(decache);
99
+ };
111
100
  /**
112
101
  *
113
102
  * @param {object} config
@@ -115,21 +104,19 @@ const clearFunctionsCache = (functionsPath) => {
115
104
  * @param {(msg: string) => void} config.errorExit
116
105
  * @returns
117
106
  */
107
+ // @ts-expect-error TS(7031) FIXME: Binding element 'errorExit' implicitly has an 'any... Remove this comment to see the full error message
118
108
  const getTargetDirectory = async ({ errorExit, projectRoot }) => {
119
- const targetDirectory = path.resolve(projectRoot, getPathInProject([SERVE_FUNCTIONS_FOLDER]))
120
-
121
- try {
122
- await mkdir(targetDirectory, { recursive: true })
123
- } catch {
124
- errorExit(`${NETLIFYDEVERR} Could not create directory: ${targetDirectory}`)
125
- }
126
-
127
- return targetDirectory
128
- }
129
-
130
- const netlifyConfigToZisiConfig = ({ config, projectRoot }) =>
131
- addFunctionsConfigDefaults(normalizeFunctionsConfig({ functionsConfig: config.functions, projectRoot }))
132
-
109
+ const targetDirectory = path.resolve(projectRoot, getPathInProject([SERVE_FUNCTIONS_FOLDER]));
110
+ try {
111
+ await mkdir(targetDirectory, { recursive: true });
112
+ }
113
+ catch {
114
+ errorExit(`${NETLIFYDEVERR} Could not create directory: ${targetDirectory}`);
115
+ }
116
+ return targetDirectory;
117
+ };
118
+ // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
119
+ const netlifyConfigToZisiConfig = ({ config, projectRoot }) => addFunctionsConfigDefaults(normalizeFunctionsConfig({ functionsConfig: config.functions, projectRoot }));
133
120
  /**
134
121
  *
135
122
  * @param {object} param0
@@ -140,54 +127,48 @@ const netlifyConfigToZisiConfig = ({ config, projectRoot }) =>
140
127
  * @param {*} param0.metadata
141
128
  * @param {string} param0.projectRoot
142
129
  */
130
+ // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
143
131
  export default async function handler({ config, directory, errorExit, func, metadata, projectRoot }) {
144
- const functionsConfig = netlifyConfigToZisiConfig({ config, projectRoot })
145
-
146
- const packageJson = await readPackageUp(func.mainFile)
147
- const hasTypeModule = packageJson && packageJson.packageJson.type === 'module'
148
-
149
- /** @type {import("@netlify/zip-it-and-ship-it/dist/feature_flags.js").FeatureFlags} */
150
- const featureFlags = {}
151
-
152
- if (metadata.runtimeAPIVersion === 2) {
153
- featureFlags.zisi_pure_esm = true
154
- featureFlags.zisi_pure_esm_mjs = true
155
- } else {
156
- // We must use esbuild for certain file extensions.
157
- const mustTranspile = ['.mjs', '.ts', '.mts', '.cts'].includes(path.extname(func.mainFile))
158
- const mustUseEsbuild = hasTypeModule || mustTranspile
159
-
160
- if (mustUseEsbuild && !functionsConfig['*'].nodeBundler) {
161
- functionsConfig['*'].nodeBundler = 'esbuild'
132
+ const functionsConfig = netlifyConfigToZisiConfig({ config, projectRoot });
133
+ const packageJson = await readPackageUp(func.mainFile);
134
+ const hasTypeModule = packageJson && packageJson.packageJson.type === 'module';
135
+ /** @type {import("@netlify/zip-it-and-ship-it/dist/feature_flags.js").FeatureFlags} */
136
+ const featureFlags = {};
137
+ if (metadata.runtimeAPIVersion === 2) {
138
+ // @ts-expect-error TS(2339) FIXME: Property 'zisi_pure_esm' does not exist on type '{... Remove this comment to see the full error message
139
+ featureFlags.zisi_pure_esm = true;
140
+ // @ts-expect-error TS(2339) FIXME: Property 'zisi_pure_esm_mjs' does not exist on typ... Remove this comment to see the full error message
141
+ featureFlags.zisi_pure_esm_mjs = true;
162
142
  }
163
-
164
- // TODO: Resolve functions config globs so that we can check for the bundler
165
- // on a per-function basis.
166
- const isUsingEsbuild = ['esbuild_zisi', 'esbuild'].includes(functionsConfig['*'].nodeBundler)
167
-
168
- if (!isUsingEsbuild) {
169
- return false
143
+ else {
144
+ // We must use esbuild for certain file extensions.
145
+ const mustTranspile = ['.mjs', '.ts', '.mts', '.cts'].includes(path.extname(func.mainFile));
146
+ const mustUseEsbuild = hasTypeModule || mustTranspile;
147
+ if (mustUseEsbuild && !functionsConfig['*'].nodeBundler) {
148
+ functionsConfig['*'].nodeBundler = 'esbuild';
149
+ }
150
+ // TODO: Resolve functions config globs so that we can check for the bundler
151
+ // on a per-function basis.
152
+ const isUsingEsbuild = ['esbuild_zisi', 'esbuild'].includes(functionsConfig['*'].nodeBundler);
153
+ if (!isUsingEsbuild) {
154
+ return false;
155
+ }
170
156
  }
171
- }
172
-
173
- // Enable source map support.
174
- sourceMapSupport.install()
175
-
176
- const targetDirectory = await getTargetDirectory({ projectRoot, errorExit })
177
-
178
- return {
179
- build: ({ cache = {} }) =>
180
- buildFunction({
181
- cache,
182
- config: functionsConfig,
183
- directory,
184
- func,
185
- projectRoot,
186
- targetDirectory,
187
- hasTypeModule,
188
- featureFlags,
189
- }),
190
- builderName: 'zip-it-and-ship-it',
191
- target: targetDirectory,
192
- }
157
+ // Enable source map support.
158
+ sourceMapSupport.install();
159
+ const targetDirectory = await getTargetDirectory({ projectRoot, errorExit });
160
+ return {
161
+ build: ({ cache = {} }) => buildFunction({
162
+ cache,
163
+ config: functionsConfig,
164
+ directory,
165
+ func,
166
+ projectRoot,
167
+ targetDirectory,
168
+ hasTypeModule,
169
+ featureFlags,
170
+ }),
171
+ builderName: 'zip-it-and-ship-it',
172
+ target: targetDirectory,
173
+ };
193
174
  }
@@ -1 +1 @@
1
- export const SECONDS_TO_MILLISECONDS = 1000
1
+ export const SECONDS_TO_MILLISECONDS = 1000;
@@ -1,118 +1,101 @@
1
- import { createConnection } from 'net'
2
- import { dirname } from 'path'
3
- import { pathToFileURL } from 'url'
4
- import { Worker } from 'worker_threads'
5
-
6
- import lambdaLocal from 'lambda-local'
7
-
8
- import detectNetlifyLambdaBuilder from './builders/netlify-lambda.mjs'
9
- import detectZisiBuilder, { parseFunctionForMetadata } from './builders/zisi.mjs'
10
- import { SECONDS_TO_MILLISECONDS } from './constants.mjs'
11
-
12
- export const name = 'js'
13
-
14
- let netlifyLambdaDetectorCache
15
-
16
- lambdaLocal.getLogger().level = 'alert'
17
-
1
+ import { createConnection } from 'net';
2
+ import { dirname } from 'path';
3
+ import { pathToFileURL } from 'url';
4
+ import { Worker } from 'worker_threads';
5
+ import lambdaLocal from 'lambda-local';
6
+ import detectNetlifyLambdaBuilder from './builders/netlify-lambda.mjs';
7
+ import detectZisiBuilder, { parseFunctionForMetadata } from './builders/zisi.mjs';
8
+ import { SECONDS_TO_MILLISECONDS } from './constants.mjs';
9
+ export const name = 'js';
10
+ // @ts-expect-error TS(7034) FIXME: Variable 'netlifyLambdaDetectorCache' implicitly h... Remove this comment to see the full error message
11
+ let netlifyLambdaDetectorCache;
12
+ lambdaLocal.getLogger().level = 'alert';
18
13
  // The netlify-lambda builder can't be enabled or disabled on a per-function
19
14
  // basis and its detection mechanism is also quite expensive, so we detect
20
15
  // it once and cache the result.
21
16
  const detectNetlifyLambdaWithCache = () => {
22
- if (netlifyLambdaDetectorCache === undefined) {
23
- netlifyLambdaDetectorCache = detectNetlifyLambdaBuilder()
24
- }
25
-
26
- return netlifyLambdaDetectorCache
27
- }
28
-
17
+ // @ts-expect-error TS(7005) FIXME: Variable 'netlifyLambdaDetectorCache' implicitly h... Remove this comment to see the full error message
18
+ if (netlifyLambdaDetectorCache === undefined) {
19
+ netlifyLambdaDetectorCache = detectNetlifyLambdaBuilder();
20
+ }
21
+ // @ts-expect-error TS(7005) FIXME: Variable 'netlifyLambdaDetectorCache' implicitly h... Remove this comment to see the full error message
22
+ return netlifyLambdaDetectorCache;
23
+ };
24
+ // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
29
25
  export const getBuildFunction = async ({ config, directory, errorExit, func, projectRoot }) => {
30
- const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
31
-
32
- if (netlifyLambdaBuilder) {
33
- return netlifyLambdaBuilder.build
34
- }
35
-
36
- const metadata = await parseFunctionForMetadata({ mainFile: func.mainFile, config, projectRoot })
37
- const zisiBuilder = await detectZisiBuilder({ config, directory, errorExit, func, metadata, projectRoot })
38
-
39
- if (zisiBuilder) {
40
- return zisiBuilder.build
41
- }
42
-
43
- // If there's no function builder, we create a simple one on-the-fly which
44
- // returns as `srcFiles` the function directory, if there is one, or its
45
- // main file otherwise.
46
- const functionDirectory = dirname(func.mainFile)
47
- const srcFiles = functionDirectory === directory ? [func.mainFile] : [functionDirectory]
48
-
49
- return () => ({ schedule: metadata.schedule, srcFiles })
50
- }
51
-
52
- const workerURL = new URL('worker.mjs', import.meta.url)
53
-
26
+ const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache();
27
+ if (netlifyLambdaBuilder) {
28
+ return netlifyLambdaBuilder.build;
29
+ }
30
+ const metadata = await parseFunctionForMetadata({ mainFile: func.mainFile, config, projectRoot });
31
+ const zisiBuilder = await detectZisiBuilder({ config, directory, errorExit, func, metadata, projectRoot });
32
+ if (zisiBuilder) {
33
+ return zisiBuilder.build;
34
+ }
35
+ // If there's no function builder, we create a simple one on-the-fly which
36
+ // returns as `srcFiles` the function directory, if there is one, or its
37
+ // main file otherwise.
38
+ const functionDirectory = dirname(func.mainFile);
39
+ const srcFiles = functionDirectory === directory ? [func.mainFile] : [functionDirectory];
40
+ // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
41
+ return () => ({ schedule: metadata.schedule, srcFiles });
42
+ };
43
+ const workerURL = new URL('worker.mjs', import.meta.url);
44
+ // @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
54
45
  export const invokeFunction = async ({ context, environment, event, func, timeout }) => {
55
- if (func.buildData.runtimeAPIVersion !== 2) {
56
- return await invokeFunctionDirectly({ context, event, func, timeout })
57
- }
58
-
59
- const workerData = {
60
- clientContext: JSON.stringify(context),
61
- environment,
62
- event,
46
+ if (func.buildData.runtimeAPIVersion !== 2) {
47
+ return await invokeFunctionDirectly({ context, event, func, timeout });
48
+ }
49
+ const workerData = {
50
+ clientContext: JSON.stringify(context),
51
+ environment,
52
+ event,
53
+ // If a function builder has defined a `buildPath` property, we use it.
54
+ // Otherwise, we'll invoke the function's main file.
55
+ // Because we use import() we have to use file:// URLs for Windows.
56
+ entryFilePath: pathToFileURL(func.buildData?.buildPath ?? func.mainFile).href,
57
+ timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
58
+ };
59
+ const worker = new Worker(workerURL, { workerData });
60
+ return await new Promise((resolve, reject) => {
61
+ worker.on('message', (result) => {
62
+ if (result?.streamPort) {
63
+ const client = createConnection({
64
+ port: result.streamPort,
65
+ host: 'localhost',
66
+ }, () => {
67
+ result.body = client;
68
+ resolve(result);
69
+ });
70
+ client.on('error', reject);
71
+ }
72
+ else {
73
+ resolve(result);
74
+ }
75
+ });
76
+ worker.on('error', reject);
77
+ });
78
+ };
79
+ // @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
80
+ export const invokeFunctionDirectly = async ({ context, event, func, timeout }) => {
63
81
  // If a function builder has defined a `buildPath` property, we use it.
64
82
  // Otherwise, we'll invoke the function's main file.
65
- // Because we use import() we have to use file:// URLs for Windows.
66
- entryFilePath: pathToFileURL(func.buildData?.buildPath ?? func.mainFile).href,
67
- timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
68
- }
69
-
70
- const worker = new Worker(workerURL, { workerData })
71
- return await new Promise((resolve, reject) => {
72
- worker.on('message', (result) => {
73
- if (result?.streamPort) {
74
- const client = createConnection(
75
- {
76
- port: result.streamPort,
77
- host: 'localhost',
78
- },
79
- () => {
80
- result.body = client
81
- resolve(result)
82
- },
83
- )
84
- client.on('error', reject)
85
- } else {
86
- resolve(result)
87
- }
88
- })
89
-
90
- worker.on('error', reject)
91
- })
92
- }
93
-
94
- export const invokeFunctionDirectly = async ({ context, event, func, timeout }) => {
95
- // If a function builder has defined a `buildPath` property, we use it.
96
- // Otherwise, we'll invoke the function's main file.
97
- const lambdaPath = func.buildData?.buildPath ?? func.mainFile
98
- const result = await lambdaLocal.execute({
99
- clientContext: JSON.stringify(context),
100
- event,
101
- lambdaPath,
102
- timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
103
- verboseLevel: 3,
104
- })
105
-
106
- return result
107
- }
108
-
83
+ const lambdaPath = func.buildData?.buildPath ?? func.mainFile;
84
+ const result = await lambdaLocal.execute({
85
+ clientContext: JSON.stringify(context),
86
+ event,
87
+ lambdaPath,
88
+ timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
89
+ verboseLevel: 3,
90
+ });
91
+ return result;
92
+ };
109
93
  export const onDirectoryScan = async () => {
110
- const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
111
-
112
- // Before we start a directory scan, we check whether netlify-lambda is being
113
- // used. If it is, we run it, so that the functions directory is populated
114
- // with the compiled files before the scan begins.
115
- if (netlifyLambdaBuilder) {
116
- await netlifyLambdaBuilder.build()
117
- }
118
- }
94
+ const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache();
95
+ // Before we start a directory scan, we check whether netlify-lambda is being
96
+ // used. If it is, we run it, so that the functions directory is populated
97
+ // with the compiled files before the scan begins.
98
+ if (netlifyLambdaBuilder) {
99
+ await netlifyLambdaBuilder.build();
100
+ }
101
+ };
@@ -1,55 +1,53 @@
1
- import { createServer } from 'net'
2
- import process from 'process'
3
- import { isMainThread, workerData, parentPort } from 'worker_threads'
4
-
5
- import { isStream } from 'is-stream'
6
- import lambdaLocal from 'lambda-local'
7
- import sourceMapSupport from 'source-map-support'
8
-
1
+ import { createServer } from 'net';
2
+ import process from 'process';
3
+ import { isMainThread, workerData, parentPort } from 'worker_threads';
4
+ import { isStream } from 'is-stream';
5
+ import lambdaLocal from 'lambda-local';
6
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'sour... Remove this comment to see the full error message
7
+ import sourceMapSupport from 'source-map-support';
9
8
  if (isMainThread) {
10
- throw new Error(`Do not import "${import.meta.url}" in the main thread.`)
9
+ throw new Error(`Do not import "${import.meta.url}" in the main thread.`);
11
10
  }
12
-
13
- sourceMapSupport.install()
14
-
15
- lambdaLocal.getLogger().level = 'alert'
16
-
17
- const { clientContext, entryFilePath, environment = {}, event, timeoutMs } = workerData
18
-
11
+ sourceMapSupport.install();
12
+ lambdaLocal.getLogger().level = 'alert';
13
+ const { clientContext, entryFilePath, environment = {}, event, timeoutMs } = workerData;
19
14
  // Injecting into the environment any properties passed in by the parent.
20
15
  for (const key in environment) {
21
- process.env[key] = environment[key]
16
+ process.env[key] = environment[key];
22
17
  }
23
-
24
- const lambdaFunc = await import(entryFilePath)
25
-
18
+ const lambdaFunc = await import(entryFilePath);
26
19
  const result = await lambdaLocal.execute({
27
- clientContext,
28
- event,
29
- lambdaFunc,
30
- region: 'dev',
31
- timeoutMs,
32
- verboseLevel: 3,
33
- })
34
-
20
+ clientContext,
21
+ event,
22
+ lambdaFunc,
23
+ region: 'dev',
24
+ timeoutMs,
25
+ verboseLevel: 3,
26
+ });
35
27
  // When the result body is a StreamResponse
36
28
  // we open up a http server that proxies back to the main thread.
29
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
37
30
  if (result && isStream(result.body)) {
38
- const { body } = result
39
- delete result.body
40
- await new Promise((resolve, reject) => {
41
- const server = createServer((socket) => {
42
- body.pipe(socket).on('end', () => server.close())
43
- })
44
- server.on('error', (error) => {
45
- reject(error)
46
- })
47
- server.listen({ port: 0, host: 'localhost' }, () => {
48
- const { port } = server.address()
49
- result.streamPort = port
50
- resolve()
51
- })
52
- })
31
+ // @ts-expect-error TS(2339) FIXME: Property 'body' does not exist on type 'unknown'.
32
+ const { body } = result;
33
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
34
+ delete result.body;
35
+ await new Promise((resolve, reject) => {
36
+ const server = createServer((socket) => {
37
+ body.pipe(socket).on('end', () => server.close());
38
+ });
39
+ server.on('error', (error) => {
40
+ reject(error);
41
+ });
42
+ server.listen({ port: 0, host: 'localhost' }, () => {
43
+ // @ts-expect-error TS(2339) FIXME: Property 'port' does not exist on type 'string | A... Remove this comment to see the full error message
44
+ const { port } = server.address();
45
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
46
+ result.streamPort = port;
47
+ // @ts-expect-error TS(2794) FIXME: Expected 1 arguments, but got 0. Did you forget to... Remove this comment to see the full error message
48
+ resolve();
49
+ });
50
+ });
53
51
  }
54
-
55
- parentPort.postMessage(result)
52
+ // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
53
+ parentPort.postMessage(result);