Skip to content

Commit

Permalink
refactor: remove json-stable-stringify (#15571)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jan 12, 2024
1 parent c643a8a commit b9b0816
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 459 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@types/estree": "^1.0.5",
"@types/etag": "^1.8.3",
"@types/fs-extra": "^11.0.4",
"@types/json-stable-stringify": "^1.0.36",
"@types/less": "^3.0.6",
"@types/micromatch": "^4.0.6",
"@types/node": "^20.11.0",
Expand Down
376 changes: 0 additions & 376 deletions packages/vite/LICENSE.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"etag": "^1.8.1",
"fast-glob": "^3.3.2",
"http-proxy": "^1.18.1",
"json-stable-stringify": "^1.1.0",
"launch-editor-middleware": "^2.6.1",
"lightningcss": "^1.22.1",
"magic-string": "^0.30.5",
Expand Down
4 changes: 0 additions & 4 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ function createNodePlugins(
pattern: /require(?=\((configFile|'ts-node')\))/g,
replacement: `__require`,
},
'json-stable-stringify/index.js': {
src: "require('jsonify')",
replacement: 'JSON',
},
// postcss-import uses the `resolve` dep if the `resolve` option is not passed.
// However, we always pass the `resolve` option. Remove this import to avoid
// bundling the `resolve` dep.
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import type {
OutputChunk,
RenderedChunk,
} from 'rollup'
import jsonStableStringify from 'json-stable-stringify'
import type { ResolvedConfig } from '..'
import type { Plugin } from '../plugin'
import { normalizePath } from '../utils'
import { normalizePath, sortObjectKeys } from '../utils'
import { generatedAssets } from './asset'
import type { GeneratedAssetMeta } from './asset'

Expand Down Expand Up @@ -162,7 +161,7 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
? config.build.manifest
: '.vite/manifest.json',
type: 'asset',
source: jsonStableStringify(manifest, { space: 2 }),
source: JSON.stringify(sortObjectKeys(manifest), undefined, 2),
})
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
ImportSpecifier,
} from 'es-module-lexer'
import type { OutputChunk } from 'rollup'
import jsonStableStringify from 'json-stable-stringify'
import type { ResolvedConfig } from '..'
import type { Plugin } from '../plugin'
import { preloadMethod } from '../plugins/importAnalysisBuild'
Expand All @@ -14,6 +13,7 @@ import {
joinUrlSegments,
normalizePath,
numberToPos,
sortObjectKeys,
} from '../utils'

export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
Expand Down Expand Up @@ -100,7 +100,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
? config.build.ssrManifest
: '.vite/ssr-manifest.json',
type: 'asset',
source: jsonStableStringify(ssrManifest, { space: 2 }),
source: JSON.stringify(sortObjectKeys(ssrManifest), undefined, 2),
})
},
}
Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1379,3 +1379,11 @@ export function promiseWithResolvers<T>(): PromiseWithResolvers<T> {
})
return { promise, resolve, reject }
}

export function sortObjectKeys<T extends Record<string, any>>(obj: T): T {
const sorted: Record<string, any> = {}
for (const key of Object.keys(obj).sort()) {
sorted[key] = obj[key]
}
return sorted as T
}
72 changes: 0 additions & 72 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9b0816

Please sign in to comment.