How to use a reason module from local package - bucklescript

I’m looking for a way to use a local package (named bs-package) from my Reason React app (named ApplicationA).
bs-package has a single file within src folder called ModuleA.re :
let greet_me = (me) => Js.log("Hello, " ++ me ++ "!");
In ApplicationA I did :
npm install /path/to/bs-package
In node_modules bs-package now appears as symbolic link.
Then added bs-package to bs-dependencies in bsconfig
"bs-dependencies": [
"reason-react",
"bs-package",
],
Then run make world in ApplicationA
bsb -make-world
Now in my Reason React app
ModuleA.greet_me("John");
Gives me
unbound module ModuleA
What am I missing ?
EDIT
Here is the config file of bs-package
It was created with
bsb -init bs-package -theme basic-reson
bsconfig.json
{
"name": "bs-pacakge",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}
package.json
{
"name": "bs-pacakge",
"version": "0.1.0",
"scripts": {
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world"
},
"keywords": [
"BuckleScript"
],
"author": "",
"license": "MIT",
"devDependencies": {
"bs-platform": "^5.0.6"
}
}
As suggested, bs-package is namespaced so this should work
BsPackage.ModuleA.greet_me("name")
But the same error appears
unbound module BsPackage

Apparently the bug came from my bs-platform version. I've just switch from version 6.2.1 to version 7.0.1 and everything works fine now (I'm on Windows).

Related

Typescript build task in VSCode on Windows 10 with Windows Subsystem for Linux

My VSCode settings (workspace settings in my case) are setup to use bash as the default terminal:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\bash.exe"
}
I need this to be able to debug my app.
My tasks.json looks like that:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "./tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
So when I try to build my project / run the build task (i.e. Ctrl + B), I get the following error:
> Executing task: tsc -p "c:\PATH_TO_MY_PROJECT\tsconfig.json" <
error TS5058: The specified path does not exist: 'c:\PATH_TO_MY_PROJECT\tsconfig.json'.
The terminal process terminated with exit code: 1
If I disable bash in my settings an use the default Windows terminal, the build works fine.
I remember it working few VSCode updates ago, but it stopped working in the latest VSCode versions. Not sure how that's related.
I tried to fix this for a while, but finally gave up on the built-in Typescript task and instead just used a custom task:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Typescript watch",
"type": "shell",
"command": "tsc --watch",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$tsc"
]
}
]
}

Deploy .Net Core MVC app w/ class library to Ubuntu 16.04:

I wanted to build a simple .net core MVC app with a single class library for data access, to get an idea of what it takes to build/deploy/run Core on Linux. Not nearly as simple as I had hoped!
EDIT: Here's a copy of the solution, if anyone is interested:
https://s3.amazonaws.com/kilonova-public/code/CoreCrossPlatform.zip
I threw together a VirtualBox VM w/ Ubuntu Server 16.04 and installed dotnet core per these instructions:
https://www.microsoft.com/net/core#ubuntu
I installed all the latest, necessary bits on the host (Win10) for VS 2015 and created a solution with an MVC app and single class library called "DataAccess". It's EF Core talking to MySQL using their latest core provider. It all runs flawlessly on the Win10 host when I run/debug it. Pulls up data and looks great.
"dotnet --version" on both the host and the VM gives me:
1.0.0-preview2-003121
However, when I deploy it to the Ubuntu VM, I get the following error on the class library dependency:
Project corecrossplatform (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling corecrossplatform for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/project.json(24,23): error NU1002: The dependency DataAccess does not support framework .NETCoreApp,Version=v1.0.
Compilation failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.0187782
This happens whether I run "dotnet restore" or "dotnet run". To be perfectly honest, I'm not even sure I'm deploying this thing correctly. Documentation is spotty and I'm making some guesses. I copied everything from the project folder "src\CoreCrossPlatform" (contains bin, Program.cs, appsettings.json, etc.) onto the VM and this is where I'm executing the "dotnet" commands from, in the VM.
The DataAccess .json file:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0",
"MySql.Data.Core": "7.0.4-IR-191",
"MySql.Data.EntityFrameworkCore": "7.0.4-IR-191",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
The MVC project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"DataAccess": "1.0.0-*"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Something to note: When I run the sample project using "dotnet new" and restore, run vis the tutorial link above, it runs fine.
What am I missing? Another side question: What's the best way to publish this type of app to a Linux box? Am I even close on that part?
Thanks much.
EDIT: While kicking this dead horse all afternoon, I compared some notes I found online, related to this "NU1002" error, and the sample project "dotnet new" generates. I tried changing the "framework" section of both project.json files (MVC and classlib) to the following, with no success...same error:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net45+win8"
]
}
}
EDIT: Much thanks to goaty: As he pointed out in the comments, copying over the entire solution and building it, results in a successful build. However, I cannot run it without an error. It doesn't seem to restore the MySQL EF Core dependency:
Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling CoreCrossPlatformFlat for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/src/CoreCrossPlatformFlat/project.json(25,52): error NU1001: The dependency MySql.Data.EntityFrameworkCore >= 7.0.4-IR-191 could not be resolved.
Compilation failed.
0 Warning(s)
1 Error(s)
The DataAccess library exists outside of your src/ directory. Therefore the web project could not find the reference.
I recommend this structure
src/
|---DataAccess/
|---CoreCrossPlatform/
Hope that helps :)

Using "preLaunchTasks" and Naming a Task in Visual Studio Code

According to the documentation, it is possible to launch a program before debugging:
To launch a task before the start of each debug session, set the preLaunchTask to the name of one of the tasks specified in tasks.json.
I've not seen example syntax of a "named" task, but the schema documentation reveals a property called taskName. I tried using that to link my launch.json preLaunchTasks to the task, but it didn't work. When I launched my program, Visual Studio Code reported this error:
Could not find a unique task 'launch-core'. Make sure the task exists and that it has a unique name.
My custom "named" task looked something like this:
{
"taskName": "launch-core",
"version": "0.1.0",
"command": "C:\\utils\\mystuff.exe",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
}
I then tried changing the property name from taskName to just name, based on this link. That also didn't work.
Intellisense gives no suggestions of how to name a task.
Does anybody know how to uniquely name a task in the tasks.json file? What is the syntax? What is the property name?
Ultimately I'd like to execute two or three node.js processes before my own node.js app is launched. For example, I'd like to have the following three apps launched before my app is launched into the debugger:
sh -c 'cd ./manager/ && node manager.js'
sh -c 'cd ./adapter/ && node adapter.js'
sh -c 'cd ./core/ && node core.js'
If I'm working on a Windows box, my task might look something like this:
{
"taskName": "core-launch",
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "start",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": [
"ACD-Manager",
"/B",
"/D",
"./manager/",
"node",
"manager.js"
]
}
The above task using using the cmd start capability. I'm not sure yet how to make several node tasks launch instead of one, but I can't even get one task to launch because of this task-naming issue.
How do I name a task in the tasks.json file?
FWIW, I'm using VS Code 1.20.1 and here's how I got my preLaunchTask to work:
In launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
...
"preLaunchTask": "npm: build",
}
]
}
In my package.json:
{
...
"scripts": {
"build": "tsc"
...
}
}
So, if it's still relevant, or if someone finds this thread with the same problem, I've just figured it out how it works:
In the tasks.json, you need to create a 'tasks' array - code hint will help you with that - which holds an array of objects. Inside an object, you can have the 'taskName' key-value pair.
Example:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run-script", "webpack"],
"showOutput": "always",
"tasks": [
{
"taskName": "runwebpack",
"suppressTaskName": true
}
]
}
In my case, I had to run the npm run-script webpack command before running my project.
In the launch.json file, the "preLaunchTask": "runwebpack" will work now.
Note: the suppressTaskName is true in my example. Omitting it, or setting it to false will result in VS Code appending the taskName after the command.
A more general approach would be something like this:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run-script"],
"showOutput": "always",
"tasks": [
{ "taskName": "webpack" }
]
}
With the latter example, you can extend the tasks array with other scripts to be run also.
Hint for my usage: npm run-script fetches what to do from the package.json file's scripts object.
Edit: this works with VS Code 1.3.1
For version 2.0.0 configuration you now use label instead of taskName.
package.json:
...
"scripts": {
"tsc": "tsc",
...
}
...
launch.json (My source is in the src directory and tsc compiles to the dist directory):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"preLaunchTask": "Compile",
"name": "Launch Program",
"program": "${workspaceFolder}/src/index.ts",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"protocol": "inspector",
"sourceMaps": true
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"type": "npm",
"script": "tsc",
"problemMatcher": []
}
]
}
For vscode 1.36.1 (1.36.1):
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build:tsc",
"type": "npm",
"script": "build:tsc"
},
{
"label": "clean",
"type": "npm",
"script": "clean"
},
{
"label": "build",
"dependsOrder": "sequence",
"dependsOn": ["clean", "build:tsc"]
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/dist/main.js",
"preLaunchTask": "build",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"console": "integratedTerminal"
}
]
}
Before running node ${workspaceFolder}/dist/main.js, the preLaunchTask will run build task firstly which includes two subtasks: clean and build. It will run clean task firstly, then run build task.
You can specify the label of a task to preLaunchTask option.
The question title is:
"Using “preLaunchTasks” and Naming a Task in Visual Studio Code
I needed to define preLaunchTask***s***.
You can config multiple tasks using the dependsOn property described here
For example, a compound task in your tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Client Build",
"command": "gulp",
"args": ["build"],
"options": {
"cwd": "${workspaceRoot}/client"
}
},
{
"label": "Server Build",
"command": "gulp",
"args": ["build"],
"options": {
"cwd": "${workspaceRoot}/server"
}
},
{
"label": "Build",
"dependsOn": ["Client Build", "Server Build"]
}
]
}
You can find more information about naming tasks here.
I've only really seen the taskName used in relation to Gulp; I'm sure there are others but nothing that I have much insight into. Perhaps this can get you off to a start with what you already have?
Run a pre-launch task in VSCODE

what is the manifest JSON of the bower package management

On the Site bower.io,it says "There must be a valid manifest JSON in the current working directory." What does that mean? What is a manifest JSON?
This is referring to the bower.json file. This is a a sample of that:
{
"name": "my-project",
"version": "1.0.0",
"main": "path/to/main.css",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<name>": "<version>",
"<name>": "<folder>",
"<name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}

Execution of a node package command not working on Ubuntu 12.04 RTS

I have created a npm package, Here is the package.json:
{
"name": "docxgen",
"version": "1.0.5",
"author": "Hans Thunam <hans.thunam#gmail.com>",
"description": "A docX Generator",
"contributors": [
{
"name": "",
"email": ""
}
],
"bin":
{
"docxgen":"./docxgenNode/bin/docxgen"
},
"keywords": [
"DocX",
"templates",
"Generator"
],
"dependencies" : {
"xmldom" : "0.1.x"
},
"devDependencies": {
"jasmine-node":"1.10.x"
},
"license": "MIT",
"engines": {
"node": ">=0.8"
}
}
Then I did sudo npm install -g in the folder of package.json, the installation worked correctly (no error nor warnings).
Howewer, when I then try to execute docxgen file.docx file.json, I get the response: File or command not found. What is strange about this is that it works on Windows 7.
Is there anything different to do for Ubuntu ?
The issue was about the character encoding of the ./docxgenNode/bin/docxgen.
The shell system didn't read the first line correctly.
I started from an existing working binary file that can be found here: https://github.com/LearnBoost/stylus/blob/master/bin/stylus

Resources