Skip to content

Commit

Permalink
fix: ignore function files with .ZIP extension (#4003)
Browse files Browse the repository at this point in the history
* fix: ignore function files with .ZIP extension

* fix: add comments to describe to fix

* chore: updated comment and log message

* chore: update log message and comment

* refactor: use path.extname to check ZIP extension

* Update src/lib/functions/registry.js

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: Lukas Holzer <lukas.holzer@netlify.com>
  • Loading branch information
3 people authored Jan 12, 2022
1 parent 463c366 commit e6f5239
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/functions/registry.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// @ts-check
const { mkdir } = require('fs').promises
const { isAbsolute, join } = require('path')
const { extname, isAbsolute, join } = require('path')
const { env } = require('process')

const terminalLink = require('terminal-link')

const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn } = require('../../utils')
const { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, log, warn } = require('../../utils')
const { getLogMessage } = require('../log')

const { NetlifyFunction } = require('./netlify-function')
const runtimes = require('./runtimes')
const { watchDebounced } = require('./watcher')

const ZIP_EXTENSION = '.zip'

class FunctionsRegistry {
constructor({ capabilities, config, isConnected = false, projectRoot, settings, timeouts }) {
this.capabilities = capabilities
Expand Down Expand Up @@ -141,6 +143,13 @@ class FunctionsRegistry {
)
}

// This fixes the bug described here https://github.com/netlify/zip-it-and-ship-it/issues/637
// If the current function's file is a zip bundle, we ignore it and log a helpful message.
if (extname(func.mainFile) === ZIP_EXTENSION) {
log(`${NETLIFYDEVWARN} Skipped bundled function ${chalk.yellow(name)}. Unzip the archive to load it from source.`)
return
}

this.functions.set(name, func)
this.buildFunctionAndWatchFiles(func)

Expand Down

1 comment on commit e6f5239

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 356 MB

Please sign in to comment.