Skip to content

Commit 87eb145

Browse files
committed
Add a --bundle option that disables node_modules -> tns_modules update.
Delete <platform/app>/tns_modules, if present, and make sure we restore it on subsequent runs without the --bundle option set.
1 parent 112e117 commit 87eb145

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ interface IOptions extends ICommonOptions {
8080
keyStorePath: string;
8181
linkTo: string;
8282
ng: boolean;
83+
bundle: boolean;
8384
platformTemplate: string;
8485
port: Number;
8586
production: boolean;

lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3737
baseConfig: { type: OptionType.String },
3838
platformTemplate: { type: OptionType.String },
3939
ng: {type: OptionType.Boolean },
40+
bundle: {type: OptionType.Boolean },
4041
all: {type: OptionType.Boolean }
4142
},
4243
path.join($hostInfo.isWindows ? process.env.AppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),

lib/services/platform-service.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export class PlatformService implements IPlatformService {
230230
let lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath).wait() ?
231231
this.$fs.getFsStats(appDestinationDirectoryPath).wait().mtime : null;
232232

233+
233234
// Copy app folder to native project
234235
this.$fs.ensureDirectoryExists(appDestinationDirectoryPath).wait();
235236
let appSourceDirectoryPath = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
@@ -280,11 +281,16 @@ export class PlatformService implements IPlatformService {
280281

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

283-
// Process node_modules folder
284284
let appDir = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
285285
try {
286286
let tnsModulesDestinationPath = path.join(appDir, constants.TNS_MODULES_FOLDER_NAME);
287-
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
287+
if (!this.$options.bundle) {
288+
// Process node_modules folder
289+
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
290+
} else {
291+
// Clean target node_modules folder. Not needed when bundling.
292+
this.$broccoliBuilder.cleanNodeModules(tnsModulesDestinationPath, platform).wait();
293+
}
288294
} catch(error) {
289295
this.$logger.debug(error);
290296
shell.rm("-rf", appDir);

lib/tools/broccoli/broccoli.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ interface BroccoliNode {
154154
interface IBroccoliBuilder {
155155
getChangedNodeModules(outputPath: string, platform: string, lastModifiedTime?: Date): IFuture<any>;
156156
prepareNodeModules(outputPath: string, platform: string, lastModifiedTime?: Date): IFuture<void>;
157+
cleanNodeModules(outputPath: string, platform: string): IFuture<void>;
157158
}
158159

159160
interface IDiffResult {
@@ -169,4 +170,4 @@ interface IBroccoliPlugin {
169170

170171
interface INodeModulesTree {
171172
makeNodeModulesTree(absoluteOutputPath: string, projectDir: string): any;
172-
}
173+
}

lib/tools/broccoli/builder.ts

+12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"use strict";
33

44
import * as constants from "../../../lib/constants";
5+
import * as fs from "fs";
56
import * as path from "path";
7+
import * as shelljs from "shelljs";
68
import Future = require("fibers/future");
79
import * as destCopyLib from "./node-modules-dest-copy";
810
import * as fiberBootstrap from "../../common/fiber-bootstrap";
@@ -112,6 +114,10 @@ export class Builder implements IBroccoliBuilder {
112114

113115
public prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime?: Date): IFuture<void> {
114116
return (() => {
117+
if (!fs.existsSync(absoluteOutputPath)) {
118+
// Force copying if the destination doesn't exist.
119+
lastModifiedTime = null;
120+
}
115121
let nodeModules = this.getChangedNodeModules(absoluteOutputPath, platform, lastModifiedTime).wait();
116122
let destCopy = this.$injector.resolve(destCopyLib.DestCopy, {
117123
inputPath: this.$projectData.projectDir,
@@ -125,5 +131,11 @@ export class Builder implements IBroccoliBuilder {
125131

126132
}).future<void>()();
127133
}
134+
135+
public cleanNodeModules(absoluteOutputPath: string, platform: string): IFuture<void> {
136+
return (() => {
137+
shelljs.rm("-rf", absoluteOutputPath);
138+
}).future<void>()();
139+
}
128140
}
129141
$injector.register("broccoliBuilder", Builder);

0 commit comments

Comments
 (0)