From 6f2ac8bf3d21a22bacd49a0afdf5d11c53511ecc Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Wed, 19 Apr 2023 07:08:02 +0200 Subject: [PATCH] chore: publish @unlazy/core as well --- .github/workflows/release.yml | 4 +- package.json | 2 +- packages/core/build.config.ts | 9 +++++ packages/core/package.json | 39 ++++++++++++++----- .../src/{blurhash/index.ts => blurhash.ts} | 8 ++-- packages/core/src/index.ts | 4 +- packages/core/src/lazyLoad.ts | 12 ++++-- packages/core/src/{blurhash => png}/crc.ts | 0 .../src/{blurhash/png.ts => png/index.ts} | 0 packages/unlazy/build.config.ts | 4 -- packages/unlazy/package.json | 17 +++----- packages/unlazy/src/blurhash.ts | 1 - packages/unlazy/src/index.ts | 2 +- packages/unlazy/vite.config.ts | 2 +- playground/app.vue | 2 +- playground/components/BlurHash/SsrDecode.vue | 3 +- pnpm-lock.yaml | 6 +-- 17 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 packages/core/build.config.ts rename packages/core/src/{blurhash/index.ts => blurhash.ts} (85%) rename packages/core/src/{blurhash => png}/crc.ts (100%) rename packages/core/src/{blurhash/png.ts => png/index.ts} (100%) delete mode 100644 packages/unlazy/src/blurhash.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a9dedd..98cdc19 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,9 +30,7 @@ jobs: run: pnpm run build - name: Publish to npm - run: | - cd packages/unlazy - npm publish --access public + run: pnpm -r publish --access public --no-git-checks env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index d045631..c39584c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lint:fix": "eslint . --fix", "test": "pnpm -r test:run", "test:types": "tsc --noEmit", - "release": "bumpp package.json packages/*/package.json --all" + "release": "bumpp -r" }, "devDependencies": { "@antfu/eslint-config": "^0.38.5", diff --git a/packages/core/build.config.ts b/packages/core/build.config.ts new file mode 100644 index 0000000..583a827 --- /dev/null +++ b/packages/core/build.config.ts @@ -0,0 +1,9 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + entries: [ + './src/index', + ], + declaration: true, + clean: true, +}) diff --git a/packages/core/package.json b/packages/core/package.json index ed355da..98e199a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -2,24 +2,45 @@ "name": "@unlazy/core", "type": "module", "version": "0.1.0", - "private": true, "packageManager": "pnpm@8.3.0", + "description": "Universal lazy loading library for placeholder images leveraging native browser APIs", + "author": "Johann Schopplich ", + "license": "MIT", + "homepage": "https://github.com/johannschopplich/unlazy#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/johannschopplich/unlazy.git" + }, + "bugs": { + "url": "https://github.com/johannschopplich/unlazy/issues" + }, + "keywords": [ + "async", + "image", + "intersection", + "lazy", + "loading", + "lozad", + "native", + "observer", + "responsive" + ], + "sideEffects": false, "exports": { ".": { - "types": "./src/index.ts", - "import": "./src/index.ts" - }, - "./blurhash": { - "types": "./src/blurhash/index.ts", - "import": "./src/blurhash/index.ts" + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs" }, - "./*": "./src/*" + "./*": "./*" }, + "types": "./dist/index.d.ts", "scripts": { + "dev": "unbuild --stub", + "build": "unbuild", "test": "vitest", "test:run": "vitest run" }, - "devDependencies": { + "dependencies": { "fast-blurhash": "^1.1.2" } } diff --git a/packages/core/src/blurhash/index.ts b/packages/core/src/blurhash.ts similarity index 85% rename from packages/core/src/blurhash/index.ts rename to packages/core/src/blurhash.ts index e335d69..3be6b59 100644 --- a/packages/core/src/blurhash/index.ts +++ b/packages/core/src/blurhash.ts @@ -1,8 +1,8 @@ import { decodeBlurHash } from 'fast-blurhash' -import { DEFAULT_BLURHASH_SIZE } from '../constants' -import { getBlurhashDimensions, isSSR } from '../utils' -import { encodeSvgAsDataUri, generateBlurredImageSvg } from '../svg' -import type { UnLazyLoadOptions } from '../types' +import { DEFAULT_BLURHASH_SIZE } from './constants' +import { getBlurhashDimensions, isSSR } from './utils' +import { encodeSvgAsDataUri, generateBlurredImageSvg } from './svg' +import type { UnLazyLoadOptions } from './types' import { getPngFromRgbaArr } from './png' export type BlurhashOptions = { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2a6d2b9..adf88e0 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1 +1,3 @@ -export { lazyLoad, autoSizes, loadImage } from './lazyLoad' +export * from './lazyLoad' +export * from './blurhash' +export * from './types' diff --git a/packages/core/src/lazyLoad.ts b/packages/core/src/lazyLoad.ts index cca93b7..c025fbe 100644 --- a/packages/core/src/lazyLoad.ts +++ b/packages/core/src/lazyLoad.ts @@ -103,13 +103,17 @@ function updateSizesAttribute(element: HTMLImageElement | HTMLSourceElement) { } function updateImageSrc(image: HTMLImageElement | HTMLSourceElement) { - image.src = image.dataset.src! - image.removeAttribute('data-src') + if (image.dataset.src) { + image.src = image.dataset.src! + image.removeAttribute('data-src') + } } function updateImageSrcset(image: HTMLImageElement | HTMLSourceElement) { - image.srcset = image.dataset.srcset! - image.removeAttribute('data-srcset') + if (image.dataset.srcset) { + image.srcset = image.dataset.srcset! + image.removeAttribute('data-srcset') + } } function updatePictureSources(image: HTMLImageElement) { diff --git a/packages/core/src/blurhash/crc.ts b/packages/core/src/png/crc.ts similarity index 100% rename from packages/core/src/blurhash/crc.ts rename to packages/core/src/png/crc.ts diff --git a/packages/core/src/blurhash/png.ts b/packages/core/src/png/index.ts similarity index 100% rename from packages/core/src/blurhash/png.ts rename to packages/core/src/png/index.ts diff --git a/packages/unlazy/build.config.ts b/packages/unlazy/build.config.ts index f91b14f..b0117af 100644 --- a/packages/unlazy/build.config.ts +++ b/packages/unlazy/build.config.ts @@ -3,12 +3,8 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ entries: [ './src/index', - './src/blurhash', ], declaration: true, clean: true, - rollup: { - emitCJS: true, - }, failOnWarn: false, }) diff --git a/packages/unlazy/package.json b/packages/unlazy/package.json index dbd83e8..b5b89f5 100644 --- a/packages/unlazy/package.json +++ b/packages/unlazy/package.json @@ -1,5 +1,6 @@ { "name": "unlazy", + "type": "module", "version": "0.1.0", "packageManager": "pnpm@8.3.0", "description": "Universal lazy loading library for placeholder images leveraging native browser APIs", @@ -28,19 +29,11 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "require": "./dist/index.cjs", "import": "./dist/index.mjs" - }, - "./blurhash": { - "types": "./dist/blurhash.d.ts", - "require": "./dist/blurhash.cjs", - "import": "./dist/blurhash.mjs" } }, - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "unpkg": "./dist/browser/unlazy.iife.js", - "jsdelivr": "./dist/browser/unlazy.iife.js", + "unpkg": "./dist/unlazy.iife.js", + "jsdelivr": "./dist/unlazy.iife.js", "types": "./dist/index.d.ts", "files": [ "dist" @@ -52,8 +45,10 @@ "peerDependencies": { "fast-blurhash": "^1.1.2" }, + "dependencies": { + "@unlazy/core": "workspace:*" + }, "devDependencies": { - "@unlazy/core": "workspace:*", "fast-blurhash": "^1.1.2" } } diff --git a/packages/unlazy/src/blurhash.ts b/packages/unlazy/src/blurhash.ts deleted file mode 100644 index 5ad08bf..0000000 --- a/packages/unlazy/src/blurhash.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@unlazy/core/blurhash' diff --git a/packages/unlazy/src/index.ts b/packages/unlazy/src/index.ts index f8beb79..c277dab 100644 --- a/packages/unlazy/src/index.ts +++ b/packages/unlazy/src/index.ts @@ -1 +1 @@ -export { autoSizes, lazyLoad, loadImage } from '@unlazy/core' +export * from '@unlazy/core' diff --git a/packages/unlazy/vite.config.ts b/packages/unlazy/vite.config.ts index 4dc7f93..9c24fca 100644 --- a/packages/unlazy/vite.config.ts +++ b/packages/unlazy/vite.config.ts @@ -6,7 +6,7 @@ const currentDir = new URL('.', import.meta.url).pathname // Only build the IIFE format for the browser export default defineConfig({ build: { - outDir: resolve(currentDir, 'dist/browser'), + emptyOutDir: false, lib: { entry: resolve(currentDir, 'src/index.iife.ts'), name: 'UnLazy', diff --git a/playground/app.vue b/playground/app.vue index 91136c0..5df8ae6 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -1,5 +1,5 @@