sveltekit-temporal 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -16
- package/dist/addon.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
# sveltekit-temporal
|
|
2
2
|
|
|
3
|
-
Think about it, temporal may be supported in big 3
|
|
3
|
+
Think about it, temporal may be supported in big 3 browsers soon, but your users may not update for some time.
|
|
4
4
|
|
|
5
|
-
One-shot CLI that wires the Temporal API polyfill into a SvelteKit project, with conditional loading so browsers that ship Temporal natively (Chrome 144+, Firefox 139+) and server runtimes that do too (Node.js 26+) pay zero bytes.
|
|
5
|
+
This One-shot CLI that wires the Temporal API polyfill into a SvelteKit project, with conditional loading so browsers that ship Temporal natively (Chrome 144+, Firefox 139+) and server runtimes that do too (Node.js 26+) pay zero bytes.
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
10
10
|
## Using with the Svelte CLI (`sv add`)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
This package also works as an `sv` add-on:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
#
|
|
16
|
-
npx sv create my-app
|
|
17
|
-
cd my-app
|
|
18
|
-
npx sv add sveltekit-temporal
|
|
15
|
+
# When creating a new project
|
|
16
|
+
npx sv create my-app --add sveltekit-temporal
|
|
19
17
|
|
|
20
18
|
# Into an existing project
|
|
21
19
|
npx sv add sveltekit-temporal
|
|
@@ -28,15 +26,14 @@ Run it inside a SvelteKit project. It will:
|
|
|
28
26
|
|
|
29
27
|
1. Verify you're in a SvelteKit project (checks `svelte` + `@sveltejs/kit` in `package.json`).
|
|
30
28
|
2. Detect TypeScript (presence of `tsconfig.json` or `src/app.d.ts`).
|
|
31
|
-
3.
|
|
32
|
-
4. Prompt you to choose a polyfill:
|
|
29
|
+
3. Prompt you to choose a polyfill:
|
|
33
30
|
- **`@js-temporal/polyfill`** — official, ~100 KB gzipped, spec-conservative.
|
|
34
31
|
- **`temporal-polyfill`** — smaller (~40 KB gzipped), same API.
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
4. Install the chosen package.
|
|
33
|
+
5. Create / update the following files:
|
|
37
34
|
- `src/lib/temporal.{ts,js}` — the conditional bootstrap module.
|
|
38
35
|
- `src/routes/+layout.{ts,js}` — prepends `import '$lib/temporal'` (preserves existing content).
|
|
39
|
-
- `src/hooks.server.{ts,js}` —
|
|
36
|
+
- `src/hooks.server.{ts,js}` — add commented out example import for server-side.
|
|
40
37
|
- `src/app.d.ts` — adds global `Temporal` type and `Date.toTemporalInstant()` augmentation (TypeScript only).
|
|
41
38
|
|
|
42
39
|
## Idempotency
|
|
@@ -49,9 +46,9 @@ Re-running is safe. Files written by the script are tagged with a `// sveltekit-
|
|
|
49
46
|
|
|
50
47
|
## Usage in your app
|
|
51
48
|
|
|
52
|
-
After running, reference `Temporal` directly anywhere — no imports needed
|
|
49
|
+
After running, reference `Temporal` directly anywhere — no imports needed and guaranteed to work.
|
|
53
50
|
|
|
54
|
-
```
|
|
51
|
+
```js
|
|
55
52
|
<script lang="ts">
|
|
56
53
|
const today = Temporal.Now.plainDateISO();
|
|
57
54
|
const inAWeek = today.add({ days: 7 });
|
|
@@ -62,11 +59,11 @@ After running, reference `Temporal` directly anywhere — no imports needed:
|
|
|
62
59
|
|
|
63
60
|
## Server hooks (only if needed)
|
|
64
61
|
|
|
65
|
-
If you use Temporal inside `hooks.server.ts` or `+server.ts` endpoints that might run before any layout,
|
|
62
|
+
If you use Temporal inside `hooks.server.ts` or `+server.ts` endpoints that might run before any layout, uncomment the import there as well:
|
|
66
63
|
|
|
67
64
|
`src/hooks.server.ts`:
|
|
68
65
|
```ts
|
|
69
|
-
import '$lib/temporal';
|
|
66
|
+
// import '$lib/temporal';
|
|
70
67
|
|
|
71
68
|
export async function handle({ event, resolve }) {
|
|
72
69
|
return resolve(event);
|
package/dist/addon.js
CHANGED
|
@@ -115,7 +115,7 @@ ${content}`
|
|
|
115
115
|
);
|
|
116
116
|
sv.file(
|
|
117
117
|
`${directory.src}/hooks.server.${ext}`,
|
|
118
|
-
(content) => content.includes("import '$lib/temporal'") ? false :
|
|
118
|
+
(content) => content.includes("import '$lib/temporal'") ? false : `// import '$lib/temporal';
|
|
119
119
|
${content}`
|
|
120
120
|
);
|
|
121
121
|
if (isTs) {
|
package/dist/index.js
CHANGED
|
@@ -806,7 +806,7 @@ async function run() {
|
|
|
806
806
|
const layoutPath = join(cwd, "src", "routes", `+layout.${ext}`);
|
|
807
807
|
ensureImportInFile(layoutPath, "import '$lib/temporal';", { created, updated, skipped });
|
|
808
808
|
const hooksPath = join(cwd, "src", `hooks.server.${ext}`);
|
|
809
|
-
ensureImportInFile(hooksPath, "import '$lib/temporal';", { created, updated, skipped });
|
|
809
|
+
ensureImportInFile(hooksPath, "// import '$lib/temporal';", { created, updated, skipped });
|
|
810
810
|
if (isTypeScript) {
|
|
811
811
|
const dtsPath = join(cwd, "src", "app.d.ts");
|
|
812
812
|
updateAppDts(dtsPath, polyfill.pkg, { created, updated, skipped });
|
package/package.json
CHANGED