Skip to content

Commit

Permalink
perf: remove unused dependencies with knip
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 7, 2025
1 parent 47cf283 commit 846b80a
Show file tree
Hide file tree
Showing 19 changed files with 1,326 additions and 1,844 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
node-version: 22
cache: "pnpm"

- name: Install dependencies
- name: 📦 Install dependencies
run: pnpm install

- name: Stub
- name: 🌱 Stub
run: pnpm dev:prepare

- name: Lint
- name: 🔠 Lint project
run: pnpm lint

- name: Check node version support
- name: ✂️ Knip project
run: pnpm knip --exclude unresolved,duplicates

- name: ⚙️ Check package engines
run: pnpm installed-check -d

test-fixtures:
Expand Down Expand Up @@ -107,7 +110,7 @@ jobs:
node-version: 18
cache: "pnpm"

- name: Install dependencies
- name: 📦 Install dependencies
run: pnpm install

- name: Install Playwright
Expand Down Expand Up @@ -166,10 +169,10 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 18
node-version: 22
cache: "pnpm"

- name: Install dependencies
- name: 📦 Install dependencies
run: pnpm install

- name: Restore dist cache
Expand All @@ -178,7 +181,7 @@ jobs:
path: packages/*/dist
key: ubuntu-latest-node-v18-${{ github.sha }}

- name: Release Edge
- name: Release nightly version
run: ./scripts/release-edge.sh
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
Expand Down
40 changes: 40 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"ignoreWorkspaces": [
"packages/bridge-schema"
],
"ignore": [
"packages/bridge-schema/schema/**"
],
"workspaces": {
".": {
"entry": [
"scripts/*.ts",
"test/**"
]
},
"packages/bridge": {
"entry": [
"src/module.ts",
"src/runtime/**"
],
"ignore": [
"src/vite/stub-vite.cjs"
],
"ignoreDependencies": [
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-typescript",
"@nuxt/cli",
"exit",
"zhead"
]
},
"playground": {
"entry": [
"{components,layouts,middleware,pages,plugins,server,store}/**",
"*.ts"
]
}
}
}
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"license": "MIT",
"scripts": {
"build": "FORCE_COLOR=1 pnpm --filter './packages/**' prepack",
"build:stub": "pnpm --filter './packages/**' prepack --stub",
"build": "FORCE_COLOR=1 pnpm run --filter './packages/**' prepack",
"build:stub": "pnpm run --filter './packages/**' prepack --stub",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:preview": "node ./playground/.output/server/index.mjs",
Expand All @@ -22,18 +22,28 @@
},
"devDependencies": {
"@nuxt/test-utils": "3.15.1",
"@nuxtjs/eslint-config": "12.0.0",
"@nuxtjs/eslint-config-typescript": "12.1.0",
"@types/semver": "7.5.8",
"changelogen": "0.5.7",
"consola": "^3.3.3",
"devalue": "5.1.1",
"eslint": "8.57.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsdoc": "50.6.1",
"execa": "9.5.2",
"globby": "14.0.2",
"h3": "1.13.0",
"installed-check": "9.3.0",
"jiti": "2.4.2",
"knip": "5.41.1",
"nuxi": "3.18.2",
"ofetch": "1.4.1",
"pathe": "^2.0.0",
"playwright-core": "1.49.1",
"semver": "7.6.3",
"std-env": "3.8.0",
"vitest": "2.1.8"
"vitest": "2.1.8",
"vue": "2.7.16"
},
"resolutions": {
"@nuxt/bridge": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion packages/bridge-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"devDependencies": {
"@types/lodash.template": "^4.5.3",
"@types/semver": "^7.5.8",
"@unhead/schema": "^1.11.15",
"nitropack": "^2.10.4",
"unbuild": "latest",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-schema/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Schema differences from Nuxt2:
- Apply preset
- render.etag.hash should be a function
- deprecated devModules
- set consola level to 0 if build.quite is true
- set consola level to 0 if build.quiet is true
- Ad-hoc: loading-screen, components and telemtry
- build.indicator and build.loadingScreen
- build.crossorigin => render.crossorigin
Expand Down
18 changes: 6 additions & 12 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@nuxt/bridge-schema": "workspace:*",
"@nuxt/devalue": "^2.0.2",
"@nuxt/kit": "3.15.1",
"@nuxt/postcss8": "^1.1.3",
"@nuxt/schema": "3.15.1",
"@nuxt/ui-templates": "^1.3.4",
"@rollup/plugin-replace": "^6.0.2",
Expand All @@ -48,7 +47,6 @@
"externality": "^1.0.2",
"fs-extra": "^10.1.0",
"get-port-please": "^3.1.2",
"globby": "^14.0.2",
"h3": "^1.13.0",
"hash-sum": "^2.0.0",
"hookable": "5.5.3",
Expand All @@ -64,17 +62,11 @@
"pathe": "^2.0.0",
"perfect-debounce": "^1.0.0",
"pkg-types": "^1.3.0",
"postcss": "^8.4.49",
"postcss-import": "^16.1.0",
"postcss-import-resolver": "^2.0.0",
"postcss-preset-env": "^10.1.3",
"postcss-url": "^10.1.3",
"scule": "^1.3.0",
"semver": "^7.6.3",
"std-env": "^3.8.0",
"terser": "^5.37.0",
"ufo": "^1.5.4",
"unctx": "^2.4.1",
"unimport": "^3.14.5",
"unplugin": "^1.16.0",
"untyped": "^1.5.2",
Expand All @@ -83,16 +75,18 @@
"vue-bundle-renderer": "^2.1.1"
},
"devDependencies": {
"@nuxt/types": "^2.18.1",
"@nuxtjs/eslint-config": "^12.0.0",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@babel/core": "^7.26.0",
"@types/estree": "^1.0.6",
"@types/fs-extra": "^9.0.13",
"@types/hash-sum": "^1.0.2",
"@types/node-fetch": "^3.0.3",
"nuxt": "^2.18.1",
"@types/webpack": "4.41.38",
"@vue/compiler-sfc": "2",
"@vue/reactivity": "^3.5.13",
"rollup": "^4.30.1",
"unbuild": "3.2.0",
"vue": "^2.7.16",
"vue-meta": "^2.4.0",
"vue-router": "^3.6.5",
"zhead": "^2.2.4"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/bridge/src/imports/presets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineUnimportPreset, InlinePreset } from 'unimport'

export const commonPresets: InlinePreset[] = [
const commonPresets: InlinePreset[] = [
// vue-demi (mocked)
defineUnimportPreset({
from: '#app/app',
Expand Down Expand Up @@ -58,7 +58,7 @@ const granularAppPresets: InlinePreset[] = [
}
]

export const vueKeys: Array<keyof typeof import('vue')> = [
const vueKeys: Array<keyof typeof import('vue')> = [
// Lifecycle
'onActivated',
'onBeforeMount',
Expand Down Expand Up @@ -118,7 +118,7 @@ export const vueKeys: Array<keyof typeof import('vue')> = [
]

// vue
export const vuePreset = defineUnimportPreset({
const vuePreset = defineUnimportPreset({
from: 'vue',
imports: vueKeys
})
Expand Down
8 changes: 1 addition & 7 deletions packages/bridge/src/page-meta/transform.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { pathToFileURL } from 'node:url'
import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo'
import type {
CallExpression,
ExportDefaultDeclaration,
ObjectExpression,
Property,
VariableDeclaration
} from 'estree'
import type { CallExpression, ExportDefaultDeclaration, ObjectExpression, Property, VariableDeclaration } from 'estree'
import type { Node } from 'estree-walker'
import { walk } from 'estree-walker'
import MagicString from 'magic-string'
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/src/utils/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function hasSuffix (path: string, suffix: string) {
return basename(path).replace(extname(path), '').endsWith(suffix)
}

export function resolveComponentName (fileName: string, prefixParts: string[]) {
function resolveComponentName (fileName: string, prefixParts: string[]) {
/**
* Array of fileName parts splitted by case, / or -
* @example third-component -> ['third', 'component']
Expand Down
7 changes: 0 additions & 7 deletions packages/bridge/src/vite-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ export function viteNodePlugin (ctx: ViteBuildContext): VitePlugin {
}
}

export function registerViteNodeMiddleware (ctx: ViteBuildContext) {
addDevServerHandler({
route: '/__nuxt_vite_node__/',
handler: createViteNodeApp(ctx).handler
})
}

function getManifest (ctx: ViteBuildContext) {
const css = Array.from(
ctx.ssrServer!.moduleGraph.urlToModuleMap.keys()
Expand Down
8 changes: 4 additions & 4 deletions packages/bridge/src/vite/dev-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import { ViteBuildContext } from './types'
import { createIsExternal } from './utils/external'
import { generateDevSSRManifest } from './manifest'

export interface TransformChunk {
interface TransformChunk {
id: string,
code: string,
deps: string[],
parents: string[]
}

export interface SSRTransformResult {
interface SSRTransformResult {
code: string,
map: object,
deps: string[]
dynamicDeps: string[]
}

export interface TransformOptions {
interface TransformOptions {
viteServer: ViteDevServer
isExternal(id: string): ReturnType<typeof isExternal>
}
Expand Down Expand Up @@ -125,7 +125,7 @@ async function transformRequestRecursive (opts: TransformOptions, id, parent = '
return Object.values(chunks)
}

export async function bundleRequest (opts: TransformOptions, entryURL: string) {
async function bundleRequest (opts: TransformOptions, entryURL: string) {
const chunks = await transformRequestRecursive(opts, entryURL)

const listIds = (ids: string[]) => ids.map(id => `// - ${id} (${hashId(id)})`).join('\n')
Expand Down
9 changes: 0 additions & 9 deletions packages/bridge/src/vite/dirs.ts

This file was deleted.

54 changes: 1 addition & 53 deletions packages/bridge/src/vite/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function prepareManifests (ctx: ViteBuildContext) {
}
}

export async function generateBuildManifest (ctx: ViteBuildContext) {
async function generateBuildManifest (ctx: ViteBuildContext) {
const rDist = (...args: string[]): string => resolve(ctx.nuxt.options.buildDir, 'dist', ...args)

const clientManifest: ViteManifest = await fse.readJSON(rDist('client/manifest.json'))
Expand Down Expand Up @@ -155,55 +155,3 @@ export async function writeClientManifest (clientManifest: any, buildDir: string
await fse.writeFile(resolve(buildDir, 'dist/server/client.manifest.json'), clientManifestJSON, 'utf8')
await fse.writeFile(resolve(buildDir, 'dist/server/client.manifest.mjs'), `export default ${clientManifestJSON}`, 'utf8')
}

export async function writeManifest (ctx: ViteBuildContext, css: string[] = []) {
// Write client manifest for use in vue-bundle-renderer
const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client')
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')

const devClientManifest: Manifest = {
'@vite/client': {
isEntry: true,
file: '@vite/client',
css,
module: true,
resourceType: 'script'
},
'entry.mjs': {
isEntry: true,
file: 'entry.mjs',
module: true,
resourceType: 'script'
}
}

const clientManifest = ctx.nuxt.options.dev
? devClientManifest
: await fse.readJSON(resolve(clientDist, 'manifest.json'))

const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir))
const BASE_RE = new RegExp(`^${escapeRE(buildAssetsDir)}`)

for (const key in clientManifest) {
if (clientManifest[key].file) {
clientManifest[key].file = clientManifest[key].file.replace(BASE_RE, '')
}
for (const item of ['css', 'assets']) {
if (clientManifest[key][item]) {
clientManifest[key][item] = clientManifest[key][item].map((i: string) => i.replace(BASE_RE, ''))
}
}
}

await fse.mkdirp(serverDist)

const manifest = normalizeViteManifest(clientManifest)
await ctx.nuxt.callHook('build:manifest', manifest)

await fse.writeFile(resolve(serverDist, 'client.manifest.json'), JSON.stringify(manifest, null, 2), 'utf8')
await fse.writeFile(resolve(serverDist, 'client.manifest.mjs'), 'export default ' + JSON.stringify(manifest, null, 2), 'utf8')

if (!ctx.nuxt.options.dev) {
await fse.rm(resolve(clientDist, 'manifest.json'), { force: true })
}
}
2 changes: 1 addition & 1 deletion packages/bridge/src/vite/plugins/dev-ssr-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { joinURL } from 'ufo'
import type { Plugin } from 'vite'
import { isCSS } from '../utils'

export interface DevStyleSSRPluginOptions {
interface DevStyleSSRPluginOptions {
srcDir: string
buildAssetsURL: string
}
Expand Down
Loading

0 comments on commit 846b80a

Please sign in to comment.