@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,60 +1,50 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
import { dirname, join, resolve } from 'path'
|
|
3
|
-
import { pathToFileURL } from 'url'
|
|
4
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { dirname, join, resolve } from 'path';
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
5
4
|
const parseManifest = async (internalSourceDirectory, systemLog) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const manifestPath = join(internalSourceDirectory, 'manifest.json');
|
|
6
|
+
try {
|
|
7
|
+
const data = await fs.readFile(manifestPath);
|
|
8
|
+
const manifest = JSON.parse(data);
|
|
9
|
+
if (manifest.version !== 1) {
|
|
10
|
+
throw new Error('Unsupported manifest version');
|
|
11
|
+
}
|
|
12
|
+
const result = {
|
|
13
|
+
declarations: manifest.functions,
|
|
14
|
+
};
|
|
15
|
+
if (manifest.import_map) {
|
|
16
|
+
const importMapPath = resolve(dirname(manifestPath), manifest.import_map);
|
|
17
|
+
const importMap = await readImportMap(importMapPath);
|
|
18
|
+
return {
|
|
19
|
+
...result,
|
|
20
|
+
importMap: {
|
|
21
|
+
baseURL: pathToFileURL(importMapPath),
|
|
22
|
+
...importMap,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
14
27
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code !== 'ENOENT') {
|
|
30
|
+
systemLog('Error while parsing internal edge functions manifest:', error);
|
|
31
|
+
}
|
|
18
32
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
importMap
|
|
27
|
-
|
|
28
|
-
...importMap,
|
|
29
|
-
},
|
|
30
|
-
}
|
|
33
|
+
return {
|
|
34
|
+
declarations: [],
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const readImportMap = async (path) => {
|
|
38
|
+
try {
|
|
39
|
+
const data = await fs.readFile(path);
|
|
40
|
+
const importMap = JSON.parse(data);
|
|
41
|
+
return importMap;
|
|
31
42
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} catch (error) {
|
|
35
|
-
if (error.code !== 'ENOENT') {
|
|
36
|
-
systemLog('Error while parsing internal edge functions manifest:', error)
|
|
43
|
+
catch {
|
|
44
|
+
// no-op
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const readImportMap = async (path) => {
|
|
46
|
-
try {
|
|
47
|
-
const data = await fs.readFile(path)
|
|
48
|
-
const importMap = JSON.parse(data)
|
|
49
|
-
|
|
50
|
-
return importMap
|
|
51
|
-
} catch {
|
|
52
|
-
// no-op
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
imports: {},
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { parseManifest }
|
|
46
|
+
return {
|
|
47
|
+
imports: {},
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export { parseManifest };
|
package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js
CHANGED
|
@@ -1,90 +1,75 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
import { join, resolve } from 'path'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ajv = new Ajv({ allErrors: true })
|
|
10
|
-
ajvErrors(ajv)
|
|
11
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join, resolve } from 'path';
|
|
3
|
+
import Ajv from 'ajv';
|
|
4
|
+
import ajvErrors from 'ajv-errors';
|
|
5
|
+
import { addErrorInfo } from '../../../error/info.js';
|
|
6
|
+
const ajv = new Ajv({ allErrors: true });
|
|
7
|
+
ajvErrors(ajv);
|
|
12
8
|
// regex pattern for manifest route pattern
|
|
13
9
|
// checks if the pattern string starts with ^ and ends with $
|
|
14
10
|
// we define this format in edge-bundler:
|
|
15
11
|
// https://github.com/netlify/edge-bundler/blob/main/src/manifest.ts#L66
|
|
16
|
-
const normalizedPatternRegex =
|
|
12
|
+
const normalizedPatternRegex = /^\^.*\$$/;
|
|
17
13
|
ajv.addFormat('regexPattern', {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
|
|
14
|
+
async: true,
|
|
15
|
+
validate: (data) => normalizedPatternRegex.test(data),
|
|
16
|
+
});
|
|
22
17
|
const bundlesSchema = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
18
|
+
$async: true,
|
|
19
|
+
type: 'object',
|
|
20
|
+
required: ['asset', 'format'],
|
|
21
|
+
properties: {
|
|
22
|
+
asset: { type: 'string' },
|
|
23
|
+
format: { type: 'string' },
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
};
|
|
33
27
|
const routesSchema = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
additionalProperties: false,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const edgeManifestSchema = {
|
|
46
|
-
$async: true,
|
|
47
|
-
type: 'object',
|
|
48
|
-
required: ['bundles', 'routes', 'bundler_version'],
|
|
49
|
-
properties: {
|
|
50
|
-
bundles: {
|
|
51
|
-
type: 'array',
|
|
52
|
-
items: bundlesSchema,
|
|
28
|
+
$async: true,
|
|
29
|
+
type: 'object',
|
|
30
|
+
required: ['function', 'pattern'],
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: 'string' },
|
|
33
|
+
function: { type: 'string' },
|
|
34
|
+
pattern: { type: 'string', format: 'regexPattern', errorMessage: `must match format ${normalizedPatternRegex}` },
|
|
53
35
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
};
|
|
38
|
+
const edgeManifestSchema = {
|
|
39
|
+
$async: true,
|
|
40
|
+
type: 'object',
|
|
41
|
+
required: ['bundles', 'routes', 'bundler_version'],
|
|
42
|
+
properties: {
|
|
43
|
+
bundles: {
|
|
44
|
+
type: 'array',
|
|
45
|
+
items: bundlesSchema,
|
|
46
|
+
},
|
|
47
|
+
routes: {
|
|
48
|
+
type: 'array',
|
|
49
|
+
items: routesSchema,
|
|
50
|
+
},
|
|
51
|
+
bundler_version: { type: 'string' },
|
|
57
52
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
errorMessage: "Couldn't validate Edge Functions manifest.json",
|
|
62
|
-
}
|
|
63
|
-
|
|
53
|
+
additionalProperties: false,
|
|
54
|
+
errorMessage: "Couldn't validate Edge Functions manifest.json",
|
|
55
|
+
};
|
|
64
56
|
const validateManifest = async (manifestData) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
addErrorInfo(parsedErr, { type: 'coreStep' })
|
|
86
|
-
throw new Error(isValidationErr ? JSON.stringify(parsedErr, null, 2) : parsedErr)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return {}
|
|
90
|
-
}
|
|
57
|
+
const validate = ajv.compile(edgeManifestSchema);
|
|
58
|
+
await validate(manifestData);
|
|
59
|
+
};
|
|
60
|
+
export const validateEdgeFunctionsManifest = async function ({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory }, }) {
|
|
61
|
+
try {
|
|
62
|
+
const edgeFunctionsDistPath = resolve(buildDir, distDirectory);
|
|
63
|
+
const manifestPath = join(edgeFunctionsDistPath, 'manifest.json');
|
|
64
|
+
const data = await fs.readFile(manifestPath);
|
|
65
|
+
const manifestData = JSON.parse(data);
|
|
66
|
+
await validateManifest(manifestData);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const isValidationErr = error instanceof Ajv.ValidationError;
|
|
70
|
+
const parsedErr = isValidationErr ? error.errors : error;
|
|
71
|
+
addErrorInfo(parsedErr, { type: 'coreStep' });
|
|
72
|
+
throw new Error(isValidationErr ? JSON.stringify(parsedErr, null, 2) : parsedErr);
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
75
|
+
};
|
|
@@ -1,133 +1,99 @@
|
|
|
1
|
-
import readdirp from 'readdirp'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const MODULE_NOT_FOUND_ESBUILD_REGEXP = /^Could not resolve ['"]([^'"]+)/
|
|
7
|
-
const MODULE_NOT_FOUND_REGEXP = /Cannot find module ['"]([^'"]+)/
|
|
8
|
-
|
|
1
|
+
import readdirp from 'readdirp';
|
|
2
|
+
import { addErrorInfo } from '../../error/info.js';
|
|
3
|
+
const MODULE_NOT_FOUND_CODE = 'MODULE_NOT_FOUND';
|
|
4
|
+
const MODULE_NOT_FOUND_ESBUILD_REGEXP = /^Could not resolve ['"]([^'"]+)/;
|
|
5
|
+
const MODULE_NOT_FOUND_REGEXP = /Cannot find module ['"]([^'"]+)/;
|
|
9
6
|
// Handle errors coming from zip-it-and-ship-it
|
|
10
7
|
export const getZipError = async function (error, functionsSrc) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return error
|
|
22
|
-
}
|
|
23
|
-
|
|
8
|
+
const moduleNotFoundError = await getModuleNotFoundError(error, functionsSrc);
|
|
9
|
+
if (moduleNotFoundError) {
|
|
10
|
+
return moduleNotFoundError;
|
|
11
|
+
}
|
|
12
|
+
if (isPackageJsonError(error)) {
|
|
13
|
+
return getPackageJsonError(error);
|
|
14
|
+
}
|
|
15
|
+
return error;
|
|
16
|
+
};
|
|
24
17
|
const getModuleNotFoundError = async function (error, functionsSrc) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return errorFromEsbuild
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
18
|
+
const errorFromZisi = await getModuleNotFoundErrorFromZISI(error, functionsSrc);
|
|
19
|
+
if (errorFromZisi) {
|
|
20
|
+
return errorFromZisi;
|
|
21
|
+
}
|
|
22
|
+
const errorFromEsbuild = await getModuleNotFoundErrorFromEsbuild(error, functionsSrc);
|
|
23
|
+
if (errorFromEsbuild) {
|
|
24
|
+
return errorFromEsbuild;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
38
27
|
const getModuleNotFoundErrorObject = async ({ error, functionsSrc, moduleNames }) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return error
|
|
45
|
-
}
|
|
46
|
-
|
|
28
|
+
const message = await getModuleNotFoundMessage(functionsSrc, moduleNames);
|
|
29
|
+
error.message = `${message}\n\n${error.message}`;
|
|
30
|
+
addErrorInfo(error, { type: 'dependencies' });
|
|
31
|
+
return error;
|
|
32
|
+
};
|
|
47
33
|
const getModuleNotFoundMessage = async function (functionsSrc, moduleNames) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return getLocalInstallMessage(moduleNames)
|
|
57
|
-
}
|
|
58
|
-
|
|
34
|
+
if (moduleNames.length === 0 || !(await lacksNodeModules(functionsSrc))) {
|
|
35
|
+
return MODULE_NOT_FOUND_MESSAGE;
|
|
36
|
+
}
|
|
37
|
+
if (moduleNames.filter(Boolean).some(isLocalPath)) {
|
|
38
|
+
return PATH_NOT_FOUND_MESSAGE;
|
|
39
|
+
}
|
|
40
|
+
return getLocalInstallMessage(moduleNames);
|
|
41
|
+
};
|
|
59
42
|
const isLocalPath = function (moduleName) {
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
43
|
+
return moduleName.startsWith('.') || moduleName.startsWith('/');
|
|
44
|
+
};
|
|
63
45
|
const getModuleNotFoundErrorFromEsbuild = function (error, functionsSrc) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
46
|
+
const { errors = [] } = error;
|
|
47
|
+
const modulesNotFound = errors.reduce((modules, errorObject) => {
|
|
48
|
+
const match = errorObject.text.match(MODULE_NOT_FOUND_ESBUILD_REGEXP);
|
|
49
|
+
if (!match) {
|
|
50
|
+
return modules;
|
|
51
|
+
}
|
|
52
|
+
return [...modules, match[1]];
|
|
53
|
+
}, []);
|
|
54
|
+
if (modulesNotFound.length === 0) {
|
|
55
|
+
return;
|
|
70
56
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, [])
|
|
74
|
-
|
|
75
|
-
if (modulesNotFound.length === 0) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: modulesNotFound })
|
|
80
|
-
}
|
|
81
|
-
|
|
57
|
+
return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: modulesNotFound });
|
|
58
|
+
};
|
|
82
59
|
const getModuleNotFoundErrorFromZISI = function (error, functionsSrc) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: moduleName ? [moduleName] : [] })
|
|
90
|
-
}
|
|
91
|
-
|
|
60
|
+
if (!(error instanceof Error && error.code === MODULE_NOT_FOUND_CODE)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const moduleName = getModuleNameFromZISIError(error);
|
|
64
|
+
return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: moduleName ? [moduleName] : [] });
|
|
65
|
+
};
|
|
92
66
|
// This error message always include the same words
|
|
93
67
|
const getModuleNameFromZISIError = function (error) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return result[1]
|
|
104
|
-
}
|
|
105
|
-
|
|
68
|
+
if (typeof error.message !== 'string') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const result = MODULE_NOT_FOUND_REGEXP.exec(error.message);
|
|
72
|
+
if (result === null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return result[1];
|
|
76
|
+
};
|
|
106
77
|
// Netlify Functions has a `package.json` but no `node_modules`
|
|
107
78
|
const lacksNodeModules = async function (functionsSrc) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
|
|
79
|
+
return (functionsSrc !== undefined &&
|
|
80
|
+
(await hasFunctionRootFile('package.json', functionsSrc)) &&
|
|
81
|
+
!(await hasFunctionRootFile('node_modules', functionsSrc)));
|
|
82
|
+
};
|
|
115
83
|
// Functions can be either files or directories, so we need to check on two
|
|
116
84
|
// depth levels
|
|
117
85
|
const hasFunctionRootFile = async function (filename, functionsSrc) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
86
|
+
const files = await readdirp.promise(functionsSrc, { depth: 1, fileFilter: filename });
|
|
87
|
+
return files.length !== 0;
|
|
88
|
+
};
|
|
122
89
|
const MODULE_NOT_FOUND_MESSAGE = `A Netlify Function failed to require one of its dependencies.
|
|
123
|
-
Please make sure it is present in the site's top-level "package.json"
|
|
90
|
+
Please make sure it is present in the site's top-level "package.json".`;
|
|
124
91
|
const PATH_NOT_FOUND_MESSAGE = `A Netlify Function failed to require a local file.
|
|
125
|
-
Please make sure the file exists and its path is correctly spelled
|
|
126
|
-
|
|
92
|
+
Please make sure the file exists and its path is correctly spelled.`;
|
|
127
93
|
// A common mistake is to assume Netlify Functions dependencies are
|
|
128
94
|
// automatically installed. This checks for this pattern.
|
|
129
95
|
const getLocalInstallMessage = function (modules) {
|
|
130
|
-
|
|
96
|
+
const genericMessage = `
|
|
131
97
|
|
|
132
98
|
By default, dependencies inside a Netlify Function's "package.json" are not automatically installed.
|
|
133
99
|
There are several ways to fix this problem:
|
|
@@ -137,27 +103,21 @@ There are several ways to fix this problem:
|
|
|
137
103
|
|
|
138
104
|
[[plugins]]
|
|
139
105
|
package = "@netlify/plugin-functions-install-core"
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return `A Netlify Function is using dependencies that have not been installed yet: ${moduleNames}${genericMessage}`
|
|
149
|
-
}
|
|
150
|
-
|
|
106
|
+
`;
|
|
107
|
+
if (modules.length === 1) {
|
|
108
|
+
return `A Netlify Function is using "${modules[0]}" but that dependency has not been installed yet.${genericMessage}`;
|
|
109
|
+
}
|
|
110
|
+
const moduleNames = modules.map((name) => `"${name}"`).join(', ');
|
|
111
|
+
return `A Netlify Function is using dependencies that have not been installed yet: ${moduleNames}${genericMessage}`;
|
|
112
|
+
};
|
|
151
113
|
// We need to load the site's `package.json` when bundling Functions. This is
|
|
152
114
|
// because `optionalDependencies` can make `import()` fail, but we don't want
|
|
153
115
|
// to error then. However, if the `package.json` is invalid, we fail the build.
|
|
154
116
|
const isPackageJsonError = function (error) {
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const PACKAGE_JSON_ORIGINAL_MESSAGES = ['is invalid JSON', 'in JSON at position']
|
|
159
|
-
|
|
117
|
+
return PACKAGE_JSON_ORIGINAL_MESSAGES.some((msg) => error.message.includes(msg));
|
|
118
|
+
};
|
|
119
|
+
const PACKAGE_JSON_ORIGINAL_MESSAGES = ['is invalid JSON', 'in JSON at position'];
|
|
160
120
|
const getPackageJsonError = function (error) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
121
|
+
addErrorInfo(error, { type: 'resolveConfig' });
|
|
122
|
+
return error;
|
|
123
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const getZisiFeatureFlags = (featureFlags) => ({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
2
|
+
...featureFlags,
|
|
3
|
+
defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
|
|
4
|
+
parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
|
|
5
|
+
traceWithNft: featureFlags.buildbot_zisi_trace_nft,
|
|
6
|
+
});
|