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

config: remove ~/assets alias #8113

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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': patch
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved
---

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.

Loading