Skip to content

Commit 7c4f851

Browse files
committed
PR comments
1 parent 47f782a commit 7c4f851

9 files changed

+50
-38
lines changed

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const VERSION_STRING = "version";
116116
export const INSPECTOR_CACHE_DIRNAME = "ios-inspector";
117117
export const POST_INSTALL_COMMAND_NAME = "post-install-cli";
118118
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = "When producing a release build, you need to specify all --key-store-* options.";
119+
export const CACACHE_DIRECTORY_NAME = "_cacache";
119120

120121
export class DebugCommandErrors {
121122
public static UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR = "The options --for-device and --emulator cannot be used simultaneously. Please use only one of them.";

lib/definitions/pacote-service.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare global {
1515
* @param packageName The name of the package
1616
* @param destinationDirectory The path to directory where the downloaded tarball will be extracted.
1717
*/
18-
downloadAndExtract(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise<void>;
18+
extractPackage(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise<void>;
1919
}
2020

2121
interface IPacoteBaseOptions {
@@ -32,8 +32,6 @@ declare global {
3232
fullMetadata?: boolean;
3333
}
3434

35-
interface IPacoteTarballStreamOptions extends IPacoteBaseOptions { }
36-
3735
interface IPacoteExtractOptions {
3836
filter?: (path: string, stat: tar.FileStat) => boolean;
3937
}

lib/definitions/pacote.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare module "pacote" {
55
export var tarball: IPacoteTarballResult;
66

77
interface IPacoteTarballResult {
8-
stream: (packageName: string, options: IPacoteTarballStreamOptions) => IPacoteTarballStreamResult;
8+
stream: (packageName: string, options: IPacoteBaseOptions) => IPacoteTarballStreamResult;
99
toFile: (packageName: string) => IPacoteTarballFileResult;
1010
}
1111

lib/definitions/project.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ interface ITemplateData {
239239
templatePackageJsonContent: ITemplatePackageJsonContent;
240240
}
241241

242-
interface ITemplatePackageJsonContent {
243-
name: string;
244-
version: string;
242+
interface ITemplatePackageJsonContent extends IBasePluginData {
245243
dependencies: IStringDictionary;
246244
devDependencies: IStringDictionary;
247245
nativescript?: {

lib/node-package-manager.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22
import { exported, cache } from "./common/decorators";
33
import { isInteractive } from "./common/helpers";
4+
import { CACACHE_DIRECTORY_NAME } from "./constants";
45

56
export class NodePackageManager implements INodePackageManager {
67
private static SCOPED_DEPENDENCY_REGEXP = /^(@.+?)(?:@(.+?))?$/;
@@ -131,7 +132,7 @@ export class NodePackageManager implements INodePackageManager {
131132
@cache()
132133
public async getCachePath(): Promise<string> {
133134
const cachePath = await this.$childProcess.exec(`npm config get cache`);
134-
return path.join(cachePath.trim(), "_cacache");
135+
return path.join(cachePath.trim(), CACACHE_DIRECTORY_NAME);
135136
}
136137

137138
private getNpmExecutableName(): string {

lib/services/pacote-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export class PacoteService implements IPacoteService {
1414
return pacote.manifest(packageName, manifestOptions);
1515
}
1616

17-
public async downloadAndExtract(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise<void> {
17+
public async extractPackage(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise<void> {
18+
// strip: Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped. More info: https://github.com/npm/node-tar/blob/e89c4d37519b1c20133a9f49d5f6b85fa34c203b/README.md
19+
// C: Create an archive
1820
const extractOptions = { strip: 1, C: destinationDirectory };
1921
if (options) {
2022
_.extend(extractOptions, options);

lib/services/project-service.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class ProjectService implements IProjectService {
6767
await this.ensureAppResourcesExist(projectDir);
6868

6969
if (!(templatePackageJsonContent && templatePackageJsonContent.dependencies && templatePackageJsonContent.dependencies[constants.TNS_CORE_MODULES_NAME])) {
70-
await this.$npmInstallationManager.install(constants.TNS_CORE_MODULES_NAME, projectDir, { dependencyType: "save" });
70+
await this.addTnsCoreModules(projectDir);
7171
}
7272

7373
if (templateVersion === constants.TemplateVersions.v1) {
@@ -123,7 +123,7 @@ export class ProjectService implements IProjectService {
123123
this.$fs.createDirectory(path.join(projectDir, "platforms"));
124124
break;
125125
case constants.TemplateVersions.v2:
126-
await this.$pacoteService.downloadAndExtract(templateData.templateName, projectDir);
126+
await this.$pacoteService.extractPackage(templateData.templateName, projectDir);
127127
break;
128128
default:
129129
this.$errors.failWithoutHelp(format(constants.ProjectTemplateErrors.InvalidTemplateVersionStringFormat, templateData.templateName, templateData.templateVersion));
@@ -140,7 +140,7 @@ export class ProjectService implements IProjectService {
140140
this.$fs.createDirectory(appResourcesDestinationPath);
141141

142142
// the template installed doesn't have App_Resources -> get from a default template
143-
await this.$pacoteService.downloadAndExtract(constants.RESERVED_TEMPLATE_NAMES["default"], appPath, { filter: (name: string, entry: any) => entry.path.indexOf(constants.APP_RESOURCES_FOLDER_NAME) !== -1 });
143+
await this.$pacoteService.extractPackage(constants.RESERVED_TEMPLATE_NAMES["default"], appPath, { filter: (name: string, entry: any) => entry.path.indexOf(constants.APP_RESOURCES_FOLDER_NAME) !== -1 });
144144
}
145145
}
146146

@@ -228,5 +228,15 @@ export class ProjectService implements IProjectService {
228228
private setAppId(projectDir: string, projectId: string): void {
229229
this.$projectDataService.setNSValue(projectDir, "id", projectId);
230230
}
231+
232+
private async addTnsCoreModules(projectDir: string): Promise<void> {
233+
const projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
234+
const packageJsonData = this.$fs.readJson(projectFilePath);
235+
236+
const version = await this.$npmInstallationManager.getLatestCompatibleVersion(constants.TNS_CORE_MODULES_NAME);
237+
packageJsonData.dependencies[constants.TNS_CORE_MODULES_NAME] = version;
238+
239+
this.$fs.writeJson(projectFilePath, packageJsonData);
240+
}
231241
}
232242
$injector.register("projectService", ProjectService);

npm-shrinkwrap.json

+27-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"mobile"
3131
],
3232
"dependencies": {
33-
"@types/tar": "4.0.0",
3433
"byline": "4.2.1",
3534
"chalk": "1.1.0",
3635
"chokidar": "1.7.0",
@@ -97,6 +96,7 @@
9796
"@types/semver": "^5.3.31",
9897
"@types/sinon": "4.0.0",
9998
"@types/source-map": "0.5.0",
99+
"@types/tar": "4.0.0",
100100
"@types/universal-analytics": "0.4.1",
101101
"@types/ws": "4.0.1",
102102
"@types/xml2js": "^0.4.2",

0 commit comments

Comments
 (0)