a turborepo pipeline task that depends on a root package.json task that does not execute in each package - turborepo

I have a root package.json task that does not execute in every package that calls yarn tsc.
Currently, I have it as a prebuild script in the root package.json:
"prebuild": "yarn tsc",
Is there anyway to specify this as a dependsOn element of build in the turborepo.json?
If I add tsc like below then it will get executed in the each package which is not what I want.
"pipeline": {
"tsc": {
"dependsOn": ["generate"],
"outputs": ["dist-types/**"]
},
"build": {
"dependsOn": ["tsc", "^build"],
"outputs": ["dist/**"]
},

Based on the documentation, your individual projects within the mono-repo need to implement a corresponding script (e.g. if you have tsc as a pipeline in turbo.json, you will need a tsc script in your package.json in your individual projects). Any project without a script matching the pipeline name will gracefully be skipped when the pipeline is run.
In your case, you would move your tsc script from the root level package.json into each project in which you want the pipeline to run against.

Related

How Can I bundle a simple node.js application

I am working with hyperledger-fabric on amazon managed blockchain. There I have written the chaincode with node.js. The problem is, the dependencies I'm using is not supported in amazon managed blockchain's peer. That's why I need to bundle my chaincode with the node modules. How can I do tha?
Here are steps for bundling Node.js chaincode with external dependencies on Amazon Managed Blockchain Hyperledger Fabric 2.2 networks:
Why bundling is needed:
Due to stringent security requirements, peer nodes in Amazon Managed Blockchain do not have access to the open internet. This means that peer nodes cannot download external dependencies at runtime when building/executing chaincode. If you suspect missing node_modules/ are responsible for errors in your chaincode, you can verify this by viewing Chaincode logs in Amazon CloudWatch, where reference to missing node_modules / dependencies will be clearly evident.
How to bundle dependencies
First, navigate to the root directory of the chaincode you wish to deploy. Your package.json file should be present in this directory. From this directory, run npm i to install node_modules. Then, move those node_modules to a new directory -- Example:
mv node_modules/ lib
Moving the dependencies to lib/ will allow you to package the installed NPM packages (dependencies) in the chaincode tar.gz file in the following steps. Because the node_modules are stored in lib/, the Node.js start script in package.json has been modified slightly to tell the container environment that runs the chaincode where to find the dependencies at runtime: "start": "NODE_PATH=lib node <entrypoint filename>.js"
{
"name": "chaincode",
"version": "1.0.0",
"scripts": {
"test": "NODE_PATH=lib mocha *_test.js",
"start": "NODE_PATH=lib node products.js"
},
"dependencies": {
"fabric-shim": "^2.0.0"
},
"devDependencies": {
"#theledger/fabric-mock-stub": "^2.0.3",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-datetime": "^1.6.0",
"moment": "^2.25.3"
}
}
With the node_modules bundled in lib/ and the start script for the chaincode modified to point to those node_modules, one can now package, install, approve and commit this chaincode as normal using the Chaincode Lifecycle commands.

Firebase Functions local "file:" dependencies

I'm using a react-crud-shared as dependency for react-crud-backend which uses Firebase Cloud Functions.
At react-crud-backend I have the following:
{
"name": "react-crud-backend",
"description": "Cloud Functions for Firebase",
"scripts": {
...
},
"dependencies": {
...
"react-crud-shared": "file:../shared",
...
},
"engines": {
"node": "8"
},
"private": true,
"devDependencies": {
...
}
}
At react-crud-shared I have the following:
{
"name": "react-crud-shared",
"version": "0.0.1",
"description": "",
"main": "src/index.js",
"private": true,
"dependencies": {
"lodash": "^4.17.11"
}
}
It works fine on development: "firebase serve --only functions", but an error is thrown on deployment:
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'react-crud-shared'
Is there a way to make it work without having to publish the private repository to NPM?
Thanks
EDIT: I found a solution for this that I like much better. I commented on this github issue here: https://github.com/firebase/firebase-tools/issues/968#issuecomment-460323113 . Basically, I have a preinstall script the runs npm pack to copy over the package under the functions directory before I use firebase deploy.
FWIW I have the exact same problem. Not exactly sure how I'm going to solve it, but this information from the doc was helpful (https://firebase.google.com/docs/functions/handle-dependencies):
To specify a dependency for your function, add it to your package.json file. If you are deploying through the gcloud command-line tool, you can also pre-install dependencies and deploy them alongside your function. By default, the node_modules folder is added to your .gcloudignore file and is not uploaded as part of your deployment. To deploy pre-installed dependencies, remove node_modules/ from the .gcloudignore file before deploying your function.
Note: Deploying pre-installed dependencies works with gcloud only; the Firebase CLI ignores the local node_modules folder.
Thus, it appears you could first run "npm install" locally, and then use gcloud for deployment, as it would copy up your node_modules directory, which would have your peer dependency in it.
Really kind of stinks, though, that I would have to switch to gcloud from firebase CLI for deployment. Ugh.
node_modules are (ordinary) being ignored for the deployment;
one can still deploy private modules with a directory structure like that:
functions/
index.js
package.json
react-crud-shared/
package.json
and a package.json alike that:
{
"dependencies": {
...
"react-crud-shared": "file:./react-crud-shared"
}
}
another method would be to blank the ignores:
{
"functions": {
"ignore": []
}
}
just think the first one is better, because this would push the whole local node_modules directory.
beside these workaround methods ...
one can install internally published modules from Cloud Source Repositories, via git+https://.
If the goal is to only share module between web and function, you may simple put the shared package under functions as file:react-crud-shared and then reference the package from web using file:../functions/react-crud-shared.
functions/
package.json
...
react-crud-shared/
package.json
...
web/
package.json
...
in functions/package.json
{
"dependencies": {
...
"react-crud-shared": "file:react-crud-shared"
}
}
in web/package.json
{
"dependencies": {
...
"react-crud-shared": "file:../functions/react-crud-shared"
}
}
It works perfectly fine for my case since I use shared protobufjs for cleaner typescript.
What I have found is that the location of your private package has to be inside your cloud functions folder (default to be functions)
So if you move your private package inside your cloud function folder and set the path of that package correctly in package.json, it should work.

.babelrc breaking semantic-ui and next app

I am not sure what went on, but whenever I wanted to add unit testing to my app, I had to add .babelrc file with just the following code:
{
"presets": [
"es2015",
"next/babel"
]
}
Prior to that, I did not need the file and it was just an nextjs app with semantic. So far, so good. Until I decided to rebuild my semantic-ui theme which turned out to be a massive mistake!
This was what I ran: cd semantic && gulp build
This caused my app to stop working whenever .babelrc is present.
These are my package.json scripts:
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"semantic": "cd semantic && gulp build",
"test": "mocha --require babel-core/register --watch-extensions js **/*.test.js"
},
If I attempt to run the next related scripts, I get the following error:
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/theJuls/Workspace/cbt/client/node_modules/babel-preset-es2015/lib/index.js
If I try to run my unit tests, I get
Error: Plugin 0 specified in "/Users/theJuls/Workspace/cbt/client/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/Users/theJuls/Workspace/cbt/client/node_modules/next/babel.js")
If I remove .babelrc, all the next scripts run normally, however I completely lost my unit tests. Why is this happening? What can I do to fix this?
I am not sure if this is relevant but here is my current file structure:
api/
components/
config/
lib/
pages/
semantic/
store/
.babelrc
package-lock.json
package.json
semantic.json
I am not sure why it suddenly broke, but I have figured out a way around it which is also the more up to date way to do it, as my previous one was deprecated.
First off I had to install the following modules: #babel/core and #babel/register
Changed the .babelrc file to as follows:
{
"presets": [
"#babel/preset-env",
"next/babel"
]
}
Finally, in package.json just slightly change the test command to:
"test": "mocha --require #babel/register --watch-extensions js **/*.test.js"
Since we are now using #babel/register
This made everything come back to normal.

Grunt Task "default" not found

I'm new to use grunt, I just create a real sample to run. But I get blocked my A warning Warning: Task "default" not found
I just copied sample from http://gruntjs.com/getting-started
My package is
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0"
}
}
my Gruntfile.js is
module.exports = function(grunt) {
grunt.registerTask('default', 'Log some stuff.', function() {
grunt.log.write('Logging some stuff...').ok();
});
};
it just print some simple log, why it doesn't work?
Copying the pasting the code from the grunt page won't do anything by itself. Did you first install grunt by console: npm install -g grunt-cli ?
Grunt is a task runner; that is, it does not have the ability to do the task itself, but starts the program listed in the gruntfile, runs the program on the noted files or folders, and stops each task before going on to the next.
You'll need to make sure that the JSHint program has been installed on your system before running grunt, or grunt won't run that task. You'll enter this in your console to install it: npm install grunt-contrib-jshint --save-dev
Grunt doesn't know what files to run JSHint on, so you'll need to tell it where to look. To do that, you'll need to carefully read the grunt-contrib-jshint page in the npm plugins site at http://gruntjs.com/plugins.
In addition, JSHint has these options: http://jshint.com/docs/options/ You'll need to learn the correct syntax to put them in the gruntfile.
Grant makes repetitive tasks simpler, but you'll still need to do a bit of homework to put all the different pieces together to get it working for you.
I wrote a complete article on getting started in grunt, based on my own learning: https://iphonedevlog.wordpress.com/2016/10/31/how-to-use-grunt-to-automate-repetitive-tasks/

ASP .NET 5 - grunt task to copy files from node modules to wwwroot

I have a simple ASP .NET 5 empty project - with npm and grunt installed.
I've used npm to install a few client-side libraries, at present located in the node_modules directory directly under my ASP .NET project.
I want to copy the relevant files (for example, jquery.min.js) from the node_modules folder into the wwwroot folder.
It's unclear to me how to use grunt to do this - as each node module has it's own dependency tree, and there doesn't seem to be any consistency in the file structure from package to package.
I could write a grunt task explicitly for each client side library I use, but in that case I may as well download everything manually and place the files where I need them manually, avoiding npm all together.
I know I could use bower, which has a flat dependency tree - which is probably the root I should go down - but I've read a few articles saying "there's no need for bower - npm can do it all" and therefore I would like to know if there's a way to do this purely with npm.
Is there a way? Or is the "npm can do it all" statement aimed at projects that will require the components directly from the node_modules?
TL DR; Is bower a better fit than npm for ASP .NET 5 projects with separation of source and build files, and if not, what's the recommended way of doing it purely with npm?
I don't fill me professional in grunt, but I use it myself and I think that I can explain you how one can use it corresponds to your requirements.
First of all you should add "New Item" to your project, choose "Client-Side" and "NPM Configuration file" to add package.json to the the project (in the same directory where you have project.json). I suppose you have already created the file, but the existence of the file is important for grunt too. Then you adds some dependencies, which you need on the client-side to "dependencies" part of package.json and add at least grunt and grunt-contrib-copy to "devDependencies" part. An example of the file you will see below
{
"version": "1.0.0",
"name": "ASP.NET",
"private": true,
"dependencies": {
"font-awesome": "^4.5.0",
"jquery": "^1.11.3"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-copy": "^0.8.2"
}
}
Now you should add "Grunt Configuration File" in the same way like you added "NPM Configuration file". You will create gruntfile.js (in the same directory where you have project.json). Finally you should fill gruntfile.js with more helpful code. For example the code
module.exports = function(grunt) {
grunt.initConfig({
clean: ["wwwroot/font-awesome/", "wwwroot/jquery*.*"],
copy: {
main: {
files: [
{
src: "node_modules/font-awesome/css/*",
dest: "wwwroot/font-awesome/css/",
expand: true,
filter: "isFile",
flatten: true
},
{
src: "node_modules/font-awesome/fonts/*",
dest: "wwwroot/font-awesome/fonts/",
expand: true,
filter: "isFile",
flatten: true
},
{
src: "node_modules/jquery/dist/*",
dest: "wwwroot/",
expand: true,
filter: "isFile",
flatten: true
}
]
}
}
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.registerTask("all", ["clean", "copy"]);
grunt.registerTask("default", "all");
};
registers two tasks: clean and copy and the aliases all and default. You can select gruntfile.js file in the solution explorer, open context menu and choose "Task Runner Explorer". You will see all defined tasks. The task with the name "default" will be executed if you execute grunt without parameters (without the task name) in the command line.
Now you can choose some task and run it. You can choose some task, click right mouse button to open context menu and check "After Build" in "Bindings":
Now the task will be executed every time when you build the project. You can click optionally "V" button on the left side to see verbose information from the executed tasks.
I hope it's already the main information which you need. Many other helpful information about plugins grunt-contrib-clean, grunt-contrib-copy, grunt-contrib-jshint, grunt-jscs, grunt-newer and many other you will find yourself. One official place of ASP.NET 5 documentation should be mentioned. It's the place.
P.S. You asked additionally about the usage of bower. I find both npm and bower not perfect, but still very practical. I would prefer to hold full control over the dependencies and especially about the data, which will be copied under wwwroot. Thus I change the content of .bowerrc file from { "directory": "wwwroot/lib" } to { "directory": "bower_components" } and I use grunt to copy the required data from bower_components in the same way like I do this with files from node_modules. See the article for more details. In other words I use packages published only in bower repository in the same way like I use npm packages.

Resources