What are the differences between a #nrwl/js library and a #nrwl/workspace library? - nrwl-nx

I have created both in a testing environment but am still having trouble to differentiate between the use cases of the two. They both have the same file structure, slightly different tsconfig.json file, #nrwl/js library is stricter by 2 extra props. Otherwise they seem to be the same. On the official site there is no info regarding the differences between the two.
Any help is appreciated.

#nrwl/js:library
Use to generate a generic typescript library.
npx nx g #nrwl/js:library --name myLibrary --directory common --buildable # creates libs/common/my-library
#nrwl/workspace:library
Use to generate a UI focused typescript library.
npx nx g #nrwl/workspace:library --name myLibrary --directory common --buildable # creates libs/common/my-library
Differences
#nrwl/workspace:library has a .babelrc file that is not present in #nrwl/js:library
#nrwl/workspace:library has a jest.config.ts that supports .tsx files while #nrwl/js:library only supports .ts files
The tsconfig files are different
How I found the differences
I created a library using each generator
npx nx g #nrwl/js:library --name library --directory common/nrwljs --buildable
npx nx g #nrwl/workspace:library --name library --directory common/nrwlworkspace --buildable
Then I compared the files of each
diff -rq libs/common/nrwljs/library libs/common/nrwlworkspace/
Only in libs/common/nrwlworkspace/library: .babelrc
Files libs/common/nrwljs/library/README.md and libs/common/nrwlworkspace/library/README.md differ
Files libs/common/nrwljs/library/jest.config.ts and libs/common/nrwlworkspace/library/jest.config.ts differ
Files libs/common/nrwljs/library/package.json and libs/common/nrwlworkspace/library/package.json differ
Files libs/common/nrwljs/library/project.json and libs/common/nrwlworkspace/library/project.json differ
Files libs/common/nrwljs/library/src/index.ts and libs/common/nrwlworkspace/library/src/index.ts differ
Only in libs/common/nrwljs/library/src/lib: common-nrwljs-library.spec.ts
Only in libs/common/nrwljs/library/src/lib: common-nrwljs-library.ts
Only in libs/common/nrwlworkspace/library/src/lib: common-nrwlworkspace-library.spec.ts
Only in libs/common/nrwlworkspace/library/src/lib: common-nrwlworkspace-library.ts
Files libs/common/nrwljs/library/tsconfig.json and libs/common/nrwlworkspace/library/tsconfig.json differ
Files libs/common/nrwljs/library/tsconfig.lib.json and libs/common/nrwlworkspace/library/tsconfig.lib.json differ
Files libs/common/nrwljs/library/tsconfig.spec.json and libs/common/nrwlworkspace/library/tsconfig.spec.json differ

It's about the options you can use for each generator. Here are the documentation of the generators:
https://nx.dev/packages/workspace/generators/library
https://nx.dev/packages/angular/generators/library
Angular generator has some specific options, eg to include routing or lazy behaviours.

Related

how to ignore folders in melos packages

working in a monorepo with this structure
monorepo/
examples/
# ...
foo/
packages/
# ...
foo/
# ...
example/ -> examples/foo/
where the example in packages/foo
is a deep link to examples/foo/
that contains a demo app called foo_example
I'm encountering a problem during melos bootstrap
Run melos bootstrap
melos.yaml: Multiple packages with the name `foo_example` found in the workspace, which is unsupported.
To fix this problem, consider renaming your packages to have a unique name.
The packages that caused the problem are:
- foo_example at packages/foo/example
- foo_example at examples/foo
Error: Process completed with exit code 1.
I would like to keep the folders for examples and packages separated
while providing an example readily available for https://pub.dev/
is there a way to exclude the packages/**/example/ folders from melos?
this is how I'm pointing at the packages right now
name: <my_mono_repo>
packages:
- examples/**
- packages/**
scripts:
# ...
always read the docs :)
https://melos.invertase.dev/configuration/overview#ignore
this does the job
ignore:
# e.g. ignore example apps
- "packages/**/example"

What is the best practice for installing external dependencies in a Coq project?

I understand what I believe is the essence of the official utilties doc https://coq.inria.fr/refman/practical-tools/utilities.html#building-a-coq-project:
one creates a _CoqProject with arguments to coqc and the file names to compile (hopefully in an order that takes into account dependencies)
then one make an automatic CoqMakefile with coq_makefile -f _CoqProject -o CoqMakefile
Then you use their recommended Makefile to run the automatically generated make file.
But then if we need other dependencies, it doesn't say how to install them (or uninstall) them. What is the standard way to do that?
My guess is that one likely adds a target to your Makefile at the end of it and do some sort of opam install?
e.g.
# KNOWNTARGETS will not be passed along to CoqMakefile
KNOWNTARGETS := CoqMakefile
# KNOWNFILES will not get implicit targets from the final rule, and so
# depending on them won't invoke the submake. TODO: Not sure what this means
# Warning: These files get declared as PHONY, so any targets depending
# on them always get rebuilt -- or better said, any rules which those names will have their cmds be re-ran (which is
# usually rebuilding functions since that is what make files are for)
KNOWNFILES := Makefile _CoqProject
# Runs invoke-coqmakefile rule if you do run make by itself. Sets the default goal to be used if no targets were specified on the command line.
.DEFAULT_GOAL := invoke-coqmakefile
# Depends on two files to run this, itself and our _CoqProject
CoqMakefile: Makefile _CoqProject
$(COQBIN)coq_makefile -f _CoqProject -o CoqMakefile
# Note make knows what is the make file in this case thanks to -f CoqMakefile
invoke-coqmakefile: CoqMakefile install_external_dependencies
$(MAKE) --no-print-directory -f CoqMakefile $(filter-out $(KNOWNTARGETS),$(MAKECMDGOALS))
#
.PHONY: invoke-coqmakefile $(KNOWNFILES)
####################################################################
## Your targets here ##
####################################################################
# This should be the last rule, to handle any targets not declared above
%: invoke-coqmakefile
#true
# I know this is not a good coq dependency example but just to make it concrete wrote some opam command
install_external_dependencies:
opam install coq-serapi
I think I wrote the install_external_dependencies in the right place but I'm not sure. Is that correct? Anyone has a real example?
For all the code see: https://github.com/brando90/ultimate-utils/tree/master/tutorials_for_myself/my_makefile_playground/beginner_coq_project_with_makefiles/debug_proj
related: question on official tutorial for building coq projects https://coq.discourse.group/t/official-place-to-learn-how-to-setup-coq-make-files-for-beginner/1682
Btw,
I don't understand the last like in the makefile yet.
# This should be the last rule, to handle any targets not declared above
%: invoke-coqmakefile
#true
i.e.
%true in the make file template coq gave us.
% in the name of the rule.
What does that line do?
Update
I'm seeking an end-to-end small demo of how to install all dependencies with whatever the recommended approach when using _CoqProject and coq_makefile as shown in the utilities doc https://coq.inria.fr/refman/practical-tools/utilities.html. The ideal answer would contain a single script to install and compile everything in one go -- say in a install_project_name.sh. Including opam switches etc.
Related:
How does one install a new version of Coq when it cannot find the repositories in a new Mac M1 machine?
Installing packages for Coq using OPAM
https://coq.discourse.group/t/official-place-to-learn-how-to-setup-coq-make-files-for-beginner/1682
The simplest setup is to install external dependencies manually with opam.
opam install packages-needed-by-my-project
Then they will be immediately available to build your own project.
The next level of organization is to package up your project. Refer to the following Coq community resources:
Coq community templates
Recommended Project Structure
The main thing immediately relevant to your question is to have a *.opam file at the root of your project which lists its dependencies (possibly with version requirements). Then you can install them using opam install . --deps-only.
The Makefile part of your question is about a bit of overengineering for passing options seamlessly to CoqMakefile. I'm not sure how it works off-hand, but it's not important anyway, especially because Dune is superseding make as the recommended build system for Coq project.

Angular PWA missing ngsw.json and ngsw-worker file

I have a problem with #angular/pwa. when I am building in production mode I am not getting ngsw-worker.js and ngsw.json files in my dist folder.
the pwa version am using is:
#angular/pwa: ^0.13.8
#angular/service-worker: ~7.1.0
#angular version 7
Thanks in advance
This answer is only relevant when:
you use nrwl/nx
which decorates the ng command
and angular configuration composition:
i.e. ng build client --configuration=production,variant
nx version 11
Now the workaround for version 10 (see below) does not work anymore!
closed-nx#4296: Cannot pass in multiple configurations using -c since nx 11
actual fix should be handled in: nx#2839: NX does not handle multiple configurations: nx run app:build --configuration=production,stage-env
a workaround can be to opt-out of the nx ng-cli-decorate patch
quote from nx#4452:
To opt out of this patch:
Replace occurrences of nx with ng in your package.json Remove the
script from your postinstall script in your package.json Delete and
reinstall your node_modules
nx version 10
To fix the issue (we use nx version 10) we replaced:
ng build client --configuration=production,variant with
nx build client -c=production,variant
The problem was, that nx did not pass the configuration correctly to ng and thus ng did not build the production configuration (thus no PWA/service-worker)
Links to nx issues:
#2839: NX does not handle multiple configurations: nx run app:build --configuration=production,stage-env
#4296: Cannot pass in multiple configurations using -c since nx 11
You can copy the files from the node_modules folder (from a prompt in your project folder):
cp node_modules/#angular/service-worker/ngsw-worker.js ./src/ngsw-worker.js
cp node_modules/#angular/service-worker/ngsw-config.json ./ngsw-config.json
You may also need to make sure your service worker is registered. Nice presentation on the subject at: https://javascript-conference.com/wp-content/uploads/2017/12/Automatic_Progressive_Web_Apps_using_Angular_Service_Worker_Maxim_Salnikov.pdf

Coq: manage LoadPath in project with subdirectories

I have a Coq project with its libraries organised into subdirectories, something like:
…/MyProj/Auxiliary/Aux.v
…/MyProj/Main/Main.v (imports Auxiliary/Aux.v)
When I compile the files, I expect to do so from working directory MyProj (via a makefile). But I also want to work on the files using Proof General/Coqtop, in which case the working directory is by default the directory in which the file lives.
But this means that the LoadPath is different between the two contexts, and so the logical path needed for the library import is different. How do I set up the coqc invocation, the LoadPath, and the import declarations so that they work in both contexts?
Each approach I have tried, something goes wrong. For instance, if I compile Aux.v by invoking
coqc -R "." "MyProj" Auxiliary/Aux.v
and import it in Main.v as
Require Import MyProj.Auxiliary.Aux.
then this works when I compile Main.v with
coqc -R "." "MyProj" Main/Main.v
but fails in Coqtop, with Error: Cannot find library MyProj.Auxiliary.Aux in loadpath. On the other hand, if before the Require Import I add
Add LoadPath ".." as MyProj.
then this works in Coqtop, but fails under coqc -R "." "MyProj" Main/Main.v, with
Error: The file […]/MyProj/Auxiliary/Aux.vo contains library
MyProj.Auxiliary.Aux and not library MyProj.MyProj.Auxiliary.Aux
I’m looking for a solution that’s robust for a library that’s shared with collaborators (and hopefully eventually with users), so in particular it can’t use absolute file paths. The best I have found for now is to add emacs local variables to set the LoadPath up when Proof General invokes Coqtop:
((coq-mode . ((coq-prog-args . ("-R" ".." "MyProj" "-emacs")))))
but this (a) seems a little hacky, and (b) only works for Proof General, not in Coqide or plain Coqtop. Is there a better solution?
Allow me to side-step your question by suggesting an alternative process, hinted at by Tiago.
Assuming that your project's tree looks like this:
MyProj/Auxiliary/Aux.v
MyProj/Main/Main.v
In MyProj, write a _CoqProject file listing all your Coq files
-R . ProjectName
Auxiliary/Aux.v
Main/Main.v
When you open one of these Coq files, emacs will look for the _CoqProject and do-the-right-thing (tm).
As shown by Tiago, coq_makefile will also give you a Makefile for free.
I know you explicitly asked for something that works across different platforms, but there's already a Proof-General-specific solution that is less hacky than the one you have. Proof General has a special variable called coq-load-path that you can set with local variables, much like you did for coq-prog-args. The advantage is that you don't have to worry about any other arguments that need to be passed to coqtop (such as -emacs in your example). Thus, your .dir-locals.el file could have a line like this:
((coq-mode . ((coq-load-path . ((".." "MyProj"))))))
Unfortunately, I am not aware of anything that works across platforms, although I'm pretty sure that something specific for CoqIDE must exist. If this is the case, maybe you could set up a script to keep these configuration files updated across different platforms?
If you use coq_makefile you can install the library in your system.
Without OPAM
To initialize your project:
coq_makefile -f _CoqProject -o Makefile
Share your library with other projects:
make install
With OPAM
Assuming you have OPAM installed, you can use coq-shell to help you take care of dependencies.
To setup your project:
coq_shell_url="https://raw.githubusercontent.com/gares/opam-coq-shell/master/src/opam-coq"
curl -s "${coq_shell_url}" | bash /dev/stdin init 8.4 # Install Coq and its dependencies
eval `opam config env --switch=coq-shell-8.4` # Setup the environment
coq_makefile -f _CoqProject -o Makefile # Generates the makefile
opam pin add coq:YOURLIBRARY . # Add your library to OPAM
When you update your library you should do:
opam upgrade coq:YOURLIBRARY
Here is an example of a project that uses the OPAM method:
https://bitbucket.org/cogumbreiro/aniceto-coq/src

compile and join coffeescript files

I have the following structure:
/lib
/ myfile.js.cofee
/ secondfile.js
/src
and i would like to compile them into
/lib
/ myfile.js.cofee
/ secondfile.js
/src
/ awesomefile.min.js
I have read about Cakefiles, but i'm not sure how to exactly do this.
Thanks,
Mike
If you happen to be using something based on connect (e.g. express), I'd recommend using connect-assets. If not, then grunt may be a good bet, as was previously suggested. If you'd like to do this yourself using a Cakefile, here is one approach you could use:
Note that the convention is to build from src to lib (which is the reverse of what you stated in the question). I'll use that convention below, but you can easily switch it back if needed.
$ npm install snockets
place the following in src/awesomefile.coffee:
#= require secondfile.js
#= require myfile.js.coffee
create a Cakefile with the following:
fs = require 'fs'
Snockets = require 'snockets'
NAME = 'awesomefile'
INPUT_FILE = "src/#{NAME}.coffee"
OUTPUT_FILE = "lib/#{NAME}.min.js"
task 'build', 'Build lib/ from src/', ->
snockets = new Snockets()
js = snockets.getConcatenation INPUT_FILE, async: false, minify: true
fs.writeFileSync OUTPUT_FILE, js
task 'clean', "remove #{OUTPUT_FILE}", ->
fs.unlinkSync OUTPUT_FILE
Now you can just do:
$ cake build
and that will create a lib/awesomefile.min.js.
You can have the files in src track their own dependencies, or you can list the order to be included in a single file like I've done above. For more, you can check out the snockets repository. Also note that the compiling chapter chapter of The Little Book on CoffeeScript is a good resource for learning about cake files.
Might not be the exact answer you expected.
Grunt.js at www.gruntjs.com is a very helpful buildtool and certainly includes a lot of stuff that you need to do on a daily basis with a webproject.