Skip to content

chore: clean-up code used for Node.js 4 and 5 #4335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 1 addition & 41 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"program": "${workspaceRoot}/lib/nativescript-cli.js",

// example commands
"args": [ "create", "cliapp"]
"args": [ "create", "cliapp", "--path", "${workspaceRoot}/scratch"]
// "args": [ "test", "android", "--justlaunch"]
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
Expand All @@ -39,53 +39,13 @@
"sourceMaps": true
},

{
"type": "node",
"runtimeArgs": [
"--harmony"
],
"request": "launch",
"name": "Launch CLI (Node 4, Node 5)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
// define the arguments that you would like to pass to CLI, for example
// "args": [ "build", "android", "--justlaunch" ]
"args": [

]
},

{
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
"type": "node",
"runtimeArgs": [
"--harmony"
],
"request": "launch",
"name": "Launch Tests (Node 4, Node 5)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},

{
"type": "node",
"request": "attach",
"name": "Attach to Broker Process",
// In case you want to debug Analytics Broker process, add `--debug-brk=9897` (or --inspect-brk=9897) when spawning analytics-broker-process.
"port": 9897,
"sourceMaps": true
},

{
"type": "node",
"request": "attach",
"name": "Attach to Eqatec Process",
// In case you want to debug Eqatec Analytics process, add `--debug-brk=9855` (or --inspect-brk=9855) when spawning eqatec-analytics-process.
// NOTE: Ensure you set it only for one of the analytics processes.
"port": 9855,
"sourceMaps": true
}

]
Expand Down
26 changes: 1 addition & 25 deletions bin/tns
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@

"use strict";
var path = require("path"),
node = require("../package.json").engines.node,
pathToLib = path.join(__dirname, "..", "lib"),
pathToCommon = path.join(pathToLib, "common");

require(path.join(pathToCommon, "verify-node-version")).verifyNodeVersion();

var pathToCliExecutable = path.join(pathToLib, "nativescript-cli.js");

var nodeArgs = require(path.join(pathToCommon, "scripts", "node-args")).getNodeArgs();

if (nodeArgs.length) {
// We need custom args for Node process, so pass them here.
var childProcess = require("child_process");
var args = process.argv;

// Remove `node` and `nativescript` from the arguments.
args.shift();
args.shift();

args.unshift(pathToCliExecutable);

args = nodeArgs.concat(args);

var nodeProcess = childProcess.spawn(process.execPath, args, { stdio: "inherit" });

nodeProcess.on("close", function (code) {
// We need this handler so if command fails, we'll exit with same exit code as CLI.
process.exit(code);
});
} else {
require(pathToCliExecutable);
}
require(pathToCliExecutable);
15 changes: 0 additions & 15 deletions lib/common/scripts/node-args.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/common/test-scripts/istanbul.js

This file was deleted.

15 changes: 0 additions & 15 deletions lib/common/test-scripts/mocha.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"main": "./lib/nativescript-cli-lib.js",
"scripts": {
"setup": "npm i --ignore-scripts && ./node_modules/.bin/grunt",
"test": "node test-scripts/istanbul.js",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha",
"postinstall": "node postinstall.js",
"preuninstall": "node preuninstall.js",
"prepack": "grunt prepare",
"postpack": "grunt set_dev_ga_id",
"mocha": "node test-scripts/mocha.js",
"mocha": "mocha",
"tsc": "tsc",
"tslint": "tslint -p tsconfig.json --type-check",
"test-watch": "node ./dev/tsc-to-mocha-watch.js",
Expand Down
3 changes: 1 addition & 2 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ var child_process = require("child_process");
var path = require("path");
var constants = require(path.join(__dirname, "lib", "constants"));
var commandArgs = [path.join(__dirname, "bin", "tns"), constants.POST_INSTALL_COMMAND_NAME];
var nodeArgs = require(path.join(__dirname, "lib", "common", "scripts", "node-args")).getNodeArgs();
var helpers = require(path.join(__dirname, "lib", "common", "helpers"));
if (helpers.isInstallingNativeScriptGlobally()) {
child_process.spawn(process.argv[0], nodeArgs.concat(commandArgs), { stdio: "inherit" });
child_process.spawn(process.argv[0], commandArgs, { stdio: "inherit" });
}
4 changes: 1 addition & 3 deletions preuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

var child_process = require("child_process");
var commandArgs = ["bin/tns", "dev-preuninstall"];
var path = require("path");
var nodeArgs = require(path.join(__dirname, "lib", "common", "scripts", "node-args")).getNodeArgs();

var child = child_process.exec("node " + nodeArgs.concat(commandArgs).join(" "), function (error) {
var child = child_process.exec("node " + commandArgs.join(" "), function (error) {
if (error) {
// Some npm versions (3.0, 3.5.1, 3.7.3) remove the NativeScript node_modules before the preuninstall script is executed and the script can't find them (the preuninstall script is like postinstall script).
// The issue is described in the npm repository https://github.com/npm/npm/issues/8806 and it is not fixed in version 3.1.1 as commented in the conversation.
Expand Down
20 changes: 0 additions & 20 deletions test-scripts/istanbul.js

This file was deleted.

15 changes: 0 additions & 15 deletions test-scripts/mocha.js

This file was deleted.

3 changes: 1 addition & 2 deletions test/nativescript-cli-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assert } from "chai";
import * as fs from "fs";
import * as path from "path";
import * as childProcess from "child_process";
const nodeArgs = require(path.join(__dirname, "..", "lib", "common", "scripts", "node-args")).getNodeArgs();

describe("nativescript-cli-lib", () => {
it("is main entry of the package", () => {
Expand Down Expand Up @@ -67,7 +66,7 @@ describe("nativescript-cli-lib", () => {
// For example $injector.register("errors", Errors) will add the errors module with its resolver (Errors) to $injector's cache.
// Calling $injector.require("errors", <path to errors file>), that's executed in our bootstrap, will fail, as the module errors is already in the cache.
// In order to workaround this problem, start new process and assert there. This way all files will not be required in it and $injector.require(...) will work correctly.
let testMethod = `"${process.execPath}" ${nodeArgs.join(" ")} -e "` +
let testMethod = `"${process.execPath}" -e "` +
"var assert = require('chai').assert;" +
`var result = require('${pathToEntryPoint}');` +
`assert.ok(result.${moduleName});`;
Expand Down