@netlify/zip-it-and-ship-it 12.1.5 → 12.2.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/dist/runtimes/node/index.js +19 -4
- package/dist/utils/fs.js +19 -3
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extname, join } from 'path';
|
|
1
|
+
import { dirname, extname, join } from 'path';
|
|
2
2
|
import { copyFile } from 'copy-file';
|
|
3
3
|
import { INVOCATION_MODE } from '../../function.js';
|
|
4
4
|
import { Priority } from '../../priority.js';
|
|
@@ -36,10 +36,20 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
|
|
|
36
36
|
await copyFile(srcPath, destPath);
|
|
37
37
|
return { config, path: destPath, entryFilename: '' };
|
|
38
38
|
}
|
|
39
|
+
// If the function is inside the plugins modules path, we need to treat that
|
|
40
|
+
// directory as the base path, not as an extra directory used for module
|
|
41
|
+
// resolution. So we unset `pluginsModulesPath` for this function. We do
|
|
42
|
+
// this because we want the modules used by those functions to be isolated
|
|
43
|
+
// from the ones defined in the project root.
|
|
44
|
+
let pluginsModulesPath = await getPluginsModulesPath(srcDir);
|
|
45
|
+
const isInPluginsModulesPath = Boolean(pluginsModulesPath && srcDir.startsWith(pluginsModulesPath));
|
|
46
|
+
if (isInPluginsModulesPath) {
|
|
47
|
+
basePath = dirname(pluginsModulesPath);
|
|
48
|
+
pluginsModulesPath = undefined;
|
|
49
|
+
}
|
|
39
50
|
const staticAnalysisResult = await parseFile(mainFile, { functionName: name });
|
|
40
51
|
const runtimeAPIVersion = staticAnalysisResult.runtimeAPIVersion === 2 ? 2 : 1;
|
|
41
52
|
const mergedConfig = augmentFunctionConfig(mainFile, config, staticAnalysisResult.config);
|
|
42
|
-
const pluginsModulesPath = await getPluginsModulesPath(srcDir);
|
|
43
53
|
const bundlerName = await getBundlerName({
|
|
44
54
|
config: mergedConfig,
|
|
45
55
|
extension,
|
|
@@ -48,7 +58,7 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
|
|
|
48
58
|
runtimeAPIVersion,
|
|
49
59
|
});
|
|
50
60
|
const bundler = getBundler(bundlerName);
|
|
51
|
-
const { aliases = new Map(), cleanupFunction, basePath:
|
|
61
|
+
const { aliases = new Map(), cleanupFunction, basePath: basePathFromBundler, bundlerWarnings, includedFiles, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, rewrites = new Map(), srcFiles, } = await bundler.bundle({
|
|
52
62
|
basePath,
|
|
53
63
|
cache,
|
|
54
64
|
config: mergedConfig,
|
|
@@ -66,7 +76,12 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
|
|
|
66
76
|
srcPath,
|
|
67
77
|
stat,
|
|
68
78
|
});
|
|
69
|
-
createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases,
|
|
79
|
+
createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases, basePathFromBundler);
|
|
80
|
+
// If the function is inside the plugins modules path, we need to force the
|
|
81
|
+
// base path to be that directory. If not, we'll run the logic that finds the
|
|
82
|
+
// common path prefix and that will break module resolution, as the modules
|
|
83
|
+
// will no longer be inside a `node_modules` directory.
|
|
84
|
+
const finalBasePath = isInPluginsModulesPath ? basePath : basePathFromBundler;
|
|
70
85
|
const generator = mergedConfig?.generator || getInternalValue(isInternal);
|
|
71
86
|
const zipResult = await zipNodeJs({
|
|
72
87
|
aliases,
|
package/dist/utils/fs.js
CHANGED
|
@@ -64,9 +64,25 @@ ${errorMessages.join('\n')}`);
|
|
|
64
64
|
}
|
|
65
65
|
return validDirectories.flat();
|
|
66
66
|
};
|
|
67
|
-
const listFunctionsDirectory = async function (
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const listFunctionsDirectory = async function (srcPath) {
|
|
68
|
+
try {
|
|
69
|
+
const filenames = await fs.readdir(srcPath);
|
|
70
|
+
return filenames.map((name) => join(srcPath, name));
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
// We could move the `stat` call up and use its result to decide whether to
|
|
74
|
+
// treat the path as a file or as a directory. We're doing it this way since
|
|
75
|
+
// historically this method only supported directories, and only later we
|
|
76
|
+
// made it accept files. To roll out that change as safely as possible, we
|
|
77
|
+
// keep the directory flow untouched and look for files only as a fallback.
|
|
78
|
+
if (error.code === 'ENOTDIR') {
|
|
79
|
+
const stat = await fs.stat(srcPath);
|
|
80
|
+
if (stat.isFile()) {
|
|
81
|
+
return srcPath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
70
86
|
};
|
|
71
87
|
export const resolveFunctionsDirectories = (input) => {
|
|
72
88
|
const directories = Array.isArray(input) ? input : [input];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=18.14.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "1c03ad22e24821b3a4803e54e8eeaa5a15c509d6"
|
|
104
104
|
}
|