@netlify/build 27.20.4 → 27.20.6
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/lib/core/bin.js +42 -59
- package/lib/core/build.js +333 -536
- package/lib/core/config.js +94 -159
- package/lib/core/constants.js +95 -135
- package/lib/core/dev.js +26 -30
- package/lib/core/dry.js +18 -36
- package/lib/core/feature_flags.js +13 -16
- package/lib/core/flags.js +168 -169
- package/lib/core/lingering.js +44 -61
- package/lib/core/main.js +94 -136
- package/lib/core/missing_side_file.js +12 -24
- package/lib/core/normalize_flags.js +52 -63
- package/lib/core/severity.js +13 -15
- package/lib/core/user_node_version.js +26 -35
- package/lib/env/changes.js +29 -37
- package/lib/env/main.js +10 -15
- package/lib/env/metadata.js +63 -76
- package/lib/error/api.js +31 -40
- package/lib/error/build.js +27 -38
- package/lib/error/cancel.js +5 -6
- package/lib/error/colors.js +7 -9
- package/lib/error/handle.js +38 -49
- package/lib/error/info.js +26 -35
- package/lib/error/monitor/location.js +12 -17
- package/lib/error/monitor/normalize.js +75 -85
- package/lib/error/monitor/print.js +19 -41
- package/lib/error/monitor/report.js +102 -121
- package/lib/error/monitor/start.js +43 -56
- package/lib/error/parse/clean_stack.js +52 -69
- package/lib/error/parse/location.js +40 -52
- package/lib/error/parse/normalize.js +18 -23
- package/lib/error/parse/parse.js +59 -93
- package/lib/error/parse/plugin.js +42 -57
- package/lib/error/parse/properties.js +13 -20
- package/lib/error/parse/serialize_log.js +29 -37
- package/lib/error/parse/serialize_status.js +15 -23
- package/lib/error/parse/stack.js +29 -38
- package/lib/error/type.js +132 -150
- package/lib/install/functions.js +16 -24
- package/lib/install/local.js +31 -48
- package/lib/install/main.js +52 -66
- package/lib/install/missing.js +40 -53
- package/lib/log/colors.js +15 -22
- package/lib/log/description.js +16 -21
- package/lib/log/header.js +11 -13
- package/lib/log/header_func.js +11 -15
- package/lib/log/logger.js +88 -119
- package/lib/log/messages/compatibility.js +100 -158
- package/lib/log/messages/config.js +76 -92
- package/lib/log/messages/core.js +40 -60
- package/lib/log/messages/core_steps.js +63 -92
- package/lib/log/messages/dry.js +31 -53
- package/lib/log/messages/install.js +21 -28
- package/lib/log/messages/ipc.js +21 -30
- package/lib/log/messages/mutations.js +51 -71
- package/lib/log/messages/plugins.js +18 -31
- package/lib/log/messages/status.js +12 -14
- package/lib/log/messages/steps.js +14 -18
- package/lib/log/old_version.js +23 -32
- package/lib/log/serialize.js +7 -10
- package/lib/log/stream.js +48 -65
- package/lib/log/theme.js +22 -23
- package/lib/plugins/child/diff.js +31 -40
- package/lib/plugins/child/error.js +20 -26
- package/lib/plugins/child/lazy.js +11 -14
- package/lib/plugins/child/load.js +15 -22
- package/lib/plugins/child/logic.js +51 -58
- package/lib/plugins/child/main.js +32 -46
- package/lib/plugins/child/run.js +18 -27
- package/lib/plugins/child/status.js +52 -63
- package/lib/plugins/child/typescript.js +19 -36
- package/lib/plugins/child/utils.js +36 -49
- package/lib/plugins/child/validate.js +25 -28
- package/lib/plugins/compatibility.js +64 -92
- package/lib/plugins/error.js +29 -35
- package/lib/plugins/events.js +7 -12
- package/lib/plugins/expected_version.js +61 -99
- package/lib/plugins/ipc.js +79 -102
- package/lib/plugins/list.js +49 -62
- package/lib/plugins/load.js +44 -64
- package/lib/plugins/manifest/check.js +64 -85
- package/lib/plugins/manifest/load.js +34 -37
- package/lib/plugins/manifest/main.js +16 -21
- package/lib/plugins/manifest/path.js +18 -25
- package/lib/plugins/manifest/validate.js +77 -94
- package/lib/plugins/node_version.js +22 -42
- package/lib/plugins/options.js +45 -78
- package/lib/plugins/pinned_version.js +58 -106
- package/lib/plugins/resolve.js +91 -133
- package/lib/plugins/spawn.js +43 -61
- package/lib/plugins_core/add.js +26 -40
- package/lib/plugins_core/build_command.js +47 -72
- package/lib/plugins_core/deploy/buildbot_client.js +61 -87
- package/lib/plugins_core/deploy/index.js +47 -71
- package/lib/plugins_core/edge_functions/index.js +73 -116
- package/lib/plugins_core/edge_functions/lib/error.js +13 -17
- package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
- package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
- package/lib/plugins_core/functions/error.js +88 -128
- package/lib/plugins_core/functions/feature_flags.js +5 -5
- package/lib/plugins_core/functions/index.js +98 -145
- package/lib/plugins_core/functions/utils.js +36 -57
- package/lib/plugins_core/functions/zisi.js +35 -52
- package/lib/plugins_core/functions_install/index.js +8 -11
- package/lib/plugins_core/list.js +15 -22
- package/lib/status/add.js +26 -32
- package/lib/status/colors.js +14 -19
- package/lib/status/load_error.js +8 -9
- package/lib/status/report.js +72 -126
- package/lib/status/success.js +10 -14
- package/lib/steps/core_step.js +54 -89
- package/lib/steps/error.js +50 -87
- package/lib/steps/get.js +33 -41
- package/lib/steps/plugin.js +53 -83
- package/lib/steps/return.js +24 -51
- package/lib/steps/run_core_steps.js +119 -171
- package/lib/steps/run_step.js +154 -270
- package/lib/steps/run_steps.js +91 -174
- package/lib/steps/update_config.js +45 -72
- package/lib/telemetry/main.js +89 -128
- package/lib/time/aggregate.js +84 -110
- package/lib/time/main.js +23 -34
- package/lib/time/measure.js +11 -15
- package/lib/time/report.js +32 -44
- package/lib/utils/errors.js +10 -9
- package/lib/utils/json.js +11 -15
- package/lib/utils/omit.js +3 -4
- package/lib/utils/package.js +19 -22
- package/lib/utils/remove_falsy.js +5 -7
- package/lib/utils/resolve.js +30 -34
- package/lib/utils/runtime.js +4 -4
- package/lib/utils/semver.js +19 -25
- package/package.json +14 -7
|
@@ -1,75 +1,50 @@
|
|
|
1
|
-
import { platform } from 'process'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { logBuildCommandStart } from '../log/messages/steps.js'
|
|
8
|
-
import { getBuildCommandStdio, handleBuildCommandOutput } from '../log/stream.js'
|
|
9
|
-
|
|
1
|
+
import { platform } from 'process';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { addErrorInfo } from '../error/info.js';
|
|
4
|
+
import { getBuildCommandDescription } from '../log/description.js';
|
|
5
|
+
import { logBuildCommandStart } from '../log/messages/steps.js';
|
|
6
|
+
import { getBuildCommandStdio, handleBuildCommandOutput } from '../log/stream.js';
|
|
10
7
|
// Fire `build.command`
|
|
11
|
-
const coreStep = async function ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} catch (error) {
|
|
39
|
-
// In our test environment we use `stdio: 'pipe'` on the build command, meaning our `stdout/stderr` output are
|
|
40
|
-
// buffered and consequently added to `error.message`. To avoid this and end up with duplicated output in our
|
|
41
|
-
// logs/snapshots we need to rely on `error.shortMessage`.
|
|
42
|
-
error.message = error.shortMessage
|
|
43
|
-
handleBuildCommandOutput(error, logs)
|
|
44
|
-
addErrorInfo(error, { type: 'buildCommand', location: { buildCommand, buildCommandOrigin, configPath } })
|
|
45
|
-
throw error
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
8
|
+
const coreStep = async function ({ configPath, buildDir, nodePath, childEnv, logs, netlifyConfig: { build: { command: buildCommand, commandOrigin: buildCommandOrigin }, }, }) {
|
|
9
|
+
logBuildCommandStart(logs, buildCommand);
|
|
10
|
+
const stdio = getBuildCommandStdio(logs);
|
|
11
|
+
const childProcess = execa(buildCommand, {
|
|
12
|
+
shell: SHELL,
|
|
13
|
+
cwd: buildDir,
|
|
14
|
+
preferLocal: true,
|
|
15
|
+
execPath: nodePath,
|
|
16
|
+
env: childEnv,
|
|
17
|
+
extendEnv: false,
|
|
18
|
+
stdio,
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
const buildCommandOutput = await childProcess;
|
|
22
|
+
handleBuildCommandOutput(buildCommandOutput, logs);
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// In our test environment we use `stdio: 'pipe'` on the build command, meaning our `stdout/stderr` output are
|
|
27
|
+
// buffered and consequently added to `error.message`. To avoid this and end up with duplicated output in our
|
|
28
|
+
// logs/snapshots we need to rely on `error.shortMessage`.
|
|
29
|
+
error.message = error.shortMessage;
|
|
30
|
+
handleBuildCommandOutput(error, logs);
|
|
31
|
+
addErrorInfo(error, { type: 'buildCommand', location: { buildCommand, buildCommandOrigin, configPath } });
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
49
35
|
// We use Bash on Unix and `cmd.exe` on Windows
|
|
50
|
-
const SHELL = platform === 'win32' ? true : 'bash'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
return getBuildCommandDescription(buildCommandOrigin)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const hasBuildCommand = function ({
|
|
61
|
-
netlifyConfig: {
|
|
62
|
-
build: { command: buildCommand },
|
|
63
|
-
},
|
|
64
|
-
}) {
|
|
65
|
-
return buildCommand !== undefined && buildCommand !== ''
|
|
66
|
-
}
|
|
67
|
-
|
|
36
|
+
const SHELL = platform === 'win32' ? true : 'bash';
|
|
37
|
+
const coreStepDescription = function ({ netlifyConfig: { build: { commandOrigin: buildCommandOrigin }, }, }) {
|
|
38
|
+
return getBuildCommandDescription(buildCommandOrigin);
|
|
39
|
+
};
|
|
40
|
+
const hasBuildCommand = function ({ netlifyConfig: { build: { command: buildCommand }, }, }) {
|
|
41
|
+
return buildCommand !== undefined && buildCommand !== '';
|
|
42
|
+
};
|
|
68
43
|
export const buildCommandCore = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
44
|
+
event: 'onBuild',
|
|
45
|
+
coreStep,
|
|
46
|
+
coreStepId: 'build_command',
|
|
47
|
+
coreStepName: 'build.command',
|
|
48
|
+
coreStepDescription,
|
|
49
|
+
condition: hasBuildCommand,
|
|
50
|
+
};
|
|
@@ -1,74 +1,54 @@
|
|
|
1
|
-
import net from 'net'
|
|
2
|
-
import { normalize, resolve, relative } from 'path'
|
|
3
|
-
import { promisify } from 'util'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import { runsAfterDeploy } from '../../plugins/events.js'
|
|
9
|
-
import { addAsyncErrorMessage } from '../../utils/errors.js'
|
|
10
|
-
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import { normalize, resolve, relative } from 'path';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { pEvent } from 'p-event';
|
|
5
|
+
import { addErrorInfo } from '../../error/info.js';
|
|
6
|
+
import { runsAfterDeploy } from '../../plugins/events.js';
|
|
7
|
+
import { addAsyncErrorMessage } from '../../utils/errors.js';
|
|
11
8
|
export const createBuildbotClient = function (buildbotServerSocket) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
9
|
+
const connectionOpts = getConnectionOpts(buildbotServerSocket);
|
|
10
|
+
const client = net.createConnection(connectionOpts);
|
|
11
|
+
return client;
|
|
12
|
+
};
|
|
17
13
|
// Windows does not support Unix sockets well, so we also support `host:port`
|
|
18
14
|
const getConnectionOpts = function (buildbotServerSocket) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
15
|
+
if (!buildbotServerSocket.includes(':')) {
|
|
16
|
+
return { path: buildbotServerSocket };
|
|
17
|
+
}
|
|
18
|
+
const [host, port] = buildbotServerSocket.split(':');
|
|
19
|
+
return { host, port };
|
|
20
|
+
};
|
|
27
21
|
const eConnectBuildbotClient = async function (client) {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const connectBuildbotClient = addAsyncErrorMessage(eConnectBuildbotClient, 'Could not connect to buildbot')
|
|
32
|
-
|
|
22
|
+
await pEvent(client, 'connect');
|
|
23
|
+
};
|
|
24
|
+
export const connectBuildbotClient = addAsyncErrorMessage(eConnectBuildbotClient, 'Could not connect to buildbot');
|
|
33
25
|
export const closeBuildbotClient = async function (client) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
26
|
+
if (client.destroyed) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await promisify(client.end.bind(client))();
|
|
30
|
+
};
|
|
41
31
|
const cWritePayload = async function (buildbotClient, payload) {
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const writePayload = addAsyncErrorMessage(cWritePayload, 'Could not send payload to buildbot')
|
|
46
|
-
|
|
32
|
+
await promisify(buildbotClient.write.bind(buildbotClient))(JSON.stringify(payload));
|
|
33
|
+
};
|
|
34
|
+
const writePayload = addAsyncErrorMessage(cWritePayload, 'Could not send payload to buildbot');
|
|
47
35
|
const cGetNextParsedResponsePromise = async function (buildbotClient) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const getNextParsedResponsePromise = addAsyncErrorMessage(
|
|
53
|
-
cGetNextParsedResponsePromise,
|
|
54
|
-
'Invalid response from buildbot',
|
|
55
|
-
)
|
|
56
|
-
|
|
36
|
+
const data = await pEvent(buildbotClient, 'data');
|
|
37
|
+
return JSON.parse(data);
|
|
38
|
+
};
|
|
39
|
+
const getNextParsedResponsePromise = addAsyncErrorMessage(cGetNextParsedResponsePromise, 'Invalid response from buildbot');
|
|
57
40
|
export const deploySiteWithBuildbotClient = async function ({ client, events, buildDir, repositoryRoot, constants }) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
41
|
+
const action = shouldWaitForPostProcessing(events) ? 'deploySiteAndAwaitLive' : 'deploySite';
|
|
42
|
+
const deployDir = getDeployDir({ buildDir, repositoryRoot, constants });
|
|
43
|
+
const payload = { action, deployDir };
|
|
44
|
+
const [{ succeeded, values: { error, error_type: errorType } = {} }] = await Promise.all([
|
|
45
|
+
getNextParsedResponsePromise(client),
|
|
46
|
+
writePayload(client, payload),
|
|
47
|
+
]);
|
|
48
|
+
if (!succeeded) {
|
|
49
|
+
return handleDeployError(error, errorType);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
72
52
|
// The file paths in the buildbot are relative to the repository root.
|
|
73
53
|
// However, the file paths in Build plugins, including `constants.PUBLISH_DIR`
|
|
74
54
|
// are relative to the build directory, which is different when there is a
|
|
@@ -76,38 +56,32 @@ export const deploySiteWithBuildbotClient = async function ({ client, events, bu
|
|
|
76
56
|
// We need to call `normalize()` in case the publish directory is the
|
|
77
57
|
// repository root, so `deployDir` is "." not ""
|
|
78
58
|
const getDeployDir = function ({ buildDir, repositoryRoot, constants: { PUBLISH_DIR } }) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
59
|
+
const absolutePublishDir = resolve(buildDir, PUBLISH_DIR);
|
|
60
|
+
const relativePublishDir = relative(repositoryRoot, absolutePublishDir);
|
|
61
|
+
const deployDir = normalize(relativePublishDir);
|
|
62
|
+
return deployDir;
|
|
63
|
+
};
|
|
85
64
|
// We distinguish between user errors and system errors during deploys
|
|
86
65
|
const handleDeployError = function (error, errorType) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
? `
|
|
66
|
+
const errorIs422 = error !== undefined && error.code === '422';
|
|
67
|
+
const errMsg = errorIs422
|
|
68
|
+
? `
|
|
91
69
|
File upload failed because of mismatched SHAs.
|
|
92
70
|
This can happen when files are changed after the deployment process has started but before they are uploaded.
|
|
93
71
|
|
|
94
72
|
Error: ${error}
|
|
95
73
|
`
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw errorA
|
|
103
|
-
}
|
|
104
|
-
|
|
74
|
+
: `Deploy did not succeed: ${error}`;
|
|
75
|
+
const errorA = new Error(errMsg);
|
|
76
|
+
const errorInfo = errorType === 'user' ? { type: 'resolveConfig' } : { type: 'coreStep', location: { coreStepName: 'Deploy site' } };
|
|
77
|
+
addErrorInfo(errorA, errorInfo);
|
|
78
|
+
throw errorA;
|
|
79
|
+
};
|
|
105
80
|
// We only wait for post-processing (last stage before site deploy) if the build
|
|
106
81
|
// has some plugins that do post-deploy logic
|
|
107
82
|
const shouldWaitForPostProcessing = function (events) {
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
83
|
+
return events.some(hasPostDeployLogic);
|
|
84
|
+
};
|
|
111
85
|
const hasPostDeployLogic = function (event) {
|
|
112
|
-
|
|
113
|
-
}
|
|
86
|
+
return runsAfterDeploy(event);
|
|
87
|
+
};
|
|
@@ -1,73 +1,49 @@
|
|
|
1
|
-
import { saveUpdatedConfig, restoreUpdatedConfig } from '../../core/config.js'
|
|
2
|
-
import { logDeploySuccess } from '../../log/messages/plugins.js'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
featureFlags,
|
|
40
|
-
context,
|
|
41
|
-
branch,
|
|
42
|
-
debug,
|
|
43
|
-
saveConfig,
|
|
44
|
-
})
|
|
45
|
-
await deploySiteWithBuildbotClient({ client, events, buildDir, repositoryRoot, constants })
|
|
46
|
-
await restoreUpdatedConfig({
|
|
47
|
-
configMutations,
|
|
48
|
-
buildDir,
|
|
49
|
-
repositoryRoot,
|
|
50
|
-
configPath,
|
|
51
|
-
headersPath,
|
|
52
|
-
redirectsPath,
|
|
53
|
-
saveConfig,
|
|
54
|
-
})
|
|
55
|
-
logDeploySuccess(logs)
|
|
56
|
-
return {}
|
|
57
|
-
} finally {
|
|
58
|
-
await closeBuildbotClient(client)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
1
|
+
import { saveUpdatedConfig, restoreUpdatedConfig } from '../../core/config.js';
|
|
2
|
+
import { logDeploySuccess } from '../../log/messages/plugins.js';
|
|
3
|
+
import { createBuildbotClient, connectBuildbotClient, closeBuildbotClient, deploySiteWithBuildbotClient, } from './buildbot_client.js';
|
|
4
|
+
const coreStep = async function ({ buildDir, configPath, repositoryRoot, constants, buildbotServerSocket, events, logs, featureFlags, context, branch, configMutations, headersPath, redirectsPath, debug, saveConfig, }) {
|
|
5
|
+
const client = createBuildbotClient(buildbotServerSocket);
|
|
6
|
+
try {
|
|
7
|
+
await connectBuildbotClient(client);
|
|
8
|
+
await saveUpdatedConfig({
|
|
9
|
+
configMutations,
|
|
10
|
+
buildDir,
|
|
11
|
+
repositoryRoot,
|
|
12
|
+
configPath,
|
|
13
|
+
headersPath,
|
|
14
|
+
redirectsPath,
|
|
15
|
+
logs,
|
|
16
|
+
featureFlags,
|
|
17
|
+
context,
|
|
18
|
+
branch,
|
|
19
|
+
debug,
|
|
20
|
+
saveConfig,
|
|
21
|
+
});
|
|
22
|
+
await deploySiteWithBuildbotClient({ client, events, buildDir, repositoryRoot, constants });
|
|
23
|
+
await restoreUpdatedConfig({
|
|
24
|
+
configMutations,
|
|
25
|
+
buildDir,
|
|
26
|
+
repositoryRoot,
|
|
27
|
+
configPath,
|
|
28
|
+
headersPath,
|
|
29
|
+
redirectsPath,
|
|
30
|
+
saveConfig,
|
|
31
|
+
});
|
|
32
|
+
logDeploySuccess(logs);
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await closeBuildbotClient(client);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
62
39
|
const shouldDeploy = function ({ buildbotServerSocket }) {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
40
|
+
return buildbotServerSocket !== undefined;
|
|
41
|
+
};
|
|
66
42
|
export const deploySite = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
43
|
+
event: 'onPostBuild',
|
|
44
|
+
coreStep,
|
|
45
|
+
coreStepId: 'deploy_site',
|
|
46
|
+
coreStepName: 'Deploy site',
|
|
47
|
+
coreStepDescription: () => 'Deploy site',
|
|
48
|
+
condition: shouldDeploy,
|
|
49
|
+
};
|
|
@@ -1,122 +1,79 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
import { dirname, join, resolve } from 'path'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { tagBundlingError } from './lib/error.js'
|
|
10
|
-
import { parseManifest } from './lib/internal_manifest.js'
|
|
11
|
-
import { validateEdgeFunctionsManifest } from './validate_manifest/validate_edge_functions_manifest.js'
|
|
12
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { dirname, join, resolve } from 'path';
|
|
3
|
+
import { bundle, find } from '@netlify/edge-bundler';
|
|
4
|
+
import { pathExists } from 'path-exists';
|
|
5
|
+
import { logFunctionsToBundle } from '../../log/messages/core_steps.js';
|
|
6
|
+
import { tagBundlingError } from './lib/error.js';
|
|
7
|
+
import { parseManifest } from './lib/internal_manifest.js';
|
|
8
|
+
import { validateEdgeFunctionsManifest } from './validate_manifest/validate_edge_functions_manifest.js';
|
|
13
9
|
// TODO: Replace this with a custom cache directory.
|
|
14
|
-
const DENO_CLI_CACHE_DIRECTORY = '.netlify/plugins/deno-cli'
|
|
15
|
-
const IMPORT_MAP_FILENAME = 'edge-functions-import-map.json'
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
try {
|
|
52
|
-
const { manifest } = await bundle(sourcePaths, distPath, declarations, {
|
|
53
|
-
basePath: buildDir,
|
|
54
|
-
cacheDirectory,
|
|
55
|
-
debug,
|
|
56
|
-
distImportMapPath,
|
|
57
|
-
featureFlags,
|
|
58
|
-
importMaps: [importMap].filter(Boolean),
|
|
59
|
-
systemLogger: featureFlags.edge_functions_system_logger ? systemLog : undefined,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
systemLog('Edge Functions manifest:', manifest)
|
|
63
|
-
} catch (error) {
|
|
64
|
-
tagBundlingError(error)
|
|
65
|
-
|
|
66
|
-
throw error
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
await validateEdgeFunctionsManifest({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory } })
|
|
70
|
-
|
|
71
|
-
return {}
|
|
72
|
-
}
|
|
73
|
-
|
|
10
|
+
const DENO_CLI_CACHE_DIRECTORY = '.netlify/plugins/deno-cli';
|
|
11
|
+
const IMPORT_MAP_FILENAME = 'edge-functions-import-map.json';
|
|
12
|
+
const coreStep = async function ({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory, EDGE_FUNCTIONS_SRC: srcDirectory, INTERNAL_EDGE_FUNCTIONS_SRC: internalSrcDirectory, IS_LOCAL: isRunningLocally, }, debug, systemLog, featureFlags, logs, netlifyConfig, }) {
|
|
13
|
+
const { edge_functions: configDeclarations = [] } = netlifyConfig;
|
|
14
|
+
const distPath = resolve(buildDir, distDirectory);
|
|
15
|
+
const internalSrcPath = resolve(buildDir, internalSrcDirectory);
|
|
16
|
+
const distImportMapPath = join(dirname(internalSrcPath), IMPORT_MAP_FILENAME);
|
|
17
|
+
const srcPath = srcDirectory ? resolve(buildDir, srcDirectory) : undefined;
|
|
18
|
+
const sourcePaths = [internalSrcPath, srcPath].filter(Boolean);
|
|
19
|
+
logFunctions({ internalSrcDirectory, internalSrcPath, logs, srcDirectory, srcPath });
|
|
20
|
+
const { declarations: internalDeclarations, importMap } = await parseManifest(internalSrcPath, systemLog);
|
|
21
|
+
const declarations = [...configDeclarations, ...internalDeclarations];
|
|
22
|
+
// If we're running in buildbot and the feature flag is enabled, we set the
|
|
23
|
+
// Deno cache dir to a directory that is persisted between builds.
|
|
24
|
+
const cacheDirectory = !isRunningLocally && featureFlags.edge_functions_cache_cli ? resolve(buildDir, DENO_CLI_CACHE_DIRECTORY) : undefined;
|
|
25
|
+
// Edge Bundler expects the dist directory to exist.
|
|
26
|
+
await fs.mkdir(distPath, { recursive: true });
|
|
27
|
+
try {
|
|
28
|
+
const { manifest } = await bundle(sourcePaths, distPath, declarations, {
|
|
29
|
+
basePath: buildDir,
|
|
30
|
+
cacheDirectory,
|
|
31
|
+
debug,
|
|
32
|
+
distImportMapPath,
|
|
33
|
+
featureFlags,
|
|
34
|
+
importMaps: [importMap].filter(Boolean),
|
|
35
|
+
systemLogger: featureFlags.edge_functions_system_logger ? systemLog : undefined,
|
|
36
|
+
});
|
|
37
|
+
systemLog('Edge Functions manifest:', manifest);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
tagBundlingError(error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
await validateEdgeFunctionsManifest({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory } });
|
|
44
|
+
return {};
|
|
45
|
+
};
|
|
74
46
|
// We run this core step if at least one of the functions directories (the
|
|
75
47
|
// one configured by the user or the internal one) exists. We use a dynamic
|
|
76
48
|
// `condition` because the directories might be created by the build command
|
|
77
49
|
// or plugins.
|
|
78
|
-
const hasEdgeFunctionsDirectories = async function ({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
const [userFunctions, internalFunctions] = await Promise.all([find([srcPath]), find([internalSrcPath])])
|
|
101
|
-
const userFunctionsSrcExists = await pathExists(srcPath)
|
|
102
|
-
const internalFunctionsSrc = internalSrcDirectory
|
|
103
|
-
|
|
104
|
-
logFunctionsToBundle({
|
|
105
|
-
logs,
|
|
106
|
-
userFunctions: userFunctions.map(({ name }) => name),
|
|
107
|
-
userFunctionsSrc,
|
|
108
|
-
userFunctionsSrcExists,
|
|
109
|
-
internalFunctions: internalFunctions.map(({ name }) => name),
|
|
110
|
-
internalFunctionsSrc,
|
|
111
|
-
type: 'Edge Functions',
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
50
|
+
const hasEdgeFunctionsDirectories = async function ({ buildDir, constants: { INTERNAL_EDGE_FUNCTIONS_SRC, EDGE_FUNCTIONS_SRC }, }) {
|
|
51
|
+
const hasFunctionsSrc = EDGE_FUNCTIONS_SRC !== undefined && EDGE_FUNCTIONS_SRC !== '';
|
|
52
|
+
if (hasFunctionsSrc) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const internalFunctionsSrc = resolve(buildDir, INTERNAL_EDGE_FUNCTIONS_SRC);
|
|
56
|
+
return await pathExists(internalFunctionsSrc);
|
|
57
|
+
};
|
|
58
|
+
const logFunctions = async ({ internalSrcDirectory, internalSrcPath, logs, srcDirectory: userFunctionsSrc, srcPath, }) => {
|
|
59
|
+
const [userFunctions, internalFunctions] = await Promise.all([find([srcPath]), find([internalSrcPath])]);
|
|
60
|
+
const userFunctionsSrcExists = await pathExists(srcPath);
|
|
61
|
+
const internalFunctionsSrc = internalSrcDirectory;
|
|
62
|
+
logFunctionsToBundle({
|
|
63
|
+
logs,
|
|
64
|
+
userFunctions: userFunctions.map(({ name }) => name),
|
|
65
|
+
userFunctionsSrc,
|
|
66
|
+
userFunctionsSrcExists,
|
|
67
|
+
internalFunctions: internalFunctions.map(({ name }) => name),
|
|
68
|
+
internalFunctionsSrc,
|
|
69
|
+
type: 'Edge Functions',
|
|
70
|
+
});
|
|
71
|
+
};
|
|
115
72
|
export const bundleEdgeFunctions = {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
73
|
+
event: 'onBuild',
|
|
74
|
+
coreStep,
|
|
75
|
+
coreStepId: 'edge_functions_bundling',
|
|
76
|
+
coreStepName: 'Edge Functions bundling',
|
|
77
|
+
coreStepDescription: () => 'Edge Functions bundling',
|
|
78
|
+
condition: hasEdgeFunctionsDirectories,
|
|
79
|
+
};
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { CUSTOM_ERROR_KEY, getErrorInfo, isBuildError } from '../../../error/info.js'
|
|
2
|
-
|
|
1
|
+
import { CUSTOM_ERROR_KEY, getErrorInfo, isBuildError } from '../../../error/info.js';
|
|
3
2
|
// If we have a custom error tagged with `functionsBundling` (which happens if
|
|
4
3
|
// there is an issue with user code), we tag it as coming from an edge function
|
|
5
4
|
// so that we can adjust the downstream error messages accordingly.
|
|
6
5
|
export const tagBundlingError = (error) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
functionType: 'edge',
|
|
20
|
-
}
|
|
21
|
-
}
|
|
6
|
+
if (!isBuildError(error)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const [errorInfo = {}] = getErrorInfo(error);
|
|
10
|
+
if (errorInfo.type !== 'functionsBundling') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
error[CUSTOM_ERROR_KEY].location = {
|
|
14
|
+
...error[CUSTOM_ERROR_KEY].location,
|
|
15
|
+
functionType: 'edge',
|
|
16
|
+
};
|
|
17
|
+
};
|