@markopack/compiler 0.3.2 → 0.4.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/index.cjs CHANGED
@@ -34,7 +34,7 @@ __export(MarkoRspackPlugin_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(MarkoRspackPlugin_exports);
36
36
 
37
- // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
37
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_supports-color@10.2.2_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
38
38
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
39
39
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
40
 
@@ -67,6 +67,13 @@ var MarkoRspackPlugin = class {
67
67
  serverCompiler = null;
68
68
  browserCompilers = [];
69
69
  clientEntries = {};
70
+ /**
71
+ * Per page entry: extra .marko modules the browser entry must import for
72
+ * hydration — components reachable only through non-.marko modules, which
73
+ * the translator's hydrate emit cannot see (see finishModules note).
74
+ */
75
+ clientHydrateImports = {};
76
+ loadEntries = {};
70
77
  clientAssets = {};
71
78
  _api = null;
72
79
  entriesReady;
@@ -111,6 +118,11 @@ var MarkoRspackPlugin = class {
111
118
  get discoveredClientEntries() {
112
119
  return this.clientEntries;
113
120
  }
121
+ /** Lazy-component load entries discovered on the server compiler
122
+ * (browser entry name → component file + its readyId). */
123
+ get discoveredLoadEntries() {
124
+ return this.loadEntries;
125
+ }
114
126
  /** Browser compilation output files per entry (compiler name → entry id → files by extension). */
115
127
  get collectedClientAssets() {
116
128
  return this.clientAssets;
@@ -186,22 +198,77 @@ var MarkoRspackPlugin = class {
186
198
  (modules) => {
187
199
  let hasChangedEntries = false;
188
200
  const removedEntryIds = new Set(Object.keys(this.clientEntries));
201
+ const entryModules = /* @__PURE__ */ new Map();
202
+ const moduleFiles = /* @__PURE__ */ new Set();
189
203
  for (const mod of modules) {
190
204
  const resource = mod.resource;
191
- if (!resource?.endsWith(".marko?server-entry")) {
205
+ if (!resource) {
192
206
  continue;
193
207
  }
194
- this.needsManifestSync = true;
195
- const filename = resource.replace(/\?server-entry$/, "");
208
+ if (resource.endsWith(".marko?server-entry")) {
209
+ this.needsManifestSync = true;
210
+ const filename = resource.replace(/\?server-entry$/, "");
211
+ moduleFiles.add(filename);
212
+ entryModules.set(filename, mod);
213
+ const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
214
+ if (!removedEntryIds.delete(entryTemplateId)) {
215
+ hasChangedEntries = true;
216
+ this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
217
+ }
218
+ } else if (/\.marko(\?.*)?$/.test(resource)) {
219
+ moduleFiles.add(resource.replace(/\?.*$/, ""));
220
+ }
221
+ }
222
+ const lazyFiles = new Set(
223
+ Object.values(this.loadEntries).map(({ file }) => file)
224
+ );
225
+ for (const [filename, entryModule] of entryModules) {
196
226
  const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
197
- if (!removedEntryIds.delete(entryTemplateId)) {
227
+ const markoOnly = reachableMarko(
228
+ compilation,
229
+ entryModule,
230
+ true
231
+ );
232
+ const full = reachableMarko(compilation, entryModule, false);
233
+ const missed = [...full].filter(
234
+ (file) => file !== filename && !markoOnly.has(file) && !lazyFiles.has(file)
235
+ ).sort();
236
+ const previous = this.clientHydrateImports[entryTemplateId];
237
+ const changedImports = previous === void 0 || previous.length !== missed.length || previous.some((file, i) => file !== missed[i]);
238
+ if (changedImports) {
198
239
  hasChangedEntries = true;
199
- this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
240
+ if (missed.length) {
241
+ this.clientHydrateImports[entryTemplateId] = missed;
242
+ } else {
243
+ delete this.clientHydrateImports[entryTemplateId];
244
+ }
245
+ }
246
+ }
247
+ const loadRegistry = globalThis.__markopack_load_assets__;
248
+ const removedLoadIds = new Set(Object.keys(this.loadEntries));
249
+ if (loadRegistry) {
250
+ for (const [file, readyId] of loadRegistry) {
251
+ if (!moduleFiles.has(file)) {
252
+ continue;
253
+ }
254
+ const entryName = module_name_default(file).replace(/^\.+/, "") + "_load";
255
+ if (!removedLoadIds.delete(entryName)) {
256
+ hasChangedEntries = true;
257
+ }
258
+ this.loadEntries[entryName] = { file, readyId };
259
+ }
260
+ }
261
+ for (const removedLoadId of removedLoadIds) {
262
+ hasChangedEntries = true;
263
+ delete this.loadEntries[removedLoadId];
264
+ for (const compilerName in this.clientAssets) {
265
+ delete this.clientAssets[compilerName][removedLoadId];
200
266
  }
201
267
  }
202
268
  for (const removedEntryId of removedEntryIds) {
203
269
  hasChangedEntries = true;
204
270
  delete this.clientEntries[removedEntryId];
271
+ delete this.clientHydrateImports[removedEntryId];
205
272
  for (const compilerName in this.clientAssets) {
206
273
  delete this.clientAssets[compilerName][removedEntryId];
207
274
  }
@@ -224,18 +291,30 @@ var MarkoRspackPlugin = class {
224
291
  if (this.needsManifestSync && this.serverCompiler?.watching) {
225
292
  await this.entriesReady;
226
293
  }
294
+ const entryImports = this.options.browserEntryImports ?? [];
227
295
  const normalizedEntries = {};
228
296
  for (const key in this.clientEntries) {
229
297
  normalizedEntries[key] = {
230
- import: [this.clientEntries[key]]
298
+ // Hydrate imports must run BEFORE the ?browser-entry module: its
299
+ // init() resolves template ids from the resume payload against the
300
+ // registration table, so a component module executing after init
301
+ // registers too late ("effects[i] is not a function").
302
+ import: [
303
+ ...entryImports,
304
+ ...this.clientHydrateImports[key] ?? [],
305
+ this.clientEntries[key]
306
+ ]
231
307
  };
232
308
  }
309
+ for (const [name, { file }] of Object.entries(this.loadEntries)) {
310
+ normalizedEntries[name] = { import: [`${file}?load-entry`] };
311
+ }
233
312
  if (typeof entryOption === "function") {
234
313
  const currentEntry = await entryOption();
235
- return { ...currentEntry, ...normalizedEntries };
314
+ return { ...this.prependEntryImports(currentEntry), ...normalizedEntries };
236
315
  }
237
316
  if (typeof entryOption === "object" && !Array.isArray(entryOption)) {
238
- return { ...entryOption, ...normalizedEntries };
317
+ return { ...this.prependEntryImports(entryOption), ...normalizedEntries };
239
318
  }
240
319
  return normalizedEntries;
241
320
  };
@@ -265,6 +344,14 @@ var MarkoRspackPlugin = class {
265
344
  assetsByType[ext] = type;
266
345
  type.push(file);
267
346
  }
347
+ const asyncCss = assetsByType.asyncCss ?? (assetsByType.asyncCss = []);
348
+ for (const asyncChunk of chunk.getAllAsyncChunks()) {
349
+ for (const file of asyncChunk.files) {
350
+ if (file.endsWith(".css") && !asyncCss.includes(file)) {
351
+ asyncCss.push(file);
352
+ }
353
+ }
354
+ }
268
355
  }
269
356
  const buildAssets = this.clientAssets[compilerName] || {};
270
357
  this.clientAssets[compilerName] = buildAssets;
@@ -283,6 +370,31 @@ var MarkoRspackPlugin = class {
283
370
  }
284
371
  );
285
372
  }
373
+ /**
374
+ * Prepends `browserEntryImports` to every host-provided browser entry,
375
+ * normalizing shorthand forms (string, string[]) along the way. Returns
376
+ * the input untouched when the option is not set.
377
+ */
378
+ prependEntryImports(entries) {
379
+ const prefix = this.options.browserEntryImports;
380
+ if (!prefix?.length) return entries;
381
+ const result = { ...entries };
382
+ for (const name of Object.keys(result)) {
383
+ const desc = result[name];
384
+ if (typeof desc === "string") {
385
+ result[name] = { import: [...prefix, desc] };
386
+ } else if (Array.isArray(desc)) {
387
+ result[name] = { import: [...prefix, ...desc] };
388
+ } else if (desc && typeof desc === "object") {
389
+ const { import: imports, ...rest } = desc;
390
+ result[name] = {
391
+ ...rest,
392
+ import: [...prefix, ...Array.isArray(imports) ? imports : []]
393
+ };
394
+ }
395
+ }
396
+ return result;
397
+ }
286
398
  normalizeRuntimeId(id) {
287
399
  return id.replace(/[^a-zA-Z0-9_]/g, "_");
288
400
  }
@@ -309,3 +421,39 @@ var MarkoRspackPlugin = class {
309
421
  return result;
310
422
  }
311
423
  };
424
+ function reachableMarko(compilation, seed, markoOnly) {
425
+ const graph = compilation.moduleGraph;
426
+ const isMarkoResource = (resource) => !!resource && /\.marko(\?.*)?$/.test(resource);
427
+ const resourceOf = (m) => m?.resource;
428
+ const seenModules = /* @__PURE__ */ new Set();
429
+ const files = /* @__PURE__ */ new Set();
430
+ const queue = [seed];
431
+ seenModules.add(seed);
432
+ while (queue.length) {
433
+ const current = queue.shift();
434
+ let outgoing;
435
+ try {
436
+ outgoing = graph.getOutgoingConnections(current);
437
+ } catch {
438
+ continue;
439
+ }
440
+ for (const connection of outgoing) {
441
+ const target = connection.module;
442
+ if (!target || seenModules.has(target)) continue;
443
+ const active = typeof connection.isActive === "function" ? connection.isActive(compilation) : true;
444
+ if (active === false) continue;
445
+ const targetResource = resourceOf(target);
446
+ if (!targetResource) continue;
447
+ if (markoOnly) {
448
+ if (!isMarkoResource(targetResource)) continue;
449
+ if (!isMarkoResource(resourceOf(current))) continue;
450
+ }
451
+ seenModules.add(target);
452
+ if (isMarkoResource(targetResource)) {
453
+ files.add(targetResource.replace(/\?.*$/, ""));
454
+ }
455
+ queue.push(target);
456
+ }
457
+ }
458
+ return files;
459
+ }
package/dist/index.d.cts CHANGED
@@ -22,12 +22,26 @@ interface MarkoPluginOptions {
22
22
  web?: Configuration['entry'];
23
23
  node?: Configuration['entry'];
24
24
  };
25
+ /**
26
+ * Modules prepended to every browser entry's import list (page entries
27
+ * and host-provided entries, not lazy load entries — those load after a
28
+ * page entry has already run them). Used to bootstrap globals that
29
+ * hydrated code relies on, e.g. @marko/run's `window.Run`.
30
+ */
31
+ browserEntryImports?: string[];
25
32
  }
26
33
  declare class MarkoRspackPlugin {
27
34
  private options;
28
35
  private serverCompiler;
29
36
  private browserCompilers;
30
37
  private clientEntries;
38
+ /**
39
+ * Per page entry: extra .marko modules the browser entry must import for
40
+ * hydration — components reachable only through non-.marko modules, which
41
+ * the translator's hydrate emit cannot see (see finishModules note).
42
+ */
43
+ private clientHydrateImports;
44
+ private loadEntries;
31
45
  private clientAssets;
32
46
  private _api;
33
47
  private entriesReady;
@@ -40,6 +54,12 @@ declare class MarkoRspackPlugin {
40
54
  get entriesReadyPromise(): ResolvablePromise<void>;
41
55
  /** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
42
56
  get discoveredClientEntries(): Record<string, string>;
57
+ /** Lazy-component load entries discovered on the server compiler
58
+ * (browser entry name → component file + its readyId). */
59
+ get discoveredLoadEntries(): Record<string, {
60
+ file: string;
61
+ readyId: string;
62
+ }>;
43
63
  /** Browser compilation output files per entry (compiler name → entry id → files by extension). */
44
64
  get collectedClientAssets(): Record<string, Record<string, Record<string, string[]>>>;
45
65
  setup(api: any): void;
@@ -47,6 +67,12 @@ declare class MarkoRspackPlugin {
47
67
  private setupRules;
48
68
  private applyServer;
49
69
  private applyBrowser;
70
+ /**
71
+ * Prepends `browserEntryImports` to every host-provided browser entry,
72
+ * normalizing shorthand forms (string, string[]) along the way. Returns
73
+ * the input untouched when the option is not set.
74
+ */
75
+ private prependEntryImports;
50
76
  private normalizeRuntimeId;
51
77
  private createDeferredPromise;
52
78
  private sortKeys;
package/dist/index.d.ts CHANGED
@@ -22,12 +22,26 @@ interface MarkoPluginOptions {
22
22
  web?: Configuration['entry'];
23
23
  node?: Configuration['entry'];
24
24
  };
25
+ /**
26
+ * Modules prepended to every browser entry's import list (page entries
27
+ * and host-provided entries, not lazy load entries — those load after a
28
+ * page entry has already run them). Used to bootstrap globals that
29
+ * hydrated code relies on, e.g. @marko/run's `window.Run`.
30
+ */
31
+ browserEntryImports?: string[];
25
32
  }
26
33
  declare class MarkoRspackPlugin {
27
34
  private options;
28
35
  private serverCompiler;
29
36
  private browserCompilers;
30
37
  private clientEntries;
38
+ /**
39
+ * Per page entry: extra .marko modules the browser entry must import for
40
+ * hydration — components reachable only through non-.marko modules, which
41
+ * the translator's hydrate emit cannot see (see finishModules note).
42
+ */
43
+ private clientHydrateImports;
44
+ private loadEntries;
31
45
  private clientAssets;
32
46
  private _api;
33
47
  private entriesReady;
@@ -40,6 +54,12 @@ declare class MarkoRspackPlugin {
40
54
  get entriesReadyPromise(): ResolvablePromise<void>;
41
55
  /** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
42
56
  get discoveredClientEntries(): Record<string, string>;
57
+ /** Lazy-component load entries discovered on the server compiler
58
+ * (browser entry name → component file + its readyId). */
59
+ get discoveredLoadEntries(): Record<string, {
60
+ file: string;
61
+ readyId: string;
62
+ }>;
43
63
  /** Browser compilation output files per entry (compiler name → entry id → files by extension). */
44
64
  get collectedClientAssets(): Record<string, Record<string, Record<string, string[]>>>;
45
65
  setup(api: any): void;
@@ -47,6 +67,12 @@ declare class MarkoRspackPlugin {
47
67
  private setupRules;
48
68
  private applyServer;
49
69
  private applyBrowser;
70
+ /**
71
+ * Prepends `browserEntryImports` to every host-provided browser entry,
72
+ * normalizing shorthand forms (string, string[]) along the way. Returns
73
+ * the input untouched when the option is not set.
74
+ */
75
+ private prependEntryImports;
50
76
  private normalizeRuntimeId;
51
77
  private createDeferredPromise;
52
78
  private sortKeys;
package/dist/index.js CHANGED
@@ -27,6 +27,13 @@ var MarkoRspackPlugin = class {
27
27
  serverCompiler = null;
28
28
  browserCompilers = [];
29
29
  clientEntries = {};
30
+ /**
31
+ * Per page entry: extra .marko modules the browser entry must import for
32
+ * hydration — components reachable only through non-.marko modules, which
33
+ * the translator's hydrate emit cannot see (see finishModules note).
34
+ */
35
+ clientHydrateImports = {};
36
+ loadEntries = {};
30
37
  clientAssets = {};
31
38
  _api = null;
32
39
  entriesReady;
@@ -71,6 +78,11 @@ var MarkoRspackPlugin = class {
71
78
  get discoveredClientEntries() {
72
79
  return this.clientEntries;
73
80
  }
81
+ /** Lazy-component load entries discovered on the server compiler
82
+ * (browser entry name → component file + its readyId). */
83
+ get discoveredLoadEntries() {
84
+ return this.loadEntries;
85
+ }
74
86
  /** Browser compilation output files per entry (compiler name → entry id → files by extension). */
75
87
  get collectedClientAssets() {
76
88
  return this.clientAssets;
@@ -146,22 +158,77 @@ var MarkoRspackPlugin = class {
146
158
  (modules) => {
147
159
  let hasChangedEntries = false;
148
160
  const removedEntryIds = new Set(Object.keys(this.clientEntries));
161
+ const entryModules = /* @__PURE__ */ new Map();
162
+ const moduleFiles = /* @__PURE__ */ new Set();
149
163
  for (const mod of modules) {
150
164
  const resource = mod.resource;
151
- if (!resource?.endsWith(".marko?server-entry")) {
165
+ if (!resource) {
152
166
  continue;
153
167
  }
154
- this.needsManifestSync = true;
155
- const filename = resource.replace(/\?server-entry$/, "");
168
+ if (resource.endsWith(".marko?server-entry")) {
169
+ this.needsManifestSync = true;
170
+ const filename = resource.replace(/\?server-entry$/, "");
171
+ moduleFiles.add(filename);
172
+ entryModules.set(filename, mod);
173
+ const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
174
+ if (!removedEntryIds.delete(entryTemplateId)) {
175
+ hasChangedEntries = true;
176
+ this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
177
+ }
178
+ } else if (/\.marko(\?.*)?$/.test(resource)) {
179
+ moduleFiles.add(resource.replace(/\?.*$/, ""));
180
+ }
181
+ }
182
+ const lazyFiles = new Set(
183
+ Object.values(this.loadEntries).map(({ file }) => file)
184
+ );
185
+ for (const [filename, entryModule] of entryModules) {
156
186
  const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
157
- if (!removedEntryIds.delete(entryTemplateId)) {
187
+ const markoOnly = reachableMarko(
188
+ compilation,
189
+ entryModule,
190
+ true
191
+ );
192
+ const full = reachableMarko(compilation, entryModule, false);
193
+ const missed = [...full].filter(
194
+ (file) => file !== filename && !markoOnly.has(file) && !lazyFiles.has(file)
195
+ ).sort();
196
+ const previous = this.clientHydrateImports[entryTemplateId];
197
+ const changedImports = previous === void 0 || previous.length !== missed.length || previous.some((file, i) => file !== missed[i]);
198
+ if (changedImports) {
158
199
  hasChangedEntries = true;
159
- this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
200
+ if (missed.length) {
201
+ this.clientHydrateImports[entryTemplateId] = missed;
202
+ } else {
203
+ delete this.clientHydrateImports[entryTemplateId];
204
+ }
205
+ }
206
+ }
207
+ const loadRegistry = globalThis.__markopack_load_assets__;
208
+ const removedLoadIds = new Set(Object.keys(this.loadEntries));
209
+ if (loadRegistry) {
210
+ for (const [file, readyId] of loadRegistry) {
211
+ if (!moduleFiles.has(file)) {
212
+ continue;
213
+ }
214
+ const entryName = module_name_default(file).replace(/^\.+/, "") + "_load";
215
+ if (!removedLoadIds.delete(entryName)) {
216
+ hasChangedEntries = true;
217
+ }
218
+ this.loadEntries[entryName] = { file, readyId };
219
+ }
220
+ }
221
+ for (const removedLoadId of removedLoadIds) {
222
+ hasChangedEntries = true;
223
+ delete this.loadEntries[removedLoadId];
224
+ for (const compilerName in this.clientAssets) {
225
+ delete this.clientAssets[compilerName][removedLoadId];
160
226
  }
161
227
  }
162
228
  for (const removedEntryId of removedEntryIds) {
163
229
  hasChangedEntries = true;
164
230
  delete this.clientEntries[removedEntryId];
231
+ delete this.clientHydrateImports[removedEntryId];
165
232
  for (const compilerName in this.clientAssets) {
166
233
  delete this.clientAssets[compilerName][removedEntryId];
167
234
  }
@@ -184,18 +251,30 @@ var MarkoRspackPlugin = class {
184
251
  if (this.needsManifestSync && this.serverCompiler?.watching) {
185
252
  await this.entriesReady;
186
253
  }
254
+ const entryImports = this.options.browserEntryImports ?? [];
187
255
  const normalizedEntries = {};
188
256
  for (const key in this.clientEntries) {
189
257
  normalizedEntries[key] = {
190
- import: [this.clientEntries[key]]
258
+ // Hydrate imports must run BEFORE the ?browser-entry module: its
259
+ // init() resolves template ids from the resume payload against the
260
+ // registration table, so a component module executing after init
261
+ // registers too late ("effects[i] is not a function").
262
+ import: [
263
+ ...entryImports,
264
+ ...this.clientHydrateImports[key] ?? [],
265
+ this.clientEntries[key]
266
+ ]
191
267
  };
192
268
  }
269
+ for (const [name, { file }] of Object.entries(this.loadEntries)) {
270
+ normalizedEntries[name] = { import: [`${file}?load-entry`] };
271
+ }
193
272
  if (typeof entryOption === "function") {
194
273
  const currentEntry = await entryOption();
195
- return { ...currentEntry, ...normalizedEntries };
274
+ return { ...this.prependEntryImports(currentEntry), ...normalizedEntries };
196
275
  }
197
276
  if (typeof entryOption === "object" && !Array.isArray(entryOption)) {
198
- return { ...entryOption, ...normalizedEntries };
277
+ return { ...this.prependEntryImports(entryOption), ...normalizedEntries };
199
278
  }
200
279
  return normalizedEntries;
201
280
  };
@@ -225,6 +304,14 @@ var MarkoRspackPlugin = class {
225
304
  assetsByType[ext] = type;
226
305
  type.push(file);
227
306
  }
307
+ const asyncCss = assetsByType.asyncCss ?? (assetsByType.asyncCss = []);
308
+ for (const asyncChunk of chunk.getAllAsyncChunks()) {
309
+ for (const file of asyncChunk.files) {
310
+ if (file.endsWith(".css") && !asyncCss.includes(file)) {
311
+ asyncCss.push(file);
312
+ }
313
+ }
314
+ }
228
315
  }
229
316
  const buildAssets = this.clientAssets[compilerName] || {};
230
317
  this.clientAssets[compilerName] = buildAssets;
@@ -243,6 +330,31 @@ var MarkoRspackPlugin = class {
243
330
  }
244
331
  );
245
332
  }
333
+ /**
334
+ * Prepends `browserEntryImports` to every host-provided browser entry,
335
+ * normalizing shorthand forms (string, string[]) along the way. Returns
336
+ * the input untouched when the option is not set.
337
+ */
338
+ prependEntryImports(entries) {
339
+ const prefix = this.options.browserEntryImports;
340
+ if (!prefix?.length) return entries;
341
+ const result = { ...entries };
342
+ for (const name of Object.keys(result)) {
343
+ const desc = result[name];
344
+ if (typeof desc === "string") {
345
+ result[name] = { import: [...prefix, desc] };
346
+ } else if (Array.isArray(desc)) {
347
+ result[name] = { import: [...prefix, ...desc] };
348
+ } else if (desc && typeof desc === "object") {
349
+ const { import: imports, ...rest } = desc;
350
+ result[name] = {
351
+ ...rest,
352
+ import: [...prefix, ...Array.isArray(imports) ? imports : []]
353
+ };
354
+ }
355
+ }
356
+ return result;
357
+ }
246
358
  normalizeRuntimeId(id) {
247
359
  return id.replace(/[^a-zA-Z0-9_]/g, "_");
248
360
  }
@@ -269,6 +381,42 @@ var MarkoRspackPlugin = class {
269
381
  return result;
270
382
  }
271
383
  };
384
+ function reachableMarko(compilation, seed, markoOnly) {
385
+ const graph = compilation.moduleGraph;
386
+ const isMarkoResource = (resource) => !!resource && /\.marko(\?.*)?$/.test(resource);
387
+ const resourceOf = (m) => m?.resource;
388
+ const seenModules = /* @__PURE__ */ new Set();
389
+ const files = /* @__PURE__ */ new Set();
390
+ const queue = [seed];
391
+ seenModules.add(seed);
392
+ while (queue.length) {
393
+ const current = queue.shift();
394
+ let outgoing;
395
+ try {
396
+ outgoing = graph.getOutgoingConnections(current);
397
+ } catch {
398
+ continue;
399
+ }
400
+ for (const connection of outgoing) {
401
+ const target = connection.module;
402
+ if (!target || seenModules.has(target)) continue;
403
+ const active = typeof connection.isActive === "function" ? connection.isActive(compilation) : true;
404
+ if (active === false) continue;
405
+ const targetResource = resourceOf(target);
406
+ if (!targetResource) continue;
407
+ if (markoOnly) {
408
+ if (!isMarkoResource(targetResource)) continue;
409
+ if (!isMarkoResource(resourceOf(current))) continue;
410
+ }
411
+ seenModules.add(target);
412
+ if (isMarkoResource(targetResource)) {
413
+ files.add(targetResource.replace(/\?.*$/, ""));
414
+ }
415
+ queue.push(target);
416
+ }
417
+ }
418
+ return files;
419
+ }
272
420
  export {
273
421
  MarkoRspackPlugin as default
274
422
  };
@@ -34,7 +34,7 @@ __export(marko_loader_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(marko_loader_exports);
36
36
 
37
- // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
37
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_supports-color@10.2.2_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
38
38
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
39
39
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
40
 
@@ -48,8 +48,13 @@ var linkAssetsRuntimePath = (0, import_node_url.fileURLToPath)(
48
48
  new URL("./link-assets-runtime.js", importMetaUrl)
49
49
  );
50
50
  var ASSET_ID_REGISTRY = globalThis.__markopack_page_assets__ ??= /* @__PURE__ */ new Map();
51
- function onAsset(_kind, filename, assetId) {
52
- ASSET_ID_REGISTRY.set(filename, assetId);
51
+ var LOAD_ASSET_REGISTRY = globalThis.__markopack_load_assets__ ??= /* @__PURE__ */ new Map();
52
+ function onAsset(kind, filename, assetId) {
53
+ if (kind === "load") {
54
+ LOAD_ASSET_REGISTRY.set(filename, assetId);
55
+ } else {
56
+ ASSET_ID_REGISTRY.set(filename, assetId);
57
+ }
53
58
  }
54
59
  function makeResolveVirtualDependency(root) {
55
60
  const virtualDir = import_node_path.default.join(
@@ -67,7 +72,14 @@ function makeResolveVirtualDependency(root) {
67
72
  )}${import_node_path.default.extname(dep.virtualPath) ? "" : ".js"}`;
68
73
  const file = import_node_path.default.join(virtualDir, name);
69
74
  import_node_fs.default.mkdirSync(virtualDir, { recursive: true });
70
- import_node_fs.default.writeFileSync(file, dep.code);
75
+ const virtualModuleDir = import_node_path.default.dirname(
76
+ import_node_path.default.resolve(import_node_path.default.dirname(from), dep.virtualPath)
77
+ );
78
+ const code = dep.code.replace(
79
+ /(from\s*|import\s*\(\s*|import\s+)("|')((?:\.\.?\/)[^"']+)\2/g,
80
+ (_m, prefix, quote, specifier) => `${prefix}${quote}${import_node_path.default.join(virtualModuleDir, specifier)}${quote}`
81
+ );
82
+ import_node_fs.default.writeFileSync(file, code);
71
83
  return file;
72
84
  };
73
85
  }
@@ -78,8 +90,9 @@ function markoLoader(_source) {
78
90
  const query = this.resourceQuery || "";
79
91
  const isServerEntry = /^\?server-entry/.test(query);
80
92
  const isBrowserEntry = /^\?browser-entry/.test(query);
93
+ const isLoadEntry = /^\?load-entry/.test(query);
81
94
  const isServer = !isBrowserEntry;
82
- const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : options.output || "dom";
95
+ const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : isLoadEntry ? "dom" : options.output || "dom";
83
96
  const compilerPath = options.compiler;
84
97
  const translator = options.translator || import_translator.default;
85
98
  Promise.resolve().then(async () => {
@@ -97,6 +110,7 @@ function markoLoader(_source) {
97
110
  output: outputFormat,
98
111
  ...isServer || isBrowserEntry ? { linkAssets: { runtime: linkAssetsRuntimePath, onAsset } } : {},
99
112
  ...isServerEntry || isBrowserEntry ? { entry: "page" } : {},
113
+ ...isLoadEntry ? { entry: "load" } : {},
100
114
  // All outputs: the translator reports virtual dependencies through
101
115
  // this callback — hydrate boundaries (browser), and extracted
102
116
  // <style> blocks as `<file>.marko.css` deps (any output). Without
@@ -8,8 +8,13 @@ var linkAssetsRuntimePath = fileURLToPath(
8
8
  new URL("./link-assets-runtime.js", import.meta.url)
9
9
  );
10
10
  var ASSET_ID_REGISTRY = globalThis.__markopack_page_assets__ ??= /* @__PURE__ */ new Map();
11
- function onAsset(_kind, filename, assetId) {
12
- ASSET_ID_REGISTRY.set(filename, assetId);
11
+ var LOAD_ASSET_REGISTRY = globalThis.__markopack_load_assets__ ??= /* @__PURE__ */ new Map();
12
+ function onAsset(kind, filename, assetId) {
13
+ if (kind === "load") {
14
+ LOAD_ASSET_REGISTRY.set(filename, assetId);
15
+ } else {
16
+ ASSET_ID_REGISTRY.set(filename, assetId);
17
+ }
13
18
  }
14
19
  function makeResolveVirtualDependency(root) {
15
20
  const virtualDir = path.join(
@@ -27,7 +32,14 @@ function makeResolveVirtualDependency(root) {
27
32
  )}${path.extname(dep.virtualPath) ? "" : ".js"}`;
28
33
  const file = path.join(virtualDir, name);
29
34
  fs.mkdirSync(virtualDir, { recursive: true });
30
- fs.writeFileSync(file, dep.code);
35
+ const virtualModuleDir = path.dirname(
36
+ path.resolve(path.dirname(from), dep.virtualPath)
37
+ );
38
+ const code = dep.code.replace(
39
+ /(from\s*|import\s*\(\s*|import\s+)("|')((?:\.\.?\/)[^"']+)\2/g,
40
+ (_m, prefix, quote, specifier) => `${prefix}${quote}${path.join(virtualModuleDir, specifier)}${quote}`
41
+ );
42
+ fs.writeFileSync(file, code);
31
43
  return file;
32
44
  };
33
45
  }
@@ -38,8 +50,9 @@ function markoLoader(_source) {
38
50
  const query = this.resourceQuery || "";
39
51
  const isServerEntry = /^\?server-entry/.test(query);
40
52
  const isBrowserEntry = /^\?browser-entry/.test(query);
53
+ const isLoadEntry = /^\?load-entry/.test(query);
41
54
  const isServer = !isBrowserEntry;
42
- const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : options.output || "dom";
55
+ const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : isLoadEntry ? "dom" : options.output || "dom";
43
56
  const compilerPath = options.compiler;
44
57
  const translator = options.translator || bundledTranslator;
45
58
  Promise.resolve().then(async () => {
@@ -57,6 +70,7 @@ function markoLoader(_source) {
57
70
  output: outputFormat,
58
71
  ...isServer || isBrowserEntry ? { linkAssets: { runtime: linkAssetsRuntimePath, onAsset } } : {},
59
72
  ...isServerEntry || isBrowserEntry ? { entry: "page" } : {},
73
+ ...isLoadEntry ? { entry: "load" } : {},
60
74
  // All outputs: the translator reports virtual dependencies through
61
75
  // this callback — hydrate boundaries (browser), and extracted
62
76
  // <style> blocks as `<file>.marko.css` deps (any output). Without
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markopack/compiler",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Marko compiler plugin for rspack (used by @markopack/rspack)",
5
5
  "type": "module",
6
6
  "sideEffects": false,