Skip to content

Fix prepare to work correctly if you have npm module and tns plugin in same project #634

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
Jul 13, 2015
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
10 changes: 5 additions & 5 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface INodePackageManager {
load(config?: any): IFuture<void>;
install(packageName: string, pathToSave: string, config?: any): IFuture<any>;
uninstall(packageName: string, config?: any): IFuture<any>;
cache(packageName: string, version: string, cache?: any): IFuture<ICacheData>;
cache(packageName: string, version: string, cache?: any): IFuture<IDependencyData>;
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
view(packageName: string, propertyName: string): IFuture<any>;
}
Expand All @@ -22,12 +22,12 @@ interface INpmInstallOptions {
version?: string;
}

interface ICacheData {
interface IDependencyData {
name: string;
version: string;
dependencies: IStringDictionary;
devDependencies: IStringDictionary;
nativescript?: any;
nativescript: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

spaces at the end of line

dependencies?: IStringDictionary;
devDependencies?: IStringDictionary;
}

interface IStaticConfig extends Config.IStaticConfig { }
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface IPluginsService {
add(plugin: string): IFuture<void>; // adds plugin by name, github url, local path and et.
remove(pluginName: string): IFuture<void>; // removes plugin only by name
prepare(pluginData: IPluginData): IFuture<void>;
prepare(pluginData: IDependencyData): IFuture<void>;
getAllInstalledPlugins(): IFuture<IPluginData[]>;
ensureAllDependenciesAreInstalled(): IFuture<void>;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class NodePackageManager implements INodePackageManager {
return this.loadAndExecute("uninstall", [[packageName]], { config: config });
}

public cache(packageName: string, version: string, config?: any): IFuture<ICacheData> {
public cache(packageName: string, version: string, config?: any): IFuture<IDependencyData> {
// function cache (pkg, ver, where, scrub, cb)
return this.loadAndExecute("cache", [packageName, version, undefined, false], { subCommandName: "add", config: config });
}
Expand Down
14 changes: 5 additions & 9 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ export class PlatformService implements IPlatformService {
this.$fs.deleteDirectory(platformPath).wait();
throw err;
}

// Prepare installed plugins
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
_.each(installedPlugins, pluginData => this.$pluginsService.prepare(pluginData).wait());

this.$logger.out("Project successfully created.");

Expand Down Expand Up @@ -179,15 +175,15 @@ export class PlatformService implements IPlatformService {

platformData.platformProjectService.prepareProject().wait();

// Process platform specific files
let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait();

// Process node_modules folder
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
var tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, PlatformService.TNS_MODULES_FOLDER_NAME);
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, this.$projectData.projectDir, platform, lastModifiedTime).wait();

// Process platform specific files
let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait();

this.$logger.out("Project successfully prepared");
}).future<void>()();
Expand Down
14 changes: 8 additions & 6 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class PluginsService implements IPluginsService {
public add(plugin: string): IFuture<void> {
return (() => {
let dependencies = this.getAllInstalledModules().wait();
let cacheData = this.$npm.cache(plugin, undefined, PluginsService.NPM_CONFIG).wait();
if(cacheData.nativescript) {
let dependencyData = this.$npm.cache(plugin, undefined, PluginsService.NPM_CONFIG).wait();
if(dependencyData.nativescript) {
let pluginName = this.executeNpmCommand(PluginsService.INSTALL_COMMAND_NAME, plugin).wait();
this.prepare(this.convertToPluginData(cacheData)).wait();
this.$logger.out(`Successfully installed plugin ${cacheData.name}.`);
this.prepare(dependencyData).wait();
this.$logger.out(`Successfully installed plugin ${dependencyData.name}.`);
} else {
this.$errors.failWithoutHelp(`${plugin} is not a valid NativeScript plugin. Verify that the plugin package.json file contains a nativescript key and try again.`);
}
Expand Down Expand Up @@ -68,8 +68,10 @@ export class PluginsService implements IPluginsService {
}).future<void>()();
}

public prepare(pluginData: IPluginData): IFuture<void> {
public prepare(dependencyData: IDependencyData): IFuture<void> {
return (() => {
let pluginData = this.convertToPluginData(dependencyData);

let action = (pluginDestinationPath: string, platform: string, platformData: IPlatformData) => {
return (() => {
// Process .js files
Expand All @@ -89,7 +91,7 @@ export class PluginsService implements IPluginsService {
}

this.$fs.ensureDirectoryExists(pluginDestinationPath).wait();
shelljs.cp("-R", pluginData.fullPath, pluginDestinationPath);
shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath);

let pluginPlatformsFolderPath = path.join(pluginDestinationPath, pluginData.name, "platforms", platform);
let pluginConfigurationFilePath = path.join(pluginPlatformsFolderPath, platformData.configurationFileName);
Expand Down
2 changes: 1 addition & 1 deletion lib/tools/broccoli/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Builder implements IBroccoliBuilder {
}

if(!lastModifiedTime || isNodeModulesModified) {
let nodeModulesDirectories = this.$fs.readDirectory(nodeModulesPath).wait();
let nodeModulesDirectories = this.$fs.exists(nodeModulesPath).wait() ? this.$fs.readDirectory(nodeModulesPath).wait() : [];
_.each(nodeModulesDirectories, nodeModuleDirectoryName => {
let nodeModuleFullPath = path.join(nodeModulesPath, nodeModuleDirectoryName);
this.nodeModules[nodeModuleFullPath] = nodeModuleFullPath;
Expand Down
12 changes: 6 additions & 6 deletions lib/tools/broccoli/node-modules-dest-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class DestCopy implements IBroccoliPlugin {
private projectDir: string,
private platform: string,
private $fs: IFileSystem,
private $projectFilesManager: IProjectFilesManager) {
private $projectFilesManager: IProjectFilesManager,
private $pluginsService: IPluginsService) {
this.dependencies = Object.create(null);
this.devDependencies = this.getDevDependencies(projectDir);
}
Expand All @@ -40,13 +41,11 @@ export class DestCopy implements IBroccoliPlugin {
let fileContent = require(packageJsonFilePath);

if(!this.devDependencies[fileContent.name]) { // Don't flatten dev dependencies
let isPlugin = fileContent.nativescript;

let currentDependency = {
name: fileContent.name,
version: fileContent.version,
directory: path.dirname(packageJsonFilePath),
isPlugin: isPlugin
nativescript: fileContent.nativescript
};

let addedDependency = this.dependencies[currentDependency.name];
Expand All @@ -72,8 +71,9 @@ export class DestCopy implements IBroccoliPlugin {
_.each(this.dependencies, dependency => {
shelljs.cp("-Rf", dependency.directory, this.outputRoot);
shelljs.rm("-rf", path.join(this.outputRoot, dependency.name, "node_modules"));
if(dependency.isPlugin) {
this.$projectFilesManager.processPlatformSpecificFiles(path.join(this.outputRoot, dependency.name), platform).wait();
let isPlugin = !!dependency.nativescript;
if(isPlugin) {
this.$pluginsService.prepare(dependency).wait();
shelljs.rm("-rf", path.join(this.outputRoot, dependency.name, "platforms"));
}
});
Expand Down