From 9058f9024ece03af4e8a995d11dead09ad569a24 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Apr 2023 11:09:33 +0800 Subject: [PATCH 1/4] refactor(compiler-sfc): ensure registered deps are normalized --- packages/compiler-sfc/src/script/resolveType.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index ac1a42be9bd..e91293dd955 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -718,7 +718,7 @@ function importSourceToScope( let resolved if (source.startsWith('.')) { // relative import - fast path - const filename = normalizePath(path.join(scope.filename, '..', source)) + const filename = path.join(scope.filename, '..', source) resolved = resolveExt(filename, fs) } else { // module or aliased import - use full TS resolution, only supported in Node @@ -741,9 +741,10 @@ function importSourceToScope( resolved = resolveWithTS(scope.filename, source, fs) } if (resolved) { + resolved = normalizePath(resolved) // (hmr) register dependency file on ctx ;(ctx.deps || (ctx.deps = new Set())).add(resolved) - return fileToScope(ctx, normalizePath(resolved)) + return fileToScope(ctx, resolved) } else { return ctx.error( `Failed to resolve import source ${JSON.stringify(source)}.`, @@ -761,8 +762,8 @@ function resolveExt(filename: string, fs: FS) { tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.d.ts`) || - tryResolve(filename + `/index.ts`) || - tryResolve(filename + `/index.d.ts`) + tryResolve(path.join(filename, `index.ts`)) || + tryResolve(path.join(filename, `index.d.ts`)) ) } From dbf2e582c385e5bf8a18a717dcb86a444e8703df Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Apr 2023 11:15:02 +0800 Subject: [PATCH 2/4] ci: add windows ci for compiler and ssr tests --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d022e11cca4..3cf31090060 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,29 @@ jobs: - name: Run unit tests run: pnpm run test-unit + unit-test-windows: + runs-on: windows-latest + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + steps: + - uses: actions/checkout@v3 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + + - name: Set node version to 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + + - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + + - name: Run compiler unit tests + run: pnpm run test-unit compiler + + - name: Run ssr unit tests + run: pnpm run test-unit server-renderer + e2e-test: runs-on: ubuntu-latest if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository From aa3942c1f149f45ebf5599bd7a570a8d8e7d2363 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Apr 2023 11:19:44 +0800 Subject: [PATCH 3/4] ci: fix window env setting --- .github/workflows/ci.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cf31090060..c52bbc06970 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,10 @@ jobs: node-version: 18 cache: 'pnpm' - - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + - name: Skip Puppeteer download + run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $GITHUB_ENV + + - run: pnpm install - name: Run unit tests run: pnpm run test-unit @@ -46,7 +49,10 @@ jobs: node-version: 18 cache: 'pnpm' - - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + - name: Skip Puppeteer download + run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $env:GITHUB_ENV + + - run: pnpm install - name: Run compiler unit tests run: pnpm run test-unit compiler @@ -95,7 +101,10 @@ jobs: node-version: 18 cache: 'pnpm' - - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + - name: Skip Puppeteer download + run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $GITHUB_ENV + + - run: pnpm install - name: Run eslint run: pnpm run lint From 45a290d294fdce505947e729b977721e63c395db Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Apr 2023 11:26:57 +0800 Subject: [PATCH 4/4] fix(compiler-sfc): ensure consistent path join on windows --- packages/compiler-sfc/src/script/resolveType.ts | 15 ++++++++------- packages/compiler-sfc/src/script/utils.ts | 9 ++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index e91293dd955..d0fd9c5896c 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -29,7 +29,8 @@ import { createGetCanonicalFileName, getId, getImportedName, - normalizePath + normalizePath, + joinPaths } from './utils' import { ScriptCompileContext, resolveParserPlugins } from './context' import { ImportBinding, SFCScriptCompileOptions } from '../compileScript' @@ -38,7 +39,7 @@ import { parse as babelParse } from '@babel/parser' import { parse } from '../parse' import { createCache } from '../cache' import type TS from 'typescript' -import path from 'path' +import { extname, dirname } from 'path' /** * TypeResolveContext is compatible with ScriptCompileContext @@ -718,7 +719,7 @@ function importSourceToScope( let resolved if (source.startsWith('.')) { // relative import - fast path - const filename = path.join(scope.filename, '..', source) + const filename = joinPaths(scope.filename, '..', source) resolved = resolveExt(filename, fs) } else { // module or aliased import - use full TS resolution, only supported in Node @@ -762,8 +763,8 @@ function resolveExt(filename: string, fs: FS) { tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.d.ts`) || - tryResolve(path.join(filename, `index.ts`)) || - tryResolve(path.join(filename, `index.d.ts`)) + tryResolve(joinPaths(filename, `index.ts`)) || + tryResolve(joinPaths(filename, `index.d.ts`)) ) } @@ -801,7 +802,7 @@ function resolveWithTS( const parsed = ts.parseJsonConfigFileContent( ts.readConfigFile(configPath, fs.readFile).config, parseConfigHost, - path.dirname(configPath), + dirname(configPath), undefined, configPath ) @@ -871,7 +872,7 @@ function parseFile( content: string, parserPlugins?: SFCScriptCompileOptions['babelParserPlugins'] ): Statement[] { - const ext = path.extname(filename) + const ext = extname(filename) if (ext === '.ts' || ext === '.tsx') { return babelParse(content, { plugins: resolveParserPlugins(ext.slice(1), parserPlugins), diff --git a/packages/compiler-sfc/src/script/utils.ts b/packages/compiler-sfc/src/script/utils.ts index e8a0518b570..53362fcdca8 100644 --- a/packages/compiler-sfc/src/script/utils.ts +++ b/packages/compiler-sfc/src/script/utils.ts @@ -99,9 +99,12 @@ export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean) { return useCaseSensitiveFileNames ? identity : toFileNameLowerCase } +// in the browser build, the polyfill doesn't expose posix, but defaults to +// posix behavior. +const normalize = (path.posix || path).normalize const windowsSlashRE = /\\/g export function normalizePath(p: string) { - // in the browser build, the polyfill doesn't expose posix, but defaults to - // posix behavior. - return (path.posix || path).normalize(p.replace(windowsSlashRE, '/')) + return normalize(p.replace(windowsSlashRE, '/')) } + +export const joinPaths = (path.posix || path).join