From a128cc5402a8988afc73816a01b1f19a4ce11091 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Sat, 30 Jul 2022 14:52:54 +0200 Subject: [PATCH 01/17] feat: add support for `kirby serve` w/ HMR plugin --- .prettierignore | 1 + package.json | 1 + pnpm-lock.yaml | 428 +++++++++++++++++++++++----------------- src/node/cli-start.ts | 19 +- src/node/index.ts | 67 ++++++- src/node/plugins/hmr.ts | 80 ++++++++ 6 files changed, 413 insertions(+), 183 deletions(-) create mode 100644 .prettierignore create mode 100644 src/node/plugins/hmr.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/package.json b/package.json index 85e753f..42621eb 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "@types/prompts": "^2.4.0", "@vitejs/plugin-vue2": "^1.1.2", "bumpp": "^8.2.1", + "detect-package-manager": "^2.0.1", "eslint": "^8.21.0", "fast-glob": "^3.2.11", "fs-extra": "^10.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d638976..614e64e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,7 @@ specifiers: cac: ^6.7.12 chokidar: ^3.5.3 consola: ^2.15.3 + detect-package-manager: ^2.0.1 eslint: ^8.21.0 fast-glob: ^3.2.11 fs-extra: ^10.1.0 @@ -61,6 +62,7 @@ devDependencies: '@types/prompts': 2.4.0 '@vitejs/plugin-vue2': 1.1.2_2g7n65ohfqr2skd3fbvxhuubee_vite@3.0.4+vue@2.7.8 bumpp: 8.2.1 + detect-package-manager: 2.0.1 eslint: 8.21.0 fast-glob: 3.2.11 fs-extra: 10.1.0 @@ -79,7 +81,7 @@ packages: '@jridgewell/trace-mapping': 0.3.14 dev: true - /@antfu/eslint-config-basic/0.25.2_iosr3hrei2tubxveewluhu5lhy: + /@antfu/eslint-config-basic/0.25.2_jnss7dz76sznncvpyatba5hbxa: resolution: {integrity: sha512-D81jE90B7cujMmU2mKEaUcRsKRAfVX4PniEoaD0c3HiqprqghfBjuv3B6p1+tG9uJQAgLBVsK+G92Y+AAgFaOA==} peerDependencies: eslint: '>=7.4.0' @@ -88,7 +90,7 @@ packages: eslint-plugin-antfu: 0.25.2_qugx7qdu5zevzvxaiqyxfiwquq eslint-plugin-eslint-comments: 3.2.0_eslint@8.21.0 eslint-plugin-html: 6.2.0 - eslint-plugin-import: 2.26.0_wuikv5nqgdfyng42xxm7lklfmi + eslint-plugin-import: 2.26.0_eygs4xj346vriqwkjbwjuyviaa eslint-plugin-jsonc: 2.3.1_eslint@8.21.0 eslint-plugin-markdown: 2.2.1_eslint@8.21.0 eslint-plugin-n: 15.2.4_eslint@8.21.0 @@ -126,9 +128,9 @@ packages: eslint: '>=7.4.0' typescript: '>=3.9' dependencies: - '@antfu/eslint-config-basic': 0.25.2_iosr3hrei2tubxveewluhu5lhy - '@typescript-eslint/eslint-plugin': 5.32.0_iosr3hrei2tubxveewluhu5lhy - '@typescript-eslint/parser': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@antfu/eslint-config-basic': 0.25.2_jnss7dz76sznncvpyatba5hbxa + '@typescript-eslint/eslint-plugin': 5.31.0_jnss7dz76sznncvpyatba5hbxa + '@typescript-eslint/parser': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq eslint: 8.21.0 typescript: 4.7.4 transitivePeerDependencies: @@ -159,12 +161,12 @@ packages: dependencies: '@antfu/eslint-config-react': 0.25.2_qugx7qdu5zevzvxaiqyxfiwquq '@antfu/eslint-config-vue': 0.25.2_qugx7qdu5zevzvxaiqyxfiwquq - '@typescript-eslint/eslint-plugin': 5.32.0_iosr3hrei2tubxveewluhu5lhy - '@typescript-eslint/parser': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/eslint-plugin': 5.31.0_jnss7dz76sznncvpyatba5hbxa + '@typescript-eslint/parser': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq eslint: 8.21.0 eslint-plugin-eslint-comments: 3.2.0_eslint@8.21.0 eslint-plugin-html: 6.2.0 - eslint-plugin-import: 2.26.0_wuikv5nqgdfyng42xxm7lklfmi + eslint-plugin-import: 2.26.0_eygs4xj346vriqwkjbwjuyviaa eslint-plugin-jsonc: 2.3.1_eslint@8.21.0 eslint-plugin-n: 15.2.4_eslint@8.21.0 eslint-plugin-promise: 6.0.0_eslint@8.21.0 @@ -196,20 +198,20 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/core/7.18.10: - resolution: {integrity: sha512-JQM6k6ENcBFKVtWvLavlvi/mPcpYZ3+R+2EySDEMSMbp7Mn4FexlbbJVrx2R7Ijhr01T8gyqrOaABWIOgxeUyw==} + /@babel/core/7.18.9: + resolution: {integrity: sha512-1LIb1eL8APMy91/IMW+31ckrfBM4yCoLaVzoDhZUKSM4cu1L1nIidyxkCgzPAgrC5WEz36IPEr/eSeSF9pIn+g==} engines: {node: '>=6.9.0'} dependencies: '@ampproject/remapping': 2.2.0 '@babel/code-frame': 7.18.6 - '@babel/generator': 7.18.10 - '@babel/helper-compilation-targets': 7.18.9_@babel+core@7.18.10 + '@babel/generator': 7.18.9 + '@babel/helper-compilation-targets': 7.18.9_@babel+core@7.18.9 '@babel/helper-module-transforms': 7.18.9 '@babel/helpers': 7.18.9 - '@babel/parser': 7.18.10 - '@babel/template': 7.18.10 - '@babel/traverse': 7.18.10 - '@babel/types': 7.18.10 + '@babel/parser': 7.18.9 + '@babel/template': 7.18.6 + '@babel/traverse': 7.18.9 + '@babel/types': 7.18.9 convert-source-map: 1.8.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -219,23 +221,23 @@ packages: - supports-color dev: true - /@babel/generator/7.18.10: - resolution: {integrity: sha512-0+sW7e3HjQbiHbj1NeU/vN8ornohYlacAfZIaXhdoGweQqgcNy69COVciYYqEXJ/v+9OBA7Frxm4CVAuNqKeNA==} + /@babel/generator/7.18.9: + resolution: {integrity: sha512-wt5Naw6lJrL1/SGkipMiFxJjtyczUWTP38deiP1PO60HsBjDeKk08CGC3S8iVuvf0FmTdgKwU1KIXzSKL1G0Ug==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 '@jridgewell/gen-mapping': 0.3.2 jsesc: 2.5.2 dev: true - /@babel/helper-compilation-targets/7.18.9_@babel+core@7.18.10: + /@babel/helper-compilation-targets/7.18.9_@babel+core@7.18.9: resolution: {integrity: sha512-tzLCyVmqUiFlcFoAPLA/gL9TeYrF61VLNtb+hvkuVaB5SUjW7jcfrglBIX1vUIoT7CLP3bBlIMeyEsIl2eFQNg==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: '@babel/compat-data': 7.18.8 - '@babel/core': 7.18.10 + '@babel/core': 7.18.9 '@babel/helper-validator-option': 7.18.6 browserslist: 4.21.3 semver: 6.3.0 @@ -250,22 +252,22 @@ packages: resolution: {integrity: sha512-fJgWlZt7nxGksJS9a0XdSaI4XvpExnNIgRP+rVefWh5U7BL8pPuir6SJUmFKRfjWQ51OtWSzwOxhaH/EBWWc0A==} engines: {node: '>=6.9.0'} dependencies: - '@babel/template': 7.18.10 - '@babel/types': 7.18.10 + '@babel/template': 7.18.6 + '@babel/types': 7.18.9 dev: true /@babel/helper-hoist-variables/7.18.6: resolution: {integrity: sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 dev: true /@babel/helper-module-imports/7.18.6: resolution: {integrity: sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 dev: true /@babel/helper-module-transforms/7.18.9: @@ -277,9 +279,9 @@ packages: '@babel/helper-simple-access': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 '@babel/helper-validator-identifier': 7.18.6 - '@babel/template': 7.18.10 - '@babel/traverse': 7.18.10 - '@babel/types': 7.18.10 + '@babel/template': 7.18.6 + '@babel/traverse': 7.18.9 + '@babel/types': 7.18.9 transitivePeerDependencies: - supports-color dev: true @@ -288,20 +290,16 @@ packages: resolution: {integrity: sha512-iNpIgTgyAvDQpDj76POqg+YEt8fPxx3yaNBg3S30dxNKm2SWfYhD0TGrK/Eu9wHpUW63VQU894TsTg+GLbUa1g==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 dev: true /@babel/helper-split-export-declaration/7.18.6: resolution: {integrity: sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 dev: true - /@babel/helper-string-parser/7.18.10: - resolution: {integrity: sha512-XtIfWmeNY3i4t7t4D2t02q50HvqHybPqW2ki1kosnvWCwuCMeo81Jf0gwr85jy/neUdg5XDdeFE/80DXiO+njw==} - engines: {node: '>=6.9.0'} - /@babel/helper-validator-identifier/7.18.6: resolution: {integrity: sha512-MmetCkz9ej86nJQV+sFCxoGGrUbU3q02kgLciwkrt9QqEB7cP39oKEY0PakknEO0Gu20SskMRi+AYZ3b1TpN9g==} engines: {node: '>=6.9.0'} @@ -315,9 +313,9 @@ packages: resolution: {integrity: sha512-Jf5a+rbrLoR4eNdUmnFu8cN5eNJT6qdTdOg5IHIzq87WwyRw9PwguLFOWYgktN/60IP4fgDUawJvs7PjQIzELQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/template': 7.18.10 - '@babel/traverse': 7.18.10 - '@babel/types': 7.18.10 + '@babel/template': 7.18.6 + '@babel/traverse': 7.18.9 + '@babel/types': 7.18.9 transitivePeerDependencies: - supports-color dev: true @@ -331,61 +329,52 @@ packages: js-tokens: 4.0.0 dev: true - /@babel/parser/7.18.10: - resolution: {integrity: sha512-TYk3OA0HKL6qNryUayb5UUEhM/rkOQozIBEA5ITXh5DWrSp0TlUQXMyZmnWxG/DizSWBeeQ0Zbc5z8UGaaqoeg==} + /@babel/parser/7.18.9: + resolution: {integrity: sha512-9uJveS9eY9DJ0t64YbIBZICtJy8a5QrDEVdiLCG97fVLpDTpGX7t8mMSb6OWw6Lrnjqj4O8zwjELX3dhoMgiBg==} engines: {node: '>=6.0.0'} hasBin: true dependencies: - '@babel/types': 7.18.10 + '@babel/types': 7.18.9 - /@babel/standalone/7.18.10: - resolution: {integrity: sha512-0KWHiRX9TUHiWE+dKYYEOIiRJcPwGU6u8Bq/p+ldekj7Kew9PCwl4S4FTSEPpTrn3Vc+r3iRSaN1l9AcGgLx4Q==} + /@babel/standalone/7.18.9: + resolution: {integrity: sha512-6E+p5azHMHcMkHzGFnA7Pqhtgfwx1cClwjMqomMHhdFupCLZDDpVQUctRGYE7p7nn7cXJZSI/L9en+tt30AP3w==} engines: {node: '>=6.9.0'} dev: true - /@babel/template/7.18.10: - resolution: {integrity: sha512-TI+rCtooWHr3QJ27kJxfjutghu44DLnasDMwpDqCXVTal9RLp3RSYNh4NdBrRP2cQAoG9A8juOQl6P6oZG4JxA==} + /@babel/template/7.18.6: + resolution: {integrity: sha512-JoDWzPe+wgBsTTgdnIma3iHNFC7YVJoPssVBDjiHfNlyt4YcunDtcDOUmfVDfCK5MfdsaIoX9PkijPhjH3nYUw==} engines: {node: '>=6.9.0'} dependencies: '@babel/code-frame': 7.18.6 - '@babel/parser': 7.18.10 - '@babel/types': 7.18.10 + '@babel/parser': 7.18.9 + '@babel/types': 7.18.9 dev: true - /@babel/traverse/7.18.10: - resolution: {integrity: sha512-J7ycxg0/K9XCtLyHf0cz2DqDihonJeIo+z+HEdRe9YuT8TY4A66i+Ab2/xZCEW7Ro60bPCBBfqqboHSamoV3+g==} + /@babel/traverse/7.18.9: + resolution: {integrity: sha512-LcPAnujXGwBgv3/WHv01pHtb2tihcyW1XuL9wd7jqh1Z8AQkTd+QVjMrMijrln0T7ED3UXLIy36P9Ao7W75rYg==} engines: {node: '>=6.9.0'} dependencies: '@babel/code-frame': 7.18.6 - '@babel/generator': 7.18.10 + '@babel/generator': 7.18.9 '@babel/helper-environment-visitor': 7.18.9 '@babel/helper-function-name': 7.18.9 '@babel/helper-hoist-variables': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 - '@babel/parser': 7.18.10 - '@babel/types': 7.18.10 + '@babel/parser': 7.18.9 + '@babel/types': 7.18.9 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: - supports-color dev: true - /@babel/types/7.18.10: - resolution: {integrity: sha512-MJvnbEiiNkpjo+LknnmRrqbY1GPUUggjv+wQVjetM/AONoupqRALB7I6jGqNUAZsKcRIEu2J6FRFvsczljjsaQ==} + /@babel/types/7.18.9: + resolution: {integrity: sha512-WwMLAg2MvJmt/rKEVQBBhIVffMmnilX4oe0sRe7iPOHIGsqpruFHHdrfj4O1CMMtgMtCU4oPafZjDPCRgO57Wg==} engines: {node: '>=6.9.0'} dependencies: - '@babel/helper-string-parser': 7.18.10 '@babel/helper-validator-identifier': 7.18.6 to-fast-properties: 2.0.0 - /@esbuild/linux-loong64/0.14.53: - resolution: {integrity: sha512-W2dAL6Bnyn4xa/QRSU3ilIK4EzD5wgYXKXJiS1HDF5vU3675qc2bvFyLwbUcdmssDveyndy7FbitrCoiV/eMLg==} - engines: {node: '>=12'} - cpu: [loong64] - os: [linux] - requiresBuild: true - optional: true - /@eslint/eslintrc/1.3.0: resolution: {integrity: sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -535,7 +524,7 @@ packages: '@rollup/pluginutils': 3.1.0_rollup@2.77.2 '@types/resolve': 1.17.1 deepmerge: 4.2.2 - is-builtin-module: 3.2.0 + is-builtin-module: 3.1.0 is-module: 1.0.0 resolve: 1.22.1 rollup: 2.77.2 @@ -631,8 +620,8 @@ packages: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} dev: true - /@typescript-eslint/eslint-plugin/5.32.0_iosr3hrei2tubxveewluhu5lhy: - resolution: {integrity: sha512-CHLuz5Uz7bHP2WgVlvoZGhf0BvFakBJKAD/43Ty0emn4wXWv5k01ND0C0fHcl/Im8Td2y/7h44E9pca9qAu2ew==} + /@typescript-eslint/eslint-plugin/5.31.0_jnss7dz76sznncvpyatba5hbxa: + resolution: {integrity: sha512-VKW4JPHzG5yhYQrQ1AzXgVgX8ZAJEvCz0QI6mLRX4tf7rnFfh5D8SKm0Pq6w5PyNfAWJk6sv313+nEt3ohWMBQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -642,10 +631,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq - '@typescript-eslint/scope-manager': 5.32.0 - '@typescript-eslint/type-utils': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq - '@typescript-eslint/utils': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/parser': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/type-utils': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/utils': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq debug: 4.3.4 eslint: 8.21.0 functional-red-black-tree: 1.0.1 @@ -658,8 +647,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.32.0_qugx7qdu5zevzvxaiqyxfiwquq: - resolution: {integrity: sha512-IxRtsehdGV9GFQ35IGm5oKKR2OGcazUoiNBxhRV160iF9FoyuXxjY+rIqs1gfnd+4eL98OjeGnMpE7RF/NBb3A==} + /@typescript-eslint/parser/5.31.0_qugx7qdu5zevzvxaiqyxfiwquq: + resolution: {integrity: sha512-UStjQiZ9OFTFReTrN+iGrC6O/ko9LVDhreEK5S3edmXgR396JGq7CoX2TWIptqt/ESzU2iRKXAHfSF2WJFcWHw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -668,9 +657,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.32.0 - '@typescript-eslint/types': 5.32.0 - '@typescript-eslint/typescript-estree': 5.32.0_typescript@4.7.4 + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/typescript-estree': 5.31.0_typescript@4.7.4 debug: 4.3.4 eslint: 8.21.0 typescript: 4.7.4 @@ -678,16 +667,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager/5.32.0: - resolution: {integrity: sha512-KyAE+tUON0D7tNz92p1uetRqVJiiAkeluvwvZOqBmW9z2XApmk5WSMV9FrzOroAcVxJZB3GfUwVKr98Dr/OjOg==} + /@typescript-eslint/scope-manager/5.31.0: + resolution: {integrity: sha512-8jfEzBYDBG88rcXFxajdVavGxb5/XKXyvWgvD8Qix3EEJLCFIdVloJw+r9ww0wbyNLOTYyBsR+4ALNGdlalLLg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.32.0 - '@typescript-eslint/visitor-keys': 5.32.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/visitor-keys': 5.31.0 dev: true - /@typescript-eslint/type-utils/5.32.0_qugx7qdu5zevzvxaiqyxfiwquq: - resolution: {integrity: sha512-0gSsIhFDduBz3QcHJIp3qRCvVYbqzHg8D6bHFsDMrm0rURYDj+skBK2zmYebdCp+4nrd9VWd13egvhYFJj/wZg==} + /@typescript-eslint/type-utils/5.31.0_qugx7qdu5zevzvxaiqyxfiwquq: + resolution: {integrity: sha512-7ZYqFbvEvYXFn9ax02GsPcEOmuWNg+14HIf4q+oUuLnMbpJ6eHAivCg7tZMVwzrIuzX3QCeAOqKoyMZCv5xe+w==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -696,7 +685,7 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/utils': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq debug: 4.3.4 eslint: 8.21.0 tsutils: 3.21.0_typescript@4.7.4 @@ -705,13 +694,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.32.0: - resolution: {integrity: sha512-EBUKs68DOcT/EjGfzywp+f8wG9Zw6gj6BjWu7KV/IYllqKJFPlZlLSYw/PTvVyiRw50t6wVbgv4p9uE2h6sZrQ==} + /@typescript-eslint/types/5.31.0: + resolution: {integrity: sha512-/f/rMaEseux+I4wmR6mfpM2wvtNZb1p9hAV77hWfuKc3pmaANp5dLAZSiE3/8oXTYTt3uV9KW5yZKJsMievp6g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.32.0_typescript@4.7.4: - resolution: {integrity: sha512-ZVAUkvPk3ITGtCLU5J4atCw9RTxK+SRc6hXqLtllC2sGSeMFWN+YwbiJR9CFrSFJ3w4SJfcWtDwNb/DmUIHdhg==} + /@typescript-eslint/typescript-estree/5.31.0_typescript@4.7.4: + resolution: {integrity: sha512-3S625TMcARX71wBc2qubHaoUwMEn+l9TCsaIzYI/ET31Xm2c9YQ+zhGgpydjorwQO9pLfR/6peTzS/0G3J/hDw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -719,8 +708,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.32.0 - '@typescript-eslint/visitor-keys': 5.32.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/visitor-keys': 5.31.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -731,16 +720,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.32.0_qugx7qdu5zevzvxaiqyxfiwquq: - resolution: {integrity: sha512-W7lYIAI5Zlc5K082dGR27Fczjb3Q57ECcXefKU/f0ajM5ToM0P+N9NmJWip8GmGu/g6QISNT+K6KYB+iSHjXCQ==} + /@typescript-eslint/utils/5.31.0_qugx7qdu5zevzvxaiqyxfiwquq: + resolution: {integrity: sha512-kcVPdQS6VIpVTQ7QnGNKMFtdJdvnStkqS5LeALr4rcwx11G6OWb2HB17NMPnlRHvaZP38hL9iK8DdE9Fne7NYg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.32.0 - '@typescript-eslint/types': 5.32.0 - '@typescript-eslint/typescript-estree': 5.32.0_typescript@4.7.4 + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/typescript-estree': 5.31.0_typescript@4.7.4 eslint: 8.21.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.21.0 @@ -749,11 +738,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.32.0: - resolution: {integrity: sha512-S54xOHZgfThiZ38/ZGTgB2rqx51CMJ5MCfVT2IplK4Q7hgzGfe0nLzLCcenDnc/cSjP568hdeKfeDcBgqNHD/g==} + /@typescript-eslint/visitor-keys/5.31.0: + resolution: {integrity: sha512-ZK0jVxSjS4gnPirpVjXHz7mgdOsZUHzNYSfTw2yPa3agfbt9YfqaBiBZFSSxeBWnpWkzCxTfUpnzA3Vily/CSg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.32.0 + '@typescript-eslint/types': 5.31.0 eslint-visitor-keys: 3.3.0 dev: true @@ -772,7 +761,7 @@ packages: /@vue/compiler-sfc/2.7.8: resolution: {integrity: sha512-2DK4YWKfgLnW9VDR9gnju1gcYRk3flKj8UNsms7fsRmFcg35slVTZEkqwBtX+wJBXaamFfn6NxSsZh3h12Ix/Q==} dependencies: - '@babel/parser': 7.18.10 + '@babel/parser': 7.18.9 postcss: 8.4.14 source-map: 0.6.1 @@ -900,7 +889,7 @@ packages: hasBin: true dependencies: caniuse-lite: 1.0.30001373 - electron-to-chromium: 1.4.210 + electron-to-chromium: 1.4.206 node-releases: 2.0.6 update-browserslist-db: 1.0.5_browserslist@4.21.3 dev: true @@ -1145,6 +1134,13 @@ packages: /defu/6.0.0: resolution: {integrity: sha512-t2MZGLf1V2rV4VBZbWIaXKdX/mUcYW0n2znQZoADBkGGxYL8EWqCuCZBmJPJ/Yy9fofJkyuuSuo5GSwo0XdEgw==} + /detect-package-manager/2.0.1: + resolution: {integrity: sha512-j/lJHyoLlWi6G1LDdLgvUtz60Zo5GEj+sVYtTVXnYLDPuzgC3llMxonXym9zIwhhUII8vjdw0LXxavpLqTbl1A==} + engines: {node: '>=12'} + dependencies: + execa: 5.1.1 + dev: true + /dir-glob/3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -1193,8 +1189,8 @@ packages: domhandler: 4.3.1 dev: true - /electron-to-chromium/1.4.210: - resolution: {integrity: sha512-kSiX4tuyZijV7Cz0MWVmGT8K2siqaOA4Z66K5dCttPPRh0HicOcOAEj1KlC8O8J1aOS/1M8rGofOzksLKaHWcQ==} + /electron-to-chromium/1.4.206: + resolution: {integrity: sha512-h+Fadt1gIaQ06JaIiyqPsBjJ08fV5Q7md+V8bUvQW/9OvXfL2LRICTz2EcnnCP7QzrFTS6/27MRV6Bl9Yn97zA==} dev: true /entities/2.2.0: @@ -1260,193 +1256,192 @@ packages: is-symbol: 1.0.4 dev: true - /esbuild-android-64/0.14.53: - resolution: {integrity: sha512-fIL93sOTnEU+NrTAVMIKiAw0YH22HWCAgg4N4Z6zov2t0kY9RAJ50zY9ZMCQ+RT6bnOfDt8gCTnt/RaSNA2yRA==} + /esbuild-android-64/0.14.51: + resolution: {integrity: sha512-6FOuKTHnC86dtrKDmdSj2CkcKF8PnqkaIXqvgydqfJmqBazCPdw+relrMlhGjkvVdiiGV70rpdnyFmA65ekBCQ==} engines: {node: '>=12'} cpu: [x64] os: [android] requiresBuild: true optional: true - /esbuild-android-arm64/0.14.53: - resolution: {integrity: sha512-PC7KaF1v0h/nWpvlU1UMN7dzB54cBH8qSsm7S9mkwFA1BXpaEOufCg8hdoEI1jep0KeO/rjZVWrsH8+q28T77A==} + /esbuild-android-arm64/0.14.51: + resolution: {integrity: sha512-vBtp//5VVkZWmYYvHsqBRCMMi1MzKuMIn5XDScmnykMTu9+TD9v0NMEDqQxvtFToeYmojdo5UCV2vzMQWJcJ4A==} engines: {node: '>=12'} cpu: [arm64] os: [android] requiresBuild: true optional: true - /esbuild-darwin-64/0.14.53: - resolution: {integrity: sha512-gE7P5wlnkX4d4PKvLBUgmhZXvL7lzGRLri17/+CmmCzfncIgq8lOBvxGMiQ4xazplhxq+72TEohyFMZLFxuWvg==} + /esbuild-darwin-64/0.14.51: + resolution: {integrity: sha512-YFmXPIOvuagDcwCejMRtCDjgPfnDu+bNeh5FU2Ryi68ADDVlWEpbtpAbrtf/lvFTWPexbgyKgzppNgsmLPr8PA==} engines: {node: '>=12'} cpu: [x64] os: [darwin] requiresBuild: true optional: true - /esbuild-darwin-arm64/0.14.53: - resolution: {integrity: sha512-otJwDU3hnI15Q98PX4MJbknSZ/WSR1I45il7gcxcECXzfN4Mrpft5hBDHXNRnCh+5858uPXBXA1Vaz2jVWLaIA==} + /esbuild-darwin-arm64/0.14.51: + resolution: {integrity: sha512-juYD0QnSKwAMfzwKdIF6YbueXzS6N7y4GXPDeDkApz/1RzlT42mvX9jgNmyOlWKN7YzQAYbcUEJmZJYQGdf2ow==} engines: {node: '>=12'} cpu: [arm64] os: [darwin] requiresBuild: true optional: true - /esbuild-freebsd-64/0.14.53: - resolution: {integrity: sha512-WkdJa8iyrGHyKiPF4lk0MiOF87Q2SkE+i+8D4Cazq3/iqmGPJ6u49je300MFi5I2eUsQCkaOWhpCVQMTKGww2w==} + /esbuild-freebsd-64/0.14.51: + resolution: {integrity: sha512-cLEI/aXjb6vo5O2Y8rvVSQ7smgLldwYY5xMxqh/dQGfWO+R1NJOFsiax3IS4Ng300SVp7Gz3czxT6d6qf2cw0g==} engines: {node: '>=12'} cpu: [x64] os: [freebsd] requiresBuild: true optional: true - /esbuild-freebsd-arm64/0.14.53: - resolution: {integrity: sha512-9T7WwCuV30NAx0SyQpw8edbKvbKELnnm1FHg7gbSYaatH+c8WJW10g/OdM7JYnv7qkimw2ZTtSA+NokOLd2ydQ==} + /esbuild-freebsd-arm64/0.14.51: + resolution: {integrity: sha512-TcWVw/rCL2F+jUgRkgLa3qltd5gzKjIMGhkVybkjk6PJadYInPtgtUBp1/hG+mxyigaT7ib+od1Xb84b+L+1Mg==} engines: {node: '>=12'} cpu: [arm64] os: [freebsd] requiresBuild: true optional: true - /esbuild-linux-32/0.14.53: - resolution: {integrity: sha512-VGanLBg5en2LfGDgLEUxQko2lqsOS7MTEWUi8x91YmsHNyzJVT/WApbFFx3MQGhkf+XdimVhpyo5/G0PBY91zg==} + /esbuild-linux-32/0.14.51: + resolution: {integrity: sha512-RFqpyC5ChyWrjx8Xj2K0EC1aN0A37H6OJfmUXIASEqJoHcntuV3j2Efr9RNmUhMfNE6yEj2VpYuDteZLGDMr0w==} engines: {node: '>=12'} cpu: [ia32] os: [linux] requiresBuild: true optional: true - /esbuild-linux-64/0.14.53: - resolution: {integrity: sha512-pP/FA55j/fzAV7N9DF31meAyjOH6Bjuo3aSKPh26+RW85ZEtbJv9nhoxmGTd9FOqjx59Tc1ZbrJabuiXlMwuZQ==} + /esbuild-linux-64/0.14.51: + resolution: {integrity: sha512-dxjhrqo5i7Rq6DXwz5v+MEHVs9VNFItJmHBe1CxROWNf4miOGoQhqSG8StStbDkQ1Mtobg6ng+4fwByOhoQoeA==} engines: {node: '>=12'} cpu: [x64] os: [linux] requiresBuild: true optional: true - /esbuild-linux-arm/0.14.53: - resolution: {integrity: sha512-/u81NGAVZMopbmzd21Nu/wvnKQK3pT4CrvQ8BTje1STXcQAGnfyKgQlj3m0j2BzYbvQxSy+TMck4TNV2onvoPA==} + /esbuild-linux-arm/0.14.51: + resolution: {integrity: sha512-LsJynDxYF6Neg7ZC7748yweCDD+N8ByCv22/7IAZglIEniEkqdF4HCaa49JNDLw1UQGlYuhOB8ZT/MmcSWzcWg==} engines: {node: '>=12'} cpu: [arm] os: [linux] requiresBuild: true optional: true - /esbuild-linux-arm64/0.14.53: - resolution: {integrity: sha512-GDmWITT+PMsjCA6/lByYk7NyFssW4Q6in32iPkpjZ/ytSyH+xeEx8q7HG3AhWH6heemEYEWpTll/eui3jwlSnw==} + /esbuild-linux-arm64/0.14.51: + resolution: {integrity: sha512-D9rFxGutoqQX3xJPxqd6o+kvYKeIbM0ifW2y0bgKk5HPgQQOo2k9/2Vpto3ybGYaFPCE5qTGtqQta9PoP6ZEzw==} engines: {node: '>=12'} cpu: [arm64] os: [linux] requiresBuild: true optional: true - /esbuild-linux-mips64le/0.14.53: - resolution: {integrity: sha512-d6/XHIQW714gSSp6tOOX2UscedVobELvQlPMkInhx1NPz4ThZI9uNLQ4qQJHGBGKGfu+rtJsxM4NVHLhnNRdWQ==} + /esbuild-linux-mips64le/0.14.51: + resolution: {integrity: sha512-vS54wQjy4IinLSlb5EIlLoln8buh1yDgliP4CuEHumrPk4PvvP4kTRIG4SzMXm6t19N0rIfT4bNdAxzJLg2k6A==} engines: {node: '>=12'} cpu: [mips64el] os: [linux] requiresBuild: true optional: true - /esbuild-linux-ppc64le/0.14.53: - resolution: {integrity: sha512-ndnJmniKPCB52m+r6BtHHLAOXw+xBCWIxNnedbIpuREOcbSU/AlyM/2dA3BmUQhsHdb4w3amD5U2s91TJ3MzzA==} + /esbuild-linux-ppc64le/0.14.51: + resolution: {integrity: sha512-xcdd62Y3VfGoyphNP/aIV9LP+RzFw5M5Z7ja+zdpQHHvokJM7d0rlDRMN+iSSwvUymQkqZO+G/xjb4/75du8BQ==} engines: {node: '>=12'} cpu: [ppc64] os: [linux] requiresBuild: true optional: true - /esbuild-linux-riscv64/0.14.53: - resolution: {integrity: sha512-yG2sVH+QSix6ct4lIzJj329iJF3MhloLE6/vKMQAAd26UVPVkhMFqFopY+9kCgYsdeWvXdPgmyOuKa48Y7+/EQ==} + /esbuild-linux-riscv64/0.14.51: + resolution: {integrity: sha512-syXHGak9wkAnFz0gMmRBoy44JV0rp4kVCEA36P5MCeZcxFq8+fllBC2t6sKI23w3qd8Vwo9pTADCgjTSf3L3rA==} engines: {node: '>=12'} cpu: [riscv64] os: [linux] requiresBuild: true optional: true - /esbuild-linux-s390x/0.14.53: - resolution: {integrity: sha512-OCJlgdkB+XPYndHmw6uZT7jcYgzmx9K+28PVdOa/eLjdoYkeAFvH5hTwX4AXGLZLH09tpl4bVsEtvuyUldaNCg==} + /esbuild-linux-s390x/0.14.51: + resolution: {integrity: sha512-kFAJY3dv+Wq8o28K/C7xkZk/X34rgTwhknSsElIqoEo8armCOjMJ6NsMxm48KaWY2h2RUYGtQmr+RGuUPKBhyw==} engines: {node: '>=12'} cpu: [s390x] os: [linux] requiresBuild: true optional: true - /esbuild-netbsd-64/0.14.53: - resolution: {integrity: sha512-gp2SB+Efc7MhMdWV2+pmIs/Ja/Mi5rjw+wlDmmbIn68VGXBleNgiEZG+eV2SRS0kJEUyHNedDtwRIMzaohWedQ==} + /esbuild-netbsd-64/0.14.51: + resolution: {integrity: sha512-ZZBI7qrR1FevdPBVHz/1GSk1x5GDL/iy42Zy8+neEm/HA7ma+hH/bwPEjeHXKWUDvM36CZpSL/fn1/y9/Hb+1A==} engines: {node: '>=12'} cpu: [x64] os: [netbsd] requiresBuild: true optional: true - /esbuild-openbsd-64/0.14.53: - resolution: {integrity: sha512-eKQ30ZWe+WTZmteDYg8S+YjHV5s4iTxeSGhJKJajFfQx9TLZJvsJX0/paqwP51GicOUruFpSUAs2NCc0a4ivQQ==} + /esbuild-openbsd-64/0.14.51: + resolution: {integrity: sha512-7R1/p39M+LSVQVgDVlcY1KKm6kFKjERSX1lipMG51NPcspJD1tmiZSmmBXoY5jhHIu6JL1QkFDTx94gMYK6vfA==} engines: {node: '>=12'} cpu: [x64] os: [openbsd] requiresBuild: true optional: true - /esbuild-sunos-64/0.14.53: - resolution: {integrity: sha512-OWLpS7a2FrIRukQqcgQqR1XKn0jSJoOdT+RlhAxUoEQM/IpytS3FXzCJM6xjUYtpO5GMY0EdZJp+ur2pYdm39g==} + /esbuild-sunos-64/0.14.51: + resolution: {integrity: sha512-HoHaCswHxLEYN8eBTtyO0bFEWvA3Kdb++hSQ/lLG7TyKF69TeSG0RNoBRAs45x/oCeWaTDntEZlYwAfQlhEtJA==} engines: {node: '>=12'} cpu: [x64] os: [sunos] requiresBuild: true optional: true - /esbuild-windows-32/0.14.53: - resolution: {integrity: sha512-m14XyWQP5rwGW0tbEfp95U6A0wY0DYPInWBB7D69FAXUpBpBObRoGTKRv36lf2RWOdE4YO3TNvj37zhXjVL5xg==} + /esbuild-windows-32/0.14.51: + resolution: {integrity: sha512-4rtwSAM35A07CBt1/X8RWieDj3ZUHQqUOaEo5ZBs69rt5WAFjP4aqCIobdqOy4FdhYw1yF8Z0xFBTyc9lgPtEg==} engines: {node: '>=12'} cpu: [ia32] os: [win32] requiresBuild: true optional: true - /esbuild-windows-64/0.14.53: - resolution: {integrity: sha512-s9skQFF0I7zqnQ2K8S1xdLSfZFsPLuOGmSx57h2btSEswv0N0YodYvqLcJMrNMXh6EynOmWD7rz+0rWWbFpIHQ==} + /esbuild-windows-64/0.14.51: + resolution: {integrity: sha512-HoN/5HGRXJpWODprGCgKbdMvrC3A2gqvzewu2eECRw2sYxOUoh2TV1tS+G7bHNapPGI79woQJGV6pFH7GH7qnA==} engines: {node: '>=12'} cpu: [x64] os: [win32] requiresBuild: true optional: true - /esbuild-windows-arm64/0.14.53: - resolution: {integrity: sha512-E+5Gvb+ZWts+00T9II6wp2L3KG2r3iGxByqd/a1RmLmYWVsSVUjkvIxZuJ3hYTIbhLkH5PRwpldGTKYqVz0nzQ==} + /esbuild-windows-arm64/0.14.51: + resolution: {integrity: sha512-JQDqPjuOH7o+BsKMSddMfmVJXrnYZxXDHsoLHc0xgmAZkOOCflRmC43q31pk79F9xuyWY45jDBPolb5ZgGOf9g==} engines: {node: '>=12'} cpu: [arm64] os: [win32] requiresBuild: true optional: true - /esbuild/0.14.53: - resolution: {integrity: sha512-ohO33pUBQ64q6mmheX1mZ8mIXj8ivQY/L4oVuAshr+aJI+zLl+amrp3EodrUNDNYVrKJXGPfIHFGhO8slGRjuw==} + /esbuild/0.14.51: + resolution: {integrity: sha512-+CvnDitD7Q5sT7F+FM65sWkF8wJRf+j9fPcprxYV4j+ohmzVj2W7caUqH2s5kCaCJAfcAICjSlKhDCcvDpU7nw==} engines: {node: '>=12'} hasBin: true requiresBuild: true optionalDependencies: - '@esbuild/linux-loong64': 0.14.53 - esbuild-android-64: 0.14.53 - esbuild-android-arm64: 0.14.53 - esbuild-darwin-64: 0.14.53 - esbuild-darwin-arm64: 0.14.53 - esbuild-freebsd-64: 0.14.53 - esbuild-freebsd-arm64: 0.14.53 - esbuild-linux-32: 0.14.53 - esbuild-linux-64: 0.14.53 - esbuild-linux-arm: 0.14.53 - esbuild-linux-arm64: 0.14.53 - esbuild-linux-mips64le: 0.14.53 - esbuild-linux-ppc64le: 0.14.53 - esbuild-linux-riscv64: 0.14.53 - esbuild-linux-s390x: 0.14.53 - esbuild-netbsd-64: 0.14.53 - esbuild-openbsd-64: 0.14.53 - esbuild-sunos-64: 0.14.53 - esbuild-windows-32: 0.14.53 - esbuild-windows-64: 0.14.53 - esbuild-windows-arm64: 0.14.53 + esbuild-android-64: 0.14.51 + esbuild-android-arm64: 0.14.51 + esbuild-darwin-64: 0.14.51 + esbuild-darwin-arm64: 0.14.51 + esbuild-freebsd-64: 0.14.51 + esbuild-freebsd-arm64: 0.14.51 + esbuild-linux-32: 0.14.51 + esbuild-linux-64: 0.14.51 + esbuild-linux-arm: 0.14.51 + esbuild-linux-arm64: 0.14.51 + esbuild-linux-mips64le: 0.14.51 + esbuild-linux-ppc64le: 0.14.51 + esbuild-linux-riscv64: 0.14.51 + esbuild-linux-s390x: 0.14.51 + esbuild-netbsd-64: 0.14.51 + esbuild-openbsd-64: 0.14.51 + esbuild-sunos-64: 0.14.51 + esbuild-windows-32: 0.14.51 + esbuild-windows-64: 0.14.51 + esbuild-windows-arm64: 0.14.51 /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} @@ -1472,7 +1467,7 @@ packages: - supports-color dev: true - /eslint-module-utils/2.7.3_gjpiwexkhexdr4bbgrtzf23bg4: + /eslint-module-utils/2.7.3_vozeh3qpn3prlhg65r4uuu3jv4: resolution: {integrity: sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==} engines: {node: '>=4'} peerDependencies: @@ -1490,7 +1485,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/parser': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq debug: 3.2.7 eslint-import-resolver-node: 0.3.6 find-up: 2.1.0 @@ -1501,7 +1496,7 @@ packages: /eslint-plugin-antfu/0.25.2_qugx7qdu5zevzvxaiqyxfiwquq: resolution: {integrity: sha512-yRhuFMwUKhSYm8BWTZsW4ymYnFPCJWZb2LzjG+mQb7JbKflk73JIFMCREPOaV4nWwc4YJEPhym75QsC7AFbqSw==} dependencies: - '@typescript-eslint/utils': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/utils': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq transitivePeerDependencies: - eslint - supports-color @@ -1536,7 +1531,7 @@ packages: htmlparser2: 7.2.0 dev: true - /eslint-plugin-import/2.26.0_wuikv5nqgdfyng42xxm7lklfmi: + /eslint-plugin-import/2.26.0_eygs4xj346vriqwkjbwjuyviaa: resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} engines: {node: '>=4'} peerDependencies: @@ -1546,14 +1541,14 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.32.0_qugx7qdu5zevzvxaiqyxfiwquq + '@typescript-eslint/parser': 5.31.0_qugx7qdu5zevzvxaiqyxfiwquq array-includes: 3.1.5 array.prototype.flat: 1.3.0 debug: 2.6.9 doctrine: 2.1.0 eslint: 8.21.0 eslint-import-resolver-node: 0.3.6 - eslint-module-utils: 2.7.3_gjpiwexkhexdr4bbgrtzf23bg4 + eslint-module-utils: 2.7.3_vozeh3qpn3prlhg65r4uuu3jv4 has: 1.0.3 is-core-module: 2.9.0 is-glob: 4.0.3 @@ -1653,7 +1648,7 @@ packages: eslint-utils: 3.0.0_eslint@8.21.0 esquery: 1.4.0 indent-string: 4.0.0 - is-builtin-module: 3.2.0 + is-builtin-module: 3.1.0 lodash: 4.17.21 pluralize: 8.0.0 read-pkg-up: 7.0.1 @@ -1792,6 +1787,15 @@ packages: - supports-color dev: true + /espree/9.3.2: + resolution: {integrity: sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + acorn: 8.8.0 + acorn-jsx: 5.3.2_acorn@8.8.0 + eslint-visitor-keys: 3.3.0 + dev: true + /espree/9.3.3: resolution: {integrity: sha512-ORs1Rt/uQTqUKjDdGCyrtYxbazf5umATSf/K4qxjmZHORR6HJk+2s/2Pqe+Kk49HHINC/xNIrGfgh8sZcll0ng==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1838,6 +1842,21 @@ packages: engines: {node: '>=0.10.0'} dev: true + /execa/5.1.1: + resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} + engines: {node: '>=10'} + dependencies: + cross-spawn: 7.0.3 + get-stream: 6.0.1 + human-signals: 2.1.0 + is-stream: 2.0.1 + merge-stream: 2.0.0 + npm-run-path: 4.0.1 + onetime: 5.1.2 + signal-exit: 3.0.7 + strip-final-newline: 2.0.0 + dev: true + /fast-deep-equal/3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} dev: true @@ -1973,6 +1992,11 @@ packages: has-symbols: 1.0.3 dev: true + /get-stream/6.0.1: + resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} + engines: {node: '>=10'} + dev: true + /get-symbol-description/1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} engines: {node: '>= 0.4'} @@ -2092,6 +2116,11 @@ packages: entities: 3.0.1 dev: true + /human-signals/2.1.0: + resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} + engines: {node: '>=10.17.0'} + dev: true + /ignore/5.2.0: resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} engines: {node: '>= 4'} @@ -2173,8 +2202,8 @@ packages: has-tostringtag: 1.0.0 dev: true - /is-builtin-module/3.2.0: - resolution: {integrity: sha512-phDA4oSGt7vl1n5tJvTWooWWAsXLY+2xCnxNqvKhGEzujg+A43wPlPOyDg3C8XQHN+6k/JTQWJ/j0dQh/qr+Hw==} + /is-builtin-module/3.1.0: + resolution: {integrity: sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==} engines: {node: '>=6'} dependencies: builtin-modules: 3.3.0 @@ -2255,6 +2284,11 @@ packages: call-bind: 1.0.2 dev: true + /is-stream/2.0.1: + resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} + engines: {node: '>=8'} + dev: true + /is-string/1.0.7: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} engines: {node: '>= 0.4'} @@ -2336,7 +2370,7 @@ packages: dependencies: acorn: 8.8.0 eslint-visitor-keys: 3.3.0 - espree: 9.3.3 + espree: 9.3.2 semver: 7.3.7 dev: true @@ -2470,6 +2504,10 @@ packages: resolution: {integrity: sha512-AW4DRS3QbBayY/jJmD8437V1Gombjf8RSOUCMFBuo5iHi58AGEgVCKQ+ezHkZZDpAQS75hcBMpLqjpJTjtUL7w==} dev: true + /merge-stream/2.0.0: + resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} + dev: true + /merge2/1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} @@ -2492,6 +2530,11 @@ packages: picomatch: 2.3.1 dev: true + /mimic-fn/2.1.0: + resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} + engines: {node: '>=6'} + dev: true + /min-indent/1.0.1: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} engines: {node: '>=4'} @@ -2523,7 +2566,7 @@ packages: optional: true dependencies: defu: 6.0.0 - esbuild: 0.14.53 + esbuild: 0.14.51 fs-extra: 10.1.0 globby: 11.1.0 jiti: 1.14.0 @@ -2582,6 +2625,13 @@ packages: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} + /npm-run-path/4.0.1: + resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} + engines: {node: '>=8'} + dependencies: + path-key: 3.1.1 + dev: true + /nth-check/2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} dependencies: @@ -2652,6 +2702,13 @@ packages: wrappy: 1.0.2 dev: true + /onetime/5.1.2: + resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} + engines: {node: '>=6'} + dependencies: + mimic-fn: 2.1.0 + dev: true + /optionator/0.9.1: resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} engines: {node: '>= 0.8.0'} @@ -2989,7 +3046,7 @@ packages: '@babel/code-frame': 7.18.6 dev: true - /rollup-plugin-esbuild/4.9.1_eqz4txfukrxgk4uaulv43wixku: + /rollup-plugin-esbuild/4.9.1_ecpsl2p7zl5puhr4xxlpah6uzm: resolution: {integrity: sha512-qn/x7Wz9p3Xnva99qcb+nopH0d2VJwVnsxJTGEg+Sh2Z3tqQl33MhOwzekVo1YTKgv+yAmosjcBRJygMfGrtLw==} engines: {node: '>=12'} peerDependencies: @@ -2999,7 +3056,7 @@ packages: '@rollup/pluginutils': 4.2.1 debug: 4.3.4 es-module-lexer: 0.9.3 - esbuild: 0.14.53 + esbuild: 0.14.51 joycon: 3.1.1 jsonc-parser: 3.1.0 rollup: 2.77.2 @@ -3081,6 +3138,10 @@ packages: object-inspect: 1.12.2 dev: true + /signal-exit/3.0.7: + resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + dev: true + /simple-git-hooks/2.8.0: resolution: {integrity: sha512-ocmZQORwa6x9mxg+gVIAp5o4wXiWOHGXyrDBA0+UxGKIEKOyFtL4LWNKkP/2ornQPdlnlDGDteVeYP5FjhIoWA==} hasBin: true @@ -3175,6 +3236,11 @@ packages: engines: {node: '>=4'} dev: true + /strip-final-newline/2.0.0: + resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} + engines: {node: '>=6'} + dev: true + /strip-indent/3.0.0: resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==} engines: {node: '>=8'} @@ -3307,7 +3373,7 @@ packages: chalk: 5.0.1 consola: 2.15.3 defu: 6.0.0 - esbuild: 0.14.53 + esbuild: 0.14.51 hookable: 5.1.1 jiti: 1.14.0 magic-string: 0.26.2 @@ -3321,7 +3387,7 @@ packages: rimraf: 3.0.2 rollup: 2.77.2 rollup-plugin-dts: 4.2.2_oo3i3f3qmqiztdz5qgxrrjmd5e - rollup-plugin-esbuild: 4.9.1_eqz4txfukrxgk4uaulv43wixku + rollup-plugin-esbuild: 4.9.1_ecpsl2p7zl5puhr4xxlpah6uzm scule: 0.2.1 typescript: 4.7.4 untyped: 0.4.4 @@ -3351,9 +3417,9 @@ packages: /untyped/0.4.4: resolution: {integrity: sha512-sY6u8RedwfLfBis0copfU/fzROieyAndqPs8Kn2PfyzTjtA88vCk81J1b5z+8/VJc+cwfGy23/AqOCpvAbkNVw==} dependencies: - '@babel/core': 7.18.10 - '@babel/standalone': 7.18.10 - '@babel/types': 7.18.10 + '@babel/core': 7.18.9 + '@babel/standalone': 7.18.9 + '@babel/types': 7.18.9 scule: 0.2.1 transitivePeerDependencies: - supports-color @@ -3409,7 +3475,7 @@ packages: terser: optional: true dependencies: - esbuild: 0.14.53 + esbuild: 0.14.51 postcss: 8.4.14 resolve: 1.22.1 rollup: 2.77.2 diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index b961040..8982ce5 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -1,7 +1,7 @@ import { cac } from 'cac' import { name, version } from '../../package.json' import type { CliOptions } from './types' -import { build } from './index' +import { build, serve } from './index' export async function startCli( cwd = process.cwd(), @@ -10,6 +10,23 @@ export async function startCli( ) { const cli = cac(name) + cli + .command('serve [file]', 'Panel input file', { + ignoreOptionDefaultValue: true, + }) + .action(async (file, flags) => { + Object.assign(options, { + cwd, + ...flags, + }) + + if (file) + options.entry = file + + const server = await serve(options) + process.on('SIGINT', () => server.close()) + }) + cli .command('[file]', 'Panel input file', { ignoreOptionDefaultValue: true, diff --git a/src/node/index.ts b/src/node/index.ts index 869b7a9..c9ca4a7 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -1,7 +1,11 @@ import { existsSync } from 'node:fs' import { readFile } from 'node:fs/promises' import { basename, dirname, resolve } from 'pathe' -import { build as _build, mergeConfig } from 'vite' +import { + build as _build, + createServer as _createServer, + mergeConfig, +} from 'vite' import vuePlugin from '@vitejs/plugin-vue2' // eslint-disable-next-line import/default import postcssrc from 'postcss-load-config' @@ -19,6 +23,7 @@ import { PrettyError, handleError } from './errors' import { printFileInfo, toArray } from './utils' import { loadConfig } from './config' import kirbyupAutoImportPlugin from './plugins/auto-import' +import kirbyupHmrPlugin from './plugins/hmr' import type { CliOptions, PostCSSConfigResult, @@ -29,6 +34,31 @@ import type { let resolvedKirbyupConfig: UserConfig let resolvedPostCssConfig: PostCSSConfigResult +async function createServer(options: ResolvedCliOptions) { + const aliasDir = resolve(options.cwd, dirname(options.entry)) + const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig + + const defaultConfig: InlineConfig = { + plugins: [vuePlugin(), kirbyupAutoImportPlugin(), kirbyupHmrPlugin(options)], + // Input needs to be specified so dep pre-bundling works + build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, + resolve: { + alias: { + '~/': `${aliasDir}/`, + '@/': `${aliasDir}/`, + ...alias, + }, + }, + css: { + postcss: resolvedPostCssConfig, + }, + envPrefix: ['VITE_', 'KIRBYUP_'], + logLevel: 'warn', + } + + return _createServer(mergeConfig(defaultConfig, extendViteConfig)) +} + async function generate(options: ResolvedCliOptions) { let result: Awaited> | undefined @@ -130,6 +160,41 @@ export async function resolveOptions(options: CliOptions) { return options as ResolvedCliOptions } +export async function serve(_options: CliOptions) { + const options = await resolveOptions(_options) + const { cwd } = options + + // Resolve kirbyup config + const { config } = await loadConfig(cwd) + resolvedKirbyupConfig = config + + // Resolve postcss config + try { + // @ts-expect-error: types won't match + resolvedPostCssConfig = await postcssrc({}) + } + catch (err: any) { + if (!/No PostCSS Config found/.test(err.message)) + throw err + resolvedPostCssConfig = { + plugins: [postcssLogical(), postcssDirPseudoClass()], + } + } + + if (!process.env.VITEST) { + consola.log(colors.green(`${name} v${version}`)) + consola.info('Starting development server...') + } + + const server = await createServer(options) + + await server.listen() + if (!process.env.VITEST) + consola.success(`Server is listening on :${server.config.server.port}`) + + return server +} + export async function build(_options: CliOptions) { const options = await resolveOptions(_options) const { cwd } = options diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts new file mode 100644 index 0000000..a706f76 --- /dev/null +++ b/src/node/plugins/hmr.ts @@ -0,0 +1,80 @@ +import { existsSync, unlinkSync } from 'node:fs' +import { writeFile } from 'node:fs/promises' +import type { AddressInfo } from 'node:net' +import { resolve } from 'pathe' +import type { Plugin, ResolvedConfig } from 'vite' +import { normalizePath } from 'vite' +import type { PM } from 'detect-package-manager' +import { detect as detectPm } from 'detect-package-manager' +import type { ResolvedCliOptions } from '../types' + +const __HMR_ID__ = '\0kirbyup:hmr' + +// Injected code to trigger full reloads for updates that aren't CSS +const __HMR_CODE__ = ` +if (import.meta.hot) { + import.meta.hot.on("vite:beforeUpdate", ({ updates }) => { + if (updates.some((update) => !update.path.match(/type=style&index=\\d+/))) { + import.meta.hot.invalidate(); + } + }); +}`.trim() + +// Proxy JS file to "forward" the plugin script loaded by Kirby to the Vite server +const getViteProxyModule = (entryUrl: string, pm: PM) => ` +try { + await import("${entryUrl}"); +} catch (err) { + console.error( + "[kirbyup] Couldn't connect to the development server. Run \`${pm} run dev\` to start Vite or build the plugin with \`${pm} run build\` so Kirby uses the production version." + ); + throw err; +}`.trim() + +export default function kirbyupHmrPlugin(options: ResolvedCliOptions): Plugin { + const indexMjs = resolve(options.cwd, 'index.mjs') + const entry = resolve(options.cwd, options.entry) + + let config: ResolvedConfig + + return { + name: 'kirbyup:hmr', + apply: 'serve', + configResolved(resolvedConfig) { + config = resolvedConfig + }, + resolveId(id) { + if (id === __HMR_ID__) + return id + }, + load(id) { + if (id === __HMR_ID__) + return __HMR_CODE__ + }, + transform(code, id) { + if (id === normalizePath(entry)) + return `import '${__HMR_ID__}';${code}` + + return code + }, + configureServer(server) { + if (!server.httpServer) + return + + server.httpServer.once('listening', async () => { + const entryPath = entry.replace(`${config.root}/`, '') + const { address, port } = server.httpServer!.address() as AddressInfo + const baseUrl = `http://${address}:${port}${config.base}` + const entryUrl = new URL(entryPath, baseUrl).href + + const pm: PM = await detectPm().catch(() => 'npm') + + await writeFile(indexMjs, getViteProxyModule(entryUrl, pm)) + }) + }, + closeBundle() { + if (existsSync(indexMjs)) + unlinkSync(indexMjs) + }, + } +} From d2ee85dacaa8f452c43cdc2547607ad7858f6448 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Sun, 31 Jul 2022 12:09:52 +0200 Subject: [PATCH 02/17] feat: allow HMR refresh, abort only on HMR reload --- src/node/plugins/hmr.ts | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts index a706f76..2ce48f9 100644 --- a/src/node/plugins/hmr.ts +++ b/src/node/plugins/hmr.ts @@ -3,21 +3,15 @@ import { writeFile } from 'node:fs/promises' import type { AddressInfo } from 'node:net' import { resolve } from 'pathe' import type { Plugin, ResolvedConfig } from 'vite' -import { normalizePath } from 'vite' import type { PM } from 'detect-package-manager' import { detect as detectPm } from 'detect-package-manager' +import { parseVueRequest } from '@vitejs/plugin-vue2' import type { ResolvedCliOptions } from '../types' -const __HMR_ID__ = '\0kirbyup:hmr' - -// Injected code to trigger full reloads for updates that aren't CSS +// Component reload (vs. refresh) doesn't work with Kirby so reload the page instead const __HMR_CODE__ = ` -if (import.meta.hot) { - import.meta.hot.on("vite:beforeUpdate", ({ updates }) => { - if (updates.some((update) => !update.path.match(/type=style&index=\\d+/))) { - import.meta.hot.invalidate(); - } - }); +if (typeof __VUE_HMR_RUNTIME__ !== 'undefined' && import.meta.hot) { + __VUE_HMR_RUNTIME__.reload = () => import.meta.hot.invalidate(); }`.trim() // Proxy JS file to "forward" the plugin script loaded by Kirby to the Vite server @@ -43,19 +37,18 @@ export default function kirbyupHmrPlugin(options: ResolvedCliOptions): Plugin { configResolved(resolvedConfig) { config = resolvedConfig }, - resolveId(id) { - if (id === __HMR_ID__) - return id - }, - load(id) { - if (id === __HMR_ID__) - return __HMR_CODE__ - }, + // Mirrors github.com/vitejs/vite-plugin-vue2/blob/d3d3a599f191bef5d6034993de92e2176e9577b3/src/index.ts#L156 transform(code, id) { - if (id === normalizePath(entry)) - return `import '${__HMR_ID__}';${code}` + const { query } = parseVueRequest(id) + + if (query.raw) + return + + if ((typeof id !== 'string' || /\0/.test(id)) && !query.vue) + return - return code + if (/\.vue$/.test(id) && !query.vue) + return `${code};${__HMR_CODE__}` }, configureServer(server) { if (!server.httpServer) From 2443f9ea62837e0d2a1237771ab6cbbf6fb9f76d Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:31:19 +0200 Subject: [PATCH 03/17] feat: rename module entry to _index.mjs makes it clearer that module entries are an internal, dev-only feature --- src/node/plugins/hmr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts index 2ce48f9..212e722 100644 --- a/src/node/plugins/hmr.ts +++ b/src/node/plugins/hmr.ts @@ -26,7 +26,7 @@ try { }`.trim() export default function kirbyupHmrPlugin(options: ResolvedCliOptions): Plugin { - const indexMjs = resolve(options.cwd, 'index.mjs') + const indexMjs = resolve(options.cwd, '_index.mjs') const entry = resolve(options.cwd, options.entry) let config: ResolvedConfig From aedc9a41379bd0d2ec5530f84dec308fb2444223 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 2 Aug 2022 20:38:04 +0200 Subject: [PATCH 04/17] docs: update examples to include serve script --- examples/eslint-and-prettier/package.json | 2 +- examples/tailwindcss/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/eslint-and-prettier/package.json b/examples/eslint-and-prettier/package.json index 35e6b55..ab923b2 100644 --- a/examples/eslint-and-prettier/package.json +++ b/examples/eslint-and-prettier/package.json @@ -1,7 +1,7 @@ { "private": true, "scripts": { - "dev": "kirbyup src/index.js --watch", + "dev": "kirbyup serve src/index.js", "build": "kirbyup src/index.js", "lint": "eslint \"src/**/*.{js,vue}\"", "lint:fix": "npm run lint -- --fix", diff --git a/examples/tailwindcss/package.json b/examples/tailwindcss/package.json index 8a7fa15..fabfa4a 100644 --- a/examples/tailwindcss/package.json +++ b/examples/tailwindcss/package.json @@ -1,7 +1,7 @@ { "private": true, "scripts": { - "dev": "kirbyup src/index.js --watch", + "dev": "kirbyup serve src/index.js", "build": "kirbyup src/index.js" }, "devDependencies": { From bc72da3475f163400ed40718d98190737282d5f6 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 2 Aug 2022 20:55:14 +0200 Subject: [PATCH 05/17] feat: reload on PHP change in serve mode --- package.json | 5 +++-- pnpm-lock.yaml | 39 +++++++++++++++++++++------------------ src/node/index.ts | 13 +++++++++++-- src/node/types.ts | 9 +++++++++ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 42621eb..5778c7f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kirbyup", "version": "1.3.2", - "packageManager": "pnpm@7.6.0", + "packageManager": "pnpm@7.8.0", "description": "Zero-config bundler for Kirby Panel plugins", "author": { "name": "Johann Schopplich", @@ -74,6 +74,7 @@ "cac": "^6.7.12", "chokidar": "^3.5.3", "consola": "^2.15.3", + "detect-package-manager": "^2.0.1", "magic-string": "^0.26.2", "pathe": "^0.3.3", "perfect-debounce": "^0.1.3", @@ -85,6 +86,7 @@ "sass": "^1.54.1", "unconfig": "^0.3.5", "vite": "^3.0.4", + "vite-plugin-live-reload": "^3.0.0", "vue": "^2.7.8" }, "devDependencies": { @@ -94,7 +96,6 @@ "@types/prompts": "^2.4.0", "@vitejs/plugin-vue2": "^1.1.2", "bumpp": "^8.2.1", - "detect-package-manager": "^2.0.1", "eslint": "^8.21.0", "fast-glob": "^3.2.11", "fs-extra": "^10.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 614e64e..bea4fb0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,6 +34,7 @@ specifiers: unbuild: ^0.7.6 unconfig: ^0.3.5 vite: ^3.0.4 + vite-plugin-live-reload: ^3.0.0 vitest: ^0.20.3 vue: ^2.7.8 @@ -42,6 +43,7 @@ dependencies: cac: 6.7.12 chokidar: 3.5.3 consola: 2.15.3 + detect-package-manager: 2.0.1 magic-string: 0.26.2 pathe: 0.3.3 perfect-debounce: 0.1.3 @@ -53,6 +55,7 @@ dependencies: sass: 1.54.1 unconfig: 0.3.5 vite: 3.0.4_sass@1.54.1 + vite-plugin-live-reload: 3.0.0 vue: 2.7.8 devDependencies: @@ -62,7 +65,6 @@ devDependencies: '@types/prompts': 2.4.0 '@vitejs/plugin-vue2': 1.1.2_2g7n65ohfqr2skd3fbvxhuubee_vite@3.0.4+vue@2.7.8 bumpp: 8.2.1 - detect-package-manager: 2.0.1 eslint: 8.21.0 fast-glob: 3.2.11 fs-extra: 10.1.0 @@ -1063,7 +1065,6 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 - dev: true /cssesc/3.0.0: resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} @@ -1139,7 +1140,7 @@ packages: engines: {node: '>=12'} dependencies: execa: 5.1.1 - dev: true + dev: false /dir-glob/3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} @@ -1855,7 +1856,7 @@ packages: onetime: 5.1.2 signal-exit: 3.0.7 strip-final-newline: 2.0.0 - dev: true + dev: false /fast-deep-equal/3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -1995,7 +1996,7 @@ packages: /get-stream/6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} - dev: true + dev: false /get-symbol-description/1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} @@ -2119,7 +2120,7 @@ packages: /human-signals/2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} - dev: true + dev: false /ignore/5.2.0: resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} @@ -2287,7 +2288,7 @@ packages: /is-stream/2.0.1: resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} engines: {node: '>=8'} - dev: true + dev: false /is-string/1.0.7: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} @@ -2311,7 +2312,6 @@ packages: /isexe/2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} - dev: true /jiti/1.14.0: resolution: {integrity: sha512-4IwstlaKQc9vCTC+qUXLM1hajy2ImiL9KnLvVYiaHOtS/v3wRjhLlGl121AmgDgx/O43uKmxownJghS5XMya2A==} @@ -2506,7 +2506,7 @@ packages: /merge-stream/2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} - dev: true + dev: false /merge2/1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} @@ -2533,7 +2533,7 @@ packages: /mimic-fn/2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} - dev: true + dev: false /min-indent/1.0.1: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} @@ -2630,7 +2630,7 @@ packages: engines: {node: '>=8'} dependencies: path-key: 3.1.1 - dev: true + dev: false /nth-check/2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} @@ -2707,7 +2707,7 @@ packages: engines: {node: '>=6'} dependencies: mimic-fn: 2.1.0 - dev: true + dev: false /optionator/0.9.1: resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} @@ -2819,7 +2819,6 @@ packages: /path-key/3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} - dev: true /path-parse/1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} @@ -3123,12 +3122,10 @@ packages: engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 - dev: true /shebang-regex/3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - dev: true /side-channel/1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} @@ -3140,7 +3137,7 @@ packages: /signal-exit/3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} - dev: true + dev: false /simple-git-hooks/2.8.0: resolution: {integrity: sha512-ocmZQORwa6x9mxg+gVIAp5o4wXiWOHGXyrDBA0+UxGKIEKOyFtL4LWNKkP/2ornQPdlnlDGDteVeYP5FjhIoWA==} @@ -3239,7 +3236,7 @@ packages: /strip-final-newline/2.0.0: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} - dev: true + dev: false /strip-indent/3.0.0: resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==} @@ -3456,6 +3453,13 @@ packages: spdx-expression-parse: 3.0.1 dev: true + /vite-plugin-live-reload/3.0.0: + resolution: {integrity: sha512-1ucmNc/UxiKvzudcVzgs+bTM3FHOLcso6U7kto2ujQsBoQolxAV7mMbqWtQ5jetm0hRiOvMada7QsP+IIK7+7w==} + dependencies: + chokidar: 3.5.3 + picocolors: 1.0.0 + dev: false + /vite/3.0.4_sass@1.54.1: resolution: {integrity: sha512-NU304nqnBeOx2MkQnskBQxVsa0pRAH5FphokTGmyy8M3oxbvw7qAXts2GORxs+h/2vKsD+osMhZ7An6yK6F1dA==} engines: {node: ^14.18.0 || >=16.0.0} @@ -3565,7 +3569,6 @@ packages: hasBin: true dependencies: isexe: 2.0.0 - dev: true /word-wrap/1.2.3: resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} diff --git a/src/node/index.ts b/src/node/index.ts index c9ca4a7..d284cbe 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -18,6 +18,7 @@ import { debounce } from 'perfect-debounce' import colors from 'picocolors' import type { RollupOutput } from 'rollup' import type { InlineConfig } from 'vite' +import liveReloadPlugin from 'vite-plugin-live-reload' import { name, version } from '../../package.json' import { PrettyError, handleError } from './errors' import { printFileInfo, toArray } from './utils' @@ -36,10 +37,18 @@ let resolvedPostCssConfig: PostCSSConfigResult async function createServer(options: ResolvedCliOptions) { const aliasDir = resolve(options.cwd, dirname(options.entry)) - const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig + const { alias = {}, extendViteConfig = {}, reloadOnPhpChange = true } = resolvedKirbyupConfig + + const defaultWatchConf: Parameters = ['./**/*.php'] + const watchConf = typeof reloadOnPhpChange === 'boolean' ? defaultWatchConf : reloadOnPhpChange + + const plugins = [vuePlugin(), kirbyupAutoImportPlugin(), kirbyupHmrPlugin(options)] + + if (reloadOnPhpChange) + plugins.push(liveReloadPlugin(...watchConf)) const defaultConfig: InlineConfig = { - plugins: [vuePlugin(), kirbyupAutoImportPlugin(), kirbyupHmrPlugin(options)], + plugins, // Input needs to be specified so dep pre-bundling works build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, resolve: { diff --git a/src/node/types.ts b/src/node/types.ts index a28f66e..0db1836 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -1,5 +1,6 @@ import type { AliasOptions, InlineConfig } from 'vite' import type * as Postcss from 'postcss' +import type liveReloadPlugin from 'vite-plugin-live-reload' export type MarkRequired = Exclude & Required> @@ -28,6 +29,14 @@ export interface UserConfig { */ alias?: AliasOptions + /** + * Controls whether the plugin's PHP files are watched for changes. + * Pass true or false to enable or disable. Alternatively you can pass + * an array of arguments that are passed to vite-plugin-live-reload. + * The default is to watch all PHP files in the plugin directory. (./\*\*\/*.php) + */ + reloadOnPhpChange: boolean | Parameters + /** * Extends Vite's configuration. Will be merged with kirbyup's * default configuration. Be careful what to extend. From f165789af930def06d49541328df7fee508e7267 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:27:38 +0200 Subject: [PATCH 06/17] feat: live-reload via CLI arg, CLI help, refactor --- package.json | 2 +- pnpm-lock.yaml | 13 +-- src/node/cli-start.ts | 67 ++++++-------- src/node/index.ts | 192 ++++++++++++++++------------------------ src/node/plugins/hmr.ts | 11 +-- src/node/types.ts | 29 +++--- 6 files changed, 131 insertions(+), 183 deletions(-) diff --git a/package.json b/package.json index 5778c7f..d96c9f5 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "sass": "^1.54.1", "unconfig": "^0.3.5", "vite": "^3.0.4", - "vite-plugin-live-reload": "^3.0.0", + "vite-plugin-full-reload": "^1.0.3", "vue": "^2.7.8" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bea4fb0..66e69b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,7 +34,7 @@ specifiers: unbuild: ^0.7.6 unconfig: ^0.3.5 vite: ^3.0.4 - vite-plugin-live-reload: ^3.0.0 + vite-plugin-full-reload: ^1.0.3 vitest: ^0.20.3 vue: ^2.7.8 @@ -55,7 +55,7 @@ dependencies: sass: 1.54.1 unconfig: 0.3.5 vite: 3.0.4_sass@1.54.1 - vite-plugin-live-reload: 3.0.0 + vite-plugin-full-reload: 1.0.3_vite@3.0.4 vue: 2.7.8 devDependencies: @@ -3453,11 +3453,14 @@ packages: spdx-expression-parse: 3.0.1 dev: true - /vite-plugin-live-reload/3.0.0: - resolution: {integrity: sha512-1ucmNc/UxiKvzudcVzgs+bTM3FHOLcso6U7kto2ujQsBoQolxAV7mMbqWtQ5jetm0hRiOvMada7QsP+IIK7+7w==} + /vite-plugin-full-reload/1.0.3_vite@3.0.4: + resolution: {integrity: sha512-owIZz/tGXFyUzIDzbu4KBpxrpd08BO+tuWqZABCug5C2laNTwOS4mcDMsMKnXT7B7WR8oRd+BI6a2kVDtsan3w==} + peerDependencies: + vite: ^2 || ^3 dependencies: - chokidar: 3.5.3 picocolors: 1.0.0 + picomatch: 2.3.1 + vite: 3.0.4_sass@1.54.1 dev: false /vite/3.0.4_sass@1.54.1: diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index 8982ce5..dcee4e7 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -1,56 +1,45 @@ import { cac } from 'cac' import { name, version } from '../../package.json' -import type { CliOptions } from './types' import { build, serve } from './index' -export async function startCli( - cwd = process.cwd(), - argv = process.argv, - options: CliOptions = {}, -) { +export async function startCli(cwd = process.cwd(), argv = process.argv) { const cli = cac(name) cli - .command('serve [file]', 'Panel input file', { - ignoreOptionDefaultValue: true, - }) - .action(async (file, flags) => { - Object.assign(options, { - cwd, - ...flags, - }) - - if (file) - options.entry = file - - const server = await serve(options) - process.on('SIGINT', () => server.close()) - }) - - cli - .command('[file]', 'Panel input file', { - ignoreOptionDefaultValue: true, - }) - .option('-d, --out-dir ', 'Output directory', { - default: cwd, - }) + .command('', 'Compile the panel plugin to index.js and index.css') + .option('-d, --out-dir ', 'Output directory', { default: cwd }) .option( '-w, --watch [path]', - 'Watch for file changes. If no path is specified, the folder of the input file will be watched. Repeat "--watch" for multiple paths.', + 'Watch for file changes. If no path is specified, the folder of the input file will be watched', + { default: false }, ) - .action(async (file: string, flags) => { - Object.assign(options, { - cwd, - ...flags, - }) + .example('kirbyup src/index.js') + .example('kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo') + .example('kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n') + .action(async (file: string, options: { outDir: string; watch: boolean | string | string[] }) => { + await build({ cwd, entry: file, ...options }) + }) - if (file) - options.entry = file + cli + .command('serve ', 'Start development server with live reload') + .option('--no-watch', 'Don\'t watch .php files for changes', { default: '\0' }) + .option('-w, --watch ', 'Watch additional files', { default: './**/*.php' }) + .example('kirbyup serve src/index.js') + .example('kirbyup serve src/index.js --no-watch') + .example('kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n') + .action(async (file: string, options: { watch: false | string | string[] }) => { + const server = await serve({ cwd, entry: file, ...options }) - await build(options) + process.on('SIGINT', () => server.close()) + process.on('exit', () => server.close()) + process.on('uncaughtException', () => { + process.exitCode = 1 + server.close() + }) }) - cli.help() + // Filter out unnecessary "default" output for negated options (zerobyte acts as marker) + cli.help(s => s.map(msg => ({ ...msg, body: msg.body.replace(' (default: \0)', '') }))) cli.version(version) // Parse CLI args without running the command to diff --git a/src/node/index.ts b/src/node/index.ts index d284cbe..14d7f8c 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -1,11 +1,7 @@ import { existsSync } from 'node:fs' import { readFile } from 'node:fs/promises' import { basename, dirname, resolve } from 'pathe' -import { - build as _build, - createServer as _createServer, - mergeConfig, -} from 'vite' +import { build as _build, createServer, mergeConfig } from 'vite' import vuePlugin from '@vitejs/plugin-vue2' // eslint-disable-next-line import/default import postcssrc from 'postcss-load-config' @@ -18,67 +14,46 @@ import { debounce } from 'perfect-debounce' import colors from 'picocolors' import type { RollupOutput } from 'rollup' import type { InlineConfig } from 'vite' -import liveReloadPlugin from 'vite-plugin-live-reload' +import fullReloadPlugin from 'vite-plugin-full-reload' import { name, version } from '../../package.json' import { PrettyError, handleError } from './errors' import { printFileInfo, toArray } from './utils' import { loadConfig } from './config' import kirbyupAutoImportPlugin from './plugins/auto-import' import kirbyupHmrPlugin from './plugins/hmr' -import type { - CliOptions, - PostCSSConfigResult, - ResolvedCliOptions, - UserConfig, -} from './types' +import type { BaseOptions, BuildOptions, GetViteConfigFn, PostCSSConfigResult, ServeOptions, UserConfig } from './types' let resolvedKirbyupConfig: UserConfig let resolvedPostCssConfig: PostCSSConfigResult -async function createServer(options: ResolvedCliOptions) { +const getViteConfig: GetViteConfigFn = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) - const { alias = {}, extendViteConfig = {}, reloadOnPhpChange = true } = resolvedKirbyupConfig - - const defaultWatchConf: Parameters = ['./**/*.php'] - const watchConf = typeof reloadOnPhpChange === 'boolean' ? defaultWatchConf : reloadOnPhpChange - - const plugins = [vuePlugin(), kirbyupAutoImportPlugin(), kirbyupHmrPlugin(options)] - - if (reloadOnPhpChange) - plugins.push(liveReloadPlugin(...watchConf)) + const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig - const defaultConfig: InlineConfig = { - plugins, - // Input needs to be specified so dep pre-bundling works - build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, + const baseConfig: InlineConfig = { resolve: { - alias: { - '~/': `${aliasDir}/`, - '@/': `${aliasDir}/`, - ...alias, - }, - }, - css: { - postcss: resolvedPostCssConfig, + alias: { '~/': `${aliasDir}/`, '@/': `${aliasDir}/`, ...alias }, }, + plugins: [vuePlugin(), kirbyupAutoImportPlugin()], + css: { postcss: resolvedPostCssConfig }, envPrefix: ['VITE_', 'KIRBYUP_'], logLevel: 'warn', } - return _createServer(mergeConfig(defaultConfig, extendViteConfig)) -} + if (command === 'serve') { + const serveConfig: InlineConfig = mergeConfig(baseConfig, { + plugins: [kirbyupHmrPlugin(options), options.watch && fullReloadPlugin(options.watch)], + // Input needs to be specified so dep pre-bundling works + build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, + }) -async function generate(options: ResolvedCliOptions) { - let result: Awaited> | undefined + return mergeConfig(serveConfig, extendViteConfig) as InlineConfig + } const mode = options.watch ? 'development' : 'production' - const outDir = options.outDir || options.cwd - const aliasDir = resolve(options.cwd, dirname(options.entry)) - const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig - const defaultConfig: InlineConfig = { + const buildConfig: InlineConfig = mergeConfig(baseConfig, { mode, - plugins: [vuePlugin(), kirbyupAutoImportPlugin()], build: { lib: { entry: resolve(options.cwd, options.entry), @@ -87,39 +62,39 @@ async function generate(options: ResolvedCliOptions) { fileName: () => 'index.js', }, minify: mode === 'production', - outDir, + outDir: options.outDir, emptyOutDir: false, rollupOptions: { external: ['vue'], output: { assetFileNames: 'index.[ext]', - globals: { - vue: 'Vue', - }, + globals: { vue: 'Vue' }, }, }, }, - resolve: { - alias: { - '~/': `${aliasDir}/`, - '@/': `${aliasDir}/`, - ...alias, - }, - }, - css: { - postcss: resolvedPostCssConfig, - }, - envPrefix: ['VITE_', 'KIRBYUP_'], - logLevel: 'warn', - } + }) + + return mergeConfig(buildConfig, extendViteConfig) as InlineConfig +} + +function ensureEntry(options: BaseOptions) { + // Ensure entry exists + if (!existsSync(resolve(options.cwd, options.entry))) + throw new PrettyError(`Cannot find "${options.entry}"`) +} + +async function generate(options: BuildOptions) { + const config = getViteConfig('build', options) + + let result: Awaited> | undefined try { - result = await _build(mergeConfig(defaultConfig, extendViteConfig)) + result = await _build(config) } catch (error) { consola.error('Build failed') - if (mode === 'production') + if (config.mode === 'production') throw error } @@ -141,9 +116,9 @@ async function generate(options: ResolvedCliOptions) { } of output) { await printFileInfo( options.cwd, - outDir, + options.outDir, fileName, - code ?? await readFile(resolve(outDir, fileName), 'utf8'), + code ?? await readFile(resolve(options.outDir, fileName), 'utf8'), type, longest, ) @@ -153,59 +128,9 @@ async function generate(options: ResolvedCliOptions) { return result } -export async function resolveOptions(options: CliOptions) { - options.cwd = options.cwd || process.cwd() - - if (!options.entry) { - throw new PrettyError( - `No input file, try ${colors.cyan(`${name} `)}`, - ) - } - - // Ensure entry exists - if (!existsSync(resolve(options.cwd, options.entry))) - throw new PrettyError(`Cannot find "${options.entry}"`) - - return options as ResolvedCliOptions -} - -export async function serve(_options: CliOptions) { - const options = await resolveOptions(_options) - const { cwd } = options - - // Resolve kirbyup config - const { config } = await loadConfig(cwd) - resolvedKirbyupConfig = config - - // Resolve postcss config - try { - // @ts-expect-error: types won't match - resolvedPostCssConfig = await postcssrc({}) - } - catch (err: any) { - if (!/No PostCSS Config found/.test(err.message)) - throw err - resolvedPostCssConfig = { - plugins: [postcssLogical(), postcssDirPseudoClass()], - } - } - - if (!process.env.VITEST) { - consola.log(colors.green(`${name} v${version}`)) - consola.info('Starting development server...') - } - - const server = await createServer(options) +export async function build(options: BuildOptions) { + ensureEntry(options) - await server.listen() - if (!process.env.VITEST) - consola.success(`Server is listening on :${server.config.server.port}`) - - return server -} - -export async function build(_options: CliOptions) { - const options = await resolveOptions(_options) const { cwd } = options // Resolve kirbyup config @@ -300,3 +225,38 @@ export async function build(_options: CliOptions) { startWatcher() } +export async function serve(options: ServeOptions) { + ensureEntry(options) + + const { cwd } = options + + // Resolve kirbyup config + const { config } = await loadConfig(cwd) + resolvedKirbyupConfig = config + + // Resolve postcss config + try { + // @ts-expect-error: types won't match + resolvedPostCssConfig = await postcssrc({}) + } + catch (err: any) { + if (!/No PostCSS Config found/.test(err.message)) + throw err + resolvedPostCssConfig = { + plugins: [postcssLogical(), postcssDirPseudoClass()], + } + } + + if (!process.env.VITEST) { + consola.log(colors.green(`${name} v${version}`)) + consola.info('Starting development server...') + } + + const server = await createServer(getViteConfig('serve', options)) + + await server.listen() + if (!process.env.VITEST) + consola.success(`Server is listening on :${server.config.server.port}`) + + return server +} diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts index 212e722..58813c2 100644 --- a/src/node/plugins/hmr.ts +++ b/src/node/plugins/hmr.ts @@ -6,7 +6,7 @@ import type { Plugin, ResolvedConfig } from 'vite' import type { PM } from 'detect-package-manager' import { detect as detectPm } from 'detect-package-manager' import { parseVueRequest } from '@vitejs/plugin-vue2' -import type { ResolvedCliOptions } from '../types' +import type { ServeOptions } from '../types' // Component reload (vs. refresh) doesn't work with Kirby so reload the page instead const __HMR_CODE__ = ` @@ -25,17 +25,18 @@ try { throw err; }`.trim() -export default function kirbyupHmrPlugin(options: ResolvedCliOptions): Plugin { - const indexMjs = resolve(options.cwd, '_index.mjs') - const entry = resolve(options.cwd, options.entry) - +export default function kirbyupHmrPlugin(options: ServeOptions): Plugin { let config: ResolvedConfig + let entry: string + let indexMjs: string return { name: 'kirbyup:hmr', apply: 'serve', configResolved(resolvedConfig) { config = resolvedConfig + entry = resolve(config.root, options.entry) + indexMjs = resolve(config.root, 'index.dev.mjs') }, // Mirrors github.com/vitejs/vite-plugin-vue2/blob/d3d3a599f191bef5d6034993de92e2176e9577b3/src/index.ts#L156 transform(code, id) { diff --git a/src/node/types.ts b/src/node/types.ts index 0db1836..cfefc05 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -1,18 +1,19 @@ import type { AliasOptions, InlineConfig } from 'vite' import type * as Postcss from 'postcss' -import type liveReloadPlugin from 'vite-plugin-live-reload' -export type MarkRequired = Exclude & -Required> +export interface BaseOptions { + cwd: string + entry: string +} -export interface CliOptions { - cwd?: string - entry?: string - outDir?: string - watch?: boolean | string | Array +export interface ServeOptions extends BaseOptions { + watch: false | string | string[] } -export type ResolvedCliOptions = MarkRequired +export interface BuildOptions extends BaseOptions { + outDir: string + watch: boolean | string | string[] +} export interface UserConfig { /** @@ -29,14 +30,6 @@ export interface UserConfig { */ alias?: AliasOptions - /** - * Controls whether the plugin's PHP files are watched for changes. - * Pass true or false to enable or disable. Alternatively you can pass - * an array of arguments that are passed to vite-plugin-live-reload. - * The default is to watch all PHP files in the plugin directory. (./\*\*\/*.php) - */ - reloadOnPhpChange: boolean | Parameters - /** * Extends Vite's configuration. Will be merged with kirbyup's * default configuration. Be careful what to extend. @@ -48,3 +41,5 @@ export interface PostCSSConfigResult { options?: Postcss.ProcessOptions plugins: Postcss.Plugin[] } + +export type GetViteConfigFn = (...args: ['build', BuildOptions] | ['serve', ServeOptions]) => InlineConfig From e9970069ba97e72f55f0aa7c88cabeac62f5c553 Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Thu, 4 Aug 2022 20:01:06 +0200 Subject: [PATCH 07/17] fix: only call server.close() if still listening --- src/node/cli-start.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index dcee4e7..f1d9427 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -1,4 +1,5 @@ import { cac } from 'cac' +import consola from 'consola' import { name, version } from '../../package.json' import { build, serve } from './index' @@ -30,11 +31,14 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) { .action(async (file: string, options: { watch: false | string | string[] }) => { const server = await serve({ cwd, entry: file, ...options }) - process.on('SIGINT', () => server.close()) - process.on('exit', () => server.close()) - process.on('uncaughtException', () => { + const close = () => server.httpServer?.listening && server.close() + + process.on('SIGINT', () => close()) + process.on('exit', () => close()) + process.on('uncaughtException', (err) => { + consola.error(err) process.exitCode = 1 - server.close() + close() }) }) From 9bbadc8f8de86fcc69b32efa0c79fd888be604ab Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 12:53:44 +0200 Subject: [PATCH 08/17] fix: set server.origin to serve assets in dev mode depends on https://github.com/vuejs/vue/pull/12732 --- src/node/index.ts | 5 +++-- src/node/types.ts | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/node/index.ts b/src/node/index.ts index 14d7f8c..5f1bcd4 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -28,7 +28,7 @@ let resolvedPostCssConfig: PostCSSConfigResult const getViteConfig: GetViteConfigFn = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) - const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig + const { alias = {}, port = 5177, extendViteConfig = {} } = resolvedKirbyupConfig const baseConfig: InlineConfig = { resolve: { @@ -45,7 +45,8 @@ const getViteConfig: GetViteConfigFn = (command, options) => { plugins: [kirbyupHmrPlugin(options), options.watch && fullReloadPlugin(options.watch)], // Input needs to be specified so dep pre-bundling works build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, - }) + server: { port, strictPort: true, origin: `http://localhost:${port}` }, + } as InlineConfig) return mergeConfig(serveConfig, extendViteConfig) as InlineConfig } diff --git a/src/node/types.ts b/src/node/types.ts index cfefc05..b704b47 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -30,6 +30,11 @@ export interface UserConfig { */ alias?: AliasOptions + /** + * Specifies the port for the development server. + */ + port?: number + /** * Extends Vite's configuration. Will be merged with kirbyup's * default configuration. Be careful what to extend. From 97b0e53703ce29d810f83518b50b6b74f4b85870 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:41:27 +0200 Subject: [PATCH 09/17] fix: always pass array to vite-full-reload-plugin https://github.com/ElMassimo/vite-plugin-full-reload/issues/9 --- src/node/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/node/index.ts b/src/node/index.ts index 5f1bcd4..97fb289 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -26,6 +26,10 @@ import type { BaseOptions, BuildOptions, GetViteConfigFn, PostCSSConfigResult, S let resolvedKirbyupConfig: UserConfig let resolvedPostCssConfig: PostCSSConfigResult +function ensureArray(arr: T | T[]): T[] { + return Array.isArray(arr) ? arr : [arr] +} + const getViteConfig: GetViteConfigFn = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) const { alias = {}, port = 5177, extendViteConfig = {} } = resolvedKirbyupConfig @@ -41,8 +45,12 @@ const getViteConfig: GetViteConfigFn = (command, options) => { } if (command === 'serve') { + // the paths to watch must be an array until this is fixed: + // https://github.com/ElMassimo/vite-plugin-full-reload/issues/9 + const watchOptions = options.watch && ensureArray(options.watch) + const serveConfig: InlineConfig = mergeConfig(baseConfig, { - plugins: [kirbyupHmrPlugin(options), options.watch && fullReloadPlugin(options.watch)], + plugins: [kirbyupHmrPlugin(options), watchOptions && fullReloadPlugin(watchOptions)], // Input needs to be specified so dep pre-bundling works build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, server: { port, strictPort: true, origin: `http://localhost:${port}` }, @@ -73,7 +81,7 @@ const getViteConfig: GetViteConfigFn = (command, options) => { }, }, }, - }) + } as InlineConfig) return mergeConfig(buildConfig, extendViteConfig) as InlineConfig } From d0eb49e318df947bbf7641e80a9df918f2c05c77 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:49:57 +0200 Subject: [PATCH 10/17] feat: specify port via cli instead of kirbyup conf --- src/node/cli-start.ts | 5 +++-- src/node/index.ts | 4 +++- src/node/types.ts | 6 +----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index f1d9427..575cd4d 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -25,10 +25,11 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) { .command('serve ', 'Start development server with live reload') .option('--no-watch', 'Don\'t watch .php files for changes', { default: '\0' }) .option('-w, --watch ', 'Watch additional files', { default: './**/*.php' }) + .option('-p, --port ', 'Port for the development server', { default: 5177 }) .example('kirbyup serve src/index.js') - .example('kirbyup serve src/index.js --no-watch') + .example('kirbyup serve src/index.js --no-watch --port 3003') .example('kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n') - .action(async (file: string, options: { watch: false | string | string[] }) => { + .action(async (file: string, options: { watch: false | string | string[]; port: number }) => { const server = await serve({ cwd, entry: file, ...options }) const close = () => server.httpServer?.listening && server.close() diff --git a/src/node/index.ts b/src/node/index.ts index 97fb289..558178d 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -32,7 +32,7 @@ function ensureArray(arr: T | T[]): T[] { const getViteConfig: GetViteConfigFn = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) - const { alias = {}, port = 5177, extendViteConfig = {} } = resolvedKirbyupConfig + const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig const baseConfig: InlineConfig = { resolve: { @@ -48,11 +48,13 @@ const getViteConfig: GetViteConfigFn = (command, options) => { // the paths to watch must be an array until this is fixed: // https://github.com/ElMassimo/vite-plugin-full-reload/issues/9 const watchOptions = options.watch && ensureArray(options.watch) + const port = options.port const serveConfig: InlineConfig = mergeConfig(baseConfig, { plugins: [kirbyupHmrPlugin(options), watchOptions && fullReloadPlugin(watchOptions)], // Input needs to be specified so dep pre-bundling works build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, + // Specify origin so asset URLs include Vite server host server: { port, strictPort: true, origin: `http://localhost:${port}` }, } as InlineConfig) diff --git a/src/node/types.ts b/src/node/types.ts index b704b47..c61b1d2 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -8,6 +8,7 @@ export interface BaseOptions { export interface ServeOptions extends BaseOptions { watch: false | string | string[] + port: number } export interface BuildOptions extends BaseOptions { @@ -30,11 +31,6 @@ export interface UserConfig { */ alias?: AliasOptions - /** - * Specifies the port for the development server. - */ - port?: number - /** * Extends Vite's configuration. Will be merged with kirbyup's * default configuration. Be careful what to extend. From 5d21ce674f85097610a9abd25f0be9b7ebba195d Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:35:04 +0200 Subject: [PATCH 11/17] refactor: update reload-plugin, remove workaround --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- src/node/index.ts | 9 +-------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index d96c9f5..3685778 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "sass": "^1.54.1", "unconfig": "^0.3.5", "vite": "^3.0.4", - "vite-plugin-full-reload": "^1.0.3", + "vite-plugin-full-reload": "^1.0.4", "vue": "^2.7.8" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66e69b8..12f6aff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,7 +34,7 @@ specifiers: unbuild: ^0.7.6 unconfig: ^0.3.5 vite: ^3.0.4 - vite-plugin-full-reload: ^1.0.3 + vite-plugin-full-reload: ^1.0.4 vitest: ^0.20.3 vue: ^2.7.8 @@ -55,7 +55,7 @@ dependencies: sass: 1.54.1 unconfig: 0.3.5 vite: 3.0.4_sass@1.54.1 - vite-plugin-full-reload: 1.0.3_vite@3.0.4 + vite-plugin-full-reload: 1.0.4_vite@3.0.4 vue: 2.7.8 devDependencies: @@ -3453,8 +3453,8 @@ packages: spdx-expression-parse: 3.0.1 dev: true - /vite-plugin-full-reload/1.0.3_vite@3.0.4: - resolution: {integrity: sha512-owIZz/tGXFyUzIDzbu4KBpxrpd08BO+tuWqZABCug5C2laNTwOS4mcDMsMKnXT7B7WR8oRd+BI6a2kVDtsan3w==} + /vite-plugin-full-reload/1.0.4_vite@3.0.4: + resolution: {integrity: sha512-9WejQII6zJ++m/YE173Zvl2jq4cqa404KNrVT+JDzDnqaGRq5UvOvA48fnsSWPIMXFV7S0dq5+sZqcSB+tKBgA==} peerDependencies: vite: ^2 || ^3 dependencies: diff --git a/src/node/index.ts b/src/node/index.ts index 558178d..1e24811 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -26,10 +26,6 @@ import type { BaseOptions, BuildOptions, GetViteConfigFn, PostCSSConfigResult, S let resolvedKirbyupConfig: UserConfig let resolvedPostCssConfig: PostCSSConfigResult -function ensureArray(arr: T | T[]): T[] { - return Array.isArray(arr) ? arr : [arr] -} - const getViteConfig: GetViteConfigFn = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig @@ -45,13 +41,10 @@ const getViteConfig: GetViteConfigFn = (command, options) => { } if (command === 'serve') { - // the paths to watch must be an array until this is fixed: - // https://github.com/ElMassimo/vite-plugin-full-reload/issues/9 - const watchOptions = options.watch && ensureArray(options.watch) const port = options.port const serveConfig: InlineConfig = mergeConfig(baseConfig, { - plugins: [kirbyupHmrPlugin(options), watchOptions && fullReloadPlugin(watchOptions)], + plugins: [kirbyupHmrPlugin(options), options.watch && fullReloadPlugin(options.watch)], // Input needs to be specified so dep pre-bundling works build: { rollupOptions: { input: resolve(options.cwd, options.entry) } }, // Specify origin so asset URLs include Vite server host From cf4ecade10fc783541f0e630c329abf2cb446d55 Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:36:05 +0200 Subject: [PATCH 12/17] feat: make sure index.dev.mjs is gone after build --- src/node/index.ts | 2 ++ src/node/plugins/build-cleanup.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/node/plugins/build-cleanup.ts diff --git a/src/node/index.ts b/src/node/index.ts index 1e24811..e5ba008 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -21,6 +21,7 @@ import { printFileInfo, toArray } from './utils' import { loadConfig } from './config' import kirbyupAutoImportPlugin from './plugins/auto-import' import kirbyupHmrPlugin from './plugins/hmr' +import kirbyupBuildCleanupPlugin from './plugins/build-cleanup' import type { BaseOptions, BuildOptions, GetViteConfigFn, PostCSSConfigResult, ServeOptions, UserConfig } from './types' let resolvedKirbyupConfig: UserConfig @@ -57,6 +58,7 @@ const getViteConfig: GetViteConfigFn = (command, options) => { const mode = options.watch ? 'development' : 'production' const buildConfig: InlineConfig = mergeConfig(baseConfig, { + plugins: [kirbyupBuildCleanupPlugin()], mode, build: { lib: { diff --git a/src/node/plugins/build-cleanup.ts b/src/node/plugins/build-cleanup.ts new file mode 100644 index 0000000..35b5b82 --- /dev/null +++ b/src/node/plugins/build-cleanup.ts @@ -0,0 +1,20 @@ +import { existsSync, unlinkSync } from 'node:fs' +import { resolve } from 'pathe' +import type { Plugin, ResolvedConfig } from 'vite' + +export default function kirbyupBuildCleanupPlugin(): Plugin { + let config: ResolvedConfig + let indexMjs: string + + return { + name: 'kirbyup:build-cleanup', + configResolved(resolvedConfig) { + config = resolvedConfig + indexMjs = resolve(config.root, 'index.dev.mjs') + }, + writeBundle() { + if (existsSync(indexMjs)) + unlinkSync(indexMjs) + }, + } +} From 6a58354b12ee819038a447d94fc0748d2c3a2029 Mon Sep 17 00:00:00 2001 From: Jonas Kuske Date: Wed, 10 Aug 2022 01:56:25 +0200 Subject: [PATCH 13/17] feat: set index.dev.mjs location with --out-dir --- src/node/cli-start.ts | 3 ++- src/node/index.ts | 2 +- src/node/plugins/build-cleanup.ts | 5 +++-- src/node/plugins/hmr.ts | 2 +- src/node/types.ts | 1 + 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index 575cd4d..b014dd7 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -26,10 +26,11 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) { .option('--no-watch', 'Don\'t watch .php files for changes', { default: '\0' }) .option('-w, --watch ', 'Watch additional files', { default: './**/*.php' }) .option('-p, --port ', 'Port for the development server', { default: 5177 }) + .option('-d, --out-dir ', 'Output directory') .example('kirbyup serve src/index.js') .example('kirbyup serve src/index.js --no-watch --port 3003') .example('kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n') - .action(async (file: string, options: { watch: false | string | string[]; port: number }) => { + .action(async (file: string, options: { watch: false | string | string[]; port: number; outDir?: string }) => { const server = await serve({ cwd, entry: file, ...options }) const close = () => server.httpServer?.listening && server.close() diff --git a/src/node/index.ts b/src/node/index.ts index e5ba008..1e2eb00 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -58,7 +58,7 @@ const getViteConfig: GetViteConfigFn = (command, options) => { const mode = options.watch ? 'development' : 'production' const buildConfig: InlineConfig = mergeConfig(baseConfig, { - plugins: [kirbyupBuildCleanupPlugin()], + plugins: [kirbyupBuildCleanupPlugin(options)], mode, build: { lib: { diff --git a/src/node/plugins/build-cleanup.ts b/src/node/plugins/build-cleanup.ts index 35b5b82..958bfbb 100644 --- a/src/node/plugins/build-cleanup.ts +++ b/src/node/plugins/build-cleanup.ts @@ -1,8 +1,9 @@ import { existsSync, unlinkSync } from 'node:fs' import { resolve } from 'pathe' import type { Plugin, ResolvedConfig } from 'vite' +import type { BuildOptions } from '../types' -export default function kirbyupBuildCleanupPlugin(): Plugin { +export default function kirbyupBuildCleanupPlugin(options: BuildOptions): Plugin { let config: ResolvedConfig let indexMjs: string @@ -10,7 +11,7 @@ export default function kirbyupBuildCleanupPlugin(): Plugin { name: 'kirbyup:build-cleanup', configResolved(resolvedConfig) { config = resolvedConfig - indexMjs = resolve(config.root, 'index.dev.mjs') + indexMjs = resolve(config.root, options.outDir, 'index.dev.mjs') }, writeBundle() { if (existsSync(indexMjs)) diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts index 58813c2..a30f0eb 100644 --- a/src/node/plugins/hmr.ts +++ b/src/node/plugins/hmr.ts @@ -36,7 +36,7 @@ export default function kirbyupHmrPlugin(options: ServeOptions): Plugin { configResolved(resolvedConfig) { config = resolvedConfig entry = resolve(config.root, options.entry) - indexMjs = resolve(config.root, 'index.dev.mjs') + indexMjs = resolve(config.root, options.outDir || '', 'index.dev.mjs') }, // Mirrors github.com/vitejs/vite-plugin-vue2/blob/d3d3a599f191bef5d6034993de92e2176e9577b3/src/index.ts#L156 transform(code, id) { diff --git a/src/node/types.ts b/src/node/types.ts index c61b1d2..e837ff3 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -9,6 +9,7 @@ export interface BaseOptions { export interface ServeOptions extends BaseOptions { watch: false | string | string[] port: number + outDir?: string } export interface BuildOptions extends BaseOptions { From d669244d77fc1ec49019fea38c02738bd42502b3 Mon Sep 17 00:00:00 2001 From: Jonas Kuske Date: Wed, 10 Aug 2022 02:47:32 +0200 Subject: [PATCH 14/17] docs: update README for serve command --- README.md | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e7142eb..35eb886 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration - 🍂 Lightweight, robust and tested - ⚡️ Fast compilation with Vite/esbuild -- 🔍 Watch mode +- 🔄 Hot Module Replacement and Watch mode - \*️⃣ `kirbyup.import` to [auto-import blocks & fields](#auto-import-blocks-and-fields) - 🎒 [PostCSS support](#postcss) - 🧭 [Path resolve aliases](#path-resolve-aliases) @@ -36,7 +36,7 @@ If you want to use kirbyup right away, there is no need to install it. Simply ca ```json { "scripts": { - "dev": "npx -y kirbyup src/index.js --watch", + "dev": "npx -y kirbyup serve src/index.js", "build": "npx -y kirbyup src/index.js" } } @@ -55,7 +55,7 @@ Example package configuration: ```json { "scripts": { - "dev": "kirbyup src/index.js --watch", + "dev": "kirbyup serve src/index.js", "build": "kirbyup src/index.js" }, "devDependencies": { @@ -70,23 +70,13 @@ Global installation is supported as well, but not recommended. ### Development -Rebuild the Panel plugin on any file changes: +Start a development server for the panel plugin: ```bash -kirbyup src/index.js --watch +kirbyup serve src/index.js ``` -You can also specify the directories to be watched. By default, if no path is specified, kirbyup watches the directory specified by the input file (`src` for the example above). - -```bash -kirbyup src/index.js --watch src -``` - -You can specify more than a single directory: - -```bash -kirbyup src/index.js --watch src --watch libs -``` +This creates `./index.dev.mjs`, telling Kirby to load the development version of the plugin from the dev server started by `kirbyup serve`, enhanced by features like hot module replacement and auto-reload. ### Production @@ -94,7 +84,7 @@ kirbyup src/index.js --watch src --watch libs kirbyup src/index.js ``` -The final panel plugin will be bundled, minified, and written into the current directory as `./index.js`. +The final panel plugin will be bundled, minified, and written into the current directory as `./index.js` and `./index.css`. ## Built-in Features @@ -222,15 +212,38 @@ For a complete list of options, take a look at the [Vite configuration options]( ## Options -> Inspect all available options with `kirbyup --help`. +> Inspect all available options with `kirbyup --help` and `kirbyup serve --help`. + +### `kirbyup ` -### `--out-dir` +##### `--out-dir ` The output directory to save the processed code into. Defaults to the current working directory. -### `--watch` +##### `--watch [path]` + +Enables watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat `--watch` for multiple paths. + +### `kirbyup serve ` + +##### `--port ` + +The port for the development server to run on. Defaults to `5177`. + +##### `--out-dir ` + +The output directory where the plugin file read by Kirby is saved. Defaults to the project root. + +##### `--watch ` + +Specifies additional files that should be watched for changes, with changes causing the page to reload. Repeat `--watch` for multiple paths. + +> 💡 By default, kirbyup will watch all PHP files (`./**/*.php`) in the plugin directory and reload the page if it detects changes. Using `--watch` to set your own path overrides this setting, so you need to add the PHP glob explicitly if you want to keep the behavior: `--watch ./my/files/* --watch ./**/*.php` + +##### `--no-watch` + +Disables the default behavior of watching all PHP files for changes. -Sets the watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat `--watch` for multiple paths. ## Credits From 4d249bf6acf5d82a5d7acbb0878cbcfefeeccfa3 Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Wed, 10 Aug 2022 09:32:53 +0200 Subject: [PATCH 15/17] docs: capitalize "panel" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35eb886..ba75c63 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Global installation is supported as well, but not recommended. ### Development -Start a development server for the panel plugin: +Start a development server for the Panel plugin: ```bash kirbyup serve src/index.js From c5767c24763248ea26233bded12c34579ff2293d Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Wed, 10 Aug 2022 10:25:11 +0200 Subject: [PATCH 16/17] refactor: inline getViteConfig() type --- src/node/index.ts | 6 ++++-- src/node/types.ts | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node/index.ts b/src/node/index.ts index 1e2eb00..d45ad28 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -22,12 +22,14 @@ import { loadConfig } from './config' import kirbyupAutoImportPlugin from './plugins/auto-import' import kirbyupHmrPlugin from './plugins/hmr' import kirbyupBuildCleanupPlugin from './plugins/build-cleanup' -import type { BaseOptions, BuildOptions, GetViteConfigFn, PostCSSConfigResult, ServeOptions, UserConfig } from './types' +import type { BaseOptions, BuildOptions, PostCSSConfigResult, ServeOptions, UserConfig } from './types' let resolvedKirbyupConfig: UserConfig let resolvedPostCssConfig: PostCSSConfigResult -const getViteConfig: GetViteConfigFn = (command, options) => { +const getViteConfig: ( + ...args: ['build', BuildOptions] | ['serve', ServeOptions] +) => InlineConfig = (command, options) => { const aliasDir = resolve(options.cwd, dirname(options.entry)) const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig diff --git a/src/node/types.ts b/src/node/types.ts index e837ff3..9274d4f 100644 --- a/src/node/types.ts +++ b/src/node/types.ts @@ -43,5 +43,3 @@ export interface PostCSSConfigResult { options?: Postcss.ProcessOptions plugins: Postcss.Plugin[] } - -export type GetViteConfigFn = (...args: ['build', BuildOptions] | ['serve', ServeOptions]) => InlineConfig From d007d3fa67516a17b172d59a861514252e92274a Mon Sep 17 00:00:00 2001 From: Jonas Kuske <30421456+jonaskuske@users.noreply.github.com> Date: Sat, 13 Aug 2022 09:31:44 +0200 Subject: [PATCH 17/17] fix: only handle SIGINT, implemented like vite --- src/node/cli-start.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index b014dd7..b3e2886 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -1,5 +1,4 @@ import { cac } from 'cac' -import consola from 'consola' import { name, version } from '../../package.json' import { build, serve } from './index' @@ -33,15 +32,16 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) { .action(async (file: string, options: { watch: false | string | string[]; port: number; outDir?: string }) => { const server = await serve({ cwd, entry: file, ...options }) - const close = () => server.httpServer?.listening && server.close() - - process.on('SIGINT', () => close()) - process.on('exit', () => close()) - process.on('uncaughtException', (err) => { - consola.error(err) - process.exitCode = 1 - close() - }) + // Vite handles SIGTERM and end of stdin (Ctrl+D) itself, but not SIGINT + const exitProcess = async () => { + try { + await server.close() + } + finally { + process.exit() + } + } + process.once('SIGINT', exitProcess) }) // Filter out unnecessary "default" output for negated options (zerobyte acts as marker)