@zappie/sdk 0.7.0 → 0.7.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.
- package/CHANGELOG.md +10 -0
- package/dist/debug.js +1 -1
- package/dist/index.js +1 -1
- package/dist/vite/index.d.ts +19 -1
- package/dist/vite/index.js +51 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @zappie/sdk
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f338b08: `@zappie/sdk/vite` adds `zappieHoistImports()`, a build plugin that makes each route's file import every chunk the route needs, so the browser requests them together on a client-side navigation. React Router loads a route by importing its file and nothing else. A chunk that the route reaches only through another chunk was requested only after that one downloaded, one round trip per level. Rollup lists these chunks in the route's own file, and Rolldown, which Vite 8 uses, does not yet. Add it after `reactRouter()`: `plugins: [reactRouter(), zappieHoistImports()]`. It runs only on the client build and keeps the order modules run in.
|
|
8
|
+
|
|
9
|
+
Since 0.6.0, a cart route that imports `@zappie/sdk/checkout` loaded three files one after another: the route, the checkout client and the request helpers it shares with the customer client. On a throttled phone connection the plugin takes that navigation from about 745 ms back to about 600 ms.
|
|
10
|
+
|
|
11
|
+
The starter's `vite.config.ts` adds the plugin.
|
|
12
|
+
|
|
3
13
|
## 0.7.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/debug.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ZappieError, isZappieError } from "./errors.js";
|
|
|
10
10
|
export * from "./models.js";
|
|
11
11
|
import { format, money } from "./money.js";
|
|
12
12
|
import { RestTransport } from "./transport/rest.js";
|
|
13
|
-
var VERSION = true ? "0.7.
|
|
13
|
+
var VERSION = true ? "0.7.1" : "0.0.0-development";
|
|
14
14
|
export {
|
|
15
15
|
API_VERSION,
|
|
16
16
|
RestTransport,
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -37,6 +37,24 @@ type MarkedSource = {
|
|
|
37
37
|
declare function zappieSource({ previewHost }: ZappieSourceOptions): Plugin;
|
|
38
38
|
/** Add source and component attributes to the intrinsic elements of one saved `.tsx` or `.jsx` file. */
|
|
39
39
|
declare function markSource(code: string, file: string): MarkedSource | null;
|
|
40
|
+
/**
|
|
41
|
+
* Make each page's code file name every chunk it needs, so the browser requests them together. React Router loads a
|
|
42
|
+
* route by importing its file and nothing else. A chunk that the route's chunk imports only through another chunk is
|
|
43
|
+
* found only after that one downloads, so each extra level costs a round trip on a client-side navigation. Rollup lists
|
|
44
|
+
* these chunks in the entry's own file (`hoistTransitiveImports`), and Rolldown, which Vite 8 uses, does not yet. The
|
|
45
|
+
* plugin adds them as plain imports after the file's own, so modules still run in the same order. It runs only on the
|
|
46
|
+
* client build.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { zappieHoistImports } from "@zappie/sdk/vite";
|
|
51
|
+
*
|
|
52
|
+
* export default defineConfig({
|
|
53
|
+
* plugins: [reactRouter(), zappieHoistImports()],
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function zappieHoistImports(): Plugin;
|
|
40
58
|
|
|
41
|
-
export { COMPONENT_ATTRIBUTE, SOURCE_ATTRIBUTE, markSource, zappieSource };
|
|
59
|
+
export { COMPONENT_ATTRIBUTE, SOURCE_ATTRIBUTE, markSource, zappieHoistImports, zappieSource };
|
|
42
60
|
export type { MarkedSource, ZappieSourceOptions };
|
package/dist/vite/index.js
CHANGED
|
@@ -146,9 +146,60 @@ function componentName(node) {
|
|
|
146
146
|
}
|
|
147
147
|
return void 0;
|
|
148
148
|
}
|
|
149
|
+
function zappieHoistImports() {
|
|
150
|
+
return {
|
|
151
|
+
name: "zappie-hoist-imports",
|
|
152
|
+
apply: "build",
|
|
153
|
+
applyToEnvironment: (environment) => environment.config.consumer === "client",
|
|
154
|
+
generateBundle(_options, bundle) {
|
|
155
|
+
const importsOf = (fileName) => {
|
|
156
|
+
const chunk = bundle[fileName];
|
|
157
|
+
return chunk?.type === "chunk" ? chunk.imports : [];
|
|
158
|
+
};
|
|
159
|
+
for (const chunk of Object.values(bundle)) {
|
|
160
|
+
if (chunk.type !== "chunk" || !chunk.isEntry) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const listed = /* @__PURE__ */ new Set([chunk.fileName, ...chunk.imports]);
|
|
164
|
+
const hoisted = [];
|
|
165
|
+
const pending = [...chunk.imports];
|
|
166
|
+
for (let index = 0; index < pending.length; index++) {
|
|
167
|
+
for (const next of importsOf(pending[index])) {
|
|
168
|
+
if (!listed.has(next)) {
|
|
169
|
+
listed.add(next);
|
|
170
|
+
hoisted.push(next);
|
|
171
|
+
pending.push(next);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (hoisted.length === 0) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const from = chunk.fileName.split("/").slice(0, -1);
|
|
179
|
+
chunk.code += `
|
|
180
|
+
${hoisted.map(
|
|
181
|
+
(file) => `import ${JSON.stringify(relativeImport(from, file))};`
|
|
182
|
+
).join("")}
|
|
183
|
+
`;
|
|
184
|
+
chunk.imports.push(...hoisted);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function relativeImport(from, file) {
|
|
190
|
+
const to = file.split("/");
|
|
191
|
+
let shared = 0;
|
|
192
|
+
while (shared < from.length && shared < to.length - 1 && from[shared] === to[shared]) {
|
|
193
|
+
shared++;
|
|
194
|
+
}
|
|
195
|
+
const up = from.length - shared;
|
|
196
|
+
const rest = to.slice(shared).join("/");
|
|
197
|
+
return up === 0 ? `./${rest}` : `${"../".repeat(up)}${rest}`;
|
|
198
|
+
}
|
|
149
199
|
export {
|
|
150
200
|
COMPONENT_ATTRIBUTE,
|
|
151
201
|
SOURCE_ATTRIBUTE,
|
|
152
202
|
markSource,
|
|
203
|
+
zappieHoistImports,
|
|
153
204
|
zappieSource
|
|
154
205
|
};
|