Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"ansi-escapes": "7.3.0",
"ansi-to-html": "0.7.2",
"ascii-table": "0.0.9",
"backoff": "2.5.0",
"boxen": "8.0.1",
"chalk": "5.6.2",
"chokidar": "4.0.3",
Expand Down Expand Up @@ -164,7 +163,6 @@
"@sindresorhus/slugify": "3.0.0",
"@tsconfig/node20": "20.1.0",
"@tsconfig/recommended": "1.0.13",
"@types/backoff": "2.5.5",
"@types/content-type": "1.1.9",
"@types/debug": "4.1.12",
"@types/envinfo": "7.8.4",
Expand Down
5 changes: 2 additions & 3 deletions src/commands/database/legacy/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createRequire } from 'module'
import { join } from 'path'

import fsPromises from 'fs/promises'
Expand All @@ -17,8 +16,8 @@ type PackageJSON = {
}

export function getPackageJSON(directory: string) {
const require = createRequire(join(directory, 'package.json'))
const packageJson = require('./package.json') as unknown
const packageJsonPath = join(directory, 'package.json')
const packageJson: unknown = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
if (typeof packageJson !== 'object' || packageJson === null) {
throw new Error('Failed to load package.json')
}
Expand Down
12 changes: 8 additions & 4 deletions src/commands/functions/functions-create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cp from 'child_process'
import fs from 'fs'
import { mkdir, readdir, unlink } from 'fs/promises'
import { createRequire } from 'module'
import path, { dirname, join, relative } from 'path'
import process from 'process'
import { fileURLToPath, pathToFileURL } from 'url'
Expand Down Expand Up @@ -30,7 +29,7 @@ import execa from '../../utils/execa.js'
import { readRepoURL, validateRepoURL } from '../../utils/read-repo-url.js'
import BaseCommand from '../base-command.js'

const require = createRequire(import.meta.url)
const readJsonFile = (filePath: string): unknown => JSON.parse(fs.readFileSync(filePath, 'utf8'))

const templatesDir = path.resolve(dirname(fileURLToPath(import.meta.url)), '../../../functions-templates')

Expand Down Expand Up @@ -443,7 +442,9 @@ const getNpmInstallPackages = (existingPackages = {}, neededPackages = {}) =>
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'functionPackageJson' implicitly h... Remove this comment to see the full error message
const installDeps = async ({ functionPackageJson, functionPath, functionsDir }) => {
const { dependencies: functionDependencies, devDependencies: functionDevDependencies } = require(functionPackageJson)
const { dependencies: functionDependencies, devDependencies: functionDevDependencies } = readJsonFile(
functionPackageJson,
) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
const sitePackageJson = await findUp('package.json', { cwd: functionsDir })
const npmInstallFlags = ['--no-audit', '--no-fund']

Expand All @@ -456,7 +457,10 @@ const installDeps = async ({ functionPackageJson, functionPath, functionsDir })
return
}

const { dependencies: siteDependencies, devDependencies: siteDevDependencies } = require(sitePackageJson)
const { dependencies: siteDependencies, devDependencies: siteDevDependencies } = readJsonFile(sitePackageJson) as {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
}
const dependencies = getNpmInstallPackages(siteDependencies, functionDependencies)
const devDependencies = getNpmInstallPackages(siteDevDependencies, functionDevDependencies)
const npmInstallPath = path.dirname(sitePackageJson)
Expand Down
22 changes: 11 additions & 11 deletions src/commands/functions/functions-invoke.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import { createRequire } from 'module'
import path from 'path'
import { pathToFileURL } from 'url'

import { OptionValues } from 'commander'
import inquirer from 'inquirer'
Expand All @@ -10,8 +10,6 @@ import { APIError, NETLIFYDEVWARN, chalk, logAndThrowError, exit } from '../../u
import { BACKGROUND, CLOCKWORK_USERAGENT, getFunctions } from '../../utils/functions/index.js'
import BaseCommand from '../base-command.js'

const require = createRequire(import.meta.url)

// https://docs.netlify.com/functions/trigger-on-events/
const events = [
'deploy-building',
Expand Down Expand Up @@ -64,20 +62,22 @@ const formatQstring = function (querystring) {
* @param {string} workingDir
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'payloadString' implicitly has an 'any' ... Remove this comment to see the full error message
const processPayloadFromFlag = function (payloadString, workingDir) {
export const processPayloadFromFlag = async function (payloadString, workingDir) {
if (payloadString) {
// case 1: jsonstring
let payload = tryParseJSON(payloadString)
if (payload) return payload
// case 2: jsonpath
const parsedJson = tryParseJSON(payloadString)
if (parsedJson) return parsedJson
// case 2: file path to a JSON or JS module
const payloadpath = path.join(workingDir, payloadString)
const pathexists = fs.existsSync(payloadpath)
if (pathexists) {
try {
if (payloadpath.endsWith('.json')) {
return JSON.parse(fs.readFileSync(payloadpath, 'utf8'))
}
// there is code execution potential here

payload = require(payloadpath)
return payload
const imported = (await import(pathToFileURL(payloadpath).href)) as { default?: unknown }
return imported.default ?? imported
} catch (error_) {
console.error(error_)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ export const functionsInvoke = async (nameArgument: string, options: OptionValue
// }
}
}
const payload = processPayloadFromFlag(options.payload, command.workingDir)
const payload = await processPayloadFromFlag(options.payload, command.workingDir)
body = { ...body, ...payload }

try {
Expand Down
Loading
Loading