How do I use Yarn's `.pnp.js` file? - yarnpkg

Using Yarn 2, the default installation method creates a .pnp.js file (Plug'n'Play) instead of a node_modules directory.
How do I use this file to run my Node application?

To run a Node application with Yarn's Plug'n'Play you must preload the .pnp.js file using the --require flag.
node --require ./.pnp.js foo.js
Note: Make sure that the --require path starts with ./ or ../.

Related

Run yarn/npm scripts from a subfolder's package.json

I maintain a monorepo for the react-querybuilder package. I'm merging in the documentation website code under the /website directory, but not as a workspace (those are in /packages/*).
The /website directory has its own package.json with the docusaurus * scripts (start/build/deploy/etc.). I'd like to have scripts in the root /package.json that execute the scripts in /website/package.json. Currently I have something like this in /package.json:
{
"scripts": {
"website:install": "cd website && yarn",
"website:start": "cd website && yarn start",
"website:build": "cd website && yarn build",
"website:deploy": "cd website && yarn deploy"
}
}
Is there a better, more generic way to do that? This way I have to name every script twice, once in /package.json and once in /website/package.json.
(I tried --cwd, but that doesn't actually run scripts defined in that other directory's package.json. It runs the scripts defined in the root package.json from the other directory. E.g., yarn --cwd website build is effectively the same as yarn build, at least in my case.)
I thought there might be a yarn flag like --cwd (--pkg? --config?) that actually runs the scripts defined in the other directory, or maybe you'd have to specify a file.
Am I missing something?

Setting a laravel storage directory permission by ebextentions

I'm working on elastic beanstalk exextentions. A storage-permission-denied error occurs every deployments and I a have to type command to resolve that. Does the code below(.extensions/chmod.config), prevent the error occur ?
container_commands:
01addpermission:
command: "chmod -R 755 /var/app/current/storage"
01clearcache:
command: "php /var/app/current config:cache"
The code sadly will not work. The reason is that container commands run when your app is in the staging folder, not in current folder:
The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server.
You can try to use relative paths:
container_commands:
01addpermission:
command: "chmod -R 755 ./storage"
02clearcache:
command: "php . config:cache"
The alternative is to use postdeploy platform hook which runs commands after you app is deployed:
Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server

docker build hangs in directory with many files

Windows 10. I have in folder just:
app (directory with many files)
Dockerfile (simpliest docker file)
I run "docker build ." and it just hangs.
If I remove "app" directory. Build runs ok.
In docker file just one line:
FROM node
Didn't find any issues like that. It fills like it tries to scan the directory or something.
Any advice?
UPD: It seems that I should use .dockerignore https://docs.docker.com/engine/reference/builder/#/dockerignore-file
When you run docker build ... the Docker client sends the context (recursive contents of the directory) via REST to the Docker daemon for building. If that context is large, this could take some time (depending on a variety of factors, if your daemon is local / remote, platform maybe, etc...).
How long are you giving it to hang before giving up? Could be that it's still just working? Or could be that the context was so large maybe the client / daemon experienced an issue. Checking the (client / daemon) logs would help debug that.
And yes, a .dockerignore file (basically a .gitignore but for Docker context) is probably what you're looking for, unless you need the contents of the app directory during your build.
Your Dockerfile should be put in the directory that only includes it's build context. For example, if you are building a spring-boot app, you can put the Dockerfile right under /app, as shown in this official docker sample.
Docker's documentation:
In most cases, it’s best to start with an empty directory as context and keep your Dockerfile in that directory. Add only the files needed for building the Dockerfile.
Warning: Do not use your root directory, /, as the PATH as it causes the build to transfer the entire contents of your hard drive to the Docker daemon.
I've seen that simple docker examples put dockerfile in the root directory, but for complicated examples like the one I posted above, the dockerfile is put only in it's relevant directory. You can dig through the dockersamples repository and find your case.

why am I getting No such file or directory message while running a command in linux

I am testing an application by starting certain commands in sequence. During which for one of the command when I get into the directory and run it it works where as when I run directly it gives No such file or directory
cd /opt/abc/ then running gulp serve will work
Where as when I run directly - /opt/abc/gulp serve it fails
Attached is the snapshot of the same.
enter image description here
You are thinking that PWD is in your PATH, which as root it should not be (I personally don't think it should be for any user, but definitely not the super user).
So, when you type in "gulp serve" it's checking your path and finding "gulp". If you type which gulp you can see where it finds it. When you type the path to gulp, it is not finding an executable there. So-- that's not the one you want, and if there is a file called gulp there it is not executable.

gulp command in heroku procfile

I have a node.js/express app, I would like to run the command gulp build to generate my static assets when deploying with heroku, just before my node command lcm server, as I keep my public folder in my .gitignore file.
I'm having trouble finding how I can run this command during my heroku deployment.
So far my Procfile is:
web: lcm server
This doesn't seem to work -
gulp build
web: lcm server
Make a Procfile
Begin by making a blank file named Procfile and placing it within the root of your project. Procfile is short for “Process File” and used to explicitly declare what command should be executed to start your app. By default, a Procfile is not required, but it’s good form for Node-based projects to create one.
If a Procfile isn’t defined, then one will be created automatically using npm start as the web process type.
Possible solution
Try this one:
web: node node_modules/gulp/bin/gulp build
The line above lets us use the locally installed version of Gulp provided by Node’s Package Manager (NPM) instead of having to use a globally installed version.
Helpful resources
from https://www.sitepoint.com/deploying-heroku-using-gulp-node-git/

Resources