@netlify/zip-it-and-ship-it 9.3.0 → 9.3.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.
|
@@ -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 { transpile } from './transpile.js';
|
|
7
10
|
const getPatchedESMPackages = async (packages, cache) => {
|
|
8
11
|
const patchedPackages = await Promise.all(packages.map((path) => patchESMPackage(path, cache)));
|
|
@@ -30,24 +33,41 @@ export const processESM = async ({ basePath, cache, config, esmPaths, featureFla
|
|
|
30
33
|
const extension = extname(mainFile);
|
|
31
34
|
// If this is a .mjs file and we want to output pure ESM files, we don't need
|
|
32
35
|
// to transpile anything.
|
|
33
|
-
if (extension === MODULE_FILE_EXTENSION.MJS &&
|
|
36
|
+
if (extension === MODULE_FILE_EXTENSION.MJS &&
|
|
37
|
+
(featureFlags.zisi_pure_esm_mjs || featureFlags.zisi_functions_api_v2)) {
|
|
34
38
|
return {
|
|
35
39
|
moduleFormat: MODULE_FORMAT.ESM,
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
const entrypointIsESM = isEntrypointESM({ basePath, esmPaths, mainFile });
|
|
39
43
|
if (!entrypointIsESM) {
|
|
44
|
+
if (featureFlags.zisi_functions_api_v2) {
|
|
45
|
+
throw new FunctionBundlingUserError(`The function '${name}' must use the ES module syntax. To learn more, visit https://ntl.fyi/esm.`, {
|
|
46
|
+
functionName: name,
|
|
47
|
+
runtime: RUNTIME.JAVASCRIPT,
|
|
48
|
+
bundler: NODE_BUNDLER.NFT,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
40
51
|
return {
|
|
41
52
|
moduleFormat: MODULE_FORMAT.COMMONJS,
|
|
42
53
|
};
|
|
43
54
|
}
|
|
44
55
|
const packageJson = await getPackageJsonIfAvailable(dirname(mainFile));
|
|
45
56
|
const nodeSupport = getNodeSupportMatrix(config.nodeVersion);
|
|
46
|
-
if (featureFlags.zisi_pure_esm
|
|
57
|
+
if ((featureFlags.zisi_pure_esm || featureFlags.zisi_functions_api_v2) &&
|
|
58
|
+
packageJson.type === 'module' &&
|
|
59
|
+
nodeSupport.esm) {
|
|
47
60
|
return {
|
|
48
61
|
moduleFormat: MODULE_FORMAT.ESM,
|
|
49
62
|
};
|
|
50
63
|
}
|
|
64
|
+
if (featureFlags.zisi_functions_api_v2) {
|
|
65
|
+
throw new FunctionBundlingUserError(`The function '${name}' must use the ES module syntax. To learn more, visit https://ntl.fyi/esm.`, {
|
|
66
|
+
functionName: name,
|
|
67
|
+
runtime: RUNTIME.JAVASCRIPT,
|
|
68
|
+
bundler: NODE_BUNDLER.NFT,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
51
71
|
const rewrites = await transpileESM({ basePath, cache, config, esmPaths, reasons, name });
|
|
52
72
|
return {
|
|
53
73
|
moduleFormat: MODULE_FORMAT.COMMONJS,
|
|
@@ -9,7 +9,7 @@ const getEntryFileContents = (mainPath, moduleFormat, featureFlags) => {
|
|
|
9
9
|
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
10
10
|
if (featureFlags.zisi_functions_api_v2) {
|
|
11
11
|
return [
|
|
12
|
-
`import func from '${importPath}'`,
|
|
12
|
+
`import * as func from '${importPath}'`,
|
|
13
13
|
`import { getLambdaHandler } from './${BOOTSTRAP_FILE_NAME}'`,
|
|
14
14
|
`export const handler = getLambdaHandler(func)`,
|
|
15
15
|
].join(';');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.1",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"normalize-path": "^3.0.0",
|
|
79
79
|
"p-map": "^5.0.0",
|
|
80
80
|
"path-exists": "^5.0.0",
|
|
81
|
-
"precinct": "^
|
|
81
|
+
"precinct": "^11.0.0",
|
|
82
82
|
"require-package-name": "^2.0.1",
|
|
83
83
|
"resolve": "^2.0.0-next.1",
|
|
84
84
|
"semver": "^7.0.0",
|