Giter Club home page Giter Club logo

Comments (8)

wickstargazer avatar wickstargazer commented on July 18, 2024 2

@ubergeoff We have released 1.1.0 that supports serverless.ts but there is sitll a bug when using import statements in the file itself. havent figured that out

from nx-plugins.

ubergeoff avatar ubergeoff commented on July 18, 2024 1

Side note: The solution should be backwards compatible, correct?

i.e. users/devs should have the choice to choose between the serverless.yml file for the serverless.ts file - are you happy with this..?

from nx-plugins.

wickstargazer avatar wickstargazer commented on July 18, 2024

sounds like awesomeness, would you like to open a pr? i can walk you through the code 🚀

from nx-plugins.

ubergeoff avatar ubergeoff commented on July 18, 2024

OK. Can do... whats the effort involved? (if you have to guess) ..?

from nx-plugins.

wickstargazer avatar wickstargazer commented on July 18, 2024

These are the two main places you need to fix

  1. Change all the configs to use .ts instead of .yaml
  2. rename the template file
  3. revisit the spec.ts and make sure it checks for .ts instead of .yaml
  4. Make sure the serverless.ts has the right initial code so that when schematics are generated it works out of the box

Tips:

  1. use yarn link to do local testing
  2. in https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/utils/serverless.ts change import on the first line to be import * as Serverless from '/node_modules/serverless/lib/Serverless.js'; instead of 'serverless/lib/Serverless'; for local testing to work.

https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/schematics/utils.ts#L18
https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/schematics/api/files/serverless.yml.template

See whts comfortable :) we can review the code once its done :)

from nx-plugins.

ubergeoff avatar ubergeoff commented on July 18, 2024

++ Serverless has this code in it: (when reading the serverless config file)

case '.ts': {
      if (!process[Symbol.for('ts-node.register.instance')]) {
        const tsNodePath = await (async () => {
          try {
            return await resolveTsNode(path.dirname(configurationPath));
          } catch (error) {
            throw new ServerlessError(
              `Cannot parse "${path.basename(
                configurationPath
              )}": Resolution of "ts-node" failed with: ${error.message}`,
              'CONFIGURATION_RESOLUTION_ERROR'
            );
          }
        })();
        try {
          require(tsNodePath).register();
        } catch (error) {
          throw new ServerlessError(
            `Cannot parse "${path.basename(
              configurationPath
            )}": Register of "ts-node" failed with: ${error.message}`,
            'CONFIGURATION_RESOLUTION_ERROR'
          );
        }
      }
    }
    // fallthrough
    case '.js': {
      const configurationEventuallyDeferred = (() => {
        try {
          return require(configurationPath);
        } catch (error) {
          if (isModuleNotFoundError(error, configurationPath)) {
            throw new ServerlessError(
              `Cannot load 1 "${path.basename(configurationPath)}": File not found`,
              'CONFIGURATION_NOT_FOUND'
            );
          }
          console.log(error);

          throw new ServerlessError(
            `Cannot load 2 "${path.basename(configurationPath)}": Initialization error: ${
              error && error.stack ? error.stack : error
            }`,
            'CONFIGURATION_INITIALIZATION_ERROR'
          );
        }
      })();
      try {
        return await configurationEventuallyDeferred;
      } catch (error) {
        throw new ServerlessError(
          `Cannot load "${path.basename(configurationPath)}": Initialization error: ${
            error && error.stack ? error.stack : error
          }`,
          'CONFIGURATION_INITIALIZATION_ERROR'
        );
      }
    }

However - it never seems to run to the .ts path - it always lands up in the "fall through" .js path... Any idea's why that might happen..?

The error I get is:

An unhandled exception occurred: Cannot load 2 "serverless.ts": Initialization error: C:\t2-online\t2\apps\myapi\serverless.ts:1
import { environment } from './environment';
^^^^^^

SyntaxError: Cannot use import statement outside a module

from nx-plugins.

wickstargazer avatar wickstargazer commented on July 18, 2024

Side note: The solution should be backwards compatible, correct?

i.e. users/devs should have the choice to choose between the serverless.yml file for the serverless.ts file - are you happy with this..?

I agree, as for the .js file i think its because the code is compiled into '.js' before the serverless commands are run? ... I am not sure when those switches are executed if before webpack-compile it should be ok but i am suspecting its after... Do you have a branch i can jump into?

from nx-plugins.

kevb10 avatar kevb10 commented on July 18, 2024

any update on this?

from nx-plugins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.