Skip to content

Commit

Permalink
Fix name and version issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Dec 14, 2021
1 parent d23051a commit 26f9ac8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/Examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import tar from 'tar';
import terminalLink from 'terminal-link';
import { promisify } from 'util';

import { sanitizeNpmPackageName } from './Template';
import { createFileTransform, createEntryResolver } from './createFileTransform';

// @ts-ignore
Expand Down Expand Up @@ -241,7 +242,6 @@ function getScriptsForProject(projectRoot: string): Record<string, string> {
}

export async function appendScriptsAsync(projectRoot: string): Promise<void> {
// Copy our default `.gitignore` if the application did not provide one
const packageJsonPath = path.join(projectRoot, 'package.json');
if (fs.existsSync(packageJsonPath)) {
let packageFile = new JsonFile(packageJsonPath);
Expand All @@ -254,11 +254,15 @@ export async function appendScriptsAsync(projectRoot: string): Promise<void> {
// Existing scripts have higher priority
...((packageJson.scripts || {}) as JSONObject),
},
// These are metadata fields related to the template package, let's remove them from the package.json.
// A good place to start
version: '1.0.0',
// Adding `private` stops npm from complaining about missing `name` and `version` fields.
// We don't add a `name` field because it also exists in `app.json`.
private: true,
};

// name and version are required for yarn workspaces (monorepos)
packageJson.name = sanitizeNpmPackageName(path.basename(projectRoot));
await packageFile.writeAsync(packageJson);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export async function extractAndPrepareTemplateAppAsync(projectRoot: string) {
// A good place to start
packageJson.version = '1.0.0';
packageJson.private = true;
delete packageJson.name;
delete packageJson.version;
delete packageJson.description;
delete packageJson.tags;
delete packageJson.repository;
Expand All @@ -66,7 +64,7 @@ export async function extractAndPrepareTemplateAppAsync(projectRoot: string) {
return projectRoot;
}

function sanitizeNpmPackageName(name: string): string {
export function sanitizeNpmPackageName(name: string): string {
// https://github.com/npm/validate-npm-package-name/#naming-rules
return (
applyKnownNpmPackageNameRules(name) ||
Expand Down

0 comments on commit 26f9ac8

Please sign in to comment.