Skip to content

Commit

Permalink
Merge branch 'main' into moorejs/effort
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Mar 27, 2024
2 parents d57c5d7 + 5b75d3f commit 21bf449
Show file tree
Hide file tree
Showing 30 changed files with 1,095 additions and 782 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-books-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-imagetools': patch
---

fix: use URI-decoded pathname when emitting file
5 changes: 5 additions & 0 deletions .changeset/loud-comics-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-imagetools': minor
---

feat: add "inline" directive
5 changes: 5 additions & 0 deletions .changeset/quiet-bulldogs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-imagetools": minor
---

feat: support Vite's `server.origin` option
6 changes: 6 additions & 0 deletions .changeset/tidy-rings-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'imagetools-core': major
'vite-imagetools': major
---

breaking: require Node 18 or newer to align with Vite and Vitest
8 changes: 4 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
with:
lfs: true

- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
- uses: actions/setup-node@v4
with:
cache: 'pnpm'
Expand All @@ -20,17 +20,17 @@ jobs:
run: pnpm run build

- name: Generate coverage report
run: pnpm run coverage --no-threads
run: pnpm run coverage

- name: Upload imagetools-core Report
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: imagetools-core
files: 'packages/core/coverage/coverage-final.json'

- name: Upload vite-imagetools Report
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: vite-imagetools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
lfs: true

- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
- uses: actions/setup-node@v4
with:
cache: 'pnpm'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
with:
lfs: true

- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
- uses: actions/setup-node@v4
with:
cache: 'pnpm'
Expand All @@ -26,9 +26,9 @@ jobs:
run: pnpm run build

- name: Run unit tests
run: pnpm run test --no-threads
run: pnpm run test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: image-diffs
Expand All @@ -46,7 +46,7 @@ jobs:
fetch-depth: 0
lfs: true

- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -58,15 +58,15 @@ jobs:
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
with:
run_install: true

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
with:
lfs: true

- uses: pnpm/action-setup@v2.4.0
- uses: pnpm/action-setup@v3.0.0
- uses: actions/setup-node@v4
with:
cache: 'pnpm'
Expand All @@ -24,9 +24,9 @@ jobs:
run: pnpm run build

- name: Run unit tests
run: pnpm run test --no-threads
run: pnpm run test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: image-diffs
Expand Down
21 changes: 19 additions & 2 deletions docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- [Source](#source)
- [Srcset](#srcset)
- [URL](#url)
- [Inline](#inline)

### Output Directives

Expand Down Expand Up @@ -486,7 +487,7 @@ html += `<img src={picture.img.src} /></picture>`

### Source

**Keyword**: `url`<br> • **Type**: _boolean_<br>
**Keyword**: `source`<br> • **Type**: _boolean_<br>

Returns information about the image necessary to render a `source` tag as a JavaScript object. This only takes the image width into consideration.

Expand All @@ -506,7 +507,7 @@ const html = `<picture>

### Srcset

**Keyword**: `url`<br>**Type**: _boolean_<br>
**Keyword**: `srcset`<br>**Type**: _boolean_<br>

Returns a srcset string of the generated images to be used in a `<picture>` tag. This only takes the image width into consideration.

Expand Down Expand Up @@ -536,3 +537,19 @@ Returns a URL to the generated image. This is the default when your directives p
```js
import Image from 'example.jpg?w=500' // the type of Image is a string and it's a URL to the transformed image
```

---

### Inline

**Keyword**: `inline`<br>**Type**: _boolean_<br>

Return base64 encoded inline image instead of URL to the generated image. This can be combined with some output directives like `srcset` or `picture`.

**Example**:

```js
import inlineImage from 'example.jpg?format=webp&inline';
```

The returned `inlineImage` will start with `data:image/webp;base64,...`
2 changes: 1 addition & 1 deletion examples/vite-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"devDependencies": {
"vite": "^4.4.7",
"vite": "^5.2.6",
"vite-imagetools": "workspace:*"
}
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@rollup/plugin-typescript": "^11.1.2",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@rollup/plugin-typescript": "^11.1.5",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.45.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
"prettier": "^3.0.3",
"rollup": "^4.0.0",
"rollup": "^4.13.0",
"tslib": "^2.6.1",
"typedoc": "^0.25.0",
"typedoc-plugin-markdown": "^3.15.4",
Expand All @@ -32,7 +32,7 @@
"@commitlint/config-conventional"
]
},
"packageManager": "pnpm@8.10.0",
"packageManager": "pnpm@8.15.5",
"engines": {
"pnpm": "^8.0.0"
},
Expand Down
36 changes: 36 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Change Log

## 6.0.4

### Patch Changes

- 0eca643: chore: bump sharp to 0.33.1

## 6.0.3

### Patch Changes

- 5d7a77d: chore: update sharp to 0.33

## 6.0.2

### Patch Changes

- e0ba6c0: fix: corrected imports to compile with `"moduleResolution": "nodenext"`

## 6.0.1

### Patch Changes

- fcd7389: chore: upgrade sharp

## 6.0.0

### Major Changes

- c54ad96: breaking: remove utils

## 5.1.1

### Patch Changes

- 7bd11b7: fix: address issues when preventing upscale

## 5.1.0

### Minor Changes
Expand Down
15 changes: 7 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagetools-core",
"version": "5.1.0",
"version": "6.0.4",
"type": "module",
"types": "dist/index.d.ts",
"exports": {
Expand All @@ -26,7 +26,7 @@
],
"sideEffects": false,
"engines": {
"node": ">=12.0.0"
"node": ">=18.0.0"
},
"scripts": {
"dev": "rollup -cw",
Expand All @@ -35,18 +35,17 @@
"coverage": "vitest run --coverage"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.2",
"@rollup/plugin-typescript": "^11.1.5",
"@types/jest-image-snapshot": "^6.1.0",
"@types/sharp": "^0.32.0",
"@vitest/coverage-v8": "^0.34.0",
"@vitest/coverage-v8": "^1.4.0",
"jest-file-snapshot": "^0.5.0",
"jest-image-snapshot": "^6.2.0",
"rollup": "^4.0.0",
"rollup": "^4.13.0",
"tslib": "^2.6.1",
"typescript": "^5.1.6",
"vitest": "^0.34.0"
"vitest": "^1.4.0"
},
"dependencies": {
"sharp": "^0.32.4"
"sharp": "^0.33.1"
}
}
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export * from './transforms/tint.js'
export * from './types.js'
export * from './builtins.js'
export * from './output-formats.js'
export * from './util.js'
export { parseURL, extractEntries } from './lib/parse-url.js'
export { resolveConfigs } from './lib/resolve-configs.js'
export { generateTransforms } from './lib/generate-transforms.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Sharp } from 'sharp'
import { ImageMetadata } from '../types'
import { ImageMetadata } from '../types.js'

export const METADATA = Symbol('image metadata')

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions packages/core/src/transforms/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export const format: TransformFactory<FormatOptions> = (config) => {
image[METADATA].format = format

return image.toFormat(format, {
compression: format == 'heif' ? 'av1' : undefined,
effort: getEffort(config, image),
quality: getQuality(config, image),
lossless: getLossless(config, image) as boolean,
progressive: getProgressive(config, image) as boolean
progressive: getProgressive(config, image) as boolean,
quality: getQuality(config, image)
})
}
}
2 changes: 1 addition & 1 deletion packages/core/src/transforms/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const resize: TransformFactory<ResizeOptions> = (config, context) => {
finalWidth = originalWidth
finalAspect = originalAspect

if (context.manualSearchParams.has('width') || context.manualSearchParams.has('height')) {
if (context.manualSearchParams.has('w') || context.manualSearchParams.has('h')) {
context.logger.info(
'allowUpscale not enabled. Image width, height and aspect ratio reverted to original values'
)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Metadata, Sharp } from 'sharp'
import { kernelValues } from './transforms/kernel'
import { positionValues } from './transforms/position'
import { kernelValues } from './transforms/kernel.js'
import { positionValues } from './transforms/position.js'

export interface ProcessedImageMetadata extends ImageMetadata {
src: string
Expand Down
18 changes: 0 additions & 18 deletions packages/core/src/util.ts

This file was deleted.

Loading

0 comments on commit 21bf449

Please sign in to comment.