Skip to content

Add a --bundle option that disables node_modules -> tns_modules update. #1671

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
Apr 8, 2016
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
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface IOptions extends ICommonOptions {
keyStorePath: string;
linkTo: string;
ng: boolean;
bundle: boolean;
platformTemplate: string;
port: Number;
production: boolean;
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
baseConfig: { type: OptionType.String },
platformTemplate: { type: OptionType.String },
ng: {type: OptionType.Boolean },
bundle: {type: OptionType.Boolean },
all: {type: OptionType.Boolean }
},
path.join($hostInfo.isWindows ? process.env.AppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
Expand Down
9 changes: 7 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,16 @@ export class PlatformService implements IPlatformService {

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

// Process node_modules folder
let appDir = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
try {
let tnsModulesDestinationPath = path.join(appDir, constants.TNS_MODULES_FOLDER_NAME);
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
if (!this.$options.bundle) {
// Process node_modules folder
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
} else {
// Clean target node_modules folder. Not needed when bundling.
this.$broccoliBuilder.cleanNodeModules(tnsModulesDestinationPath, platform);
}
} catch(error) {
this.$logger.debug(error);
shell.rm("-rf", appDir);
Expand Down
3 changes: 2 additions & 1 deletion lib/tools/broccoli/broccoli.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ interface BroccoliNode {
interface IBroccoliBuilder {
getChangedNodeModules(outputPath: string, platform: string, lastModifiedTime?: Date): IFuture<any>;
prepareNodeModules(outputPath: string, platform: string, lastModifiedTime?: Date): IFuture<void>;
cleanNodeModules(outputPath: string, platform: string): void;
}

interface IDiffResult {
Expand All @@ -169,4 +170,4 @@ interface IBroccoliPlugin {

interface INodeModulesTree {
makeNodeModulesTree(absoluteOutputPath: string, projectDir: string): any;
}
}
10 changes: 10 additions & 0 deletions lib/tools/broccoli/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"use strict";

import * as constants from "../../../lib/constants";
import * as fs from "fs";
import * as path from "path";
import * as shelljs from "shelljs";
import Future = require("fibers/future");
import * as destCopyLib from "./node-modules-dest-copy";
import * as fiberBootstrap from "../../common/fiber-bootstrap";
Expand Down Expand Up @@ -112,6 +114,10 @@ export class Builder implements IBroccoliBuilder {

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

}).future<void>()();
}

public cleanNodeModules(absoluteOutputPath: string, platform: string): void {
shelljs.rm("-rf", absoluteOutputPath);
}
}
$injector.register("broccoliBuilder", Builder);
22 changes: 22 additions & 0 deletions test/npm-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ describe("Npm support tests", () => {
let scopedDependencyPath = path.join(tnsModulesFolderPath, "@reactivex", "rxjs");
assert.isTrue(fs.exists(scopedDependencyPath).wait());
});

it("Ensures that tns_modules absent when bundling", () => {
let fs = testInjector.resolve("fs");
let options = testInjector.resolve("options");
let tnsModulesFolderPath = path.join(appDestinationFolderPath, "app", "tns_modules");

try {
options.bundle = false;
preparePlatform(testInjector).wait();
assert.isTrue(fs.exists(tnsModulesFolderPath).wait(), "tns_modules created first");

options.bundle = true;
preparePlatform(testInjector).wait();
assert.isFalse(fs.exists(tnsModulesFolderPath).wait(), "tns_modules deleted when bundling");

options.bundle = false;
preparePlatform(testInjector).wait();
assert.isTrue(fs.exists(tnsModulesFolderPath).wait(), "tns_modules recreated");
} finally {
options.bundle = false;
}
});
});

describe("Flatten npm modules tests", () => {
Expand Down