@batijs/cli 0.0.214 → 0.0.216
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/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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
1616
|
+
version: "0.0.216",
|
|
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.
|
|
3
|
+
"version": "0.0.216",
|
|
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/compile": "0.0.
|
|
25
|
-
"@batijs/build": "0.0.
|
|
25
|
+
"@batijs/compile": "0.0.216",
|
|
26
|
+
"@batijs/build": "0.0.216"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@batijs/
|
|
29
|
-
"@batijs/
|
|
29
|
+
"@batijs/features": "0.0.216",
|
|
30
|
+
"@batijs/core": "0.0.216"
|
|
30
31
|
},
|
|
31
32
|
"bin": "./dist/index.js",
|
|
32
33
|
"exports": {
|