From 9706a70151119478872b94978f6046a91358eb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 7 Jul 2019 10:47:41 +0200 Subject: [PATCH] chore: remove unstable init --template shorthand support --- docs/commands.md | 1 - docs/init.md | 1 - .../init/__tests__/templateName.test.js | 22 ------------- .../cli/src/commands/init/templateName.js | 31 ++----------------- 4 files changed, 2 insertions(+), 53 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index b01ed8a06..4e29ed00d 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -139,7 +139,6 @@ Uses a custom directory instead of ``. 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` diff --git a/docs/init.md b/docs/init.md index 166473ff6..74971ac58 100644 --- a/docs/init.md +++ b/docs/init.md @@ -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`. diff --git a/packages/cli/src/commands/init/__tests__/templateName.test.js b/packages/cli/src/commands/init/__tests__/templateName.test.js index db972581b..e460622f1 100644 --- a/packages/cli/src/commands/init/__tests__/templateName.test.js +++ b/packages/cli/src/commands/init/__tests__/templateName.test.js @@ -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, diff --git a/packages/cli/src/commands/init/templateName.js b/packages/cli/src/commands/init/templateName.js index d2b8b7e98..5dcf37d0f 100644 --- a/packages/cli/src/commands/init/templateName.js +++ b/packages/cli/src/commands/init/templateName.js @@ -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; -}