Skip to content

Fix debug android command #2713

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 3 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/services/android-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class AndroidDebugService extends DebugServiceBase implements IPlatformDebugServ
debugerStarted = forwardsResult.indexOf(waitText) === -1;

if (!debugerStarted) {
sleep(500);
await sleep(500);
Copy link
Contributor

@yyosifov yyosifov Apr 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! :)

Small typo: debugerStarted => debuggerStarted

What do you think of introducing a function wait.Until(function, condition, sleepIntervalMs) which implements a loop which sleeps for several iterations or until a condition is met? This way, we can introduce unit tests for it, reuse it and don't worry about such bugs anymore? I've seen this implemented and it was working good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the snippet I've been referring to (from another project and in C#):

public class PollingService : IPollingService
	{
		public bool WaitUntil(Func<bool> successCriteria, int millisecondsInterval, int iterations)
		{
			var succeeded = false;
			for (int i = 0; i < iterations; i++)
			{
				if (successCriteria())
				{
					succeeded = true;
					break;
				}
				else if (i < iterations - 1)
				{
					Thread.Sleep(millisecondsInterval);
				}
			}

			return succeeded;
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea and I suggest to implement it in another PR (where we will add tests for it). We can use it on several places in CLI (at least two :) )
Thanks for the suggestion.

}
}

Expand Down
108 changes: 0 additions & 108 deletions lib/tools/node-modules/node-modules-builder.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,13 @@
import * as constants from "../../../lib/constants";
import * as path from "path";
import * as shelljs from "shelljs";
import { TnsModulesCopy, NpmPluginPrepare } from "./node-modules-dest-copy";
import { NodeModulesDependenciesBuilder } from "./node-modules-dependencies-builder";
import { sleep, deferPromise } from "../../../lib/common/helpers";

let glob = require("glob");

export class NodeModulesBuilder implements INodeModulesBuilder {
constructor(private $fs: IFileSystem,
private $injector: IInjector,
private $lockfile: ILockFile,
private $options: IOptions
) { }

public async getChangedNodeModules(absoluteOutputPath: string, platform: string, projectData: IProjectData, lastModifiedTime?: Date): Promise<any> {
let projectDir = projectData.projectDir;
let isNodeModulesModified = false;
let nodeModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME);
let nodeModules: any = {};

if (lastModifiedTime) {
let defer = deferPromise();

let match = new glob.Glob("node_modules/**", {
cwd: projectDir,
follow: true,
stat: true
}, (er: Error, files: string[]) => {
while (this.$lockfile.check()) {
sleep(10);
}

this.$lockfile.lock();
if (er) {
if (!defer.isResolved()) {
defer.reject(er);
}

this.$lockfile.unlock();
match.abort();
return;
}
for (let i = 0, l = files.length; i < l; i++) {
let file = files[i],
resolvedPath = path.join(projectDir, file),
relativePath = path.relative(projectDir, resolvedPath);
let stat = match.statCache[resolvedPath] || match.statCache[relativePath];
if (!stat) {
match.statCache[resolvedPath] = stat = this.$fs.getFsStats(resolvedPath);
}

if (stat.mtime <= lastModifiedTime) {
continue;
}
if (file === constants.NODE_MODULES_FOLDER_NAME) {
isNodeModulesModified = true;
this.$lockfile.unlock();
match.abort();
if (!defer.isResolved()) {
defer.resolve();
}

return;
}
let rootModuleName = path.normalize(file).split(path.sep)[1];
let rootModuleFullPath = path.join(nodeModulesPath, rootModuleName);
nodeModules[rootModuleFullPath] = rootModuleFullPath;
}

this.$lockfile.unlock();
});

match.on("end", () => {
if (!defer.isResolved()) {
let intervalId = setInterval(() => {
if (!this.$lockfile.check() || defer.isResolved()) {
if (!defer.isResolved()) {
defer.resolve();
}
clearInterval(intervalId);
}
}, 100);
}
});

await defer.promise;
}

if (isNodeModulesModified && this.$fs.exists(absoluteOutputPath)) {
let currentPreparedTnsModules = this.$fs.readDirectory(absoluteOutputPath);
let tnsModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME, constants.TNS_CORE_MODULES_NAME);
let tnsModulesInApp = this.$fs.readDirectory(tnsModulesPath);
let modulesToDelete = _.difference(currentPreparedTnsModules, tnsModulesInApp);
_.each(modulesToDelete, moduleName => this.$fs.deleteDirectory(path.join(absoluteOutputPath, moduleName)));
}

if (!lastModifiedTime || isNodeModulesModified) {
this.expandScopedModules(nodeModulesPath, nodeModules);
}

return nodeModules;
}

private expandScopedModules(nodeModulesPath: string, nodeModules: IStringDictionary): void {
let nodeModulesDirectories = this.$fs.exists(nodeModulesPath) ? this.$fs.readDirectory(nodeModulesPath) : [];
_.each(nodeModulesDirectories, nodeModuleDirectoryName => {
let isNpmScope = /^@/.test(nodeModuleDirectoryName);
let nodeModuleFullPath = path.join(nodeModulesPath, nodeModuleDirectoryName);
if (isNpmScope) {
this.expandScopedModules(nodeModuleFullPath, nodeModules);
} else {
nodeModules[nodeModuleFullPath] = nodeModuleFullPath;
}
});
}

public async prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void> {
if (!this.$fs.exists(absoluteOutputPath)) {
// Force copying if the destination doesn't exist.
Expand Down