@netlify/edge-bundler
Advanced tools
Comparing version 1.8.0 to 1.9.0
import { ExecaChildProcess } from 'execa'; | ||
import { Logger } from './logger.js'; | ||
declare type OnBeforeDownloadHook = () => void | Promise<void>; | ||
@@ -8,2 +9,3 @@ declare type OnAfterDownloadHook = (error?: Error) => void | Promise<void>; | ||
denoDir?: string; | ||
logger: Logger; | ||
onAfterDownload?: OnAfterDownloadHook; | ||
@@ -25,2 +27,3 @@ onBeforeDownload?: OnBeforeDownloadHook; | ||
denoDir?: string; | ||
logger: Logger; | ||
onAfterDownload?: OnAfterDownloadHook; | ||
@@ -30,5 +33,5 @@ onBeforeDownload?: OnBeforeDownloadHook; | ||
versionRange: string; | ||
constructor(options?: DenoOptions); | ||
constructor(options: DenoOptions); | ||
private downloadBinary; | ||
static getBinaryVersion(binaryPath: string): Promise<string | undefined>; | ||
private getBinaryVersion; | ||
private getCachedBinary; | ||
@@ -45,3 +48,2 @@ private getGlobalBinary; | ||
getEnvironmentVariables(): Record<string, string>; | ||
log(...data: unknown[]): void; | ||
run(args: string[], { pipeOutput }?: RunOptions): Promise<import("execa").ExecaReturnValue<string>>; | ||
@@ -48,0 +50,0 @@ runInBackground(args: string[], pipeOutput?: boolean, ref?: ProcessRef): Promise<void>; |
@@ -12,3 +12,3 @@ import { promises as fs } from 'fs'; | ||
class DenoBridge { | ||
constructor(options = {}) { | ||
constructor(options) { | ||
var _a, _b, _c, _d; | ||
@@ -18,2 +18,3 @@ this.cacheDirectory = (_a = options.cacheDirectory) !== null && _a !== void 0 ? _a : getPathInHome('deno-cli'); | ||
this.denoDir = options.denoDir; | ||
this.logger = options.logger; | ||
this.onAfterDownload = options.onAfterDownload; | ||
@@ -28,5 +29,5 @@ this.onBeforeDownload = options.onBeforeDownload; | ||
await this.ensureCacheDirectory(); | ||
this.log(`Downloading Deno CLI to ${this.cacheDirectory}...`); | ||
this.logger.system(`Downloading Deno CLI to ${this.cacheDirectory}`); | ||
const binaryPath = await download(this.cacheDirectory, this.versionRange); | ||
const downloadedVersion = await DenoBridge.getBinaryVersion(binaryPath); | ||
const downloadedVersion = await this.getBinaryVersion(binaryPath); | ||
// We should never get here, because it means that `DENO_VERSION_RANGE` is | ||
@@ -44,3 +45,3 @@ // a malformed semver range. If this does happen, let's throw an error so | ||
} | ||
static async getBinaryVersion(binaryPath) { | ||
async getBinaryVersion(binaryPath) { | ||
try { | ||
@@ -54,4 +55,4 @@ const { stdout } = await execa(binaryPath, ['--version']); | ||
} | ||
catch { | ||
// no-op | ||
catch (error) { | ||
this.logger.system('Error checking Deno binary version', error); | ||
} | ||
@@ -79,3 +80,3 @@ } | ||
const globalBinaryName = 'deno'; | ||
const globalVersion = await DenoBridge.getBinaryVersion(globalBinaryName); | ||
const globalVersion = await this.getBinaryVersion(globalBinaryName); | ||
if (globalVersion === undefined || !semver.satisfies(globalVersion, this.versionRange)) { | ||
@@ -112,3 +113,3 @@ return; | ||
if (globalPath !== undefined) { | ||
this.log('Using global installation of Deno CLI'); | ||
this.logger.system('Using global installation of Deno CLI'); | ||
return { global: true, path: globalPath }; | ||
@@ -118,3 +119,3 @@ } | ||
if (cachedPath !== undefined) { | ||
this.log('Using cached Deno CLI from', cachedPath); | ||
this.logger.system('Using cached Deno CLI from', cachedPath); | ||
return { global: false, path: cachedPath }; | ||
@@ -132,8 +133,2 @@ } | ||
} | ||
log(...data) { | ||
if (!this.debug) { | ||
return; | ||
} | ||
console.log(...data); | ||
} | ||
// Runs the Deno CLI in the background and returns a reference to the child | ||
@@ -140,0 +135,0 @@ // process, awaiting its execution. |
@@ -6,2 +6,3 @@ import { OnAfterDownloadHook, OnBeforeDownloadHook } from './bridge.js'; | ||
import { ImportMapFile } from './import_map.js'; | ||
import { LogFunction } from './logger.js'; | ||
interface BundleOptions { | ||
@@ -16,4 +17,5 @@ basePath?: string; | ||
onBeforeDownload?: OnBeforeDownloadHook; | ||
systemLogger?: LogFunction; | ||
} | ||
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, }?: BundleOptions) => Promise<{ | ||
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, systemLogger, }?: BundleOptions) => Promise<{ | ||
functions: EdgeFunction[]; | ||
@@ -20,0 +22,0 @@ manifest: import("./manifest.js").Manifest; |
@@ -11,2 +11,3 @@ import { promises as fs } from 'fs'; | ||
import { ImportMap } from './import_map.js'; | ||
import { getLogger } from './logger.js'; | ||
import { writeManifest } from './manifest.js'; | ||
@@ -39,3 +40,4 @@ import { ensureLatestTypes } from './types.js'; | ||
}; | ||
const bundle = async (sourceDirectories, distDirectory, declarations = [], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, } = {}) => { | ||
const bundle = async (sourceDirectories, distDirectory, declarations = [], { basePath: inputBasePath, cacheDirectory, debug, distImportMapPath, featureFlags: inputFeatureFlags, importMaps, onAfterDownload, onBeforeDownload, systemLogger, } = {}) => { | ||
const logger = getLogger(systemLogger, debug); | ||
const featureFlags = getFlags(inputFeatureFlags); | ||
@@ -45,2 +47,3 @@ const options = { | ||
cacheDirectory, | ||
logger, | ||
onAfterDownload, | ||
@@ -54,3 +57,3 @@ onBeforeDownload, | ||
const basePath = getBasePath(sourceDirectories, inputBasePath); | ||
await ensureLatestTypes(deno); | ||
await ensureLatestTypes(deno, logger); | ||
// The name of the bundle will be the hash of its contents, which we can't | ||
@@ -57,0 +60,0 @@ // compute until we run the bundle process. For now, we'll use a random ID |
import { OnAfterDownloadHook, OnBeforeDownloadHook } from '../bridge.js'; | ||
import type { EdgeFunction } from '../edge_function.js'; | ||
import { ImportMapFile } from '../import_map.js'; | ||
import { LogFunction } from '../logger.js'; | ||
declare type FormatFunction = (name: string) => string; | ||
@@ -21,4 +22,5 @@ interface InspectSettings { | ||
port: number; | ||
systemLogger?: LogFunction; | ||
} | ||
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[]) => Promise<{ | ||
declare const serve: ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }: ServeOptions) => Promise<(newFunctions: EdgeFunction[]) => Promise<{ | ||
graph: any; | ||
@@ -25,0 +27,0 @@ success: boolean; |
@@ -5,2 +5,3 @@ import { tmpName } from 'tmp-promise'; | ||
import { ImportMap } from '../import_map.js'; | ||
import { getLogger } from '../logger.js'; | ||
import { ensureLatestTypes } from '../types.js'; | ||
@@ -44,5 +45,7 @@ import { killProcess, waitForServer } from './util.js'; | ||
}; | ||
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, }) => { | ||
const serve = async ({ certificatePath, debug, distImportMapPath, inspectSettings, formatExportTypeError, formatImportError, importMaps, onAfterDownload, onBeforeDownload, port, systemLogger, }) => { | ||
const logger = getLogger(systemLogger, debug); | ||
const deno = new DenoBridge({ | ||
debug, | ||
logger, | ||
onAfterDownload, | ||
@@ -57,3 +60,3 @@ onBeforeDownload, | ||
// Downloading latest types if needed. | ||
await ensureLatestTypes(deno); | ||
await ensureLatestTypes(deno, logger); | ||
// Creating an ImportMap instance with any import maps supplied by the user, | ||
@@ -60,0 +63,0 @@ // if any. |
import type { DenoBridge } from './bridge.js'; | ||
declare const ensureLatestTypes: (deno: DenoBridge, customTypesURL?: string) => Promise<void>; | ||
import type { Logger } from './logger.js'; | ||
declare const ensureLatestTypes: (deno: DenoBridge, logger: Logger, customTypesURL?: string) => Promise<void>; | ||
export { ensureLatestTypes }; |
@@ -5,3 +5,3 @@ import { promises as fs } from 'fs'; | ||
const TYPES_URL = 'https://edge.netlify.com'; | ||
const ensureLatestTypes = async (deno, customTypesURL) => { | ||
const ensureLatestTypes = async (deno, logger, customTypesURL) => { | ||
const typesURL = customTypesURL !== null && customTypesURL !== void 0 ? customTypesURL : TYPES_URL; | ||
@@ -13,10 +13,10 @@ let [localVersion, remoteVersion] = [await getLocalVersion(deno), '']; | ||
catch (error) { | ||
deno.log('Could not check latest version of types:', error); | ||
logger.system('Could not check latest version of types:', error); | ||
return; | ||
} | ||
if (localVersion === remoteVersion) { | ||
deno.log('Local version of types is up-to-date:', localVersion); | ||
logger.system('Local version of types is up-to-date:', localVersion); | ||
return; | ||
} | ||
deno.log('Local version of types is outdated, updating:', localVersion); | ||
logger.system('Local version of types is outdated, updating:', localVersion); | ||
try { | ||
@@ -26,3 +26,3 @@ await deno.run(['cache', '-r', typesURL]); | ||
catch (error) { | ||
deno.log('Could not download latest types:', error); | ||
logger.system('Could not download latest types:', error); | ||
return; | ||
@@ -29,0 +29,0 @@ } |
{ | ||
"name": "@netlify/edge-bundler", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Intelligently prepare Netlify Edge Functions for deployment", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49467
50
1146