Skip to content

Commit

Permalink
feat!: minimize package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jan 7, 2024
1 parent db77a3b commit 5b0486b
Show file tree
Hide file tree
Showing 8 changed files with 841 additions and 675 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ jobs:

# Currently, only npm supports publishing packages with provenance
# https://docs.npmjs.com/generating-provenance-statements
run: npm publish --provenance --access public
run: |
npm install --force
npm run package
npm publish --provenance --access public
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
package
dist
build
node_modules
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ Load a custom locale and set it as the default locale using the [dayjs.locale AP
import { dayjs } from "svelte-time";
</script>
<button on:click={() => (document.title = dayjs().format("MMM DD, YYYY"))}> Set title </button>
<button on:click={() => (document.title = dayjs().format("MMM DD, YYYY"))}>
Set title
</button>
```

## API
Expand Down
51 changes: 18 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,29 @@
"license": "MIT",
"description": "Svelte component and action to format a timestamp using day.js",
"author": "Eric Liu (https://github.com/metonym)",
"type": "module",
"svelte": "./src/index.js",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"exports": {
".": {
"types": "./src/index.d.ts",
"svelte": "./src/index.js",
"default": "./src/index.js"
},
"./src/*.svelte": {
"types": "./src/*.svelte.d.ts",
"import": "./src/*.svelte"
},
"./src/*": {
"types": "./src/*.d.ts",
"import": "./src/*.js"
}
},
"scripts": {
"dev": "rollup -cw",
"format": "prettier --ignore-path .gitignore --write .",
"test": "vitest"
"format": "prettier --write .",
"test": "vitest",
"package": "dlz"
},
"dependencies": {
"dayjs": "^1.11.10"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.1.0",
"@sveltejs/vite-plugin-svelte": "^2.4.6",
"@testing-library/svelte": "^4.0.3",
"jsdom": "^22.1.0",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"svelte": "^4.2.0",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@testing-library/svelte": "^4.0.5",
"dlz": "^0.1.2",
"jsdom": "^23.1.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.8",
"svelte-readme": "^3.6.3",
"typescript": "^5.2.2",
"vitest": "^0.34.4"
"typescript": "^5.3.3",
"vitest": "^1.1.3"
},
"repository": {
"type": "git",
Expand All @@ -50,16 +36,15 @@
"bugs": "https://github.com/metonym/svelte-time/issues",
"keywords": [
"svelte",
"svelte component",
"svelte action",
"dayjs",
"time formatter",
"timestamp",
"relative",
"ago"
],
"files": [
"src"
],
"type": "module"
"prettier": {
"plugins": [
"prettier-plugin-svelte"
]
}
}
13 changes: 9 additions & 4 deletions src/Time.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@
});
$: if (relative && live !== false) {
interval = setInterval(() => {
formatted = dayjs(timestamp).from();
}, Math.abs(typeof live === "number" ? live : DEFAULT_INTERVAL));
interval = setInterval(
() => {
formatted = dayjs(timestamp).from();
},
Math.abs(typeof live === "number" ? live : DEFAULT_INTERVAL),
);
}
$: formatted = relative ? dayjs(timestamp).from() : dayjs(timestamp).format(format);
$: formatted = relative
? dayjs(timestamp).from()
: dayjs(timestamp).format(format);
$: title = relative ? dayjs(timestamp).format(format) : undefined;
</script>

Expand Down
12 changes: 10 additions & 2 deletions tests/SvelteTime.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
<!-- Basic -->
<Time data-test="default" />
<Time data-test="timestamp-string" timestamp="2020-02-01" />
<Time data-test="timestamp-date" timestamp={new Date()} format="dddd @ h:mm a" />
<Time data-test="timestamp-number" timestamp={1e10} format="dddd @ h:mm A · MMMM D, YYYY" />
<Time
data-test="timestamp-date"
timestamp={new Date()}
format="dddd @ h:mm a"
/>
<Time
data-test="timestamp-number"
timestamp={1e10}
format="dddd @ h:mm A · MMMM D, YYYY"
/>

<!-- Relative time -->
<Time data-test="relative" relative />
Expand Down
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { svelte, vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import path from "path";
import { defineConfig } from "vite";
import pkg from "./package.json";

export default defineConfig({
plugins: [svelte({ hot: false, preprocess: [vitePreprocess()] })],
resolve: {
alias: {
[pkg.name]: pkg.main,
[pkg.name]: path.resolve("./src"),
},
},
test: {
Expand Down
Loading

0 comments on commit 5b0486b

Please sign in to comment.