@inkandswitch/patchwork 0.0.1

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.
Files changed (70) hide show
  1. package/build-head.js +10 -0
  2. package/dist/client.d.ts +38 -0
  3. package/dist/global.css +1 -0
  4. package/dist/head.d.ts +1 -0
  5. package/dist/head.js +52 -0
  6. package/dist/index.d.ts +37 -0
  7. package/dist/index.js +294 -0
  8. package/dist/loading.d.ts +5 -0
  9. package/dist/loading.js +125 -0
  10. package/dist/repo.d.ts +25 -0
  11. package/dist/repo.js +108 -0
  12. package/dist/router.d.ts +18 -0
  13. package/dist/router.js +132 -0
  14. package/dist/site-kit/html.d.ts +4 -0
  15. package/dist/site-kit/html.js +70 -0
  16. package/dist/site-kit/icons.d.ts +9 -0
  17. package/dist/site-kit/icons.js +36 -0
  18. package/dist/site-kit/index.d.ts +15 -0
  19. package/dist/site-kit/index.js +5 -0
  20. package/dist/site-kit/manifest.d.ts +3 -0
  21. package/dist/site-kit/manifest.js +29 -0
  22. package/dist/site-kit/netlify.d.ts +5 -0
  23. package/dist/site-kit/netlify.js +27 -0
  24. package/dist/site-kit/options.d.ts +67 -0
  25. package/dist/site-kit/options.js +9 -0
  26. package/dist/site-kit/sync-servers.d.ts +11 -0
  27. package/dist/site-kit/sync-servers.js +36 -0
  28. package/dist/types.d.ts +104 -0
  29. package/dist/types.js +1 -0
  30. package/dist/vite/config-plugin.d.ts +12 -0
  31. package/dist/vite/config-plugin.js +70 -0
  32. package/dist/vite/html-plugin.d.ts +11 -0
  33. package/dist/vite/html-plugin.js +51 -0
  34. package/dist/vite/icons.d.ts +4 -0
  35. package/dist/vite/icons.js +42 -0
  36. package/dist/vite/importmap-plugin.d.ts +4 -0
  37. package/dist/vite/importmap-plugin.js +83 -0
  38. package/dist/vite/manifest-plugin.d.ts +4 -0
  39. package/dist/vite/manifest-plugin.js +34 -0
  40. package/dist/vite/netlify-plugin.d.ts +9 -0
  41. package/dist/vite/netlify-plugin.js +29 -0
  42. package/dist/vite/patchwork-plugin.d.ts +43 -0
  43. package/dist/vite/patchwork-plugin.js +40 -0
  44. package/dist/vite/service-worker-plugin.d.ts +2 -0
  45. package/dist/vite/service-worker-plugin.js +49 -0
  46. package/package.json +55 -0
  47. package/src/client.d.ts +38 -0
  48. package/src/global.css +1 -0
  49. package/src/head.ts +14 -0
  50. package/src/index.ts +469 -0
  51. package/src/loading.ts +137 -0
  52. package/src/repo.ts +146 -0
  53. package/src/router.ts +195 -0
  54. package/src/site-kit/html.ts +100 -0
  55. package/src/site-kit/icons.ts +49 -0
  56. package/src/site-kit/index.ts +22 -0
  57. package/src/site-kit/manifest.ts +39 -0
  58. package/src/site-kit/netlify.ts +35 -0
  59. package/src/site-kit/options.ts +73 -0
  60. package/src/site-kit/sync-servers.ts +39 -0
  61. package/src/types.ts +135 -0
  62. package/src/vite/config-plugin.ts +88 -0
  63. package/src/vite/html-plugin.ts +60 -0
  64. package/src/vite/icons.ts +47 -0
  65. package/src/vite/importmap-plugin.ts +112 -0
  66. package/src/vite/manifest-plugin.ts +39 -0
  67. package/src/vite/netlify-plugin.ts +34 -0
  68. package/src/vite/patchwork-plugin.ts +67 -0
  69. package/src/vite/service-worker-plugin.ts +54 -0
  70. package/tsconfig.json +14 -0
@@ -0,0 +1,67 @@
1
+ import type { Plugin, ServerOptions, PreviewOptions, BuildOptions } from "vite";
2
+
3
+ import { importmap } from "./importmap-plugin.js";
4
+ import { serviceworker } from "./service-worker-plugin.js";
5
+ import { configPlugin, wasm } from "./config-plugin.js";
6
+ import { iconsPlugin } from "./icons.js";
7
+ import { htmlPlugin } from "./html-plugin.js";
8
+ import { manifestPlugin } from "./manifest-plugin.js";
9
+ import { netlifyPlugin } from "./netlify-plugin.js";
10
+ import type { PatchworkSiteOptions } from "../site-kit/options.js";
11
+
12
+ /**
13
+ * The patchwork vite plugin. A site's vite.config.ts can shrink down to
14
+ * `plugins: [patchwork({...})]` plus a single source icon file — this plugin
15
+ * owns the wasm plugin, the importmap/service-worker emission, the generated
16
+ * index.html/manifest.webmanifest/Netlify _headers+_redirects, the site's
17
+ * icon set, and vite's server/preview/worker/build/define config.
18
+ *
19
+ * Each generated piece is switched off individually by passing `false` for
20
+ * its option (`html: false`, `manifest: false`, `netlify: false`,
21
+ * `icons: false`, `server: false`, `preview: false`, `worker: false`).
22
+ *
23
+ * `server`/`preview`/`worker`/`build`/`define` are owned by this plugin's
24
+ * `config()` hook and driven entirely by these options — don't also set them
25
+ * in the site's own `defineConfig({...})` alongside `patchwork()`, since
26
+ * Vite's plugin-config merge order doesn't guarantee which one wins.
27
+ *
28
+ * Most of what this plugin does — icon rendering, and building the
29
+ * index.html/manifest.webmanifest/Netlify _headers content — has no vite
30
+ * dependency at all; see `../site-kit/index.ts` for those pieces reused by
31
+ * a different bundler adapter.
32
+ */
33
+ export default function patchwork(options?: PatchworkVitePluginOptions) {
34
+ return [
35
+ wasm(),
36
+ configPlugin(options),
37
+ iconsPlugin(options),
38
+ htmlPlugin(options),
39
+ manifestPlugin(options),
40
+ netlifyPlugin(options),
41
+ importmap(options),
42
+ serviceworker(),
43
+ ].filter((plugin): plugin is Plugin => plugin != null);
44
+ }
45
+
46
+ type Imports = { [name: string]: string };
47
+ export type ImportMap = {
48
+ imports: Imports;
49
+ scopes?: { [scope: string]: Imports };
50
+ };
51
+
52
+ export type {
53
+ PatchworkSiteOptions,
54
+ PatchworkIconsOptions,
55
+ PatchworkHtmlOptions,
56
+ PatchworkNetlifyOptions,
57
+ PatchworkSyncServersOptions,
58
+ } from "../site-kit/options.js";
59
+
60
+ export interface PatchworkVitePluginOptions extends PatchworkSiteOptions {
61
+ importmap?: ImportMap;
62
+
63
+ server?: false | ServerOptions;
64
+ preview?: false | PreviewOptions;
65
+ worker?: false | { format?: "es" | "iife" };
66
+ build?: BuildOptions;
67
+ }
@@ -0,0 +1,54 @@
1
+ import type { Plugin } from "vite";
2
+ import { fileURLToPath } from "node:url";
3
+ import { builtins } from "./importmap-plugin.js";
4
+
5
+ // Anchor resolution at this file (inside @inkandswitch/patchwork's own
6
+ // installed directory) rather than the site root — these worker specifiers
7
+ // are @inkandswitch/patchwork-bootloader's own exports, a transitive
8
+ // dependency of the site under strict pnpm, not resolvable from the site's
9
+ // own node_modules by bare specifier.
10
+ const self = fileURLToPath(import.meta.url);
11
+
12
+ // The service worker and the automerge shared worker are emitted as their
13
+ // own chunks. Their heavy imports are marked external and resolved to
14
+ // /packages/... URLs (both workers are created with type:"module", so the
15
+ // browser fetches those as regular network requests).
16
+ const workers = [
17
+ {
18
+ specifier: "@inkandswitch/patchwork-bootloader/service-worker",
19
+ fileName: "service-worker.js",
20
+ },
21
+ {
22
+ specifier: "@inkandswitch/patchwork-bootloader/automerge-worker",
23
+ fileName: "automerge-worker.js",
24
+ },
25
+ {
26
+ specifier: "@inkandswitch/patchwork-bootloader/module-loader-worker",
27
+ fileName: "module-loader-worker.js",
28
+ },
29
+ ];
30
+
31
+ export function serviceworker(): Plugin {
32
+ const entryIds = new Set<string>();
33
+
34
+ return {
35
+ name: "@patchwork/service-worker",
36
+ enforce: "pre",
37
+ async buildStart() {
38
+ for (const { specifier, fileName } of workers) {
39
+ const resolved = await this.resolve(specifier, self);
40
+ entryIds.add(resolved!.id);
41
+ this.emitFile({
42
+ type: "chunk",
43
+ id: resolved!.id,
44
+ fileName,
45
+ });
46
+ }
47
+ },
48
+ resolveId(source, importer) {
49
+ if (importer && entryIds.has(importer) && source in builtins) {
50
+ return { id: builtins[source], external: true };
51
+ }
52
+ },
53
+ };
54
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "moduleResolution": "bundler",
6
+ "outDir": "dist",
7
+ "declaration": true,
8
+ "lib": ["esnext", "dom"],
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "isolatedModules": true
12
+ },
13
+ "include": ["src"]
14
+ }