Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit f129ca1

Browse files
feat: add priority field to manifest (#1705)
* feat: add `priority` field to manifest * chore: fix test
1 parent 64ee032 commit f129ca1

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

src/manifest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface ManifestFunction {
1919
displayName?: string
2020
bundler?: string
2121
generator?: string
22+
priority?: number
2223
}
2324

2425
export interface Manifest {
@@ -53,6 +54,7 @@ const formatFunctionForManifest = ({
5354
mainFile,
5455
name,
5556
path,
57+
priority,
5658
routes,
5759
runtime,
5860
runtimeVersion,
@@ -67,6 +69,7 @@ const formatFunctionForManifest = ({
6769
buildData: { runtimeAPIVersion },
6870
mainFile,
6971
name,
72+
priority,
7073
runtimeVersion,
7174
path: resolve(path),
7275
runtime,

src/priority.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum Priority {
2+
GeneratedFunction = 0,
3+
UserFunction = 10,
4+
}

src/runtimes/node/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { extname, join } from 'path'
33
import { copyFile } from 'cp-file'
44

55
import { INVOCATION_MODE } from '../../function.js'
6+
import { Priority } from '../../priority.js'
67
import getInternalValue from '../../utils/get_internal_value.js'
78
import { GetSrcFilesFunction, Runtime, RUNTIME, ZipFunction } from '../runtime.js'
89

@@ -142,6 +143,7 @@ const zipFunction: ZipFunction = async function ({
142143

143144
const outputModuleFormat =
144145
extname(finalMainFile) === MODULE_FILE_EXTENSION.MJS ? MODULE_FORMAT.ESM : MODULE_FORMAT.COMMONJS
146+
const priority = isInternal ? Priority.GeneratedFunction : Priority.UserFunction
145147

146148
return {
147149
bundler: bundlerName,
@@ -157,6 +159,7 @@ const zipFunction: ZipFunction = async function ({
157159
outputModuleFormat,
158160
nativeNodeModules,
159161
path: zipPath.path,
162+
priority,
160163
runtimeVersion:
161164
runtimeAPIVersion === 2 ? getNodeRuntimeForV2(config.nodeVersion) : getNodeRuntime(config.nodeVersion),
162165
}

src/runtimes/runtime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface ZipFunctionResult {
5353
outputModuleFormat?: ModuleFormat
5454
nativeNodeModules?: object
5555
path: string
56+
priority?: number
5657
runtimeVersion?: string
5758
staticAnalysisResult?: StaticAnalysisResult
5859
entryFilename: string

tests/main.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,3 +2864,37 @@ describe('zip-it-and-ship-it', () => {
28642864
expect(duplicates).toHaveLength(0)
28652865
})
28662866
})
2867+
2868+
test('Adds a `priority` field to the generated manifest file', async () => {
2869+
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
2870+
const fixtureName = 'multiple-src-directories'
2871+
const manifestPath = join(tmpDir, 'manifest.json')
2872+
const paths = {
2873+
generated: `${fixtureName}/.netlify/internal-functions`,
2874+
user: `${fixtureName}/netlify/functions`,
2875+
}
2876+
2877+
await zipNode([paths.generated, paths.user], {
2878+
length: 3,
2879+
opts: {
2880+
internalSrcFolder: join(FIXTURES_DIR, paths.generated),
2881+
manifest: manifestPath,
2882+
},
2883+
})
2884+
2885+
const manifest = JSON.parse(await readFile(manifestPath, 'utf-8'))
2886+
2887+
expect(manifest.version).toBe(1)
2888+
expect(manifest.system.arch).toBe(arch)
2889+
expect(manifest.system.platform).toBe(platform)
2890+
expect(manifest.timestamp).toBeTypeOf('number')
2891+
2892+
const userFunction1 = manifest.functions.find((fn) => fn.name === 'function_user')
2893+
expect(userFunction1.priority).toBe(10)
2894+
2895+
const userFunction2 = manifest.functions.find((fn) => fn.name === 'function')
2896+
expect(userFunction2.priority).toBe(10)
2897+
2898+
const generatedFunction1 = manifest.functions.find((fn) => fn.name === 'function_internal')
2899+
expect(generatedFunction1.priority).toBe(0)
2900+
})

0 commit comments

Comments
 (0)