From cdf96d3f874f4848da698026833120751659466e Mon Sep 17 00:00:00 2001 From: kanno <812137533@qq.com> Date: Wed, 10 Jan 2024 04:14:33 +0800 Subject: [PATCH] fix:windows system should format slash --- e2e/fixtures/open-props/index.html | 2 +- e2e/fixtures/open-props/{ => src}/app.tsx | 0 e2e/fixtures/open-props/{ => src}/main.tsx | 0 e2e/fixtures/path-alias/src/app.tsx | 5 +++-- e2e/fixtures/path-alias/src/themes/color.stylex.ts | 6 ++++++ package.json | 5 ----- src/patch-alias.ts | 6 +++--- 7 files changed, 13 insertions(+), 11 deletions(-) rename e2e/fixtures/open-props/{ => src}/app.tsx (100%) rename e2e/fixtures/open-props/{ => src}/main.tsx (100%) create mode 100644 e2e/fixtures/path-alias/src/themes/color.stylex.ts diff --git a/e2e/fixtures/open-props/index.html b/e2e/fixtures/open-props/index.html index b24cbd1..5727caa 100644 --- a/e2e/fixtures/open-props/index.html +++ b/e2e/fixtures/open-props/index.html @@ -7,6 +7,6 @@
- + \ No newline at end of file diff --git a/e2e/fixtures/open-props/app.tsx b/e2e/fixtures/open-props/src/app.tsx similarity index 100% rename from e2e/fixtures/open-props/app.tsx rename to e2e/fixtures/open-props/src/app.tsx diff --git a/e2e/fixtures/open-props/main.tsx b/e2e/fixtures/open-props/src/main.tsx similarity index 100% rename from e2e/fixtures/open-props/main.tsx rename to e2e/fixtures/open-props/src/main.tsx diff --git a/e2e/fixtures/path-alias/src/app.tsx b/e2e/fixtures/path-alias/src/app.tsx index e724b2e..18cca31 100644 --- a/e2e/fixtures/path-alias/src/app.tsx +++ b/e2e/fixtures/path-alias/src/app.tsx @@ -2,14 +2,15 @@ /* eslint-disable jsx-a11y/click-events-have-key-events */ import * as stylex from '@stylexjs/stylex' import { useState } from 'react' +import { colors } from '@/themes/color.stylex' const styles = stylex.create({ text: { fontSize: '20px', cursor: 'pointer' }, blue: { - color: 'blue' + color: colors.blue }, red: { - color: 'red' + color: colors.red } }) diff --git a/e2e/fixtures/path-alias/src/themes/color.stylex.ts b/e2e/fixtures/path-alias/src/themes/color.stylex.ts new file mode 100644 index 0000000..dc8deca --- /dev/null +++ b/e2e/fixtures/path-alias/src/themes/color.stylex.ts @@ -0,0 +1,6 @@ +import { defineVars } from '@stylexjs/stylex' + +export const colors = defineVars({ + blue: 'blue', + red: 'red' +}) diff --git a/package.json b/package.json index 2d13d80..cc59650 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,6 @@ "import": "./dist/index.mjs", "require": "./dist/index.js" }, - "./url.js": { - "types": "./dist/url.d.ts", - "import": "./dist/url.mjs", - "require": "./dist/url.js" - }, "./*": "./*" }, "files": [ diff --git a/src/patch-alias.ts b/src/patch-alias.ts index e980f0e..234c901 100644 --- a/src/patch-alias.ts +++ b/src/patch-alias.ts @@ -9,6 +9,7 @@ // convert: // import { kind } from './x.stylex' import path from 'path' +import { normalizePath } from 'vite' import MagicString from 'magic-string' import type { ImportSpecifier } from 'es-module-lexer' import type { Alias, AliasOptions, Plugin } from 'vite' @@ -22,9 +23,8 @@ interface PatchAliasOptions { type AliasPath = ImportSpecifier & { relative: string } function handleRelativePath(from: string, to: string) { - let relativePath = path.relative(path.dirname(from), to).replace(/\.\w+$/, '') - relativePath = `./${relativePath}` - return relativePath + const relativePath = path.relative(path.dirname(from), to).replace(/\.\w+$/, '') + return `./${normalizePath(relativePath)}` } export function createPatchAlias(alias: AliasOptions & Alias[], opts: PatchAliasOptions) {