@netlify/zip-it-and-ship-it 15.4.2 → 15.5.1
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/dist/feature_flags.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const defaultFlags: {
|
|
|
5
5
|
readonly zisi_pure_esm_mjs: false;
|
|
6
6
|
readonly zisi_output_cjs_extension: false;
|
|
7
7
|
readonly zisi_esbuild_fail_double_glob: false;
|
|
8
|
+
readonly zisi_error_cjs_in_esm_scope: false;
|
|
8
9
|
readonly zisi_add_instrumentation_loader: true;
|
|
9
10
|
readonly zisi_netlify_play: false;
|
|
10
11
|
readonly zisi_container_functions: false;
|
|
@@ -17,6 +18,7 @@ export declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
|
17
18
|
readonly zisi_pure_esm_mjs: false;
|
|
18
19
|
readonly zisi_output_cjs_extension: false;
|
|
19
20
|
readonly zisi_esbuild_fail_double_glob: false;
|
|
21
|
+
readonly zisi_error_cjs_in_esm_scope: false;
|
|
20
22
|
readonly zisi_add_instrumentation_loader: true;
|
|
21
23
|
readonly zisi_netlify_play: false;
|
|
22
24
|
readonly zisi_container_functions: false;
|
package/dist/feature_flags.js
CHANGED
|
@@ -14,6 +14,9 @@ export const defaultFlags = {
|
|
|
14
14
|
zisi_output_cjs_extension: false,
|
|
15
15
|
// If multiple glob stars are in includedFiles, fail the build instead of warning.
|
|
16
16
|
zisi_esbuild_fail_double_glob: false,
|
|
17
|
+
// Fail the build when a CommonJS function file sits inside a `"type": "module"`
|
|
18
|
+
// package scope, instead of producing a bundle that fails at runtime.
|
|
19
|
+
zisi_error_cjs_in_esm_scope: false,
|
|
17
20
|
// Adds the `___netlify-telemetry.mjs` file to the function bundle.
|
|
18
21
|
zisi_add_instrumentation_loader: true,
|
|
19
22
|
zisi_netlify_play: false,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { basename, dirname, extname, resolve } from 'path';
|
|
2
|
+
import { FunctionBundlingUserError } from '../../../../utils/error.js';
|
|
2
3
|
import { cachedReadFile } from '../../../../utils/fs.js';
|
|
4
|
+
import { RUNTIME } from '../../../runtime.js';
|
|
3
5
|
import { MODULE_FILE_EXTENSION, MODULE_FORMAT } from '../../utils/module_format.js';
|
|
4
6
|
import { getNodeSupportMatrix } from '../../utils/node_version.js';
|
|
5
7
|
import { getPackageJsonIfAvailable } from '../../utils/package_json.js';
|
|
8
|
+
import { NODE_BUNDLER } from '../types.js';
|
|
6
9
|
import { transpileESMToCJS } from './transpile.js';
|
|
7
10
|
const getPatchedESMPackages = async (packages, cache) => {
|
|
8
11
|
const patchedPackages = await Promise.all(packages.map((path) => patchESMPackage(path, cache)));
|
|
@@ -36,6 +39,16 @@ export const processESM = async ({ basePath, cache, config, esmPaths, featureFla
|
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
if (!isEntrypointESM({ basePath, esmPaths, mainFile })) {
|
|
42
|
+
// The entrypoint is a `.js` file with no ESM syntax. If it lives inside a
|
|
43
|
+
// `"type": "module"` package scope, the `package.json` is traced into the
|
|
44
|
+
// bundle verbatim and Node.js will load the file as an ES module at
|
|
45
|
+
// runtime, where its CommonJS globals are not defined.
|
|
46
|
+
if (featureFlags.zisi_error_cjs_in_esm_scope && extension === MODULE_FILE_EXTENSION.JS) {
|
|
47
|
+
const scopePackageJson = await getPackageJsonIfAvailable(dirname(mainFile));
|
|
48
|
+
if (scopePackageJson.type === 'module') {
|
|
49
|
+
throw new FunctionBundlingUserError(`The function file '${mainFile}' is a CommonJS module, but the closest 'package.json' declares '"type": "module"', so Node.js will fail to load it at runtime. Either use ESM syntax ('import'/'export'), rename the file extension to '.cjs', or remove '"type": "module"' from the 'package.json'.`, { functionName: name, runtime: RUNTIME.JAVASCRIPT, bundler: NODE_BUNDLER.NFT });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
39
52
|
return {
|
|
40
53
|
moduleFormat: MODULE_FORMAT.COMMONJS,
|
|
41
54
|
};
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type UserError = Error & {
|
|
|
13
13
|
customErrorInfo: CustomErrorInfo;
|
|
14
14
|
};
|
|
15
15
|
export declare class FunctionBundlingUserError extends Error {
|
|
16
|
+
customErrorInfo: CustomErrorInfo;
|
|
16
17
|
constructor(message: string, customErrorInfo: CustomErrorLocation);
|
|
17
18
|
static addCustomErrorInfo(error: Error, customErrorInfo: CustomErrorLocation): UserError;
|
|
18
19
|
}
|
package/dist/utils/error.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
const createFunctionsBundlingErrorInfo = (location) => ({
|
|
2
|
+
type: 'functionsBundling',
|
|
3
|
+
location,
|
|
4
|
+
});
|
|
1
5
|
export class FunctionBundlingUserError extends Error {
|
|
6
|
+
customErrorInfo;
|
|
2
7
|
constructor(message, customErrorInfo) {
|
|
3
8
|
super(message);
|
|
4
9
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
5
10
|
this.name = 'FunctionBundlingUserError';
|
|
6
11
|
Error.captureStackTrace(this, FunctionBundlingUserError);
|
|
7
|
-
|
|
12
|
+
this.customErrorInfo = createFunctionsBundlingErrorInfo(customErrorInfo);
|
|
8
13
|
}
|
|
9
14
|
static addCustomErrorInfo(error, customErrorInfo) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
location: customErrorInfo,
|
|
13
|
-
};
|
|
14
|
-
error.customErrorInfo = info;
|
|
15
|
+
;
|
|
16
|
+
error.customErrorInfo = createFunctionsBundlingErrorInfo(customErrorInfo);
|
|
15
17
|
return error;
|
|
16
18
|
}
|
|
17
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.5.1",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"resolve": "^2.0.0-next.1",
|
|
70
70
|
"semver": "^7.3.8",
|
|
71
71
|
"tmp-promise": "^3.0.2",
|
|
72
|
-
"toml": "^
|
|
72
|
+
"toml": "^4.2.0",
|
|
73
73
|
"unixify": "^1.0.0",
|
|
74
74
|
"urlpattern-polyfill": "8.0.2",
|
|
75
75
|
"yargs": "^17.0.0",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@types/unixify": "1.0.2",
|
|
87
87
|
"@types/yargs": "17.0.35",
|
|
88
88
|
"@vitest/coverage-v8": "^3.0.0",
|
|
89
|
-
"browserslist": "4.28.
|
|
89
|
+
"browserslist": "4.28.7",
|
|
90
90
|
"cardinal": "2.1.1",
|
|
91
91
|
"cpy": "11.1.0",
|
|
92
92
|
"decompress": "4.2.1",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=22.12.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "d30dc9ad0c79ea23f01354f2487187d3398f5de2"
|
|
104
104
|
}
|