x4js 2.3.4 → 2.3.5

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.
@@ -4,6 +4,7 @@ import { sassPlugin } from "esbuild-sass-plugin";
4
4
  import { lessPlugin } from "./less-plugin.mjs";
5
5
  import { copyPlugin } from "./copy-plugin.mjs";
6
6
  import { rawFilePlugin } from "./rawfile-plugin.mjs";
7
+ import { diagnosticsPlugin } from "./diagnostic.mjs";
7
8
 
8
9
  const cliDir = path.dirname(fileURLToPath(import.meta.url));
9
10
  const devClient = path.join(cliDir, "dev-client.js");
@@ -26,6 +27,7 @@ export function createBuildOptions(config, mode) {
26
27
  charset: "utf8",
27
28
  keepNames: true,
28
29
  platform: "browser",
30
+ logLevel: "silent",
29
31
  format: "iife",
30
32
  target: "es2020",
31
33
  minify: production,
@@ -58,6 +60,9 @@ export function createBuildOptions(config, mode) {
58
60
  }),
59
61
  lessPlugin(config.root),
60
62
  copyPlugin(config, { dev }),
63
+
64
+ //last
65
+ ...(dev ? [diagnosticsPlugin()] : []),
61
66
  ],
62
67
  };
63
68
 
package/cli/build.mjs CHANGED
@@ -4,6 +4,7 @@ import esbuild from "esbuild";
4
4
  import { loadConfig } from "./config.mjs";
5
5
  import { createBuildOptions } from "./build-options.mjs";
6
6
  import { info, success } from "./log.mjs";
7
+ import { printBuildError} from "./diagnostic-plugin.mjs";
7
8
 
8
9
  export async function build(argv = [], root = process.cwd()) {
9
10
  const { values, positionals } = parseArgs({
@@ -28,6 +29,19 @@ export async function build(argv = [], root = process.cwd()) {
28
29
  await fs.mkdir(config.outdir, { recursive: true });
29
30
 
30
31
  const started = performance.now();
31
- await esbuild.build(createBuildOptions(config, mode));
32
- success("built", `${Math.round(performance.now() - started)}ms`);
32
+ const options = createBuildOptions(config, mode);
33
+
34
+ try {
35
+ const result = await esbuild.build(options);
36
+ if (result.warnings.length)
37
+ await printWarnings(result.warnings);
38
+
39
+ logSuccess(`built ${Date.now() - start}ms`);
40
+ }
41
+ catch (error) {
42
+ await printBuildError(error);
43
+ process.exitCode = 1;
44
+ }
45
+
46
+ success("built", `${Math.round(performance.now() - started)}ms`);
33
47
  }
@@ -0,0 +1,73 @@
1
+ import * as esbuild from "esbuild";
2
+ import { styleText } from "node:util";
3
+
4
+ function useColors() {
5
+ return process.stderr.isTTY && !process.env.NO_COLOR;
6
+ }
7
+
8
+ async function format(messages, kind) {
9
+ if (!messages?.length)
10
+ return [];
11
+
12
+ return esbuild.formatMessages(messages, {
13
+ kind,
14
+ color: useColors(),
15
+ terminalWidth: process.stderr.columns || 100,
16
+ });
17
+ }
18
+
19
+ export async function printWarnings(messages) {
20
+ const lines = await format(messages, "warning");
21
+
22
+ for (const line of lines)
23
+ process.stderr.write(line);
24
+ }
25
+
26
+ export async function printErrors(messages) {
27
+ if (!messages?.length)
28
+ return;
29
+
30
+ console.error(styleText("red", "\nbuild failed\n"));
31
+
32
+ const lines = await format(messages, "error");
33
+
34
+ for (const line of lines)
35
+ process.stderr.write(line);
36
+ }
37
+
38
+ export async function printBuildError(error) {
39
+ if (error?.errors?.length) {
40
+ await printErrors(error.errors);
41
+
42
+ if (error.warnings?.length)
43
+ await printWarnings(error.warnings);
44
+
45
+ return;
46
+ }
47
+
48
+ // Erreur x4 / Node, pas une erreur esbuild
49
+ console.error(
50
+ styleText(
51
+ "red",
52
+ error instanceof Error ? error.message : String(error)
53
+ )
54
+ );
55
+ }
56
+
57
+ export function diagnosticsPlugin() {
58
+ return {
59
+ name: "x4-diagnostics",
60
+
61
+ setup(build) {
62
+ build.onEnd(async (result) => {
63
+ if (result.errors.length) {
64
+ await printErrors(result.errors);
65
+ return;
66
+ }
67
+
68
+ if (result.warnings.length)
69
+ await printWarnings(result.warnings);
70
+ });
71
+ },
72
+ };
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x4js",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
4
4
  "type": "module",
5
5
  "main": "src/x4.ts",
6
6
  "module": "src/x4.ts",