Skip to content

Commit

Permalink
Merge pull request #4011 from NativeScript/vladimirov/improve-prepare
Browse files Browse the repository at this point in the history
fix: prepare node_modules only once
  • Loading branch information
Dimitar Tachev authored Oct 10, 2018
2 parents 2b5416c + 27b61e8 commit 0b5d097
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ interface INodeModulesData extends IPlatform, IProjectDataComposition, IAppFiles
interface INodeModulesBuilderData {
nodeModulesData: INodeModulesData;
release: boolean;
copyNodeModules?: boolean;
}

interface INodeModulesBuilder {
Expand Down
3 changes: 2 additions & 1 deletion lib/services/prepare-platform-js-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export class PreparePlatformJSService extends PreparePlatformService implements
appFilesUpdaterOptions,
projectFilesConfig
},
release: appFilesUpdaterOptions.release
release: appFilesUpdaterOptions.release,
copyNodeModules: true
});
} catch (error) {
this.$logger.debug(error);
Expand Down
19 changes: 14 additions & 5 deletions lib/tools/node-modules/node-modules-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,33 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
) { }

public async prepareNodeModules(opts: INodeModulesBuilderData): Promise<void> {
const productionDependencies = this.initialPrepareNodeModules(opts);
const productionDependencies = this.intialPrepareNodeModulesIfRequired(opts);
const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare);
await npmPluginPrepare.preparePlugins(productionDependencies, opts.nodeModulesData.platform, opts.nodeModulesData.projectData, opts.nodeModulesData.projectFilesConfig);
}

public async prepareJSNodeModules(opts: INodeModulesBuilderData): Promise<void> {
const productionDependencies = this.initialPrepareNodeModules(opts);
const productionDependencies = this.intialPrepareNodeModulesIfRequired(opts);
const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare);
await npmPluginPrepare.prepareJSPlugins(productionDependencies, opts.nodeModulesData.platform, opts.nodeModulesData.projectData, opts.nodeModulesData.projectFilesConfig);
}

private intialPrepareNodeModulesIfRequired(opts: INodeModulesBuilderData): IDependencyData[] {
const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(opts.nodeModulesData.projectData.projectDir);

if (opts.copyNodeModules) {
this.initialPrepareNodeModules(opts, productionDependencies);
}

return productionDependencies;
}

public cleanNodeModules(absoluteOutputPath: string): void {
shelljs.rm("-rf", absoluteOutputPath);
}

private initialPrepareNodeModules(opts: INodeModulesBuilderData): IDependencyData[] {
private initialPrepareNodeModules(opts: INodeModulesBuilderData, productionDependencies: IDependencyData[]): IDependencyData[] {
const { nodeModulesData, release } = opts;
const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(nodeModulesData.projectData.projectDir);

if (!this.$fs.exists(nodeModulesData.absoluteOutputPath)) {
// Force copying if the destination doesn't exist.
Expand All @@ -36,7 +45,7 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
const tnsModulesCopy: TnsModulesCopy = this.$injector.resolve(TnsModulesCopy, {
outputRoot: nodeModulesData.absoluteOutputPath
});
tnsModulesCopy.copyModules({ dependencies: productionDependencies, release});
tnsModulesCopy.copyModules({ dependencies: productionDependencies, release });
} else {
this.cleanNodeModules(nodeModulesData.absoluteOutputPath);
}
Expand Down

0 comments on commit 0b5d097

Please sign in to comment.