How to login to codeartifact for a single project - npm

I have the following structure:
nodejs_projects_directory
├ project_A
│ └ node_modules/codeartifact_dependencies
└ project_B
└ node_modules/npm_dependencies
I have to login to codeartifact to install the project_A dependencies, but then if I have to work on project_B, the npm install/yarn install goes to project_A's codeartifact repository. I have to either delete the ~/.npmrc file or login to codeartifact from the CLI every time I want to switch between the projects. Is there a way to scope the codeartifact auth token to a specific directory?
I referred to this question:
How to run AWS codeartifact login and keep default registry
But it says about namespacing not directory specific login.

Related

Problem with installing and running aws-amplify cli and global npm packages in general

I'm trying to install the aws amplify cli on my Mac. It seems to install ok, but when i run it afterwards is responds with
bash: amplify: command not found
I was thinking that it probably had something to do with the directory of the global npm packages, so i ran
$ npm -g root
Which returned:
/usr/local/lib/node_modules/node/lib/node_modules
It seems very odd that my node_modules are placed inside another node modules folder.
When i run:
$ which npm
it returns:
/usr/local/bin/npm
I also tried listing my global packages with the command
$ npm list -g --depth=0
Which returned:
/usr/local/lib/node_modules/node/lib
├── #angular/cli#7.3.1
├── #aws-amplify/cli#1.5.1
├── ng#0.0.0
├── npm#6.9.0
├── npm-check#5.9.0
├── tsc#1.20150623.0
├── typeorm#0.2.16
└── typescript#3.2.2
Can somebody please help me sort this mess out?
I ran into the same issue following the AWS Tutorial for deploying a React App: https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-two/
I used the command below as stated in the tutorial to install the Amplify CLI:
npm install -g #aws-amplify/cli
The packages installed successfully but after moving to the next step of the tutorial I got the same error:
amplify: command not found
The issue was the package was being installed outside my path and could not be found. However running the curl command below added the necessary line to my zshrc file and configured my $Path correctly.
curl -sL https://aws-amplify.github.io/amplify-cli/install | bash && $SHELL
(https://docs.amplify.aws/cli/start/install)
This is the result of running the curl command above
The line below was automatically added to my .zshrc file:
# Added by Amplify CLI binary installer
export PATH="$HOME/.amplify/bin:$PATH"
In case if someone is installing amplify using curl on Mac, then you need to edit your .zprofile (if you are using zsh terminal) or .bash_profile.
Open your terminal
1. cd
2. vim .zprofile
3. Press i, then paste this line
export PATH="$HOME/.amplify/bin:$PATH"
4. Press Esc and :wq to save this file
5. Restart your terminal

How to organise multi package flutter project and use it as dependency

I would like to organise a flutter project into a multi-package one with following requirements:
use one repository for this project
able for developers to work on the packages in this repository locally
make the packages accessible as dependencies from other projects outside of this repository
The file setup for the repository I have now is:
.
├── app_base
│ ├── ...
│ └── pubspec.yaml
├── feature
│ ├── ...
│ └── pubspec.yaml
└── README.md
I tried using path dependencies like this in app_base/pubspec.yaml:
name: app_base
dependencies:
feature:
path: ../feature
and it works for local development but if I try to use app_base in a completely different project and not use paths but a git dependency:
name: actual_app
dependencies:
app_base:
git:
url: ssh://address.to/the_repo.git
path: app_base
ref: deadbaca
it cannot resolve the transitive feature dependency:
Running "flutter packages get" in actual_app...
Error on line 21, column 11: Invalid description: "../feature" is a relative path, but this isn't a local pubspec.
path: ../feature
^^^^^^^^^^
pub get failed (65)
Process finished with exit code 65
Is there a way to make it work for both local development and used as a git dependency from other project?
Just use Git dependencies for both scenarios (locally and for other projects).
If you think this is cumbersome during local development, use path dependencies locally and change it back to Git before committing.

webpack a module that contains node_modules

Question
I want to make changes to an open source JavaScript library. Using webpack and npm and keeping everything local, what options do I have to make changes to a local module and import it into project in place of an public npm module downloaded from the registry? The local module and consuming app will also be source controlled under two separate git repositories.
Problem
I am testing this within an Aurelia app, but I think it is a webpack and npm problem. I have an app called my-app which has a dependency on aurelia-binding. I wish to make local changes to aurelia-binding and push them to a fork in GitHub. My project structure looks like this:
└───my-app
├───.git
├───dist
├───node_modules
│ └───aurelia-binding
| ├───.git
│ ├───dist
│ └───src
└───src
When built and run, everything works as expected. To make a change to aurelia-binding and test them in my-app, I need to install its dependencies and build it. This results in a structure like this:
└───my-app
├───dist
├───node_modules
│ └───aurelia-binding
| ├───.git
│ ├───dist
| ├───node_modules
| | └───dependencies...
│ └───src
└───src
When the node_modules are installed on the dependency, webpack throws an error at runtime. The error may look like an issue with the aurlia module, but I do not believe this is the case.
Unhandled rejection Error: Error invoking SVGAnalyzer. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: __WEBPACK_IMPORTED_MODULE_1_aurelia_pal__.a.createElement is not a function
I have also tried this using npm link with the library cloned next to my-app instead of within in but got the same result.
I used the following addition to the webpack.config.js to be able to use npm/yarn linked packages. It forces webpack to resolve the modules only using the main node_modules and not the "nearest" ones.
resolve: {
extensions: [".ts", ".js"],
symlinks: false,
modules: ["ClientApp", path.resolve('node_modules')],
}
Where "ClientApp" is the folder where my aurelia app is located. The symlinks parameter is used to prevent webpack from resolving the symlinked path to an absolute path.
A word of warning, with this setup you circumvent version checking by npm so you are responsible for linking a compatible version.

Require the main app "package.json"

I'm making a small web app that will be served both via npm and the git repo.
I'd like to read (via Browserify) the "package.json" of the main app, which would be:
Via Git fork:
my-app
|-package.json <-- there it is
|-src
|--app.js <-- ('require from ../package.json')
Via NPM
user-app
|-package.json <-- it's still here
|-node_modules
|--my-module
|---src
|----app.js <-- but this guy is now too far ('require from ../../../package.json')
This could still be different if the user has a custom package path. doing require('package.json') doesn't work.
Is there a way I could make sure I'll reach this file?

Share node_modules installation between sub-projects, while maintaining separate package.json files

I have the following folder structure:
project
├───components
│ ├───component-one
│ │ package.json
│ │
│ └───component-two
│ │ package.json
│ │
│ └───node_modules
├───node_modules
└───package.json
Project root project folder contains package.json and is intended to have various infrastructural modules installed (Gulp, for example, as the build is centralized).
Each component under components folder is eventually, after build and whatnot, is deployed somewhere to be consumed by an application - using the usual npm install from folder or tarball. For that reason, each component must maintain its own dependencies in its own package.json.
Going the trivial route, installing node_modules into each of the component folders would lead to a crazy amount of duplication, as there may be 100s of components, each installing mostly the same dependencies.
Ideally I would like to:
run, for example, npm install -D <module> in component-one folder
have package.json in that folder updated with the <module>
have <module> installed in the project folder
This can be achieved, to some extent, running (on Windows, in this case) mklink /D node_modules ..\..\node_modules from component-one to create a symlink.
However, symlinks are fragile and finicky, so I'd like to avoid that solution.
Is there an npm solution, via npm link or something that I am missing?