Skip to content

Commit a534dce

Browse files
thymikeedratwas
authored andcommitted
chore: remove unstable init --template shorthand support (react-native-community#495)
1 parent 669b905 commit a534dce

File tree

4 files changed

+2
-53
lines changed

4 files changed

+2
-53
lines changed

docs/commands.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ Uses a custom directory instead of `<projectName>`.
139139
Uses a custom template. Accepts following template sources:
140140

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

docs/init.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ npx react-native@${VERSION} init ProjectName
3535
In following examples `TEMPLATE_NAME` can be either:
3636

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

packages/cli/src/commands/init/__tests__/templateName.test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,6 @@ test('supports file protocol with absolute path', async () => {
2121
});
2222
});
2323

24-
test('supports shorthand templates', async () => {
25-
const templateName = 'typescript';
26-
(fetch: any).mockImplementationOnce(() => {
27-
return Promise.resolve(`{"name": "react-native-template-${templateName}"}`);
28-
});
29-
expect(await processTemplateName(templateName)).toEqual({
30-
uri: `react-native-template-${templateName}`,
31-
name: `react-native-template-${templateName}`,
32-
});
33-
});
34-
35-
test('supports not-found shorthand templates', async () => {
36-
const templateName = 'typescriptz';
37-
(fetch: any).mockImplementationOnce(() => {
38-
return Promise.resolve('Not found');
39-
});
40-
expect(await processTemplateName(templateName)).toEqual({
41-
uri: templateName,
42-
name: templateName,
43-
});
44-
});
45-
4624
test('supports npm packages as template names', async () => {
4725
expect(await processTemplateName(RN_NPM_PACKAGE)).toEqual({
4826
uri: RN_NPM_PACKAGE,

packages/cli/src/commands/init/templateName.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,8 @@ export async function processTemplateName(templateName: string) {
5757
return handleVersionedPackage(templateName);
5858
}
5959

60-
const name = await tryTemplateShorthand(templateName);
61-
6260
return {
63-
uri: name,
64-
name,
61+
uri: templateName,
62+
name: templateName,
6563
};
6664
}
67-
68-
/**
69-
* `init` may be invoked with a shorthand like `--template typescript`
70-
* which should resolve to `react-native-template-typescript` package.
71-
* To support that, we query npm registry if a package like this exists, if not
72-
* we return the original name without a change.
73-
*/
74-
async function tryTemplateShorthand(templateName: string) {
75-
if (templateName.match(FILE_PROTOCOL) || templateName.match(HTTP_PROTOCOL)) {
76-
return templateName;
77-
}
78-
try {
79-
const reactNativeTemplatePackage = `react-native-template-${templateName}`;
80-
const response = await fetch(
81-
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/latest`,
82-
);
83-
84-
if (JSON.parse(response).name) {
85-
return reactNativeTemplatePackage;
86-
}
87-
} catch (e) {
88-
// we expect this to fail when `file://` protocol or regular module is passed
89-
}
90-
return templateName;
91-
}

0 commit comments

Comments
 (0)