@trebired/bundler 0.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/CHANGELOG.md +13 -0
- package/LICENSE +661 -0
- package/README.md +155 -0
- package/dist/cli/run-cli.d.ts +14 -0
- package/dist/cli/run-cli.d.ts.map +1 -0
- package/dist/cli/run-cli.js +104 -0
- package/dist/cli/run-cli.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +10 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +32 -0
- package/dist/config/index.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/build.d.ts +4 -0
- package/dist/core/build.d.ts.map +1 -0
- package/dist/core/build.js +40 -0
- package/dist/core/build.js.map +1 -0
- package/dist/core/esbuild-options.d.ts +25 -0
- package/dist/core/esbuild-options.d.ts.map +1 -0
- package/dist/core/esbuild-options.js +91 -0
- package/dist/core/esbuild-options.js.map +1 -0
- package/dist/core/shared.d.ts +12 -0
- package/dist/core/shared.d.ts.map +1 -0
- package/dist/core/shared.js +41 -0
- package/dist/core/shared.js.map +1 -0
- package/dist/core/watch.d.ts +4 -0
- package/dist/core/watch.d.ts.map +1 -0
- package/dist/core/watch.js +61 -0
- package/dist/core/watch.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.d.ts +4 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +12 -0
- package/dist/logging.js.map +1 -0
- package/dist/plugins/scss.d.ts +11 -0
- package/dist/plugins/scss.d.ts.map +1 -0
- package/dist/plugins/scss.js +44 -0
- package/dist/plugins/scss.js.map +1 -0
- package/dist/plugins/source-annotations.d.ts +17 -0
- package/dist/plugins/source-annotations.d.ts.map +1 -0
- package/dist/plugins/source-annotations.js +78 -0
- package/dist/plugins/source-annotations.js.map +1 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @trebired/bundler
|
|
2
|
+
|
|
3
|
+
Fast bundler wrapper around `esbuild` with SCSS support, watch mode, and inline source path annotations.
|
|
4
|
+
|
|
5
|
+
`@trebired/bundler` is not a full custom bundler. It keeps the package-owned API small and lets `esbuild` do the heavy lifting, while adding logging aligned with other packages published by Trebired, SCSS compilation through `sass-embedded`, config-driven CLI commands, and optional inline source path comments in generated output.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Runtime support: Bun 1+ and Node.js 18+.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @trebired/bundler
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What It Is For
|
|
16
|
+
|
|
17
|
+
Use this when:
|
|
18
|
+
|
|
19
|
+
- you want a bundling package that fits alongside other packages published by Trebired instead of wiring `esbuild` directly in every project
|
|
20
|
+
- you need one package that handles `tsx`, `jsx`, `ts`, `js`, `scss`, and `css`
|
|
21
|
+
- you want watch mode and config-driven CLI commands without building a separate toolchain wrapper
|
|
22
|
+
- you want generated bundles to optionally include inline comments that point back to the original source file path
|
|
23
|
+
- you want package-owned logs routed through `@trebired/logger-adapter`
|
|
24
|
+
|
|
25
|
+
## What It Does Not Do
|
|
26
|
+
|
|
27
|
+
This package does not:
|
|
28
|
+
|
|
29
|
+
- replace `esbuild`
|
|
30
|
+
- provide a dev server or HMR
|
|
31
|
+
- invent a separate package-specific module graph format
|
|
32
|
+
- manage HTML templates or deployment assets for you
|
|
33
|
+
|
|
34
|
+
If you want a fast bundling wrapper from the Trebired package ecosystem, use this package. If you want a fully custom bundler runtime, this package is intentionally not that.
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { bundle } from "@trebired/bundler";
|
|
40
|
+
|
|
41
|
+
await bundle({
|
|
42
|
+
entries: {
|
|
43
|
+
app: "./src/app.tsx",
|
|
44
|
+
theme: "./src/theme.css",
|
|
45
|
+
},
|
|
46
|
+
outDir: "./dist",
|
|
47
|
+
sourcemap: "external",
|
|
48
|
+
annotateSources: true,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## CLI
|
|
53
|
+
|
|
54
|
+
Create a config module:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { defineBundlerConfig } from "@trebired/bundler";
|
|
58
|
+
|
|
59
|
+
export default defineBundlerConfig({
|
|
60
|
+
entries: {
|
|
61
|
+
app: "./src/app.tsx",
|
|
62
|
+
},
|
|
63
|
+
outDir: "./dist",
|
|
64
|
+
annotateSources: true,
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
trebired-bundler build --config ./bundler.config.mjs
|
|
72
|
+
trebired-bundler watch --config ./bundler.config.mjs
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Source Annotation Comments
|
|
76
|
+
|
|
77
|
+
Set `annotateSources: true` to inject preserved inline comments into bundled output.
|
|
78
|
+
|
|
79
|
+
JavaScript and TypeScript modules are annotated like this:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
/*! @trebired/source: src/app.tsx */
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
CSS and SCSS sources are annotated like this:
|
|
86
|
+
|
|
87
|
+
```css
|
|
88
|
+
/*! @trebired/source: src/styles/site.scss */
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
These comments are emitted with project-relative POSIX-style paths so the generated bundle still points back to the original source file that contributed that segment.
|
|
92
|
+
|
|
93
|
+
## Supported File Types
|
|
94
|
+
|
|
95
|
+
The package supports:
|
|
96
|
+
|
|
97
|
+
- `js`
|
|
98
|
+
- `jsx`
|
|
99
|
+
- `ts`
|
|
100
|
+
- `tsx`
|
|
101
|
+
- `css`
|
|
102
|
+
- `scss`
|
|
103
|
+
|
|
104
|
+
Plain JS, TS, JSX, TSX, and CSS are handled directly by `esbuild`. SCSS is compiled with `sass-embedded` and then passed back into the bundle pipeline as CSS.
|
|
105
|
+
|
|
106
|
+
## Logging
|
|
107
|
+
|
|
108
|
+
Package-owned logs are normalized through `@trebired/logger-adapter`, the same way other packages published by Trebired do it.
|
|
109
|
+
|
|
110
|
+
You can pass:
|
|
111
|
+
|
|
112
|
+
- a logger using the same call shape as other Trebired packages
|
|
113
|
+
- an event sink logger
|
|
114
|
+
- a common logger object
|
|
115
|
+
- a custom `loggerAdapter(logger, event)` for exact output control
|
|
116
|
+
|
|
117
|
+
## Public API
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
type BundlerOptions = {
|
|
121
|
+
entries: string[] | Record<string, string>;
|
|
122
|
+
outDir: string;
|
|
123
|
+
rootDir?: string;
|
|
124
|
+
platform?: "browser" | "node" | "neutral";
|
|
125
|
+
format?: "esm" | "cjs" | "iife";
|
|
126
|
+
target?: string | string[];
|
|
127
|
+
minify?: boolean;
|
|
128
|
+
sourcemap?: boolean | "inline" | "external";
|
|
129
|
+
splitting?: boolean;
|
|
130
|
+
publicPath?: string;
|
|
131
|
+
external?: string[];
|
|
132
|
+
define?: Record<string, string>;
|
|
133
|
+
clean?: boolean;
|
|
134
|
+
annotateSources?: boolean;
|
|
135
|
+
logger?: unknown;
|
|
136
|
+
loggerAdapter?: (logger: unknown, event: unknown) => unknown;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
declare function bundle(options: BundlerOptions): Promise<{
|
|
140
|
+
outputs: string[];
|
|
141
|
+
warnings: number;
|
|
142
|
+
metafile?: object;
|
|
143
|
+
durationMs: number;
|
|
144
|
+
}>;
|
|
145
|
+
|
|
146
|
+
declare function watch(options: BundlerOptions): Promise<{
|
|
147
|
+
rebuild(): Promise<{
|
|
148
|
+
outputs: string[];
|
|
149
|
+
warnings: number;
|
|
150
|
+
metafile?: object;
|
|
151
|
+
durationMs: number;
|
|
152
|
+
}>;
|
|
153
|
+
dispose(): Promise<void>;
|
|
154
|
+
}>;
|
|
155
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
type CliRunOptions = {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
stderr?: (text: string) => void;
|
|
5
|
+
stdout?: (text: string) => void;
|
|
6
|
+
watchDurationMs?: number;
|
|
7
|
+
};
|
|
8
|
+
type CliRunResult = {
|
|
9
|
+
exitCode: number;
|
|
10
|
+
};
|
|
11
|
+
declare function runCli(argv: string[], options?: CliRunOptions): Promise<CliRunResult>;
|
|
12
|
+
export { runCli };
|
|
13
|
+
export type { CliRunOptions, CliRunResult };
|
|
14
|
+
//# sourceMappingURL=run-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cli.d.ts","sourceRoot":"","sources":["../../src/cli/run-cli.ts"],"names":[],"mappings":";AAQA,KAAK,aAAa,GAAG;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA4DF,iBAAe,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAkDxF;AAQD,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { loadBundlerConfigModule } from "../config/index.js";
|
|
4
|
+
import { bundle } from "../core/build.js";
|
|
5
|
+
import { watch } from "../core/watch.js";
|
|
6
|
+
function renderHelp() {
|
|
7
|
+
return [
|
|
8
|
+
"Usage: trebired-bundler <command> --config <path>",
|
|
9
|
+
"",
|
|
10
|
+
"Commands:",
|
|
11
|
+
" build run a one-shot bundle using the config module",
|
|
12
|
+
" watch run bundle watch mode using the config module",
|
|
13
|
+
"",
|
|
14
|
+
"Config:",
|
|
15
|
+
" --config <path> must point to a module that default-exports the config object.",
|
|
16
|
+
"",
|
|
17
|
+
].join("\n");
|
|
18
|
+
}
|
|
19
|
+
function parseArgs(args) {
|
|
20
|
+
let configPath;
|
|
21
|
+
const extra = [];
|
|
22
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
23
|
+
const arg = args[index];
|
|
24
|
+
if (arg === "--config") {
|
|
25
|
+
const value = args[index + 1];
|
|
26
|
+
if (!value) {
|
|
27
|
+
throw new Error("Missing value for --config");
|
|
28
|
+
}
|
|
29
|
+
configPath = value;
|
|
30
|
+
index += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
extra.push(arg);
|
|
34
|
+
}
|
|
35
|
+
return { configPath, extra };
|
|
36
|
+
}
|
|
37
|
+
async function waitForStop(session, durationMs) {
|
|
38
|
+
if (typeof durationMs === "number") {
|
|
39
|
+
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
40
|
+
await session.dispose();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await new Promise((resolve) => {
|
|
44
|
+
const stop = async () => {
|
|
45
|
+
process.off("SIGINT", stop);
|
|
46
|
+
process.off("SIGTERM", stop);
|
|
47
|
+
await session.dispose();
|
|
48
|
+
resolve();
|
|
49
|
+
};
|
|
50
|
+
process.on("SIGINT", stop);
|
|
51
|
+
process.on("SIGTERM", stop);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function runCli(argv, options = {}) {
|
|
55
|
+
const cwd = options.cwd ?? process.cwd();
|
|
56
|
+
const stdout = options.stdout ?? ((text) => process.stdout.write(text));
|
|
57
|
+
const stderr = options.stderr ?? ((text) => process.stderr.write(text));
|
|
58
|
+
const [command, ...rest] = argv;
|
|
59
|
+
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
60
|
+
stdout(`${renderHelp()}\n`);
|
|
61
|
+
return { exitCode: 0 };
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const parsed = parseArgs(rest);
|
|
65
|
+
if (parsed.extra.length > 0) {
|
|
66
|
+
throw new Error(`Unexpected arguments: ${parsed.extra.join(" ")}`);
|
|
67
|
+
}
|
|
68
|
+
if (!parsed.configPath) {
|
|
69
|
+
throw new Error("Missing required --config <path> option");
|
|
70
|
+
}
|
|
71
|
+
const { config } = await loadBundlerConfigModule(cwd, parsed.configPath);
|
|
72
|
+
if (command === "build") {
|
|
73
|
+
const result = await bundle({
|
|
74
|
+
...config,
|
|
75
|
+
rootDir: config.rootDir ?? cwd,
|
|
76
|
+
});
|
|
77
|
+
stdout(`${JSON.stringify(result)}\n`);
|
|
78
|
+
return { exitCode: 0 };
|
|
79
|
+
}
|
|
80
|
+
if (command === "watch") {
|
|
81
|
+
const session = await watch({
|
|
82
|
+
...config,
|
|
83
|
+
rootDir: config.rootDir ?? cwd,
|
|
84
|
+
});
|
|
85
|
+
stdout("Watching for changes.\n");
|
|
86
|
+
await waitForStop(session, options.watchDurationMs);
|
|
87
|
+
return { exitCode: 0 };
|
|
88
|
+
}
|
|
89
|
+
stderr(`Unknown command: ${command}\n`);
|
|
90
|
+
stderr(`${renderHelp()}\n`);
|
|
91
|
+
return { exitCode: 1 };
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
stderr(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
95
|
+
return { exitCode: 1 };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const entryPath = process.argv[1] ? pathToFileURL(process.argv[1]).href : null;
|
|
99
|
+
if (entryPath && import.meta.url === entryPath) {
|
|
100
|
+
const result = await runCli(process.argv.slice(2));
|
|
101
|
+
process.exitCode = result.exitCode;
|
|
102
|
+
}
|
|
103
|
+
export { runCli };
|
|
104
|
+
//# sourceMappingURL=run-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cli.js","sourceRoot":"","sources":["../../src/cli/run-cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAazC,SAAS,UAAU;IACjB,OAAO;QACL,mDAAmD;QACnD,EAAE;QACF,WAAW;QACX,+DAA+D;QAC/D,+DAA+D;QAC/D,EAAE;QACF,SAAS;QACT,kFAAkF;QAClF,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,UAA8B,CAAC;IACnC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAExB,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAC9B,IAAI,CAAC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EAAE,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAQ1C,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { runCli } from "./cli/run-cli.js";
|
|
4
|
+
const entryPath = process.argv[1] ? pathToFileURL(process.argv[1]).href : null;
|
|
5
|
+
if (entryPath && import.meta.url === entryPath) {
|
|
6
|
+
const result = await runCli(process.argv.slice(2));
|
|
7
|
+
process.exitCode = result.exitCode;
|
|
8
|
+
}
|
|
9
|
+
export { runCli };
|
|
10
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BundlerOptions, LoadedBundlerConfig } from "../types.js";
|
|
2
|
+
declare function defineBundlerConfig(config: BundlerOptions): BundlerOptions;
|
|
3
|
+
declare function loadBundlerConfigModule(projectRoot: string, configPath: string): Promise<LoadedBundlerConfig>;
|
|
4
|
+
export { defineBundlerConfig, loadBundlerConfigModule };
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvE,iBAAS,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAEnE;AAWD,iBAAe,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAkB5G;AAED,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
function defineBundlerConfig(config) {
|
|
5
|
+
return config;
|
|
6
|
+
}
|
|
7
|
+
async function pathExists(filePath) {
|
|
8
|
+
try {
|
|
9
|
+
await fs.access(filePath);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function loadBundlerConfigModule(projectRoot, configPath) {
|
|
17
|
+
const resolvedPath = path.resolve(projectRoot, configPath);
|
|
18
|
+
if (!await pathExists(resolvedPath)) {
|
|
19
|
+
throw new Error(`Config module was not found: ${resolvedPath}`);
|
|
20
|
+
}
|
|
21
|
+
const imported = await import(pathToFileURL(resolvedPath).href);
|
|
22
|
+
const config = imported.default;
|
|
23
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
24
|
+
throw new Error("Config module must default-export a config object");
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
config: config,
|
|
28
|
+
configPath: resolvedPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { defineBundlerConfig, loadBundlerConfigModule };
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,SAAS,mBAAmB,CAAC,MAAsB;IACjD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,WAAmB,EAAE,UAAkB;IAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAE3D,IAAI,CAAC,MAAM,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,gCAAgC,YAAY,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAkB,CAAC;IAE3C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAwB;QAChC,UAAU,EAAE,YAAY;KACzB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB,YAAY,CAAC;AACpC,QAAA,MAAM,oBAAoB,sBAAsB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/core/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAItE,iBAAe,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkC1E;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { build as runEsbuild } from "esbuild";
|
|
2
|
+
import { logPackageInitialized } from "@trebired/logger-adapter";
|
|
3
|
+
import { BUNDLER_LOG_GROUP, BUNDLER_PACKAGE_NAME } from "../constants.js";
|
|
4
|
+
import { resolveLogger } from "../logging.js";
|
|
5
|
+
import { createEsbuildOptions, normalizeBundlerOptions } from "./esbuild-options.js";
|
|
6
|
+
import { cleanOutDir, formatFailure, logWarnings, toBuildResult } from "./shared.js";
|
|
7
|
+
async function bundle(options) {
|
|
8
|
+
const normalized = normalizeBundlerOptions(options || {});
|
|
9
|
+
const logger = resolveLogger(normalized.logger, normalized.loggerAdapter);
|
|
10
|
+
logPackageInitialized({
|
|
11
|
+
adapter: normalized.loggerAdapter,
|
|
12
|
+
fallback: "console",
|
|
13
|
+
group: BUNDLER_LOG_GROUP,
|
|
14
|
+
logger: normalized.logger,
|
|
15
|
+
source: BUNDLER_PACKAGE_NAME,
|
|
16
|
+
});
|
|
17
|
+
if (normalized.clean) {
|
|
18
|
+
logger.info("build", `clean :: ${normalized.outDir}`);
|
|
19
|
+
await cleanOutDir(normalized.outDir);
|
|
20
|
+
}
|
|
21
|
+
logger.info("build", "start");
|
|
22
|
+
const startedAt = Date.now();
|
|
23
|
+
try {
|
|
24
|
+
const result = await runEsbuild(createEsbuildOptions(normalized, logger));
|
|
25
|
+
logWarnings(logger, result.warnings);
|
|
26
|
+
const summary = toBuildResult({
|
|
27
|
+
result,
|
|
28
|
+
rootDir: normalized.rootDir,
|
|
29
|
+
startedAt,
|
|
30
|
+
});
|
|
31
|
+
logger.info("build", `complete :: outputs=${summary.outputs.length} warnings=${summary.warnings}`);
|
|
32
|
+
return summary;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
logger.fail("build", `failed :: ${formatFailure(error)}`);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export { bundle };
|
|
40
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/core/build.ts"],"names":[],"mappings":"AAAA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QAAQ,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,aAAa,CAAC;YAC5B,MAAM;YACN,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,SAAS;SACV,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,uBAAuB,OAAO,CAAC,OAAO,CAAC,MAAM,aAAa,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnG,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BuildOptions } from "esbuild";
|
|
2
|
+
import type { BundlerOptions, NormalizedBundlerLogger } from "../types.js";
|
|
3
|
+
type NormalizedBundlerOptions = {
|
|
4
|
+
annotateSources: boolean;
|
|
5
|
+
clean: boolean;
|
|
6
|
+
define?: Record<string, string>;
|
|
7
|
+
entries: string[] | Record<string, string>;
|
|
8
|
+
external?: string[];
|
|
9
|
+
format?: BundlerOptions["format"];
|
|
10
|
+
logger?: BundlerOptions["logger"];
|
|
11
|
+
loggerAdapter?: BundlerOptions["loggerAdapter"];
|
|
12
|
+
minify: boolean;
|
|
13
|
+
outDir: string;
|
|
14
|
+
platform?: BundlerOptions["platform"];
|
|
15
|
+
publicPath?: string;
|
|
16
|
+
rootDir: string;
|
|
17
|
+
sourcemap?: BundlerOptions["sourcemap"];
|
|
18
|
+
splitting: boolean;
|
|
19
|
+
target?: string | string[];
|
|
20
|
+
};
|
|
21
|
+
declare function normalizeBundlerOptions(options: BundlerOptions): NormalizedBundlerOptions;
|
|
22
|
+
declare function createEsbuildOptions(options: NormalizedBundlerOptions, logger: NormalizedBundlerLogger): BuildOptions;
|
|
23
|
+
export { createEsbuildOptions, normalizeBundlerOptions };
|
|
24
|
+
export type { NormalizedBundlerOptions };
|
|
25
|
+
//# sourceMappingURL=esbuild-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-options.d.ts","sourceRoot":"","sources":["../../src/core/esbuild-options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3E,KAAK,wBAAwB,GAAG;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAClC,aAAa,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;IACxC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B,CAAC;AA4BF,iBAAS,uBAAuB,CAAC,OAAO,EAAE,cAAc,GAAG,wBAAwB,CA6BlF;AAED,iBAAS,oBAAoB,CAC3B,OAAO,EAAE,wBAAwB,EACjC,MAAM,EAAE,uBAAuB,GAC9B,YAAY,CAyCd;AAED,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createScssPlugin } from "../plugins/scss.js";
|
|
3
|
+
import { createSourceAnnotationsPlugin } from "../plugins/source-annotations.js";
|
|
4
|
+
function normalizeEntries(entries) {
|
|
5
|
+
if (Array.isArray(entries)) {
|
|
6
|
+
const filtered = entries.map((value) => String(value || "").trim()).filter(Boolean);
|
|
7
|
+
if (!filtered.length) {
|
|
8
|
+
throw new Error("bundler-missing-entries");
|
|
9
|
+
}
|
|
10
|
+
return filtered;
|
|
11
|
+
}
|
|
12
|
+
if (!entries || typeof entries !== "object") {
|
|
13
|
+
throw new Error("bundler-missing-entries");
|
|
14
|
+
}
|
|
15
|
+
const normalized = Object.fromEntries(Object.entries(entries)
|
|
16
|
+
.map(([key, value]) => [String(key || "").trim(), String(value || "").trim()])
|
|
17
|
+
.filter(([key, value]) => Boolean(key && value)));
|
|
18
|
+
if (Object.keys(normalized).length === 0) {
|
|
19
|
+
throw new Error("bundler-missing-entries");
|
|
20
|
+
}
|
|
21
|
+
return normalized;
|
|
22
|
+
}
|
|
23
|
+
function normalizeBundlerOptions(options) {
|
|
24
|
+
const rootDir = path.resolve(String(options.rootDir || "").trim() || process.cwd());
|
|
25
|
+
const outDir = String(options.outDir || "").trim();
|
|
26
|
+
if (!outDir) {
|
|
27
|
+
throw new Error("bundler-missing-out-dir");
|
|
28
|
+
}
|
|
29
|
+
const resolvedOutDir = path.resolve(rootDir, outDir);
|
|
30
|
+
const entries = normalizeEntries(options.entries);
|
|
31
|
+
return {
|
|
32
|
+
annotateSources: Boolean(options.annotateSources),
|
|
33
|
+
clean: options.clean !== false,
|
|
34
|
+
define: options.define,
|
|
35
|
+
entries,
|
|
36
|
+
external: options.external,
|
|
37
|
+
format: options.format,
|
|
38
|
+
logger: options.logger,
|
|
39
|
+
loggerAdapter: options.loggerAdapter,
|
|
40
|
+
minify: Boolean(options.minify),
|
|
41
|
+
outDir: resolvedOutDir,
|
|
42
|
+
platform: options.platform,
|
|
43
|
+
publicPath: options.publicPath,
|
|
44
|
+
rootDir,
|
|
45
|
+
sourcemap: options.sourcemap,
|
|
46
|
+
splitting: Boolean(options.splitting),
|
|
47
|
+
target: options.target,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createEsbuildOptions(options, logger) {
|
|
51
|
+
if (options.annotateSources) {
|
|
52
|
+
logger.info("annotate", "inline source annotations enabled");
|
|
53
|
+
}
|
|
54
|
+
logger.info("scss", "scss compiler enabled");
|
|
55
|
+
return {
|
|
56
|
+
absWorkingDir: options.rootDir,
|
|
57
|
+
bundle: true,
|
|
58
|
+
define: options.define,
|
|
59
|
+
entryPoints: options.entries,
|
|
60
|
+
external: options.external,
|
|
61
|
+
format: options.format,
|
|
62
|
+
legalComments: options.annotateSources ? "inline" : undefined,
|
|
63
|
+
logLevel: "silent",
|
|
64
|
+
metafile: true,
|
|
65
|
+
minify: options.minify,
|
|
66
|
+
outbase: options.rootDir,
|
|
67
|
+
outdir: options.outDir,
|
|
68
|
+
platform: options.platform,
|
|
69
|
+
plugins: [
|
|
70
|
+
createScssPlugin({
|
|
71
|
+
annotateSources: options.annotateSources,
|
|
72
|
+
logger,
|
|
73
|
+
rootDir: options.rootDir,
|
|
74
|
+
sourcemapEnabled: Boolean(options.sourcemap),
|
|
75
|
+
}),
|
|
76
|
+
...(options.annotateSources ? [
|
|
77
|
+
createSourceAnnotationsPlugin({
|
|
78
|
+
logger,
|
|
79
|
+
rootDir: options.rootDir,
|
|
80
|
+
}),
|
|
81
|
+
] : []),
|
|
82
|
+
],
|
|
83
|
+
publicPath: options.publicPath,
|
|
84
|
+
sourcemap: options.sourcemap,
|
|
85
|
+
splitting: options.splitting,
|
|
86
|
+
target: options.target,
|
|
87
|
+
write: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export { createEsbuildOptions, normalizeBundlerOptions };
|
|
91
|
+
//# sourceMappingURL=esbuild-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-options.js","sourceRoot":"","sources":["../../src/core/esbuild-options.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AAsBjF,SAAS,gBAAgB,CAAC,OAAkC;IAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpF,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;SAC7E,MAAM,CAA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5B,MAAM;oBACN,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB,CAAC;aACH,CAAC,CAAC,CAAC,EAAE,CAAC;SACR;QACD,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,IAAI;KACZ,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BuildResult, Message } from "esbuild";
|
|
2
|
+
import type { BundlerBuildResult, NormalizedBundlerLogger } from "../types.js";
|
|
3
|
+
declare function logWarnings(logger: NormalizedBundlerLogger, warnings: Message[]): void;
|
|
4
|
+
declare function toBuildResult(args: {
|
|
5
|
+
result: BuildResult<any>;
|
|
6
|
+
rootDir: string;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
}): BundlerBuildResult;
|
|
9
|
+
declare function cleanOutDir(outDir: string): Promise<void>;
|
|
10
|
+
declare function formatFailure(error: unknown): string;
|
|
11
|
+
export { cleanOutDir, formatFailure, logWarnings, toBuildResult };
|
|
12
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/core/shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAU/E,iBAAS,WAAW,CAAC,MAAM,EAAE,uBAAuB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAI/E;AAUD,iBAAS,aAAa,CAAC,IAAI,EAAE;IAC3B,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,kBAAkB,CAOrB;AAED,iBAAe,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExD;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO7C;AAED,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function formatEsbuildMessage(message) {
|
|
4
|
+
const location = message.location
|
|
5
|
+
? `${message.location.file}:${message.location.line}:${message.location.column}`
|
|
6
|
+
: "";
|
|
7
|
+
const pieces = [location, message.text].filter(Boolean);
|
|
8
|
+
return pieces.join(" :: ");
|
|
9
|
+
}
|
|
10
|
+
function logWarnings(logger, warnings) {
|
|
11
|
+
for (const warning of warnings) {
|
|
12
|
+
logger.warn("build", formatEsbuildMessage(warning));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function resolveOutputs(result, rootDir) {
|
|
16
|
+
if (!result.metafile)
|
|
17
|
+
return [];
|
|
18
|
+
return Object.keys(result.metafile.outputs)
|
|
19
|
+
.map((value) => path.isAbsolute(value) ? value : path.resolve(rootDir, value))
|
|
20
|
+
.sort();
|
|
21
|
+
}
|
|
22
|
+
function toBuildResult(args) {
|
|
23
|
+
return {
|
|
24
|
+
outputs: resolveOutputs(args.result, args.rootDir),
|
|
25
|
+
warnings: args.result.warnings.length,
|
|
26
|
+
metafile: args.result.metafile,
|
|
27
|
+
durationMs: Date.now() - args.startedAt,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function cleanOutDir(outDir) {
|
|
31
|
+
await fs.rm(outDir, { force: true, recursive: true });
|
|
32
|
+
}
|
|
33
|
+
function formatFailure(error) {
|
|
34
|
+
if (error && typeof error === "object" && Array.isArray(error.errors)) {
|
|
35
|
+
const errors = error.errors;
|
|
36
|
+
return errors.map(formatEsbuildMessage).join(" | ");
|
|
37
|
+
}
|
|
38
|
+
return error instanceof Error ? error.message : String(error);
|
|
39
|
+
}
|
|
40
|
+
export { cleanOutDir, formatFailure, logWarnings, toBuildResult };
|
|
41
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/core/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,SAAS,oBAAoB,CAAC,OAAyB;IACrD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ;QAC/B,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE;QAChF,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,WAAW,CAAC,MAA+B,EAAE,QAAmB;IACvE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAAwB,EAAE,OAAe;IAC/D,IAAI,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAC;IAEhC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;SACxC,GAAG,CAAC,CAAC,KAAK,EAA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