Content-Length: 346580 | pFad | http://github.com/NativeScript/nativescript-cli/pull/5517/files

C6 feat: default template version based on cli major by janoshrubos · Pull Request #5517 · NativeScript/nativescript-cli · GitHub
Skip to content
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

feat: default template version based on cli major #5517

Merged
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
35 changes: 29 additions & 6 deletions lib/services/project-templates-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";
import * as semver from "semver";
import * as constants from "../constants";
import { performanceLog } from "../common/decorators";
import {
Expand All @@ -9,6 +10,7 @@ import {
import {
IPackageInstallationManager,
INodePackageManager,
IStaticConfig,
} from "../declarations";
import {
IFileSystem,
Expand All @@ -26,7 +28,8 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
private $logger: ILogger,
private $packageInstallationManager: IPackageInstallationManager,
private $pacoteService: IPacoteService,
private $packageManager: INodePackageManager
private $packageManager: INodePackageManager,
private $staticConfig: IStaticConfig
) {}

@performanceLog()
Expand All @@ -45,11 +48,11 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
constants.RESERVED_TEMPLATE_NAMES[templateNameParts.name] ||
templateNameParts.name;

const version =
templateNameParts.version ||
(await this.$packageInstallationManager.getLatestCompatibleVersionSafe(
templateValue
));
const version = await this.getDesiredVersion(
templateValue,
templateNameParts.version
);

const fullTemplateName = await this.$packageManager.getPackageFullName({
name: templateValue,
version: version,
Expand Down Expand Up @@ -116,5 +119,25 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
);
}
}

private async getDesiredVersion(
templateName: string,
defaultVersion?: string
) {
if (defaultVersion) {
return defaultVersion;
}

try {
const cliMajorVersion = semver.parse(
semver.coerce(this.$staticConfig.version)
).major;
return `^${cliMajorVersion}.0.0`;
} catch (err) {
return this.$packageInstallationManager.getLatestCompatibleVersionSafe(
templateName
);
}
}
}
injector.register("projectTemplatesService", ProjectTemplatesService);
7 changes: 2 additions & 5 deletions test/project-templates-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { IAnalyticsService, IFileSystem } from "../lib/common/declarations";
import { IEventActionData } from "../lib/common/definitions/google-analytics";

const nativeScriptValidatedTemplatePath = "nsValidatedTemplatePath";
const compatibleTemplateVersion = "1.2.3";

function createTestInjector(
configuration: {
Expand All @@ -33,6 +32,7 @@ function createTestInjector(
exists: (pathToCheck: string) => false,
readJson: (pathToFile: string) => configuration.packageJsonContent || {},
});
injector.register("staticConfig", { version: "8.0.0" });

class NpmStub extends stubs.NodePackageManagerStub {
public async install(
Expand Down Expand Up @@ -70,9 +70,6 @@ function createTestInjector(

return Promise.resolve(nativeScriptValidatedTemplatePath);
}
async getLatestCompatibleVersionSafe(packageName: string): Promise<string> {
return compatibleTemplateVersion;
}
}

injector.register("packageInstallationManager", NpmInstallationManagerStub);
Expand Down Expand Up @@ -275,7 +272,7 @@ describe("project-templates-service", () => {
{
name: "is correct when scoped package name without version is passed",
templateName: "@nativescript/vue-template",
expectedVersion: compatibleTemplateVersion,
expectedVersion: "^8.0.0",
expectedTemplateName: "@nativescript/vue-template",
},
{
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/nativescript-cli/pull/5517/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy