Skip to content

Commit

Permalink
fix: scoped runtimes, project detection, frameworkPath
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 committed Sep 4, 2020
1 parent 25edea4 commit 8805f1e
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 258 deletions.
3 changes: 2 additions & 1 deletion lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ export class CreateProjectCommand implements ICommand {
(this.$options.tsc ||
this.$options.ng ||
this.$options.vue ||
this.$options.react ||
this.$options.js) &&
this.$options.template
) {
this.$errors.failWithHelp(
"You cannot use a flavor option like --ng, --vue, --tsc and --js together with --template."
"You cannot use a flavor option like --ng, --vue, --react, --tsc and --js together with --template."
);
}

Expand Down
27 changes: 13 additions & 14 deletions lib/common/project-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";
import * as _ from "lodash";
import { IProjectHelper, IFileSystem } from "./declarations";
import { IErrors, IFileSystem, IProjectHelper } from "./declarations";
import { IOptions } from "../declarations";
import { injector } from "./yok";

Expand All @@ -9,7 +9,7 @@ export class ProjectHelper implements IProjectHelper {
private $logger: ILogger,
private $fs: IFileSystem,
private $staticConfig: Config.IStaticConfig,
// private $errors: IErrors,
private $errors: IErrors,
private $options: IOptions
) {}

Expand Down Expand Up @@ -73,19 +73,18 @@ export class ProjectHelper implements IProjectHelper {
}

private isProjectFileCorrect(projectFilePath: string): boolean {
// this is no longer correct, since we have moved the "nativescript" key out from package.json

// if (this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE) {
// try {
// const fileContent = this.$fs.readJson(projectFilePath);
// const clientSpecificData = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] && fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE].id;
// return !!clientSpecificData;
// } catch (err) {
// this.$errors.fail("The project file is corrupted. Additional technical information: %s", err);
// }
// }
try {
const fileContent = this.$fs.readText(projectFilePath);
return fileContent.includes("nativescript");
} catch (err) {
this.$errors.fail(
"The project file is corrupted. Additional technical information: %s",
err
);
}

return true;
return false;
}
}

injector.register("projectHelper", ProjectHelper);
6 changes: 3 additions & 3 deletions lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
packageName: MigrateController.typescriptPackageName,
isDev: true,
verifiedVersion: "3.9.0",
}
},
];

get verifiedPlatformVersions(): IDictionary<string> {
return {
[this.$devicePlatformsConstants.Android.toLowerCase()]: "7.0.0",
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "7.0.0",
[this.$devicePlatformsConstants.Android.toLowerCase()]: "6.5.3",
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "6.5.2",
};
}

Expand Down
44 changes: 26 additions & 18 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interface IPackageManager extends INodePackageManager {
}

interface IPerformanceService {
// Will process the data based on the command opitons (--performance flag and user-reporting setting)
// Will process the data based on the command options (--performance flag and user-reporting setting)
processExecutionData(
methodInfo: string,
startTime: number,
Expand All @@ -143,6 +143,11 @@ interface IPackageInstallationManager {
packageDir: string,
options?: INpmInstallOptions
): Promise<any>;
uninstall(
packageName: string,
packageDir: string,
options?: IDictionary<string | boolean>
): Promise<any>;
getLatestVersion(packageName: string): Promise<string>;
getNextVersion(packageName: string): Promise<string>;
getLatestCompatibleVersion(
Expand Down Expand Up @@ -344,36 +349,36 @@ interface INpmInstallCLIResult {
interface INpm5InstallCliResult {
/**
* Added dependencies. Note that whenever add a particular dependency with npm 5 it is listed inside of array with key "Added".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
added: INpm5DependencyInfo[];
/**
* Removed dependencies. Note that whenever remove a particular dependency with npm 5 it is listed inside of array with key "removed".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
removed: INpm5DependencyInfo[];
/**
* Updated dependencies. Note that whenever update a particular dependency with npm 5 it is listed inside of array with key "updated".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
updated: INpm5DependencyInfo[];
/**
* Moved dependencies. Note that whenever move a particular dependency with npm 5 it is listed inside of array with key "moved".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
moved: INpm5DependencyInfo[];
/**
* Failed dependencies. Note that whenever use npm 5 and the operation over particular dependency fail it is listed inside of array with key "failed".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
failed: INpm5DependencyInfo[];
/**
* Warnings. Note that whenever use npm 5 and the operation over particular dependency have warnings they are listed inside of array with key "warnings".
* @type {INpmDependencyUpdateInfo[]}
* @type {INpm5DependencyInfo[]}
*/
warnings: INpm5DependencyInfo[];
/**
*Time elapsed.
* Time elapsed.
* @type {Number}
*/
elapsed: Number;
Expand Down Expand Up @@ -515,7 +520,7 @@ interface IApplicationPackage {
}

interface IOpener {
open(target: string, appname: string): void;
open(target: string, appName: string): void;
}

interface IBundleString {
Expand Down Expand Up @@ -748,7 +753,7 @@ interface IITMSData {
}

/**
* Used for communicating with Xcode's iTMS Transporter tool.
* Used for communicating with Xcode iTMS Transporter tool.
*/
interface IITMSTransporterService {
validate(): Promise<void>;
Expand All @@ -766,7 +771,7 @@ interface IITMSTransporterService {
interface IAndroidToolsInfo {
/**
* Provides information about installed Android SDKs, Build Tools, Support Library
* and ANDROID_HOME environement variable.
* and ANDROID_HOME environment variable.
* @param {IProjectDir} config Object with a single property - projectDir. This is the root directory where NativeScript project is located.
* @return {IAndroidToolsInfoData} Information about installed Android Tools and SDKs.
*/
Expand Down Expand Up @@ -879,13 +884,15 @@ interface IAppDebugSocketProxyFactory extends NodeJS.EventEmitter {
removeAllProxies(): void;
}

// tslint:disable-next-line:interface-name
interface IiOSNotification extends NodeJS.EventEmitter {
getAttachRequest(appId: string, deviceId: string): string;
getReadyForAttach(appId: string): string;
getRefreshRequest(appId: string): string;
getAppRefreshStarted(appId: string): string;
}

// tslint:disable-next-line:interface-name
interface IiOSSocketRequestExecutor {
executeAttachRequest(
device: Mobile.IiOSDevice,
Expand Down Expand Up @@ -959,9 +966,9 @@ interface IVersionsService {
interface IProjectNameService {
/**
* Ensures the passed project name is valid. If the project name is not valid prompts for actions.
* @param {string} project name to be checked.
* @param {IOptions} current command options.
* @return {Promise<strng>} returns the selected name of the project.
* @param {string} projectName project name to be checked.
* @param {IOptions} validateOptions current command options.
* @return {Promise<string>} returns the selected name of the project.
*/
ensureValidName(
projectName: string,
Expand Down Expand Up @@ -997,15 +1004,15 @@ interface IXcprojService {
*/
interface IXcprojInfo {
/**
* determines whether the system needs xcproj to execute ios builds sucessfully
* determines whether the system needs xcproj to execute ios builds successfully
*/
shouldUseXcproj: boolean;
/**
* pod version string, as returned by `pod --version`
*/
cocoapodVer: string;
/**
* Xcode's version
* Xcode version
*/
xcodeVersion: IVersionData;
/**
Expand All @@ -1032,7 +1039,7 @@ interface IXcconfigService {

/**
* Merges the content of source file into destination file
* @param sourceFile The content of thes source file
* @param sourceFile The content of the source file
* @param destinationFile The content of the destination file
* @returns {Promise<void>}
*/
Expand All @@ -1046,6 +1053,7 @@ interface IBundleValidatorHelper {
/**
* Validates bundling options.
* In case when minSupportedVersion is provided, gets the current version of @nativescript/webpack from package.json and compares with the provided version.
* @param {IProjectData} projectData
* @param {string} minSupportedVersion the minimum supported version of @nativescript/webpack
* @return {void}
*/
Expand Down Expand Up @@ -1206,7 +1214,7 @@ interface IPlatformCommandHelper {
cleanPlatforms(
platforms: string[],
projectData: IProjectData,
framworkPath: string
frameworkPath: string
): Promise<void>;
removePlatforms(
platforms: string[],
Expand Down
4 changes: 3 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ interface INsConfigAndroid extends INsConfigPlaform {
discardUncaughtJsExceptions?: boolean;

enableLineBreakpoints?: boolean;

enableMultithreadedJavascript?: boolean;
}

interface INsConfig {
Expand Down Expand Up @@ -375,7 +377,7 @@ interface ITemplateData {
* In case template is v1, will be {pathToProjectDir}/node_modules/{templateName}.
* In case template is v2, will be null.
*/
templatePath: string;
// templatePath: string;
/**
* The whole content of package.json file
*/
Expand Down
10 changes: 7 additions & 3 deletions lib/helpers/platform-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
platform.toLowerCase()
);
this.$fs.deleteDirectory(platformDir);
this.$projectDataService.removeNSProperty(
projectData.projectDir,
platformData.frameworkPackageName
await this.$packageInstallationManager.uninstall(
platformData.frameworkPackageName,
projectData.projectDir
);
// this.$projectDataService.removeNSProperty(
// projectData.projectDir,
// platformData.frameworkPackageName
// );

this.$logger.info(`Platform ${platform} successfully removed.`);
} catch (err) {
Expand Down
29 changes: 25 additions & 4 deletions lib/package-installation-manager.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import * as path from "path";
const semver = require("semver");
import * as constants from "./constants";
import {
INpmInstallOptions,
INpmInstallResultInfo,
IPackageInstallationManager,
IPackageManager,
IStaticConfig,
INpmInstallOptions,
INpmInstallResultInfo,
} from "./declarations";
import { IProjectDataService } from "./definitions/project";
import {
IChildProcess,
ISettingsService,
IDictionary,
IFileSystem,
ISettingsService,
} from "./common/declarations";
import { injector } from "./common/yok";

const semver = require("semver");

export class PackageInstallationManager implements IPackageInstallationManager {
constructor(
private $packageManager: IPackageManager,
Expand Down Expand Up @@ -151,6 +153,24 @@ export class PackageInstallationManager implements IPackageInstallationManager {
}
}

public async uninstall(
packageToUninstall: string,
projectDir: string,
opts?: IDictionary<string | boolean>
): Promise<any> {
try {
return await this.$packageManager.uninstall(
packageToUninstall,
opts,
projectDir
);
} catch (error) {
this.$logger.debug(error);

throw error;
}
}

public async getInspectorFromCache(
inspectorNpmPackageName: string,
projectDir: string
Expand Down Expand Up @@ -308,4 +328,5 @@ export class PackageInstallationManager implements IPackageInstallationManager {
return data[version];
}
}

injector.register("packageInstallationManager", PackageInstallationManager);
9 changes: 7 additions & 2 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export class ProjectData implements IProjectData {
},
{
type: constants.ProjectTypes.NgFlavorName,
requiredDependencies: ["@angular/core", "nativescript-angular"],
requiredDependencies: [
"@angular/core",
"nativescript-angular",
"@nativescript/angular",
],
},
{
type: constants.ProjectTypes.VueFlavorName,
Expand Down Expand Up @@ -147,7 +151,7 @@ export class ProjectData implements IProjectData {
);
}

if (nsConfig) {
if (nsConfig && packageJsonData) {
this.projectDir = projectDir;
this.projectName = this.$projectHelper.sanitizeName(
path.basename(projectDir)
Expand Down Expand Up @@ -291,6 +295,7 @@ export class ProjectData implements IProjectData {
ios: config.id,
android: config.id,
};

if (config.ios && config.ios.id) {
identifier.ios = config.ios.id;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/services/marking-mode-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MARKING_MODE_NONE_CONFIRM_MSG = `Do you want to switch your app to the rec
More info about the reasons for this change can be found in the link below:
https://www.nativescript.org/blog/markingmode-none-is-official-boost-android-performance-while-avoiding-memory-issues`;

// TODO: update to work with new configs!
export class MarkingModeService implements IMarkingModeService {
constructor(
private $fs: IFileSystem,
Expand All @@ -28,6 +29,11 @@ export class MarkingModeService implements IMarkingModeService {
public async handleMarkingModeFullDeprecation(
options: IMarkingModeFullDeprecationOptions
): Promise<void> {
this.$logger.error(
"handleMarkingModeFullDeprecation has not yet been updated to the new config handling!!!!"
);
return;

const { projectDir, skipWarnings, forceSwitch } = options;
const projectData = this.$projectDataService.getProjectData(projectDir);
const innerPackageJsonPath = path.join(
Expand Down
Loading

0 comments on commit 8805f1e

Please sign in to comment.