Skip to content

Commit efc8979

Browse files
authoredJan 4, 2023
feat: reproducible manifest (#11542)
1 parent b89ddd6 commit efc8979

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@types/estree": "^1.0.0",
4848
"@types/etag": "^1.8.1",
4949
"@types/fs-extra": "^9.0.13",
50+
"@types/json-stable-stringify": "^1.0.34",
5051
"@types/less": "^3.0.3",
5152
"@types/micromatch": "^4.0.2",
5253
"@types/minimist": "^1.2.2",

‎packages/vite/LICENSE.md

+26
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,32 @@ Repository: git+https://github.com/isaacs/isexe.git
18331833
18341834
---------------------------------------
18351835

1836+
## json-stable-stringify
1837+
License: MIT
1838+
By: James Halliday
1839+
Repository: git://github.com/ljharb/json-stable-stringify.git
1840+
1841+
> This software is released under the MIT license:
1842+
>
1843+
> Permission is hereby granted, free of charge, to any person obtaining a copy of
1844+
> this software and associated documentation files (the "Software"), to deal in
1845+
> the Software without restriction, including without limitation the rights to
1846+
> use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
1847+
> the Software, and to permit persons to whom the Software is furnished to do so,
1848+
> subject to the following conditions:
1849+
>
1850+
> The above copyright notice and this permission notice shall be included in all
1851+
> copies or substantial portions of the Software.
1852+
>
1853+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1854+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1855+
> FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1856+
> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1857+
> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1858+
> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1859+
1860+
---------------------------------------
1861+
18361862
## launch-editor
18371863
License: MIT
18381864
By: Evan You

‎packages/vite/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"etag": "^1.8.1",
9898
"fast-glob": "^3.2.12",
9999
"http-proxy": "^1.18.1",
100+
"json-stable-stringify": "^1.0.2",
100101
"launch-editor-middleware": "^2.6.0",
101102
"magic-string": "^0.27.0",
102103
"micromatch": "^4.0.5",

‎packages/vite/rollup.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ function createNodePlugins(
112112
pattern: /require(?=\((configFile|'ts-node')\))/g,
113113
replacement: `eval('require')`,
114114
},
115+
'json-stable-stringify/index.js': {
116+
pattern: /^var json = typeof JSON.+require\('jsonify'\);$/gm,
117+
replacement: 'var json = JSON',
118+
},
115119
}),
116120

117121
commonjs({

‎packages/vite/src/node/plugins/manifest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path'
22
import type { OutputAsset, OutputChunk } from 'rollup'
3+
import jsonStableStringify from 'json-stable-stringify'
34
import type { ResolvedConfig } from '..'
45
import type { Plugin } from '../plugin'
56
import { normalizePath } from '../utils'
@@ -158,7 +159,7 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
158159
? config.build.manifest
159160
: 'manifest.json',
160161
type: 'asset',
161-
source: JSON.stringify(manifest, null, 2),
162+
source: jsonStableStringify(manifest, { space: 2 }),
162163
})
163164
}
164165
},

‎packages/vite/src/node/ssr/ssrManifestPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { basename, dirname, join, relative } from 'node:path'
22
import { parse as parseImports } from 'es-module-lexer'
33
import type { ImportSpecifier } from 'es-module-lexer'
44
import type { OutputChunk } from 'rollup'
5+
import jsonStableStringify from 'json-stable-stringify'
56
import type { ResolvedConfig } from '..'
67
import type { Plugin } from '../plugin'
78
import { preloadMethod } from '../plugins/importAnalysisBuild'
@@ -81,7 +82,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
8182
? config.build.ssrManifest
8283
: 'ssr-manifest.json',
8384
type: 'asset',
84-
source: JSON.stringify(ssrManifest, null, 2),
85+
source: jsonStableStringify(ssrManifest, { space: 2 }),
8586
})
8687
},
8788
}

‎pnpm-lock.yaml

+32-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.