Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local invoke with --no-build flag(s) causes deprecation warnings #965

Closed
thehideki81 opened this issue Sep 28, 2021 · 2 comments · Fixed by #1007 or #1190
Closed

local invoke with --no-build flag(s) causes deprecation warnings #965

thehideki81 opened this issue Sep 28, 2021 · 2 comments · Fixed by #1007 or #1190
Milestone

Comments

@thehideki81
Copy link

thehideki81 commented Sep 28, 2021

This is a (Bug Report)

Description

Using --no-build (and --webpack-offline) causes deprecation warnings

serverless invoke local --no-build --webpack-offline -f ${FUNCTION}

Detected unrecognized CLI options: "--build", "--webpack-offline".
Starting with the next major, Serverless Framework will report them with a thrown error
More Info: https://www.serverless.com/framework/docs/deprecations/#UNSUPPORTED_CLI_OPTIONS

Additional Data

"serverless": "^2.44.0",
"serverless-offline": "8.2.0",
"serverless-webpack": "^5.5.0",
"webpack": "^5.4.0"
@thehideki81
Copy link
Author

thehideki81 commented Sep 28, 2021

I'm currently using a custom plugin to circumvent this issue, can be used as a helper if this issue is not fixed before Serverless Offline 3.0

It also has support to fix no-build without individual packaging

'use strict'

class ServerlessPlugin {
  constructor(serverless, options) {
    this.hookEnabled = false
    this.serverless = serverless
    this.options = options
    this.individually = this.serverless.service.package.individually

    this.hooks = {
      'before:invoke:local:invoke': this.prepareWebpackOfflineInvoke.bind(this),
      'after:invoke:local:invoke': this.finishWebpackOfflineInvoke.bind(this)
    }
  }

  prepareWebpackOfflineInvoke() {
    // Use normal services folder for invokes
    if (this.individually && process.env.IS_OFFLINE) {
      this.hookEnabled = true
      // Serverless from 3.x doesn't support custom CLI parameters.
      // We do a trick to provide some options to serverless-webpack through this plugin.
      // Revisit this when this maybe fixed:
      // https://github.com/serverless-heaven/serverless-webpack/issues/965
      this.serverless.processedInput.options.build = false
      this.serverless.processedInput.options.webpack_offline = true
      // Disable individual packaging. Fixes serverless-webpack usage without building again.
      this.serverless.service.package.individually = false
    }
  }

  finishWebpackOfflineInvoke() {
    // change back
    if (this.hookEnabled) {
      this.serverless.service.package.individually = true
    }
  }
}

module.exports = ServerlessPlugin

@vicary
Copy link
Member

vicary commented Sep 28, 2021

CLI options are more restrictive now, though it still works. One of the options I could think of is falling back to serverless.yml, e.g. custom.webpack.build so users can use the ${file:(foo.js)} syntax without making a custom plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants