@netlify/zip-it-and-ship-it 4.29.2 → 4.30.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/manifest.js CHANGED
@@ -25,11 +25,11 @@ const createManifest = ({ functions, path }) => __awaiter(void 0, void 0, void 0
25
25
  yield (0, fs_1.writeFile)(path, JSON.stringify(payload));
26
26
  });
27
27
  exports.createManifest = createManifest;
28
- const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }) => ({
28
+ const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }) => ({
29
29
  mainFile,
30
30
  name,
31
31
  path: (0, path_1.resolve)(path),
32
32
  runtime,
33
- schedule: config.schedule,
33
+ schedule,
34
34
  });
35
35
  //# sourceMappingURL=manifest.js.map
@@ -17,6 +17,7 @@ const fs_1 = require("../../../../utils/fs");
17
17
  const bundler_target_1 = require("./bundler_target");
18
18
  const plugin_dynamic_imports_1 = require("./plugin_dynamic_imports");
19
19
  const plugin_native_modules_1 = require("./plugin_native_modules");
20
+ const plugin_node_builtin_1 = require("./plugin_node_builtin");
20
21
  // Maximum number of log messages that an esbuild instance will produce. This
21
22
  // limit is important to avoid out-of-memory errors due to too much data being
22
23
  // sent in the Go<>Node IPC channel.
@@ -45,6 +46,7 @@ const bundleJsFile = function ({ additionalModulePaths, basePath, config, extern
45
46
  const dynamicImportsIncludedPaths = new Set();
46
47
  // The list of esbuild plugins to enable for this build.
47
48
  const plugins = [
49
+ (0, plugin_node_builtin_1.getNodeBuiltinPlugin)(),
48
50
  (0, plugin_native_modules_1.getNativeModulesPlugin)(nativeNodeModules),
49
51
  (0, plugin_dynamic_imports_1.getDynamicImportsPlugin)({
50
52
  basePath,
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '@netlify/esbuild';
2
+ declare const getNodeBuiltinPlugin: () => Plugin;
3
+ export { getNodeBuiltinPlugin };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNodeBuiltinPlugin = void 0;
4
+ const getNodeBuiltinPlugin = () => ({
5
+ name: 'builtin-modules',
6
+ setup(build) {
7
+ build.onResolve({ filter: /^node:/ }, (args) => ({ path: args.path.slice('node:'.length), external: true }));
8
+ },
9
+ });
10
+ exports.getNodeBuiltinPlugin = getNodeBuiltinPlugin;
11
+ //# sourceMappingURL=plugin_node_builtin.js.map
@@ -27,7 +27,7 @@ const patchESMPackage = (path, fsCache) => __awaiter(void 0, void 0, void 0, fun
27
27
  const patchedPackageJson = Object.assign(Object.assign({}, packageJson), { type: 'commonjs' });
28
28
  return JSON.stringify(patchedPackageJson);
29
29
  });
30
- const shouldTranspile = (path, cache, reasons) => {
30
+ const shouldTranspile = (path, cache, esmPaths, reasons) => {
31
31
  if (cache.has(path)) {
32
32
  return cache.get(path);
33
33
  }
@@ -39,32 +39,33 @@ const shouldTranspile = (path, cache, reasons) => {
39
39
  return false;
40
40
  }
41
41
  const { parents } = reason;
42
- // If the path doesn't have any parents, it's safe to transpile.
42
+ // If the path is an entrypoint, we transpile it only if it's an ESM file.
43
43
  if (parents.size === 0) {
44
- cache.set(path, true);
45
- return true;
44
+ const isESM = esmPaths.has(path);
45
+ cache.set(path, isESM);
46
+ return isESM;
46
47
  }
47
48
  // The path should be transpiled if every parent will also be transpiled, or
48
49
  // if there is no parent.
49
- const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, reasons));
50
+ const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons));
50
51
  cache.set(path, shouldTranspilePath);
51
52
  return shouldTranspilePath;
52
53
  };
53
54
  const transpileESM = ({ basePath, config, esmPaths, fsCache, reasons, }) => __awaiter(void 0, void 0, void 0, function* () {
54
55
  const cache = new Map();
55
- const paths = [...esmPaths].filter((path) => shouldTranspile(path, cache, reasons));
56
- const pathsSet = new Set(paths);
56
+ const pathsToTranspile = [...esmPaths].filter((path) => shouldTranspile(path, cache, esmPaths, reasons));
57
+ const pathsToTranspileSet = new Set(pathsToTranspile);
57
58
  const packageJsonPaths = [...reasons.entries()]
58
59
  .filter(([path, reason]) => {
59
60
  if ((0, path_1.basename)(path) !== 'package.json') {
60
61
  return false;
61
62
  }
62
- const needsPatch = [...reason.parents].some((parentPath) => pathsSet.has(parentPath));
63
+ const needsPatch = [...reason.parents].some((parentPath) => pathsToTranspileSet.has(parentPath));
63
64
  return needsPatch;
64
65
  })
65
66
  .map(([path]) => (basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path)));
66
67
  const rewrites = yield getPatchedESMPackages(packageJsonPaths, fsCache);
67
- yield Promise.all(paths.map((path) => __awaiter(void 0, void 0, void 0, function* () {
68
+ yield Promise.all(pathsToTranspile.map((path) => __awaiter(void 0, void 0, void 0, function* () {
68
69
  const absolutePath = basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path);
69
70
  const transpiled = yield (0, transpile_1.transpile)(absolutePath, config);
70
71
  rewrites.set(absolutePath, transpiled);
@@ -22,6 +22,7 @@ const transpile = (path, config) => __awaiter(void 0, void 0, void 0, function*
22
22
  format: 'cjs',
23
23
  logLevel: 'error',
24
24
  platform: 'node',
25
+ sourcemap: Boolean(config.nodeSourcemap),
25
26
  target: [nodeTarget],
26
27
  write: false,
27
28
  });
@@ -36,6 +36,7 @@ const make_dir_1 = __importDefault(require("make-dir"));
36
36
  const p_map_1 = __importDefault(require("p-map"));
37
37
  const unixify_1 = __importDefault(require("unixify"));
38
38
  const archive_1 = require("../../../archive");
39
+ const fs_2 = require("../../../utils/fs");
39
40
  const pStat = (0, util_1.promisify)(fs_1.default.stat);
40
41
  const pWriteFile = (0, util_1.promisify)(fs_1.default.writeFile);
41
42
  // Taken from https://www.npmjs.com/package/cpy.
@@ -67,7 +68,7 @@ const createDirectory = function ({ aliases = new Map(), basePath, destFolder, e
67
68
  });
68
69
  const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
69
70
  if (rewrites.has(srcFile)) {
70
- return pWriteFile(absoluteDestPath, rewrites.get(srcFile));
71
+ return (0, fs_2.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
71
72
  }
72
73
  return (0, cp_file_1.default)(srcFile, absoluteDestPath);
73
74
  }, { concurrency: COPY_FILE_CONCURRENCY });
@@ -2,6 +2,7 @@ import { FunctionArchive } from '../function';
2
2
  import { RuntimeName } from '../runtimes/runtime';
3
3
  declare type FunctionResult = Omit<FunctionArchive, 'runtime'> & {
4
4
  runtime: RuntimeName;
5
+ schedule?: string;
5
6
  };
6
7
  declare const formatZipResult: (archive: FunctionArchive) => FunctionResult;
7
8
  export { formatZipResult };
@@ -4,7 +4,8 @@ exports.formatZipResult = void 0;
4
4
  const remove_undefined_1 = require("./remove_undefined");
5
5
  // Takes the result of zipping a function and formats it for output.
6
6
  const formatZipResult = (archive) => {
7
- const functionResult = Object.assign(Object.assign({}, archive), { runtime: archive.runtime.name });
7
+ var _a;
8
+ const functionResult = Object.assign(Object.assign({}, archive), { runtime: archive.runtime.name, schedule: (_a = archive === null || archive === void 0 ? void 0 : archive.config) === null || _a === void 0 ? void 0 : _a.schedule });
8
9
  return (0, remove_undefined_1.removeUndefined)(functionResult);
9
10
  };
10
11
  exports.formatZipResult = formatZipResult;
@@ -17,5 +17,6 @@ declare const safeUnlink: (path: string) => Promise<void>;
17
17
  declare const listFunctionsDirectories: (srcFolders: string[]) => Promise<string[]>;
18
18
  declare const listFunctionsDirectory: (srcFolder: string) => Promise<string[]>;
19
19
  declare const resolveFunctionsDirectories: (input: string | string[]) => string[];
20
- export { cachedLstat, cachedReaddir, cachedReadFile, pLstat as lstat, getPathWithExtension, listFunctionsDirectories, listFunctionsDirectory, resolveFunctionsDirectories, safeUnlink, pStat as stat, pWriteFile as writeFile, pReadFile as readFile, };
20
+ declare const mkdirAndWriteFile: typeof pWriteFile;
21
+ export { cachedLstat, cachedReaddir, cachedReadFile, pLstat as lstat, getPathWithExtension, listFunctionsDirectories, listFunctionsDirectory, resolveFunctionsDirectories, safeUnlink, pStat as stat, pWriteFile as writeFile, pReadFile as readFile, mkdirAndWriteFile, };
21
22
  export type { FsCache };
package/dist/utils/fs.js CHANGED
@@ -8,11 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.readFile = exports.writeFile = exports.stat = exports.safeUnlink = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.getPathWithExtension = exports.lstat = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
15
+ exports.mkdirAndWriteFile = exports.readFile = exports.writeFile = exports.stat = exports.safeUnlink = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.getPathWithExtension = exports.lstat = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
13
16
  const fs_1 = require("fs");
14
17
  const path_1 = require("path");
15
18
  const util_1 = require("util");
19
+ const make_dir_1 = __importDefault(require("make-dir"));
16
20
  const non_nullable_1 = require("./non_nullable");
17
21
  const pLstat = (0, util_1.promisify)(fs_1.lstat);
18
22
  exports.lstat = pLstat;
@@ -93,4 +97,12 @@ const resolveFunctionsDirectories = (input) => {
93
97
  return absoluteDirectories;
94
98
  };
95
99
  exports.resolveFunctionsDirectories = resolveFunctionsDirectories;
100
+ const mkdirAndWriteFile = (path, ...params) => __awaiter(void 0, void 0, void 0, function* () {
101
+ if (typeof path === 'string') {
102
+ const directory = (0, path_1.dirname)(path);
103
+ yield (0, make_dir_1.default)(directory);
104
+ }
105
+ return pWriteFile(path, ...params);
106
+ });
107
+ exports.mkdirAndWriteFile = mkdirAndWriteFile;
96
108
  //# sourceMappingURL=fs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "4.29.2",
3
+ "version": "4.30.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -94,7 +94,7 @@
94
94
  },
95
95
  "devDependencies": {
96
96
  "@babel/types": "^7.15.6",
97
- "@netlify/eslint-config-node": "^3.3.6",
97
+ "@netlify/eslint-config-node": "^3.3.7",
98
98
  "@types/archiver": "^5.1.1",
99
99
  "@types/end-of-stream": "^1.4.1",
100
100
  "@types/resolve": "^1.20.1",
@@ -111,6 +111,7 @@
111
111
  "nyc": "^15.0.0",
112
112
  "sinon": "^12.0.0",
113
113
  "sort-on": "^4.1.1",
114
+ "source-map-support": "^0.5.20",
114
115
  "throat": "^6.0.1",
115
116
  "typescript": "^4.4.3"
116
117
  },