litestar-vite-plugin 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +53 -61
  2. package/tools/clean.js +38 -50
package/package.json CHANGED
@@ -1,65 +1,57 @@
1
1
  {
2
- "name": "litestar-vite-plugin",
3
- "version": "0.7.1",
4
- "type": "module",
5
- "description": "Litestar plugin for Vite.",
6
- "keywords": [
7
- "litestar",
8
- "vite",
9
- "vite-plugin"
10
- ],
11
- "homepage": "https://github.com/litestar-org/litestar-vite",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/litestar-org/litestar-vite.git"
2
+ "name": "litestar-vite-plugin",
3
+ "version": "0.8.1",
4
+ "type": "module",
5
+ "description": "Litestar plugin for Vite.",
6
+ "keywords": ["litestar", "vite", "vite-plugin"],
7
+ "homepage": "https://github.com/litestar-org/litestar-vite",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/litestar-org/litestar-vite.git"
11
+ },
12
+ "license": "MIT",
13
+ "author": "Litestar",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/js/index.d.ts",
17
+ "default": "./dist/js/index.js"
15
18
  },
16
- "license": "MIT",
17
- "author": "Litestar",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/js/index.d.ts",
21
- "default": "./dist/js/index.js"
22
- },
23
- "./inertia-helpers": {
24
- "types": "./dist/js/inertia-helpers/index.d.ts",
25
- "default": "./dist/js/inertia-helpers/index.js"
26
- }
27
- },
28
- "types": "./dist/js/index.d.ts",
29
- "files": [
30
- "/dist/js/",
31
- "/dist/js/inertia-helpers"
32
- ],
33
- "bin": {
34
- "clean-orphaned-assets": "tools/clean.js"
35
- },
36
- "scripts": {
37
- "build": "npm run build-plugin && npm run build-inertia-helpers",
38
- "build-plugin": "rm -rf dist/js && npm run build-plugin-types && npm run build-plugin-esm && cp src/js/src/dev-server-index.html dist/js/",
39
- "build-plugin-types": "tsc --project src/js/tsconfig.json --emitDeclarationOnly",
40
- "build-plugin-esm": "esbuild src/js/src/index.ts --platform=node --format=esm --outfile=dist/js/index.js",
41
- "build-inertia-helpers": "rm -rf dist/inertia-helpers && tsc --project src/js/tsconfig.inertia-helpers.json",
42
- "lint": "eslint --ext .ts ./src/js/src ./src/js/tests",
43
- "test": "vitest run"
44
- },
45
- "devDependencies": {
46
- "@types/node": "^18.11.9",
47
- "@typescript-eslint/eslint-plugin": "^5.21.0",
48
- "@typescript-eslint/parser": "^5.21.0",
49
- "esbuild": "0.16.10",
50
- "eslint": "^8.14.0",
51
- "typescript": "^4.6.4",
52
- "vite": "^5.0.0",
53
- "vitest": "^0.34.4"
54
- },
55
- "peerDependencies": {
56
- "vite": "^5.0.0"
57
- },
58
- "engines": {
59
- "node": "^18.0.0 || >=20.0.0"
60
- },
61
- "dependencies": {
62
- "picocolors": "^1.0.0",
63
- "vite-plugin-full-reload": "^1.1.0"
19
+ "./inertia-helpers": {
20
+ "types": "./dist/js/inertia-helpers/index.d.ts",
21
+ "default": "./dist/js/inertia-helpers/index.js"
64
22
  }
23
+ },
24
+ "types": "./dist/js/index.d.ts",
25
+ "files": ["/dist/js/", "/dist/js/inertia-helpers"],
26
+ "bin": {
27
+ "clean-orphaned-assets": "tools/clean.js"
28
+ },
29
+ "scripts": {
30
+ "build": "npm run build-plugin && npm run build-inertia-helpers",
31
+ "build-plugin": "rm -rf dist/js && npm run build-plugin-types && npm run build-plugin-esm && cp src/js/src/dev-server-index.html dist/js/",
32
+ "build-plugin-types": "tsc --project src/js/tsconfig.json --emitDeclarationOnly",
33
+ "build-plugin-esm": "esbuild src/js/src/index.ts --platform=node --format=esm --outfile=dist/js/index.js",
34
+ "build-inertia-helpers": "rm -rf dist/inertia-helpers && tsc --project src/js/tsconfig.inertia-helpers.json",
35
+ "lint": "eslint --ext .ts ./src/js/src ./src/js/tests",
36
+ "test": "vitest --config ./src/js/vitest.config.ts run"
37
+ },
38
+ "devDependencies": {
39
+ "@biomejs/biome": "1.9.4",
40
+ "@types/node": "^22.10.1",
41
+ "esbuild": "0.24.0",
42
+ "happy-dom": "^15.11.7",
43
+ "typescript": "^5.7.2",
44
+ "vite": "^6.0.1",
45
+ "vitest": "^2.1.6"
46
+ },
47
+ "peerDependencies": {
48
+ "vite": ">=5.0.0"
49
+ },
50
+ "engines": {
51
+ "node": "^18.0.0 || >=20.0.0"
52
+ },
53
+ "dependencies": {
54
+ "picocolors": "^1.1.1",
55
+ "vite-plugin-full-reload": "^1.2.0"
56
+ }
65
57
  }
package/tools/clean.js CHANGED
@@ -1,18 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { readFileSync, readdirSync, unlinkSync, existsSync } from 'fs'
4
- import { dirname } from 'path'
3
+ import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs"
4
+ import { dirname } from "node:path"
5
5
 
6
6
  /*
7
7
  * Argv helpers.
8
8
  */
9
9
 
10
10
  const argument = (name) => {
11
- const index = process.argv.findIndex(argument => argument.startsWith(`--${name}=`))
11
+ const index = process.argv.findIndex((argument) => argument.startsWith(`--${name}=`))
12
12
 
13
- return index === -1
14
- ? undefined
15
- : process.argv[index].substring(`--${name}=`.length)
13
+ return index === -1 ? undefined : process.argv[index].substring(`--${name}=`.length)
16
14
  }
17
15
 
18
16
  const option = (name) => process.argv.includes(`--${name}`)
@@ -20,73 +18,63 @@ const option = (name) => process.argv.includes(`--${name}`)
20
18
  /*
21
19
  * Helpers.
22
20
  */
23
- const info = option(`quiet`) ? (() => undefined) : console.log
24
- const error = option(`quiet`) ? (() => undefined) : console.error
21
+ const info = option("quiet") ? () => undefined : console.log
22
+ const error = option("quiet") ? () => undefined : console.error
25
23
 
26
24
  /*
27
25
  * Clean.
28
26
  */
29
27
 
30
28
  const main = () => {
31
- const manifestPaths = argument(`manifest`) ? [argument(`manifest`)] : (option(`ssr`)
32
- ? [`./bootstrap/ssr/ssr-manifest.json`, `./bootstrap/ssr/manifest.json`]
33
- : [`./public/build/manifest.json`])
29
+ const manifestPaths = argument("manifest")
30
+ ? [argument("manifest")]
31
+ : option("ssr")
32
+ ? ["./bootstrap/ssr/ssr-manifest.json", "./bootstrap/ssr/manifest.json"]
33
+ : ["./public/build/manifest.json"]
34
34
 
35
- const foundManifestPath = manifestPaths.find(existsSync)
35
+ const foundManifestPath = manifestPaths.find(existsSync)
36
36
 
37
- if (! foundManifestPath) {
38
- error(`Unable to find manifest file.`)
37
+ if (!foundManifestPath) {
38
+ error("Unable to find manifest file.")
39
39
 
40
- process.exit(1)
41
- }
40
+ process.exit(1)
41
+ }
42
42
 
43
- info(`Reading manifest [${foundManifestPath}].`)
43
+ info(`Reading manifest [${foundManifestPath}].`)
44
44
 
45
- const manifest = JSON.parse(readFileSync(foundManifestPath).toString())
45
+ const manifest = JSON.parse(readFileSync(foundManifestPath).toString())
46
46
 
47
- const manifestFiles = Object.keys(manifest)
47
+ const manifestFiles = Object.keys(manifest)
48
48
 
49
- const isSsr = Array.isArray(manifest[manifestFiles[0]])
49
+ const isSsr = Array.isArray(manifest[manifestFiles[0]])
50
50
 
51
- isSsr
52
- ? info(`SSR manifest found.`)
53
- : info(`Non-SSR manifest found.`)
51
+ isSsr ? info("SSR manifest found.") : info("Non-SSR manifest found.")
54
52
 
55
- const manifestAssets = isSsr
56
- ? manifestFiles.flatMap(key => manifest[key])
57
- : manifestFiles.flatMap(key => [
58
- ...manifest[key].css ?? [],
59
- manifest[key].file,
60
- ])
53
+ const manifestAssets = isSsr ? manifestFiles.flatMap((key) => manifest[key]) : manifestFiles.flatMap((key) => [...(manifest[key].css ?? []), manifest[key].file])
61
54
 
62
- const assetsPath = argument('assets') ?? dirname(foundManifestPath)+'/assets'
55
+ const assetsPath = argument("assets") ?? `${dirname(foundManifestPath)}/assets`
63
56
 
64
- info(`Verify assets in [${assetsPath}].`)
57
+ info(`Verify assets in [${assetsPath}].`)
65
58
 
66
- const existingAssets = readdirSync(assetsPath, { withFileTypes: true })
59
+ const existingAssets = readdirSync(assetsPath, { withFileTypes: true })
67
60
 
68
- const orphanedAssets = existingAssets.filter(file => file.isFile())
69
- .filter(file => manifestAssets.findIndex(asset => asset.endsWith(`/${file.name}`)) === -1)
61
+ const orphanedAssets = existingAssets.filter((file) => file.isFile()).filter((file) => manifestAssets.findIndex((asset) => asset.endsWith(`/${file.name}`)) === -1)
70
62
 
71
- if (orphanedAssets.length === 0) {
72
- info(`No orphaned assets found.`)
73
- } else {
74
- orphanedAssets.length === 1
75
- ? info(`[${orphanedAssets.length}] orphaned asset found.`)
76
- : info(`[${orphanedAssets.length}] orphaned assets found.`)
63
+ if (orphanedAssets.length === 0) {
64
+ info("No orphaned assets found.")
65
+ } else {
66
+ orphanedAssets.length === 1 ? info(`[${orphanedAssets.length}] orphaned asset found.`) : info(`[${orphanedAssets.length}] orphaned assets found.`)
77
67
 
78
- orphanedAssets.forEach(asset => {
79
- const path = `${assetsPath}/${asset.name}`
68
+ orphanedAssets.forEach((asset) => {
69
+ const path = `${assetsPath}/${asset.name}`
80
70
 
81
- option(`dry-run`)
82
- ? info(`Orphaned asset [${path}] would be removed.`)
83
- : info(`Removing orphaned asset [${path}].`)
71
+ option("dry-run") ? info(`Orphaned asset [${path}] would be removed.`) : info(`Removing orphaned asset [${path}].`)
84
72
 
85
- if (! option(`dry-run`)) {
86
- unlinkSync(path)
87
- }
88
- })
89
- }
73
+ if (!option("dry-run")) {
74
+ unlinkSync(path)
75
+ }
76
+ })
77
+ }
90
78
  }
91
79
 
92
80
  main()