From 69d85d6988a503480c7a0044e9f798192fc786ad Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Thu, 28 Oct 2021 16:29:57 -0600 Subject: [PATCH] Enable Windows tests --- .github/workflows/ci.yml | 21 +++++++++---------- .github/workflows/format.yml | 2 +- .github/workflows/stat.yml | 14 ++++++------- packages/astro/package.json | 2 +- packages/astro/src/runtime/server/index.ts | 19 ++++++++++++----- packages/astro/src/vite-plugin-astro/index.ts | 3 ++- yarn.lock | 8 +++---- 7 files changed, 39 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f52a7fad0..59eee393a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,16 +18,15 @@ jobs: matrix: os: [ubuntu-latest] node_version: [12, 14, 16] - # TODO: uncomment this (Vite has trouble resolving imports on Windows) - # include: - # - os: windows-latest - # node_version: 14 + include: + - os: windows-latest + node_version: 16 fail-fast: false env: LANG: en-us name: 'Test: node-${{ matrix.node_version }}, ${{ matrix.os }}' steps: - - name: Checkout + - name: Check out uses: actions/checkout@v2 - name: Set node version to ${{ matrix.node_version }} @@ -50,16 +49,16 @@ jobs: lint: runs-on: ubuntu-latest - name: 'Lint: node-14, ubuntu-latest' + name: 'Lint: node-16, ubuntu-latest' steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set node version to 14 + - name: Set node version to 16 uses: actions/setup-node@v2 with: - node-version: 14 + node-version: 16 cache: 'yarn' - name: Debug @@ -77,16 +76,16 @@ jobs: # NOTE: temporarily disabled until `next` branch can build docs again # smoke: # runs-on: ubuntu-latest - # name: 'Smoke: node-14, ubuntu-latest' + # name: 'Smoke: node-16, ubuntu-latest' # steps: # - uses: actions/checkout@v2 # with: # fetch-depth: 0 - # - name: Set node version to 14 + # - name: Set node version to 16 # uses: actions/setup-node@v2 # with: - # node-version: 14 + # node-version: 16 # cache: 'yarn' # - name: Debug diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index bc6834e7c..fef2e7318 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,7 +6,7 @@ on: - main env: - node_version: 14 + node_version: 16 jobs: format: diff --git a/.github/workflows/stat.yml b/.github/workflows/stat.yml index 67afc0476..d9f7ea959 100644 --- a/.github/workflows/stat.yml +++ b/.github/workflows/stat.yml @@ -1,24 +1,24 @@ name: 'Collect Stats' -on: +on: schedule: # * is a special character in YAML so you have to quote this string - cron: '0 12 * * *' env: - node_version: 14 + node_version: 16 jobs: stat: if: github.repository == 'snowpackjs/astro' runs-on: ubuntu-latest steps: - # Check out code using git - - uses: actions/checkout@v2 - # Install Node 14 - - uses: actions/setup-node@v1 + - name: Check out + uses: actions/checkout@v2 + - name: Set up Node.js 16.x + uses: actions/setup-node@v1 with: - version: 14 + version: 16 - run: yarn install --frozen-lockfile --ignore-engines --ignore-scripts - run: node scripts/stats/index.js env: diff --git a/packages/astro/package.json b/packages/astro/package.json index ffb7c1fb1..54bacbeb7 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -67,7 +67,7 @@ "astring": "^1.7.5", "ci-info": "^3.2.0", "connect": "^3.7.0", - "es-module-lexer": "^0.7.1", + "es-module-lexer": "^0.9.3", "esbuild": "^0.13.6", "estree-util-value-to-estree": "^1.2.0", "fast-xml-parser": "^3.19.0", diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 7a41ef7ab..93779ad17 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -5,6 +5,7 @@ import type { TopLevelAstro } from '../../@types/astro-runtime'; import { valueToEstree } from 'estree-util-value-to-estree'; import * as astring from 'astring'; import shorthash from 'shorthash'; +import { fileURLToPath } from 'url'; export { createMetadata } from './metadata.js'; const { generate, GENERATOR } = astring; @@ -117,7 +118,11 @@ function extractDirectives(inputProps: Record): ExtractedP } switch (key) { case 'client:component-path': { - extracted.hydration.componentUrl = value; + try { + extracted.hydration.componentUrl = fileURLToPath(new URL(`file://${value}`)); + } catch { + extracted.hydration.componentUrl = value; + } break; } case 'client:component-export': { @@ -365,13 +370,17 @@ export async function renderToString(result: SSRResult, componentFactory: AstroC const uniqueElements = (item: any, index: number, all: any[]) => { const props = JSON.stringify(item.props); const children = item.children; - return index === all.findIndex(i => JSON.stringify(i.props) === props && i.children == children) -} + return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children); +}; export async function renderPage(result: SSRResult, Component: AstroComponentFactory, props: any, children: any) { const template = await renderToString(result, Component, props, children); - const styles = Array.from(result.styles).filter(uniqueElements).map((style) => renderElement('style', style)); - const scripts = Array.from(result.scripts).filter(uniqueElements).map((script) => renderElement('script', script)); + const styles = Array.from(result.styles) + .filter(uniqueElements) + .map((style) => renderElement('style', style)); + const scripts = Array.from(result.scripts) + .filter(uniqueElements) + .map((script) => renderElement('script', script)); return template.replace('', styles.join('\n') + scripts.join('\n') + ''); } diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index ee3ea5b67..d22b1caf1 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -46,7 +46,8 @@ export default function astro({ config, devServer }: AstroPluginOptions): vite.P } // pages and layouts should be transformed as full documents (implicit etc) // everything else is treated as a fragment - const isPage = id.startsWith(fileURLToPath(config.pages)) || id.startsWith(fileURLToPath(config.layouts)); + const normalizedID = fileURLToPath(new URL(`file://${id}`)); + const isPage = normalizedID.startsWith(fileURLToPath(config.pages)) || id.startsWith(fileURLToPath(config.layouts)); let source = await fs.promises.readFile(id, 'utf8'); let tsResult: TransformResult | undefined; diff --git a/yarn.lock b/yarn.lock index e5558040f..1d07087be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4074,10 +4074,10 @@ es-abstract@^1.18.0-next.2, es-abstract@^1.18.5: string.prototype.trimstart "^1.0.4" unbox-primitive "^1.0.1" -es-module-lexer@^0.7.1: - version "0.7.1" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.7.1.tgz#c2c8e0f46f2df06274cdaf0dd3f3b33e0a0b267d" - integrity sha512-MgtWFl5No+4S3TmhDmCz2ObFGm6lEpTnzbQi+Dd+pw4mlTIZTmM2iAs5gRlmx5zS9luzobCSBSI90JM/1/JgOw== +es-module-lexer@^0.9.3: + version "0.9.3" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" + integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== es-to-primitive@^1.2.1: version "1.2.1"