Comments (13)
Ah ok, yes we can fix that by moving the sequence around a bit
from nx-plugins.
Hi! ... was wonderng is there an error message somewhere? because i check the serverless code, and it seems to be included, but i am having a hunch about the file path that might be screwing up ...
Below is their function ... If you can provide an error or any warning messages? If not I will debug into their code. If you could help out it would be awesome .. 😄
D:\<your-project>\node_modules\serverless\lib\classes\Variables.js
getValueFromFile(variableString) {
const matchedFileRefString = variableString.match(this.fileRefSyntax)[0];
const referencedFileRelativePath = matchedFileRefString
.replace(this.fileRefSyntax, (match, varName) => varName.trim())
.replace('~', os.homedir());
let referencedFileFullPath = path.isAbsolute(referencedFileRelativePath)
? referencedFileRelativePath
: path.join(this.serverless.config.servicePath, referencedFileRelativePath);
// Get real path to handle potential symlinks (but don't fatal error)
referencedFileFullPath = fse.existsSync(referencedFileFullPath)
? fse.realpathSync(referencedFileFullPath)
: referencedFileFullPath;
let fileExtension = referencedFileRelativePath.split('.');
fileExtension = fileExtension[fileExtension.length - 1];
// Validate file exists
if (!this.serverless.utils.fileExistsSync(referencedFileFullPath)) {
return BbPromise.resolve(undefined);
}
let valueToPopulate;
// Process JS files
if (fileExtension === 'js') {
// eslint-disable-next-line global-require, import/no-dynamic-require
const jsFile = require(referencedFileFullPath);
const variableArray = variableString.split(':');
let returnValue;
if (variableArray[1]) {
let jsModule = variableArray[1];
jsModule = jsModule.split('.')[0];
returnValue = jsFile[jsModule];
} else {
returnValue = jsFile;
}
if (typeof returnValue === 'function') {
valueToPopulate = returnValue.call(jsFile, this.serverless);
} else {
valueToPopulate = returnValue;
}
return BbPromise.resolve(valueToPopulate).then(valueToPopulateResolved => {
let deepProperties = variableString.replace(matchedFileRefString, '');
deepProperties = deepProperties.slice(1).split('.');
deepProperties.splice(0, 1);
return this.getDeeperValue(deepProperties, valueToPopulateResolved).then(
deepValueToPopulateResolved => {
if (unsupportedJsTypes.has(typeof deepValueToPopulateResolved)) {
const errorMessage = [
'Invalid variable syntax when referencing',
` file "${referencedFileRelativePath}".`,
' Check if your javascript is returning the correct data.',
].join('');
return BbPromise.reject(new this.serverless.classes.Error(errorMessage));
}
return BbPromise.resolve(deepValueToPopulateResolved);
}
);
});
}
// Process everything except JS
if (fileExtension !== 'js') {
valueToPopulate = this.serverless.utils.readFileSync(referencedFileFullPath);
if (matchedFileRefString !== variableString) {
let deepProperties = variableString.replace(matchedFileRefString, '');
if (deepProperties.substring(0, 1) !== ':') {
const errorMessage = [
'Invalid variable syntax when referencing',
` file "${referencedFileRelativePath}" sub properties`,
' Please use ":" to reference sub properties.',
].join('');
return BbPromise.reject(new this.serverless.classes.Error(errorMessage));
}
deepProperties = deepProperties.slice(1).split('.');
return this.getDeeperValue(deepProperties, valueToPopulate);
}
}
return BbPromise.resolve(valueToPopulate);
}
I am thinking this would be the culprit.
if (!this.serverless.utils.fileExistsSync(referencedFileFullPath)) {
return BbPromise.resolve(undefined);
}
from nx-plugins.
@hiepinnomizetech so, did you have to add some new package to the package.json
? If so lets fix it to be a depedency needed for the lib :)
from nx-plugins.
i am looking at the project this week and next. We will have an update within first week jan and again first week feb 👍🏽
from nx-plugins.
following this issue for the fix --> serverless/serverless#2997
from nx-plugins.
Could you help paste a reference to serverless importing yml as function? I dont think i considered this feature when building it as we don't use it. But I would be happy to in-corporate it into the library! 😄
from nx-plugins.
I have created an example at https://github.com/hiepinnomizetech/nx-serverless
In this example, I separate AWS cloud formation to 3 files serverless.config.yml, hello-world.yml and serverless.yml. But I think file() function isn't supported by this plugin (https://www.serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-in-other-files).
I hope you can include this feature in the plugin. My current project has a large serverless.yml. If this plugin can separate serverless.yml, it is so great.
Thank you very much!
from nx-plugins.
Hi @hiepinnomizetech I haven't forgot this, will be looking into it this working week 😄
from nx-plugins.
@wickstargazer , i have checked and I see serverless has included other files by using file() function. Thank so much!
from nx-plugins.
@hiepinnomizetech So should i add some new dependency for the file()
funciton? i still dint get the answer 😄
from nx-plugins.
@wickstargazer thanks!
I only tested file() function can load another file data, but I didn't test why it doesn't work in Demo project (I think it is caused by include URL). So I will close issue. Thank you very much!
from nx-plugins.
@wickstargazer , I have found root cause.
If I use file() function on Lambda function section:
functions: hello-world: ${file(hello-world.yml)}
hello-world.yml will not be loaded because file() function doesn't run.
But if i use file() function on custom section:
custom: config: ${file(serverless.config.yml)}
serverless.config.yml will be loaded.
from nx-plugins.
Any update @wickstargazer?
Our project's growing to a size where splitting into separate files would be useful
from nx-plugins.
Related Issues (20)
- [BUG] Cannot create new api HOT 1
- [BUG] Cannot find module '@nrwl/workspace/src/utilities/run-webpack' HOT 1
- [BUG] Schematic "init" cannot resolve the factory. HOT 3
- [BUG] nx-serverless: Property 'port' does not match the schema. '7777' should be a 'number'. HOT 1
- [BUG] When using npm as packager, pacakgelist is not properly computed resulting in "*" for all package versions HOT 2
- [FEAT] Webpack stats.json support HOT 4
- [BUG] NX 13 and Webpack5 Support HOT 10
- Configuration error at 'useDotenv': should be equal to constant HOT 2
- [BUG] After creating monorepo blank workspace not able to create api HOT 3
- [FEAT] Nx-Serverless | option to exclude ALL dependencies from build HOT 1
- Cannot destructure property 'name' of 'node' as it is undefined. - @flowaccount/scully-plugin-angular-delay
- Support newer Serverless framework
- [BUG] Not able to run or build the freshly scaffolded project HOT 3
- [FEAT] Build functions individually HOT 9
- [BUG] Zip file resolution error when deploying a single artifact HOT 18
- Allow for a serverless.ts file HOT 8
- [BUG] External dependencies are unavailable after deploying HOT 5
- [BUG] Cannot Include Json Schema in serverless.yml HOT 6
- [BUG] Runtime.ImportModuleError in every Lambda function after deploying new project HOT 2
- [BUG] Missing compat.ts for sls executor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nx-plugins.