@netlify/zip-it-and-ship-it 12.2.0-experimental → 12.2.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2020 Netlify <team@netlify.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/bin.js CHANGED
File without changes
package/dist/config.d.ts CHANGED
@@ -18,7 +18,6 @@ export declare const functionConfig: z.ZodObject<{
18
18
  nodeVersion: z.ZodCatch<z.ZodOptional<z.ZodString>>;
19
19
  rustTargetDirectory: z.ZodCatch<z.ZodOptional<z.ZodString>>;
20
20
  schedule: z.ZodCatch<z.ZodOptional<z.ZodString>>;
21
- scopedToFunctionDirectory: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
22
21
  timeout: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
23
22
  zipGo: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
24
23
  nodeModuleFormat: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<{
@@ -37,7 +36,6 @@ export declare const functionConfig: z.ZodObject<{
37
36
  nodeVersion?: string | undefined;
38
37
  rustTargetDirectory?: string | undefined;
39
38
  schedule?: string | undefined;
40
- scopedToFunctionDirectory?: boolean | undefined;
41
39
  timeout?: number | undefined;
42
40
  zipGo?: boolean | undefined;
43
41
  nodeModuleFormat?: "cjs" | "esm" | undefined;
@@ -53,7 +51,6 @@ export declare const functionConfig: z.ZodObject<{
53
51
  nodeVersion?: unknown;
54
52
  rustTargetDirectory?: unknown;
55
53
  schedule?: unknown;
56
- scopedToFunctionDirectory?: unknown;
57
54
  timeout?: unknown;
58
55
  zipGo?: unknown;
59
56
  nodeModuleFormat?: unknown;
package/dist/config.js CHANGED
@@ -20,7 +20,6 @@ export const functionConfig = z.object({
20
20
  nodeVersion: z.string().optional().catch(undefined),
21
21
  rustTargetDirectory: z.string().optional().catch(undefined),
22
22
  schedule: z.string().optional().catch(undefined),
23
- scopedToFunctionDirectory: z.boolean().optional().catch(false),
24
23
  timeout: z.number().optional().catch(undefined),
25
24
  zipGo: z.boolean().optional().catch(undefined),
26
25
  // Temporary configuration property, only meant to be used by the deploy
@@ -38,14 +38,13 @@ export declare const inSourceConfig: z.ZodObject<Pick<{
38
38
  nodeVersion: z.ZodCatch<z.ZodOptional<z.ZodString>>;
39
39
  rustTargetDirectory: z.ZodCatch<z.ZodOptional<z.ZodString>>;
40
40
  schedule: z.ZodCatch<z.ZodOptional<z.ZodString>>;
41
- scopedToFunctionDirectory: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
42
41
  timeout: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
43
42
  zipGo: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
44
43
  nodeModuleFormat: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<{
45
44
  readonly COMMONJS: "cjs";
46
45
  readonly ESM: "esm";
47
46
  }>>>;
48
- }, "name" | "externalNodeModules" | "generator" | "includedFiles" | "ignoredNodeModules" | "nodeBundler" | "nodeVersion" | "schedule" | "scopedToFunctionDirectory" | "timeout"> & {
47
+ }, "name" | "externalNodeModules" | "generator" | "includedFiles" | "ignoredNodeModules" | "nodeBundler" | "nodeVersion" | "schedule" | "timeout"> & {
49
48
  method: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, z.ZodArray<z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, "many">]>, ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[], unknown>>;
50
49
  path: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
51
50
  excludedPath: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
@@ -84,7 +83,6 @@ export declare const inSourceConfig: z.ZodObject<Pick<{
84
83
  nodeBundler?: "none" | "esbuild" | "esbuild_zisi" | "nft" | "zisi" | undefined;
85
84
  nodeVersion?: string | undefined;
86
85
  schedule?: string | undefined;
87
- scopedToFunctionDirectory?: boolean | undefined;
88
86
  timeout?: number | undefined;
89
87
  method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined;
90
88
  excludedPath?: string[] | undefined;
@@ -107,7 +105,6 @@ export declare const inSourceConfig: z.ZodObject<Pick<{
107
105
  nodeBundler?: unknown;
108
106
  nodeVersion?: unknown;
109
107
  schedule?: unknown;
110
- scopedToFunctionDirectory?: unknown;
111
108
  timeout?: unknown;
112
109
  method?: unknown;
113
110
  excludedPath?: string | string[] | undefined;
@@ -138,7 +135,6 @@ export declare const augmentFunctionConfig: (mainFile: string, tomlConfig: Funct
138
135
  nodeVersion?: string | undefined;
139
136
  rustTargetDirectory?: string | undefined;
140
137
  schedule?: string | undefined;
141
- scopedToFunctionDirectory?: boolean | undefined;
142
138
  timeout?: number | undefined;
143
139
  zipGo?: boolean | undefined;
144
140
  nodeModuleFormat?: "cjs" | "esm" | undefined;
@@ -152,7 +148,6 @@ export declare const augmentFunctionConfig: (mainFile: string, tomlConfig: Funct
152
148
  nodeBundler?: "none" | "esbuild" | "esbuild_zisi" | "nft" | "zisi" | undefined;
153
149
  nodeVersion?: string | undefined;
154
150
  schedule?: string | undefined;
155
- scopedToFunctionDirectory?: boolean | undefined;
156
151
  timeout?: number | undefined;
157
152
  method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined;
158
153
  excludedPath?: string[] | undefined;
@@ -29,7 +29,6 @@ export const inSourceConfig = functionConfig
29
29
  nodeBundler: true,
30
30
  nodeVersion: true,
31
31
  schedule: true,
32
- scopedToFunctionDirectory: true,
33
32
  timeout: true,
34
33
  })
35
34
  .extend({
@@ -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,8 +58,7 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
48
58
  runtimeAPIVersion,
49
59
  });
50
60
  const bundler = getBundler(bundlerName);
51
- const functionBasePath = mergedConfig.scopedToFunctionDirectory && srcDir === srcPath ? srcDir : repositoryRoot;
52
- const { aliases = new Map(), cleanupFunction, basePath: finalBasePath, bundlerWarnings, includedFiles, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, rewrites = new Map(), srcFiles, } = await bundler.bundle({
61
+ const { aliases = new Map(), cleanupFunction, basePath: basePathFromBundler, bundlerWarnings, includedFiles, inputs, mainFile: finalMainFile = mainFile, moduleFormat, nativeNodeModules, rewrites = new Map(), srcFiles, } = await bundler.bundle({
53
62
  basePath,
54
63
  cache,
55
64
  config: mergedConfig,
@@ -60,14 +69,19 @@ const zipFunction = async function ({ archiveFormat, basePath, branch, cache, co
60
69
  mainFile,
61
70
  name,
62
71
  pluginsModulesPath,
63
- repositoryRoot: functionBasePath,
72
+ repositoryRoot,
64
73
  runtime,
65
74
  runtimeAPIVersion,
66
75
  srcDir,
67
76
  srcPath,
68
77
  stat,
69
78
  });
70
- createPluginsModulesPathAliases(srcFiles, pluginsModulesPath, aliases, finalBasePath);
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;
71
85
  const generator = mergedConfig?.generator || getInternalValue(isInternal);
72
86
  const zipResult = await zipNodeJs({
73
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 (srcFolder) {
68
- const filenames = await fs.readdir(srcFolder);
69
- return filenames.map((name) => join(srcFolder, name));
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.2.0-experimental",
3
+ "version": "12.2.1",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -42,9 +42,9 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@babel/parser": "^7.22.5",
45
- "@babel/types": "7.27.6",
45
+ "@babel/types": "7.28.0",
46
46
  "@netlify/binary-info": "^1.0.0",
47
- "@netlify/serverless-functions-api": "^2.1.2",
47
+ "@netlify/serverless-functions-api": "^2.1.3",
48
48
  "@vercel/nft": "0.29.4",
49
49
  "archiver": "^7.0.0",
50
50
  "common-path-prefix": "^3.0.0",
@@ -85,7 +85,7 @@
85
85
  "@types/unixify": "1.0.2",
86
86
  "@types/yargs": "17.0.33",
87
87
  "@vitest/coverage-v8": "^3.0.0",
88
- "browserslist": "4.25.0",
88
+ "browserslist": "4.25.1",
89
89
  "cardinal": "2.1.1",
90
90
  "cpy": "11.1.0",
91
91
  "decompress": "4.2.1",
@@ -99,5 +99,6 @@
99
99
  },
100
100
  "engines": {
101
101
  "node": ">=18.14.0"
102
- }
102
+ },
103
+ "gitHead": "a317a69700be1392b54976ef34b456ac47d75f5a"
103
104
  }