How to inject pouchdb-browser - npm

I work on an web app with pouchdb, and protractor for e2e tests.
Recently, following pouchdb documentation, we switch from npm pouchdb package to pouchdb-browser package, which is more suitable for in-browser use.
It has a side effect as we also inject pouchdb from portractor in order to force some state during e2e test:
export namespace pouchBackdoor {
function _inject(): void {
browser.executeScript('return typeof PouchDB == "undefined"').then(res => {
if (res) {
let lib = path.join(
__dirname, '../node_modules/pouchdb/dist/pouchdb.js');
browser.executeScript(fs.readFileSync(lib, 'utf-8'));
}
});
}
Following the modification node_modules/pouchdb doesn't exist anymore and our test dont pass.
A quick workaround is to re-install the complete pouchdb distribution for the dev environment, but it's not really satisfying as everything we need should be in pouchdb-browser already.
So I tried to find the equivalent of node_modules/pouchdb/dist/pouchdb.js file in node_modules/pouchdb-browser/ folder but it turns out that i'm not able to do it.
I tried to use node_modules/pouchdb-browser/lib/index.js but it returns the following error:
Failed: unknown error: require is not defined
Which make sence as require doesn't exist in browser environment.
So my question is, does anyone tried to do the same and find a solution, or you does anyone know better how npm works and can give me any leads ?
PS: there is the contain of my node_modules/pouchdb-browser/ folder after a clean npm install pouchdb-browser:
pouchdb-browser/
├── lib
│   ├── index.es.js
│   └── index.js
├── LICENSE
├── node_modules
│   └── lie
│   ├── ...
├── package.json
└── README.md
Thanks for reading !
Edit:
Issue open in github/pouchdb to ask for pouchdb.js inclusion in pouchdb-browser package:
https://github.com/pouchdb/pouchdb/issues/6745

Related

Vue packages version mismatch

I'm trying to deploy my old nuxt project again with new changes but I get this error even tho I removed the node_modules folder, package-lock.json & refreshed the npm cache and of course run npm i after all of this + I don't have neither of these packages in my package.json.
Here's the error I'm getting after running npm run dev:
Vue packages version mismatch:
- vue#3.2.45
- vue-server-renderer#2.7.14
This may cause things to work incorrectly. Make sure to use the same version for both.
here's my package.json:
├── #nuxtjs/axios#5.13.6
├── #nuxtjs/dotenv#1.4.1
├── #nuxtjs/vercel-builder#0.22.1
├── #nuxtjs/vuetify#1.12.3
├── #stripe/stripe-js#1.46.0
├── body-parser#1.20.1
├── cookie-parser#1.4.6
├── cookieparser#0.1.0
├── core-js#3.26.1
├── cors#2.8.5
├── express#4.18.2
├── gsap#npm:#gsap/shockingly#3.11.3
├── nuxt-gsap-module#1.7.2
├── nuxt#2.15.8
├── stripe#8.222.0
├── underscore#1.13.6
└── vuex-persistedstate#4.1.0
I have tried all I can but cannot come up with a solution. Is there anything I could try to make this work?
Please execute this command.
npm install vue#2.7.14 --save

Yarn Workspaces seemingly not recognizing directory

Wasn't sure the best verbiage for the title, but basically I have a monorepo setup using yarn workspaces. It works for every other directory I have. Here's my layout to make it easy to visualize
├── root
├── package.json
├── node_modules
├── appsync
│ ├── package.json
├── aurora
│ ├── package.json
├── lambdas
│ ├── lambda-function-1
│ ├── └── package.json
│ ├── lambda-function-2
│ ├── └── package.json
Roughly this is as simple as I can make it without getting into too much unnecessary detail. In my root package.json I have my yarn workspaces setup like so:
"workspaces": {
"packages": [
"./*",
"aurora/*",
"lambdas/**",
]
}
The issue is this:
For every other directory I have. Yarn Workspaces is working perfectly. appsync is covered in the ./* declaration. And I have packages in that package.json that get installed property to the root directory and not in the appsync directory. Same with my lambdas. I define those differently because it wont be covered from the ./* declaration. And this works great too, no issues.
Today I added a new directory, and to my surprise saw modules being installed to aurora and not to the root. So I'm very confused whats wrong with my root package.json thats causing this? Or any ideas I can try to get more information? I have done yarn both at root and in the aurora directory as well, and no matter what I try, it always installs modules to the aurora directory and also adds a yarn.lock file to that directory as well.
Any help is appreciated.

How to use npm workspace

I develop my app by using npm workspace.but I am totally novice to this concept so that I would like to understand npm workspace behavior
.
├── package.json
└── packages
├── a
│ └── package.json
├── b
│ └── package.json
└── c
└── package.json
package.json
{
"workspaces": [
"packages/*"
]
}
My question is
①what happens when I run npm install in root directory ?
All the packages are installed in each repository ? or root directory ?
②npm install in each project is not recommended ?
if someone has opinion, will you please let me know.
Thanks
So long as all packages have the same version of dependencies listed (e.g. thing#1.0.0), then npm install run from the root of your repository will add the dependency into the root node_modules directory.
If one of your packages (e.g. packages/c) has a different version of a dependency (e.g. thing#1.0.1) then that would appear in packages/2/node_modules)
In theory you are using npm workspaces to ensure some consistency across packages, therefore ensuring your versions are consistent will mean node_modules is only ever created in the root of your repository

NPM doesn't work properly with scoped modules from git repos

I'm still waiting for the company set up its account on NPM to allow me to use private modules.
Meanwhile, I'm making it work with npm + git private repos.
In order to reduce the friction when we finally switch to NPM private modules, I was willing to declare dependencies like:
{
"dependencies": {
"#company/repo": "git+https://<token>:x-oauth-basic#github.com/company/repo"
}
}
And then, in my code, do this:
import repo from '#company/repo'
However, when I run npm installand inspect my node_modules/, instead of finding something like:
node_modules
├── #company
│   └── repo
├── ...
The resulting structure is flat, there is no #company folder:
node_modules
├── repo
├── ...
I couldn't find anything in the NPM docs about this behavior with git repos, so I want to know if this is a possible bug or if it's working as designed.

How do I setup a Minecraft Forge development environment?

I want to start creating awesome Minecraft mods, and it seems that the current way to do so is with Minecraft Forge. I already got Gradle and the JDK installed, but no matter what I do I can't seem to get anything to build.
How can I get a Forge development environment working?
After downloading the Forge Mod Development Kit (MDK) archive, it should contain the following files:
forge-somewhere/
├── build.gradle
├── CREDITS-fml.txt
├── eclipse
├── forge-1.10.2-12.18.1.2073-changelog.txt
├── gradle
│   └── wrapper
│   ├── gradle-wrapper.jar
│   └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── LICENSE-new.txt
├── MinecraftForge-Credits.txt
├── Paulscode IBXM Library License.txt
├── Paulscode SoundSystem CodecIBXM License.txt
├── README.txt
└── src
└── main
├── java
│   └── com
│   └── example
│   └── examplemod
│   └── ExampleMod.java
└── resources
└── mcmod.info
In the README.txt there are instructions on how to set it up, but to put it simple, open a console/terminal in forge-somewhere and run gradle setupDecompWorkspace. It should set up a development environment and then you should be able to run gradle build normally. Note that you have to re-run setupDecompWorkspace for every mod you want to develop/compile.
If you're not using an IDE, or the command fails because of heap memory, you can use gradle setupDevWorkspace instead. This doesn't decompile Minecraft, so you won't be able to check the sources (which you can't without an IDE or something anyway), but it doesn't use nearly as much RAM, which is useful if you're on a lower-end system.
Simple:
Once you have downloaded the Forge .zip for the version that you plan on using, go to the same directory as your "gradlew.bat" file, hold shift-rightclick and open the command prompt.
Type:
gradlew.bat setupDecompWorkspace eclipse
Or if you're running with Intellij Idea (Which I recommend):
gradlew.bat setupDecompWorkspace idea
After that, it'll set up the Workspace as well as the correct coding software package that you wish to be using.