From 6ff7c7e02eff6c0b82712c7f7263b06eaae7f9a4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 13 Nov 2020 14:18:07 +0100 Subject: [PATCH] feat: improve mocks --- packages/nitro/src/rollup/config.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/nitro/src/rollup/config.ts b/packages/nitro/src/rollup/config.ts index e79aeeb9da..58c3ae4b4a 100644 --- a/packages/nitro/src/rollup/config.ts +++ b/packages/nitro/src/rollup/config.ts @@ -18,7 +18,7 @@ import dynamicRequire from './dynamic-require' export type RollupConfig = InputOptions & { output: OutputOptions } export const getRollupConfig = (config: SLSOptions) => { - const mocks = [ + const genericMocks = [ // @nuxt/devalue 'consola', // vue2 @@ -46,8 +46,21 @@ export const getRollupConfig = (config: SLSOptions) => { const external = [] + const aliases: {[key: string]: string} = {} + if (config.node === false) { - mocks.push(...Module.builtinModules) + // Generic mocks + Object.assign(aliases, [...genericMocks, ...Module.builtinModules].reduce((p, c) => ({ ...p, [c]: '~mock' }), {})) + + // Custom + aliases.depd = '~runtime/mocks/depd' + aliases.http = '~runtime/mocks/http' + + // Builtin (browserify) + aliases.buffer = require.resolve('buffer/index.js') + aliases.util = require.resolve('util/util.js') + aliases.events = require.resolve('events/events.js') + aliases.inherits = require.resolve('inherits/inherits_browser.js') } else { external.push(...Module.builtinModules) } @@ -118,9 +131,9 @@ export const getRollupConfig = (config: SLSOptions) => { '~runtime': config.runtimeDir, '~renderer': require.resolve(resolve(config.runtimeDir, 'ssr', renderer)), '~build': config.buildDir, - '~mock': require.resolve(resolve(config.runtimeDir, 'utils/mock')), - ...mocks.reduce((p, c) => ({ ...p, [c]: '~mock' }), {}), - ...providedDeps.reduce((p, c) => ({ ...p, [c]: require.resolve(c) }), {}) + '~mock': require.resolve(resolve(config.runtimeDir, 'mocks/generic')), + ...providedDeps.reduce((p, c) => ({ ...p, [c]: require.resolve(c) }), {}), + ...aliases } }))