Skip to content

Commit

Permalink
rename virtual module according to vite convention and fix the module…
Browse files Browse the repository at this point in the history
… not being found in build
  • Loading branch information
StarLederer committed Apr 4, 2022
1 parent 2595b34 commit 2d50884
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ await fs.rm('path/to/somewhere', { recursive: true });
This is a more direct way to interact with the relay server, however, it is inconvenient, error-prone and does not have a stable API. Breaking changes to this method are not documented. **This method is documented purely for educational reasons.** Only use this method if you want to play around with the plugin and better understand what it does in the background.

```ts
import { activePort } from '@vite-plugin-fs-runtime';
import { activePort } from 'virtual:fs';

const url = `http://localhost:${activePort}`;

Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/abstraction/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ global.fetch = jest.fn((url: RequestInfo, init?: RequestInit) => {
}) as jest.Mock;

const testPort = 7070;
jest.mock('@vite-plugin-fs-runtime', () => ({ activePort: 7070 }), { virtual: true });
jest.mock('virtual:fs', () => ({ activePort: 7070 }), { virtual: true });

describe('abstraction', () => {
it('should build correct readdir queries', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/abstraction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { activePort } from '@vite-plugin-fs-runtime';
import { activePort } from 'virtual:fs';
import type { SimpleDirent, SimpleStats } from 'src/common/ApiResponses';

const url = `http://localhost:${activePort}`;
Expand Down
8 changes: 7 additions & 1 deletion src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserOptions, resolveOptions } from './Options';
function VitePluginFs(userOptiuons: UserOptions = {}): Plugin {
const options = resolveOptions(userOptiuons);

const virtualModuleId = '@vite-plugin-fs-runtime';
const virtualModuleId = 'virtual:fs';
const resolvedVirtualModuleId = `\0${virtualModuleId}`;

let server: null | FsServer = null;
Expand All @@ -21,6 +21,12 @@ function VitePluginFs(userOptiuons: UserOptions = {}): Plugin {
if (env.mode === 'development') {
isProd = false;
}

return {
optimizeDeps: {
exclude: [virtualModuleId],
},
};
},

async buildStart() {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare module '@vite-plugin-fs-runtime' {
declare module 'virtual:fs' {
const activePort: number;
}
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export default defineConfig({
format: ['cjs', 'esm'],
target: 'node14',
outDir: 'lib',
external: ['@vite-plugin-fs-runtime'],
external: ['virtual:fs'],
});

0 comments on commit 2d50884

Please sign in to comment.