@batijs/cli 0.0.213 → 0.0.215

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.
@@ -18,7 +18,7 @@ nodeApp.use(
18
18
  }),
19
19
  );
20
20
 
21
- nodeApp.mount("/", app.fetch);
21
+ nodeApp.route("/", app);
22
22
 
23
23
  const port = envs.PORT ? parseInt(envs.PORT, 10) : 3000;
24
24
 
@@ -1,3 +1,4 @@
1
+ /*# BATI include-if-imported #*/
1
2
  /// <reference lib="webworker" />
2
3
  import { renderPage } from "vike/server";
3
4
 
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <h1>Star Wars Movies</h1>
3
3
  <ol>
4
- <li v-for="item in movies" :key="item.id">
4
+ <li v-for="item in movies.data" :key="item.id">
5
5
  <a :href="'/star-wars/' + item.id">{{ item.title }}</a> ({{ item.release_date }})
6
6
  </li>
7
7
  </ol>
@@ -11,7 +11,7 @@ export const data = async () => {
11
11
  // We remove data we don't need because the data is passed to the client; we should
12
12
  // minimize what is sent over the network.
13
13
  const movies = minimize(moviesData);
14
- return movies;
14
+ return { data: movies };
15
15
  };
16
16
 
17
17
  function minimize(movies: MovieDetails[]): Movie[] {
@@ -2,6 +2,6 @@ import type { PageContext } from "vike/types";
2
2
  import type { Data } from "./+data.js";
3
3
 
4
4
  export function title(pageContext: PageContext<Data>) {
5
- const movies = pageContext.data;
5
+ const movies = pageContext.data.data;
6
6
  return `${movies.length} Star Wars Movies`;
7
7
  }
@@ -1,3 +1,5 @@
1
1
  import type { Movie } from "../types.js";
2
2
  export type Data = Awaited<ReturnType<typeof data>>;
3
- export declare const data: () => Promise<Movie[]>;
3
+ export declare const data: () => Promise<{
4
+ data: Movie[];
5
+ }>;
package/dist/index.js CHANGED
@@ -66,9 +66,10 @@ async function mergeDts({
66
66
  currentAst.$ast.body.splice(index, 0, node);
67
67
  }
68
68
  }
69
- return transformAndFormat(currentAst.generate().code, meta, {
69
+ const res = await transformAndFormat(currentAst.generate().code, meta, {
70
70
  filepath
71
71
  });
72
+ return res.code;
72
73
  }
73
74
  function queue() {
74
75
  const tasks = [];
@@ -139,14 +140,56 @@ async function importTransformer(p) {
139
140
  const f = await import(importFile);
140
141
  return f.default;
141
142
  }
143
+ function importToPotentialTargets(imp) {
144
+ let subject = imp;
145
+ const ext = path.posix.extname(imp);
146
+ const targets = [];
147
+ if (ext.match(/^\.[jt]sx?$/)) {
148
+ subject = subject.replace(/^\.[jt]sx?$/, "");
149
+ }
150
+ if (!ext || subject !== imp) {
151
+ targets.push(...[".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"].map((e) => `${subject}${e}`));
152
+ } else {
153
+ targets.push(imp);
154
+ }
155
+ return targets;
156
+ }
142
157
  async function main(options, meta) {
143
158
  const sources = Array.isArray(options.source) ? options.source : [options.source];
144
159
  const targets = /* @__PURE__ */ new Set();
160
+ const allImports = /* @__PURE__ */ new Set();
161
+ const includeIfImported = /* @__PURE__ */ new Map();
145
162
  const priorityQ = queue();
146
163
  const transformAndWriteQ = queue();
164
+ function updateAllImports(target, imports) {
165
+ if (!imports) return;
166
+ for (const imp of imports.values()) {
167
+ const importTarget = path.posix.resolve(path.posix.dirname(target), imp);
168
+ const importTargets = importToPotentialTargets(importTarget);
169
+ for (const imp2 of importTargets) {
170
+ allImports.add(imp2);
171
+ }
172
+ }
173
+ }
174
+ async function triggerPendingTargets(target, imports) {
175
+ if (!imports) return;
176
+ for (const imp of imports.values()) {
177
+ const importTarget = path.posix.resolve(path.posix.dirname(target), imp);
178
+ const importTargets = importToPotentialTargets(importTarget);
179
+ for (const imp2 of importTargets) {
180
+ if (includeIfImported.has(imp2)) {
181
+ const fn = includeIfImported.get(imp2);
182
+ includeIfImported.delete(imp2);
183
+ await fn();
184
+ break;
185
+ }
186
+ }
187
+ }
188
+ }
147
189
  for (const source of sources) {
148
190
  for await (const p of walk(source)) {
149
191
  const target = toDist(p, source, options.dist);
192
+ const targetAbsolute = path.resolve(target);
150
193
  const parsed = path.parse(p);
151
194
  if (parsed.name.match(reIgnoreFile)) {
152
195
  continue;
@@ -172,16 +215,16 @@ Please report this issue to https://github.com/batijs/bati`
172
215
  );
173
216
  if (fileContent !== null) {
174
217
  await safeWriteFile(target, fileContent);
175
- targets.add(target);
176
218
  }
177
219
  });
178
220
  } else {
179
221
  priorityQ.add(async () => {
180
222
  const code = await readFile2(p, { encoding: "utf-8" });
181
223
  const filepath = path.relative(source, p);
182
- let fileContent = await transformAndFormat2(code, meta, {
224
+ const result = await transformAndFormat2(code, meta, {
183
225
  filepath
184
226
  });
227
+ let fileContent = result.code;
185
228
  if (p.endsWith(".d.ts") && targets.has(target)) {
186
229
  fileContent = await mergeDts({
187
230
  fileContent,
@@ -191,7 +234,13 @@ Please report this issue to https://github.com/batijs/bati`
191
234
  });
192
235
  }
193
236
  if (fileContent) {
194
- await safeWriteFile(target, fileContent.trimStart());
237
+ updateAllImports(targetAbsolute, result.context?.imports);
238
+ if (!result.context?.flags.has("include-if-imported") || allImports.has(targetAbsolute)) {
239
+ await safeWriteFile(target, fileContent.trimStart());
240
+ await triggerPendingTargets(targetAbsolute, result.context?.imports);
241
+ } else {
242
+ includeIfImported.set(targetAbsolute, () => safeWriteFile(target, fileContent.trimStart()));
243
+ }
195
244
  targets.add(target);
196
245
  }
197
246
  });
@@ -200,6 +249,11 @@ Please report this issue to https://github.com/batijs/bati`
200
249
  }
201
250
  await priorityQ.run();
202
251
  await transformAndWriteQ.run();
252
+ for (const target of includeIfImported.keys()) {
253
+ if (allImports.has(target)) {
254
+ await includeIfImported.get(target)();
255
+ }
256
+ }
203
257
  }
204
258
 
205
259
  // index.ts
@@ -1559,7 +1613,7 @@ var import_which_pm_runs = __toESM(require_which_pm_runs(), 1);
1559
1613
  // package.json
1560
1614
  var package_default = {
1561
1615
  name: "@batijs/cli",
1562
- version: "0.0.213",
1616
+ version: "0.0.215",
1563
1617
  type: "module",
1564
1618
  scripts: {
1565
1619
  "check-types": "tsc --noEmit",
@@ -1586,6 +1640,7 @@ var package_default = {
1586
1640
  sift: "^17.1.3",
1587
1641
  tsup: "^8.1.0",
1588
1642
  typescript: "^5.5.2",
1643
+ "unplugin-purge-polyfills": "^0.0.4",
1589
1644
  vite: "^5.3.2",
1590
1645
  "which-pm-runs": "^1.1.0"
1591
1646
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/cli",
3
- "version": "0.0.213",
3
+ "version": "0.0.215",
4
4
  "type": "module",
5
5
  "keywords": [],
6
6
  "description": "Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want",
@@ -19,14 +19,15 @@
19
19
  "sift": "^17.1.3",
20
20
  "tsup": "^8.1.0",
21
21
  "typescript": "^5.5.2",
22
+ "unplugin-purge-polyfills": "^0.0.4",
22
23
  "vite": "^5.3.2",
23
24
  "which-pm-runs": "^1.1.0",
24
- "@batijs/build": "0.0.213",
25
- "@batijs/compile": "0.0.213"
25
+ "@batijs/build": "0.0.215",
26
+ "@batijs/compile": "0.0.215"
26
27
  },
27
28
  "dependencies": {
28
- "@batijs/core": "0.0.213",
29
- "@batijs/features": "0.0.213"
29
+ "@batijs/features": "0.0.215",
30
+ "@batijs/core": "0.0.215"
30
31
  },
31
32
  "bin": "./dist/index.js",
32
33
  "exports": {