Skip to content

Commit

Permalink
Merge branch 'vitejs:main' into fixReactWorkerRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
toSayNothing authored Dec 31, 2021
2 parents 136883d + dd8869b commit 2825779
Show file tree
Hide file tree
Showing 21 changed files with 399 additions and 200 deletions.
3 changes: 3 additions & 0 deletions packages/playground/assets/css/import.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.import-css {
color: #0088ff;
}
29 changes: 29 additions & 0 deletions packages/playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,35 @@ <h2>new URL(`./${dynamic}`, import.meta.url)</h2>
<code class="dynamic-import-meta-url-2"></code>
</p>

<h2>url in style tag</h2>
<h3>url</h3>
<style class="style-url">
.style-url-assets {
background: url('./nested/asset.png');
background-size: 10px 10px;
}
</style>
<div style="background: url('./nested/asset.png'); background-size: 10px 10px">
inline style
</div>
<div class="style-url-assets">use style class</div>

<h3>base64</h3>
<style class="style-base64">
.style-base64-assets {
background: url('./static/icon.png');
}
</style>
<p class="inline-style-base64" style="background: url(./static/icon.png)">
inline style
</p>
<p class="style-base64-assets">use style class</p>

<h3 class="import-css">@import</h3>
<style class="style-import">
@import url('./css/import.css');
</style>

<script type="module">
import './css/fonts.css'
import './css/css-url.css'
Expand Down
5 changes: 4 additions & 1 deletion packages/playground/cli/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const { defineConfig } = require('vite')

module.exports = defineConfig({
server: {
host: 'localhost'
host: 'localhost',
headers: {
'Cache-Control': 'no-store'
}
},
build: {
//speed up build
Expand Down
58 changes: 0 additions & 58 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2108,35 +2108,6 @@ Repository: micromatch/micromatch
---------------------------------------

## mime
License: MIT
By: Robert Kieffer
Repository: https://github.com/broofa/mime

> The MIT License (MIT)
>
> Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
---------------------------------------

## mime-db
License: MIT
By: Douglas Christopher Wilson, Jonathan Ong, Robert Kieffer
Expand Down Expand Up @@ -3468,35 +3439,6 @@ Repository: git://github.com/feross/safe-buffer.git
---------------------------------------

## selfsigned
License: MIT
By: José F. Romaniello, Paolo Fragomeni, Charles Bushong
Repository: git://github.com/jfromaniello/selfsigned.git

> MIT License
>
> Copyright (c) 2013 José F. Romaniello
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## shebang-command
License: MIT
By: Kevin Mårtensson
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"launch-editor-middleware": "^2.3.0",
"magic-string": "^0.25.7",
"micromatch": "^4.0.4",
"mime": "^3.0.0",
"mrmime": "^1.0.0",
"node-forge": "^0.10.0",
"okie": "^1.0.1",
"open": "^8.4.0",
"periscopic": "^2.0.3",
Expand All @@ -108,7 +109,6 @@
"postcss-modules": "^4.3.0",
"resolve.exports": "^1.1.0",
"rollup-plugin-license": "^2.6.0",
"selfsigned": "^1.10.11",
"sirv": "^1.0.19",
"source-map": "^0.6.1",
"source-map-support": "^0.5.21",
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ describe('preview config', () => {
host: true,
open: true,
https: true,
headers: {
'Cache-Control': 'no-store'
},
proxy: { '/foo': 'http://localhost:4567' },
cors: false
})
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,14 @@ async function doBuild(
watch: {
...watcherOptions,
chokidar: {
ignoreInitial: true,
ignorePermissionErrors: true,
...watcherOptions.chokidar,
ignored: [
'**/node_modules/**',
'**/.git/**',
...(watcherOptions?.chokidar?.ignored || [])
],
ignoreInitial: true,
ignorePermissionErrors: true,
...watcherOptions.chokidar
]
}
}
})
Expand Down
145 changes: 145 additions & 0 deletions packages/vite/src/node/certificate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// simplified fork of
// https://github.com/jfromaniello/selfsigned/blob/da38146f8d02183c35f49f91659a744a243e8707/index.js
// with inlined options and partial node-forge usage
// to achieve smaller bundle
//
// this utility create untrusted certificate which still
// allows to access page after proceeding a wall with warning
//
// should be deprecated eventually and replaced with recipes
// about generating secure trusted certificates

// @ts-ignore
import forge from 'node-forge/lib/forge'
// @ts-ignore
import 'node-forge/lib/pki'

// a hexString is considered negative if it's most significant bit is 1
// because serial numbers use ones' complement notation
// this RFC in section 4.1.2.2 requires serial numbers to be positive
// http://www.ietf.org/rfc/rfc5280.txt
function toPositiveHex(hexString: string) {
let mostSiginficativeHexAsInt = parseInt(hexString[0], 16)
if (mostSiginficativeHexAsInt < 8) {
return hexString
}

mostSiginficativeHexAsInt -= 8
return mostSiginficativeHexAsInt.toString() + hexString.substring(1)
}

export function createCertificate(): string {
const days = 30
const keySize = 2048

const extensions = [
// {
// name: 'basicConstraints',
// cA: true,
// },
{
name: 'keyUsage',
keyCertSign: true,
digitalSignature: true,
nonRepudiation: true,
keyEncipherment: true,
dataEncipherment: true
},
{
name: 'extKeyUsage',
serverAuth: true,
clientAuth: true,
codeSigning: true,
timeStamping: true
},
{
name: 'subjectAltName',
altNames: [
{
// type 2 is DNS
type: 2,
value: 'localhost'
},
{
type: 2,
value: 'localhost.localdomain'
},
{
type: 2,
value: 'lvh.me'
},
{
type: 2,
value: '*.lvh.me'
},
{
type: 2,
value: '[::1]'
},
{
// type 7 is IP
type: 7,
ip: '127.0.0.1'
},
{
type: 7,
ip: 'fe80::1'
}
]
}
]

const attrs = [
{
name: 'commonName',
value: 'example.org'
},
{
name: 'countryName',
value: 'US'
},
{
shortName: 'ST',
value: 'Virginia'
},
{
name: 'localityName',
value: 'Blacksburg'
},
{
name: 'organizationName',
value: 'Test'
},
{
shortName: 'OU',
value: 'Test'
}
]

const keyPair = forge.pki.rsa.generateKeyPair(keySize)

const cert = forge.pki.createCertificate()

cert.serialNumber = toPositiveHex(
forge.util.bytesToHex(forge.random.getBytesSync(9))
) // the serial number can be decimal or hex (if preceded by 0x)

cert.validity.notBefore = new Date()
cert.validity.notAfter = new Date()
cert.validity.notAfter.setDate(cert.validity.notBefore.getDate() + days)

cert.setSubject(attrs)
cert.setIssuer(attrs)

cert.publicKey = keyPair.publicKey

cert.setExtensions(extensions)

const algorithm = forge.md.sha256.create()
cert.sign(keyPair.privateKey, algorithm)

const privateKeyPem = forge.pki.privateKeyToPem(keyPair.privateKey)
const certPem = forge.pki.certificateToPem(cert)

return privateKeyPem + certPem
}
Loading

0 comments on commit 2825779

Please sign in to comment.