@trebired/bundler 0.1.0 → 0.3.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +168 -9
  3. package/dist/core/build.d.ts.map +1 -1
  4. package/dist/core/build.js +11 -2
  5. package/dist/core/build.js.map +1 -1
  6. package/dist/core/derive-manifest.d.ts +10 -0
  7. package/dist/core/derive-manifest.d.ts.map +1 -0
  8. package/dist/core/derive-manifest.js +150 -0
  9. package/dist/core/derive-manifest.js.map +1 -0
  10. package/dist/core/discovery-watch.d.ts +9 -0
  11. package/dist/core/discovery-watch.d.ts.map +1 -0
  12. package/dist/core/discovery-watch.js +71 -0
  13. package/dist/core/discovery-watch.js.map +1 -0
  14. package/dist/core/discovery.d.ts +30 -0
  15. package/dist/core/discovery.d.ts.map +1 -0
  16. package/dist/core/discovery.js +257 -0
  17. package/dist/core/discovery.js.map +1 -0
  18. package/dist/core/esbuild-options.d.ts +7 -2
  19. package/dist/core/esbuild-options.d.ts.map +1 -1
  20. package/dist/core/esbuild-options.js +18 -22
  21. package/dist/core/esbuild-options.js.map +1 -1
  22. package/dist/core/manifest.d.ts +15 -0
  23. package/dist/core/manifest.d.ts.map +1 -0
  24. package/dist/core/manifest.js +31 -0
  25. package/dist/core/manifest.js.map +1 -0
  26. package/dist/core/shared.d.ts +6 -2
  27. package/dist/core/shared.d.ts.map +1 -1
  28. package/dist/core/shared.js +14 -2
  29. package/dist/core/shared.js.map +1 -1
  30. package/dist/core/watch.d.ts.map +1 -1
  31. package/dist/core/watch.js +125 -14
  32. package/dist/core/watch.js.map +1 -1
  33. package/dist/index.d.ts +3 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/plugins/source-annotations.js +1 -1
  38. package/dist/plugins/source-annotations.js.map +1 -1
  39. package/dist/plugins/virtual-entries.d.ts +11 -0
  40. package/dist/plugins/virtual-entries.d.ts.map +1 -0
  41. package/dist/plugins/virtual-entries.js +32 -0
  42. package/dist/plugins/virtual-entries.js.map +1 -0
  43. package/dist/types.d.ts +58 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to `@trebired/bundler` will be documented here.
4
4
 
5
5
  This project follows semantic versioning once published.
6
6
 
7
+ ## 0.3.0
8
+
9
+ - Changed inline source annotations from `@trebired/source:` to neutral `source:` comments.
10
+ - Added `virtualEntries` for in-memory generated entry modules.
11
+ - Added `deriveManifest()` for stable entry-centric asset graph derivation from esbuild metafiles.
12
+ - Added watch lifecycle hooks through `onRebuilt()` and `onEntrySetChanged()`.
13
+ - Aligned written manifest output with the same derived manifest graph used by runtime helpers.
14
+
15
+ ## 0.2.0
16
+
17
+ - Added built-in entry discovery so the package can walk source directories and generate entry lists itself.
18
+ - Added source-tree watching for discovered entries, including new and removed matching files during watch mode.
19
+ - Added optional manifest writing that records resolved entries and generated outputs.
20
+ - Made `entries` optional when `discover` is configured.
21
+
7
22
  ## 0.1.0
8
23
 
9
24
  - Added the `bundle()` and `watch()` APIs for fast esbuild-backed bundling.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Fast bundler wrapper around `esbuild` with SCSS support, watch mode, and inline source path annotations.
4
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.
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`, built-in source walking, config-driven CLI commands, virtual entry modules, derived manifest helpers, and inline source path comments in generated output.
6
6
 
7
7
  ## Install
8
8
 
@@ -18,7 +18,13 @@ Use this when:
18
18
 
19
19
  - you want a bundling package that fits alongside other packages published by Trebired instead of wiring `esbuild` directly in every project
20
20
  - you need one package that handles `tsx`, `jsx`, `ts`, `js`, `scss`, and `css`
21
+ - you want the package to discover entry files by walking your source tree
22
+ - you want in-memory generated entry modules without writing temp files
21
23
  - you want watch mode and config-driven CLI commands without building a separate toolchain wrapper
24
+ - you want newly created matching files to join the build without external entry regeneration code
25
+ - you want a manifest describing resolved entries and generated outputs
26
+ - you want a stable helper for turning esbuild metafiles into runtime asset graphs
27
+ - you want rebuild hooks instead of scraping logger text
22
28
  - you want generated bundles to optionally include inline comments that point back to the original source file path
23
29
  - you want package-owned logs routed through `@trebired/logger-adapter`
24
30
 
@@ -39,13 +45,20 @@ If you want a fast bundling wrapper from the Trebired package ecosystem, use thi
39
45
  import { bundle } from "@trebired/bundler";
40
46
 
41
47
  await bundle({
42
- entries: {
43
- app: "./src/app.tsx",
44
- theme: "./src/theme.css",
48
+ discover: {
49
+ dir: "./src",
50
+ include: ["app.tsx", "theme.css"],
51
+ },
52
+ virtualEntries: {
53
+ "entry-server": `
54
+ import { message } from "./src/lib/message";
55
+ export const rendered = message.toUpperCase();
56
+ `,
45
57
  },
46
58
  outDir: "./dist",
47
59
  sourcemap: "external",
48
60
  annotateSources: true,
61
+ manifest: true,
49
62
  });
50
63
  ```
51
64
 
@@ -57,11 +70,13 @@ Create a config module:
57
70
  import { defineBundlerConfig } from "@trebired/bundler";
58
71
 
59
72
  export default defineBundlerConfig({
60
- entries: {
61
- app: "./src/app.tsx",
73
+ discover: {
74
+ dir: "./src/frontend",
75
+ include: ["**/*.tsx", "**/*.scss", "**/*.css"],
62
76
  },
63
77
  outDir: "./dist",
64
78
  annotateSources: true,
79
+ manifest: true,
65
80
  });
66
81
  ```
67
82
 
@@ -72,6 +87,113 @@ trebired-bundler build --config ./bundler.config.mjs
72
87
  trebired-bundler watch --config ./bundler.config.mjs
73
88
  ```
74
89
 
90
+ ## Discovery And Walking
91
+
92
+ Set `discover` when you want `@trebired/bundler` to walk the source tree and build the entry list itself.
93
+
94
+ ```ts
95
+ await bundle({
96
+ discover: {
97
+ dir: "./src/frontend",
98
+ include: ["**/*.tsx", "global/**/*.scss"],
99
+ exclude: ["**/*.test.tsx"],
100
+ ignoreDirs: ["legacy"],
101
+ namePrefix: "frontend",
102
+ },
103
+ outDir: "./dist",
104
+ });
105
+ ```
106
+
107
+ The package:
108
+
109
+ - walks the configured directory recursively
110
+ - matches files by extension plus optional include and exclude patterns
111
+ - derives entry names from relative paths
112
+ - rebuilds the entry list during watch mode when matching files are added or removed
113
+
114
+ You can combine manual `entries` with `discover`. If both resolve the same entry name to different files, the build fails so the collision is explicit.
115
+
116
+ ## Manifest
117
+
118
+ Set `manifest: true` to write `dist/bundler-manifest.json`, or pass `manifest: { file: "custom-name.json" }` to choose a different path inside `outDir`.
119
+
120
+ The manifest contains:
121
+
122
+ - resolved entries
123
+ - whether each entry came from `manual` config or `discover`
124
+ - generated output files
125
+
126
+ If you want a runtime-friendly asset graph directly in app code, call `deriveManifest()` on the returned `metafile`:
127
+
128
+ ```ts
129
+ import { bundle, deriveManifest } from "@trebired/bundler";
130
+
131
+ const result = await bundle({
132
+ entries: {
133
+ app: "./src/app.tsx",
134
+ },
135
+ outDir: "./dist",
136
+ });
137
+
138
+ const manifest = deriveManifest(result.metafile!, {
139
+ rootDir: process.cwd(),
140
+ outDir: "./dist",
141
+ });
142
+ ```
143
+
144
+ The helper returns:
145
+
146
+ - `entries`: entry output -> JS/CSS/import graph
147
+ - `chunks`: shared output -> import/CSS graph
148
+ - `allOutputs`: flat normalized output index
149
+
150
+ ## Virtual Entries
151
+
152
+ Use `virtualEntries` when you want generated entry modules without writing temporary files:
153
+
154
+ ```ts
155
+ await bundle({
156
+ entries: {
157
+ app: "./src/app.tsx",
158
+ },
159
+ virtualEntries: {
160
+ "entry-server": `
161
+ import { message } from "./src/lib/message";
162
+ export const rendered = message.toUpperCase();
163
+ `,
164
+ "global.client": `
165
+ import "./src/styles/site.scss";
166
+ console.log("global-client");
167
+ `,
168
+ },
169
+ outDir: "./dist",
170
+ });
171
+ ```
172
+
173
+ Virtual entries are loaded as TypeScript/ESM modules and resolve relative imports from `rootDir`.
174
+
175
+ ## Watch Hooks
176
+
177
+ Use watch hooks when app code needs clean lifecycle points after rebuilds:
178
+
179
+ ```ts
180
+ await watch({
181
+ discover: {
182
+ dir: "./src/pages",
183
+ include: ["**/*.tsx"],
184
+ },
185
+ outDir: "./dist",
186
+ async onEntrySetChanged(entries) {
187
+ console.log(entries);
188
+ },
189
+ async onRebuilt(result) {
190
+ console.log(result.outputs);
191
+ },
192
+ });
193
+ ```
194
+
195
+ `onEntrySetChanged()` runs only when the resolved entry set changes. `onRebuilt()` runs after a successful rebuild result is assembled.
196
+
75
197
  ## Source Annotation Comments
76
198
 
77
199
  Set `annotateSources: true` to inject preserved inline comments into bundled output.
@@ -79,13 +201,13 @@ Set `annotateSources: true` to inject preserved inline comments into bundled out
79
201
  JavaScript and TypeScript modules are annotated like this:
80
202
 
81
203
  ```js
82
- /*! @trebired/source: src/app.tsx */
204
+ /*! source: src/app.tsx */
83
205
  ```
84
206
 
85
207
  CSS and SCSS sources are annotated like this:
86
208
 
87
209
  ```css
88
- /*! @trebired/source: src/styles/site.scss */
210
+ /*! source: src/styles/site.scss */
89
211
  ```
90
212
 
91
213
  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.
@@ -118,7 +240,23 @@ You can pass:
118
240
 
119
241
  ```ts
120
242
  type BundlerOptions = {
121
- entries: string[] | Record<string, string>;
243
+ entries?: string[] | Record<string, string>;
244
+ discover?: {
245
+ dir: string;
246
+ include?: string[];
247
+ exclude?: string[];
248
+ extensions?: string[];
249
+ ignoreDirs?: string[];
250
+ namePrefix?: string;
251
+ } | Array<{
252
+ dir: string;
253
+ include?: string[];
254
+ exclude?: string[];
255
+ extensions?: string[];
256
+ ignoreDirs?: string[];
257
+ namePrefix?: string;
258
+ }>;
259
+ virtualEntries?: Record<string, string>;
122
260
  outDir: string;
123
261
  rootDir?: string;
124
262
  platform?: "browser" | "node" | "neutral";
@@ -132,22 +270,43 @@ type BundlerOptions = {
132
270
  define?: Record<string, string>;
133
271
  clean?: boolean;
134
272
  annotateSources?: boolean;
273
+ manifest?: boolean | {
274
+ file?: string;
275
+ };
276
+ onRebuilt?: (result: BundlerBuildResult) => void | Promise<void>;
277
+ onEntrySetChanged?: (entries: Record<string, string>) => void | Promise<void>;
135
278
  logger?: unknown;
136
279
  loggerAdapter?: (logger: unknown, event: unknown) => unknown;
137
280
  };
138
281
 
139
282
  declare function bundle(options: BundlerOptions): Promise<{
283
+ entries: Record<string, string>;
140
284
  outputs: string[];
141
285
  warnings: number;
142
286
  metafile?: object;
287
+ manifestPath?: string;
143
288
  durationMs: number;
144
289
  }>;
145
290
 
291
+ declare function deriveManifest(
292
+ metafile: object,
293
+ options: {
294
+ rootDir: string;
295
+ outDir: string;
296
+ },
297
+ ): {
298
+ entries: Record<string, unknown>;
299
+ chunks: Record<string, unknown>;
300
+ allOutputs: Record<string, unknown>;
301
+ };
302
+
146
303
  declare function watch(options: BundlerOptions): Promise<{
147
304
  rebuild(): Promise<{
305
+ entries: Record<string, string>;
148
306
  outputs: string[];
149
307
  warnings: number;
150
308
  metafile?: object;
309
+ manifestPath?: string;
151
310
  durationMs: number;
152
311
  }>;
153
312
  dispose(): Promise<void>;
@@ -1 +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"}
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;AAKtE,iBAAe,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0C1E;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -3,6 +3,7 @@ import { logPackageInitialized } from "@trebired/logger-adapter";
3
3
  import { BUNDLER_LOG_GROUP, BUNDLER_PACKAGE_NAME } from "../constants.js";
4
4
  import { resolveLogger } from "../logging.js";
5
5
  import { createEsbuildOptions, normalizeBundlerOptions } from "./esbuild-options.js";
6
+ import { resolveBundlerEntries } from "./discovery.js";
6
7
  import { cleanOutDir, formatFailure, logWarnings, toBuildResult } from "./shared.js";
7
8
  async function bundle(options) {
8
9
  const normalized = normalizeBundlerOptions(options || {});
@@ -21,9 +22,17 @@ async function bundle(options) {
21
22
  logger.info("build", "start");
22
23
  const startedAt = Date.now();
23
24
  try {
24
- const result = await runEsbuild(createEsbuildOptions(normalized, logger));
25
+ const resolvedEntries = await resolveBundlerEntries(options || {}, normalized.rootDir);
26
+ logger.info("build", `entries :: count=${resolvedEntries.records.length}`);
27
+ const result = await runEsbuild(createEsbuildOptions({
28
+ ...normalized,
29
+ entryRecords: resolvedEntries.records,
30
+ }, logger));
25
31
  logWarnings(logger, result.warnings);
26
- const summary = toBuildResult({
32
+ const summary = await toBuildResult({
33
+ entries: resolvedEntries.records,
34
+ manifest: normalized.manifest,
35
+ outDir: normalized.outDir,
27
36
  result,
28
37
  rootDir: normalized.rootDir,
29
38
  startedAt,
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/core/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe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AO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Metafile } from "esbuild";
2
+ import type { BundlerDerivedManifest } from "../types.js";
3
+ type DeriveManifestOptions = {
4
+ outDir: string;
5
+ rootDir: string;
6
+ };
7
+ declare function deriveManifest(metafile: Metafile, options: DeriveManifestOptions): BundlerDerivedManifest;
8
+ export { deriveManifest };
9
+ export type { DeriveManifestOptions };
10
+ //# sourceMappingURL=derive-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive-manifest.d.ts","sourceRoot":"","sources":["../../src/core/derive-manifest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EACV,sBAAsB,EAKvB,MAAM,aAAa,CAAC;AAIrB,KAAK,qBAAqB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAmFF,iBAAS,cAAc,CACrB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,qBAAqB,GAC7B,sBAAsB,CA8FxB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,150 @@
1
+ import path from "node:path";
2
+ import { toPosixPath } from "./discovery.js";
3
+ import { VIRTUAL_ENTRY_PREFIX } from "./discovery.js";
4
+ function normalizeFilePath(filePath, rootDir) {
5
+ if (filePath.startsWith(VIRTUAL_ENTRY_PREFIX)) {
6
+ return `virtual:${filePath.slice(VIRTUAL_ENTRY_PREFIX.length)}`;
7
+ }
8
+ const absolute = path.isAbsolute(filePath) ? filePath : path.resolve(rootDir, filePath);
9
+ return toPosixPath(path.relative(rootDir, absolute));
10
+ }
11
+ function normalizeInputPaths(inputs, rootDir) {
12
+ return Object.keys(inputs)
13
+ .map((value) => normalizeFilePath(value, rootDir))
14
+ .sort();
15
+ }
16
+ function normalizeImportedOutputPaths(metafile, outputPath, rootDir) {
17
+ const output = metafile.outputs[outputPath];
18
+ if (!output)
19
+ return [];
20
+ return output.imports
21
+ .filter((item) => !item.external && Boolean(metafile.outputs[item.path]))
22
+ .map((item) => normalizeFilePath(item.path, rootDir))
23
+ .sort();
24
+ }
25
+ function resolveOutputKind(args) {
26
+ if (args.outputValue.entryPoint)
27
+ return "entry";
28
+ if (args.importedOutputs.has(args.outputRel) || /\.(?:[mc]?js)$/i.test(args.outputRel))
29
+ return "chunk";
30
+ return "asset";
31
+ }
32
+ function deriveEntryName(args) {
33
+ if (args.outputValue.entryPoint) {
34
+ const entryRel = normalizeFilePath(args.outputValue.entryPoint, args.rootDir);
35
+ const ext = path.extname(entryRel);
36
+ return toPosixPath(ext ? entryRel.slice(0, -ext.length) : entryRel);
37
+ }
38
+ const absoluteOutDir = path.resolve(args.rootDir, args.outDir);
39
+ const absoluteOutput = path.resolve(args.rootDir, args.entryOutput);
40
+ const relOut = toPosixPath(path.relative(absoluteOutDir, absoluteOutput));
41
+ if (!relOut || relOut.startsWith(".."))
42
+ return undefined;
43
+ const ext = path.extname(relOut);
44
+ return ext ? relOut.slice(0, -ext.length) : relOut;
45
+ }
46
+ function collectReachableOutputs(args) {
47
+ const seen = new Set();
48
+ const stack = [args.outputPath];
49
+ while (stack.length) {
50
+ const current = stack.pop();
51
+ if (seen.has(current))
52
+ continue;
53
+ seen.add(current);
54
+ const currentOutput = args.metafile.outputs[current];
55
+ if (!currentOutput)
56
+ continue;
57
+ for (const imported of currentOutput.imports) {
58
+ if (imported.external || !args.metafile.outputs[imported.path])
59
+ continue;
60
+ stack.push(imported.path);
61
+ }
62
+ }
63
+ return Array.from(seen).sort().map((value) => normalizeFilePath(value, args.rootDir));
64
+ }
65
+ function deriveManifest(metafile, options) {
66
+ const outputs = Object.entries(metafile.outputs).sort(([a], [b]) => a.localeCompare(b));
67
+ const importedOutputs = new Set();
68
+ for (const [, output] of outputs) {
69
+ for (const imported of output.imports) {
70
+ if (!imported.external && metafile.outputs[imported.path]) {
71
+ importedOutputs.add(normalizeFilePath(imported.path, options.rootDir));
72
+ }
73
+ }
74
+ }
75
+ const entries = {};
76
+ const chunks = {};
77
+ const allOutputs = {};
78
+ for (const [outputPath, outputValue] of outputs) {
79
+ const outputRel = normalizeFilePath(outputPath, options.rootDir);
80
+ const imports = normalizeImportedOutputPaths(metafile, outputPath, options.rootDir);
81
+ const css = outputValue.cssBundle
82
+ ? [normalizeFilePath(outputValue.cssBundle, options.rootDir)]
83
+ : outputRel.endsWith(".css")
84
+ ? [outputRel]
85
+ : [];
86
+ const outputInfo = {
87
+ output: outputRel,
88
+ kind: resolveOutputKind({
89
+ importedOutputs,
90
+ outputPath,
91
+ outputRel,
92
+ outputValue,
93
+ }),
94
+ entryPoint: outputValue.entryPoint ? normalizeFilePath(outputValue.entryPoint, options.rootDir) : undefined,
95
+ entryName: deriveEntryName({
96
+ entryOutput: outputPath,
97
+ outputValue,
98
+ outDir: options.outDir,
99
+ rootDir: options.rootDir,
100
+ }),
101
+ inputs: normalizeInputPaths(outputValue.inputs, options.rootDir),
102
+ css,
103
+ imports,
104
+ bytes: outputValue.bytes,
105
+ };
106
+ allOutputs[outputRel] = outputInfo;
107
+ }
108
+ for (const [outputPath] of outputs) {
109
+ const outputRel = normalizeFilePath(outputPath, options.rootDir);
110
+ const outputInfo = allOutputs[outputRel];
111
+ if (!outputInfo)
112
+ continue;
113
+ if (outputInfo.kind === "entry") {
114
+ const reachable = collectReachableOutputs({
115
+ metafile,
116
+ outputPath,
117
+ rootDir: options.rootDir,
118
+ });
119
+ const js = reachable.filter((value) => /\.(?:[mc]?js)$/i.test(value));
120
+ const reachableCss = Array.from(new Set(reachable.flatMap((value) => {
121
+ const info = allOutputs[value];
122
+ return info ? info.css : value.endsWith(".css") ? [value] : [];
123
+ }))).sort();
124
+ entries[outputRel] = {
125
+ entryOutput: outputRel,
126
+ entryName: outputInfo.entryName,
127
+ inputs: outputInfo.inputs,
128
+ js,
129
+ css: reachableCss,
130
+ imports: outputInfo.imports,
131
+ };
132
+ continue;
133
+ }
134
+ if (outputInfo.kind === "chunk") {
135
+ chunks[outputRel] = {
136
+ output: outputRel,
137
+ inputs: outputInfo.inputs,
138
+ css: outputInfo.css,
139
+ imports: outputInfo.imports,
140
+ };
141
+ }
142
+ }
143
+ return {
144
+ entries: Object.fromEntries(Object.entries(entries).sort(([a], [b]) => a.localeCompare(b))),
145
+ chunks: Object.fromEntries(Object.entries(chunks).sort(([a], [b]) => a.localeCompare(b))),
146
+ allOutputs: Object.fromEntries(Object.entries(allOutputs).sort(([a], [b]) => a.localeCompare(b))),
147
+ };
148
+ }
149
+ export { deriveManifest };
150
+ //# sourceMappingURL=derive-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive-manifest.js","sourceRoot":"","sources":["../../src/core/derive-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAU7B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAOtD,SAAS,iBAAiB,CAAC,QAAgB,EAAE,OAAe;IAC1D,IAAI,QAAQ,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC9C,OAAO,WAAW,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;IAClE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxF,OAAO,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,mBAAmB,CAAC,MAA+B,EAAE,OAAe;IAC3E,OAAO,MAAM,CAAC,IAAI,CAAC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GAAG,EAAE,UAAU,CAAC,GAAG;gBACnB,OAAO,EAAE,UAAU,CAAC,OAAO;aAC5B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3F,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QACzF,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;KAClG,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ type DiscoveryWatcher = {
2
+ close(): void;
3
+ };
4
+ declare function createDiscoveryWatcher(args: {
5
+ dirs: string[];
6
+ onChange: () => void;
7
+ }): DiscoveryWatcher;
8
+ export { createDiscoveryWatcher };
9
+ //# sourceMappingURL=discovery-watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery-watch.d.ts","sourceRoot":"","sources":["../../src/core/discovery-watch.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,iBAAS,sBAAsB,CAAC,IAAI,EAAE;IACpC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,gBAAgB,CAqEnB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ function createDiscoveryWatcher(args) {
4
+ const watchers = new Map();
5
+ let closed = false;
6
+ let timer = null;
7
+ const interval = setInterval(() => {
8
+ for (const dir of args.dirs) {
9
+ refresh(dir);
10
+ }
11
+ emitChange();
12
+ }, 250);
13
+ const emitChange = () => {
14
+ if (closed)
15
+ return;
16
+ if (timer)
17
+ clearTimeout(timer);
18
+ timer = setTimeout(() => {
19
+ timer = null;
20
+ args.onChange();
21
+ }, 80);
22
+ };
23
+ const ensureWatch = (dir) => {
24
+ if (closed || watchers.has(dir) || !fs.existsSync(dir))
25
+ return;
26
+ if (!fs.statSync(dir).isDirectory())
27
+ return;
28
+ const watcher = fs.watch(dir, () => {
29
+ refresh(dir);
30
+ emitChange();
31
+ });
32
+ watcher.on("error", () => {
33
+ watchers.delete(dir);
34
+ });
35
+ watchers.set(dir, watcher);
36
+ };
37
+ const refresh = (startDir) => {
38
+ if (closed || !fs.existsSync(startDir))
39
+ return;
40
+ const stack = [startDir];
41
+ while (stack.length) {
42
+ const current = stack.pop();
43
+ ensureWatch(current);
44
+ for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
45
+ if (!entry.isDirectory())
46
+ continue;
47
+ const child = path.join(current, entry.name);
48
+ if (!watchers.has(child)) {
49
+ stack.push(child);
50
+ }
51
+ }
52
+ }
53
+ };
54
+ for (const dir of args.dirs) {
55
+ refresh(dir);
56
+ }
57
+ return {
58
+ close() {
59
+ closed = true;
60
+ clearInterval(interval);
61
+ if (timer)
62
+ clearTimeout(timer);
63
+ for (const watcher of watchers.values()) {
64
+ watcher.close();
65
+ }
66
+ watchers.clear();
67
+ },
68
+ };
69
+ }
70
+ export { createDiscoveryWatcher };
71
+ //# sourceMappingURL=discovery-watch.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AAO,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;gBACxC,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,CAAC;YACD,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { BundlerEntryRecord, BundlerManifestOptions, BundlerOptions } from "../types.js";
2
+ declare const VIRTUAL_ENTRY_PREFIX = "trebired-virtual:";
3
+ type NormalizedDiscoverOptions = {
4
+ dir: string;
5
+ dirAbs: string;
6
+ exclude: string[];
7
+ extensions: string[];
8
+ ignoreDirs: Set<string>;
9
+ include: string[];
10
+ namePrefix: string;
11
+ };
12
+ type ResolvedEntries = {
13
+ records: BundlerEntryRecord[];
14
+ signature: string;
15
+ };
16
+ type NormalizedManifestOptions = {
17
+ enabled: boolean;
18
+ file?: string;
19
+ };
20
+ declare function toPosixPath(value: string): string;
21
+ declare function resolveBundlerEntries(options: BundlerOptions, rootDir: string, settings?: {
22
+ allowEmpty?: boolean;
23
+ }): Promise<ResolvedEntries>;
24
+ declare function toEntryPointMap(records: BundlerEntryRecord[], rootDir: string): Record<string, string>;
25
+ declare function toPublicEntryMap(records: BundlerEntryRecord[], rootDir: string): Record<string, string>;
26
+ declare function normalizeManifestOptions(manifest: BundlerManifestOptions | undefined): NormalizedManifestOptions;
27
+ declare function normalizeDiscoverRoots(rootDir: string, discover: BundlerOptions["discover"]): string[];
28
+ export { normalizeDiscoverRoots, normalizeManifestOptions, resolveBundlerEntries, toPublicEntryMap, toEntryPointMap, toPosixPath, VIRTUAL_ENTRY_PREFIX, };
29
+ export type { NormalizedDiscoverOptions, NormalizedManifestOptions, ResolvedEntries };
30
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK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