@netlify/zip-it-and-ship-it 9.18.1 → 9.19.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.
@@ -2,6 +2,7 @@ import type { InvocationMode } from './function.js';
2
2
  import type { FunctionResult } from './utils/format_result.js';
3
3
  import type { Route } from './utils/routes.js';
4
4
  interface ManifestFunction {
5
+ buildData?: Record<string, unknown>;
5
6
  invocationMode?: InvocationMode;
6
7
  mainFile: string;
7
8
  name: string;
package/dist/manifest.js CHANGED
@@ -12,12 +12,13 @@ export const createManifest = async ({ functions, path }) => {
12
12
  };
13
13
  await fs.writeFile(path, JSON.stringify(payload));
14
14
  };
15
- const formatFunctionForManifest = ({ bundler, displayName, generator, invocationMode, mainFile, name, path, routes, runtime, runtimeVersion, schedule, }) => {
15
+ const formatFunctionForManifest = ({ bundler, displayName, generator, invocationMode, mainFile, name, path, routes, runtime, runtimeVersion, runtimeAPIVersion, schedule, }) => {
16
16
  const manifestFunction = {
17
17
  bundler,
18
18
  displayName,
19
19
  generator,
20
20
  invocationMode,
21
+ buildData: { runtimeAPIVersion },
21
22
  mainFile,
22
23
  name,
23
24
  runtimeVersion,
@@ -7,7 +7,8 @@ import { getBasePath } from '../../utils/base_path.js';
7
7
  import { filterExcludedPaths, getPathsOfIncludedFiles } from '../../utils/included_files.js';
8
8
  import { MODULE_FORMAT, MODULE_FILE_EXTENSION, tsExtensions } from '../../utils/module_format.js';
9
9
  import { getNodeSupportMatrix } from '../../utils/node_version.js';
10
- import { getModuleFormat as getTSModuleFormat } from '../../utils/tsconfig.js';
10
+ import { getClosestPackageJson } from '../../utils/package_json.js';
11
+ import { getModuleFormat as getModuleFormatFromTsConfig } from '../../utils/tsconfig.js';
11
12
  import { processESM } from './es_modules.js';
12
13
  import { transpile } from './transpile.js';
13
14
  const appearsToBeModuleName = (name) => !name.startsWith('.');
@@ -50,9 +51,32 @@ const getIgnoreFunction = (config) => {
50
51
  return shouldIgnore;
51
52
  };
52
53
  };
54
+ /**
55
+ * Returns the module format that should be used when transpiling a TypeScript
56
+ * file.
57
+ */
58
+ const getTSModuleFormat = async (mainFile, repositoryRoot) => {
59
+ const fromTsConfig = getModuleFormatFromTsConfig(mainFile, repositoryRoot);
60
+ // If we can infer the module type from a `tsconfig.json` file, use that.
61
+ if (fromTsConfig !== undefined) {
62
+ return fromTsConfig;
63
+ }
64
+ // At this point, we need to infer the module type from the `type` field in
65
+ // the closest `package.json`.
66
+ try {
67
+ const packageJSON = await getClosestPackageJson(dirname(mainFile), repositoryRoot);
68
+ if (packageJSON?.contents.type === 'module') {
69
+ return MODULE_FORMAT.ESM;
70
+ }
71
+ }
72
+ catch {
73
+ // no-op
74
+ }
75
+ return MODULE_FORMAT.COMMONJS;
76
+ };
53
77
  const traceFilesAndTranspile = async function ({ basePath, cache, config, featureFlags, mainFile, pluginsModulesPath, name, repositoryRoot, runtimeAPIVersion, }) {
54
78
  const isTypeScript = tsExtensions.has(extname(mainFile));
55
- const tsFormat = isTypeScript ? getTSModuleFormat(mainFile, repositoryRoot) : MODULE_FORMAT.COMMONJS;
79
+ const tsFormat = isTypeScript ? await getTSModuleFormat(mainFile, repositoryRoot) : MODULE_FORMAT.COMMONJS;
56
80
  const tsAliases = new Map();
57
81
  const tsRewrites = new Map();
58
82
  const { fileList: dependencyPaths, esmFileList, reasons, } = await nodeFileTrace([mainFile], {
@@ -1 +1,6 @@
1
- export declare const getModuleFormat: (path: string, boundary?: string) => "cjs" | "esm";
1
+ /**
2
+ * Looks for a `tsconfig.json` file on a given path and, if one exists, returns
3
+ * the module format inferred from the `module` property. If no file is found
4
+ * or if no `module` property is defined, the function returns `undefined`.
5
+ */
6
+ export declare const getModuleFormat: (path: string, boundary?: string) => "cjs" | "esm" | undefined;
@@ -2,19 +2,25 @@ import { dirname, relative } from 'path';
2
2
  import { getTsconfig } from 'get-tsconfig';
3
3
  import { MODULE_FORMAT } from './module_format.js';
4
4
  const esmModuleValues = new Set(['es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext']);
5
- // Returns the module format that should be used for a TypeScript file at a
6
- // given path, by reading the associated `tsconfig.json` file if it exists.
5
+ /**
6
+ * Looks for a `tsconfig.json` file on a given path and, if one exists, returns
7
+ * the module format inferred from the `module` property. If no file is found
8
+ * or if no `module` property is defined, the function returns `undefined`.
9
+ */
7
10
  export const getModuleFormat = (path, boundary) => {
8
11
  const file = getTsconfig(path);
9
12
  if (!file) {
10
- return MODULE_FORMAT.COMMONJS;
13
+ return;
11
14
  }
12
15
  // If there is a boundary defined and the file we found is outside of it,
13
16
  // discard the file.
14
17
  if (boundary !== undefined && relative(boundary, dirname(file.path)).startsWith('..')) {
15
- return MODULE_FORMAT.COMMONJS;
18
+ return;
19
+ }
20
+ const moduleProp = file.config.compilerOptions?.module;
21
+ if (!moduleProp) {
22
+ return;
16
23
  }
17
- const moduleProp = file.config.compilerOptions?.module?.toLowerCase() ?? '';
18
24
  return esmModuleValues.has(moduleProp) ? MODULE_FORMAT.ESM : MODULE_FORMAT.COMMONJS;
19
25
  };
20
26
  //# sourceMappingURL=tsconfig.js.map
@@ -126,7 +126,8 @@ const createZipArchive = async function ({ aliases = new Map(), basePath, cache,
126
126
  addZipContent(archive, packageJSON.contents, packageJSON.path);
127
127
  }
128
128
  }
129
- const srcFilesInfos = await Promise.all(srcFiles.map((file) => addStat(cache, file)));
129
+ const deduplicatedSrcFiles = [...new Set(srcFiles)];
130
+ const srcFilesInfos = await Promise.all(deduplicatedSrcFiles.map((file) => addStat(cache, file)));
130
131
  // We ensure this is not async, so that the archive's checksum is
131
132
  // deterministic. Otherwise it depends on the order the files were added.
132
133
  srcFilesInfos.forEach(({ srcFile, stat }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "9.18.1",
3
+ "version": "9.19.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -88,21 +88,22 @@
88
88
  "yargs": "^17.0.0"
89
89
  },
90
90
  "devDependencies": {
91
- "@babel/types": "7.22.17",
91
+ "@babel/types": "7.22.19",
92
92
  "@netlify/eslint-config-node": "7.0.1",
93
93
  "@skn0tt/lambda-local": "2.0.3",
94
- "@types/archiver": "5.3.2",
94
+ "@types/archiver": "5.3.3",
95
95
  "@types/glob": "8.1.0",
96
- "@types/is-ci": "3.0.0",
97
- "@types/node": "14.18.56",
96
+ "@types/is-ci": "3.0.1",
97
+ "@types/node": "14.18.63",
98
98
  "@types/normalize-path": "3.0.0",
99
99
  "@types/resolve": "1.20.2",
100
- "@types/semver": "7.5.1",
101
- "@types/tmp": "0.2.3",
100
+ "@types/semver": "7.5.2",
101
+ "@types/tmp": "0.2.4",
102
102
  "@types/unixify": "1.0.0",
103
103
  "@types/yargs": "17.0.24",
104
104
  "@vitest/coverage-v8": "0.34.4",
105
- "browserslist": "4.21.10",
105
+ "adm-zip": "0.5.10",
106
+ "browserslist": "4.21.11",
106
107
  "cardinal": "2.1.1",
107
108
  "cpy": "9.0.1",
108
109
  "deepmerge": "4.3.1",