forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fs-serve import graph awareness (vitejs#3784)
Co-authored-by: Shinigami <chrissi92@hotmail.de>
- Loading branch information
1 parent
9f3e8a9
commit c9c0ded
Showing
17 changed files
with
235 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { isBuild } from '../../testUtils' | ||
|
||
const json = require('../safe.json') | ||
const stringified = JSON.stringify(json) | ||
|
||
if (!isBuild) { | ||
test('default import', async () => { | ||
expect(await page.textContent('.full')).toBe(stringified) | ||
}) | ||
|
||
test('named import', async () => { | ||
expect(await page.textContent('.named')).toBe(json.msg) | ||
}) | ||
|
||
test('safe fetch', async () => { | ||
expect(await page.textContent('.safe-fetch')).toBe(stringified) | ||
expect(await page.textContent('.safe-fetch-status')).toBe('200') | ||
}) | ||
|
||
test('unsafe fetch', async () => { | ||
expect(await page.textContent('.unsafe-fetch')).toBe('') | ||
expect(await page.textContent('.unsafe-fetch-status')).toBe('403') | ||
}) | ||
|
||
test('nested entry', async () => { | ||
expect(await page.textContent('.nested-entry')).toBe('foobar') | ||
}) | ||
} else { | ||
test('dummy test to make jest happy', async () => { | ||
// Your test suite must contain at least one test. | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { msg } from './nested/foo' | ||
|
||
export const fullmsg = msg + 'bar' | ||
|
||
document.querySelector('.nested-entry').textContent = fullmsg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const msg = 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "test-fs-serve", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite root", | ||
"build": "vite build root", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<h2>Normal Import</h2> | ||
<pre class="full"></pre> | ||
<pre class="named"></pre> | ||
|
||
<h2>Safe Fetch</h2> | ||
<pre class="safe-fetch-status"></pre> | ||
<pre class="safe-fetch"></pre> | ||
|
||
<h2>Unsafe Fetch</h2> | ||
<pre class="unsafe-fetch-status"></pre> | ||
<pre class="unsafe-fetch"></pre> | ||
|
||
<h2>Nested Entry</h2> | ||
<pre class="nested-entry"></pre> | ||
|
||
<script type="module"> | ||
import '../entry' | ||
import json, { msg } from '../safe.json' | ||
|
||
text('.full', JSON.stringify(json)) | ||
text('.named', msg) | ||
|
||
// imported before, should be treated as safe | ||
fetch('/@fs/' + ROOT + '/safe.json') | ||
.then((r) => { | ||
text('.safe-fetch-status', r.status) | ||
return r.json() | ||
}) | ||
.then((data) => { | ||
text('.safe-fetch', JSON.stringify(data)) | ||
}) | ||
|
||
// not imported before, outside of root, treated as unsafe | ||
fetch('/@fs/' + ROOT + '/unsafe.json') | ||
.then((r) => { | ||
text('.unsafe-fetch-status', r.status) | ||
return r.json() | ||
}) | ||
.then((data) => { | ||
text('.unsafe-fetch', JSON.stringify(data)) | ||
}) | ||
.catch((e) => { | ||
console.error(e) | ||
}) | ||
|
||
function text(sel, text) { | ||
document.querySelector(sel).textContent = text | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const path = require('path') | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
module.exports = { | ||
server: { | ||
fsServe: { | ||
root: __dirname, | ||
strict: true | ||
}, | ||
hmr: { | ||
overlay: false | ||
} | ||
}, | ||
define: { | ||
ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/')) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"msg": "safe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"msg": "unsafe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.