-
-
Notifications
You must be signed in to change notification settings - Fork 196
Implement lockfile and symlink option #140
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule common
updated
9 files
+0 −1 | definitions/mobile.d.ts | |
+5 −5 | helpers.ts | |
+3 −3 | mobile/android/android-device.ts | |
+2 −2 | mobile/app-identifier.ts | |
+1 −1 | mobile/ios/ios-core.ts | |
+11 −20 | mobile/ios/ios-emulator-services.ts | |
+4 −1 | options.ts | |
+1 −1 | services/commands-service.ts | |
+3 −3 | services/hooks-service.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
declare module "lockfile" { | ||
export function lock(lockFilename: string, lockParams: ILockParams, callback: (err: Error) => void): void; | ||
export function lockSync(lockFilename: string, lockParams: ILockSyncParams): void; | ||
export function unlock(lockFilename: string, callback: (err: Error) => void): void; | ||
export function unlockSync(lockFilename: string): void; | ||
|
||
interface ILockSyncParams { | ||
retries: number; | ||
stale: number; | ||
} | ||
|
||
interface ILockParams extends ILockSyncParams { | ||
retryWait: number; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
///<reference path=".d.ts"/> | ||
"use strict"; | ||
|
||
import Future = require("fibers/future"); | ||
import lockfile = require("lockfile"); | ||
import path = require("path"); | ||
import options = require("./options"); | ||
|
||
export class LockFile implements ILockFile { | ||
private static LOCK_FILENAME = path.join(options["profile-dir"], ".lock"); | ||
private static LOCK_EXPIRY_PERIOD_SEC = 180; | ||
private static LOCK_PARAMS = { | ||
retryWait: 100, | ||
retries: LockFile.LOCK_EXPIRY_PERIOD_SEC*10, | ||
stale: LockFile.LOCK_EXPIRY_PERIOD_SEC*1000 | ||
}; | ||
|
||
public lock(): IFuture<void> { | ||
var future = new Future<void>(); | ||
lockfile.lock(LockFile.LOCK_FILENAME, LockFile.LOCK_PARAMS, (err: Error) => { | ||
if(err) { | ||
future.throw(err); | ||
} else { | ||
future.return(); | ||
} | ||
}); | ||
return future; | ||
} | ||
|
||
public unlock(): IFuture<void> { | ||
var future = new Future<void>(); | ||
lockfile.unlock(LockFile.LOCK_FILENAME, (err: Error) => { | ||
if(err) { | ||
future.throw(err); | ||
} else { | ||
future.return(); | ||
} | ||
}); | ||
return future; | ||
} | ||
} | ||
$injector.register("lockfile", LockFile); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
///<reference path=".d.ts"/> | ||
"use strict"; | ||
|
||
import path = require("path"); | ||
|
||
require("./bootstrap"); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,28 +14,22 @@ export class NodePackageManager implements INodePackageManager { | |
private static NPM_REGISTRY_URL = "http://registry.npmjs.org/"; | ||
|
||
private versionsCache: IDictionary<string[]>; | ||
private isLoaded: boolean; | ||
|
||
constructor(private $logger: ILogger, | ||
private $errors: IErrors, | ||
private $httpClient: Server.IHttpClient, | ||
private $staticConfig: IStaticConfig, | ||
private $fs: IFileSystem) { | ||
private $fs: IFileSystem, | ||
private $lockfile: ILockFile) { | ||
this.versionsCache = {}; | ||
this.load().wait(); | ||
} | ||
|
||
public getCacheRootPath(): IFuture<string> { | ||
return (() => { | ||
this.load().wait(); | ||
return npm.cache; | ||
}).future<string>()(); | ||
public getCacheRootPath(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not a property? |
||
return npm.cache; | ||
} | ||
|
||
public addToCache(packageName: string, version: string): IFuture<void> { | ||
return (() => { | ||
this.load().wait(); | ||
this.addToCacheCore(packageName, version).wait(); | ||
}).future<void>()(); | ||
return this.addToCacheCore(packageName, version); | ||
} | ||
|
||
public load(config?: any): IFuture<void> { | ||
|
@@ -52,29 +46,21 @@ export class NodePackageManager implements INodePackageManager { | |
|
||
public install(packageName: string, opts?: INpmInstallOptions): IFuture<string> { | ||
return (() => { | ||
try { | ||
this.load().wait(); // It's obligatory to execute load before whatever npm function | ||
this.$lockfile.lock().wait(); | ||
|
||
try { | ||
var packageToInstall = packageName; | ||
var pathToSave = (opts && opts.pathToSave) || npm.cache; | ||
var version = (opts && opts.version) || null; | ||
var isSemanticVersioningDisabled = options.frameworkPath ? true : false; // We need to disable sem versioning for local packages | ||
|
||
if(version) { | ||
this.validateVersion(packageName, version).wait(); | ||
packageToInstall = packageName + "@" + version; | ||
} | ||
|
||
this.installCore(packageToInstall, pathToSave, isSemanticVersioningDisabled).wait(); | ||
return this.installCore(packageToInstall, pathToSave, version).wait(); | ||
} catch(error) { | ||
this.$logger.debug(error); | ||
this.$errors.fail(NodePackageManager.NPM_LOAD_FAILED); | ||
this.$errors.fail("%s. Error: %s", NodePackageManager.NPM_LOAD_FAILED, error); | ||
} finally { | ||
this.$lockfile.unlock().wait(); | ||
} | ||
|
||
var pathToNodeModules = path.join(pathToSave, "node_modules"); | ||
var folders = this.$fs.readDirectory(pathToNodeModules).wait(); | ||
return path.join(pathToNodeModules, folders[0]); | ||
|
||
}).future<string>()(); | ||
} | ||
|
||
|
@@ -86,21 +72,39 @@ export class NodePackageManager implements INodePackageManager { | |
}).future<string>()(); | ||
} | ||
|
||
private installCore(packageName: string, pathToSave: string, isSemanticVersioningDisabled: boolean): IFuture<void> { | ||
var currentVersion = this.$staticConfig.version; | ||
if(!semver.valid(currentVersion)) { | ||
this.$errors.fail("Invalid version."); | ||
} | ||
private installCore(packageName: string, pathToSave: string, version: string): IFuture<string> { | ||
return (() => { | ||
if (options.frameworkPath) { | ||
if (this.$fs.getFsStats(options.frameworkPath).wait().isFile()) { | ||
this.npmInstall(packageName, pathToSave, version).wait(); | ||
var pathToNodeModules = path.join(pathToSave, "node_modules"); | ||
var folders = this.$fs.readDirectory(pathToNodeModules).wait(); | ||
return path.join(pathToNodeModules, folders[0]); | ||
} | ||
return options.frameworkPath; | ||
} else { | ||
var version = version || this.getLatestVersion(packageName).wait(); | ||
var packagePath = path.join(npm.cache, packageName, version, "package"); | ||
if (!this.isPackageCached(packagePath).wait()) { | ||
this.addToCacheCore(packageName, version).wait(); | ||
} | ||
|
||
if(!isSemanticVersioningDisabled) { | ||
var incrementedVersion = semver.inc(currentVersion, constants.ReleaseType.MINOR); | ||
if(packageName.indexOf("@") < 0) { | ||
packageName = packageName + "@<" + incrementedVersion; | ||
if(!this.isPackageUnpacked(packagePath).wait()) { | ||
this.cacheUnpack(packageName, version).wait(); | ||
} | ||
return packagePath; | ||
} | ||
} | ||
}).future<string>()(); | ||
} | ||
|
||
private npmInstall(packageName: string, pathToSave: string, version: string): IFuture<void> { | ||
this.$logger.out("Installing ", packageName); | ||
|
||
var incrementedVersion = semver.inc(version, constants.ReleaseType.MINOR); | ||
if (!options.frameworkPath && packageName.indexOf("@") < 0) { | ||
packageName = packageName + "@<" + incrementedVersion; | ||
} | ||
|
||
var future = new Future<void>(); | ||
npm.commands["install"](pathToSave, packageName, (err: Error, data: any) => { | ||
if(err) { | ||
|
@@ -113,6 +117,17 @@ export class NodePackageManager implements INodePackageManager { | |
return future; | ||
} | ||
|
||
private isPackageCached(packagePath: string): IFuture<boolean> { | ||
return this.$fs.exists(packagePath); | ||
} | ||
|
||
private isPackageUnpacked(packagePath: string): IFuture<boolean> { | ||
return (() => { | ||
return this.$fs.getFsStats(packagePath).wait().isDirectory() && | ||
helpers.enumerateFilesInDirectorySync(packagePath).length > 1; | ||
}).future<boolean>()(); | ||
} | ||
|
||
private addToCacheCore(packageName: string, version: string): IFuture<void> { | ||
var future = new Future<void>(); | ||
npm.commands["cache"].add(packageName, version, undefined, (err: Error, data: any) => { | ||
|
@@ -150,14 +165,5 @@ export class NodePackageManager implements INodePackageManager { | |
return this.versionsCache[packageName]; | ||
}).future<string[]>()(); | ||
} | ||
|
||
private validateVersion(packageName: string, version: string): IFuture<void> { | ||
return (() => { | ||
var versions = this.getAvailableVersions(packageName).wait(); | ||
if(!_.contains(versions, version)) { | ||
this.$errors.fail("Invalid version. Valid versions are: %s", helpers.formatListOfNames(versions, "and")); | ||
} | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.register("npm", NodePackageManager); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"use strict";