Skip to content

Commit

Permalink
ci: setup windows ci for compiler and SSR tests (vuejs#8143)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 24, 2023
1 parent 29da504 commit 01f43c1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
36 changes: 34 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,40 @@ 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

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'

- 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

- 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
Expand Down Expand Up @@ -72,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
Expand Down
18 changes: 10 additions & 8 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
createGetCanonicalFileName,
getId,
getImportedName,
normalizePath
normalizePath,
joinPaths
} from './utils'
import { ScriptCompileContext, resolveParserPlugins } from './context'
import { ImportBinding, SFCScriptCompileOptions } from '../compileScript'
Expand All @@ -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
Expand Down Expand Up @@ -718,7 +719,7 @@ function importSourceToScope(
let resolved
if (source.startsWith('.')) {
// relative import - fast path
const filename = normalizePath(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
Expand All @@ -741,9 +742,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)}.`,
Expand All @@ -761,8 +763,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(joinPaths(filename, `index.ts`)) ||
tryResolve(joinPaths(filename, `index.d.ts`))
)
}

Expand Down Expand Up @@ -800,7 +802,7 @@ function resolveWithTS(
const parsed = ts.parseJsonConfigFileContent(
ts.readConfigFile(configPath, fs.readFile).config,
parseConfigHost,
path.dirname(configPath),
dirname(configPath),
undefined,
configPath
)
Expand Down Expand Up @@ -870,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),
Expand Down
9 changes: 6 additions & 3 deletions packages/compiler-sfc/src/script/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 01f43c1

Please sign in to comment.