From a3d468e54dd3de51c2a0c788c1c8962d1c6abfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 9 Jul 2019 10:32:30 +0200 Subject: [PATCH] chore: remove unstable `init --template` shorthand support (#495) --- 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 3cb120a6c..27fc9c44d 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 9fdef32ac..42ff684a9 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; -}