sveltekit-temporal 0.4.0 → 0.6.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 +11 -18
- package/dist/addon.js +0 -5
- package/dist/index.js +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
# sveltekit-temporal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Temporal may soon be supported in big 3 browsers, but your users may not update for some time.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This one-shot CLI 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
|
-
## Using with the Svelte CLI
|
|
11
|
-
|
|
12
|
-
If you prefer the official Svelte CLI, this package also works as an `sv` add-on:
|
|
10
|
+
## Using with the Svelte CLI
|
|
13
11
|
|
|
14
12
|
```bash
|
|
15
|
-
#
|
|
16
|
-
npx sv create my-app
|
|
17
|
-
cd my-app
|
|
18
|
-
npx sv add sveltekit-temporal
|
|
13
|
+
# When creating a new project
|
|
14
|
+
npx sv create my-app --add sveltekit-temporal
|
|
19
15
|
|
|
20
16
|
# Into an existing project
|
|
21
17
|
npx sv add sveltekit-temporal
|
|
@@ -28,15 +24,13 @@ Run it inside a SvelteKit project. It will:
|
|
|
28
24
|
|
|
29
25
|
1. Verify you're in a SvelteKit project (checks `svelte` + `@sveltejs/kit` in `package.json`).
|
|
30
26
|
2. Detect TypeScript (presence of `tsconfig.json` or `src/app.d.ts`).
|
|
31
|
-
3.
|
|
32
|
-
4. Prompt you to choose a polyfill:
|
|
27
|
+
3. Prompt you to choose a polyfill:
|
|
33
28
|
- **`@js-temporal/polyfill`** — official, ~100 KB gzipped, spec-conservative.
|
|
34
29
|
- **`temporal-polyfill`** — smaller (~40 KB gzipped), same API.
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
4. Install the chosen package.
|
|
31
|
+
5. Create / update the following files:
|
|
37
32
|
- `src/lib/temporal.{ts,js}` — the conditional bootstrap module.
|
|
38
33
|
- `src/routes/+layout.{ts,js}` — prepends `import '$lib/temporal'` (preserves existing content).
|
|
39
|
-
- `src/hooks.server.{ts,js}` — same import for server-side.
|
|
40
34
|
- `src/app.d.ts` — adds global `Temporal` type and `Date.toTemporalInstant()` augmentation (TypeScript only).
|
|
41
35
|
|
|
42
36
|
## Idempotency
|
|
@@ -49,9 +43,9 @@ Re-running is safe. Files written by the script are tagged with a `// sveltekit-
|
|
|
49
43
|
|
|
50
44
|
## Usage in your app
|
|
51
45
|
|
|
52
|
-
After running, reference `Temporal` directly anywhere — no imports needed
|
|
46
|
+
After running, reference `Temporal` directly anywhere — no imports needed and guaranteed to work.
|
|
53
47
|
|
|
54
|
-
```
|
|
48
|
+
```js
|
|
55
49
|
<script lang="ts">
|
|
56
50
|
const today = Temporal.Now.plainDateISO();
|
|
57
51
|
const inAWeek = today.add({ days: 7 });
|
|
@@ -62,9 +56,8 @@ After running, reference `Temporal` directly anywhere — no imports needed:
|
|
|
62
56
|
|
|
63
57
|
## Server hooks (only if needed)
|
|
64
58
|
|
|
65
|
-
If you use Temporal inside `hooks.server.ts` or `+server.ts` endpoints that might run before any layout,
|
|
59
|
+
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
60
|
|
|
67
|
-
`src/hooks.server.ts`:
|
|
68
61
|
```ts
|
|
69
62
|
import '$lib/temporal';
|
|
70
63
|
|
package/dist/addon.js
CHANGED
|
@@ -111,11 +111,6 @@ var addon_default = defineAddon({
|
|
|
111
111
|
sv.file(
|
|
112
112
|
`${directory.kitRoutes}/+layout.${ext}`,
|
|
113
113
|
(content) => content.includes("import '$lib/temporal'") ? false : `import '$lib/temporal';
|
|
114
|
-
${content}`
|
|
115
|
-
);
|
|
116
|
-
sv.file(
|
|
117
|
-
`${directory.src}/hooks.server.${ext}`,
|
|
118
|
-
(content) => content.includes("import '$lib/temporal'") ? false : `import '$lib/temporal';
|
|
119
114
|
${content}`
|
|
120
115
|
);
|
|
121
116
|
if (isTs) {
|
package/dist/index.js
CHANGED
|
@@ -805,8 +805,6 @@ async function run() {
|
|
|
805
805
|
writeManaged(bootstrapPath, bootstrapContents, { created, updated, skipped });
|
|
806
806
|
const layoutPath = join(cwd, "src", "routes", `+layout.${ext}`);
|
|
807
807
|
ensureImportInFile(layoutPath, "import '$lib/temporal';", { created, updated, skipped });
|
|
808
|
-
const hooksPath = join(cwd, "src", `hooks.server.${ext}`);
|
|
809
|
-
ensureImportInFile(hooksPath, "import '$lib/temporal';", { created, updated, skipped });
|
|
810
808
|
if (isTypeScript) {
|
|
811
809
|
const dtsPath = join(cwd, "src", "app.d.ts");
|
|
812
810
|
updateAppDts(dtsPath, polyfill.pkg, { created, updated, skipped });
|
package/package.json
CHANGED