@sse-ui/builder 1.0.2 → 1.1.0
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/{babel-VTL3CZAT.js → babel-QBNMMXUJ.js} +1 -1
- package/dist/{chunk-5S2N5WDQ.js → chunk-44E7L73Q.js} +261 -52
- package/dist/cli.js +122 -148
- package/dist/config.d.ts +8 -1
- package/dist/{typescript-CS6YZCMJ.js → typescript-3J237V7Q.js} +1 -1
- package/package.json +8 -4
- package/bin/sse-tools.js +0 -2
|
@@ -168,7 +168,8 @@ async function createPackageExports({
|
|
|
168
168
|
cwd,
|
|
169
169
|
addTypes = false,
|
|
170
170
|
isFlat = false,
|
|
171
|
-
packageType = "commonjs"
|
|
171
|
+
packageType = "commonjs",
|
|
172
|
+
exportExtensions = [".js", ".mjs", ".cjs"]
|
|
172
173
|
}) {
|
|
173
174
|
const resolvedPackageType = packageType === "module" ? "module" : "commonjs";
|
|
174
175
|
const rawExports = typeof packageExports === "string" || Array.isArray(packageExports) ? { ".": packageExports } : packageExports || {};
|
|
@@ -179,8 +180,29 @@ async function createPackageExports({
|
|
|
179
180
|
const result = {
|
|
180
181
|
exports: newExports
|
|
181
182
|
};
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
const baseBundle = bundles.find((b) => b.type === "esm") || bundles[0];
|
|
184
|
+
const scanDir = isFlat ? outputDir : path.join(outputDir, baseBundle.dir);
|
|
185
|
+
const buildFiles = await globby("**/*", { cwd: scanDir });
|
|
186
|
+
const jsDirs = /* @__PURE__ */ new Set();
|
|
187
|
+
const otherFiles = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const file of buildFiles) {
|
|
189
|
+
if (file.endsWith(".d.ts") || file.endsWith(".d.mts") || file.endsWith(".d.cts")) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const ext = path.extname(file);
|
|
193
|
+
const normalizedFile = file.split(path.sep).join(path.posix.sep);
|
|
194
|
+
if (exportExtensions.includes(ext)) {
|
|
195
|
+
jsDirs.add(path.posix.dirname(normalizedFile));
|
|
196
|
+
} else {
|
|
197
|
+
otherFiles.add(normalizedFile);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const getIndexFileName = (type) => `index${getOutExtension(type, { isFlat, packageType: resolvedPackageType })}`;
|
|
201
|
+
const rootIndexExists = await fs.stat(path.join(scanDir, getIndexFileName(baseBundle.type))).then((s) => s.isFile()).catch(() => false);
|
|
202
|
+
if (rootIndexExists && originalExports["."] === void 0) {
|
|
203
|
+
newExports["."] ??= {};
|
|
204
|
+
const rootConditions = newExports["."];
|
|
205
|
+
for (const { type, dir: bundleDir } of bundles) {
|
|
184
206
|
const outExtension = getOutExtension(type, {
|
|
185
207
|
isFlat,
|
|
186
208
|
packageType: resolvedPackageType
|
|
@@ -190,59 +212,157 @@ async function createPackageExports({
|
|
|
190
212
|
isType: true,
|
|
191
213
|
packageType: resolvedPackageType
|
|
192
214
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
);
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const exportDir = `./${dirPrefix}index${outExtension}`;
|
|
203
|
-
const typeExportDir = `./${dirPrefix}index${typeOutExtension}`;
|
|
204
|
-
if (indexFileExists) {
|
|
205
|
-
if (type === "cjs") {
|
|
206
|
-
result.main = exportDir;
|
|
207
|
-
}
|
|
208
|
-
if (typeof newExports["."] === "string" || Array.isArray(newExports["."])) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
`The export "." is already defined as a string or Array.`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
newExports["."] ??= {};
|
|
214
|
-
newExports["."][type === "cjs" ? "require" : "import"] = typeFileExists ? {
|
|
215
|
-
types: typeExportDir,
|
|
216
|
-
default: exportDir
|
|
217
|
-
} : exportDir;
|
|
215
|
+
const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
|
|
216
|
+
const exportPath = `./${dirPrefix}index${outExtension}`;
|
|
217
|
+
const typeExportPath = `./${dirPrefix}index${typeOutExtension}`;
|
|
218
|
+
const typeExists = addTypes && await fs.stat(path.join(outputDir, bundleDir, `index${typeOutExtension}`)).then((s) => s.isFile()).catch(() => false);
|
|
219
|
+
const conditionKey = type === "cjs" ? "require" : "import";
|
|
220
|
+
rootConditions[conditionKey] = typeExists ? { types: typeExportPath, default: exportPath } : exportPath;
|
|
221
|
+
if (type === "cjs" || type === "esm" && bundles.length === 1) {
|
|
222
|
+
result.main = exportPath;
|
|
223
|
+
if (typeExists) result.types = typeExportPath;
|
|
218
224
|
}
|
|
219
|
-
|
|
220
|
-
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const dir of jsDirs) {
|
|
228
|
+
const globKey = dir === "." ? "./*" : `./${dir}/*`;
|
|
229
|
+
if (originalExports[globKey] === void 0) {
|
|
230
|
+
newExports[globKey] ??= {};
|
|
231
|
+
const globConditions = newExports[globKey];
|
|
232
|
+
for (const { type, dir: bundleDir } of bundles) {
|
|
233
|
+
const outExtension = getOutExtension(type, {
|
|
234
|
+
isFlat,
|
|
235
|
+
packageType: resolvedPackageType
|
|
236
|
+
});
|
|
237
|
+
const typeOutExtension = getOutExtension(type, {
|
|
238
|
+
isFlat,
|
|
239
|
+
isType: true,
|
|
240
|
+
packageType: resolvedPackageType
|
|
241
|
+
});
|
|
242
|
+
const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
|
|
243
|
+
const basePath = dir === "." ? "" : `${dir}/`;
|
|
244
|
+
const exportPath = `./${dirPrefix}${basePath}*${outExtension}`;
|
|
245
|
+
const typeExportPath = `./${dirPrefix}${basePath}*${typeOutExtension}`;
|
|
246
|
+
const conditionKey = type === "cjs" ? "require" : "import";
|
|
247
|
+
globConditions[conditionKey] = addTypes ? { types: typeExportPath, default: exportPath } : exportPath;
|
|
221
248
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
249
|
+
}
|
|
250
|
+
if (dir !== ".") {
|
|
251
|
+
const dirIndexExists = await fs.stat(path.posix.join(scanDir, dir, getIndexFileName(baseBundle.type))).then((s) => s.isFile()).catch(() => false);
|
|
252
|
+
const dirKey = `./${dir}`;
|
|
253
|
+
if (dirIndexExists && originalExports[dirKey] === void 0) {
|
|
254
|
+
newExports[dirKey] ??= {};
|
|
255
|
+
const dirConditions = newExports[dirKey];
|
|
256
|
+
for (const { type, dir: bundleDir } of bundles) {
|
|
257
|
+
const outExtension = getOutExtension(type, {
|
|
258
|
+
isFlat,
|
|
259
|
+
packageType: resolvedPackageType
|
|
260
|
+
});
|
|
261
|
+
const typeOutExtension = getOutExtension(type, {
|
|
262
|
+
isFlat,
|
|
263
|
+
isType: true,
|
|
264
|
+
packageType: resolvedPackageType
|
|
265
|
+
});
|
|
266
|
+
const dirPrefix = bundleDir === "." ? "" : `${bundleDir}/`;
|
|
267
|
+
const basePath = `${dir}/`;
|
|
268
|
+
const exportPath = `./${dirPrefix}${basePath}index${outExtension}`;
|
|
269
|
+
const typeExportPath = `./${dirPrefix}${basePath}index${typeOutExtension}`;
|
|
270
|
+
const typeExists = addTypes && await fs.stat(
|
|
271
|
+
path.join(
|
|
272
|
+
outputDir,
|
|
273
|
+
bundleDir,
|
|
274
|
+
dir,
|
|
275
|
+
`index${typeOutExtension}`
|
|
276
|
+
)
|
|
277
|
+
).then((s) => s.isFile()).catch(() => false);
|
|
278
|
+
const conditionKey = type === "cjs" ? "require" : "import";
|
|
279
|
+
dirConditions[conditionKey] = typeExists ? { types: typeExportPath, default: exportPath } : exportPath;
|
|
228
280
|
}
|
|
229
|
-
await createExportsFor({
|
|
230
|
-
importPath,
|
|
231
|
-
key,
|
|
232
|
-
cwd,
|
|
233
|
-
dir,
|
|
234
|
-
type,
|
|
235
|
-
newExports,
|
|
236
|
-
typeOutExtension,
|
|
237
|
-
outExtension,
|
|
238
|
-
addTypes
|
|
239
|
-
});
|
|
240
281
|
}
|
|
241
|
-
}
|
|
242
|
-
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
for (const file of otherFiles) {
|
|
285
|
+
const exportKey = `./${file}`;
|
|
286
|
+
if (originalExports[exportKey] !== void 0) continue;
|
|
287
|
+
const dirPrefix = baseBundle.dir === "." ? "" : `${baseBundle.dir}/`;
|
|
288
|
+
newExports[exportKey] = `./${dirPrefix}${file}`;
|
|
289
|
+
}
|
|
290
|
+
const exportKeys = Object.keys(originalExports);
|
|
291
|
+
for (const key of exportKeys) {
|
|
292
|
+
const importPath = originalExports[key];
|
|
293
|
+
if (!importPath) {
|
|
294
|
+
newExports[key] = null;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (key === ".") continue;
|
|
298
|
+
await Promise.all(
|
|
299
|
+
bundles.map(async ({ type, dir }) => {
|
|
300
|
+
const outExtension = getOutExtension(type, {
|
|
301
|
+
isFlat,
|
|
302
|
+
packageType: resolvedPackageType
|
|
303
|
+
});
|
|
304
|
+
const typeOutExtension = getOutExtension(type, {
|
|
305
|
+
isFlat,
|
|
306
|
+
isType: true,
|
|
307
|
+
packageType: resolvedPackageType
|
|
308
|
+
});
|
|
309
|
+
const indexFileExists = await fs.stat(path.join(outputDir, dir, `index${outExtension}`)).then(
|
|
310
|
+
(stats) => stats.isFile(),
|
|
311
|
+
() => false
|
|
312
|
+
);
|
|
313
|
+
const typeFileExists = addTypes && await fs.stat(path.join(outputDir, dir, `index${typeOutExtension}`)).then(
|
|
314
|
+
(stats) => stats.isFile(),
|
|
315
|
+
() => false
|
|
316
|
+
);
|
|
317
|
+
const dirPrefix = dir === "." ? "" : `${dir}/`;
|
|
318
|
+
const exportDir = `./${dirPrefix}index${outExtension}`;
|
|
319
|
+
const typeExportDir = `./${dirPrefix}index${typeOutExtension}`;
|
|
320
|
+
if (indexFileExists && originalExports["."] !== void 0) {
|
|
321
|
+
if (type === "cjs") {
|
|
322
|
+
result.main = exportDir;
|
|
323
|
+
}
|
|
324
|
+
if (typeof newExports["."] === "string" || Array.isArray(newExports["."])) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
`The export "." is already defined as a string or Array.`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
newExports["."] ??= {};
|
|
330
|
+
const rootConditions = newExports["."];
|
|
331
|
+
rootConditions[type === "cjs" ? "require" : "import"] = typeFileExists ? {
|
|
332
|
+
types: typeExportDir,
|
|
333
|
+
default: exportDir
|
|
334
|
+
} : exportDir;
|
|
335
|
+
}
|
|
336
|
+
if (typeFileExists && type === "cjs") {
|
|
337
|
+
result.types = typeExportDir;
|
|
338
|
+
}
|
|
339
|
+
const exportKeys2 = Object.keys(originalExports);
|
|
340
|
+
for (const key2 of exportKeys2) {
|
|
341
|
+
const importPath2 = originalExports[key2];
|
|
342
|
+
if (!importPath2) {
|
|
343
|
+
newExports[key2] = null;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (key2 === ".") continue;
|
|
347
|
+
await createExportsFor({
|
|
348
|
+
importPath: importPath2,
|
|
349
|
+
key: key2,
|
|
350
|
+
cwd,
|
|
351
|
+
dir,
|
|
352
|
+
type,
|
|
353
|
+
newExports,
|
|
354
|
+
typeOutExtension,
|
|
355
|
+
outExtension,
|
|
356
|
+
addTypes
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
);
|
|
361
|
+
}
|
|
243
362
|
bundles.forEach(({ dir }) => {
|
|
244
363
|
if (dir !== ".") {
|
|
245
364
|
newExports[`./${dir}`] = null;
|
|
365
|
+
newExports[`./${dir}/*`] = null;
|
|
246
366
|
}
|
|
247
367
|
});
|
|
248
368
|
Object.keys(newExports).forEach((key) => {
|
|
@@ -390,12 +510,101 @@ async function mapConcurrently(items, mapper, concurrency) {
|
|
|
390
510
|
await Promise.all(workers);
|
|
391
511
|
return results;
|
|
392
512
|
}
|
|
513
|
+
async function addLicense({
|
|
514
|
+
name,
|
|
515
|
+
version,
|
|
516
|
+
license,
|
|
517
|
+
bundle,
|
|
518
|
+
outputDir,
|
|
519
|
+
isFlat,
|
|
520
|
+
packageType
|
|
521
|
+
}) {
|
|
522
|
+
const outExtension = getOutExtension(bundle, { isFlat, packageType });
|
|
523
|
+
const file = path.join(outputDir, `index${outExtension}`);
|
|
524
|
+
if (!await fs.stat(file).then(
|
|
525
|
+
(stats) => stats.isFile(),
|
|
526
|
+
() => false
|
|
527
|
+
)) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const content = await fs.readFile(file, { encoding: "utf8" });
|
|
531
|
+
await fs.writeFile(
|
|
532
|
+
file,
|
|
533
|
+
`/**
|
|
534
|
+
* ${name} v${version}
|
|
535
|
+
*
|
|
536
|
+
* @license ${license}
|
|
537
|
+
* This source code is licensed under the ${license} license found in the
|
|
538
|
+
* LICENSE file in the root directory of this source tree.
|
|
539
|
+
*/
|
|
540
|
+
${content}`,
|
|
541
|
+
{ encoding: "utf8" }
|
|
542
|
+
);
|
|
543
|
+
if (process.env.SSE_BUILD_VERBOSE) console.log(`License added to ${file}`);
|
|
544
|
+
}
|
|
545
|
+
async function writePackageJson({
|
|
546
|
+
packageJson,
|
|
547
|
+
bundles,
|
|
548
|
+
outputDir,
|
|
549
|
+
cwd,
|
|
550
|
+
addTypes = false,
|
|
551
|
+
isFlat = false,
|
|
552
|
+
packageType,
|
|
553
|
+
exportExtensions
|
|
554
|
+
}) {
|
|
555
|
+
delete packageJson.scripts;
|
|
556
|
+
delete packageJson.publishConfig?.directory;
|
|
557
|
+
delete packageJson.devDependencies;
|
|
558
|
+
delete packageJson.imports;
|
|
559
|
+
const resolvedPackageType = packageType || packageJson.type || "commonjs";
|
|
560
|
+
packageJson.type = resolvedPackageType;
|
|
561
|
+
const originalExports = packageJson.exports;
|
|
562
|
+
delete packageJson.exports;
|
|
563
|
+
const originalBin = packageJson.bin;
|
|
564
|
+
delete packageJson.bin;
|
|
565
|
+
const {
|
|
566
|
+
exports: packageExports,
|
|
567
|
+
main,
|
|
568
|
+
types
|
|
569
|
+
} = await createPackageExports({
|
|
570
|
+
exports: originalExports,
|
|
571
|
+
bundles,
|
|
572
|
+
outputDir,
|
|
573
|
+
cwd,
|
|
574
|
+
addTypes,
|
|
575
|
+
isFlat,
|
|
576
|
+
packageType: resolvedPackageType,
|
|
577
|
+
exportExtensions
|
|
578
|
+
});
|
|
579
|
+
packageJson.exports = packageExports;
|
|
580
|
+
if (main) {
|
|
581
|
+
packageJson.main = main;
|
|
582
|
+
}
|
|
583
|
+
if (types) {
|
|
584
|
+
packageJson.types = types;
|
|
585
|
+
}
|
|
586
|
+
const bin = await createPackageBin({
|
|
587
|
+
bin: originalBin,
|
|
588
|
+
bundles,
|
|
589
|
+
cwd,
|
|
590
|
+
isFlat,
|
|
591
|
+
packageType: resolvedPackageType
|
|
592
|
+
});
|
|
593
|
+
if (bin) {
|
|
594
|
+
packageJson.bin = bin;
|
|
595
|
+
}
|
|
596
|
+
await fs.writeFile(
|
|
597
|
+
path.join(outputDir, "package.json"),
|
|
598
|
+
JSON.stringify(packageJson, null, 2),
|
|
599
|
+
"utf-8"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
393
602
|
|
|
394
603
|
export {
|
|
395
604
|
getOutExtension,
|
|
396
|
-
createPackageExports,
|
|
397
|
-
createPackageBin,
|
|
398
605
|
validatePkgJson,
|
|
399
606
|
BASE_IGNORES,
|
|
400
|
-
mapConcurrently
|
|
607
|
+
mapConcurrently,
|
|
608
|
+
addLicense,
|
|
609
|
+
writePackageJson
|
|
401
610
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
createPackageExports,
|
|
3
|
+
addLicense,
|
|
5
4
|
getOutExtension,
|
|
6
5
|
mapConcurrently,
|
|
7
|
-
validatePkgJson
|
|
8
|
-
|
|
6
|
+
validatePkgJson,
|
|
7
|
+
writePackageJson
|
|
8
|
+
} from "./chunk-44E7L73Q.js";
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
11
|
import { Command as Command11 } from "commander";
|
|
@@ -19,6 +19,7 @@ import * as path from "path";
|
|
|
19
19
|
import { sep as posixSep } from "path/posix";
|
|
20
20
|
import * as semver from "semver";
|
|
21
21
|
import { Command } from "commander";
|
|
22
|
+
import { build as esbuild } from "esbuild";
|
|
22
23
|
|
|
23
24
|
// src/utils/loadConfig.ts
|
|
24
25
|
import { loadConfig as loadC12Config } from "c12";
|
|
@@ -41,93 +42,6 @@ async function loadConfig() {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// src/core/build.ts
|
|
44
|
-
async function addLicense({
|
|
45
|
-
name,
|
|
46
|
-
version,
|
|
47
|
-
license,
|
|
48
|
-
bundle,
|
|
49
|
-
outputDir,
|
|
50
|
-
isFlat,
|
|
51
|
-
packageType
|
|
52
|
-
}) {
|
|
53
|
-
const outExtension = getOutExtension(bundle, { isFlat, packageType });
|
|
54
|
-
const file = path.join(outputDir, `index${outExtension}`);
|
|
55
|
-
if (!await fs.stat(file).then(
|
|
56
|
-
(stats) => stats.isFile(),
|
|
57
|
-
() => false
|
|
58
|
-
)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const content = await fs.readFile(file, { encoding: "utf8" });
|
|
62
|
-
await fs.writeFile(
|
|
63
|
-
file,
|
|
64
|
-
`/**
|
|
65
|
-
* ${name} v${version}
|
|
66
|
-
*
|
|
67
|
-
* @license ${license}
|
|
68
|
-
* This source code is licensed under the ${license} license found in the
|
|
69
|
-
* LICENSE file in the root directory of this source tree.
|
|
70
|
-
*/
|
|
71
|
-
${content}`,
|
|
72
|
-
{ encoding: "utf8" }
|
|
73
|
-
);
|
|
74
|
-
console.log(`License added to ${file}`);
|
|
75
|
-
}
|
|
76
|
-
async function writePackageJson({
|
|
77
|
-
packageJson,
|
|
78
|
-
bundles,
|
|
79
|
-
outputDir,
|
|
80
|
-
cwd,
|
|
81
|
-
addTypes = false,
|
|
82
|
-
isFlat = false,
|
|
83
|
-
packageType
|
|
84
|
-
}) {
|
|
85
|
-
delete packageJson.scripts;
|
|
86
|
-
delete packageJson.publishConfig?.directory;
|
|
87
|
-
delete packageJson.devDependencies;
|
|
88
|
-
delete packageJson.imports;
|
|
89
|
-
const resolvedPackageType = packageType || packageJson.type || "commonjs";
|
|
90
|
-
packageJson.type = resolvedPackageType;
|
|
91
|
-
const originalExports = packageJson.exports;
|
|
92
|
-
delete packageJson.exports;
|
|
93
|
-
const originalBin = packageJson.bin;
|
|
94
|
-
delete packageJson.bin;
|
|
95
|
-
const {
|
|
96
|
-
exports: packageExports,
|
|
97
|
-
main: main2,
|
|
98
|
-
types
|
|
99
|
-
} = await createPackageExports({
|
|
100
|
-
exports: originalExports,
|
|
101
|
-
bundles,
|
|
102
|
-
outputDir,
|
|
103
|
-
cwd,
|
|
104
|
-
addTypes,
|
|
105
|
-
isFlat,
|
|
106
|
-
packageType: resolvedPackageType
|
|
107
|
-
});
|
|
108
|
-
packageJson.exports = packageExports;
|
|
109
|
-
if (main2) {
|
|
110
|
-
packageJson.main = main2;
|
|
111
|
-
}
|
|
112
|
-
if (types) {
|
|
113
|
-
packageJson.types = types;
|
|
114
|
-
}
|
|
115
|
-
const bin = await createPackageBin({
|
|
116
|
-
bin: originalBin,
|
|
117
|
-
bundles,
|
|
118
|
-
cwd,
|
|
119
|
-
isFlat,
|
|
120
|
-
packageType: resolvedPackageType
|
|
121
|
-
});
|
|
122
|
-
if (bin) {
|
|
123
|
-
packageJson.bin = bin;
|
|
124
|
-
}
|
|
125
|
-
await fs.writeFile(
|
|
126
|
-
path.join(outputDir, "package.json"),
|
|
127
|
-
JSON.stringify(packageJson, null, 2),
|
|
128
|
-
"utf-8"
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
45
|
var buildCommand = new Command("build").description("Builds the package for publishing.").option("--bundle <bundles...>", "Bundles to output", ["esm", "cjs"]).option(
|
|
132
46
|
"--hasLargeFiles",
|
|
133
47
|
"Set to `true` if you know you are transpiling large files.",
|
|
@@ -164,6 +78,14 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
164
78
|
"--flat",
|
|
165
79
|
"Builds the package in a flat structure without subdirectories for each module type.",
|
|
166
80
|
process.env.SSE_BUILD_FLAT === "1"
|
|
81
|
+
).option(
|
|
82
|
+
"--bundleSingleFile",
|
|
83
|
+
"Bundle all modules into single files using esbuild (tsup style)",
|
|
84
|
+
false
|
|
85
|
+
).option(
|
|
86
|
+
"--exportExtensions <exts...>",
|
|
87
|
+
"Available extensions for generating exports wildcards.",
|
|
88
|
+
[".js", ".mjs", ".cjs"]
|
|
167
89
|
).option("--verbose", "Enable verbose logging.", false).action(async (cliOptions) => {
|
|
168
90
|
const fileConfig = await loadConfig();
|
|
169
91
|
const options = {
|
|
@@ -180,7 +102,9 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
180
102
|
verbose: cliOptions.verbose ?? fileConfig.verbose ?? false,
|
|
181
103
|
skipBabelRuntimeCheck: false,
|
|
182
104
|
skipPackageJson: false,
|
|
183
|
-
skipMainCheck: false
|
|
105
|
+
skipMainCheck: false,
|
|
106
|
+
bundleSingleFile: cliOptions.bundleSingleFile ?? fileConfig.bundleSingleFile ?? false,
|
|
107
|
+
exportExtensions: cliOptions.exportExtensions ?? fileConfig.exportExtensions ?? [".js", ".mjs", ".cjs"]
|
|
184
108
|
};
|
|
185
109
|
const {
|
|
186
110
|
bundle: bundles,
|
|
@@ -193,7 +117,9 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
193
117
|
skipBabelRuntimeCheck = false,
|
|
194
118
|
skipPackageJson = false,
|
|
195
119
|
enableReactCompiler = false,
|
|
196
|
-
tsgo: useTsgo = false
|
|
120
|
+
tsgo: useTsgo = false,
|
|
121
|
+
bundleSingleFile,
|
|
122
|
+
exportExtensions
|
|
197
123
|
} = options;
|
|
198
124
|
const cwd = process.cwd();
|
|
199
125
|
const pkgJsonPath = path.join(cwd, "package.json");
|
|
@@ -229,7 +155,7 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
229
155
|
);
|
|
230
156
|
return;
|
|
231
157
|
}
|
|
232
|
-
const { build: babelBuild, cjsCopy } = await import("./babel-
|
|
158
|
+
const { build: babelBuild, cjsCopy } = await import("./babel-QBNMMXUJ.js");
|
|
233
159
|
const relativeOutDirs = !options.flat ? {
|
|
234
160
|
cjs: ".",
|
|
235
161
|
esm: "esm"
|
|
@@ -245,67 +171,114 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
245
171
|
`[feature] Building with React compiler enabled. The compiler mode is "${mode}" right now.${mode === "opt-in" ? ' Use explicit "use memo" directives in your components to enable the React compiler for them.' : ""}`
|
|
246
172
|
);
|
|
247
173
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
sourceDir,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
} : void 0
|
|
276
|
-
})
|
|
277
|
-
);
|
|
278
|
-
if (buildDir !== outputDir && !skipBundlePackageJson && !options.flat) {
|
|
279
|
-
promises.push(
|
|
280
|
-
fs.writeFile(
|
|
174
|
+
if (bundleSingleFile) {
|
|
175
|
+
if (verbose)
|
|
176
|
+
console.log("\u{1F4E6} Bundling package into single files via esbuild...");
|
|
177
|
+
await Promise.all(
|
|
178
|
+
bundles.map(async (bundle) => {
|
|
179
|
+
const outExtension = getOutExtension(bundle, {
|
|
180
|
+
isFlat: !!options.flat,
|
|
181
|
+
isType: false,
|
|
182
|
+
packageType
|
|
183
|
+
});
|
|
184
|
+
const relativeOutDir = relativeOutDirs[bundle];
|
|
185
|
+
const outputDir = path.join(buildDir, relativeOutDir);
|
|
186
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
187
|
+
await esbuild({
|
|
188
|
+
entryPoints: [path.join(sourceDir, "index.ts")],
|
|
189
|
+
bundle: true,
|
|
190
|
+
outfile: path.join(outputDir, `index${outExtension}`),
|
|
191
|
+
format: bundle === "esm" ? "esm" : "cjs",
|
|
192
|
+
target: ["es2020", "node14"],
|
|
193
|
+
minify: false,
|
|
194
|
+
external: [
|
|
195
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
196
|
+
...Object.keys(packageJson.peerDependencies || {})
|
|
197
|
+
]
|
|
198
|
+
});
|
|
199
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !options.flat) {
|
|
200
|
+
await fs.writeFile(
|
|
281
201
|
path.join(outputDir, "package.json"),
|
|
282
202
|
JSON.stringify({
|
|
283
203
|
type: bundle === "esm" ? "module" : "commonjs",
|
|
284
204
|
sideEffects: packageJson.sideEffects ?? false
|
|
285
205
|
})
|
|
286
|
-
)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
await addLicense({
|
|
209
|
+
bundle,
|
|
210
|
+
license: packageJson.license,
|
|
211
|
+
name: packageJson.name,
|
|
212
|
+
version: packageJson.version,
|
|
213
|
+
outputDir,
|
|
214
|
+
isFlat: !!options.flat,
|
|
215
|
+
packageType
|
|
216
|
+
});
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
} else {
|
|
220
|
+
await Promise.all(
|
|
221
|
+
bundles.map(async (bundle) => {
|
|
222
|
+
const outExtension = getOutExtension(bundle, {
|
|
223
|
+
isFlat: !!options.flat,
|
|
224
|
+
isType: false,
|
|
225
|
+
packageType
|
|
226
|
+
});
|
|
227
|
+
const relativeOutDir = relativeOutDirs[bundle];
|
|
228
|
+
const outputDir = path.join(buildDir, relativeOutDir);
|
|
229
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
230
|
+
const promises = [];
|
|
231
|
+
promises.push(
|
|
232
|
+
babelBuild({
|
|
233
|
+
cwd,
|
|
234
|
+
sourceDir,
|
|
235
|
+
outDir: outputDir,
|
|
236
|
+
babelRuntimeVersion,
|
|
237
|
+
hasLargeFiles,
|
|
238
|
+
bundle,
|
|
239
|
+
verbose,
|
|
240
|
+
optimizeClsx: packageJson.dependencies?.clsx !== void 0 || packageJson.dependencies?.classnames !== void 0,
|
|
241
|
+
removePropTypes: packageJson.dependencies?.["prop-types"] !== void 0,
|
|
242
|
+
pkgVersion: packageJson.version,
|
|
243
|
+
ignores: extraIgnores,
|
|
244
|
+
outExtension,
|
|
245
|
+
reactCompiler: enableReactCompiler ? {
|
|
246
|
+
reactVersion: reactVersion || "latest"
|
|
247
|
+
} : void 0
|
|
248
|
+
})
|
|
287
249
|
);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
250
|
+
if (buildDir !== outputDir && !skipBundlePackageJson && !options.flat) {
|
|
251
|
+
promises.push(
|
|
252
|
+
fs.writeFile(
|
|
253
|
+
path.join(outputDir, "package.json"),
|
|
254
|
+
JSON.stringify({
|
|
255
|
+
type: bundle === "esm" ? "module" : "commonjs",
|
|
256
|
+
sideEffects: packageJson.sideEffects ?? false
|
|
257
|
+
})
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (!options.flat) {
|
|
262
|
+
promises.push(cjsCopy({ from: sourceDir, to: outputDir }));
|
|
263
|
+
}
|
|
264
|
+
await Promise.all(promises);
|
|
265
|
+
await addLicense({
|
|
266
|
+
bundle,
|
|
267
|
+
license: packageJson.license,
|
|
268
|
+
name: packageJson.name,
|
|
269
|
+
version: packageJson.version,
|
|
270
|
+
outputDir,
|
|
271
|
+
isFlat: !!options.flat,
|
|
272
|
+
packageType
|
|
273
|
+
});
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
if (options.flat) {
|
|
277
|
+
await cjsCopy({ from: sourceDir, to: buildDir });
|
|
278
|
+
}
|
|
306
279
|
}
|
|
307
280
|
if (buildTypes) {
|
|
308
|
-
const tsMod = await import("./typescript-
|
|
281
|
+
const tsMod = await import("./typescript-3J237V7Q.js");
|
|
309
282
|
const bundleMap = bundles.map((type) => ({
|
|
310
283
|
type,
|
|
311
284
|
dir: relativeOutDirs[type]
|
|
@@ -336,7 +309,8 @@ var buildCommand = new Command("build").description("Builds the package for publ
|
|
|
336
309
|
outputDir: buildDir,
|
|
337
310
|
addTypes: buildTypes,
|
|
338
311
|
isFlat: !!options.flat,
|
|
339
|
-
packageType
|
|
312
|
+
packageType,
|
|
313
|
+
exportExtensions: options.exportExtensions
|
|
340
314
|
});
|
|
341
315
|
await copyHandler({
|
|
342
316
|
cwd,
|
package/dist/config.d.ts
CHANGED
|
@@ -29,11 +29,18 @@ interface BuildOptions {
|
|
|
29
29
|
tsgo: boolean;
|
|
30
30
|
/** Builds the package in a flat structure without subdirectories for each module type. */
|
|
31
31
|
flat: boolean;
|
|
32
|
+
/** Bundle the package into single files for each format using esbuild (tsup style). */
|
|
33
|
+
bundleSingleFile: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Available extensions for generating exports wildcards.
|
|
36
|
+
* @default [".js", ".mjs", ".cjs"]
|
|
37
|
+
*/
|
|
38
|
+
exportExtensions: string[];
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Helper to provide autocomplete and type checking for the sse-tools config.
|
|
36
43
|
*/
|
|
37
|
-
declare function defineConfig(config: BuildOptions): BuildOptions
|
|
44
|
+
declare function defineConfig(config: Partial<BuildOptions>): Partial<BuildOptions>;
|
|
38
45
|
|
|
39
46
|
export { type BuildOptions, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sse-ui/builder",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Builder By SSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup",
|
|
8
8
|
"prepublish": "npm run build"
|
|
9
9
|
},
|
|
10
|
-
"main": "./
|
|
11
|
-
"files": [
|
|
10
|
+
"main": "./dist/cli.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
12
14
|
"bin": {
|
|
13
|
-
"sse-
|
|
15
|
+
"sse-tools": "./dist/cli.js"
|
|
14
16
|
},
|
|
15
17
|
"exports": {
|
|
16
18
|
"./babel-config": {
|
|
@@ -45,9 +47,11 @@
|
|
|
45
47
|
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
|
46
48
|
"c12": "^4.0.0-beta.3",
|
|
47
49
|
"commander": "^14.0.3",
|
|
50
|
+
"esbuild": "^0.27.4",
|
|
48
51
|
"execa": "^9.6.1",
|
|
49
52
|
"find-workspaces": "^0.3.1",
|
|
50
53
|
"globby": "^16.1.1",
|
|
54
|
+
"jiti": "^2.6.1",
|
|
51
55
|
"minimatch": "^10.2.4",
|
|
52
56
|
"mismatch": "^1.2.0",
|
|
53
57
|
"semver": "^7.7.4"
|
package/bin/sse-tools.js
DELETED