@netlify/zip-it-and-ship-it 11.0.0 → 12.0.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.d.ts +0 -2
- package/dist/feature_flags.js +0 -2
- package/dist/runtimes/node/utils/entry_file.d.ts +0 -8
- package/dist/runtimes/node/utils/entry_file.js +0 -47
- package/dist/runtimes/node/utils/zip.js +3 -13
- package/package.json +4 -4
- package/dist/runtimes/node/utils/entry_file.test.d.ts +0 -1
- package/dist/runtimes/node/utils/entry_file.test.js +0 -35
package/dist/feature_flags.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare const defaultFlags: {
|
|
|
7
7
|
readonly zisi_output_cjs_extension: false;
|
|
8
8
|
readonly zisi_unique_entry_file: false;
|
|
9
9
|
readonly zisi_esbuild_fail_double_glob: false;
|
|
10
|
-
readonly zisi_add_instrumentation_loader: true;
|
|
11
10
|
readonly zisi_dynamic_import_function_handler: false;
|
|
12
11
|
};
|
|
13
12
|
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>;
|
|
@@ -20,6 +19,5 @@ export declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
|
20
19
|
readonly zisi_output_cjs_extension: false;
|
|
21
20
|
readonly zisi_unique_entry_file: false;
|
|
22
21
|
readonly zisi_esbuild_fail_double_glob: false;
|
|
23
|
-
readonly zisi_add_instrumentation_loader: true;
|
|
24
22
|
readonly zisi_dynamic_import_function_handler: false;
|
|
25
23
|
}) => FeatureFlags;
|
package/dist/feature_flags.js
CHANGED
|
@@ -18,8 +18,6 @@ export const defaultFlags = {
|
|
|
18
18
|
zisi_unique_entry_file: false,
|
|
19
19
|
// If multiple glob stars are in includedFiles, fail the build instead of warning.
|
|
20
20
|
zisi_esbuild_fail_double_glob: false,
|
|
21
|
-
// Adds the `___netlify-telemetry.mjs` file to the function bundle.
|
|
22
|
-
zisi_add_instrumentation_loader: true,
|
|
23
21
|
// Dynamically import the function handler.
|
|
24
22
|
zisi_dynamic_import_function_handler: false,
|
|
25
23
|
};
|
|
@@ -4,17 +4,10 @@ export declare const ENTRY_FILE_NAME = "___netlify-entry-point";
|
|
|
4
4
|
export declare const BOOTSTRAP_FILE_NAME = "___netlify-bootstrap.mjs";
|
|
5
5
|
export declare const BOOTSTRAP_VERSION_FILE_NAME = "___netlify-bootstrap-version";
|
|
6
6
|
export declare const METADATA_FILE_NAME = "___netlify-metadata.json";
|
|
7
|
-
export declare const TELEMETRY_FILE_NAME = "___netlify-telemetry.mjs";
|
|
8
7
|
export interface EntryFile {
|
|
9
8
|
contents: string;
|
|
10
9
|
filename: string;
|
|
11
10
|
}
|
|
12
|
-
/**
|
|
13
|
-
* A minimal implementation of kebab-case.
|
|
14
|
-
* It is used to transform the generator name into a service name for the telemetry file.
|
|
15
|
-
* As DataDog has a special handling for the service name, we need to make sure it is kebab-case.
|
|
16
|
-
*/
|
|
17
|
-
export declare const kebabCase: (input: string) => string;
|
|
18
11
|
export declare const isNamedLikeEntryFile: (file: string, { basePath, featureFlags, filename, runtimeAPIVersion, }: {
|
|
19
12
|
basePath: string;
|
|
20
13
|
featureFlags: FeatureFlags;
|
|
@@ -29,7 +22,6 @@ export declare const conflictsWithEntryFile: (srcFiles: string[], { basePath, ex
|
|
|
29
22
|
mainFile: string;
|
|
30
23
|
runtimeAPIVersion: number;
|
|
31
24
|
}) => boolean;
|
|
32
|
-
export declare const getTelemetryFile: (generator?: string) => EntryFile;
|
|
33
25
|
export declare const getEntryFile: ({ commonPrefix, featureFlags, filename, mainFile, moduleFormat, userNamespace, runtimeAPIVersion, }: {
|
|
34
26
|
commonPrefix: string;
|
|
35
27
|
featureFlags: FeatureFlags;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
1
|
import { basename, extname, resolve } from 'path';
|
|
4
2
|
import { FunctionBundlingUserError } from '../../../utils/error.js';
|
|
5
3
|
import { RUNTIME } from '../../runtime.js';
|
|
@@ -9,20 +7,6 @@ export const ENTRY_FILE_NAME = '___netlify-entry-point';
|
|
|
9
7
|
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs';
|
|
10
8
|
export const BOOTSTRAP_VERSION_FILE_NAME = '___netlify-bootstrap-version';
|
|
11
9
|
export const METADATA_FILE_NAME = '___netlify-metadata.json';
|
|
12
|
-
export const TELEMETRY_FILE_NAME = '___netlify-telemetry.mjs';
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
14
|
-
/**
|
|
15
|
-
* A minimal implementation of kebab-case.
|
|
16
|
-
* It is used to transform the generator name into a service name for the telemetry file.
|
|
17
|
-
* As DataDog has a special handling for the service name, we need to make sure it is kebab-case.
|
|
18
|
-
*/
|
|
19
|
-
export const kebabCase = (input) => input
|
|
20
|
-
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
21
|
-
.replace(/[@#//$\s_\\.-]+/g, ' ')
|
|
22
|
-
.trim()
|
|
23
|
-
.toLowerCase()
|
|
24
|
-
.split(' ')
|
|
25
|
-
.join('-');
|
|
26
10
|
const getEntryFileContents = (mainPath, moduleFormat, featureFlags, runtimeAPIVersion) => {
|
|
27
11
|
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
28
12
|
if (runtimeAPIVersion === 2) {
|
|
@@ -93,37 +77,6 @@ const getEntryFileName = ({ extension, featureFlags, filename, runtimeAPIVersion
|
|
|
93
77
|
}
|
|
94
78
|
return `${basename(filename, extname(filename))}${extension}`;
|
|
95
79
|
};
|
|
96
|
-
export const getTelemetryFile = (generator) => {
|
|
97
|
-
// TODO: switch with import.meta.resolve once we drop support for Node 16.x
|
|
98
|
-
const filePath = require.resolve('@netlify/serverless-functions-api/instrumentation.js');
|
|
99
|
-
let serviceName;
|
|
100
|
-
let serviceVersion;
|
|
101
|
-
if (generator) {
|
|
102
|
-
// the generator can be something like: `@netlify/plugin-nextjs@14.13.2`
|
|
103
|
-
// following the convention of name@version but it must not have a version.
|
|
104
|
-
// split the generator by the @ sign to separate name and version.
|
|
105
|
-
// pop the last part (the version) and join the rest with a @ again.
|
|
106
|
-
const versionSepPos = generator.lastIndexOf('@');
|
|
107
|
-
if (versionSepPos > 1) {
|
|
108
|
-
const name = generator.substring(0, versionSepPos);
|
|
109
|
-
const version = generator.substring(versionSepPos + 1);
|
|
110
|
-
serviceVersion = version;
|
|
111
|
-
serviceName = kebabCase(name);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
serviceName = kebabCase(generator);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const contents = `
|
|
118
|
-
var SERVICE_NAME = ${JSON.stringify(serviceName)};
|
|
119
|
-
var SERVICE_VERSION = ${JSON.stringify(serviceVersion)};
|
|
120
|
-
${readFileSync(filePath, 'utf8')}
|
|
121
|
-
`;
|
|
122
|
-
return {
|
|
123
|
-
contents,
|
|
124
|
-
filename: TELEMETRY_FILE_NAME,
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
80
|
export const getEntryFile = ({ commonPrefix, featureFlags, filename, mainFile, moduleFormat, userNamespace, runtimeAPIVersion, }) => {
|
|
128
81
|
const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
|
|
129
82
|
const extension = getFileExtensionForFormat(moduleFormat, featureFlags, runtimeAPIVersion);
|
|
@@ -7,7 +7,7 @@ import { copyFile } from 'cp-file';
|
|
|
7
7
|
import pMap from 'p-map';
|
|
8
8
|
import { addZipContent, addZipFile, ARCHIVE_FORMAT, endZip, startZip, } from '../../../archive.js';
|
|
9
9
|
import { cachedLstat, mkdirAndWriteFile } from '../../../utils/fs.js';
|
|
10
|
-
import { BOOTSTRAP_FILE_NAME, METADATA_FILE_NAME, conflictsWithEntryFile, getEntryFile,
|
|
10
|
+
import { BOOTSTRAP_FILE_NAME, METADATA_FILE_NAME, conflictsWithEntryFile, getEntryFile, isNamedLikeEntryFile, } from './entry_file.js';
|
|
11
11
|
import { getMetadataFile } from './metadata_file.js';
|
|
12
12
|
import { normalizeFilePath } from './normalize_path.js';
|
|
13
13
|
import { getPackageJsonIfAvailable } from './package_json.js';
|
|
@@ -49,18 +49,12 @@ const createDirectory = async function ({ aliases = new Map(), basePath, cache,
|
|
|
49
49
|
userNamespace,
|
|
50
50
|
runtimeAPIVersion,
|
|
51
51
|
});
|
|
52
|
-
const { contents: telemetryContents, filename: telemetryFilename } = getTelemetryFile();
|
|
53
52
|
const functionFolder = join(destFolder, basename(filename, extension));
|
|
54
53
|
// Deleting the functions directory in case it exists before creating it.
|
|
55
54
|
await rm(functionFolder, { recursive: true, force: true, maxRetries: 3 });
|
|
56
55
|
await mkdir(functionFolder, { recursive: true });
|
|
57
56
|
// Writing entry files.
|
|
58
|
-
await
|
|
59
|
-
writeFile(join(functionFolder, entryFilename), entryContents),
|
|
60
|
-
featureFlags.zisi_add_instrumentation_loader
|
|
61
|
-
? writeFile(join(functionFolder, telemetryFilename), telemetryContents)
|
|
62
|
-
: Promise.resolve(),
|
|
63
|
-
]);
|
|
57
|
+
await writeFile(join(functionFolder, entryFilename), entryContents);
|
|
64
58
|
if (runtimeAPIVersion === 2) {
|
|
65
59
|
addBootstrapFile(srcFiles, aliases);
|
|
66
60
|
}
|
|
@@ -100,7 +94,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, cache,
|
|
|
100
94
|
});
|
|
101
95
|
return { path: functionFolder, entryFilename };
|
|
102
96
|
};
|
|
103
|
-
const createZipArchive = async function ({ aliases = new Map(), basePath, branch, cache, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, runtimeAPIVersion, srcFiles,
|
|
97
|
+
const createZipArchive = async function ({ aliases = new Map(), basePath, branch, cache, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, runtimeAPIVersion, srcFiles, }) {
|
|
104
98
|
const destPath = join(destFolder, `${basename(filename, extension)}.zip`);
|
|
105
99
|
const { archive, output } = startZip(destPath);
|
|
106
100
|
// There is a naming conflict with the entry file if one of the supporting
|
|
@@ -138,10 +132,6 @@ const createZipArchive = async function ({ aliases = new Map(), basePath, branch
|
|
|
138
132
|
entryFilename = entryFile.filename;
|
|
139
133
|
addEntryFileToZip(archive, entryFile);
|
|
140
134
|
}
|
|
141
|
-
const telemetryFile = getTelemetryFile(generator);
|
|
142
|
-
if (featureFlags.zisi_add_instrumentation_loader === true) {
|
|
143
|
-
addEntryFileToZip(archive, telemetryFile);
|
|
144
|
-
}
|
|
145
135
|
if (runtimeAPIVersion === 2) {
|
|
146
136
|
const bootstrapPath = addBootstrapFile(srcFiles, aliases);
|
|
147
137
|
const { version } = await getPackageJsonIfAvailable(bootstrapPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"@babel/parser": "^7.22.5",
|
|
45
45
|
"@babel/types": "7.27.1",
|
|
46
46
|
"@netlify/binary-info": "^1.0.0",
|
|
47
|
-
"@netlify/serverless-functions-api": "
|
|
47
|
+
"@netlify/serverless-functions-api": "2.0.2",
|
|
48
48
|
"@vercel/nft": "0.27.7",
|
|
49
|
-
"archiver": "^
|
|
49
|
+
"archiver": "^7.0.0",
|
|
50
50
|
"common-path-prefix": "^3.0.0",
|
|
51
51
|
"cp-file": "^10.0.0",
|
|
52
52
|
"es-module-lexer": "^1.0.0",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"engines": {
|
|
103
103
|
"node": ">=18.14.0"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "11241b50b724a2f229614e74dd22c86c4ca8757d"
|
|
106
106
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { test, expect } from 'vitest';
|
|
2
|
-
import { getTelemetryFile, kebabCase } from './entry_file.js';
|
|
3
|
-
test('kebab-case', () => {
|
|
4
|
-
expect(kebabCase('hello-world')).toBe('hello-world');
|
|
5
|
-
expect(kebabCase('hello World')).toBe('hello-world');
|
|
6
|
-
expect(kebabCase('--Hello--World--')).toBe('hello-world');
|
|
7
|
-
expect(kebabCase('Next.js Runtime')).toBe('next-js-runtime');
|
|
8
|
-
expect(kebabCase('@netlify/plugin-nextjs@14')).toBe('netlify-plugin-nextjs-14');
|
|
9
|
-
expect(kebabCase('CamelCaseShould_Be_transformed')).toBe('camel-case-should-be-transformed');
|
|
10
|
-
expect(kebabCase('multiple spaces')).toBe('multiple-spaces');
|
|
11
|
-
});
|
|
12
|
-
test('getTelemetryFile should handle no defined generator', () => {
|
|
13
|
-
const telemetryFile = getTelemetryFile();
|
|
14
|
-
expect(telemetryFile.filename).toBe('___netlify-telemetry.mjs');
|
|
15
|
-
expect(telemetryFile.contents).toContain('var SERVICE_NAME = undefined;');
|
|
16
|
-
expect(telemetryFile.contents).toContain('var SERVICE_VERSION = undefined;');
|
|
17
|
-
});
|
|
18
|
-
test('getTelemetryFile should handle internalFunc generator', () => {
|
|
19
|
-
const telemetryFile = getTelemetryFile('internalFunc');
|
|
20
|
-
expect(telemetryFile.filename).toBe('___netlify-telemetry.mjs');
|
|
21
|
-
expect(telemetryFile.contents).toContain('var SERVICE_NAME = "internal-func";');
|
|
22
|
-
expect(telemetryFile.contents).toContain('var SERVICE_VERSION = undefined;');
|
|
23
|
-
});
|
|
24
|
-
test('getTelemetryFile should handle generator with version', () => {
|
|
25
|
-
const telemetryFile = getTelemetryFile('@netlify/plugin-nextjs@14.13.2');
|
|
26
|
-
expect(telemetryFile.filename).toBe('___netlify-telemetry.mjs');
|
|
27
|
-
expect(telemetryFile.contents).toContain('var SERVICE_NAME = "netlify-plugin-nextjs";');
|
|
28
|
-
expect(telemetryFile.contents).toContain('var SERVICE_VERSION = "14.13.2";');
|
|
29
|
-
});
|
|
30
|
-
test('getTelemetryFile should handle generator without version', () => {
|
|
31
|
-
const telemetryFile = getTelemetryFile('@netlify/plugin-nextjs');
|
|
32
|
-
expect(telemetryFile.filename).toBe('___netlify-telemetry.mjs');
|
|
33
|
-
expect(telemetryFile.contents).toContain('var SERVICE_NAME = "netlify-plugin-nextjs";');
|
|
34
|
-
expect(telemetryFile.contents).toContain('var SERVICE_VERSION = undefined;');
|
|
35
|
-
});
|