@batijs/build 0.0.462 → 0.0.465

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 (2) hide show
  1. package/dist/index.js +61 -59
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -2,12 +2,11 @@
2
2
  import { existsSync } from "fs";
3
3
  import { mkdir, opendir, rm, rmdir, writeFile } from "fs/promises";
4
4
  import path from "path";
5
- import "@batijs/core";
6
5
 
7
6
  // src/operations/file.ts
8
- import { transformAndFormat as transformAndFormat2 } from "@batijs/core";
9
7
  import { readFile } from "fs/promises";
10
8
  import { relative } from "path";
9
+ import { transformAndFormat as transformAndFormat2 } from "@batijs/core";
11
10
 
12
11
  // src/operations/merge-dts.ts
13
12
  import { parseModule, transformAndFormat } from "@batijs/core";
@@ -46,7 +45,10 @@ function clearExports(code, meta) {
46
45
  }
47
46
  if (meta.BATI.has("biome")) {
48
47
  const index = code.indexOf("\nexport {};");
49
- return code.slice(0, index) + "\n// biome-ignore lint/complexity/noUselessEmptyExport: ensure that the file is considered as a module" + code.slice(index);
48
+ const foundImport = code.match(/^import .* from /gm);
49
+ if (index !== -1 && foundImport) {
50
+ return code.slice(0, index) + "\n// biome-ignore lint/complexity/noUselessEmptyExport: ensure that the file is considered as a module" + code.slice(index);
51
+ }
50
52
  }
51
53
  return code;
52
54
  }
@@ -80,13 +82,63 @@ async function executeOperationFile(op, {
80
82
  };
81
83
  }
82
84
 
85
+ // src/utils.ts
86
+ function orderBy(array, getter) {
87
+ return array.slice().sort((a, b) => {
88
+ const valueA = getter(a);
89
+ const valueB = getter(b);
90
+ if (valueA < valueB) return -1;
91
+ if (valueA > valueB) return 1;
92
+ return 0;
93
+ });
94
+ }
95
+
96
+ // src/operations/rearranger.ts
97
+ var OperationsRearranger = class {
98
+ files;
99
+ constructor() {
100
+ this.files = /* @__PURE__ */ new Map();
101
+ }
102
+ addFile(file) {
103
+ if (!this.files.has(file.destination)) {
104
+ this.files.set(file.destination, []);
105
+ }
106
+ this.files.get(file.destination).push(file);
107
+ }
108
+ *compute() {
109
+ for (const file of this.files.values()) {
110
+ if (file.filter((op) => op.important).length >= 2) {
111
+ throw new Error(`Error while trying to generate file: '${file[0].destination}'.
112
+ Multiple important file is not yet supported.
113
+ Please report this issue to https://github.com/vikejs/bati`);
114
+ }
115
+ const newOrder = orderBy(file, (op) => {
116
+ if (op.kind === "file" && !op.important) return 1;
117
+ if (op.kind === "file" && op.important) return 2;
118
+ if (op.kind === "transform" && !op.important) return 3;
119
+ if (op.kind === "transform" && op.important) return 4;
120
+ throw new Error("Unhandled OperationsRearranger.compute orderBy case");
121
+ });
122
+ if (file[0].sourceAbsolute.endsWith(".d.ts")) {
123
+ yield* newOrder.filter((op) => op.kind === "file");
124
+ } else {
125
+ const input = newOrder.filter((op) => op.kind === "file").at(-1);
126
+ if (input) {
127
+ yield input;
128
+ }
129
+ }
130
+ yield* newOrder.filter((op) => op.kind !== "file");
131
+ }
132
+ }
133
+ };
134
+
83
135
  // src/operations/transform.ts
84
136
  import { parse } from "path";
85
137
  import { formatCode } from "@batijs/core";
86
138
  var isWin = process.platform === "win32";
87
139
  async function transformFileAfterExec(filepath, fileContent) {
88
140
  if (fileContent === void 0 || fileContent === null) return null;
89
- if (typeof fileContent == "object" && typeof fileContent.finalize === "function") {
141
+ if (typeof fileContent === "object" && typeof fileContent.finalize === "function") {
90
142
  fileContent = fileContent.finalize();
91
143
  if (typeof fileContent !== "string") {
92
144
  throw new Error("finalize() must return a string");
@@ -127,7 +179,7 @@ async function transformFileAfterExec(filepath, fileContent) {
127
179
  throw new Error(`Unsupported file extension ${parsed.base} (${filepath})`);
128
180
  }
129
181
  async function importTransformer(p) {
130
- const importFile = isWin ? "file://" + p : p;
182
+ const importFile = isWin ? `file://${p}` : p;
131
183
  const f = await import(importFile);
132
184
  return f.default;
133
185
  }
@@ -153,56 +205,6 @@ async function executeOperationTransform(op, {
153
205
  };
154
206
  }
155
207
 
156
- // src/utils.ts
157
- function orderBy(array, getter) {
158
- return array.slice().sort((a, b) => {
159
- const valueA = getter(a);
160
- const valueB = getter(b);
161
- if (valueA < valueB) return -1;
162
- if (valueA > valueB) return 1;
163
- return 0;
164
- });
165
- }
166
-
167
- // src/operations/rearranger.ts
168
- var OperationsRearranger = class {
169
- files;
170
- constructor() {
171
- this.files = /* @__PURE__ */ new Map();
172
- }
173
- addFile(file) {
174
- if (!this.files.has(file.destination)) {
175
- this.files.set(file.destination, []);
176
- }
177
- this.files.get(file.destination).push(file);
178
- }
179
- *compute() {
180
- for (const file of this.files.values()) {
181
- if (file.filter((op) => op.important).length >= 2) {
182
- throw new Error(`Error while trying to generate file: '${file[0].destination}'.
183
- Multiple important file is not yet supported.
184
- Please report this issue to https://github.com/vikejs/bati`);
185
- }
186
- const newOrder = orderBy(file, (op) => {
187
- if (op.kind === "file" && !op.important) return 1;
188
- if (op.kind === "file" && op.important) return 2;
189
- if (op.kind === "transform" && !op.important) return 3;
190
- if (op.kind === "transform" && op.important) return 4;
191
- throw new Error("Unhandled OperationsRearranger.compute orderBy case");
192
- });
193
- if (file[0].sourceAbsolute.endsWith(".d.ts")) {
194
- yield* newOrder.filter((op) => op.kind === "file");
195
- } else {
196
- const input = newOrder.filter((op) => op.kind === "file").at(-1);
197
- if (input) {
198
- yield input;
199
- }
200
- }
201
- yield* newOrder.filter((op) => op.kind !== "file");
202
- }
203
- }
204
- };
205
-
206
208
  // src/relations.ts
207
209
  import { extname } from "path";
208
210
  var RelationFile = class _RelationFile {
@@ -231,6 +233,7 @@ var RelationImport = class _RelationImport {
231
233
  return RelationFile.allPathAbsolute.get(target);
232
234
  }
233
235
  }
236
+ return void 0;
234
237
  }
235
238
  static computeUnimportedFiles() {
236
239
  const unimportedFiles = [];
@@ -309,7 +312,7 @@ async function safeRmFile(destination, options) {
309
312
  }
310
313
  }
311
314
  } catch {
312
- console.warn(`Failed to remove unecessary file: ${destination}`);
315
+ console.warn(`Failed to remove unnecessary file: ${destination}`);
313
316
  }
314
317
  }
315
318
  async function* walk(dir) {
@@ -338,7 +341,6 @@ async function main(options, meta) {
338
341
  const targetAbsolute = path.isAbsolute(target) ? target : path.resolve(target);
339
342
  const parsed = path.parse(p);
340
343
  if (parsed.name.match(reIgnoreFile)) {
341
- continue;
342
344
  } else if (parsed.name.startsWith("$") && parsed.ext.match(/\.tsx?$/)) {
343
345
  throw new Error(
344
346
  `Typescript file needs to be compiled before it can be executed: '${p}'.
@@ -367,8 +369,8 @@ Please report this issue to https://github.com/vikejs/bati`
367
369
  }
368
370
  }
369
371
  }
370
- let previousOp = void 0;
371
- let previousOpContent = void 0;
372
+ let previousOp;
373
+ let previousOpContent;
372
374
  let packageJson = {};
373
375
  const packageJsonDistAbsolute = path.join(
374
376
  path.isAbsolute(options.dist) ? options.dist : path.resolve(options.dist),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/build",
3
- "version": "0.0.462",
3
+ "version": "0.0.465",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -10,11 +10,11 @@
10
10
  "devDependencies": {
11
11
  "@types/node": "^20.19.9",
12
12
  "tsup": "^8.5.0",
13
- "@batijs/features": "0.0.462",
14
- "@batijs/compile": "0.0.462"
13
+ "@batijs/features": "0.0.465",
14
+ "@batijs/compile": "0.0.465"
15
15
  },
16
16
  "dependencies": {
17
- "@batijs/core": "0.0.462"
17
+ "@batijs/core": "0.0.465"
18
18
  },
19
19
  "main": "./dist/index.js",
20
20
  "module": "./dist/index.js",