Skip to content

Commit

Permalink
chore: format and fix typo (#5718)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Nov 17, 2021
1 parent 01f9b16 commit 5987a77
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 33 deletions.
1 change: 0 additions & 1 deletion packages/playground/ssr-vue/__tests__/ssr-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test('vuex can be import succeed by named import', async () => {
expect(storeHtml).toMatch('bar')
})


test('/about', async () => {
await page.goto(url + '/about')
expect(await page.textContent('h1')).toMatch('About')
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/tailwind/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default defineConfig({
server: {
// This option caused issues with HMR,
// although it should not affect the build
origin: "http://localhost:8080/",
origin: 'http://localhost:8080/'
}
})
2 changes: 1 addition & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
const isProjectFile =
!isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/'))

let plugins = isProjectFile ? [...userPlugins] : []
const plugins = isProjectFile ? [...userPlugins] : []

let useFastRefresh = false
if (!skipFastRefresh && !ssr && !isNodeModules) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
? createFilter(/\.(j|t)sx?$/, /node_modules/)
: createFilter(refTransform)

// compat for older verisons
// compat for older versions
const canUseRefTransform = typeof compiler.shouldTransformRef === 'function'

let options: ResolvedOptions = {
Expand Down
76 changes: 52 additions & 24 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,56 @@ describe('resolveLibFilename', () => {

describe('resolveBuildOptions', () => {
test('resolve build.rollupOptions.input', async () => {
const config = await resolveConfig({
build: {
rollupOptions: {
input: 'index.html'
const config = await resolveConfig(
{
build: {
rollupOptions: {
input: 'index.html'
}
}
}
}, 'build', 'production')
},
'build',
'production'
)

expect(config.build.rollupOptions.input).toBe(resolve('index.html'))
})
test('resolve build.rollupOptions.input{}', async () => {
const config = await resolveConfig({
build: {
rollupOptions: {
input: {
index: 'index.html'
const config = await resolveConfig(
{
build: {
rollupOptions: {
input: {
index: 'index.html'
}
}
}
}
}, 'build', 'production')
},
'build',
'production'
)

expect(config.build.rollupOptions.input['index']).toBe(resolve('index.html'))
expect(config.build.rollupOptions.input['index']).toBe(
resolve('index.html')
)
})

test('resolve build.rollupOptions.input[]', async () => {
const config = await resolveConfig({
build: {
rollupOptions: {
input: ['index.html']
const config = await resolveConfig(
{
build: {
rollupOptions: {
input: ['index.html']
}
}
}
}, 'build', 'production')
},
'build',
'production'
)

expect(config.build.rollupOptions.input).toStrictEqual([resolve('index.html')])
expect(config.build.rollupOptions.input).toStrictEqual([
resolve('index.html')
])
})

test('resolve index.html', async () => {
Expand All @@ -112,7 +128,11 @@ describe('resolveBuildOptions', () => {
})

test('resolve build.outdir', async () => {
const config = await resolveConfig({ build: { outDir: 'outDir' } }, 'build', 'production')
const config = await resolveConfig(
{ build: { outDir: 'outDir' } },
'build',
'production'
)

expect(config.build.outDir).toBe(resolve('outDir'))
})
Expand All @@ -124,13 +144,21 @@ describe('resolveBuildOptions', () => {
})

test('resolve build.lib.entry', async () => {
const config = await resolveConfig({ build: { lib: { entry: 'index.html' } } }, 'build', 'production')
const config = await resolveConfig(
{ build: { lib: { entry: 'index.html' } } },
'build',
'production'
)

expect(config.build.rollupOptions.input).toBe(resolve('index.html'))
})

test('resolve build.ssr', async () => {
const config = await resolveConfig({ build: { ssr: 'ssr.ts' } }, 'build', 'production')
const config = await resolveConfig(
{ build: { ssr: 'ssr.ts' } },
'build',
'production'
)

expect(config.build.rollupOptions.input).toBe(resolve('ssr.ts'))
})
Expand Down
15 changes: 11 additions & 4 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ export type ResolvedBuildOptions = Required<
>
>

export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedBuildOptions {
export function resolveBuildOptions(
root: string,
raw?: BuildOptions
): ResolvedBuildOptions {
const resolved: ResolvedBuildOptions = {
target: 'modules',
polyfillModulePreload: true,
Expand Down Expand Up @@ -269,18 +272,22 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB
}
}

const resolve = (p: string) => p.startsWith('\0') ? p : path.resolve(root, p)
const resolve = (p: string) =>
p.startsWith('\0') ? p : path.resolve(root, p)

resolved.outDir = resolve(resolved.outDir)

let input

if (raw?.rollupOptions?.input) {
input = Array.isArray(raw.rollupOptions.input)
? raw.rollupOptions.input.map(input => resolve(input))
? raw.rollupOptions.input.map((input) => resolve(input))
: typeof raw.rollupOptions.input === 'object'
? Object.fromEntries(
Object.entries(raw.rollupOptions.input).map(([key, value]) => [key, resolve(value)])
Object.entries(raw.rollupOptions.input).map(([key, value]) => [
key,
resolve(value)
])
)
: resolve(raw.rollupOptions.input)
} else {
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
: await moduleGraph.ensureEntryFromUrl(
(
await fileToUrl(file, config, this)
).replace((config.server?.origin ?? '') + config.base, '/')
).replace(
(config.server?.origin ?? '') + config.base,
'/'
)
)
)
}
Expand Down

0 comments on commit 5987a77

Please sign in to comment.