nvm-windows Node.js version change in NW.js - javascript

I am using nvm-windows and I've two different node.js versions installed.
I am also working with nw.js but after having some problem with async/await I checked the node.js installation in use running:
nvm ls
I get:
* 14.6.0 (Currently using 64-bit executable)
5.11.0
But when I console.log the node.js version inside the nw.js app I get:
console.log(process.version);
console.log(process.versions['nw']);
console.log(process.versions['chromium']);
v5.12.0
0.14.7
50.0.2661.102
So I am clearly missing something!
Is there a way I can specify to nw.js the node.js version to use?
my package.json dependencies:
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.0",
"bootstrap": "^4.5.2",
"jquery": "^3.5.1",
"popper.js": "^1.16.1"
},
"devDependencies": {
"nw": "^0.48.3-sdk",
"nwjs-builder-phoenix": "^1.15.0"
}
Also inside package.json:
"scripts": {
"dist": "build --tasks win-x86,win-x64,linux-x86,linux-x64,mac-x64 --mirror https://dl.nwjs.io/ .",
"start": "run --x86 --mirror https://dl.nwjs.io/ ."
},
as suggested here because I am using nwjs-builder-phoenix

To solve the problem use nw u [version] like:
nw u 0.48.3
Then add this snippet to the package.json:
"build": {
"nwVersion": "0.48.3"
},
It is needed by nwjs-builder-phoenix to chose the nw version to use.
And run npm start again
[ Also helpful ]
To install a new nw version run nw i [version]

Related

Firebase Functions + monorepo - Deploying doesn't work + deps not installed locally

Looks like someone has the same problem here: https://github.com/firebase/firebase-functions/issues/1050
Problem
I have moved my project structure to a monorepo with the following structure:
/
|
| - node_modules/
|
| - packages/
| - - app/
| - - - - index.js
| - - - - package.json
| - - functions/
| - - - - src/
| - - - - - - helloWorld.function.js
| - - - - - - index.js
| - - - - package.json
|
| - .firebaserc
| - firebase.json
| - firestore.indexes.json
| - firestore.rules
| - package.json
| - yarn.lock
| - LICENSE.md
As far as I know, all code our functions depends on must be inside the functions directory. But... when I run yarn install, the node_modules of my functions are saved in the root node_modules folder.
Then, if I run firebase deploy from the root of my project, I get the error:
Error: Error occurred while parsing your function triggers.
The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Note: I haven't made any code change... before configuring the project to the monorepo structure, everything worked fine.
My attempt to solve this problem
I have tried to use nohoist when defining my workspaces inside my root package.json:
{
"private": true,
"name": "#company/project",
"version": "1.0.0",
"description": "Project monorepo",
"repository": "...",
"license": "MIT",
"author": {
"name": "Raul",
"email": "...
},
"scripts": {
"app": "yarn workspace #company/app start",
"documentation": "yarn workspace #company/documentation start",
"server": "yarn workspace #company/server start"
},
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/#company/server"] <---- HERE
}
}
-Note: when I run yarn server the functions shell is started correctly.
But... for some reason, after reinstalling everything:
rm -rf node_modules (everywhere)
yarn cache clean
yarn install
The dependencies of the functions packages are installed in the root node_modules!
Any ideas?
This is how my functions node_modules looks like after installing the deps:
node_modules/
.bin/
eslint
eslint-config-prettier
firebase-functions
functions-framework
functions-framework-nodejs
image_size
uuid
qs/
uuid/
And these are the dependencies required (which are installed in the root package.json, which is not the behavior I expect):
"name": "#company/server",
...
"dependencies": {
"#google-cloud/functions-framework": "^3.1.1",
"#google-cloud/translate": "^6.3.1",
"#google-cloud/vision": "^2.4.2",
"#googlemaps/google-maps-services-js": "^3.3.3",
"axios": "^0.27.2",
"camelcase": "^6.3.0",
"dotenv": "^16.0.1",
"expo-server-sdk": "^3.6.0",
"firebase-admin": "^10.3.0",
"firebase-functions": "^3.21.2",
"glob": "^7.2.0",
"image-size": "^1.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.3",
"qs": "^6.10.3",
"sharp": "^0.30.6",
"uuid": "^8.3.2"
},
"devDependencies": {
"eslint": "^8.3.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1",
"firebase-functions-test": "^0.2.0"
}
UPDATE
Instead of nohoisting in the root, I have placed this segment in the packages/functions/package.json:
workspaces: { nohoist: ["**"] }
and all the deps are installed locally!
But... when I do firebase deploy, same error. If instead of running the command from the root folder I do it from packages/functions/package.json the deployment is successful.
Why? What is happening?
This is my firebase.json file:
{
"functions": {
"predeploy": ["yarn --cwd \"$RESOURCE_DIR\" lint"],
"source": "packages/functions"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}
Workaround (Not the correct solution, just a trick):
Instead of using nohoist to installing all the deps locally inside the packages/functions directory, what about excluding it from the yarn workspaces?
For this, update your root's package.json to:
"workspaces": [
"packages/app",
"packages/documentation"
]
(packages/functions is not included as a workspace.)
Test it:
Now, if you run (wherever you want in your project) firebase deploy, everything works fine... the deployment is successful and all our backend deps are installed locally (it is required, since all the cloud functions code must be inside the functions folder).
Also, this error is solved too!
Pros:
You can maintain the monorepository structure and deploy your cloud functions without problems.
Cons:
This is a tricky solution... when you run yarn install from the root of your project, packages/functions/package.json dependencies are not installed (as we have remove it from the workspace in order to install them locally.)
In order to solve this little issue, in your root package.json, write the following:
{
"scripts": {
...,
"postinstall": "cd path/to/your/functions && yarn install", // automatically executed after running `yarn install`
}
}
in my case:
{
"scripts": {
...,
"postinstall": "cd packages/functions && yarn install", // automatically executed after running `yarn install`
}
}

Editing package.js file

i'm having a hard time to understand how to run all of my .js files using package.js files
i have almost 2000.js scripts i need to run them one by one, i'm using a api made by gameflip
in the folder i found package.js, but i don't know how to use it ,
can anyone tell me how to do that ? thank you
here the script :
{
"name": "gfapi",
"version": "0.1.1",
"description": "Gameflip API",
"keywords": "Gameflip",
"homepage": "https://github.com/iJJi/gfapi",
"bugs": "https://github.com/iJJi/gfapi/issues",
"author": {
"name": "Eng-Shien Wu",
"email": "engshien.wu#ijji.com"
},
"license": "MIT",
"private": true,
"files": [
"index.js"
],
"repository": "iJJi/gfapi",
"engines": {
"node": ">=8.5.0"
},
"scripts": {
"bulk_listing": "node src/samples/bulk_listing.js",
"test": "ENVIRONMENT=mocha mocha src/test --recursive",
"docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
},
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^3.5.0",
"bunyan": "^1.8.12",
"file-type": "^8.1.0",
"http-errors": "^1.6.2",
"node-rest-client-promise": "^3.1.1",
"promise-ratelimit": "^0.0.3",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"marked": "^0.3.19",
"docco": "^0.7.0",``
"jsdoc": "^3.5.5"
}
}
What you posted isn't a package.js (I don't even know if it exists), but a package.json. It's generated by NPM, the Node Package Manager. It's a list of all the project's dependencies. I think that what you're looking for are the npm scripts, they are in the script object of package.json.
npm run <script>
# For example :
npm run bulk_listing
npm run test
npm run docs
Each script will run its associated command in this package.json.
npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js
More about package.json.
The script I talked about below
If you want to run all the scripts, this should do the job :
const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?
fileNames.forEach(async (path, index) => {
// It's pretty much like 'node <path>'
await require(path);
// All the code here is executed AFTER the script has been launched
console.log(`LAUNCHED ${index} | ${path}`)
});

Meteor import directory test files not eagerly loading

Meteor version 1.7.0.5
Using meteortesting:mocha
I have a very simple meteor react app. I added a test file in imports/startup/simple-schema.tests.js
describe('Todos_item', function () {
console.log('Todo');
});
I was running npm run test-app so it should be logged in console but that file actually doesn't run. But when I added this snippet to my tests/main.js Todo is logged in console. So am I missing something.
My directory tree
package.json
{
"name": "meteor-bootstrap",
"private": true,
"scripts": {
"start": "meteor run",
"test": "meteor test --once --driver-package meteortesting:mocha",
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
"visualize": "meteor --production --extra-packages bundle-visualizer"
},
"dependencies": {
"#babel/runtime": "7.0.0-beta.55",
"meteor-node-stubs": "^0.4.1",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-router-dom": "^4.3.1",
"simpl-schema": "^1.5.3"
},
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests/main.js"
},
"engines": {
"node": "8.11.4"
}
}
Any help will be greatly appreciated. Thanks in advance.
New Meteor apps since 1.7 have eager loading turned off by default (which is causing your problem)
The behaviour is controlled by the meteor section in your package.json.
To restore the eager loading behaviour for tests, delete the testModule key-value pair from your package.json. It should look like this:
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
}
},
If you want to restore pre-1.7 behaviour for all files, just delete the whole meteor section from package.json
If you don't want to use eager loading, you will need to import all of your test files from the tests/main.js file
Also one thing to add when with #Fred answer importing test files have to use require not import though I am not sure is it due to my node version or not I am using my node version v6.11.1

does Babel with the `es2016` preset implement tail call optimization?

I used the following example to test tail call recursion with Babel and the es2016 preset:
'use strict';
try {
function r(n) {
if (n%5000===0)
console.log(`reached a depth of ${n}`);
r(n+1);
}
r(0);
} catch (e) {
if (!(e instanceof RangeError))
throw e;
else
console.log('stack blown');
}
My package.json file is:
{
"name": "tail-call-optimization",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel es6 --out-dir es5 --source-maps",
"watch": "babel es6 --out-dir es5 --source-maps --watch",
"start": "node es5/app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.7.4",
"babel-preset-es2016": "^6.0.10",
"babel-runtime": "^6.6.1"
},
"dependencies": {
"babel-polyfill": "^6.7.4",
"source-map-support": "^0.4.0"
}
}
... and the .babelrc is simply:
{
"presets": ["es2016"]
}
Running the above with:
npm run build && npm run start
... results in the following console output:
reached a depth of 0
reached a depth of 5000
reached a depth of 10000
reached a depth of 15000
stack blown
Indeed, looking at the transpiled file in the es5 directory, there's nothing to suggest that TCO has been implemented.
Am I missing something?
My node version is 4.3.2.
Looking at: https://babeljs.io/docs/learn-es2015/ one reads:
Temporarily Removed in Babel 6
Only explicit self referencing tail recursion was supported due to the complexity and performance impact of supporting tail calls globally. Removed due to other bugs and will be re-implemented.
So I guess it's not presently implemented.
None of the "official" Babel 6 plugins / presets currently implements TCO. babel-preset-es2016 is not an "official" preset. Unless TCO relies on parser support in Babylon (off the top of my head I wouldn't think so, but I'm not sure) then I suppose a userland plugin / preset could implement it, and perhaps does (but not that I know of). Here is the issue tracking eventual "official" re-implementation: T2614. If someone wants to PR that link into the Learn ES2015 docs #Marcus mentioned ping me here and I'll merge it.

Require highcharts-browserify to use specific version of highcharts?

I'm working with highcharts-browserify. This is what my package.json file looks like:
{
"main": "index.js",
"scripts": {
"watch-index": "watchify index.js -o ../../static/js/index.js --debug --verbose",
"watch": "npm run watch-index",
"build-index": "browserify index.js | uglifyjs > ../../static/js/index.min.js",
"build": "npm run build-index"
},
"dependencies": {
"highcharts-browserify": "^0.1.5-4.1.7",
"jquery": "^1.11.3",
}
}
However, when I run npm run watch, the compiled file has v4.0.4 of Highcharts in it, not the latest version (v4.1.7).
How can I make sure I've got the latest version?
I need to use the latest version because of this bug in x-axis labels in v4.0.4 of Highcharts: http://jsfiddle.net/5z8rf83y/7/
The highcharts-browserify library currently uses v 4.0.4.
https://github.com/soldair/highcharts-browserify/blob/master/highcharts.js#L2
You could open a ticket to have it updated, or fix it and submit a pull request.
Also, you can by pass using this library, and use browserify-shim which would look like this -
{
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"Highcharts": {
"depends": ["HighchartsAdapter:HighchartsAdapter"],
"exports": "Highcharts"
},
"HighchartsAdapter": {"exports":"HighchartsAdapter"}
},
"browser": {
"Highcharts": "./bower_components/highcharts-release/highcharts.src.js",
"HighchartsAdapter": "./bower_components/highcharts-release/adapters/standalone-framework.src.js"
}
}

Categories

Resources