Unix pipe in NX project.json - nrwl-nx

Is it possible to pipe the output of an executor to a CLI command.
In package.json I would do this:
"dev": "node index.js | pino-pretty"
I cannot figure out how to apply this to the project.json
"dev": {
"executor": "#nrwl/node:node",
"options": {
"buildTarget": "api:build"
}
}

I managed to get it to work by creating a custom task:
"pretty": {
"command":"npx nx serve | pino-pretty"
},
"serve" ...
So now I use npx nx pretty myproject and that runs nx serve and pipes it to pino-pretty

Related

CI Using Azure Pipelines and Nx fails

UPDATE: I was able to get this working by setting "ProduceReferenceAssembly" to false in the .csproj files of the libs. Not sure if this is optimal or intended but that is what worked for me. See: Ref folder within .NET 5.0 bin folder
I'm trying to set up a proof of concept using NX dot net and Azure using this exaple .yml: https://nx.dev/recipes/ci/monorepo-ci-azure
I have 3 services (libs) and 3 apis (apps) ... I made a change to one of the apis to test caching and incremental builds.
The unchanged projects all say [remote cache] but then the build fails because it's looking for the .dlls in the /obj/Debug/ directory. Why use that when there are .dlls in the /dist directory?
How can I fix this? Is there something in the nx.json or project.json files I need to change?
(https://i.stack.imgur.com/IQhaO.png)
I tried using the same command locally on my machine and it completes as expected. I expect the build to complete. The build fails when remote caching is used.
{
"name": "ShipmentService",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "libs/ShipmentService",
"targets": {
"build": {
"executor": "#nx-dotnet/core:build",
"outputs": [
"{workspaceRoot}/dist/libs/ShipmentService",
"{workspaceRoot}/libs/ShipmentService/obj"
],
"options": {
"configuration": "Debug",
"noDependencies": true
},
"configurations": {
"production": {
"configuration": "Release"
}
}
},
"lint": {
"executor": "#nx-dotnet/core:format"
}
},
"tags": []
}
Tried proposed workaround, here's what I'm noticing: platformservice:build [remote cache]
Error, it sees the intermediates part, but basically same issue: same error
Updated project.json (all of them have been updated to look similar to this [tried with and without /obj portion]):
"outputs": [
"{workspaceRoot}/dist/libs/ShipmentService",
"{workspaceRoot}/dist/intermediates/libs/ShipmentService/obj"
],
This is a bug on nx-dotnet's side, and we aren't quite capturing all of the outputs that are needed for the cache. If you add the path to the obj directory into the outputs array of the build target in project.json it should work. Here's the workaround which will eventually be migrated:
I've got a branch with this working, you do indeed need the obj directory as part of the cache. There are some weird intricacies with this though. I'll work on a migration + patch. In the meantime, the workaround that I used is:
Update Directory.Build.props adding these to the property group containing the output path manipulation:
<BaseIntermediateOutputPath>$(RepoRoot)dist/intermediates/$(ProjectRelativePath)/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
As an example, the full file looks like this on the nx-dotnet repo now:
<Project>
<PropertyGroup>
<!-- Output path configuration -->
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</RepoRoot>
<ProjectRelativePath>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</ProjectRelativePath>
<BaseOutputPath>$(RepoRoot)dist/$(ProjectRelativePath)</BaseOutputPath>
<OutputPath>$(BaseOutputPath)</OutputPath>
<BaseIntermediateOutputPath>$(RepoRoot)dist/intermediates/$(ProjectRelativePath)/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup>
<RestorePackagesWithLockFile>false</RestorePackagesWithLockFile>
</PropertyGroup>
</Project>
Your project.json file should look something like this now:
{
"name": "demo-webapi",
"sourceRoot": "demo/apps/webapi",
"targets": {
"build": {
"executor": "#nx-dotnet/core:build",
"outputs": [
"{workspaceRoot}/dist/demo/apps/webapi",
"{workspaceRoot}/dist/intermediates/demo/apps/webapi"
],
"options": {
"configuration": "Debug",
"noDependencies": true
},
"configurations": {
"production": {
"configuration": "Release"
}
}
}
}
}

api.targets is not a function in plugin-proposal-object-rest-spread

I have this error when I try to compile my app. The error comes from babel-plugin-proposal-object-rest-spread here https://github.com/babel/babel/blob/6e551ae8827d064680c1344074db9fb3093967e9/packages/babel-plugin-proposal-object-rest-spread/src/index.js#L22 :
Trace: error TypeError: api.targets is not a function
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/preset-env/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js:38:25
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/preset-env/node_modules/#babel/helper-plugin-utils/lib/index.js:19:12
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:166:14
| at cachedFunction (/home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/caching.js:32:19)
| at loadPluginDescriptor (/home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:201:28)
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:71:20
My babel.config.json is like this:
{
"plugins": [
"emotion",
"macros",
"#babel/plugin-proposal-class-properties"
],
"presets": ["next/babel"],
"env": {
"test": {
"plugins": ["require-context-hook"]
}
}
}
Does anyone has an idea? Thank you
The problem was solved when I removed the node_modules folder and then ran yarn install
Run "npm install" once, It will fix the issue.

How to correctly bundle a vscode extension using webpack

The problem that i am having is that when i run vsce package i still get the This extension consists of 3587 separate files. For performance reasons, you should bundle your extension: warning, i followed the Bundling Extension steps, debugging works as expected.
package.json
{
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"compile": "npm run webpack",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
}
The webpack config is an exact copy of the Bundling Extension example.
This sounds like you might've forgotten to add the source directories to .vscodeignore, so they're still being packaged into the release. The ignore file should probably contain at least the following, plus anything else not needed at runtime:
src/**
node_modules/**
If you are working with a Language Server extension which has both client and server folders, If you exclude the node_modules of the client and server from the bundle the extension would fail when installed and launch for the first time
.vscodeignore contains
.vscode
**/*.ts
**/*.map
out/**
node_modules/**
test_files/**
client/src/**
server/src/**
tsconfig.json
webpack.config.js
.gitignore
Also the documentation is a bit obsolete regarding the webpack.config.js, you have to wrap the 'use strict' into a function with all the settings.
The entry setting was changed according to my needs
//#ts-check
(function () {
'use strict';
const path = require('path');
/**#type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
entry: './client/src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
clean: true, //clean the dist folder for each time webpack is run
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
}
};
module.exports = config;
}());

how to pass multiple args to vscode task command?

in tasks.json I am using the "args" property to specify the arguments to pass to "command":"gulp". But when I run the task in vscode, only the first argument is being passed to gulp.
I want to run a gulp task against a single file. In gulpfile.js I am using the process.argv array to retrieve the command line arguments. So, on the command line I enter "gulp copy3 --file abc.js" and the copy3 task is run. The code then reads the argv array to get the name of the file being copied.
this code works from the command line. But does not work when I run it as a task in vscode. How to do that?
the gulpfile.js code:
gulp.task('copy3', function( )
{
console.log(process.argv) ;
let pattern = '*.js' ;
// single file to copy
if (( process.argv.length >= 5 ) && ( process.argv[3] == '--file' ))
{
let fileName = process.argv[4] ;
pattern = fileName ;
}
console.log('pattern:' + pattern ) ;
return gulp.src(pattern).pipe(gulp.dest('dev'));
}) ;
the tasks.json file
{
"version": "2.0.0",
"tasks": [
{
"taskName": "copy3",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
]
}
Here is the terminal output:
[10:52:57] Using gulpfile C:\vscTest\rpgproj\gulpfile.js
[10:52:57] Starting 'copy3'...
[ 'C:\\Program Files\\nodejs\\node.exe',
'C:\\vscTest\\rpgproj\\node_modules\\gulp\\bin\\gulp.js',
'copy3' ]
pattern:*.js
[10:52:57] Finished 'copy3' after 16 ms
thanks,
I made a couple of small changes, try:
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
and your entire code works perfectly. Make sure to reload vscode after modifying the tasks.json.
VSCode appears to have a built-in gulp extension. This seems to scan your gulpfile for tasks and list them for you. It also seems to ignore the args option.
The workaround is to use the full path to gulp as the command e.g. ./node_modules/.bin/gulp to bypass it.

Configure Sublime Text build system for Scala?

I'm trying to configure a build system for Scala with SublimeText, but I am having some difficulty. I have tried both of the following:
{
"shell_cmd": "scala",
"working_dir": "${project_path:${folder}}",
"selector": "source.scala"
}
{
"cmd": ["/path/to/bin/scala", "$file_name"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala",
"shell": true
}
Both of these attempts produce the same failed output - it seems to start up the interactive Scala shell rather than running my script. Any advice?
The answer that worked turned out to be very close to the second answer - apparently I'm not supposed to open up a new shell. If someone can clarify when to set "shell": true in the comments, that would be really helpful.
{
"cmd": ["/path/to/bin/scala", "$file_name"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala"
}
{
"cmd": ["C:/Program Files (x86)/scala/bin/scala.bat", "$file_name"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala"
}
This worked for me.
replace C:/ with your own path.
In Packages/Scala/Scala.sublime-build, add this:
{
"cmd": ["[PATH TO SCALA]", "$file"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala"
}
Replace the [PATH TO SCALA] with the path of where scala interpreter is located in your system. Do a "which scala" to find out.
This works for me:
{
"cmd": ["scala", "$file"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala",
"shell": true
}
given you set the system PATH thing:
Variable: %PATH%
Value: C:\Program Files (x86)\scala\bin
in my case I didn't install Scala or SublimeText, I just used the zip. But this code worked for me to compile the .scala files from SublimeText3 on Windows.
{"cmd": ["C:/Scala/scala-2.13.3/bin/scalac.bat", "$file"],
"working_dir": "$file_path",
"selector": "source.scala",
"encoding":"utf-8",
"file_patterns": "*.scala",
"shell": true}
You can create it or download it and put it in the directory Sublime Text Build 3 ###\Data\Packages\User
Build System For Scala :
OSX - (Mac)
Use the below:
{
"cmd": ["/opt/homebrew/bin/scala", "$file_name"],
"working_dir": "${project_path:${folder}}",
"selector": "source.scala"
}
Path to delete the build:
/Library/Application Support/Sublime Text/Packages/User