@inkandswitch/patchwork 0.3.0 → 0.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @inkandswitch/patchwork
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 5fbc712: Prebundle development import-map dependencies so dynamically loaded packages share module singletons and receive Vite's CommonJS interop.
8
+
9
+ ## 0.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 896fa22: Resolve built-in import-map packages through Vite during development so the site and dynamically loaded tools share module singletons.
14
+
3
15
  ## 0.3.0
4
16
 
5
17
  ### Minor Changes
@@ -37,11 +37,32 @@ function createImportMap(options) {
37
37
  Object.assign(importmap.imports, builtins);
38
38
  return { importmap, builtins };
39
39
  }
40
+ function devDependencyId(id) {
41
+ if (id === "@inkandswitch/patchwork")
42
+ return id;
43
+ if (id === "@inkandswitch/patchwork-bootloader") {
44
+ return `@inkandswitch/patchwork > ${id}`;
45
+ }
46
+ return `@inkandswitch/patchwork > @inkandswitch/patchwork-bootloader > ${id}`;
47
+ }
40
48
  export function importmap(options) {
41
49
  const { importmap, builtins } = createImportMap(options);
50
+ let serve = false;
42
51
  return {
43
52
  name: "@patchwork/vite",
53
+ config() {
54
+ return {
55
+ optimizeDeps: {
56
+ include: Object.keys(builtins).map(devDependencyId),
57
+ },
58
+ };
59
+ },
60
+ configResolved(config) {
61
+ serve = config.command === "serve";
62
+ },
44
63
  async buildStart() {
64
+ if (serve)
65
+ return;
45
66
  for (const [id, fileName] of Object.entries(builtins)) {
46
67
  this.emitFile({
47
68
  type: "chunk",
@@ -66,14 +87,20 @@ export function importmap(options) {
66
87
  },
67
88
  transformIndexHtml: {
68
89
  order: "pre",
69
- handler(html) {
90
+ handler(html, context) {
91
+ const activeImportmap = structuredClone(importmap);
92
+ if (context.server) {
93
+ for (const id of Object.keys(builtins)) {
94
+ activeImportmap.imports[id] = `/@id/${devDependencyId(id)}`;
95
+ }
96
+ }
70
97
  return {
71
98
  html,
72
99
  tags: [
73
100
  {
74
101
  tag: "script",
75
102
  attrs: { type: "importmap" },
76
- children: JSON.stringify(importmap, null, 2),
103
+ children: JSON.stringify(activeImportmap, null, 2),
77
104
  },
78
105
  ],
79
106
  };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/inkandswitch/patchwork-system.git",
6
6
  "directory": "core/patchwork"
7
7
  },
8
- "version": "0.3.0",
8
+ "version": "0.3.2",
9
9
  "author": "Ink & Switch",
10
10
  "type": "module",
11
11
  "license": "MIT",
@@ -43,10 +43,10 @@
43
43
  "sharp": "^0.35.3",
44
44
  "vite-plugin-wasm": "^3.6.0",
45
45
  "@inkandswitch/patchwork-bootloader": "^0.5.3",
46
- "@inkandswitch/patchwork-elements": "^5.0.0",
47
- "@inkandswitch/patchwork-plugins": "^1.1.0",
48
46
  "@inkandswitch/patchwork-filesystem": "^0.2.5",
49
- "@inkandswitch/patchwork-providers": "^0.4.2"
47
+ "@inkandswitch/patchwork-providers": "^0.4.2",
48
+ "@inkandswitch/patchwork-plugins": "^1.1.0",
49
+ "@inkandswitch/patchwork-elements": "^5.0.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "esbuild": "^0.23.1",
@@ -65,11 +65,31 @@ function createImportMap(options?: PatchworkVitePluginOptions) {
65
65
  return { importmap, builtins };
66
66
  }
67
67
 
68
+ function devDependencyId(id: string): string {
69
+ if (id === "@inkandswitch/patchwork") return id;
70
+ if (id === "@inkandswitch/patchwork-bootloader") {
71
+ return `@inkandswitch/patchwork > ${id}`;
72
+ }
73
+ return `@inkandswitch/patchwork > @inkandswitch/patchwork-bootloader > ${id}`;
74
+ }
75
+
68
76
  export function importmap(options?: PatchworkVitePluginOptions): Plugin {
69
77
  const { importmap, builtins } = createImportMap(options);
78
+ let serve = false;
70
79
  return {
71
80
  name: "@patchwork/vite",
81
+ config() {
82
+ return {
83
+ optimizeDeps: {
84
+ include: Object.keys(builtins).map(devDependencyId),
85
+ },
86
+ };
87
+ },
88
+ configResolved(config) {
89
+ serve = config.command === "serve";
90
+ },
72
91
  async buildStart() {
92
+ if (serve) return;
73
93
  for (const [id, fileName] of Object.entries(builtins)) {
74
94
  this.emitFile({
75
95
  type: "chunk",
@@ -95,14 +115,20 @@ export function importmap(options?: PatchworkVitePluginOptions): Plugin {
95
115
  },
96
116
  transformIndexHtml: {
97
117
  order: "pre",
98
- handler(html) {
118
+ handler(html, context) {
119
+ const activeImportmap = structuredClone(importmap);
120
+ if (context.server) {
121
+ for (const id of Object.keys(builtins)) {
122
+ activeImportmap.imports[id] = `/@id/${devDependencyId(id)}`;
123
+ }
124
+ }
99
125
  return {
100
126
  html,
101
127
  tags: [
102
128
  {
103
129
  tag: "script",
104
130
  attrs: { type: "importmap" },
105
- children: JSON.stringify(importmap, null, 2),
131
+ children: JSON.stringify(activeImportmap, null, 2),
106
132
  },
107
133
  ],
108
134
  };