From f7732ed4fdb2d0a19315a39a748dbb86c0318b3c Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 10 Jun 2021 04:44:18 -0700 Subject: [PATCH] Insert a proper flipper-plugin version Summary: `flipper-pkg init` would always introduce `flipper-plugin` peer with version `latest`. Since that can never be checked against the current flipper version, it always generated a warning. Updated the init process to take the version the plugin was generated with as base version instead. Note that in the test the version will always display as 0.0.0, will double check after release that the proper version will show up when running from npx, but don't see a reason why not (famous last words) Reviewed By: nikoant, priteshrnandgaonkar Differential Revision: D28992531 fbshipit-source-id: c32aad1650f575f790c2e04d089104b7a616d26f --- desktop/pkg/{jestconfig.json => jest.config.json} | 1 + desktop/pkg/src/__tests__/runInit.node.ts | 8 ++------ desktop/pkg/src/commands/init.ts | 7 +++++++ desktop/pkg/templates/device-plugin/package.json.template | 4 +--- desktop/pkg/templates/plugin/package.json.template | 4 +--- docs/tutorial/js-setup.mdx | 5 ++++- 6 files changed, 16 insertions(+), 13 deletions(-) rename desktop/pkg/{jestconfig.json => jest.config.json} (90%) diff --git a/desktop/pkg/jestconfig.json b/desktop/pkg/jest.config.json similarity index 90% rename from desktop/pkg/jestconfig.json rename to desktop/pkg/jest.config.json index ea34bfc7e..6cd00eb00 100644 --- a/desktop/pkg/jestconfig.json +++ b/desktop/pkg/jest.config.json @@ -2,6 +2,7 @@ "transform": { "^.+\\.tsx?$": "ts-jest" }, + "testEnvironment": "node", "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "testPathIgnorePatterns": [ "\/node_modules\/", diff --git a/desktop/pkg/src/__tests__/runInit.node.ts b/desktop/pkg/src/__tests__/runInit.node.ts index b42da7b2b..bda57996c 100644 --- a/desktop/pkg/src/__tests__/runInit.node.ts +++ b/desktop/pkg/src/__tests__/runInit.node.ts @@ -80,8 +80,7 @@ test('It generates the correct files for client plugin', async () => { \\"test\\": \\"jest --no-watchman\\" }, \\"peerDependencies\\": { - \\"flipper\\": \\"latest\\", - \\"flipper-plugin\\": \\"latest\\", + \\"flipper-plugin\\": \\"^0.0.0\\", \\"antd\\": \\"latest\\" }, \\"devDependencies\\": { @@ -92,7 +91,6 @@ test('It generates the correct files for client plugin', async () => { \\"@types/react\\": \\"latest\\", \\"@types/react-dom\\": \\"latest\\", \\"antd\\": \\"latest\\", - \\"flipper\\": \\"latest\\", \\"flipper-plugin\\": \\"latest\\", \\"flipper-pkg\\": \\"latest\\", \\"jest\\": \\"latest\\", @@ -258,8 +256,7 @@ test('It generates the correct files for device plugin', async () => { \\"test\\": \\"jest --no-watchman\\" }, \\"peerDependencies\\": { - \\"flipper\\": \\"latest\\", - \\"flipper-plugin\\": \\"latest\\", + \\"flipper-plugin\\": \\"^0.0.0\\", \\"antd\\": \\"latest\\" }, \\"devDependencies\\": { @@ -270,7 +267,6 @@ test('It generates the correct files for device plugin', async () => { \\"@types/react\\": \\"latest\\", \\"@types/react-dom\\": \\"latest\\", \\"antd\\": \\"latest\\", - \\"flipper\\": \\"latest\\", \\"flipper-plugin\\": \\"latest\\", \\"flipper-pkg\\": \\"latest\\", \\"jest\\": \\"latest\\", diff --git a/desktop/pkg/src/commands/init.ts b/desktop/pkg/src/commands/init.ts index 83ece650e..11abdbc18 100644 --- a/desktop/pkg/src/commands/init.ts +++ b/desktop/pkg/src/commands/init.ts @@ -147,6 +147,12 @@ export async function initTemplate( supportedDevices: string[] | undefined, outputDirectory: string, ) { + const flipper_version = JSON.parse( + await fs.readFile( + path.resolve(__dirname, '..', '..', 'package.json'), + 'utf-8', + ), + ).version; const packageName = getPackageNameFromId(id); const templateDir = pluginType === 'device' ? devicePluginTemplateDir : pluginTemplateDir; @@ -169,6 +175,7 @@ export async function initTemplate( .toString() .replace('{{id}}', id) .replace('{{title}}', title) + .replace('{{flipper_version}}', flipper_version) .replace( '{{supported_devices}}', JSON.stringify( diff --git a/desktop/pkg/templates/device-plugin/package.json.template b/desktop/pkg/templates/device-plugin/package.json.template index 6262b9380..313b1798a 100644 --- a/desktop/pkg/templates/device-plugin/package.json.template +++ b/desktop/pkg/templates/device-plugin/package.json.template @@ -21,8 +21,7 @@ "test": "jest --no-watchman" }, "peerDependencies": { - "flipper": "latest", - "flipper-plugin": "latest", + "flipper-plugin": "^{{flipper_version}}", "antd": "latest" }, "devDependencies": { @@ -33,7 +32,6 @@ "@types/react": "latest", "@types/react-dom": "latest", "antd": "latest", - "flipper": "latest", "flipper-plugin": "latest", "flipper-pkg": "latest", "jest": "latest", diff --git a/desktop/pkg/templates/plugin/package.json.template b/desktop/pkg/templates/plugin/package.json.template index 71234fcf9..56c59f906 100644 --- a/desktop/pkg/templates/plugin/package.json.template +++ b/desktop/pkg/templates/plugin/package.json.template @@ -20,8 +20,7 @@ "test": "jest --no-watchman" }, "peerDependencies": { - "flipper": "latest", - "flipper-plugin": "latest", + "flipper-plugin": "^{{flipper_version}}", "antd": "latest" }, "devDependencies": { @@ -32,7 +31,6 @@ "@types/react": "latest", "@types/react-dom": "latest", "antd": "latest", - "flipper": "latest", "flipper-plugin": "latest", "flipper-pkg": "latest", "jest": "latest", diff --git a/docs/tutorial/js-setup.mdx b/docs/tutorial/js-setup.mdx index 78ed3df92..2f349bab1 100644 --- a/docs/tutorial/js-setup.mdx +++ b/docs/tutorial/js-setup.mdx @@ -18,7 +18,10 @@ on the desktop side. ## Scaffolding a new Desktop plugin -A new Flipper Desktop plugin can be scaffolded by running `npx flipper-pkg init` in the directory where you want to store the plugin sources (Don't run this command inside the Flipper repository itself!). For example: +A new Flipper Desktop plugin can be scaffolded by running `npx flipper-pkg init` in the directory where you want to store the plugin sources (Don't run this command inside the Flipper repository itself!). +Before running this command, make sure Flipper is closed. + +For example: ```bash mkdir ~/FlipperPlugins