Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Vite fork #1585

Merged
merged 5 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
!packages/astro/**/*.js
!packages/astro/**/*.ts
packages/astro/test/**/*.js
packages/astro/vendor/vite/**/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ package-lock.json

# do not commit .env files or any files that end with `.env`
*.env

!packages/astro/vendor/vite/dist
3 changes: 2 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"components",
"dist",
"astro.js",
"README.md"
"README.md",
"vite"
],
"scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { rollupPluginHTML } from '@web/rollup-plugin-html';
import fs from 'fs';
import { bold, cyan, green, dim } from 'kleur/colors';
import { performance } from 'perf_hooks';
import vite, { ViteDevServer } from 'vite';
import vite, { ViteDevServer } from '../vite.js';
Copy link
Member

@FredKSchott FredKSchott Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on using a Node.js import map, and import from '#vite'? It will be easier to switch in-and-out in the future as needed, if this ever happens again https://nodejs.org/api/packages.html#packages_subpath_imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this but TypeScript doesn't seem to understand the # syntax. microsoft/TypeScript#44848

I created this vite.ts wrapper to serve this purpose, we can just change that file when moving back to real vite and not have to update any other files.

import { fileURLToPath } from 'url';
import { createVite } from '../create-vite.js';
import { pad } from '../dev/util.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs';
import slash from 'slash';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
import vite from 'vite';
import vite from './vite.js';
import astroVitePlugin from '../vite-plugin-astro/index.js';
import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js';
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
Expand Down
7 changes: 4 additions & 3 deletions packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { NextFunction } from 'connect';
import type http from 'http';
import type { AstroConfig, ManifestData, RouteCache, RouteData } from '../../@types/astro-core';
import type { LogOptions } from '../logger';
import type { HmrContext, ModuleNode } from 'vite';
import type { HmrContext, ModuleNode } from '../vite';

import { fileURLToPath } from 'url';
import connect from 'connect';
import mime from 'mime';
import { performance } from 'perf_hooks';
import stripAnsi from 'strip-ansi';
import vite from 'vite';
import vite from '../vite.js';
import { defaultLogOptions, error, info } from '../logger.js';
import { ssr } from '../ssr/index.js';
import { createRouteManifest, matchRoute } from '../ssr/routing.js';
Expand Down Expand Up @@ -151,7 +151,8 @@ export class AstroDevServer {
} catch (e) {
const err = e as Error;
this.viteServer.ssrFixStacktrace(err);
console.log(err.stack);
// eslint-disable-next-line
console.error(err.stack);
this.viteServer.ws.send({
type: 'full-reload',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/ssr/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BuildResult } from 'esbuild';
import type { ViteDevServer } from 'vite';
import type { ViteDevServer } from '../vite';
import type { AstroConfig, ComponentInstance, GetStaticPathsResult, Params, Props, Renderer, RouteCache, RouteData, RuntimeMode, SSRError } from '../../@types/astro-core';
import type { AstroGlobal, TopLevelAstro, SSRResult } from '../../@types/astro-runtime';
import type { LogOptions } from '../logger';
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/core/vite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../../vendor/vite/dist/node/index.js';
export { default } from '../../vendor/vite/dist/node/index.js';
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function createFetchContentFn(url: URL) {
}

export function createAstro(fileURLStr: string, site: string): TopLevelAstro {
const url = pathToFileURL(fileURLStr);
const url = new URL(fileURLStr);
const fetchContent = createFetchContentFn(url) as unknown as TopLevelAstro['fetchContent'];
return {
// TODO I think this is no longer needed.
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/runtime/server/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { pathToFileURL } from 'url';

interface ModuleInfo {
module: Record<string, any>;
specifier: string;
Expand All @@ -14,7 +12,7 @@ class Metadata {
public fileURL: URL;
private metadataCache: Map<any, ComponentMetadata | null>;
constructor(fileURL: string, public modules: ModuleInfo[], components: any[]) {
this.fileURL = pathToFileURL(fileURL);
this.fileURL = new URL(fileURL);
this.metadataCache = new Map<any, ComponentMetadata | null>();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-postprocess/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as t from '@babel/types';
import type { Plugin } from 'vite';
import type { Plugin } from '../core/vite';
import type { AstroConfig } from '../@types/astro-core';
import type { AstroDevServer } from '../core/dev/index';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TransformResult } from '@astrojs/compiler';
import type { Plugin } from 'vite';
import type { Plugin } from '../core/vite';
import type { AstroConfig } from '../@types/astro-core';

import esbuild from 'esbuild';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite';
import type { Plugin } from '../core/vite';
import MagicString from 'magic-string';

// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-jsx/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite';
import type { Plugin } from '../core/vite';
import type { TransformResult } from 'rollup';
import type { AstroConfig, Renderer } from '../@types/astro-core';
import type { LogOptions } from '../core/logger';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite';
import type { Plugin } from '../core/vite';
import type { AstroConfig } from '../@types/astro-core';

import esbuild from 'esbuild';
Expand Down
28 changes: 14 additions & 14 deletions packages/astro/test/astro-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

let fixture;
let previewServer;
describe('Astro basics', () => {
let fixture;
let previewServer;

before(async () => {
fixture = await loadFixture({ projectRoot: './fixtures/astro-basic/' });
await fixture.build();
previewServer = await fixture.preview();
});
before(async () => {
fixture = await loadFixture({ projectRoot: './fixtures/astro-basic/' });
await fixture.build();
previewServer = await fixture.preview();
});

// important: close preview server (free up port and connection)
after(async () => {
if (previewServer) await previewServer.stop();
});

describe('Astro basics', () => {
describe('build', () => {
it('Can load page', async () => {
const html = await fixture.readFile(`/index.html`);
Expand Down Expand Up @@ -89,9 +94,4 @@ describe('Astro basics', () => {
expect(result.status).to.equal(404);
});
});
});

// important: close preview server (free up port and connection)
after(async () => {
if (previewServer) await previewServer.stop();
});
});
4 changes: 2 additions & 2 deletions packages/astro/test/astro-global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Astro.*', () => {
it('Astro.resolve in development', async () => {
const html = await fixture.readFile('/resolve/index.html');
const $ = cheerio.load(html);
expect($('img').attr('src')).to.equal('/src/images/penguin.png');
expect($('#inner-child img').attr('src')).to.equal('/src/components/nested/images/penguin.png');
expect($('img').attr('src')).to.include('/src/images/penguin.png');
expect($('#inner-child img').attr('src')).to.include('/src/components/nested/images/penguin.png');
});
});
21 changes: 21 additions & 0 deletions packages/astro/vendor/vite/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading