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,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { chalk, error, log } from '../../utils/command-helpers.mjs'
|
|
7
|
-
import { init } from '../init/index.mjs'
|
|
8
|
-
|
|
1
|
+
import pWaitFor from 'p-wait-for';
|
|
2
|
+
import prettyjson from 'prettyjson';
|
|
3
|
+
import { startSpinner, stopSpinner } from '../../lib/spinner.mjs';
|
|
4
|
+
import { chalk, error, log } from '../../utils/command-helpers.mjs';
|
|
5
|
+
import { init } from '../init/index.mjs';
|
|
9
6
|
// 1 second
|
|
10
|
-
const INIT_WAIT = 1e3
|
|
11
|
-
|
|
7
|
+
const INIT_WAIT = 1e3;
|
|
12
8
|
// 1 second
|
|
13
|
-
const BUILD_FINISH_INTERVAL = 1e3
|
|
9
|
+
const BUILD_FINISH_INTERVAL = 1e3;
|
|
14
10
|
// 20 minutes
|
|
15
|
-
const BUILD_FINISH_TIMEOUT = 12e5
|
|
16
|
-
|
|
11
|
+
const BUILD_FINISH_TIMEOUT = 12e5;
|
|
17
12
|
/**
|
|
18
13
|
*
|
|
19
14
|
* @param {import('netlify').NetlifyAPI} api
|
|
@@ -21,111 +16,102 @@ const BUILD_FINISH_TIMEOUT = 12e5
|
|
|
21
16
|
* @param {import('ora').Ora} spinner
|
|
22
17
|
* @returns {Promise<boolean>}
|
|
23
18
|
*/
|
|
19
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'api' implicitly has an 'any' type.
|
|
24
20
|
const waitForBuildFinish = async function (api, siteId, spinner) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// return only when build done or timeout happens
|
|
52
|
-
return firstPass
|
|
53
|
-
}
|
|
54
|
-
|
|
21
|
+
let firstPass = true;
|
|
22
|
+
const waitForBuildToFinish = async function () {
|
|
23
|
+
const builds = await api.listSiteBuilds({ siteId });
|
|
24
|
+
// build.error
|
|
25
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'build' implicitly has an 'any' type.
|
|
26
|
+
const currentBuilds = builds.filter((build) => !build.done);
|
|
27
|
+
// if build.error
|
|
28
|
+
// @TODO implement build error messages into this
|
|
29
|
+
if (!currentBuilds || currentBuilds.length === 0) {
|
|
30
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ spinner: any; }' is not assign... Remove this comment to see the full error message
|
|
31
|
+
stopSpinner({ spinner });
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
firstPass = false;
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
await pWaitFor(waitForBuildToFinish, {
|
|
38
|
+
interval: BUILD_FINISH_INTERVAL,
|
|
39
|
+
timeout: {
|
|
40
|
+
milliseconds: BUILD_FINISH_TIMEOUT,
|
|
41
|
+
message: 'Timeout while waiting for deploy to finish',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
// return only when build done or timeout happens
|
|
45
|
+
return firstPass;
|
|
46
|
+
};
|
|
55
47
|
/**
|
|
56
48
|
* The watch command
|
|
57
49
|
* @param {import('commander').OptionValues} options
|
|
58
50
|
* @param {import('../base-command.mjs').default} command
|
|
59
51
|
*/
|
|
52
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
|
|
60
53
|
const watch = async (options, command) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// "error": null,
|
|
89
|
-
// "created_at": "2018-07-17T17:14:03.423Z"
|
|
90
|
-
// }
|
|
91
|
-
//
|
|
92
|
-
const spinner = startSpinner({ text: 'Waiting for active site deploys to complete' })
|
|
93
|
-
try {
|
|
94
|
-
// Fetch all builds!
|
|
95
|
-
// const builds = await client.listSiteBuilds({siteId})
|
|
54
|
+
await command.authenticate();
|
|
55
|
+
const client = command.netlify.api;
|
|
56
|
+
let siteId = command.netlify.site.id;
|
|
57
|
+
if (!siteId) {
|
|
58
|
+
// TODO: build init command
|
|
59
|
+
const siteData = await init({}, command);
|
|
60
|
+
siteId = siteData.id;
|
|
61
|
+
}
|
|
62
|
+
// wait for 1 sec for everything to kickoff
|
|
63
|
+
console.time('Deploy time');
|
|
64
|
+
await new Promise((resolve) => {
|
|
65
|
+
// @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
|
|
66
|
+
setTimeout(() => resolve(), INIT_WAIT);
|
|
67
|
+
});
|
|
68
|
+
// Get latest commit and look for that
|
|
69
|
+
// git rev-parse HEAD
|
|
70
|
+
// if no sha, its a manual "triggered deploy"
|
|
71
|
+
//
|
|
72
|
+
// {
|
|
73
|
+
// "id": "5b4e23db82d3f1780abd74f3",
|
|
74
|
+
// "deploy_id": "5b4e23db82d3f1780abd74f2",
|
|
75
|
+
// "sha": "pull/1/head",
|
|
76
|
+
// "log": [],
|
|
77
|
+
// "done": false,
|
|
78
|
+
// "error": null,
|
|
79
|
+
// "created_at": "2018-07-17T17:14:03.423Z"
|
|
80
|
+
// }
|
|
96
81
|
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
82
|
+
const spinner = startSpinner({ text: 'Waiting for active site deploys to complete' });
|
|
83
|
+
try {
|
|
84
|
+
// Fetch all builds!
|
|
85
|
+
// const builds = await client.listSiteBuilds({siteId})
|
|
86
|
+
//
|
|
87
|
+
// // Filter down to any that are not done
|
|
88
|
+
// const buildsToWatch = builds.filter((build) => {
|
|
89
|
+
// return !build.done
|
|
90
|
+
// })
|
|
91
|
+
const noActiveBuilds = await waitForBuildFinish(client, siteId, spinner);
|
|
92
|
+
const siteData = await client.getSite({ siteId });
|
|
93
|
+
const message = chalk.cyanBright.bold.underline(noActiveBuilds ? 'Last build' : 'Deploy complete');
|
|
94
|
+
log();
|
|
95
|
+
log(message);
|
|
96
|
+
log(prettyjson.render({
|
|
97
|
+
URL: siteData.ssl_url || siteData.url,
|
|
98
|
+
Admin: siteData.admin_url,
|
|
99
|
+
}));
|
|
100
|
+
console.timeEnd('Deploy time');
|
|
101
|
+
}
|
|
102
|
+
catch (error_) {
|
|
103
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
|
|
104
|
+
error(error_);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
121
107
|
/**
|
|
122
108
|
* Creates the `netlify watch` command
|
|
123
109
|
* @param {import('../base-command.mjs').default} program
|
|
124
110
|
* @returns
|
|
125
111
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
|
|
113
|
+
export const createWatchCommand = (program) => program
|
|
128
114
|
.command('watch')
|
|
129
115
|
.description('Watch for site deploy to finish')
|
|
130
116
|
.addExamples([`netlify watch`, `git push && netlify watch`])
|
|
131
|
-
.action(watch)
|
|
117
|
+
.action(watch);
|
package/src/lib/account.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @param {any} account
|
|
5
3
|
* @param {string} capability
|
|
6
4
|
* @returns {boolean}
|
|
7
5
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
|
|
7
|
+
const supportsBooleanCapability = (account, capability) => Boolean(account?.capabilities?.[capability]?.included);
|
|
10
8
|
/**
|
|
11
9
|
* @param {any} account
|
|
12
10
|
* @returns {boolean}
|
|
13
11
|
*/
|
|
14
|
-
|
|
12
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
|
|
13
|
+
export const supportsBackgroundFunctions = (account) => supportsBooleanCapability(account, 'background_functions');
|
package/src/lib/api.mjs
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { warn } from '../utils/command-helpers.mjs'
|
|
2
|
-
|
|
1
|
+
import { warn } from '../utils/command-helpers.mjs';
|
|
2
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
3
3
|
export const cancelDeploy = async ({ api, deployId }) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
4
|
+
try {
|
|
5
|
+
await api.cancelSiteDeploy({ deploy_id: deployId });
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
9
|
+
warn(`Failed canceling deploy with id ${deployId}: ${error.message}`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const FIRST_PAGE = 1;
|
|
13
|
+
const MAX_PAGES = 10;
|
|
14
|
+
const MAX_PER_PAGE = 100;
|
|
15
|
+
// @ts-expect-error TS(7023) FIXME: 'listSites' implicitly has return type 'any' becau... Remove this comment to see the full error message
|
|
14
16
|
export const listSites = async ({ api, options }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
17
|
+
const { maxPages = MAX_PAGES, page = FIRST_PAGE, ...rest } = options;
|
|
18
|
+
const sites = await api.listSites({ page, per_page: MAX_PER_PAGE, ...rest });
|
|
19
|
+
// TODO: use pagination headers when js-client returns them
|
|
20
|
+
if (sites.length === MAX_PER_PAGE && page + 1 <= maxPages) {
|
|
21
|
+
return [...sites, ...(await listSites({ api, options: { page: page + 1, maxPages, ...rest } }))];
|
|
22
|
+
}
|
|
23
|
+
return sites;
|
|
24
|
+
};
|
package/src/lib/blobs/blobs.mjs
CHANGED
|
@@ -1,50 +1,41 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { BlobsServer } from '@netlify/blobs';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { log, NETLIFYDEVLOG } from '../../utils/command-helpers.mjs';
|
|
5
|
+
import { getPathInProject } from '../settings.mjs';
|
|
6
|
+
let hasPrintedLocalBlobsNotice = false;
|
|
7
|
+
const printLocalBlobsNotice = () => {
|
|
8
|
+
if (hasPrintedLocalBlobsNotice) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
hasPrintedLocalBlobsNotice = true;
|
|
12
|
+
log(`${NETLIFYDEVLOG} Netlify Blobs running in sandbox mode for local development. Refer to https://ntl.fyi/local-blobs for more information.`);
|
|
13
|
+
};
|
|
14
|
+
const startBlobsServer = async (debug, projectRoot, token) => {
|
|
15
|
+
const directory = path.resolve(projectRoot, getPathInProject(['blobs-serves']));
|
|
16
|
+
const server = new BlobsServer({
|
|
17
|
+
debug,
|
|
18
|
+
directory,
|
|
19
|
+
onRequest: () => {
|
|
20
|
+
printLocalBlobsNotice();
|
|
21
|
+
},
|
|
22
|
+
token,
|
|
23
|
+
});
|
|
24
|
+
const { port } = await server.start();
|
|
25
|
+
return { port };
|
|
26
|
+
};
|
|
17
27
|
/**
|
|
18
28
|
* Starts a local Blobs server and returns a context object that lets functions
|
|
19
29
|
* connect to it.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} options
|
|
22
|
-
* @param {boolean} options.debug
|
|
23
|
-
* @param {string} options.projectRoot
|
|
24
|
-
* @param {string} options.siteID
|
|
25
|
-
* @returns {Promise<BlobsContext>}
|
|
26
30
|
*/
|
|
27
31
|
export const getBlobsContext = async ({ debug, projectRoot, siteID }) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const startBlobsServer = async ({ debug, projectRoot, token }) => {
|
|
41
|
-
const directory = path.resolve(projectRoot, getPathInProject(['blobs']))
|
|
42
|
-
const server = new BlobsServer({
|
|
43
|
-
debug,
|
|
44
|
-
directory,
|
|
45
|
-
token,
|
|
46
|
-
})
|
|
47
|
-
const { port } = await server.start()
|
|
48
|
-
|
|
49
|
-
return { port }
|
|
50
|
-
}
|
|
32
|
+
const token = uuidv4();
|
|
33
|
+
const { port } = await startBlobsServer(debug, projectRoot, token);
|
|
34
|
+
const context = {
|
|
35
|
+
deployID: '0',
|
|
36
|
+
edgeURL: `http://localhost:${port}`,
|
|
37
|
+
siteID,
|
|
38
|
+
token,
|
|
39
|
+
};
|
|
40
|
+
return context;
|
|
41
|
+
};
|
package/src/lib/build.mjs
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { getBootstrapURL } from './edge-functions/bootstrap.mjs'
|
|
11
|
-
import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.mjs'
|
|
12
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import process from 'process';
|
|
3
|
+
import build from '@netlify/build';
|
|
4
|
+
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'toml... Remove this comment to see the full error message
|
|
5
|
+
import tomlify from 'tomlify-j0.4';
|
|
6
|
+
import { isFeatureFlagEnabled } from '../utils/feature-flags.mjs';
|
|
7
|
+
import { getBootstrapURL } from './edge-functions/bootstrap.mjs';
|
|
8
|
+
import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.mjs';
|
|
13
9
|
/**
|
|
14
10
|
* The buildConfig + a missing cachedConfig
|
|
15
11
|
* @typedef BuildConfig
|
|
16
12
|
* @type {Parameters<import('@netlify/build/src/core/main.js')>[0] & {cachedConfig: any}}
|
|
17
13
|
*/
|
|
18
|
-
|
|
19
14
|
// We have already resolved the configuration using `@netlify/config`
|
|
20
15
|
// This is stored as `netlify.cachedConfig` and can be passed to
|
|
21
16
|
// `@netlify/build --cachedConfig`.
|
|
@@ -30,88 +25,90 @@ import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/cons
|
|
|
30
25
|
* @param {*} config.deployHandler
|
|
31
26
|
* @returns {BuildConfig}
|
|
32
27
|
*/
|
|
33
|
-
export const getBuildOptions = ({
|
|
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
|
-
|
|
28
|
+
export const getBuildOptions = ({
|
|
29
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'cachedConfig' implicitly has an '... Remove this comment to see the full error message
|
|
30
|
+
cachedConfig,
|
|
31
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'currentDir' implicitly has an 'an... Remove this comment to see the full error message
|
|
32
|
+
currentDir,
|
|
33
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'deployHandler' implicitly has an ... Remove this comment to see the full error message
|
|
34
|
+
deployHandler,
|
|
35
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
|
|
36
|
+
options: { context, cwd, debug, dry, json, offline, silent },
|
|
37
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'packagePath' implicitly has an 'a... Remove this comment to see the full error message
|
|
38
|
+
packagePath,
|
|
39
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'token' implicitly has an 'any' ty... Remove this comment to see the full error message
|
|
40
|
+
token, }) => {
|
|
41
|
+
const eventHandlers = {
|
|
42
|
+
onEnd: {
|
|
43
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'netlifyConfig' implicitly has an ... Remove this comment to see the full error message
|
|
44
|
+
handler: ({ netlifyConfig }) => {
|
|
45
|
+
const string = tomlify.toToml(netlifyConfig);
|
|
46
|
+
if (!fs.existsSync(`${currentDir}/.netlify`)) {
|
|
47
|
+
fs.mkdirSync(`${currentDir}/.netlify`, { recursive: true });
|
|
48
|
+
}
|
|
49
|
+
fs.writeFileSync(`${currentDir}/.netlify/netlify.toml`, string);
|
|
50
|
+
return {};
|
|
51
|
+
},
|
|
52
|
+
description: 'Save updated config',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
if (deployHandler) {
|
|
56
|
+
// @ts-expect-error TS(2339) FIXME: Property 'onPostBuild' does not exist on type '{ o... Remove this comment to see the full error message
|
|
57
|
+
eventHandlers.onPostBuild = {
|
|
58
|
+
handler: deployHandler,
|
|
59
|
+
description: 'Deploy Site',
|
|
60
|
+
};
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
62
|
+
return {
|
|
63
|
+
cachedConfig,
|
|
64
|
+
siteId: cachedConfig.siteInfo.id,
|
|
65
|
+
packagePath,
|
|
66
|
+
token,
|
|
67
|
+
dry,
|
|
68
|
+
debug,
|
|
69
|
+
context,
|
|
70
|
+
mode: 'cli',
|
|
71
|
+
telemetry: false,
|
|
72
|
+
// buffer = true will not stream output
|
|
73
|
+
buffer: json || silent,
|
|
74
|
+
offline,
|
|
75
|
+
cwd,
|
|
76
|
+
featureFlags: {
|
|
77
|
+
...edgeFunctionsFeatureFlags,
|
|
78
|
+
...getFeatureFlagsFromSiteInfo(cachedConfig.siteInfo),
|
|
79
|
+
functionsBundlingManifest: true,
|
|
80
|
+
},
|
|
81
|
+
eventHandlers,
|
|
82
|
+
edgeFunctionsBootstrapURL: getBootstrapURL(),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
88
85
|
/**
|
|
89
86
|
* @param {*} siteInfo
|
|
90
87
|
* @returns {Record<string, any>}
|
|
91
88
|
*/
|
|
89
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'siteInfo' implicitly has an 'any' type.
|
|
92
90
|
const getFeatureFlagsFromSiteInfo = (siteInfo) => ({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
|
|
91
|
+
...siteInfo.feature_flags,
|
|
92
|
+
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
|
|
93
|
+
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
|
|
94
|
+
});
|
|
98
95
|
/**
|
|
99
96
|
* run the build command
|
|
100
97
|
* @param {BuildConfig} options
|
|
101
98
|
* @returns
|
|
102
99
|
*/
|
|
100
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
|
|
103
101
|
export const runBuild = async (options) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
// If netlify NETLIFY_API_URL is set we need to pass this information to @netlify/build
|
|
103
|
+
// TODO don't use testOpts, but add real properties to do this.
|
|
104
|
+
if (process.env.NETLIFY_API_URL) {
|
|
105
|
+
const apiUrl = new URL(process.env.NETLIFY_API_URL);
|
|
106
|
+
const testOpts = {
|
|
107
|
+
scheme: apiUrl.protocol.slice(0, -1),
|
|
108
|
+
host: apiUrl.host,
|
|
109
|
+
};
|
|
110
|
+
options = { ...options, testOpts };
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options)
|
|
116
|
-
return { exitCode, newConfig, configMutations }
|
|
117
|
-
}
|
|
112
|
+
const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options);
|
|
113
|
+
return { exitCode, newConfig, configMutations };
|
|
114
|
+
};
|