[ci] format
This commit is contained in:
parent
4af4d8fa00
commit
f20ff17aa3
3 changed files with 47 additions and 42 deletions
|
@ -1,8 +1,7 @@
|
||||||
import type { AstroSettings } from '../@types/astro';
|
|
||||||
import type * as vite from 'vite';
|
|
||||||
import nodeFs from 'fs';
|
import nodeFs from 'fs';
|
||||||
import npath from 'path';
|
import npath from 'path';
|
||||||
|
import type * as vite from 'vite';
|
||||||
|
import type { AstroSettings } from '../@types/astro';
|
||||||
|
|
||||||
type NodeFileSystemModule = typeof nodeFs;
|
type NodeFileSystemModule = typeof nodeFs;
|
||||||
|
|
||||||
|
@ -11,7 +10,10 @@ export interface LoadFallbackPluginParams {
|
||||||
settings: AstroSettings;
|
settings: AstroSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function loadFallbackPlugin({ fs, settings }: LoadFallbackPluginParams): vite.Plugin[] | false {
|
export default function loadFallbackPlugin({
|
||||||
|
fs,
|
||||||
|
settings,
|
||||||
|
}: LoadFallbackPluginParams): vite.Plugin[] | false {
|
||||||
// Only add this plugin if a custom fs implementation is provided.
|
// Only add this plugin if a custom fs implementation is provided.
|
||||||
if (!fs || fs === nodeFs) {
|
if (!fs || fs === nodeFs) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -35,31 +37,34 @@ export default function loadFallbackPlugin({ fs, settings }: LoadFallbackPluginP
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return [{
|
return [
|
||||||
name: 'astro:load-fallback',
|
{
|
||||||
enforce: 'post',
|
name: 'astro:load-fallback',
|
||||||
resolveId(id, parent) {
|
enforce: 'post',
|
||||||
if(id.startsWith('.') && parent && fs.existsSync(parent)) {
|
resolveId(id, parent) {
|
||||||
return npath.posix.join(npath.posix.dirname(parent), id);
|
if (id.startsWith('.') && parent && fs.existsSync(parent)) {
|
||||||
}
|
return npath.posix.join(npath.posix.dirname(parent), id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async load(id) {
|
||||||
|
const source = await tryLoadModule(id);
|
||||||
|
return source;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
async load(id) {
|
{
|
||||||
const source = await tryLoadModule(id);
|
name: 'astro:load-fallback-hmr',
|
||||||
return source;
|
enforce: 'pre',
|
||||||
}
|
handleHotUpdate(context) {
|
||||||
}, {
|
// Wrap context.read so it checks our filesystem first.
|
||||||
name: 'astro:load-fallback-hmr',
|
const read = context.read;
|
||||||
enforce: 'pre',
|
context.read = async () => {
|
||||||
handleHotUpdate(context) {
|
const source = await tryLoadModule(context.file);
|
||||||
// Wrap context.read so it checks our filesystem first.
|
if (source) return source;
|
||||||
const read = context.read;
|
return read.call(context);
|
||||||
context.read = async () => {
|
};
|
||||||
const source = await tryLoadModule(context.file);
|
},
|
||||||
if(source) return source;
|
},
|
||||||
return read.call(context);
|
];
|
||||||
};
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryRE = /\?.*$/s;
|
const queryRE = /\?.*$/s;
|
||||||
|
|
|
@ -70,12 +70,17 @@ describe('dev container', () => {
|
||||||
let $ = cheerio.load(html);
|
let $ = cheerio.load(html);
|
||||||
expect($('body.one')).to.have.a.lengthOf(1);
|
expect($('body.one')).to.have.a.lengthOf(1);
|
||||||
|
|
||||||
fs.writeFileFromRootSync('/src/components/Header.astro', `
|
fs.writeFileFromRootSync(
|
||||||
|
'/src/components/Header.astro',
|
||||||
|
`
|
||||||
<h1>{Astro.props.title}</h1>
|
<h1>{Astro.props.title}</h1>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
triggerFSEvent(container, fs, '/src/components/Header.astro', 'change');
|
triggerFSEvent(container, fs, '/src/components/Header.astro', 'change');
|
||||||
|
|
||||||
fs.writeFileFromRootSync('/src/pages/index.astro', `
|
fs.writeFileFromRootSync(
|
||||||
|
'/src/pages/index.astro',
|
||||||
|
`
|
||||||
---
|
---
|
||||||
import Header from '../components/Header.astro';
|
import Header from '../components/Header.astro';
|
||||||
const name = 'Testing';
|
const name = 'Testing';
|
||||||
|
@ -86,7 +91,8 @@ describe('dev container', () => {
|
||||||
<Header title={name} />
|
<Header title={name} />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
triggerFSEvent(container, fs, '/src/pages/index.astro', 'change');
|
triggerFSEvent(container, fs, '/src/pages/index.astro', 'change');
|
||||||
|
|
||||||
r = createRequestAndResponse({
|
r = createRequestAndResponse({
|
||||||
|
|
|
@ -60,17 +60,11 @@ export function createFs(json, root) {
|
||||||
* @param {'change'} eventType
|
* @param {'change'} eventType
|
||||||
*/
|
*/
|
||||||
export function triggerFSEvent(container, fs, shortPath, eventType) {
|
export function triggerFSEvent(container, fs, shortPath, eventType) {
|
||||||
container.viteServer.watcher.emit(
|
container.viteServer.watcher.emit(eventType, fs.getFullyResolvedPath(shortPath));
|
||||||
eventType,
|
|
||||||
fs.getFullyResolvedPath(shortPath)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(!fileURLToPath(container.settings.config.root).startsWith('/')) {
|
if (!fileURLToPath(container.settings.config.root).startsWith('/')) {
|
||||||
const drive = fileURLToPath(container.settings.config.root).slice(0, 2);
|
const drive = fileURLToPath(container.settings.config.root).slice(0, 2);
|
||||||
container.viteServer.watcher.emit(
|
container.viteServer.watcher.emit(eventType, drive + fs.getFullyResolvedPath(shortPath));
|
||||||
eventType,
|
|
||||||
drive + fs.getFullyResolvedPath(shortPath)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue