@batijs/build 0.0.176 → 0.0.178
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 +53 -11
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
|
-
import { mkdir, opendir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { mkdir, opendir, readFile as readFile2, writeFile } from "fs/promises";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { transformAndFormat } from "@batijs/core";
|
|
5
|
+
import { transformAndFormat as transformAndFormat2 } from "@batijs/core";
|
|
6
|
+
|
|
7
|
+
// src/merge-dts.ts
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { parseModule, transformAndFormat } from "@batijs/core";
|
|
10
|
+
async function mergeDts({
|
|
11
|
+
target,
|
|
12
|
+
fileContent,
|
|
13
|
+
filepath,
|
|
14
|
+
meta
|
|
15
|
+
}) {
|
|
16
|
+
const previousCode = await readFile(target, { encoding: "utf-8" });
|
|
17
|
+
const previousAst = parseModule(previousCode);
|
|
18
|
+
const currentAst = parseModule(fileContent);
|
|
19
|
+
for (const imp of previousAst.imports.$items) {
|
|
20
|
+
currentAst.imports[imp.local] = imp;
|
|
21
|
+
}
|
|
22
|
+
const index = currentAst.$ast.body.findIndex(
|
|
23
|
+
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
24
|
+
);
|
|
25
|
+
for (const node of previousAst.$ast.body) {
|
|
26
|
+
if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (index === -1) {
|
|
30
|
+
currentAst.$ast.body.push(node);
|
|
31
|
+
} else {
|
|
32
|
+
currentAst.$ast.body.splice(index, 0, node);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return transformAndFormat(currentAst.generate().code, meta, {
|
|
36
|
+
filepath
|
|
37
|
+
});
|
|
38
|
+
}
|
|
6
39
|
|
|
7
40
|
// src/queue.ts
|
|
8
41
|
function queue() {
|
|
@@ -82,7 +115,7 @@ async function importTransformer(p) {
|
|
|
82
115
|
async function main(options, meta) {
|
|
83
116
|
const sources = Array.isArray(options.source) ? options.source : [options.source];
|
|
84
117
|
const targets = /* @__PURE__ */ new Set();
|
|
85
|
-
const
|
|
118
|
+
const priorityQ = queue();
|
|
86
119
|
const transformAndWriteQ = queue();
|
|
87
120
|
for (const source of sources) {
|
|
88
121
|
for await (const p of walk(source)) {
|
|
@@ -93,13 +126,13 @@ async function main(options, meta) {
|
|
|
93
126
|
} else if (parsed.name.startsWith("$") && parsed.ext.match(/\.tsx?$/)) {
|
|
94
127
|
throw new Error(
|
|
95
128
|
`Typescript file needs to be compiled before it can be executed: '${p}'.
|
|
96
|
-
Please report this issue to https://github.com/
|
|
129
|
+
Please report this issue to https://github.com/batijs/bati`
|
|
97
130
|
);
|
|
98
131
|
} else if (parsed.name.startsWith("$") && parsed.ext.match(/\.jsx?$/)) {
|
|
99
132
|
transformAndWriteQ.add(async () => {
|
|
100
133
|
const transformer = await importTransformer(p);
|
|
101
134
|
const rf = () => {
|
|
102
|
-
return
|
|
135
|
+
return readFile2(target, { encoding: "utf-8" });
|
|
103
136
|
};
|
|
104
137
|
const fileContent = transformFileAfterExec(
|
|
105
138
|
target,
|
|
@@ -116,20 +149,29 @@ Please report this issue to https://github.com/magne4000/bati`
|
|
|
116
149
|
}
|
|
117
150
|
});
|
|
118
151
|
} else {
|
|
119
|
-
|
|
120
|
-
const code = await
|
|
121
|
-
const
|
|
122
|
-
|
|
152
|
+
priorityQ.add(async () => {
|
|
153
|
+
const code = await readFile2(p, { encoding: "utf-8" });
|
|
154
|
+
const filepath = path.relative(source, p);
|
|
155
|
+
let fileContent = await transformAndFormat2(code, meta, {
|
|
156
|
+
filepath
|
|
123
157
|
});
|
|
158
|
+
if (p.endsWith(".d.ts") && targets.has(target)) {
|
|
159
|
+
fileContent = await mergeDts({
|
|
160
|
+
fileContent,
|
|
161
|
+
target,
|
|
162
|
+
meta,
|
|
163
|
+
filepath
|
|
164
|
+
});
|
|
165
|
+
}
|
|
124
166
|
if (fileContent) {
|
|
125
|
-
await safeWriteFile(target, fileContent);
|
|
167
|
+
await safeWriteFile(target, fileContent.trimStart());
|
|
126
168
|
targets.add(target);
|
|
127
169
|
}
|
|
128
170
|
});
|
|
129
171
|
}
|
|
130
172
|
}
|
|
131
173
|
}
|
|
132
|
-
await
|
|
174
|
+
await priorityQ.run();
|
|
133
175
|
await transformAndWriteQ.run();
|
|
134
176
|
}
|
|
135
177
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@batijs/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.178",
|
|
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.0.2",
|
|
13
|
-
"@batijs/compile": "0.0.
|
|
13
|
+
"@batijs/compile": "0.0.178"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@batijs/core": "0.0.
|
|
16
|
+
"@batijs/core": "0.0.178"
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"module": "./dist/index.js",
|