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
Initialization extensions (move TS handling to extension package) #9311
Labels
Comments
@fredericbarthelet @pgrzesik let me know what you think about this proposal |
Thanks @medikoo for a detailed proposal 🙌 It looks great in my opinion from a extension-agnostic point of view - as I'm not an expert on TS-related stuff, I cannot fully say that it will allow to support all intended use cases listed on original issue in |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case description
Originally discussed at serverless/typescript#28 (comment)
Framework already supports plugins. Still plugins can be configured only through service configuration, which means that there's no way to e.g. add support for different file type to serve as configuration type through plugin.
In light of that, such support needs to be baked into Framework internals (and this is what we did with TypeScript). Still that proves to be limited, error-prone, and incurs additional maintenance cost to the core.
Ideally if such extension can be configured externally and injected prior service file resolution.
Having that we could also move all TS related support to
@serverless/typescript
, and in its context solve all TS related challenges and make TS support even better.Proposed solution (Strategy)
Recognize
serverless.extensions
property inpackage.json
(resolved from current working directory only) which should be an array listing all extensions to be loaded whenserverless
command is invoked.Each item in
serverless.extensions
should be a path to module, to be resolved with Node.js module resolution rules, e.g:Will attempt to load main module of
@serverless/typescript
package fromnode_modules
Extension should export an object, which may expose following properties:
resolveServiceConfiguration
- (possibly async) function which will be invoked before Framework internally attempts to resolve the service configuration. When invoked it should either returnnull
, or object withconfiguration
,serviceDir
andconfigurationFilename
properties.variableFileSources
- Object with configuration of support for additional file import variable extensions.Example:
How to implement it? (Tactics)
1. Extensions resolution
lib/cli/resolve-initialization-extensions.js
module, which should:package.json
from current working directoryserverless.extensions
property. It should validate it as an array (if it isn't it should throw meaningful error), and should load each extension, then it should confirm that all of them export plain object, with optionalresolveServiceConfiguration
plain function, and optionalvariableFileSources
plain object, on which all properties are plain functions. Module should return array of resolved extensions.serverless
process intialization resolve extensions withlib/cli/resolve-initialization-extensions.js
util.2. Resolution of configuration data through extension
Right before we resolve configuration path internally, run
resolveServiceConfiguration
from all resolved extensions, stop on first that resolves a value. Validate existence of all propertiesconfiguration
,serviceDir
andconfigurationFilename
.if configuration data was resolved from extension, use it in the process, and do not resolve those values internally.
3. Registration of new file source extension
serverless/scripts/serverless.js
Line 208 in 712a569
this.customFileResolvers
here:serverless/lib/configuration/variables/sources/file.js
Line 140 in 712a569
The text was updated successfully, but these errors were encountered: