Skip to content

Commit

Permalink
Merge branch 'main' into chore/ts-conversion-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored Dec 6, 2023
2 parents 916501c + 33177fc commit aac5bf2
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,55 @@ const deployProgressCb = function () {
}
}

const uploadDeployBlobs = async ({
cachedConfig,
deployId,
options,
silent,
siteId,
}: {
cachedConfig: any
deployId: string
options: OptionValues
silent: boolean
siteId: string
}) => {
const statusCb = silent ? () => {} : deployProgressCb()

statusCb({
type: 'blobs-uploading',
msg: 'Uploading blobs to deploy store...\n',
phase: 'start',
})

const [token] = await getToken(false)

const { success } = await runCoreSteps(['blobs_upload'], {
...options,
quiet: silent,
cachedConfig,
deployId,
siteId,
token,
})

if (!success) {
statusCb({
type: 'blobs-uploading',
msg: 'Deploy aborted due to error while uploading blobs to deploy store',
phase: 'error',
})

error('Error while uploading blobs to deploy store')
}

statusCb({
type: 'blobs-uploading',
msg: 'Finished uploading blobs to deploy store',
phase: 'stop',
})
}

const runDeploy = async ({
// @ts-expect-error TS(7031) FIXME: Binding element 'alias' implicitly has an 'any' ty... Remove this comment to see the full error message
alias,
Expand All @@ -364,6 +413,8 @@ const runDeploy = async ({
functionsConfig,
// @ts-expect-error TS(7031) FIXME: Binding element 'functionsFolder' implicitly has a... Remove this comment to see the full error message
functionsFolder,
// @ts-expect-error TS(7031) FIXME: Binding element 'options' implicitly has an 'a... Remove this comment to see the full error message
options,
// @ts-expect-error TS(7031) FIXME: Binding element 'packagePath' implicitly has an 'a... Remove this comment to see the full error message
packagePath,
// @ts-expect-error TS(7031) FIXME: Binding element 'silent' implicitly has an 'any' t... Remove this comment to see the full error message
Expand Down Expand Up @@ -421,6 +472,7 @@ const runDeploy = async ({
})

config.headers = headers
uploadDeployBlobs({ deployId, siteId, silent, options, cachedConfig: command.netlify.cachedConfig })

results = await deploySite(api, siteId, deployFolder, {
config,
Expand Down Expand Up @@ -690,6 +742,7 @@ const prepAndRunDeploy = async ({
functionsConfig,
// pass undefined functionsFolder if doesn't exist
functionsFolder: functionsFolderStat && functionsFolder,
options,
packagePath: command.workspacePackage,
silent: options.json || options.silent,
site,
Expand Down
56 changes: 56 additions & 0 deletions tests/integration/commands/deploy/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import process from 'process'
import { fileURLToPath } from 'url'

import execa from 'execa'
import fetch from 'node-fetch'
import { afterAll, beforeAll, describe, test } from 'vitest'

Expand Down Expand Up @@ -817,4 +818,59 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
t.expect(response).toEqual('Bundled at deployment')
})
})

test('should upload blobs when saved into .netlify directory', async (t) => {
await withSiteBuilder('site-with-blobs', async (builder) => {
await builder
.withNetlifyToml({
config: {
build: { publish: 'dist', functions: 'functions' },
},
})
.withContentFile({
path: 'dist/.netlify/blobs/deploy/hello',
content: 'hello from the blob',
})
.withPackageJson({
packageJson: {
dependencies: {
'@netlify/blobs': '^6.3.0',
'@netlify/functions': '^2.4.0',
},
},
})
.withContentFile({
path: 'functions/read-blob.ts',
content: `
import { getDeployStore } from "@netlify/blobs"
import { Config, Context } from "@netlify/functions"
export default async (req: Request, context: Context) => {
const store = getDeployStore()
const blob = await store.get('hello')
return new Response(blob)
}
export const config: Config = {
path: "/read-blob"
}
`,
})
.buildAsync()

await execa.command('npm install', { cwd: builder.directory })
const { deploy_url: deployUrl } = await callCli(
['deploy', '--json'],
{
cwd: builder.directory,
env: { NETLIFY_SITE_ID: context.siteId },
},
true,
)

const response = await fetch(`${deployUrl}/read-blob`).then((res) => res.text())
t.expect(response).toEqual('hello from the blob')
})
})
})

0 comments on commit aac5bf2

Please sign in to comment.