@netlify/zip-it-and-ship-it 5.7.4 → 5.9.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/feature_flags.js +1 -1
- package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +4 -1
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +9 -2
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +8 -2
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +19 -3
- package/dist/runtimes/node/bundlers/esbuild/index.js +3 -2
- package/dist/runtimes/node/bundlers/index.js +5 -6
- package/dist/runtimes/node/utils/package_json.d.ts +6 -1
- package/dist/runtimes/node/utils/package_json.js +44 -19
- package/package.json +6 -6
package/dist/feature_flags.js
CHANGED
|
@@ -5,9 +5,9 @@ const process_1 = require("process");
|
|
|
5
5
|
exports.defaultFlags = {
|
|
6
6
|
buildGoSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
|
|
7
7
|
buildRustSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
8
|
-
defaultEsModulesToEsbuild: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
|
|
9
8
|
parseWithEsbuild: false,
|
|
10
9
|
traceWithNft: false,
|
|
10
|
+
zisi_detect_esm: false,
|
|
11
11
|
zisi_pure_esm: false,
|
|
12
12
|
};
|
|
13
13
|
// List of supported flags and their default value.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { FunctionConfig } from '../../../../config.js';
|
|
2
|
+
import { FeatureFlags } from '../../../../feature_flags.js';
|
|
2
3
|
export declare const ESBUILD_LOG_LIMIT = 10;
|
|
3
|
-
export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, externalModules, ignoredModules, name, srcDir, srcFile, }: {
|
|
4
|
+
export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, externalModules, featureFlags, ignoredModules, name, srcDir, srcFile, }: {
|
|
4
5
|
additionalModulePaths?: string[] | undefined;
|
|
5
6
|
basePath?: string | undefined;
|
|
6
7
|
config: FunctionConfig;
|
|
7
8
|
externalModules: string[];
|
|
9
|
+
featureFlags: FeatureFlags;
|
|
8
10
|
ignoredModules: string[];
|
|
9
11
|
name: string;
|
|
10
12
|
srcDir: string;
|
|
@@ -14,6 +16,7 @@ export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, e
|
|
|
14
16
|
bundlePaths: Map<string, string>;
|
|
15
17
|
cleanTempFiles: () => Promise<void>;
|
|
16
18
|
inputs: string[];
|
|
19
|
+
moduleFormat: import("../../utils/module_format.js").ModuleFormat;
|
|
17
20
|
nativeNodeModules: {};
|
|
18
21
|
nodeModulesWithDynamicImports: string[];
|
|
19
22
|
warnings: import("@netlify/esbuild").Message[];
|
|
@@ -17,7 +17,7 @@ exports.ESBUILD_LOG_LIMIT = 10;
|
|
|
17
17
|
// the extensions that esbuild will look for, in this order.
|
|
18
18
|
const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.json'];
|
|
19
19
|
// eslint-disable-next-line max-statements
|
|
20
|
-
const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], ignoredModules = [], name, srcDir, srcFile, }) {
|
|
20
|
+
const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], featureFlags, ignoredModules = [], name, srcDir, srcFile, }) {
|
|
21
21
|
// We use a temporary directory as the destination for esbuild files to avoid
|
|
22
22
|
// any naming conflicts with files generated by other functions.
|
|
23
23
|
const targetDirectory = await (0, tmp_promise_1.tmpName)();
|
|
@@ -52,11 +52,16 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
52
52
|
// in `destFolder`. We use `sourceRoot` to establish that relation. They are
|
|
53
53
|
// URLs, not paths, so even on Windows they should use forward slashes.
|
|
54
54
|
const sourceRoot = targetDirectory.replace(/\\/g, '/');
|
|
55
|
+
// Configuring the output format of esbuild. The `includedFiles` array we get
|
|
56
|
+
// here contains additional paths to include with the bundle, like the path
|
|
57
|
+
// to a `package.json` with {"type": "module"} in case of an ESM function.
|
|
58
|
+
const { includedFiles: includedFilesFromModuleDetection, moduleFormat } = await (0, bundler_target_js_1.getModuleFormat)(srcDir, featureFlags, config.nodeVersion);
|
|
55
59
|
try {
|
|
56
60
|
const { metafile = { inputs: {}, outputs: {} }, warnings } = await (0, esbuild_1.build)({
|
|
57
61
|
bundle: true,
|
|
58
62
|
entryPoints: [srcFile],
|
|
59
63
|
external,
|
|
64
|
+
format: moduleFormat,
|
|
60
65
|
logLevel: 'warning',
|
|
61
66
|
logLimit: exports.ESBUILD_LOG_LIMIT,
|
|
62
67
|
metafile: true,
|
|
@@ -76,11 +81,13 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
76
81
|
});
|
|
77
82
|
const inputs = Object.keys(metafile.inputs).map((path) => (0, path_1.resolve)(path));
|
|
78
83
|
const cleanTempFiles = getCleanupFunction([...bundlePaths.keys()]);
|
|
84
|
+
const additionalPaths = [...dynamicImportsIncludedPaths, ...includedFilesFromModuleDetection];
|
|
79
85
|
return {
|
|
80
|
-
additionalPaths
|
|
86
|
+
additionalPaths,
|
|
81
87
|
bundlePaths,
|
|
82
88
|
cleanTempFiles,
|
|
83
89
|
inputs,
|
|
90
|
+
moduleFormat,
|
|
84
91
|
nativeNodeModules,
|
|
85
92
|
nodeModulesWithDynamicImports: [...nodeModulesWithDynamicImports],
|
|
86
93
|
warnings,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FeatureFlags } from '../../../../feature_flags';
|
|
2
|
+
import { ModuleFormat } from '../../utils/module_format';
|
|
1
3
|
declare const versionMap: {
|
|
2
4
|
readonly '8.x': "node8";
|
|
3
5
|
readonly '10.x': "node10";
|
|
@@ -6,5 +8,9 @@ declare const versionMap: {
|
|
|
6
8
|
};
|
|
7
9
|
declare type VersionKeys = keyof typeof versionMap;
|
|
8
10
|
declare type VersionValues = typeof versionMap[VersionKeys];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
declare const getBundlerTarget: (suppliedVersion?: string | undefined) => VersionValues;
|
|
12
|
+
declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, configVersion?: string | undefined) => Promise<{
|
|
13
|
+
includedFiles: string[];
|
|
14
|
+
moduleFormat: ModuleFormat;
|
|
15
|
+
}>;
|
|
16
|
+
export { getBundlerTarget, getModuleFormat };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBundlerTarget = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.getModuleFormat = exports.getBundlerTarget = void 0;
|
|
4
|
+
const node_version_1 = require("../../utils/node_version");
|
|
5
|
+
const package_json_1 = require("../../utils/package_json");
|
|
5
6
|
const versionMap = {
|
|
6
7
|
'8.x': 'node8',
|
|
7
8
|
'10.x': 'node10',
|
|
@@ -13,9 +14,24 @@ const getBundlerTarget = (suppliedVersion) => {
|
|
|
13
14
|
if (version && version in versionMap) {
|
|
14
15
|
return versionMap[version];
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return versionMap[`${node_version_1.DEFAULT_NODE_VERSION}.x`];
|
|
17
18
|
};
|
|
18
19
|
exports.getBundlerTarget = getBundlerTarget;
|
|
20
|
+
const getModuleFormat = async (srcDir, featureFlags, configVersion) => {
|
|
21
|
+
const packageJsonFile = await (0, package_json_1.getClosestPackageJson)(srcDir);
|
|
22
|
+
const nodeSupport = (0, node_version_1.getNodeSupportMatrix)(configVersion);
|
|
23
|
+
if (featureFlags.zisi_pure_esm && (packageJsonFile === null || packageJsonFile === void 0 ? void 0 : packageJsonFile.contents.type) === 'module' && nodeSupport.esm) {
|
|
24
|
+
return {
|
|
25
|
+
includedFiles: [packageJsonFile.path],
|
|
26
|
+
moduleFormat: 'esm',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
includedFiles: [],
|
|
31
|
+
moduleFormat: 'cjs',
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getModuleFormat = getModuleFormat;
|
|
19
35
|
const normalizeVersion = (version) => {
|
|
20
36
|
const match = version && version.match(/^nodejs(.*)$/);
|
|
21
37
|
return match ? match[1] : version;
|
|
@@ -30,11 +30,12 @@ const getExternalAndIgnoredModules = async ({ config, srcDir }) => {
|
|
|
30
30
|
};
|
|
31
31
|
const bundle = async ({ basePath, config = {}, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, repositoryRoot, runtime, srcDir, srcPath, stat, }) => {
|
|
32
32
|
const { externalModules, ignoredModules } = await getExternalAndIgnoredModules({ config, srcDir });
|
|
33
|
-
const { additionalPaths, bundlePaths, cleanTempFiles, inputs, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_js_1.bundleJsFile)({
|
|
33
|
+
const { additionalPaths, bundlePaths, cleanTempFiles, inputs, moduleFormat, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_js_1.bundleJsFile)({
|
|
34
34
|
additionalModulePaths: pluginsModulesPath ? [pluginsModulesPath] : [],
|
|
35
35
|
basePath,
|
|
36
36
|
config,
|
|
37
37
|
externalModules,
|
|
38
|
+
featureFlags,
|
|
38
39
|
ignoredModules,
|
|
39
40
|
name,
|
|
40
41
|
srcDir,
|
|
@@ -78,7 +79,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
|
|
|
78
79
|
bundlerWarnings,
|
|
79
80
|
inputs,
|
|
80
81
|
mainFile: normalizedMainFile,
|
|
81
|
-
moduleFormat
|
|
82
|
+
moduleFormat,
|
|
82
83
|
nativeNodeModules,
|
|
83
84
|
nodeModulesWithDynamicImports,
|
|
84
85
|
srcFiles: [...supportingSrcFiles, ...bundlePaths.keys()],
|
|
@@ -25,17 +25,16 @@ exports.getBundler = getBundler;
|
|
|
25
25
|
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
26
26
|
// esbuild is the only option.
|
|
27
27
|
const getDefaultBundler = async ({ extension, mainFile, featureFlags, }) => {
|
|
28
|
-
const { defaultEsModulesToEsbuild, traceWithNft } = featureFlags;
|
|
29
28
|
if (['.mjs', '.ts'].includes(extension)) {
|
|
30
29
|
return 'esbuild';
|
|
31
30
|
}
|
|
32
|
-
if (traceWithNft) {
|
|
31
|
+
if (featureFlags.traceWithNft) {
|
|
33
32
|
return 'nft';
|
|
34
33
|
}
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
return '
|
|
34
|
+
if (featureFlags.zisi_detect_esm) {
|
|
35
|
+
const functionIsESM = await (0, detect_es_module_js_1.detectEsModule)({ mainFile });
|
|
36
|
+
if (functionIsESM) {
|
|
37
|
+
return 'nft';
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
return 'zisi';
|
|
@@ -13,6 +13,11 @@ export interface PackageJson {
|
|
|
13
13
|
binary?: boolean;
|
|
14
14
|
type?: string;
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export interface PackageJsonFile {
|
|
17
|
+
contents: PackageJson;
|
|
18
|
+
path: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const getClosestPackageJson: (resolveDir: string) => Promise<PackageJsonFile | null>;
|
|
17
21
|
export declare const getPackageJson: (srcDir: string) => Promise<PackageJson>;
|
|
18
22
|
export declare const getPackageJsonIfAvailable: (srcDir: string) => Promise<PackageJson>;
|
|
23
|
+
export declare const sanitisePackageJson: (packageJson: Record<string, unknown>) => PackageJson;
|
|
@@ -3,35 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPackageJsonIfAvailable = exports.getPackageJson = exports.
|
|
6
|
+
exports.sanitisePackageJson = exports.getPackageJsonIfAvailable = exports.getPackageJson = exports.getClosestPackageJson = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
8
10
|
const pkg_dir_1 = __importDefault(require("pkg-dir"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const getClosestPackageJson = async (resolveDir) => {
|
|
12
|
+
const packageJsonPath = await (0, find_up_1.default)(async (directory) => {
|
|
13
|
+
// We stop traversing if we're about to leave the boundaries of any
|
|
14
|
+
// node_modules directory.
|
|
15
|
+
if ((0, path_1.basename)(directory) === 'node_modules') {
|
|
16
|
+
return find_up_1.default.stop;
|
|
17
|
+
}
|
|
18
|
+
const path = (0, path_1.join)(directory, 'package.json');
|
|
19
|
+
const hasPackageJson = await find_up_1.default.exists(path);
|
|
20
|
+
return hasPackageJson ? path : undefined;
|
|
21
|
+
}, { cwd: resolveDir });
|
|
22
|
+
if (packageJsonPath === undefined) {
|
|
23
|
+
return null;
|
|
12
24
|
}
|
|
13
|
-
|
|
25
|
+
const packageJson = await readPackageJson(packageJsonPath);
|
|
26
|
+
return {
|
|
27
|
+
contents: packageJson,
|
|
28
|
+
path: packageJsonPath,
|
|
29
|
+
};
|
|
14
30
|
};
|
|
15
|
-
|
|
16
|
-
...packageJson,
|
|
17
|
-
files: sanitiseFiles(packageJson.files),
|
|
18
|
-
});
|
|
19
|
-
exports.sanitisePackageJson = sanitisePackageJson;
|
|
31
|
+
exports.getClosestPackageJson = getClosestPackageJson;
|
|
20
32
|
// Retrieve the `package.json` of a specific project or module
|
|
21
33
|
const getPackageJson = async function (srcDir) {
|
|
22
34
|
const packageRoot = await (0, pkg_dir_1.default)(srcDir);
|
|
23
35
|
if (packageRoot === undefined) {
|
|
24
36
|
return {};
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
// The path depends on the user's build, i.e. must be dynamic
|
|
29
|
-
const packageJson = JSON.parse(await fs_1.promises.readFile(packageJsonPath, 'utf8'));
|
|
30
|
-
return (0, exports.sanitisePackageJson)(packageJson);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
throw new Error(`${packageJsonPath} is invalid JSON: ${error.message}`);
|
|
34
|
-
}
|
|
38
|
+
return readPackageJson(`${packageRoot}/package.json`);
|
|
35
39
|
};
|
|
36
40
|
exports.getPackageJson = getPackageJson;
|
|
37
41
|
const getPackageJsonIfAvailable = async (srcDir) => {
|
|
@@ -44,4 +48,25 @@ const getPackageJsonIfAvailable = async (srcDir) => {
|
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
exports.getPackageJsonIfAvailable = getPackageJsonIfAvailable;
|
|
51
|
+
const readPackageJson = async (path) => {
|
|
52
|
+
try {
|
|
53
|
+
// The path depends on the user's build, i.e. must be dynamic
|
|
54
|
+
const packageJson = JSON.parse(await fs_1.promises.readFile(path, 'utf8'));
|
|
55
|
+
return (0, exports.sanitisePackageJson)(packageJson);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`${path} is invalid JSON: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const sanitiseFiles = (files) => {
|
|
62
|
+
if (!Array.isArray(files)) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return files.filter((file) => typeof file === 'string');
|
|
66
|
+
};
|
|
67
|
+
const sanitisePackageJson = (packageJson) => ({
|
|
68
|
+
...packageJson,
|
|
69
|
+
files: sanitiseFiles(packageJson.files),
|
|
70
|
+
});
|
|
71
|
+
exports.sanitisePackageJson = sanitisePackageJson;
|
|
47
72
|
//# sourceMappingURL=package_json.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/parser": "7.16.8",
|
|
56
|
-
"@netlify/esbuild": "
|
|
56
|
+
"@netlify/esbuild": "0.13.6",
|
|
57
57
|
"@vercel/nft": "^0.17.0",
|
|
58
58
|
"archiver": "^5.3.0",
|
|
59
59
|
"common-path-prefix": "^3.0.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"junk": "^3.1.0",
|
|
71
71
|
"locate-path": "^6.0.0",
|
|
72
72
|
"merge-options": "^3.0.4",
|
|
73
|
-
"minimatch": "^
|
|
73
|
+
"minimatch": "^4.0.0",
|
|
74
74
|
"p-map": "^4.0.0",
|
|
75
75
|
"path-exists": "^4.0.0",
|
|
76
76
|
"pkg-dir": "^5.0.0",
|
|
@@ -81,13 +81,12 @@
|
|
|
81
81
|
"semver": "^7.0.0",
|
|
82
82
|
"tmp-promise": "^3.0.2",
|
|
83
83
|
"toml": "^3.0.0",
|
|
84
|
-
"typescript": "^4.6.0-beta",
|
|
85
84
|
"unixify": "^1.0.0",
|
|
86
85
|
"yargs": "^16.0.0"
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
89
88
|
"@babel/types": "^7.15.6",
|
|
90
|
-
"@netlify/eslint-config-node": "^5.1.
|
|
89
|
+
"@netlify/eslint-config-node": "^5.1.5",
|
|
91
90
|
"@types/archiver": "^5.1.1",
|
|
92
91
|
"@types/end-of-stream": "^1.4.1",
|
|
93
92
|
"@types/resolve": "^1.20.1",
|
|
@@ -105,7 +104,8 @@
|
|
|
105
104
|
"sinon": "^13.0.0",
|
|
106
105
|
"sort-on": "^4.1.1",
|
|
107
106
|
"source-map-support": "^0.5.20",
|
|
108
|
-
"throat": "^6.0.1"
|
|
107
|
+
"throat": "^6.0.1",
|
|
108
|
+
"typescript": "^4.6.0-beta"
|
|
109
109
|
},
|
|
110
110
|
"engines": {
|
|
111
111
|
"node": "^12.20.0 || ^14.14.0 || >=16.0.0"
|