From f1427a7269c6600a6f5827aab853f1ab114aa2d4 Mon Sep 17 00:00:00 2001 From: hugos68 Date: Thu, 1 Feb 2024 16:37:28 +0100 Subject: [PATCH] Removed pagefind as a dep, now just using the CLI installed by the end user --- .changeset/sour-tips-warn.md | 5 +++ CHANGELOG.md | 58 ++++++++++++++--------------- README.md | 2 +- package.json | 3 +- pnpm-lock.yaml | 72 ------------------------------------ src/index.ts | 51 ++++++++++--------------- 6 files changed, 56 insertions(+), 135 deletions(-) create mode 100644 .changeset/sour-tips-warn.md diff --git a/.changeset/sour-tips-warn.md b/.changeset/sour-tips-warn.md new file mode 100644 index 0000000..e8b8c4a --- /dev/null +++ b/.changeset/sour-tips-warn.md @@ -0,0 +1,5 @@ +--- +"vite-plugin-pagefind": patch +--- + +Cleaned up some internals diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e66ba..d052e64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,147 +4,147 @@ ### Patch Changes -- 19ca67b: Fixed executeMeasured return time (start - stop should be stop - start) +- 19ca67b: Fixed executeMeasured return time (start - stop should be stop - start) ## 0.0.24 ### Patch Changes -- 720dbb8: Removed the automatic pagefind run on post build in favor of manually doing so to be framework agnostic (some frameworks have their own CLI wrappers around Vite so it was impossible to run post build since the framework ran after `vite build` had completed. +- 720dbb8: Removed the automatic pagefind run on post build in favor of manually doing so to be framework agnostic (some frameworks have their own CLI wrappers around Vite so it was impossible to run post build since the framework ran after `vite build` had completed. ## 0.0.23 ### Patch Changes -- d8de3ba: Graph improvements +- d8de3ba: Graph improvements ## 0.0.22 ### Patch Changes -- 7aafe6b: Added flow chart to showcase what pagefind does +- 7aafe6b: Added flow chart to showcase what pagefind does ## 0.0.21 ### Patch Changes -- 74aed9c: Added Astro example :tada: +- 74aed9c: Added Astro example :tada: ## 0.0.20 ### Patch Changes -- ce7ba7a: Docs cleanup and default empty object fix +- ce7ba7a: Docs cleanup and default empty object fix ## 0.0.19 ### Patch Changes -- 396c975: Added @antfu/ni in order to detect package and allow for more flexible build process (rather than harcoding `vite build` +- 396c975: Added @antfu/ni in order to detect package and allow for more flexible build process (rather than harcoding `vite build` ## 0.0.18 ### Patch Changes -- 6da3d09: Minor doc changes +- 6da3d09: Minor doc changes ## 0.0.17 ### Patch Changes -- dfde5a4: Added examples folder, added SvelteKit +- dfde5a4: Added examples folder, added SvelteKit ## 0.0.16 ### Patch Changes -- e1cbe1f: Fixed dynamic imports being due to faulty vite configuration +- e1cbe1f: Fixed dynamic imports being due to faulty vite configuration ## 0.0.15 ### Patch Changes -- 6bb27bc: Fixed nested pagefind dir +- 6bb27bc: Fixed nested pagefind dir ## 0.0.14 ### Patch Changes -- 3759d12: Removed testing console.log +- 3759d12: Removed testing console.log ## 0.0.13 ### Patch Changes -- a9d0e41: Removed prerequisites from docs since the plugin will handle pagefind through the node API +- a9d0e41: Removed prerequisites from docs since the plugin will handle pagefind through the node API ## 0.0.12 ### Patch Changes -- e08ff34: Cleaned up docs, renamed appDir to publicDir (makes more sense with vite), added LICENSE -- b974483: Fixed docs +- e08ff34: Cleaned up docs, renamed appDir to publicDir (makes more sense with vite), added LICENSE +- b974483: Fixed docs ## 0.0.11 ### Patch Changes -- 692518a: Added assetsInclude config and external config to make usage of pagefind FAR easier +- 692518a: Added assetsInclude config and external config to make usage of pagefind FAR easier ## 0.0.10 ### Patch Changes -- cf9d8a7: Forced buildDir to be present -- 9f91f77: Fixed buildDir being optional type +- cf9d8a7: Forced buildDir to be present +- 9f91f77: Fixed buildDir being optional type ## 0.0.9 ### Patch Changes -- 1dc1751: Renamed pagefindDir to appDir and removed the need to specify the `pagefind` folder -- 1dc1751: Added documentation (see README.md) +- 1dc1751: Renamed pagefindDir to appDir and removed the need to specify the `pagefind` folder +- 1dc1751: Added documentation (see README.md) ## 0.0.8 ### Patch Changes -- bd97d3d: Finally fixed running pagefind after build -- fcf32c0: Fixed broken vite dependency: https://github.com/vitejs/vite/issues/15714 +- bd97d3d: Finally fixed running pagefind after build +- fcf32c0: Fixed broken vite dependency: https://github.com/vitejs/vite/issues/15714 ## 0.0.7 ### Patch Changes -- 9bdcc49: Fixed pagefind post build not running after the build process +- 9bdcc49: Fixed pagefind post build not running after the build process ## 0.0.6 ### Patch Changes -- d911925: Fixed hardcoded buildDir -- 324852e: Added quotes around paths for pagefind to prevent invalid paths from occuring +- d911925: Fixed hardcoded buildDir +- 324852e: Added quotes around paths for pagefind to prevent invalid paths from occuring ## 0.0.5 ### Patch Changes -- 04163e9: Added cwd option that defaults to process.cwd, added default to buildDir: build +- 04163e9: Added cwd option that defaults to process.cwd, added default to buildDir: build ## 0.0.4 ### Patch Changes -- 93731cd: Bugfix: Had colorette as devDep causing issues with the plugin +- 93731cd: Bugfix: Had colorette as devDep causing issues with the plugin ## 0.0.3 ### Patch Changes -- 2f8a075: Only packaging dist files now +- 2f8a075: Only packaging dist files now ## 0.0.2 ### Patch Changes -- a969687: Released package +- a969687: Released package diff --git a/README.md b/README.md index cbb45d8..a89830a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Note: If your framework does not have a `vite.config` checkout the [examples](#e } ``` -Note: replace `` with your build directory. +Note: Replace `` with your build directory. ## Config diff --git a/package.json b/package.json index bcf59ab..b9480b9 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,7 @@ }, "dependencies": { "@antfu/ni": "^0.21.12", - "colorette": "^2.0.20", - "pagefind": "^1.0.4" + "colorette": "^2.0.20" }, "type": "module", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84d7dc8..2eb0320 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ dependencies: colorette: specifier: ^2.0.20 version: 2.0.20 - pagefind: - specifier: ^1.0.4 - version: 1.0.4 devDependencies: '@changesets/cli': @@ -648,61 +645,6 @@ packages: fastq: 1.17.0 dev: true - /@pagefind/darwin-arm64@1.0.4: - resolution: - { - integrity: sha512-2OcthvceX2xhm5XbgOmW+lT45oLuHqCmvFeFtxh1gsuP5cO8vcD8ZH8Laj4pXQFCcK6eAdSShx+Ztx/LsQWZFQ== - } - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@pagefind/darwin-x64@1.0.4: - resolution: - { - integrity: sha512-xkdvp0D9Ld/ZKsjo/y1bgfhTEU72ITimd2PMMQtts7jf6JPIOJbsiErCvm37m/qMFuPGEq/8d+fZ4pydOj08HQ== - } - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@pagefind/linux-arm64@1.0.4: - resolution: - { - integrity: sha512-jGBrcCzIrMnNxLKVtogaQyajVfTAXM59KlBEwg6vTn8NW4fQ6nuFbbhlG4dTIsaamjEM5e8ZBEAKZfTB/qd9xw== - } - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@pagefind/linux-x64@1.0.4: - resolution: - { - integrity: sha512-LIn/QcvcEtLEBqKe5vpSbSC2O3fvqbRCWOTIklslqSORisCsvzsWbP6j+LYxE9q0oWIfkdMoWV1vrE/oCKRxHg== - } - cpu: [x64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@pagefind/windows-x64@1.0.4: - resolution: - { - integrity: sha512-QlBCVeZfj9fc9sbUgdOz76ZDbeK4xZihOBAFqGuRJeChfM8pnVeH9iqSnXgO3+m9oITugTf7PicyRUFAG76xeQ== - } - cpu: [x64] - os: [win32] - requiresBuild: true - dev: false - optional: true - /@rollup/rollup-android-arm-eabi@4.9.6: resolution: { @@ -2367,20 +2309,6 @@ packages: engines: { node: '>=6' } dev: true - /pagefind@1.0.4: - resolution: - { - integrity: sha512-oRIizYe+zSI2Jw4zcMU0ebDZm27751hRFiSOBLwc1OIYMrsZKk+3m8p9EVaOmc6zZdtqwwdilNUNxXvBeHcP9w== - } - hasBin: true - optionalDependencies: - '@pagefind/darwin-arm64': 1.0.4 - '@pagefind/darwin-x64': 1.0.4 - '@pagefind/linux-arm64': 1.0.4 - '@pagefind/linux-x64': 1.0.4 - '@pagefind/windows-x64': 1.0.4 - dev: false - /parse-json@5.2.0: resolution: { diff --git a/src/index.ts b/src/index.ts index 66792e8..fabc8ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,10 @@ -import type { PluginOption } from 'vite'; +import { build, type PluginOption } from 'vite'; import { join } from 'path'; import { existsSync } from 'fs'; import { execSync } from 'child_process'; import { performance } from 'perf_hooks'; import { blue, bold } from 'colorette'; import { detect, getCommand } from '@antfu/ni'; -import * as pagefind from 'pagefind'; type PagefindPluginConfig = { publicDir?: string; @@ -13,12 +12,6 @@ type PagefindPluginConfig = { buildScript?: string; }; -type PagefindDevPluginConfig = { - publicDir: string; - buildDir: string; - buildScript: string; -}; - function log(input: string) { console.log(`${blue('[vite-plugin-pagefind]')} ${bold(input)}`); } @@ -42,7 +35,7 @@ function pagefindDevPlugin({ publicDir, buildDir, buildScript -}: PagefindDevPluginConfig): PluginOption { +}: Required): PluginOption { return { name: 'pagefind-dev', apply: 'serve', @@ -57,29 +50,25 @@ function pagefindDevPlugin({ }; }, async configureServer() { - if (!existsSync(join(publicDir, 'pagefind'))) { - log('Pagefind not found.'); - if (!existsSync(join(buildDir, 'pagefind'))) { - const buildCommand = await getBuildCommand(buildScript); - log(`Build not found, running "${buildCommand}".`); - const time = await executeMeasured(() => - execSync(buildCommand) - ); - log(`Build completed in ${millisToSeconds(time)}.`); - } - log('Running pagefind...'); - const time = await executeMeasured(async () => { - const { index } = await pagefind.createIndex({}); - await index.addDirectory({ - path: buildDir - }); - await index.writeFiles({ - outputPath: join(publicDir, 'pagefind') - }); - await pagefind.close(); - }); - log(`Pagefind completed in ${millisToSeconds(time)}.`); + if (existsSync(join(publicDir, 'pagefind'))) { + return; + } + log('Pagefind not found.'); + if (!existsSync(join(buildDir, 'pagefind'))) { + const buildCommand = await getBuildCommand(buildScript); + log(`Build not found, running "${buildCommand}".`); + const time = await executeMeasured(() => + execSync(buildCommand) + ); + log(`Build completed in ${millisToSeconds(time)}.`); } + log('Running pagefind...'); + const time = await executeMeasured(() => + execSync( + `pagefind --site ${buildDir} --output-path ${publicDir}` + ) + ); + log(`Pagefind completed in ${millisToSeconds(time)}.`); } }; }