From 3e7e42f1e426efeb154973fb0be132dd26b6a3fe Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 15 Jan 2022 09:52:31 +0200 Subject: [PATCH] chore(deps): remove read-pkg-up --- npm-shrinkwrap.json | 1 - package.json | 1 - .../functions/runtimes/js/builders/zisi.js | 21 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 3487618e182..9f52b452b2b 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -95,7 +95,6 @@ "prettyjson": "^1.2.1", "pump": "^3.0.0", "raw-body": "^2.4.1", - "read-pkg-up": "^7.0.1", "semver": "^7.3.5", "source-map-support": "^0.5.19", "static-server": "^2.2.1", diff --git a/package.json b/package.json index 895f7c2a885..fa6284162a1 100644 --- a/package.json +++ b/package.json @@ -161,7 +161,6 @@ "prettyjson": "^1.2.1", "pump": "^3.0.0", "raw-body": "^2.4.1", - "read-pkg-up": "^7.0.1", "semver": "^7.3.5", "source-map-support": "^0.5.19", "static-server": "^2.2.1", diff --git a/src/lib/functions/runtimes/js/builders/zisi.js b/src/lib/functions/runtimes/js/builders/zisi.js index c5ddfa96e00..16a731d1963 100644 --- a/src/lib/functions/runtimes/js/builders/zisi.js +++ b/src/lib/functions/runtimes/js/builders/zisi.js @@ -1,9 +1,9 @@ -const { mkdir, writeFile } = require('fs').promises +const { mkdir, readFile, writeFile } = require('fs').promises const path = require('path') const { zipFunction } = require('@netlify/zip-it-and-ship-it') const decache = require('decache') -const readPkgUp = require('read-pkg-up') +const findUp = require('find-up') const sourceMapSupport = require('source-map-support') const { NETLIFYDEVERR } = require('../../../../../utils') @@ -79,13 +79,26 @@ const getTargetDirectory = async ({ errorExit }) => { return targetDirectory } +const readPackageJson = async (func) => { + const cwd = path.dirname(func.mainFile) + const packageJsonPath = await findUp('package.json', { cwd, type: 'file' }) + + if (!packageJsonPath) { + return + } + + const packageJson = await readFile(packageJsonPath, 'utf-8') + + return JSON.parse(packageJson) +} + module.exports = async ({ config, directory, errorExit, func, projectRoot }) => { const functionsConfig = addFunctionsConfigDefaults( normalizeFunctionsConfig({ functionsConfig: config.functions, projectRoot }), ) - const packageJson = await readPkgUp(func.mainFile) - const hasTypeModule = packageJson && packageJson.packageJson.type === 'module' + const packageJson = await readPackageJson(func) + const hasTypeModule = packageJson && packageJson.type === 'module' // We must use esbuild for certain file extensions. const mustTranspile = ['.mjs', '.ts'].includes(path.extname(func.mainFile))