Skip to content

Commit

Permalink
fix(v6, serverless): use named exports instead of default (#8857)
Browse files Browse the repository at this point in the history
The packing/nft helper kind of mixes named exports with default exports
and it ends up confusing build tools. It looks like we want named
exports, so I just refactored it to that. This was causing `yarn rw
deploy serverless --pack-only` to fail in deploy target CI (see
https://github.com/redwoodjs/deploy-target-ci/actions/runs/5482609165/jobs/9988107090).
Bug was introduced in #8456.
  • Loading branch information
jtoar committed Jul 9, 2023
1 parent d80bc14 commit 9dfbcf4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/__tests__/nftPack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import { buildApi } from '@redwoodjs/internal/dist/build/api'
import { findApiDistFunctions } from '@redwoodjs/internal/dist/files'

import nftPacker from '../packing/nft'
import * as nftPacker from '../packing/nft'

const FIXTURE_PATH = path.resolve(
__dirname,
Expand Down
19 changes: 4 additions & 15 deletions packages/cli/src/commands/deploy/packing/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensurePosixPath, getPaths } from '@redwoodjs/project-config'

const ZIPBALL_DIR = './api/dist/zipball'

function zipDirectory(source, out) {
export function zipDirectory(source, out) {
const archive = archiver('zip', { zlib: { level: 5 } })
const stream = fse.createWriteStream(out)

Expand All @@ -25,7 +25,7 @@ function zipDirectory(source, out) {
}

// returns a tuple of [filePath, fileContent]
function generateEntryFile(functionAbsolutePath, name) {
export function generateEntryFile(functionAbsolutePath, name) {
const relativeImport = ensurePosixPath(
path.relative(getPaths().base, functionAbsolutePath)
)
Expand All @@ -35,7 +35,7 @@ function generateEntryFile(functionAbsolutePath, name) {
]
}

async function packageSingleFunction(functionFile) {
export async function packageSingleFunction(functionFile) {
const { name: functionName } = path.parse(functionFile)

const { fileList: functionDependencyFileList } = await nodeFileTrace([
Expand Down Expand Up @@ -67,18 +67,7 @@ async function packageSingleFunction(functionFile) {
return
}

function nftPack() {
export function nftPack() {
const filesToBePacked = findApiDistFunctions()
return Promise.all(filesToBePacked.map(exports.packageSingleFunction))
}

// We do this, so we can spy the functions in the test
// It didn't make sense to separate into different files
const exports = {
nftPack,
packageSingleFunction,
generateEntryFile,
zipDirectory,
}

export default exports
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const buildCommands = ({ sides }) => {
task: async () => {
// Dynamically import this function
// because its dependencies are only installed when `rw setup deploy serverless` is run
const { nftPack } = (await import('./packing/nft.js')).default
const { nftPack } = await import('./packing/nft.js')

await nftPack()
},
Expand Down

0 comments on commit 9dfbcf4

Please sign in to comment.