@netlify/zip-it-and-ship-it 5.10.2 → 6.0.0-beta
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/feature_flags.js +1 -2
- package/dist/runtimes/go/builder.js +1 -0
- package/dist/runtimes/go/index.js +1 -4
- package/dist/runtimes/node/bundlers/index.js +2 -7
- package/dist/runtimes/node/in_source_config/index.js +12 -2
- package/dist/runtimes/node/index.js +1 -0
- package/dist/runtimes/node/runtime_api/index.d.ts +3 -0
- package/dist/runtimes/node/runtime_api/index.js +46 -0
- package/dist/runtimes/node/utils/detect_native_module.js +4 -1
- package/dist/runtimes/node/utils/entry_file.d.ts +4 -2
- package/dist/runtimes/node/utils/entry_file.js +8 -4
- package/dist/runtimes/node/utils/zip.d.ts +2 -0
- package/dist/runtimes/node/utils/zip.js +14 -4
- package/package.json +2 -1
package/dist/feature_flags.js
CHANGED
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFlags = exports.defaultFlags = void 0;
|
|
4
4
|
const process_1 = require("process");
|
|
5
5
|
exports.defaultFlags = {
|
|
6
|
-
buildGoSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
|
|
7
6
|
buildRustSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
8
7
|
parseWithEsbuild: false,
|
|
9
8
|
traceWithNft: false,
|
|
10
|
-
zisi_detect_esm: false,
|
|
11
9
|
zisi_pure_esm: false,
|
|
10
|
+
zisi_functions_api_v2: false,
|
|
12
11
|
};
|
|
13
12
|
// List of supported flags and their default value.
|
|
14
13
|
const getFlags = (input = {}, flags = exports.defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
@@ -29,14 +29,11 @@ const findFunctionsInPaths = async function ({ featureFlags, fsCache, paths }) {
|
|
|
29
29
|
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ featureFlags, fsCache, path })));
|
|
30
30
|
return functions.filter(non_nullable_js_1.nonNullable);
|
|
31
31
|
};
|
|
32
|
-
const findFunctionInPath = async function ({
|
|
32
|
+
const findFunctionInPath = async function ({ fsCache, path }) {
|
|
33
33
|
const runtime = await (0, detect_runtime_js_1.detectBinaryRuntime)({ fsCache, path });
|
|
34
34
|
if (runtime === 'go') {
|
|
35
35
|
return processBinary({ fsCache, path });
|
|
36
36
|
}
|
|
37
|
-
if (featureFlags.buildGoSource !== true) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
37
|
const goSourceFile = await detectGoFunction({ fsCache, path });
|
|
41
38
|
if (goSourceFile) {
|
|
42
39
|
return processSource({ fsCache, mainFile: goSourceFile, path });
|
|
@@ -31,13 +31,8 @@ const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
|
|
|
31
31
|
if (featureFlags.traceWithNft) {
|
|
32
32
|
return 'nft';
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (functionIsESM) {
|
|
37
|
-
return 'nft';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return 'zisi';
|
|
34
|
+
const functionIsESM = await (0, detect_es_module_js_1.detectEsModule)({ mainFile });
|
|
35
|
+
return functionIsESM ? 'nft' : 'zisi';
|
|
41
36
|
};
|
|
42
37
|
exports.getDefaultBundler = getDefaultBundler;
|
|
43
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -17,6 +17,8 @@ const findISCDeclarationsInPath = async (sourcePath) => {
|
|
|
17
17
|
return {};
|
|
18
18
|
}
|
|
19
19
|
const imports = ast.body.flatMap((node) => (0, imports_js_1.getImports)(node, exports.IN_SOURCE_CONFIG_MODULE));
|
|
20
|
+
const scheduledFuncsExpected = imports.filter(({ imported }) => imported === 'schedule').length;
|
|
21
|
+
let scheduledFuncsFound = 0;
|
|
20
22
|
const getAllBindings = (0, bindings_js_1.createBindingsMethod)(ast.body);
|
|
21
23
|
const mainExports = (0, exports_js_1.getMainExport)(ast.body, getAllBindings);
|
|
22
24
|
const iscExports = mainExports
|
|
@@ -26,14 +28,22 @@ const findISCDeclarationsInPath = async (sourcePath) => {
|
|
|
26
28
|
return null;
|
|
27
29
|
}
|
|
28
30
|
switch (matchingImport.imported) {
|
|
29
|
-
case 'schedule':
|
|
30
|
-
|
|
31
|
+
case 'schedule': {
|
|
32
|
+
const parsed = (0, schedule_js_1.parse)({ args }, getAllBindings);
|
|
33
|
+
if (parsed.schedule) {
|
|
34
|
+
scheduledFuncsFound += 1;
|
|
35
|
+
}
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
31
38
|
default:
|
|
32
39
|
// no-op
|
|
33
40
|
}
|
|
34
41
|
return null;
|
|
35
42
|
})
|
|
36
43
|
.filter(non_nullable_js_1.nonNullable);
|
|
44
|
+
if (scheduledFuncsFound < scheduledFuncsExpected) {
|
|
45
|
+
throw new Error('Warning: unable to find cron expression for scheduled function. `schedule` imported but not called or exported. If you meant to schedule a function, please check that `schedule` is invoked with an appropriate cron expression.');
|
|
46
|
+
}
|
|
37
47
|
const mergedExports = iscExports.reduce((acc, obj) => ({ ...acc, ...obj }), {});
|
|
38
48
|
return mergedExports;
|
|
39
49
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getRuntimeLayer = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const esbuild_1 = require("@netlify/esbuild");
|
|
9
|
+
const del_1 = __importDefault(require("del"));
|
|
10
|
+
const tmp_promise_1 = require("tmp-promise");
|
|
11
|
+
const getCompatCode = (importPath, format) => {
|
|
12
|
+
const compatPath = require.resolve('@netlify/functions');
|
|
13
|
+
if (format === 'cjs') {
|
|
14
|
+
return `
|
|
15
|
+
const { getHandler } = require('${compatPath}')
|
|
16
|
+
const func = require('${importPath}')
|
|
17
|
+
|
|
18
|
+
module.exports.handler = getHandler(func)
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
return `
|
|
22
|
+
import { getHandler } from '${compatPath}'
|
|
23
|
+
import * as func from '${importPath}'
|
|
24
|
+
|
|
25
|
+
export const handler = getHandler(func)
|
|
26
|
+
`;
|
|
27
|
+
};
|
|
28
|
+
const getRuntimeLayer = async (importPath, format) => {
|
|
29
|
+
const postfix = format === 'esm' ? '.mjs' : '.js';
|
|
30
|
+
const tmpPath = await (0, tmp_promise_1.tmpName)({ postfix });
|
|
31
|
+
const contents = getCompatCode(importPath, format);
|
|
32
|
+
await fs_1.promises.writeFile(tmpPath, contents);
|
|
33
|
+
const { outputFiles } = await (0, esbuild_1.build)({
|
|
34
|
+
bundle: true,
|
|
35
|
+
entryPoints: [tmpPath],
|
|
36
|
+
external: [importPath],
|
|
37
|
+
format,
|
|
38
|
+
logLevel: 'warning',
|
|
39
|
+
platform: 'node',
|
|
40
|
+
write: false,
|
|
41
|
+
});
|
|
42
|
+
await (0, del_1.default)(tmpPath, { force: true });
|
|
43
|
+
return outputFiles[0].text;
|
|
44
|
+
};
|
|
45
|
+
exports.getRuntimeLayer = getRuntimeLayer;
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -11,7 +11,10 @@ const isNativeModule = ({ binary, dependencies = {}, devDependencies = {}, files
|
|
|
11
11
|
if (hasMarkerModule) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
// Check if files is an array, as we never know (see https://github.com/math-utils/hamming-distance/pull/4)
|
|
15
|
+
const hasBinaryFile = Array.isArray(files)
|
|
16
|
+
? files.some((path) => !path.startsWith('!') && (0, path_1.extname)(path) === '.node')
|
|
17
|
+
: false;
|
|
15
18
|
return hasBinaryFile;
|
|
16
19
|
};
|
|
17
20
|
exports.isNativeModule = isNativeModule;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { FeatureFlags } from '../../../feature_flags.js';
|
|
1
2
|
import type { ModuleFormat } from './module_format.js';
|
|
2
3
|
export interface EntryFile {
|
|
3
4
|
contents: string;
|
|
4
5
|
filename: string;
|
|
5
6
|
}
|
|
6
|
-
export declare const getEntryFile: ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }: {
|
|
7
|
+
export declare const getEntryFile: ({ commonPrefix, featureFlags, filename, mainFile, moduleFormat, userNamespace, }: {
|
|
7
8
|
commonPrefix: string;
|
|
9
|
+
featureFlags: FeatureFlags;
|
|
8
10
|
filename: string;
|
|
9
11
|
mainFile: string;
|
|
10
12
|
moduleFormat: ModuleFormat;
|
|
11
13
|
userNamespace: string;
|
|
12
|
-
}) => EntryFile
|
|
14
|
+
}) => Promise<EntryFile>;
|
|
@@ -2,19 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEntryFile = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const index_js_1 = require("../runtime_api/index.js");
|
|
5
6
|
const normalize_path_js_1 = require("./normalize_path.js");
|
|
6
|
-
const getEntryFileContents = (
|
|
7
|
-
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
7
|
+
const getEntryFileContents = (importPath, moduleFormat) => {
|
|
8
8
|
if (moduleFormat === 'cjs') {
|
|
9
9
|
return `module.exports = require('${importPath}')`;
|
|
10
10
|
}
|
|
11
11
|
return `export { handler } from '${importPath}'`;
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const getImportPath = (modulePath) => `.${modulePath.startsWith('/') ? modulePath : `/${modulePath}`}`;
|
|
14
|
+
const getEntryFile = async ({ commonPrefix, featureFlags, filename, mainFile, moduleFormat, userNamespace, }) => {
|
|
14
15
|
const mainPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
|
|
15
16
|
const extension = (0, path_1.extname)(filename);
|
|
16
17
|
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
17
|
-
const
|
|
18
|
+
const importPath = getImportPath(mainPath);
|
|
19
|
+
const contents = featureFlags.zisi_functions_api_v2
|
|
20
|
+
? await (0, index_js_1.getRuntimeLayer)(importPath, moduleFormat)
|
|
21
|
+
: getEntryFileContents(importPath, moduleFormat);
|
|
18
22
|
return {
|
|
19
23
|
contents,
|
|
20
24
|
filename: entryFilename,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeatureFlags } from '../../../feature_flags.js';
|
|
1
2
|
import type { ModuleFormat } from './module_format.js';
|
|
2
3
|
export declare type ArchiveFormat = 'none' | 'zip';
|
|
3
4
|
interface ZipNodeParameters {
|
|
@@ -5,6 +6,7 @@ interface ZipNodeParameters {
|
|
|
5
6
|
basePath: string;
|
|
6
7
|
destFolder: string;
|
|
7
8
|
extension: string;
|
|
9
|
+
featureFlags: FeatureFlags;
|
|
8
10
|
filename: string;
|
|
9
11
|
mainFile: string;
|
|
10
12
|
moduleFormat: ModuleFormat;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.zipNodeJs = void 0;
|
|
7
|
+
/* eslint-disable max-lines */
|
|
7
8
|
const buffer_1 = require("buffer");
|
|
8
9
|
const fs_1 = require("fs");
|
|
9
10
|
const os_1 = __importDefault(require("os"));
|
|
@@ -20,9 +21,10 @@ const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.defaul
|
|
|
20
21
|
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
21
22
|
// the entry file generated by zip-it-and-ship-it).
|
|
22
23
|
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
23
|
-
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
|
|
24
|
-
const { contents: entryContents, filename: entryFilename } = (0, entry_file_js_1.getEntryFile)({
|
|
24
|
+
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
|
|
25
|
+
const { contents: entryContents, filename: entryFilename } = await (0, entry_file_js_1.getEntryFile)({
|
|
25
26
|
commonPrefix: basePath,
|
|
27
|
+
featureFlags,
|
|
26
28
|
filename,
|
|
27
29
|
mainFile,
|
|
28
30
|
moduleFormat,
|
|
@@ -50,7 +52,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
|
|
|
50
52
|
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
51
53
|
return functionFolder;
|
|
52
54
|
};
|
|
53
|
-
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
|
|
55
|
+
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
|
|
54
56
|
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
55
57
|
const { archive, output } = (0, archive_js_1.startZip)(destPath);
|
|
56
58
|
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
@@ -66,7 +68,14 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
|
|
|
66
68
|
// than the entry file) to its own sub-directory.
|
|
67
69
|
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
68
70
|
if (needsEntryFile) {
|
|
69
|
-
const entryFile = (0, entry_file_js_1.getEntryFile)({
|
|
71
|
+
const entryFile = await (0, entry_file_js_1.getEntryFile)({
|
|
72
|
+
commonPrefix: basePath,
|
|
73
|
+
featureFlags,
|
|
74
|
+
filename,
|
|
75
|
+
mainFile,
|
|
76
|
+
moduleFormat,
|
|
77
|
+
userNamespace,
|
|
78
|
+
});
|
|
70
79
|
addEntryFileToZip(archive, entryFile);
|
|
71
80
|
}
|
|
72
81
|
const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
|
|
@@ -111,4 +120,5 @@ const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrit
|
|
|
111
120
|
(0, archive_js_1.addZipFile)(archive, srcFile, normalizedDestPath, stat);
|
|
112
121
|
}
|
|
113
122
|
};
|
|
123
|
+
/* eslint-enable max-lines */
|
|
114
124
|
//# sourceMappingURL=zip.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/parser": "7.16.8",
|
|
56
56
|
"@netlify/esbuild": "0.14.25",
|
|
57
|
+
"@netlify/functions": "^2.0.0-beta",
|
|
57
58
|
"@vercel/nft": "^0.20.0",
|
|
58
59
|
"archiver": "^5.3.0",
|
|
59
60
|
"common-path-prefix": "^3.0.0",
|