Skip to content

Commit

Permalink
config: remove ~/assets alias (#8113)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Mia Kanashi <[email protected]>
  • Loading branch information
3 people committed Aug 17, 2023
1 parent 4967c69 commit 2484dc4
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 24 deletions.
13 changes: 13 additions & 0 deletions .changeset/clever-bats-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'astro': major
---

This import alias is no longer included by default with astro:assets. If you were using this alias with experimental assets, you must convert them to relative file paths, or create your own [import aliases](https://docs.astro.build/en/guides/aliases/).

```diff
---
// src/pages/posts/post-1.astro
- import rocket from '~/assets/rocket.png'
+ import rocket from '../../assets/rocket.png';
---
```
2 changes: 1 addition & 1 deletion packages/astro/src/assets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type LocalImageProps<T> = ImageSharedProps<T> & {
*
* **Example**:
* ```js
* import myImage from "~/assets/my_image.png";
* import myImage from "../assets/my_image.png";
* ```
* And then refer to the image, like so:
* ```astro
Expand Down
13 changes: 0 additions & 13 deletions packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MagicString from 'magic-string';
import { fileURLToPath } from 'node:url';
import type * as vite from 'vite';
import { normalizePath } from 'vite';
import type { AstroPluginOptions, ImageTransform } from '../@types/astro';
Expand Down Expand Up @@ -31,18 +30,6 @@ export default function assets({
// Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
{
name: 'astro:assets',
config() {
return {
resolve: {
alias: [
{
find: /^~\/assets\/(.+)$/,
replacement: fileURLToPath(new URL('./assets/$1', settings.config.srcDir)),
},
],
},
};
},
async resolveId(id) {
if (id === VIRTUAL_SERVICE_ID) {
return await this.resolve(settings.config.image.service.entrypoint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"alt": "Futuristic landscape with chrome buildings and blue skies",
"src": "~/assets/the-future.jpg"
"src": "../../assets/the-future.jpg"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: One
image: ~/assets/penguin2.jpg
image: ../../assets/penguin2.jpg
cover:
image: ../../assets/penguin1.jpg
---
Expand Down
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/core-image-base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
}
}
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/core-image-ssg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: One
image: ~/assets/penguin2.jpg
image: ../../assets/penguin2.jpg
cover:
image: ../../assets/penguin1.jpg
arrayOfImages:
- ~/assets/penguin2.jpg
- ~/assets/penguin1.jpg
- ../../assets/penguin2.jpg
- ../../assets/penguin1.jpg
refinedImage: ../../assets/penguin1.jpg
---

Expand Down
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/core-image/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
}
}
5 changes: 0 additions & 5 deletions packages/astro/tsconfigs/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
"esModuleInterop": true,
// Skip typechecking libraries and .d.ts files
"skipLibCheck": true,
// Add alias for assets folder for easy reference to assets
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
// Allow JavaScript files to be imported
"allowJs": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/assets/*": ["src/assets/*"]
},
}
}
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2484dc4

Please sign in to comment.