AWS Lambda Layers - git push only .zip file but no nodejs folder - javascript

I'm trying to add a layer for my aws lambda function.
The layer folder is structured like this:
layers/
nameOfLayer/
--nameOfLayer.zip
--nodejs/
-- node_modules
-- package-lock.json
-- package.json
And the nameOfLayer.zip file is structured like this:
nameOfLayer.zip
--nodejs/
-- node_modules
-- package-lock.json
-- package.json
If I git push this to my repo, I can see the .zip file but not the nodejs folder.
My .gitignore file looks like this:
*.js
!jest.config.js
*.d.ts
!lambda/*.js
.vscode
!layers/*.json
node_modules
*.json
# CDK asset staging directory
.cdk.staging
cdk.out
Why is this happening and what is the solution?
Thanks in advance
EDIT_1: My repo is at CodeCommit. Are there more options to set up stuff than the .gitignore file?

I think you want to replace !layers/*.json with !layers/**.json
The former would match layers/file.json but not layers/subdir/file.json
You need to use the double asterisk to match multiple subdirectories.
Refer to: https://git-scm.com/docs/gitignore#_pattern_format

I've added !package.json to the .gitignore probably not the best practice but it works

Related

config file on node_modules

I created a generic npm package which has my business logic, but I need some google cloud storage information that is in my config files. How can I access this file, if my package is in my node_modules folder? What would be a good solution for that?
this is the structure:
-config
-google_storage_config
-node_modules
-package
-serviceWhichNeedsThatConfig
Based on your folder structure, we will assume your path to the config will be ../../../config/google_storage_config, since node_modules/package/serviceWhichNeedsThatConfig should always be in the root directory.
Now, to access any variables from this config file, simply include the following code in the serviceWhichNeedsThatConfig,
var config = require('../../../config/google_storage_config');
console.log(config.myVariable);
Hi~Have you tried require?
var config = require('../../config/google_storage_config');

Understanding source code symlink in a Angular 2 webpack project

I have two Angular2 projects using webpack as module bundler and typescript.
Aiming to share code between, I split some of the source code and created a symlink to this 'external' source code from each of this two projects.
After doing this the "symlinked code" can not resolve the imports properly.
below a "hello world" project to shows my concerns.
https://github.com/datracka/angular2-symlink-issue
This project runs straight forward BUT if you remove the given src folder and create a symlink to another src folder with the same source code BUT located at /another/path/src then you get a compiler error:
ERROR in .-shared/src/main.ts
Module build failed: TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.dirname (path.js:1326:5)
at ensureTypeScriptInstance (/Users/vicensfayos/Projects/angular2-abc/node_modules/ts-loader/index.js:156:103)
at Object.loader (/Users/vicensfayos/Projects/angular2-abc/node_modules/ts-loader/index.js:403:14)
So my question is: what I am missing with symlinks when I "distribute" the source code in another folder out of the project folder itself?
My guess is about configure properly resolving object in webpack https://webpack.github.io/docs/resolving.html to override the node.js loading node_modules algorithm https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders but not luck.
Hopefully somebody can point me in some direction.
I found the answer.
My guess was right. it was about how nodejs resolve the dependencies. https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders
The symlinked code is trying to find the dependencies moving up all the way failing until it finds node_module. But nothing is there. node_module is in the parent project.
Therefore the solution is create another symlink from the symlinked code to the node_modules folder of the parent project to resolve the dependencies.
I have a similar setup but decided to add a path to my tsconfig.json in my main app:
"paths": {
"*": ["*", "node_modules/*"]
}
All the modules required by the source code in the shared symlinked folders are in the main app's node_modules folder. This tells the compiler to look in the main app's node_modules folder before trying to find a node_modules folder further up the tree.

How to ignore node_modules directory from gulp:watch?

I have a gulp script that watches for code changes in all javascript files. It looks like this:
gulp.watch(['./**/*.jsx', './**/*.js'], ['build:react']);
So, it watches for all .js and .jsx files from root directory, but I want to ignore node_modules directory.
How can I do that ?
You ca use gulp unwatch This removes the folder specified from your pipe. However, it's generally a good idea to have a source folder that gulp watches instead of the project root folder (then the .git directory and all sorts will be caught up in your task.

Node.js: Which module to "require('..')" to use socket.io?

In https://github.com/socketio/socket.io/blob/master/test/socket.io.js
The code:
What is the module name to require?
It requires the module from the parent directory - in this case, socket.io
A folder can be used as a module if that folder contains, index.js or package.json files etc.
So in this case it is requiring the socket.io.js file in the above folder.
Also if a package.json and index.js file are in the same folder the package.json will get look up priority.

Why am I unable to specify a relative path in a .gitignore?

I have the following directory structure on a windows machine:
.gitignore
WebUserApp/
lib/
angular/
angular-ui-router/
typings/
.gitignore and WebUserApp are at the same level and under the WebUserApp is a lib direcotry. The lib directory contains three folders and I want to ignore the sending of the angular and angular-ui-router folders.
I tried the following .gitignore and it did not work:
# Ignore
WebUserApp/lib/angular
WebUserApp/lib/angular-ui-router
I tried this .gitignore and it worked:
# Ignore
/angular
/angular-ui-router
Can someone explain to me why the first version of .gitignore does not work
I think
someFolder/
ignores all folders named someFolder independent of the level in the tree, as long as it is below the current level.
You actually might want to try:
# Ignore
/WebUserApp/lib/angular/
/WebUserApp/lib/angular-ui-router/
Then you should be able to reference an relative path.
A slash at the end of the path such as
/WebUserApp/lib/angular/
git will just ignore folders named like that, but no files or symbolic links.
Try this
angular/
angular-ui-router/
It must be work fine.

Categories

Resources