how to override package.json name and version fields - npm

If the package.json is as follows :
{
"name": "mypackage",
"version": "0.0.1"
"scripts": {
"test": "program.js"
}
}
program.js uses npm version during execution.
Is there a way to override the package.json version so that program.js takes the overridden version?

Related

make lerna update package containing 2 versions

I have a requirement where we will have the depedency declared in the package.json as
"sample-package" : "file:../../sample-package || 1.0.0"
when we publish "sample-package" we want to make sure it updates the package dependency as below:
"sample-package" : "3.0.0 || 1.0.0"
but looks like lerna is not updating the version and it is same as above after checking the dependency in published package.
how to achieve the above result?
our lerna.json looks like below:
{
"packages": [
"components/*"
],
"version": "3.0.0",
"command": {
"init": {
"exact": true
},
"version": {
"exact": true,
"forcePublish": true
}
}
}

How to setup plain text env vars in Expo build?

I'm working on an expo project and trying to link environment variables for build profiles. I was trying to achieve that using eas.json but I cannot get it to work.
I have two build profiles - development and production:
{
"cli": {
"version": ">= 3.3.1"
},
"build": {
"development": {
"distribution": "internal",
"env": {
"API_URL": "https://staging-api.example.com",
"STRIPE_ENV": "test"
},
"ios": {
"resourceClass": "m1-medium"
}
},
"production": {
"env": {
"API_URL": "https://api.example.com",
"STRIPE_ENV": "production"
},
"ios": {
"resourceClass": "m1-medium"
},
"autoIncrement": true
}
},
"submit": {
"production": {
...
}
}
}
Build command:
eas build --profile development --platform ios
Based on their documentation, I sohuld be able to use process.env.API_URL but it's undefined.
Am I missing something?
Putting those values in eas.json is only ensuring that those envs will be set during the build process on EAS. To pass them to the application code you need to pass those values to the extra field in app.config.js.
process.env.API_URL will be defined when evaluating app.config.js, but in your application code, you need to access those values via expo-constants package.

How to use argument on package.json script from package.json attribute

Imagine I have the following package.json structure:
{
"version": "2.0.1",
"scripts": {
"testing": "build --version 2.0.1"
}
}
I know you could replace the actual version with environment variables but is it possible with a package.json attribute? For example:
{
"version": "2.0.1",
"scripts": {
"testing": "build --version ${package.version}"
}
}

Package.json, add local directory to node-modules

I have local library for some graphs and I need add it to node_modules. Is there any way how to add this library using package.json?
Our package.json looks like:
{
"name": "name",
"version": "1.01.01",
"scripts": {
...
},
"dependencies": {
...
},
...
}
I mean to add something like:
"directory": {
"my-library": "./src/path/to/my/lib"
}
Thank for any help.
According to the documentation you can define your local directories as dependencies in the following format:
{
"name": "baz",
"dependencies": {
"bar": "file:../foo/bar"
}
}
You can read more here: https://docs.npmjs.com/files/package.json#local-paths

npm run script causes Windows Script Host error

I a trying to use npm to minify javascript.
This is my package.json:
{
"name": "name1",
"version": "1.0.0",
"description": "",
"scripts": {
"minifyjs": "minifyJs",
"minifycss": "minifyCss",
"minifyhtml": "minifyHtml"
},
"author": "",
"license": "ISC",
"devDependencies": {
"clean-css": "^3.4.19",
"html-minifier": "^3.0.2",
"uglify-js": "^2.7.0"
}
}
and my minifyJs script is :
var uglifyJS = require('uglify-js');
var fs = require('fs');
var result = uglifyJS.minify(['src/main1.js', 'src/main2.js'], {
compress: {
drop_console: true,
unused: true
}
});
fs.writeFileSync('dist/minifyJs.js', result.code);
When I call npm run minifyjs I get the following error:
What am I doing wrong - btw this was working on another machine.....
Can anyone help?
The entries under scripts are commands that are run by NPM. They are not simply paths to JavaScript files.
You need to tell NPM to run your JavaScript tasks using node:
...
"scripts": {
"minifyjs": "node minifyJs",
"minifycss": "node minifyCss",
"minifyhtml": "node minifyHtml"
},
...