Skip to content

Commit

Permalink
feat: move "Uploading blobs" output to system logs
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed May 22, 2024
1 parent 466e98c commit 1df4eda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
4 changes: 3 additions & 1 deletion packages/build/src/log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { createWriteStream } from 'fs'
import figures from 'figures'
import indentString from 'indent-string'

import type { SystemLogger } from '../plugins_core/types.js'

import { getHeader } from './header.js'
import { OutputFlusher } from './output_flusher.js'
import { serializeArray, serializeObject } from './serialize.js'
Expand Down Expand Up @@ -162,7 +164,7 @@ export const getSystemLogger = function (
debug: boolean,
/** A system log file descriptor, if non is provided it will be a noop logger */
systemLogFile?: number,
): (...args: any[]) => void {
): SystemLogger {
// If the `debug` flag is used, we return a function that pipes system logs
// to the regular logger, as the intention is for them to end up in stdout.
if (debug) {
Expand Down
28 changes: 10 additions & 18 deletions packages/build/src/plugins_core/blobs_upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import { getDeployStore } from '@netlify/blobs'
import pMap from 'p-map'
import semver from 'semver'

import { log, logError } from '../../log/logger.js'
import { logError } from '../../log/logger.js'
import { getFileWithMetadata, getKeysToUpload, scanForBlobs } from '../../utils/blobs.js'
import { type CoreStep, type CoreStepCondition, type CoreStepFunction } from '../types.js'

const coreStep: CoreStepFunction = async function ({
debug,
logs,
deployId,
buildDir,
quiet,
packagePath,
constants: { SITE_ID, NETLIFY_API_TOKEN, NETLIFY_API_HOST },
systemLog,
}) {
// This should never happen due to the condition check
if (!deployId || !NETLIFY_API_TOKEN) {
Expand All @@ -41,9 +40,8 @@ const coreStep: CoreStepFunction = async function ({

// We checked earlier, but let's be extra safe
if (blobs === null) {
if (!quiet) {
log(logs, 'No blobs to upload to deploy store.')
}
systemLog('No blobs to upload to deploy store.')

return {}
}

Expand All @@ -57,23 +55,19 @@ const coreStep: CoreStepFunction = async function ({
const keys = await getKeysToUpload(blobs.directory)

if (keys.length === 0) {
if (!quiet) {
log(logs, 'No blobs to upload to deploy store.')
}
systemLog('No blobs to upload to deploy store.')

return {}
}

if (!quiet) {
log(logs, `Uploading ${keys.length} blobs to deploy store...`)
}
systemLog(`Uploading ${keys.length} blobs to deploy store`)

try {
await pMap(
keys,
async (key: string) => {
if (debug && !quiet) {
log(logs, `- Uploading blob ${key}`, { indent: true })
}
systemLog(`Uploading blob ${key}`)

const { data, metadata } = await getFileWithMetadata(blobs.directory, key)
await blobStore.set(key, data, { metadata })
},
Expand All @@ -85,9 +79,7 @@ const coreStep: CoreStepFunction = async function ({
throw new Error(`Failed while uploading blobs to deploy store`)
}

if (!quiet) {
log(logs, `Done uploading blobs to deploy store.`)
}
systemLog(`Done uploading blobs to deploy store.`)

return {}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/build/src/plugins_core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export type CoreStepFunctionArgs = {
quiet?: boolean
debug?: boolean
logs?: BufferedLogs
systemLog?: (message: unknown) => void
systemLog: SystemLogger
edgeFunctionsBootstrapURL?: string
// systemLog(...args: any[]): void
featureFlags?: Record<string, any>

netlifyConfig: NetlifyConfig
Expand Down

0 comments on commit 1df4eda

Please sign in to comment.