diff --git a/apps/www/next.config.mjs b/apps/www/next.config.mjs index 816488a07d..6e0d2fddb3 100644 --- a/apps/www/next.config.mjs +++ b/apps/www/next.config.mjs @@ -5,6 +5,7 @@ const nextConfig = { // Enable React strict mode. // https://nextjs.org/docs/api-reference/next.config.js/react-strict-mod reactStrictMode: true, + transpilePackages: ['@udecode/*'], // Configure domains to allow for optimized image loading. // https://nextjs.org/docs/basic-features/image-optimization#domains diff --git a/config/tsup.config.cjs b/config/tsup.config.cjs new file mode 100644 index 0000000000..e6e1e02459 --- /dev/null +++ b/config/tsup.config.cjs @@ -0,0 +1,43 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { defineConfig } from 'tsup'; + +const cwd = process.cwd(); + +const INPUT_FILE_PATH = path.join(cwd, 'src/index.ts'); +const INPUT_FILE = fs.existsSync(INPUT_FILE_PATH) + ? INPUT_FILE_PATH + : path.join(cwd, 'src/index.tsx'); + +// export default defineConfig({ +// entry: [INPUT_FILE], +// silent: true, +// format: ['cjs', 'esm'], +// outExtension: (ctx) => { +// return { js: `.${ctx.format === 'esm' ? 'es' : ctx.format}.js` }; +// }, +// outDir: 'dist', +// }); + +const { dependencies = {}, peerDependencies = {} } = JSON.parse( + fs.readFileSync(path.join(cwd, 'package.json'), 'utf8') +); + +export default defineConfig({ + clean: true, + outDir: 'dist', + sourcemap: true, + format: ['esm', 'cjs'], + entry: [INPUT_FILE], + external: [ + ...Object.keys(dependencies), + ...Object.keys(peerDependencies), + 'react-textarea-autosize', + ], + outExtension: (ctx) => { + return { js: `.${ctx.format === 'esm' ? 'es' : ctx.format}.js` }; + }, + env: { + NODE_ENV: 'production', + }, +}); diff --git a/package.json b/package.json index ef8880d03e..0af6c0ed6e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "check:install": "yarn dlx @yarnpkg/doctor@4.0.0-rc.10 --configFileName config/.ncurc.yml packages", "deps:check": "yarn dlx npm-check-updates@latest --configFileName config/.ncurc.yml --deep --mergeConfig", "deps:update": "deps:check -u", - "dev": "turbo --filter=www dev", + "dev": "concurrently \"turbo --filter=www dev\" \"node ./turborepo-watch.mjs\"", "dev:cli": "yarn workspace @udecode/plate-ui dev", "docs:build": "cd docs && yarn && yarn build", "docs:start": "cd docs && yarn && yarn start", @@ -52,12 +52,13 @@ "nuke:node_modules": "rimraf '**/node_modules'", "p:brl": "cd $INIT_CWD && barrelsby -d $INIT_CWD/src -D -l all -q -e '.*(fixture|template|spec|__tests__).*'", "p:brl:below": "cd $INIT_CWD && barrelsby -d $INIT_CWD/src -D -l below -q -e '.*(fixture|template|spec|__tests__).*'", - "p:build": "cd $INIT_CWD && yarn p:rollup && tsc", - "p:build:watch": "cd $INIT_CWD && concurrently \"yarn p:rollup -w\" \"yarn p:typecheck -w\"", + "p:build": "cd \"$INIT_CWD\" && yarn p:tsup && tsc", + "p:build:watch": "cd \"$INIT_CWD\" && concurrently \"yarn p:tsup --watch\" \"yarn p:typecheck -w\"", "p:clean": "cd $INIT_CWD && rimraf dist && jest --clear-cache", "p:lint": "eslint $INIT_CWD/src --color", "p:lint:fix": "eslint $INIT_CWD/src --color --fix", "p:rollup": "cd $INIT_CWD && rollup -c=${PROJECT_CWD}/config/rollup.config.cjs", + "p:tsup": "cd \"$INIT_CWD\" && tsup --config \"${PROJECT_CWD}\"/config/tsup.config.cjs", "p:test": "cd $INIT_CWD && jest --config=${PROJECT_CWD}/jest.config.cjs --passWithNoTests $INIT_CWD ", "p:typecheck": "cd $INIT_CWD && tsc --noEmit --emitDeclarationOnly false", "postinstall": "patch-package", @@ -176,6 +177,7 @@ "slate-test-utils": "1.3.2", "tailwindcss": "^3.3.2", "ts-jest": "^29.1.1", + "tsup": "7.2.0", "turbo": "^1.10.7", "typescript": "5.1.6" }, diff --git a/turborepo-watch.mjs b/turborepo-watch.mjs new file mode 100644 index 0000000000..c3f4f01f7d --- /dev/null +++ b/turborepo-watch.mjs @@ -0,0 +1,44 @@ +/* eslint-disable no-console */ +import { spawn } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; + +/** SETUP */ +const projectRootDirectory = process.cwd(); +const packagesDirectory = path.join(projectRootDirectory, 'packages'); + +// Only watch changes under src/ to stop infinite loops. +const srcDirectoryRegex = /^[^/]+\/src\/.*\.(?:js|ts|tsx|jsx)$/; + +function runBuildPackage(packageName) { + const commandToRun = `turbo run build --filter=./packages/${packageName}`; + const command = spawn(commandToRun, [], { + shell: true, + stdio: 'inherit', + }); + command.on('error', (err) => { + console.error(`Error running command: ${err}`); + }); +} + +/** SCRIPT START */ +console.log( + '👀 Watching packages//src/*.(js|ts|tsx|jsx) files to rebuild.' +); + +fs.watch(packagesDirectory, { recursive: true }, (eventType, filename) => { + if ( + (eventType === 'change' || eventType === 'rename') && + filename && + srcDirectoryRegex.test(filename) + ) { + const parts = filename.split('/'); + if (parts.length >= 2) { + const packageName = parts[0]; // Extract package name from the path + console.log( + `Detected ${eventType} in ${filename}. Running command for package ${packageName}:` + ); + runBuildPackage(packageName); + } + } +}); diff --git a/yarn.lock b/yarn.lock index b7c7c12944..8488ff1754 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2314,6 +2314,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-arm64@npm:0.18.20" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-arm@npm:0.17.19" @@ -2335,6 +2342,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-arm@npm:0.18.20" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/android-x64@npm:0.17.19" @@ -2356,6 +2370,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/android-x64@npm:0.18.20" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-arm64@npm:0.17.19" @@ -2377,6 +2398,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/darwin-arm64@npm:0.18.20" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/darwin-x64@npm:0.17.19" @@ -2398,6 +2426,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/darwin-x64@npm:0.18.20" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-arm64@npm:0.17.19" @@ -2419,6 +2454,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/freebsd-arm64@npm:0.18.20" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/freebsd-x64@npm:0.17.19" @@ -2440,6 +2482,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/freebsd-x64@npm:0.18.20" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm64@npm:0.17.19" @@ -2461,6 +2510,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-arm64@npm:0.18.20" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-arm@npm:0.17.19" @@ -2482,6 +2538,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-arm@npm:0.18.20" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ia32@npm:0.17.19" @@ -2503,6 +2566,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-ia32@npm:0.18.20" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-loong64@npm:0.17.19" @@ -2524,6 +2594,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-loong64@npm:0.18.20" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-mips64el@npm:0.17.19" @@ -2545,6 +2622,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-mips64el@npm:0.18.20" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-ppc64@npm:0.17.19" @@ -2566,6 +2650,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-ppc64@npm:0.18.20" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-riscv64@npm:0.17.19" @@ -2587,6 +2678,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-riscv64@npm:0.18.20" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-s390x@npm:0.17.19" @@ -2608,6 +2706,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-s390x@npm:0.18.20" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/linux-x64@npm:0.17.19" @@ -2629,6 +2734,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/linux-x64@npm:0.18.20" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/netbsd-x64@npm:0.17.19" @@ -2650,6 +2762,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/netbsd-x64@npm:0.18.20" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/openbsd-x64@npm:0.17.19" @@ -2671,6 +2790,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/openbsd-x64@npm:0.18.20" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/sunos-x64@npm:0.17.19" @@ -2692,6 +2818,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/sunos-x64@npm:0.18.20" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-arm64@npm:0.17.19" @@ -2713,6 +2846,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-arm64@npm:0.18.20" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-ia32@npm:0.17.19" @@ -2734,6 +2874,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-ia32@npm:0.18.20" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.17.19": version: 0.17.19 resolution: "@esbuild/win32-x64@npm:0.17.19" @@ -2755,6 +2902,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.18.20": + version: 0.18.20 + resolution: "@esbuild/win32-x64@npm:0.18.20" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.3.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" @@ -10841,6 +10995,83 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:^0.18.2": + version: 0.18.20 + resolution: "esbuild@npm:0.18.20" + dependencies: + "@esbuild/android-arm": "npm:0.18.20" + "@esbuild/android-arm64": "npm:0.18.20" + "@esbuild/android-x64": "npm:0.18.20" + "@esbuild/darwin-arm64": "npm:0.18.20" + "@esbuild/darwin-x64": "npm:0.18.20" + "@esbuild/freebsd-arm64": "npm:0.18.20" + "@esbuild/freebsd-x64": "npm:0.18.20" + "@esbuild/linux-arm": "npm:0.18.20" + "@esbuild/linux-arm64": "npm:0.18.20" + "@esbuild/linux-ia32": "npm:0.18.20" + "@esbuild/linux-loong64": "npm:0.18.20" + "@esbuild/linux-mips64el": "npm:0.18.20" + "@esbuild/linux-ppc64": "npm:0.18.20" + "@esbuild/linux-riscv64": "npm:0.18.20" + "@esbuild/linux-s390x": "npm:0.18.20" + "@esbuild/linux-x64": "npm:0.18.20" + "@esbuild/netbsd-x64": "npm:0.18.20" + "@esbuild/openbsd-x64": "npm:0.18.20" + "@esbuild/sunos-x64": "npm:0.18.20" + "@esbuild/win32-arm64": "npm:0.18.20" + "@esbuild/win32-ia32": "npm:0.18.20" + "@esbuild/win32-x64": "npm:0.18.20" + dependenciesMeta: + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: e8ff43647209dd6f29bbdbfbeed578f8a20763c2e5714e53d01afcf3a12bc097b03a8eb14f5f4e26965b8336e6f349978e3fa7778abc5bd2dac45544a36ca739 + languageName: node + linkType: hard + "escalade@npm:^3.1.1": version: 3.1.1 resolution: "escalade@npm:3.1.1" @@ -20205,6 +20436,7 @@ __metadata: slate-test-utils: "npm:1.3.2" tailwindcss: "npm:^3.3.2" ts-jest: "npm:^29.1.1" + tsup: "npm:7.2.0" turbo: "npm:^1.10.7" typescript: "npm:5.1.6" languageName: unknown @@ -21837,6 +22069,42 @@ __metadata: languageName: node linkType: hard +"tsup@npm:7.2.0": + version: 7.2.0 + resolution: "tsup@npm:7.2.0" + dependencies: + bundle-require: "npm:^4.0.0" + cac: "npm:^6.7.12" + chokidar: "npm:^3.5.1" + debug: "npm:^4.3.1" + esbuild: "npm:^0.18.2" + execa: "npm:^5.0.0" + globby: "npm:^11.0.3" + joycon: "npm:^3.0.1" + postcss-load-config: "npm:^4.0.1" + resolve-from: "npm:^5.0.0" + rollup: "npm:^3.2.5" + source-map: "npm:0.8.0-beta.0" + sucrase: "npm:^3.20.3" + tree-kill: "npm:^1.2.2" + peerDependencies: + "@swc/core": ^1 + postcss: ^8.4.12 + typescript: ">=4.1.0" + peerDependenciesMeta: + "@swc/core": + optional: true + postcss: + optional: true + typescript: + optional: true + bin: + tsup: dist/cli-default.js + tsup-node: dist/cli-node.js + checksum: f8bd6a05042af09d63f78e4e83bfe1ade9448f8eea8bac51f9335683f74fd827acef8510f2d061970060d7a6f697b6ca88318c411583a7a6ad07032830579474 + languageName: node + linkType: hard + "tsup@npm:^6.6.3": version: 6.7.0 resolution: "tsup@npm:6.7.0"