Compare commits

...

4 commits

Author SHA1 Message Date
unknown
9b3c57a1cf Move client types into Astro 2022-07-07 15:36:29 -04:00
unknown
c53ec165fb Export the Image type 2022-07-07 13:32:08 -04:00
unknown
9e0582aeb0 Adds a changeset 2022-07-07 12:25:54 -04:00
unknown
86b6e4bfb8 Allow importing Image component from @astrojs/image 2022-07-07 12:23:25 -04:00
39 changed files with 259 additions and 36 deletions

View file

@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/image': patch
---
Allow importing the Image component from @astrojs/image

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -1,4 +1,4 @@
/// <reference types="vite/client" /> /// <reference types="astro/client" />
interface ImportMetaEnv { interface ImportMetaEnv {
readonly DB_PASSWORD: string; readonly DB_PASSWORD: string;

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -13,6 +13,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -13,6 +13,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -10,6 +10,6 @@
// Enable stricter transpilation for better output. // Enable stricter transpilation for better output.
"isolatedModules": true, "isolatedModules": true,
// Add type definitions for our Vite runtime. // Add type definitions for our Vite runtime.
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

207
packages/astro/client.d.ts vendored Normal file
View file

@ -0,0 +1,207 @@
/// <reference types="vite/types/importMeta" />
// CSS modules
type CSSModuleClasses = { readonly [key: string]: string }
declare module '*.module.css' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.scss' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.sass' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.less' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.styl' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.stylus' {
const classes: CSSModuleClasses
export default classes
}
declare module '*.module.pcss' {
const classes: CSSModuleClasses
export default classes
}
// CSS
declare module '*.css' {
const css: string
export default css
}
declare module '*.scss' {
const css: string
export default css
}
declare module '*.sass' {
const css: string
export default css
}
declare module '*.less' {
const css: string
export default css
}
declare module '*.styl' {
const css: string
export default css
}
declare module '*.stylus' {
const css: string
export default css
}
declare module '*.pcss' {
const css: string
export default css
}
// Built-in asset types
// see `src/constants.ts`
// images
declare module '*.jpg' {
const src: string
export default src
}
declare module '*.jpeg' {
const src: string
export default src
}
declare module '*.png' {
const src: string
export default src
}
declare module '*.gif' {
const src: string
export default src
}
declare module '*.svg' {
const src: string
export default src
}
declare module '*.ico' {
const src: string
export default src
}
declare module '*.webp' {
const src: string
export default src
}
declare module '*.avif' {
const src: string
export default src
}
// media
declare module '*.mp4' {
const src: string
export default src
}
declare module '*.webm' {
const src: string
export default src
}
declare module '*.ogg' {
const src: string
export default src
}
declare module '*.mp3' {
const src: string
export default src
}
declare module '*.wav' {
const src: string
export default src
}
declare module '*.flac' {
const src: string
export default src
}
declare module '*.aac' {
const src: string
export default src
}
// fonts
declare module '*.woff' {
const src: string
export default src
}
declare module '*.woff2' {
const src: string
export default src
}
declare module '*.eot' {
const src: string
export default src
}
declare module '*.ttf' {
const src: string
export default src
}
declare module '*.otf' {
const src: string
export default src
}
// other
declare module '*.wasm' {
const initWasm: (options: WebAssembly.Imports) => Promise<WebAssembly.Exports>
export default initWasm
}
declare module '*.webmanifest' {
const src: string
export default src
}
declare module '*.pdf' {
const src: string
export default src
}
declare module '*.txt' {
const src: string
export default src
}
// web worker
declare module '*?worker' {
const workerConstructor: {
new (): Worker
}
export default workerConstructor
}
declare module '*?worker&inline' {
const workerConstructor: {
new (): Worker
}
export default workerConstructor
}
declare module '*?sharedworker' {
const sharedWorkerConstructor: {
new (): SharedWorker
}
export default sharedWorkerConstructor
}
declare module '*?raw' {
const src: string
export default src
}
declare module '*?url' {
const src: string
export default src
}
declare module '*?inline' {
const src: string
export default src
}

View file

@ -1,4 +1,4 @@
/// <reference types="vite/client" /> /// <reference path="./client.d.ts" />
type Astro = import('astro').AstroGlobal; type Astro = import('astro').AstroGlobal;

View file

@ -26,6 +26,7 @@
"exports": { "exports": {
".": "./astro.js", ".": "./astro.js",
"./env": "./env.d.ts", "./env": "./env.d.ts",
"./client": "./client.d.ts",
"./astro-jsx": "./astro-jsx.d.ts", "./astro-jsx": "./astro-jsx.d.ts",
"./jsx/*": "./dist/jsx/*", "./jsx/*": "./dist/jsx/*",
"./jsx-runtime": "./dist/jsx-runtime/index.js", "./jsx-runtime": "./dist/jsx-runtime/index.js",
@ -63,6 +64,7 @@
"config.d.ts", "config.d.ts",
"config.mjs", "config.mjs",
"env.d.ts", "env.d.ts",
"client.d.ts",
"astro-jsx.d.ts", "astro-jsx.d.ts",
"README.md", "README.md",
"vendor" "vendor"

View file

@ -111,6 +111,7 @@ export async function createVite(
replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)), replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)),
}, },
], ],
conditions: ['astro'],
}, },
// Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html) // Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html)
ssr: { ssr: {
@ -129,6 +130,7 @@ export async function createVite(
result = vite.mergeConfig(result, astroConfig.vite || {}); result = vite.mergeConfig(result, astroConfig.vite || {});
result = vite.mergeConfig(result, commandConfig); result = vite.mergeConfig(result, commandConfig);
sortPlugins(result); sortPlugins(result);
return result; return result;
} }

View file

@ -7,6 +7,6 @@
"module": "ES2020", "module": "ES2020",
"outDir": "./dist", "outDir": "./dist",
"target": "ES2020", "target": "ES2020",
"types": ["vite/client"] "types": ["astro/client"]
} }
} }

View file

@ -109,7 +109,7 @@ export default {
```html ```html
--- ---
import { Image } from '@astrojs/image/components'; import { Image } from '@astrojs/image';
import heroImage from '../assets/hero.png'; import heroImage from '../assets/hero.png';
--- ---
@ -136,7 +136,7 @@ import heroImage from '../assets/hero.png';
```html ```html
--- ---
import { Image } from '@astrojs/image/components'; import { Image } from '@astrojs/image';
const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'; const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
--- ---
@ -162,7 +162,7 @@ const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelog
```html ```html
--- ---
setup: | setup: |
import { Image } from '@astrojs/image/components' import { Image } from '@astrojs/image'
import hero from '../../assets/blog/introducing-astro.jpg' import hero from '../../assets/blog/introducing-astro.jpg'
title: Hello world! title: Hello world!
publishDate: 12 Sep 2021 publishDate: 12 Sep 2021

View file

@ -19,7 +19,10 @@
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build", "homepage": "https://astro.build",
"exports": { "exports": {
".": "./dist/index.js", ".": {
"astro": "./components/index.js",
"import": "./dist/index.js"
},
"./sharp": "./dist/loaders/sharp.js", "./sharp": "./dist/loaders/sharp.js",
"./endpoints/dev": "./dist/endpoints/dev.js", "./endpoints/dev": "./dist/endpoints/dev.js",
"./endpoints/prod": "./dist/endpoints/prod.js", "./endpoints/prod": "./dist/endpoints/prod.js",

View file

@ -1,4 +1,5 @@
export * from './index'; export * from './index';
export type { Image } from '../components/index';
export type InputFormat = export type InputFormat =
| 'heic' | 'heic'

View file

@ -1,6 +1,6 @@
--- ---
import socialJpg from '../assets/social.jpg'; import socialJpg from '../assets/social.jpg';
import { Image } from '@astrojs/image/components'; import { Image } from '@astrojs/image';
--- ---
<html> <html>

View file

@ -2,6 +2,7 @@ import { expect } from 'chai';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import path from 'path'; import path from 'path';
import sizeOf from 'image-size'; import sizeOf from 'image-size';
import { fileURLToPath } from 'url';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
let fixture; let fixture;
@ -12,7 +13,8 @@ describe('SSG images', function () {
}); });
function verifyImage(pathname, expected) { function verifyImage(pathname, expected) {
const dist = path.join('test/fixtures/basic-image/dist', pathname); const url = new URL('./fixtures/basic-image/dist/' + pathname, import.meta.url);
const dist = fileURLToPath(url);
const result = sizeOf(dist); const result = sizeOf(dist);
expect(result).to.deep.equal(expected); expect(result).to.deep.equal(expected);
} }