How to skip go, python, and ruby on netlify build? - netlify

I just use node and npm, I don't need go, python or ruby on netlify build. Can i skip it at netlify build?
I've tried to put it into netlify.toml using variable, like below code :
[build]
command = "pnpm build || ( npm install pnpm && pnpm build )"
publish = "build"
[build.environment ]
NODE_VERSION = "16.14.0"
GO_VERSION = false
RUBY_VERSION = false
PYTHON_VERSION = false
But it will give me error like this
: json: cannot unmarshal bool into Go struct field BuildConfig.Config.build.environment of type string

Related

How to modify this flake.nix so that I don't have to load the nix package every time I load the environment

I've taken this post as example for my question :https://johns.codes/blog/building-typescript-node-apps-with-nix
I try to make development environment with a npm package that has not a nix equivalent.
I think that I'm very near from the end but I probably miss something important and it doesn't work.
in the folder node-gyp-build:
npm init -y
npm install node-gyp-build
mkdir nix
rm -fr node_module
node2nix -16 --development --input package.json --lock package-lock.json --node-env ./nix/node-env.nix --composition ./nix/default.nix --output ./nix/node-package.nix
nix-build nix/default.nix
Now my question is how to use the inout in in a flake.nix in order to have developement environment with this package
I've tried with that flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
npm_pack = import (./nix/default.nix);
in with pkgs;{
devShell = mkShell { buildInputs = [ npm_pack];};
]; };
});
}
and this command:
nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --ignore-environment
error: Dependency is not of a valid type: element 1 of buildInputs for nix-shell
The npm_pack var in your example has the following attributes (many omitted)
package - The nix output of the package you are building (which can be added as a buildInput in your dev shell if its some executable)
shell - a devShell which gives you the npm deps to run the package you are trying to build, this would be equilvant to you cloning the package and runing npm install
so if you just want to use the package for another project your flake would look like
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
npm_pack = import ./nix { inherit pkgs system;};
in with pkgs;{
devShell = mkShell { buildInputs = [ npm_pack.package ];};
});
If you want to just make it so you auto have npm deps "installed" you can use the shell, so the flake would look like
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
npm_pack = import ./nix { inherit pkgs system;};
in with pkgs;{
devShell = npm_pack.shell
});

unable to install #angular/material 8

I am using command ng add #angular/material
Unable to fetch package metadata: Cannot read property 'startsWith' of null is the error I am getting npm config list [-l] [--json];
cli configs metrics-registry = "https://artifacthub-tip.oraclecorp.com/api/npm/npmjs-remote" scope = "" user-agent = "npm/6.12.0 node/v12.13.0 win32 x64";
userconfig C:\Users\goparao\.npmrc
http_proxy = "http://registry.npmjs.org/"
key = "value"
registry = "https://artifacthub-tip.oraclecorp.com/api/npm/npmjs-remote"
strict-ssl = true;
builtin config undefined prefix = "C:\\Users\\goparao\\AppData\\Roaming\\npm"; node bin location = C:\Program Files\nodejs\node.exe ;
cwd = D:\angular_practice\hello-world ;
HOME = C:\Users\goparao ;
"npm config ls -l" to show all defaults.
PS D:\angular_practice\hello-world>
If you still have issues to install Angular Material, you can first install it with the command : npm i #angular/material then run the command ng add #angular\material. (Worked with Angular 10)

Yarn install production dependencies of a single package in workspace

I'm trying to install the production dependencies only for a single package in my workspace. Is that possible?
I've already tried this:
yarn workspace my-package-in-workspace install -- --prod
But it is installing all production dependencies of all my packages.
yarn 1 doesn't support it as far as I know.
If you are trying to install a specific package in a dockerfile, then there is a workaround:
copy the yarn.lock file and the root package.json
copy only the packages's package.json that you need: your package and which other packages that your package depends on (locally in the monorepo).
in the dockerfile, manually remove all the devDependnecies of all the package.json(s) that you copied.
run yarn install on the root package.json.
Note:
Deterministic installation - It is recommended to do so in monorepos to force deterministic install - https://stackoverflow.com/a/64503207/806963
Full dockefile example:
FROM node:12
WORKDIR /usr/project
COPY yarn.lock package.json remove-all-dev-deps-from-all-package-jsons.js change-version.js ./
ARG package_path=packages/dancer-placing-manager
COPY ${package_path}/package.json ./${package_path}/package.json
RUN node remove-all-dev-deps-from-all-package-jsons.js && rm remove-all-dev-deps-from-all-package-jsons.js
RUN yarn install --frozen-lockfile --production
COPY ${package_path}/dist/src ./${package_path}/dist/src
COPY ${package_path}/src ./${package_path}/src
CMD node --unhandled-rejections=strict ./packages/dancer-placing-manager/dist/src/index.js
remove-all-dev-deps-from-all-package-jsons.js:
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
async function deleteDevDeps(packageJsonPath) {
const packageJson = require(packageJsonPath)
delete packageJson.devDependencies
await new Promise((res, rej) =>
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8', error => (error ? rej(error) : res())),
)
}
function getSubPackagesPaths(repoPath) {
const result = execSync(`yarn workspaces --json info`).toString()
const workspacesInfo = JSON.parse(JSON.parse(result).data)
return Object.values(workspacesInfo)
.map(workspaceInfo => workspaceInfo.location)
.map(packagePath => path.join(repoPath, packagePath, 'package.json'))
}
async function main() {
const repoPath = __dirname
const packageJsonPath = path.join(repoPath, 'package.json')
await deleteDevDeps(packageJsonPath)
await Promise.all(getSubPackagesPaths(repoPath).map(packageJsonPath => deleteDevDeps(packageJsonPath)))
}
if (require.main === module) {
main()
}
It looks like this is easily possible now with Yarn 2: https://yarnpkg.com/cli/workspaces/focus
But I haven't tried myself.
Here is my solution for Yarn 1:
# Install dependencies for the whole monorepo because
# 1. The --ignore-workspaces flag is not implemented https://github.com/yarnpkg/yarn/issues/4099
# 2. The --focus flag is broken https://github.com/yarnpkg/yarn/issues/6715
# Avoid the target workspace dependencies to land in the root node_modules.
sed -i 's|"dependencies":|"workspaces": { "nohoist": ["**"] }, "dependencies":|g' apps/target-app/package.json
# Run `yarn install` twice to workaround https://github.com/yarnpkg/yarn/issues/6988
yarn || yarn
# Find all linked node_modules and dereference them so that there are no broken
# symlinks if the target-app is copied somewhere. (Don't use
# `cp -rL apps/target-app some/destination` because then it also dereferences
# node_modules/.bin/* and thus breaks them.)
cd apps/target-app/node_modules
for f in $(find . -maxdepth 1 -type l)
do
l=$(readlink -f $f) && rm $f && cp -rf $l $f
done
Now apps/target-app can be copied and used as a standalone app.
I would not recommend it for production. It is slow (because it installs dependencies for the whole monorepo) and not really reliable (because there may be additional issues with symlinks).
You may try
yarn workspace #my-monorepo/my-package-in-workspace install -- --prod

Running npm install with sbt

So I have a sbt project that uses sbt-js-engine and sbt-webpack plugins.
It successfully gets and resolves npm packages just fine. And then webpack would build the project.
I have added a npm install script into package.json like so,
"scripts": {
"install": "bower install"
}
However, the problem I am currently having is that when I run webpack (which intern uses sbt-js-engine ) it runs npm update instead of npm install.
Heres an excerpt of my build.sbt,
lazy val common = project.in(file("common")).
enablePlugins(SbtWeb).
settings(
sourceDirectory in webpack := baseDirectory.value,
resourceManaged in webpack := (resourceManaged in webpack in root).value,
includeFilter in webpack := ("*.jsx" || "*.js" || "*.json") && new FileFilter {
#tailrec
override def accept(pathname: File): Boolean = {
if (pathname == null) false
else if (pathname.getName == "javascripts") true
else accept(pathname.getParentFile)
}
},
JsEngineKeys.engineType := JsEngineKeys.EngineType.Node
)
Is there anyway I could run npm install instead or even before as a depedency for webpack task ?
You could try something like this:
sourceDirectory in webpack := {
Process("/usr/local/bin/npm install", file("[path to working dir]")).!
baseDirectory.value
}
That would mean it would run at same time as setting the webpack settings.

Grunt and NPM, package all production dependencies

I am unsure when the way the NPM installs dependencies changed.
In the past I remember that if in my project.json I had a dependency on "abc", which in turn would depend on "xyz", a npm install would result in something like:
package.json
node_modules/
abc/
node_modules/
xyz/
some-dev-dep/
When packaging my node project to be used by AWS Lambda, I would have to include that node_modules structure (less any dev-dependencies that were there). I would use Grunt for my packaging, so I wrote this handy thing to help me get all production dependencies into this zip (extracting part of my gruntfile.js):
function getDependencies(pkg) {
return Object.keys(pkg.dependencies)
.map(function(val) { return val + '/**'; });
}
var config = {
compress: {
prod: {
options: {
archive: 'public/lambda.zip'
},
files: [
{ src: 'index.js', dest: '/' },
{ expand: true, cwd: 'node_modules/', src: getDependencies(pkg), dest: '/node_modules' }
]
}
}
};
This would work because dependencies of my dependencies were nested.
Recently (or maybe not-so-recently) this has changed (I am unsure when as I was using very old version of NPM and updated it recently).
Now if I depend on "abc" which in turn depends on "xyz" I will get:
node_modules/
abc/
xyz/
some-dev-dep/
As you can see, my way of getting only production dependencies just won't work.
Is there any easy way to get only list of production dependencies (together with sub-dependencies) within grunt job?
I could do it using recursive function scanning for my dependencies, and then checking project.json files of those and then searching for sub-dependencies etc. This approach seems like a lot of hassle that is possibly a common scenario for many projects...
Here is a function that returns an array of the production dependency module names. (Note: you might need to have the 'npm' module installed locally in your project for this to work.)
/**
* Returns an array of the node dependencies needed for production.
* See https://docs.npmjs.com/cli/ls for info on the 'npm ls' command.
*/
var getProdDependencies = function(callback) {
require('child_process').exec('npm ls --prod=true --parseable=true', undefined,
function(err, stdout, stderr) {
var array = stdout.split('\n');
var nodeModuleNames = [];
array.forEach(function(line) {
var index = line.indexOf('node_modules');
if (index > -1) {
nodeModuleNames.push(line.substr(index + 13));
}
});
callback(nodeModuleNames);
});
};
This change was introduced with the release of npm 3 (see npm v3 Dependency Resolution).
It's not exactly clear why you need to use Grunt at all. If what you want to do is get only production dependencies you can simply run:
npm install --production
With the --production flag, all dev dependencies will be ignored. The same is also true if the NODE_ENV environment variable is set to 'production'.

Resources