-
Notifications
You must be signed in to change notification settings - Fork 88
feat: add generator meta data for framework generated Netlify Functions #1973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
bd84f28
feat: create generator file for functions
taty2010 7439f6b
fix: prettier update
taty2010 da735ec
fix: adding required version number and making sure file name matches
taty2010 b8a95ad
feat: create generator field for ipx
taty2010 ef18051
fix: spacing
taty2010 0569c82
fix: need to use functionsDir instead of functionDir
taty2010 c2cf826
fix: refactoring writeGeneratorField
taty2010 c610f63
fix: prettier
taty2010 7abf64e
fix: remove check for packageplugin
taty2010 ecf8ef0
feat: udated functionality to help prevent slow build
taty2010 528832a
fix: removed extra param
taty2010 5064473
fix: check for version in node modules instead of package
taty2010 a2a1ded
fix: changed not found message and added xtra check
taty2010 8982ab6
fix: needing to check if nodemodule first
taty2010 33e506b
using resolvemoduleroot to access correct package
taty2010 9e9209b
chore: added ava testing framework
nickytonline dc61d8a
chore: moved writeFunctionConfiguration to a separate utils folder
nickytonline db3051f
test: added a test for writeFunctionConfiguration
nickytonline 082704f
test: added more tests for writeFunctionConfiguration
nickytonline e51ef70
chore: merged latest from main
nickytonline 3021f37
chore: removed unused deps that were added
nickytonline 27d408e
chore: added mock-fs package
nickytonline 999831b
chore: renamed and shuffled some files around
nickytonline 7af73c9
chore: refactored some tests
nickytonline 54797bd
Merge branch 'main' into tn/generator-serverless
taty2010 30d848e
chore: sorting out npm install issues
nickytonline 76ec9c7
Revert "chore: sorting out npm install issues"
nickytonline 60d15af
Revert "Merge branch 'main' into tn/generator-serverless"
nickytonline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { existsSync, readJSON, writeFile } from 'fs-extra' | ||
import { join } from 'pathe' | ||
|
||
import { NEXT_PLUGIN, NEXT_PLUGIN_NAME } from '../../constants' | ||
import { resolveModuleRoot } from '../config' | ||
|
||
const checkForPackage = async (packageDir: string, nodeModule: boolean) => { | ||
const packagePlugin = existsSync(packageDir) ? await readJSON(packageDir) : null | ||
let nextPlugin | ||
if (!nodeModule && packagePlugin) { | ||
nextPlugin = packagePlugin.dependencies[NEXT_PLUGIN] ? packagePlugin.dependencies[NEXT_PLUGIN] : null | ||
} else if (nodeModule && packagePlugin) { | ||
nextPlugin = packagePlugin.version ? packagePlugin.version : null | ||
} | ||
|
||
return nextPlugin | ||
} | ||
|
||
/** | ||
* Creates a function configuration file for the given function | ||
* | ||
* @param functionName The name of the function, e.g. `___netlify-handler` | ||
* @param functionTitle The name of the function that will be displayed in logs, e.g. `Next.js SSR handler` | ||
* @param functionsDir The directory where the function is located, e.g. `.netlify/functions` | ||
*/ | ||
export const writeFunctionConfiguration = async (functionName: string, functionTitle: string, functionsDir: string) => { | ||
const pluginPackagePath = '.netlify/plugins/package.json' | ||
const ProjDir = resolveModuleRoot(NEXT_PLUGIN) | ||
const nodeModulesPath = `${ProjDir}/package.json` | ||
|
||
const nextPluginVersion = | ||
(await checkForPackage(nodeModulesPath, true)) || (await checkForPackage(pluginPackagePath, false)) | ||
|
||
const metadata = { | ||
config: { | ||
name: functionTitle, | ||
generator: nextPluginVersion ? `${NEXT_PLUGIN_NAME}@${nextPluginVersion}` : 'Next Runtime Version Not Found', | ||
}, | ||
version: 1, | ||
} | ||
|
||
await writeFile(join(functionsDir, functionName, `${functionName}.json`), JSON.stringify(metadata)) | ||
MarcL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.