Package.json, add local directory to node-modules - npm

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

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}"
}
}

db-migrate with #babel/register and ES6 modules - "SyntaxError: Unexpected token export" error

Really hoping someone can help me with this as it's driving me crazy.
Node v12.4.0
package.json: -
{
"name": "#mypackage/db-migrate",
"private": true,
"version": "1.0.0",
"main": "index.js",
"license": "ISC",
"workspaces": {
"packages": [
"common/models"
]
},
"dependencies": {
"#babel/core": "^7.6.0",
"#babel/preset-env": "^7.6.0",
"#babel/register": "^7.6.0",
"#mypackage/models": "1.0.0",
"db-migrate-mysql": "^1.1.10",
"db-migrate-plugin-babel": "^2.0.1",
"npm-upgrade": "^2.0.2"
}
}
.babelrc: -
{
"presets": [
"#babel/preset-env"
]
}
Directory structure: -
common->models - this contains the source lib for #mypackage/models
migrations - contains all the migration files
Yarn installs all the dependencies without issue.
So when I run a migration command ("db-migrate down -c 1", for example), I get the following: -
export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };
^^^^^^
SyntaxError: Unexpected token export
This is happening when I am trying to export/import from one of the #mypackage/models files.
var CONSTANT_ONE = "foo_one";
var CONSTANT_TWO = "foo_two";
var CONSTANT_THREE = "foo_three";
export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };
Is this a root directory issue? I am complete baffled and utterly frustrated. Any help VERY welcome.
Solved by changing .babelrc to babel.config.js.

Is it possible to specify browserify config in package.json (other than transform)?

In package.json we can specify browserify transforms like this:
"browserify": {
"transform": ["babelify"]
}
Is it possible to set other config like debug, detectGlobals, input source file, output file, etc. For example, something like:
"browserify": {
"debug": true,
"detectGlobals": false,
"transform": ["babelify"]
}
Thanks
In case you haven't found an answer to this yet:
Yes, it is and quite simple. You were very close. here's the example from the browserify README.md
{
"browserify": {
"transform": [["babelify", { "presets": ["es2015"] }]]
}
}
read more here.