netlify-cli 17.3.2 → 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.
- package/README.md +2 -138
- package/npm-shrinkwrap.json +76 -76
- package/package.json +16 -15
- package/src/commands/addons/addons-auth.mjs +27 -30
- package/src/commands/addons/addons-config.mjs +145 -154
- package/src/commands/addons/addons-create.mjs +94 -108
- package/src/commands/addons/addons-delete.mjs +36 -41
- package/src/commands/addons/addons-list.mjs +38 -42
- package/src/commands/addons/addons.mjs +26 -28
- package/src/commands/addons/index.mjs +1 -1
- package/src/commands/api/api.mjs +45 -53
- package/src/commands/api/index.mjs +1 -1
- package/src/commands/base-command.mjs +597 -684
- package/src/commands/blobs/blobs-delete.mjs +35 -0
- package/src/commands/blobs/blobs-get.mjs +44 -0
- package/src/commands/blobs/blobs-list.mjs +48 -0
- package/src/commands/blobs/blobs-set.mjs +54 -0
- package/src/commands/blobs/blobs.mjs +32 -0
- package/src/commands/blobs/index.mjs +1 -0
- package/src/commands/build/build.mjs +55 -67
- package/src/commands/build/index.mjs +1 -1
- package/src/commands/completion/completion.mjs +41 -46
- package/src/commands/completion/index.mjs +1 -1
- package/src/commands/deploy/deploy.mjs +675 -710
- package/src/commands/deploy/index.mjs +1 -1
- package/src/commands/dev/dev-exec.mjs +20 -32
- package/src/commands/dev/dev.mjs +217 -302
- package/src/commands/dev/index.mjs +1 -1
- package/src/commands/dev/types.d.ts +30 -0
- package/src/commands/env/env-clone.mjs +157 -184
- package/src/commands/env/env-get.mjs +49 -68
- package/src/commands/env/env-import.mjs +100 -119
- package/src/commands/env/env-list.mjs +104 -129
- package/src/commands/env/env-set.mjs +160 -185
- package/src/commands/env/env-unset.mjs +104 -122
- package/src/commands/env/env.mjs +28 -30
- package/src/commands/env/index.mjs +1 -1
- package/src/commands/functions/functions-build.mjs +29 -41
- package/src/commands/functions/functions-create.mjs +533 -601
- package/src/commands/functions/functions-invoke.mjs +193 -216
- package/src/commands/functions/functions-list.mjs +45 -55
- package/src/commands/functions/functions-serve.mjs +51 -61
- package/src/commands/functions/functions.mjs +26 -32
- package/src/commands/functions/index.mjs +1 -1
- package/src/commands/index.mjs +2 -2
- package/src/commands/init/index.mjs +1 -1
- package/src/commands/init/init.mjs +138 -167
- package/src/commands/integration/deploy.mjs +337 -399
- package/src/commands/integration/index.mjs +12 -13
- package/src/commands/link/index.mjs +1 -1
- package/src/commands/link/link.mjs +298 -317
- package/src/commands/lm/index.mjs +1 -1
- package/src/commands/lm/lm-info.mjs +23 -31
- package/src/commands/lm/lm-install.mjs +13 -17
- package/src/commands/lm/lm-setup.mjs +80 -84
- package/src/commands/lm/lm-uninstall.mjs +7 -12
- package/src/commands/lm/lm.mjs +18 -22
- package/src/commands/login/index.mjs +1 -1
- package/src/commands/login/login.mjs +35 -41
- package/src/commands/logout/index.mjs +1 -1
- package/src/commands/logout/logout.mjs +25 -31
- package/src/commands/main.mjs +166 -201
- package/src/commands/open/index.mjs +1 -1
- package/src/commands/open/open-admin.mjs +15 -18
- package/src/commands/open/open-site.mjs +16 -19
- package/src/commands/open/open.mjs +24 -27
- package/src/commands/recipes/common.mjs +23 -34
- package/src/commands/recipes/index.mjs +1 -1
- package/src/commands/recipes/recipes-list.mjs +13 -20
- package/src/commands/recipes/recipes.mjs +59 -72
- package/src/commands/serve/index.mjs +1 -1
- package/src/commands/serve/serve.mjs +142 -189
- package/src/commands/sites/index.mjs +2 -2
- package/src/commands/sites/sites-create-template.mjs +214 -236
- package/src/commands/sites/sites-create.mjs +145 -157
- package/src/commands/sites/sites-delete.mjs +75 -81
- package/src/commands/sites/sites-list.mjs +63 -66
- package/src/commands/sites/sites.mjs +18 -20
- package/src/commands/status/index.mjs +1 -1
- package/src/commands/status/status-hooks.mjs +32 -34
- package/src/commands/status/status.mjs +99 -106
- package/src/commands/switch/index.mjs +1 -1
- package/src/commands/switch/switch.mjs +32 -37
- package/src/commands/types.d.ts +31 -0
- package/src/commands/unlink/index.mjs +1 -1
- package/src/commands/unlink/unlink.mjs +23 -29
- package/src/commands/watch/index.mjs +1 -1
- package/src/commands/watch/watch.mjs +91 -105
- package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
- package/src/lib/account.mjs +4 -5
- package/src/lib/api.mjs +22 -20
- package/src/lib/blobs/blobs.mjs +36 -45
- package/src/lib/build.mjs +82 -85
- package/src/lib/completion/constants.mjs +2 -4
- package/src/lib/completion/generate-autocompletion.mjs +33 -36
- package/src/lib/completion/get-autocompletion.mjs +31 -35
- package/src/lib/completion/index.mjs +1 -1
- package/src/lib/completion/script.mjs +12 -19
- package/src/lib/edge-functions/bootstrap.mjs +3 -5
- package/src/lib/edge-functions/consts.mjs +9 -10
- package/src/lib/edge-functions/deploy.mjs +28 -34
- package/src/lib/edge-functions/editor-helper.mjs +29 -42
- package/src/lib/edge-functions/headers.mjs +24 -26
- package/src/lib/edge-functions/internal.mjs +38 -44
- package/src/lib/edge-functions/proxy.mjs +229 -228
- package/src/lib/edge-functions/registry.mjs +473 -574
- package/src/lib/exec-fetcher.mjs +115 -122
- package/src/lib/fs.mjs +28 -27
- package/src/lib/functions/background.mjs +16 -20
- package/src/lib/functions/config.mjs +12 -9
- package/src/lib/functions/form-submissions-handler.mjs +143 -149
- package/src/lib/functions/local-proxy.mjs +40 -44
- package/src/lib/functions/memoized-build.mjs +19 -21
- package/src/lib/functions/netlify-function.mjs +269 -249
- package/src/lib/functions/registry.mjs +509 -568
- package/src/lib/functions/runtimes/go/index.mjs +62 -71
- package/src/lib/functions/runtimes/index.mjs +8 -15
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
- package/src/lib/functions/runtimes/js/constants.mjs +1 -1
- package/src/lib/functions/runtimes/js/index.mjs +92 -109
- package/src/lib/functions/runtimes/js/worker.mjs +43 -45
- package/src/lib/functions/runtimes/rust/index.mjs +64 -73
- package/src/lib/functions/scheduled.mjs +70 -88
- package/src/lib/functions/server.mjs +269 -327
- package/src/lib/functions/synchronous.mjs +118 -147
- package/src/lib/functions/utils.mjs +38 -46
- package/src/lib/geo-location.mjs +69 -81
- package/src/lib/http-agent.mjs +87 -90
- package/src/lib/images/proxy.mjs +97 -99
- package/src/lib/log.mjs +6 -9
- package/src/lib/path.mjs +2 -1
- package/src/lib/render-error-template.mjs +19 -20
- package/src/lib/settings.mjs +17 -19
- package/src/lib/spinner.mjs +21 -23
- package/src/lib/string.mjs +4 -2
- package/src/recipes/vscode/index.mjs +69 -85
- package/src/recipes/vscode/settings.mjs +53 -58
- package/src/utils/addons/compare.mjs +31 -32
- package/src/utils/addons/diffs/index.mjs +16 -17
- package/src/utils/addons/diffs/options.mjs +99 -101
- package/src/utils/addons/prepare.mjs +100 -97
- package/src/utils/addons/prompts.mjs +73 -76
- package/src/utils/addons/render.mjs +33 -36
- package/src/utils/addons/validation.mjs +19 -15
- package/src/utils/banner.mjs +11 -16
- package/src/utils/build-info.mjs +65 -66
- package/src/utils/command-helpers.mjs +185 -199
- package/src/utils/create-deferred.mjs +9 -12
- package/src/utils/create-stream-promise.mjs +54 -47
- package/src/utils/deploy/constants.mjs +9 -11
- package/src/utils/deploy/deploy-site.mjs +162 -182
- package/src/utils/deploy/hash-config.mjs +21 -21
- package/src/utils/deploy/hash-files.mjs +34 -38
- package/src/utils/deploy/hash-fns.mjs +149 -154
- package/src/utils/deploy/hasher-segments.mjs +58 -52
- package/src/utils/deploy/upload-files.mjs +99 -113
- package/src/utils/deploy/util.mjs +85 -91
- package/src/utils/detect-server-settings.mjs +236 -268
- package/src/utils/dev.mjs +163 -178
- package/src/utils/dot-env.mjs +37 -42
- package/src/utils/env/index.mjs +148 -148
- package/src/utils/execa.mjs +9 -13
- package/src/utils/feature-flags.mjs +6 -5
- package/src/utils/framework-server.mjs +43 -52
- package/src/utils/functions/constants.mjs +1 -1
- package/src/utils/functions/functions.mjs +30 -40
- package/src/utils/functions/get-functions.mjs +28 -29
- package/src/utils/functions/index.mjs +3 -3
- package/src/utils/get-global-config.mjs +33 -36
- package/src/utils/get-package-json.mjs +14 -15
- package/src/utils/get-repo-data.mjs +54 -64
- package/src/utils/get-site.mjs +14 -14
- package/src/utils/gh-auth.mjs +79 -100
- package/src/utils/gitignore.mjs +37 -40
- package/src/utils/headers.mjs +33 -35
- package/src/utils/hooks/requires-site-info.mjs +26 -22
- package/src/utils/init/config-github.mjs +207 -219
- package/src/utils/init/config-manual.mjs +83 -100
- package/src/utils/init/config.mjs +25 -26
- package/src/utils/init/node-version.mjs +23 -30
- package/src/utils/init/plugins.mjs +12 -8
- package/src/utils/init/utils.mjs +152 -172
- package/src/utils/live-tunnel.mjs +118 -141
- package/src/utils/lm/install.mjs +220 -259
- package/src/utils/lm/requirements.mjs +54 -63
- package/src/utils/lm/steps.mjs +31 -31
- package/src/utils/lm/ui.mjs +13 -20
- package/src/utils/open-browser.mjs +31 -32
- package/src/utils/parse-raw-flags.mjs +39 -35
- package/src/utils/proxy-server.mjs +84 -71
- package/src/utils/proxy.mjs +696 -750
- package/src/utils/read-repo-url.mjs +48 -47
- package/src/utils/redirects.mjs +49 -49
- package/src/utils/request-id.mjs +2 -4
- package/src/utils/rules-proxy.mjs +96 -100
- package/src/utils/run-build.mjs +109 -132
- package/src/utils/shell.mjs +99 -106
- package/src/utils/sign-redirect.mjs +14 -14
- package/src/utils/sites/utils.mjs +48 -55
- package/src/utils/state-config.mjs +101 -101
- package/src/utils/static-server.mjs +28 -34
- package/src/utils/telemetry/index.mjs +2 -2
- package/src/utils/telemetry/report-error.mjs +45 -49
- package/src/utils/telemetry/request.mjs +36 -43
- package/src/utils/telemetry/telemetry.mjs +90 -105
- package/src/utils/telemetry/utils.mjs +5 -6
- package/src/utils/telemetry/validation.mjs +55 -53
- package/src/utils/types.d.ts +46 -0
- 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
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import sourceMapSupport from 'source-map-support'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
mainFile
|
|
61
|
-
|
|
62
|
-
path: functionPath,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
targetDirectory,
|
|
187
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
23
|
-
netlifyLambdaDetectorCache
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
6
|
-
|
|
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
|
-
|
|
9
|
+
throw new Error(`Do not import "${import.meta.url}" in the main thread.`);
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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);
|