Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix REPL in dev #4964

Merged
merged 2 commits into from Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions build-plugins/replace-browser-modules.ts
@@ -1,6 +1,6 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Plugin } from 'rollup';
import type { Plugin } from 'vite';

const resolve = (path: string) => fileURLToPath(new URL(`../${path}`, import.meta.url));

Expand All @@ -14,10 +14,10 @@ const REPLACED_MODULES = [
'resolveId'
];

export const resolutions: ReadonlyMap<string, string> = new Map(
const resolutions: ReadonlyMap<string, string> = new Map(
REPLACED_MODULES.flatMap(module => {
const originalId = resolve(`src/utils/${module}`);
const replacementId = resolve(`browser/src//${module}.ts`);
const replacementId = resolve(`browser/src/${module}.ts`);
return [
[originalId, replacementId],
[`${originalId}.ts`, replacementId]
Expand All @@ -27,11 +27,18 @@ export const resolutions: ReadonlyMap<string, string> = new Map(

export default function replaceBrowserModules(): Plugin {
return {
apply: 'serve',
enforce: 'pre',
name: 'replace-browser-modules',
resolveId(source, importer) {
if (importer && source[0] === '.') {
return resolutions.get(join(dirname(importer), source));
}
},
transformIndexHtml(html) {
// Unfortunately, picomatch sneaks as a dedendency into the dev bundle.
// This fixes an error.
return html.replace('</head>', '<script>window.process={}</script></head>');
}
};
}
18 changes: 2 additions & 16 deletions docs/.vitepress/config.ts
@@ -1,7 +1,7 @@
import alias from '@rollup/plugin-alias';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sir

import { defineConfig } from 'vitepress';
import { moduleAliases } from '../../build-plugins/aliases';
import { resolutions } from '../../build-plugins/replace-browser-modules';
import replaceBrowserModules from '../../build-plugins/replace-browser-modules';
import '../declarations.d';
import { examplesPlugin } from './create-examples';
import { renderMermaidGraphsPlugin } from './mermaid';
Expand Down Expand Up @@ -135,21 +135,7 @@ export default defineConfig({
vite: {
plugins: [
renderMermaidGraphsPlugin(),
{
apply: 'serve',
enforce: 'pre',
name: 'replace-browser-modules',
resolveId(source, importer) {
if (importer && source.startsWith('/@fs')) {
return resolutions.get(source.slice(4));
}
},
transformIndexHtml(html) {
// Unfortunately, picomatch sneaks as a dedendency into the dev bundle.
// This fixes an error.
return html.replace('</head>', '<script>window.process={}</script></head>');
}
},
replaceBrowserModules(),
{
apply: 'build',
enforce: 'pre',
Expand Down
2 changes: 1 addition & 1 deletion test/watch/index.js
Expand Up @@ -1263,7 +1263,7 @@ describe('rollup.watch', () => {

it('rebuilds immediately by default', async () => {
await copy('test/watch/samples/basic', 'test/_tmp/input');
await wait(200);
await wait(300);
watcher = rollup.watch({
input: 'test/_tmp/input/main.js',
output: {
Expand Down