Skip to content

chore: remove unstable init --template shorthand support #495

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
Jul 9, 2019
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: 0 additions & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ Uses a custom directory instead of `<projectName>`.
Uses a custom template. Accepts following template sources:

- an npm package name
- a shorthand name for packages prefixed with `react-native-template-`
- an absolute path to a local directory
- an absolute path to a tarball created using `npm pack`

Expand Down
1 change: 0 additions & 1 deletion docs/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ npx react-native@${VERSION} init ProjectName
In following examples `TEMPLATE_NAME` can be either:

- Full package name, eg. `react-native-template-typescript`.
- Shorthand name of template, eg. `typescript`.
- Absolute path to directory containing template, eg. `file:///Users/username/project/some-template`.
- Absolute path to a tarball created using `npm pack`.

Expand Down
22 changes: 0 additions & 22 deletions packages/cli/src/commands/init/__tests__/templateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,6 @@ test('supports file protocol with absolute path', async () => {
});
});

test('supports shorthand templates', async () => {
const templateName = 'typescript';
(fetch: any).mockImplementationOnce(() => {
return Promise.resolve(`{"name": "react-native-template-${templateName}"}`);
});
expect(await processTemplateName(templateName)).toEqual({
uri: `react-native-template-${templateName}`,
name: `react-native-template-${templateName}`,
});
});

test('supports not-found shorthand templates', async () => {
const templateName = 'typescriptz';
(fetch: any).mockImplementationOnce(() => {
return Promise.resolve('Not found');
});
expect(await processTemplateName(templateName)).toEqual({
uri: templateName,
name: templateName,
});
});

test('supports npm packages as template names', async () => {
expect(await processTemplateName(RN_NPM_PACKAGE)).toEqual({
uri: RN_NPM_PACKAGE,
Expand Down
31 changes: 2 additions & 29 deletions packages/cli/src/commands/init/templateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,8 @@ export async function processTemplateName(templateName: string) {
return handleVersionedPackage(templateName);
}

const name = await tryTemplateShorthand(templateName);

return {
uri: name,
name,
uri: templateName,
name: templateName,
};
}

/**
* `init` may be invoked with a shorthand like `--template typescript`
* which should resolve to `react-native-template-typescript` package.
* To support that, we query npm registry if a package like this exists, if not
* we return the original name without a change.
*/
async function tryTemplateShorthand(templateName: string) {
if (templateName.match(FILE_PROTOCOL) || templateName.match(HTTP_PROTOCOL)) {
return templateName;
}
try {
const reactNativeTemplatePackage = `react-native-template-${templateName}`;
const response = await fetch(
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/latest`,
);

if (JSON.parse(response).name) {
return reactNativeTemplatePackage;
}
} catch (e) {
// we expect this to fail when `file://` protocol or regular module is passed
}
return templateName;
}