Skip to content

Commit

Permalink
fix path format on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Applelo committed Jan 20, 2024
1 parent 5d4e059 commit 493891e
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 98 deletions.
4 changes: 2 additions & 2 deletions demo/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"devDependencies": {
"@spiriit/vite-plugin-svg-spritemap": "workspace:*",
"@sveltejs/adapter-auto": "^3.1.0",
"@sveltejs/kit": "^2.4.0",
"@sveltejs/adapter-auto": "^3.1.1",
"@sveltejs/kit": "^2.4.1",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"sass": "^1.70.0",
"svelte": "^4.2.9",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@vitest/coverage-v8": "^1.2.1",
"c8": "^9.1.0",
"eslint": "^8.56.0",
"playwright": "^1.41.0",
"playwright": "^1.41.1",
"rollup": "^4.9.5",
"svg-element-attributes": "^2.1.0",
"tsup": "^8.0.1",
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions src/helpers/utils.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/plugins/build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'node:path'
import { posix as path } from 'node:path'
import type { ExternalOption } from 'rollup'
import type { Plugin, ResolvedConfig } from 'vite'
import type { Options, Pattern } from '../types'
import { SVGManager } from '../svgManager'
import { getFileName } from '../helpers/filename'
import { joinUrlSegments } from '../helpers/utils'

export default function BuildPlugin(iconsPattern: Pattern, options: Options): Plugin {
let config: ResolvedConfig
Expand Down Expand Up @@ -82,7 +81,7 @@ export default function BuildPlugin(iconsPattern: Pattern, options: Options): Pl
return {
code: code.replace(
spritemapFilter,
joinUrlSegments(base, this.getFileName(fileRef)),
path.join(base, this.getFileName(fileRef)),
),
map: null,
}
Expand Down
19 changes: 10 additions & 9 deletions test/external.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ import type { ExternalOption } from 'rollup'
import { buildVite } from './helper/build'

const configs: Record<string, ExternalOption | undefined> = {
'no external': undefined,
'external string': 'jquery',
'external array': ['jquery'],
'external function': (source) => {
no_external: undefined,
external_string: 'jquery',
external_array: ['jquery'],
external_function: (source) => {
if (source.includes('jquery'))
return true
},
}

describe('output manifest generation', () => {
describe('external', () => {
for (const key in configs) {
if (Object.prototype.hasOwnProperty.call(configs, key)) {
it(key, async () => {
const config = configs[key]
await buildVite(
await buildVite({
name: `external_${key}`,
options:
{
output: true,
},
null,
{
viteConfig: {
build: {
rollupOptions: {
external: config,
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('output manifest generation', () => {
},
],
},
)
})
})
}
}
Expand Down
17 changes: 11 additions & 6 deletions test/helper/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import VitePluginSvgSpritemap from '../../src'
import type { UserOptions } from '../../src/types'
import { getPath } from './path'

export async function buildVite(
options: UserOptions,
path: string | null = null,
config: InlineConfig = {},
) {
export async function buildVite(obj: {
name: string
options?: UserOptions
path?: string
viteConfig?: InlineConfig
}) {
const { name, options, path, viteConfig } = obj
const defaultConfig: InlineConfig = {
root: getPath('./fixtures/basic'),
build: {
outDir: getPath(`./fixtures/basic/dist/${name}`),
},
plugins: [
VitePluginSvgSpritemap(
getPath(path || './fixtures/basic/svg/*.svg'),
Expand All @@ -19,5 +24,5 @@ export async function buildVite(
],
}

return await build(mergeConfig(defaultConfig, config))
return await build(mergeConfig(defaultConfig, viteConfig || {}))
}
2 changes: 1 addition & 1 deletion test/idify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('idefy', () => {
if (Object.prototype.hasOwnProperty.call(idifyConfigs, key)) {
it(key, async () => {
const idify = idifyConfigs[key]
const result = await buildVite({ idify })
const result = await buildVite({ name: `idify_${key}`, options: { idify } })
if (!('output' in result))
return
const asset = result.output.find(
Expand Down
Loading

0 comments on commit 493891e

Please sign in to comment.