From f276deeeeb8224210d83b2b05cc8f5a0275a6ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 13 Mar 2024 20:10:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20sdk:=20fix=20nextjs=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/sdks/nextjs/package.json | 6 ++--- packages/sdks/nextjs/tsup.config.ts | 2 +- sh/move-sdks-to-examples | 11 ++++++++ tooling/publish/publish.ts | 40 +++++++++++++++++------------ 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100755 sh/move-sdks-to-examples diff --git a/packages/sdks/nextjs/package.json b/packages/sdks/nextjs/package.json index 4a3957d8..2dd1293c 100644 --- a/packages/sdks/nextjs/package.json +++ b/packages/sdks/nextjs/package.json @@ -12,9 +12,9 @@ "@openpanel/web": "workspace:*" }, "peerDependencies": { - "next": "^14.0.0", - "react": "^18.2.0", - "react-dom": "^18.2.0" + "next": "^12.0.0 || ^13.0.0 || ^14.0.0", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" }, "devDependencies": { "@openpanel/eslint-config": "workspace:*", diff --git a/packages/sdks/nextjs/tsup.config.ts b/packages/sdks/nextjs/tsup.config.ts index befb1075..346bb9a5 100644 --- a/packages/sdks/nextjs/tsup.config.ts +++ b/packages/sdks/nextjs/tsup.config.ts @@ -5,5 +5,5 @@ import config from '@openpanel/tsconfig/tsup.config.json' assert { type: 'json' export default defineConfig({ ...(config as any), entry: ['index.tsx'], - format: ['cjs', 'esm'], + external: ['react', 'next'], }); diff --git a/sh/move-sdks-to-examples b/sh/move-sdks-to-examples new file mode 100755 index 00000000..bca1729e --- /dev/null +++ b/sh/move-sdks-to-examples @@ -0,0 +1,11 @@ +#!/bin/bash + +# nextjs-13-pages +rm -rf ../openpanel-examples/nextjs-13-pages/node_modules/@openpanel/nextjs && cp -R packages/sdks/nextjs ../openpanel-examples/nextjs-13-pages/node_modules/@openpanel/nextjs +rm -rf ../openpanel-examples/nextjs-13-pages/node_modules/@openpanel/web && cp -R packages/sdks/nextjs ../openpanel-examples/nextjs-13-pages/node_modules/@openpanel/web +# nextjs-app-dir +rm -rf ../openpanel-examples/nextjs-app-dir/node_modules/@openpanel/nextjs && cp -R packages/sdks/nextjs ../openpanel-examples/nextjs-app-dir/node_modules/@openpanel/nextjs +rm -rf ../openpanel-examples/nextjs-app-dir/node_modules/@openpanel/web && cp -R packages/sdks/nextjs ../openpanel-examples/nextjs-app-dir/node_modules/@openpanel/web +# expo-app +rm -rf ../openpanel-examples/expo-app/node_modules/@openpanel/react-native && cp -R packages/sdks/react-native ../openpanel-examples/expo-app/node_modules/@openpanel/react-native +rm -rf ../openpanel-examples/expo-app/node_modules/@openpanel/sdk && cp -R packages/sdks/sdk ../openpanel-examples/expo-app/node_modules/@openpanel/sdk \ No newline at end of file diff --git a/tooling/publish/publish.ts b/tooling/publish/publish.ts index 8bb65a91..9206e9af 100644 --- a/tooling/publish/publish.ts +++ b/tooling/publish/publish.ts @@ -40,16 +40,19 @@ function checkUncommittedChanges() { } function main() { - checkUncommittedChanges(); - const args = arg({ // Types '--version': String, '--test': Boolean, + '--skip-git': Boolean, // Aliases '-v': '--version', }); + if (!args['--skip-git']) { + checkUncommittedChanges(); + } + const version = args['--version']; const test = args['--test']; @@ -57,22 +60,27 @@ function main() { return console.error('Version is not valid'); } - const properties = { - private: false, - version, - type: 'module', - main: './dist/index.js', - module: './dist/index.mjs', - types: './dist/index.d.ts', - files: ['dist'], - exports: { - import: './dist/index.js', - require: './dist/index.cjs', - }, - }; - try { for (const name of sdkPackages) { + const properties: Record = { + private: false, + version, + type: 'module', + main: './dist/index.js', + module: './dist/index.mjs', + types: './dist/index.d.ts', + files: ['dist'], + exports: { + import: './dist/index.js', + require: './dist/index.cjs', + }, + }; + + // Not sure if I even should have type: module for any sdk + if (name === 'nextjs') { + delete properties.type; + } + const pkgJson = require( workspacePath(`./packages/sdks/${name}/package.json`) );