@netlify/dev-utils
Advanced tools
Comparing version
@@ -0,1 +1,2 @@ | ||
import { Context } from '@netlify/types'; | ||
import { FSWatcher } from 'chokidar'; | ||
@@ -9,2 +10,4 @@ import { EventEmitter } from 'node:events'; | ||
declare const renderFunctionErrorPage: (errString: string, functionType: string) => Promise<string>; | ||
interface DevEvent { | ||
@@ -15,2 +18,5 @@ name: string; | ||
type Geolocation = Context['geo']; | ||
declare const mockLocation: Geolocation; | ||
type logFunction = (...message: unknown[]) => void; | ||
@@ -85,2 +91,3 @@ type Logger = { | ||
declare class HTTPServer { | ||
private url?; | ||
private handler; | ||
@@ -174,2 +181,2 @@ private nodeServer?; | ||
export { type DevEvent, type DevEventHandler, EventInspector, Fixture, HTTPServer, type Handler, LocalState, type Logger, type MemoizeCache, MockFetch, createMockLogger, ensureNetlifyIgnore, getAPIToken, globalConfig, headers, memoize, shouldBase64Encode, toMultiValueHeaders, watchDebounced }; | ||
export { type DevEvent, type DevEventHandler, EventInspector, Fixture, type Geolocation, HTTPServer, type Handler, LocalState, type Logger, type MemoizeCache, MockFetch, createMockLogger, ensureNetlifyIgnore, getAPIToken, globalConfig, headers, memoize, mockLocation, renderFunctionErrorPage, shouldBase64Encode, toMultiValueHeaders, watchDebounced }; |
@@ -138,4 +138,32 @@ var __defProp = Object.defineProperty; | ||
// src/lib/errors.ts | ||
import { readFile } from "fs/promises"; | ||
import { dirname, resolve } from "path"; | ||
import { fileURLToPath } from "url"; | ||
var templatesPath = dirname(fileURLToPath(import.meta.url)); | ||
var functionErrorTemplatePath = resolve(templatesPath, "../src/templates/function-error.html"); | ||
var errorTemplateFile; | ||
var renderFunctionErrorPage = async (errString, functionType) => { | ||
const errorDetailsRegex = /<!--@ERROR-DETAILS-->/g; | ||
const functionTypeRegex = /<!--@FUNCTION-TYPE-->/g; | ||
try { | ||
errorTemplateFile = errorTemplateFile || await readFile(functionErrorTemplatePath, "utf-8"); | ||
return errorTemplateFile.replace(errorDetailsRegex, errString).replace(functionTypeRegex, functionType); | ||
} catch { | ||
return errString; | ||
} | ||
}; | ||
// src/lib/geo-location.ts | ||
var mockLocation = { | ||
city: "San Francisco", | ||
country: { code: "US", name: "United States" }, | ||
subdivision: { code: "CA", name: "California" }, | ||
longitude: 0, | ||
latitude: 0, | ||
timezone: "UTC" | ||
}; | ||
// src/lib/gitignore.ts | ||
import { readFile, stat, writeFile } from "fs/promises"; | ||
import { readFile as readFile2, stat, writeFile } from "fs/promises"; | ||
import path3 from "path"; | ||
@@ -162,3 +190,3 @@ import parseIgnore from "parse-gitignore"; | ||
try { | ||
gitIgnoreContents = await readFile(gitIgnorePath, "utf8"); | ||
gitIgnoreContents = await readFile2(gitIgnorePath, "utf8"); | ||
ignorePatterns = parseIgnore.parse(gitIgnoreContents); | ||
@@ -195,3 +223,3 @@ } catch { | ||
import path4 from "path"; | ||
import process from "process"; | ||
import process2 from "process"; | ||
import { deleteProperty, getProperty as getProperty2, hasProperty, setProperty as setProperty2 } from "dot-prop"; | ||
@@ -251,4 +279,4 @@ import { findUpSync } from "find-up"; | ||
get(key) { | ||
if (key === "siteId" && process.env.NETLIFY_SITE_ID) { | ||
return process.env.NETLIFY_SITE_ID; | ||
if (key === "siteId" && process2.env.NETLIFY_SITE_ID) { | ||
return process2.env.NETLIFY_SITE_ID; | ||
} | ||
@@ -290,3 +318,2 @@ return getProperty2(this.all, key); | ||
cache[cacheKey] = { | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
task: command().finally(() => { | ||
@@ -311,2 +338,3 @@ const entry = cache[cacheKey]; | ||
var HTTPServer = class { | ||
url; | ||
handler; | ||
@@ -318,6 +346,9 @@ nodeServer; | ||
async start(port = 0) { | ||
if (this.url) { | ||
return this.url; | ||
} | ||
const adapter = createServerAdapter((request) => this.handler(request)); | ||
const server = http.createServer(adapter); | ||
this.nodeServer = server; | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve2, reject) => { | ||
server.listen(port, () => { | ||
@@ -328,3 +359,5 @@ const address = server.address(); | ||
} | ||
resolve(`http://localhost:${address.port}`); | ||
const url = `http://localhost:${address.port}`; | ||
this.url = url; | ||
resolve2(url); | ||
}); | ||
@@ -338,3 +371,3 @@ }); | ||
} | ||
await new Promise((resolve, reject) => { | ||
await new Promise((resolve2, reject) => { | ||
server.close((error) => { | ||
@@ -344,3 +377,3 @@ if (error) { | ||
} | ||
resolve(null); | ||
resolve2(null); | ||
}); | ||
@@ -414,3 +447,3 @@ }); | ||
waitFor(filter, timeoutMs = DEFAULT_TIMEOUT) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve2, reject) => { | ||
setTimeout(() => { | ||
@@ -424,3 +457,3 @@ reject(new Error(`\`waitFor\` timed out after ${timeoutMs} ms`)); | ||
if (filter(event)) { | ||
resolve(event); | ||
resolve2(event); | ||
} | ||
@@ -525,3 +558,3 @@ }); | ||
}; | ||
var readAsString = (input) => new Promise((resolve, reject) => { | ||
var readAsString = (input) => new Promise((resolve2, reject) => { | ||
let buffer = ""; | ||
@@ -535,3 +568,3 @@ input.on("data", (chunk) => { | ||
input.on("end", () => { | ||
resolve(buffer); | ||
resolve2(buffer); | ||
}); | ||
@@ -544,3 +577,3 @@ }); | ||
import { EOL } from "os"; | ||
import { dirname, join } from "path"; | ||
import { dirname as dirname2, join } from "path"; | ||
import { promisify } from "util"; | ||
@@ -571,2 +604,3 @@ import tmp from "tmp-promise"; | ||
version: "0.0.0", | ||
type: "module", | ||
dependencies: this.npmDependencies | ||
@@ -587,3 +621,3 @@ }; | ||
const filePath = join(this.directory.path, relativePath); | ||
await fs3.mkdir(dirname(filePath), { recursive: true }); | ||
await fs3.mkdir(dirname2(filePath), { recursive: true }); | ||
await fs3.writeFile(filePath, this.files[relativePath]); | ||
@@ -605,2 +639,3 @@ } | ||
async destroy() { | ||
if (process.env.CI) return; | ||
await fs3.rm(this.directory.path, { force: true, recursive: true }); | ||
@@ -657,2 +692,4 @@ } | ||
memoize, | ||
mockLocation, | ||
renderFunctionErrorPage, | ||
shouldBase64Encode, | ||
@@ -659,0 +696,0 @@ toMultiValueHeaders, |
{ | ||
"name": "@netlify/dev-utils", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "TypeScript utilities for the local emulation of the Netlify environment", | ||
@@ -9,11 +9,6 @@ "type": "module", | ||
}, | ||
"main": "./dist/main.cjs", | ||
"module": "./dist/main.js", | ||
"main": "./dist/main.js", | ||
"types": "./dist/main.d.ts", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/main.d.cts", | ||
"default": "./dist/main.cjs" | ||
}, | ||
"import": { | ||
@@ -52,3 +47,3 @@ "types": "./dist/main.d.ts", | ||
"@types/lodash.debounce": "^4.0.9", | ||
"@types/node": "^20.5.1", | ||
"@types/node": "^18.19.110", | ||
"@types/parse-gitignore": "^1.0.2", | ||
@@ -70,4 +65,4 @@ "@types/write-file-atomic": "^4.0.3", | ||
"uuid": "^11.1.0", | ||
"write-file-atomic": "^6.0.0" | ||
"write-file-atomic": "^5.0.1" | ||
} | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
8
-38.46%2
-50%26672
-49.29%3
-40%820
-43.45%+ Added
- Removed
Updated