@batijs/build 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.
- package/dist/index.js +58 -4
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -32,9 +32,10 @@ async function mergeDts({
|
|
|
32
32
|
currentAst.$ast.body.splice(index, 0, node);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const res = await transformAndFormat(currentAst.generate().code, meta, {
|
|
36
36
|
filepath
|
|
37
37
|
});
|
|
38
|
+
return res.code;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
// src/queue.ts
|
|
@@ -109,14 +110,56 @@ async function importTransformer(p) {
|
|
|
109
110
|
const f = await import(importFile);
|
|
110
111
|
return f.default;
|
|
111
112
|
}
|
|
113
|
+
function importToPotentialTargets(imp) {
|
|
114
|
+
let subject = imp;
|
|
115
|
+
const ext = path.posix.extname(imp);
|
|
116
|
+
const targets = [];
|
|
117
|
+
if (ext.match(/^\.[jt]sx?$/)) {
|
|
118
|
+
subject = subject.replace(/^\.[jt]sx?$/, "");
|
|
119
|
+
}
|
|
120
|
+
if (!ext || subject !== imp) {
|
|
121
|
+
targets.push(...[".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"].map((e) => `${subject}${e}`));
|
|
122
|
+
} else {
|
|
123
|
+
targets.push(imp);
|
|
124
|
+
}
|
|
125
|
+
return targets;
|
|
126
|
+
}
|
|
112
127
|
async function main(options, meta) {
|
|
113
128
|
const sources = Array.isArray(options.source) ? options.source : [options.source];
|
|
114
129
|
const targets = /* @__PURE__ */ new Set();
|
|
130
|
+
const allImports = /* @__PURE__ */ new Set();
|
|
131
|
+
const includeIfImported = /* @__PURE__ */ new Map();
|
|
115
132
|
const priorityQ = queue();
|
|
116
133
|
const transformAndWriteQ = queue();
|
|
134
|
+
function updateAllImports(target, imports) {
|
|
135
|
+
if (!imports) return;
|
|
136
|
+
for (const imp of imports.values()) {
|
|
137
|
+
const importTarget = path.posix.resolve(path.posix.dirname(target), imp);
|
|
138
|
+
const importTargets = importToPotentialTargets(importTarget);
|
|
139
|
+
for (const imp2 of importTargets) {
|
|
140
|
+
allImports.add(imp2);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function triggerPendingTargets(target, imports) {
|
|
145
|
+
if (!imports) return;
|
|
146
|
+
for (const imp of imports.values()) {
|
|
147
|
+
const importTarget = path.posix.resolve(path.posix.dirname(target), imp);
|
|
148
|
+
const importTargets = importToPotentialTargets(importTarget);
|
|
149
|
+
for (const imp2 of importTargets) {
|
|
150
|
+
if (includeIfImported.has(imp2)) {
|
|
151
|
+
const fn = includeIfImported.get(imp2);
|
|
152
|
+
includeIfImported.delete(imp2);
|
|
153
|
+
await fn();
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
117
159
|
for (const source of sources) {
|
|
118
160
|
for await (const p of walk(source)) {
|
|
119
161
|
const target = toDist(p, source, options.dist);
|
|
162
|
+
const targetAbsolute = path.resolve(target);
|
|
120
163
|
const parsed = path.parse(p);
|
|
121
164
|
if (parsed.name.match(reIgnoreFile)) {
|
|
122
165
|
continue;
|
|
@@ -142,16 +185,16 @@ Please report this issue to https://github.com/batijs/bati`
|
|
|
142
185
|
);
|
|
143
186
|
if (fileContent !== null) {
|
|
144
187
|
await safeWriteFile(target, fileContent);
|
|
145
|
-
targets.add(target);
|
|
146
188
|
}
|
|
147
189
|
});
|
|
148
190
|
} else {
|
|
149
191
|
priorityQ.add(async () => {
|
|
150
192
|
const code = await readFile2(p, { encoding: "utf-8" });
|
|
151
193
|
const filepath = path.relative(source, p);
|
|
152
|
-
|
|
194
|
+
const result = await transformAndFormat2(code, meta, {
|
|
153
195
|
filepath
|
|
154
196
|
});
|
|
197
|
+
let fileContent = result.code;
|
|
155
198
|
if (p.endsWith(".d.ts") && targets.has(target)) {
|
|
156
199
|
fileContent = await mergeDts({
|
|
157
200
|
fileContent,
|
|
@@ -161,7 +204,13 @@ Please report this issue to https://github.com/batijs/bati`
|
|
|
161
204
|
});
|
|
162
205
|
}
|
|
163
206
|
if (fileContent) {
|
|
164
|
-
|
|
207
|
+
updateAllImports(targetAbsolute, result.context?.imports);
|
|
208
|
+
if (!result.context?.flags.has("include-if-imported") || allImports.has(targetAbsolute)) {
|
|
209
|
+
await safeWriteFile(target, fileContent.trimStart());
|
|
210
|
+
await triggerPendingTargets(targetAbsolute, result.context?.imports);
|
|
211
|
+
} else {
|
|
212
|
+
includeIfImported.set(targetAbsolute, () => safeWriteFile(target, fileContent.trimStart()));
|
|
213
|
+
}
|
|
165
214
|
targets.add(target);
|
|
166
215
|
}
|
|
167
216
|
});
|
|
@@ -170,6 +219,11 @@ Please report this issue to https://github.com/batijs/bati`
|
|
|
170
219
|
}
|
|
171
220
|
await priorityQ.run();
|
|
172
221
|
await transformAndWriteQ.run();
|
|
222
|
+
for (const target of includeIfImported.keys()) {
|
|
223
|
+
if (allImports.has(target)) {
|
|
224
|
+
await includeIfImported.get(target)();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
173
227
|
}
|
|
174
228
|
export {
|
|
175
229
|
main as default,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@batijs/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.215",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/node": "^18.19.14",
|
|
12
12
|
"tsup": "^8.1.0",
|
|
13
|
-
"@batijs/compile": "0.0.
|
|
13
|
+
"@batijs/compile": "0.0.215"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@batijs/core": "0.0.
|
|
16
|
+
"@batijs/core": "0.0.215"
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"module": "./dist/index.js",
|