Aurelia build on VSO Hosted Build Controller - azure-devops

I am trying to get a build going for Aurelia on VSO Hosted Build Controller. I created a small powershell script to run the following commands
npm install
.node_modules/.bin/jspm cc
.node_modules/.bin/jspm install -y
.node_modules/.bin/gulp build
I do have AfterBuild targets to copy the jspm_packages and dist folders to my _publishedWebsites folder.
npm install runs fine, but when it comes to jspm cc (if I remove the jspm cc and let it run jspm install -y), it fails trying to this
jspm cc
Migrating global jspm folder from C:\Users\buildguest\.jspm to C:\Users\buildguest\AppData\Local\.jspm...
Copying configuration...
err Error migrating to new jspm folder
2>EXEC : error : ENOENT, no such file or directory 'C:\Users\buildguest\.jspm\config' [d:\a\src\WebGUI\OwinAureliaScaffold\OwinAureliaScaffold.csproj]
at Object.fs.openSync (evalmachine.<anonymous>:427:18)
at Object.fs.readFileSync (evalmachine.<anonymous>:284:15)
at Object.<anonymous> (d:\a\src\WebGUI\OwinAureliaScaffold\public\node_modules\jspm\lib\global-config.js:36:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (d:\a\src\WebGUI\OwinAureliaScaffold\public\node_modules\jspm\lib\registry.js:19:20)
ok Loader file cache cleared.
ok Package cache cleared.
I do understand the jspm is not installed globally, since it is a hosted controller, I cannot really install it globally. My question is, how do I work through this without having a global jspm install? Is there a workaround where it does not have to migrate the config file?

Even though you cannot install and run the jspm CLI on the hosted build agent, you can run jspm through node itself.
First, make sure jspm is installed - which your powershell script does. Alternatively, you can use VSO Build's "npm install task", provided jspm is in your package.json file.
I used Gulp to execute jspm through node. I'm not sure if that's the best way to do this step, but it works... I used VSO's "Gulp task"
Here are the relevant bits from gulpfile.js:
var gulp = require('gulp'),
exec = require('child_process').exec;
//#region Build Tasks
gulp.task('build:jspm', function (cb) {
exec("node ./node_modules/jspm/jspm.js install", function(err, stdout, stderr) {
console.log(stdout);
console.error(stderr);
cb(err);
});
});
gulp.task('_build', ['build:jspm']);

I do understand the jspm is not installed globally, since it is a hosted controller, I cannot really install it globally.
It appears that this is not true (at least currently.) You can install jspm globally on a hosted controller.
I was able to solve this with a build process that looks like this:
npm install
npm install -g jspm
node C:\NPM\Modules\node_modules\jspm\jspm.js install
1) Installs all of the local dependencies from my package.json. 2) Installs a global version of JSPM 3) Evokes it from the global installation location
I realized from M Falanga's answer that node was obviously in the controller's path so I could call it from Powershell/command line. The global JSPM install location I found from looking at the build's debug logs. Note to implementors, you'll want to make sure your working directory for steps 1 and 3 are set to where your package.json is located.
Alternative Solution
I have not tested this next option in a build yet but you should be able to skip the extra build steps and just use the scripts feature of NPM to do the JSPM install. In this case you won't need the NPM install step nor the Run node step above.
In your package.json you'll need the following script entry:
"keywords": [...],
"scripts": {
"postinstall": "./node_modules/.bin/jspm install -y"
},
"jspm": {...

If administrative privileges are required on the computer to install a package, there's no way for you to do it in hosted build. You will have to create your own build machine in this case. It's something we hope to solve in the future.
That said, here's what one person did to get Aurelia set up: http://fabhojs.blogspot.com/2015/03/aurelia-app-skeleton-yeoman-generator.html (from this question). Those steps are different and may help.

Related

Trying to run babel : "cannot find module #babel/core"

I'm trying to set up a build environment to explore react.
My build process uses gulp.
I installed packages like this:
npm install --save-dev gulp-babel#7 babel-core babel-preset-env
After discovering that I needed to install something related to babel and react I also ran:
npm install --save-dev #babel/preset-react
My .babelrc has this:
{ "presets": ["#babel/preset-react"] }
My gulpfile has this:
gulp.task('scripts', function() {
return gulp.src(['./src/js/main.js' ])
.pipe(babel({
presets : ['#babel/preset/react']
}))
.pipe(concat('test.js'))
.pipe(gulp.dest('./js'))
.pipe(uglify())
.pipe(rename('test.min.js'))
.pipe(gulp.dest('./js')) ;
});
When I run 'gulp scripts' I get this:
[22:51:14] Using gulpfile ~/play/learning-react-2/gulpfile.js
[22:51:14] Starting 'scripts'...
[22:51:14] 'scripts' errored after 59 ms
[22:51:14] Error in plugin "gulp-babel"
Message:
Cannot find module '#babel/core' (While processing preset: "/home/bob/play/learning-react-2/node_modules/#babel/preset-react/lib/index.js")
I deleted babel-core from node_modules, and reinstalled it using the command:
npm install --save-dev #babel/core
If I look at the contents of node_modules, I see these packages related to babel:
babel-code-frame/
babel-helper-builder-binary-assignment-operator-visitor/
babel-helper-call-delegate/
babel-helper-define-map/
babel-helper-explode-assignable-expression/
babel-helper-function-name/
babel-helper-get-function-arity/
babel-helper-hoist-variables/
babel-helper-optimise-call-expression/
babel-helper-regex/
babel-helper-remap-async-to-generator/
babel-helper-replace-supers/
babel-messages/
babel-plugin-check-es2015-constants/
babel-plugin-syntax-async-functions/
babel-plugin-syntax-exponentiation-operator/
babel-plugin-syntax-trailing-function-commas/
babel-plugin-transform-async-to-generator/
babel-plugin-transform-es2015-arrow-functions/
babel-plugin-transform-es2015-block-scoped-functions/
babel-plugin-transform-es2015-block-scoping/
babel-plugin-transform-es2015-classes/
babel-plugin-transform-es2015-computed-properties/
babel-plugin-transform-es2015-destructuring/
babel-plugin-transform-es2015-duplicate-keys/
babel-plugin-transform-es2015-for-of/
babel-plugin-transform-es2015-function-name/
babel-plugin-transform-es2015-literals/
babel-plugin-transform-es2015-modules-amd/
babel-plugin-transform-es2015-modules-commonjs/
babel-plugin-transform-es2015-modules-systemjs/
babel-plugin-transform-es2015-modules-umd/
babel-plugin-transform-es2015-object-super/
babel-plugin-transform-es2015-parameters/
babel-plugin-transform-es2015-shorthand-properties/
babel-plugin-transform-es2015-spread/
babel-plugin-transform-es2015-sticky-regex/
babel-plugin-transform-es2015-template-literals/
babel-plugin-transform-es2015-typeof-symbol/
babel-plugin-transform-es2015-unicode-regex/
babel-plugin-transform-exponentiation-operator/
babel-plugin-transform-regenerator/
babel-plugin-transform-strict-mode/
babel-preset-env/
babel-runtime/
babel-template/
babel-traverse/
babel-types/
I'm guessing that at least one of them is "babel core"
So... how do I actually run babel from gulp? How do I run it at all?
I had the same issue. I resolved it by removing node_modules and I reinstalled packages (with yarn OR npm install). The problem was fixed.
In case Victor's answer doesn't help, it may be worth a try to clean your machine's package cache by running npm cache clean/yarn cache clean or removing the cache folder manually.

Error: Error: Cannot find module 'cucumber'

I am trying to execute a small example of automated test using Webstorm, cucumber and protractor.
I have already installed cucumber using this command within the root of the project:
sudo npm install -g cucumber
I have already created the conf.js file and when running this command within the prompt:
> protractor conf.js
Finally, the output is:
*
[13:13:18] E/launcher - Error: Error: Cannot find module 'cucumber'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.module.exports.load (/Users/alfredo.bazo/node_modules/protractor-cucumber-framework/lib/cucumberLoader.js:19:24)
at Object.<anonymous> (/Users/alfredo.bazo/node_modules/protractor-cucumber-framework/index.js:8:33)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
[13:13:18] E/launcher - Process exited with error code 100
I have no idea what else I can do, any suggestions?
There are two approach to resolve your problem, and recommend to use approach 1).
1) install cucumber as project local package, rather than global package.
npm install -S cucumber
2) install cucumber as global package, and you need to add below Environment variable to tell node.exe where to find and load global package.
NODE_PATH=<npm global package install folder path on your machine>
you can execute npm config get prefix which will print out the global package install folder path.
Important: After add environment variable, you need to try in new opened cmd/terminal window.
how to overcome this :try to share video please regarding this query : ...
install cucumber as global package, and you need to add below Environment variable to tell node.exe where to find and load global package.
NODE_PATH=
you can execute npm config get prefix which will print out the global package install folder path.
Important: After add environment variable, you need to try in new opened cmd/terminal window.

code ship fails with error - You have to be inside an angular-cli project in order to use the serve command

For my angular CLI/Bitbucket project I am running following script in Codeship but it gives error You have to be inside an angular-cli project in order to use the serve command.
#install node version, 4.x is required for the angular-cli
nvm install 4.1
#install angular-cli
npm install angular-cli
#run npm install for your project dependencies
npm install
Under that script is the "Test Pipelines", where the script is setup to run the tests.
#serve the application adding '&' to run command in background
ng serve &
#start end to end tests using protractor
ng test
#if all of the tests pass, then build the production assets
ng build -prod
According to https://github.com/angular/angular-cli/issues/4379 this error message is usually triggered if you're using the (now deprecated) angular-cli package.
Either update the package.json file for the project to reference the #angular/cli package, or make sure to install this package instead of the deprecated one.

How to verify facebook jest is installed successfully

I followed the instructions to install Facebook jest on https://facebook.github.io/jest/docs/getting-started.html#content :
npm install --save-dev jest-cli
After the install command I typed jest in the terminal, and press enter but It popped:
bash: jest: command not found.
But when I run the getting started sample by using npm test in the terminal, it worked well.
So, how can I verify that Facebook jest is installed successfully?
Ways to install a package in npm
In node.js you have two ways to install a package: globally or locally.
The sintax is the following:
// globally
npm install -g [package_name]
// locally
npm install --save-dev [package_name]
So, now what it happens is that you run the local one which downloads the package in node_modules under your project folder.
To check you installed jest properly so you can check on your node_modules if there is a jest folder.
How to check if jest is installed
In addition to that npm is creating a shortcut in you local node_modules under the directory .bin son in there you should find a link to jest.
You can test that like that:
cd your_project_folder
./node_modules/.bin/jest
Why npm test works?
The reason why npm test works is because when you run it npm is going to look for the commands globally and locally.

`npm install <folder>` or `npm pack` does not install dependencies

I have an npm package that uses coffeescript source, which I want to precompile before pack or publish. However, my prepublish script depends on coffee-script as a devDependency, but npm isn't installing it before running the prepublish action. I have to run npm install separately first, which seems wrong. The same issue exists if I try to npm install the source folder into a different project.
I suspect that I'm "doing it wrong," but the only other guidence I've seen is to compile on install rather than publish. I'd rather not do that, so I'm hoping there are examples of prepublish compilation that I can crib from.