@markopack/compiler 0.1.5 → 0.2.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 +11 -69
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -69
- package/dist/link-assets-runtime.cjs +35 -0
- package/dist/link-assets-runtime.d.cts +19 -0
- package/dist/link-assets-runtime.d.ts +19 -0
- package/dist/link-assets-runtime.js +10 -0
- package/dist/marko-loader.cjs +47 -1
- package/dist/marko-loader.js +42 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -81,20 +81,16 @@ var MarkoRspackPlugin = class {
|
|
|
81
81
|
}
|
|
82
82
|
browserApply(compiler) {
|
|
83
83
|
this.browserCompilers.push(compiler);
|
|
84
|
-
this.applyBrowser(compiler);
|
|
85
84
|
this.setupRules(compiler);
|
|
86
|
-
|
|
85
|
+
this.applyBrowser(compiler);
|
|
87
86
|
}
|
|
88
87
|
serverApply(compiler) {
|
|
89
88
|
this.serverCompiler = compiler;
|
|
90
|
-
this.applyServer(compiler);
|
|
91
89
|
this.setupRules(compiler);
|
|
90
|
+
this.applyServer(compiler);
|
|
92
91
|
compiler.options.entry = this.getEntryPoints(compiler);
|
|
93
92
|
}
|
|
94
93
|
applyDependencies(multiCompiler, isWatch) {
|
|
95
|
-
if (!this.needsManifestSync) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
94
|
if (isWatch) {
|
|
99
95
|
this.entriesReady = this.createDeferredPromise();
|
|
100
96
|
return;
|
|
@@ -111,6 +107,14 @@ var MarkoRspackPlugin = class {
|
|
|
111
107
|
get entriesReadyPromise() {
|
|
112
108
|
return this.entriesReady;
|
|
113
109
|
}
|
|
110
|
+
/** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
|
|
111
|
+
get discoveredClientEntries() {
|
|
112
|
+
return this.clientEntries;
|
|
113
|
+
}
|
|
114
|
+
/** Browser compilation output files per entry (compiler name → entry id → files by extension). */
|
|
115
|
+
get collectedClientAssets() {
|
|
116
|
+
return this.clientAssets;
|
|
117
|
+
}
|
|
114
118
|
setup(api) {
|
|
115
119
|
this._api = api;
|
|
116
120
|
}
|
|
@@ -195,7 +199,7 @@ var MarkoRspackPlugin = class {
|
|
|
195
199
|
}
|
|
196
200
|
this.needsManifestSync = true;
|
|
197
201
|
const filename = resource.replace(/\?server-entry$/, "");
|
|
198
|
-
const entryTemplateId = module_name_default(filename);
|
|
202
|
+
const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
|
|
199
203
|
if (!removedEntryIds.delete(entryTemplateId)) {
|
|
200
204
|
hasChangedEntries = true;
|
|
201
205
|
this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
|
|
@@ -216,68 +220,6 @@ var MarkoRspackPlugin = class {
|
|
|
216
220
|
this.entriesReady.resolve();
|
|
217
221
|
}
|
|
218
222
|
);
|
|
219
|
-
compilation.hooks.processAssets.tapPromise(
|
|
220
|
-
{
|
|
221
|
-
name: "MarkoRspackServer:processAssets",
|
|
222
|
-
stage: -100
|
|
223
|
-
},
|
|
224
|
-
async () => {
|
|
225
|
-
if (!this.needsManifestSync || !Object.keys(this.clientEntries).length) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
await Promise.all(
|
|
229
|
-
this.browserCompilers.map(
|
|
230
|
-
(browserCompiler) => browserCompiler.markoAssetsPending
|
|
231
|
-
)
|
|
232
|
-
);
|
|
233
|
-
const clientAssets = this.sortKeys(this.clientAssets);
|
|
234
|
-
let placeholderFound = false;
|
|
235
|
-
for (const chunk of compilation.chunks) {
|
|
236
|
-
if (!chunk.canBeInitial()) {
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
for (const file of chunk.files) {
|
|
240
|
-
compilation.updateAsset(file, (old) => {
|
|
241
|
-
const placeholder = "MARKO_MANIFEST_PLACEHOLDER";
|
|
242
|
-
const placeholderPosition = old.source().toString().indexOf(placeholder);
|
|
243
|
-
if (placeholderPosition < 0) {
|
|
244
|
-
return old;
|
|
245
|
-
}
|
|
246
|
-
placeholderFound = true;
|
|
247
|
-
const hasMultipleBuilds = this.browserCompilers.length > 1;
|
|
248
|
-
const defaultBuild = this.browserCompilers.length > 0 && this.browserCompilers[0].name ? clientAssets[this.browserCompilers[0].name] || {} : {};
|
|
249
|
-
const content = hasMultipleBuilds ? `{
|
|
250
|
-
getAssets(entry, buildName) {
|
|
251
|
-
const buildAssets = this.builds[buildName];
|
|
252
|
-
if (!buildAssets) {
|
|
253
|
-
throw new Error("Unable to load assets for build with a '$global.buildName' of '" + buildName + "'.");
|
|
254
|
-
}
|
|
255
|
-
return buildAssets[entry] || {};
|
|
256
|
-
},
|
|
257
|
-
builds: ${JSON.stringify(clientAssets)}
|
|
258
|
-
}` : `{
|
|
259
|
-
getAssets(entry) {
|
|
260
|
-
return this.build[entry] || {};
|
|
261
|
-
},
|
|
262
|
-
build: ${JSON.stringify(defaultBuild)}
|
|
263
|
-
}`;
|
|
264
|
-
const newSource = new import_core.sources.ReplaceSource(old);
|
|
265
|
-
newSource.replace(
|
|
266
|
-
placeholderPosition,
|
|
267
|
-
placeholderPosition + placeholder.length - 1,
|
|
268
|
-
content
|
|
269
|
-
);
|
|
270
|
-
return newSource;
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (Object.keys(this.clientEntries).length > 0 && !placeholderFound) {
|
|
275
|
-
throw new Error(
|
|
276
|
-
"Unable to inject the Marko manifest because the server bundle did not contain MARKO_MANIFEST_PLACEHOLDER."
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
223
|
}
|
|
282
224
|
);
|
|
283
225
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -38,6 +38,10 @@ declare class MarkoRspackPlugin {
|
|
|
38
38
|
serverApply(compiler: Compiler): void;
|
|
39
39
|
applyDependencies(multiCompiler: Compiler, isWatch: boolean): void;
|
|
40
40
|
get entriesReadyPromise(): ResolvablePromise<void>;
|
|
41
|
+
/** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
|
|
42
|
+
get discoveredClientEntries(): Record<string, string>;
|
|
43
|
+
/** Browser compilation output files per entry (compiler name → entry id → files by extension). */
|
|
44
|
+
get collectedClientAssets(): Record<string, Record<string, Record<string, string[]>>>;
|
|
41
45
|
setup(api: any): void;
|
|
42
46
|
private getEntryPoints;
|
|
43
47
|
private setupRules;
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ declare class MarkoRspackPlugin {
|
|
|
38
38
|
serverApply(compiler: Compiler): void;
|
|
39
39
|
applyDependencies(multiCompiler: Compiler, isWatch: boolean): void;
|
|
40
40
|
get entriesReadyPromise(): ResolvablePromise<void>;
|
|
41
|
+
/** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
|
|
42
|
+
get discoveredClientEntries(): Record<string, string>;
|
|
43
|
+
/** Browser compilation output files per entry (compiler name → entry id → files by extension). */
|
|
44
|
+
get collectedClientAssets(): Record<string, Record<string, Record<string, string[]>>>;
|
|
41
45
|
setup(api: any): void;
|
|
42
46
|
private getEntryPoints;
|
|
43
47
|
private setupRules;
|
package/dist/index.js
CHANGED
|
@@ -41,20 +41,16 @@ var MarkoRspackPlugin = class {
|
|
|
41
41
|
}
|
|
42
42
|
browserApply(compiler) {
|
|
43
43
|
this.browserCompilers.push(compiler);
|
|
44
|
-
this.applyBrowser(compiler);
|
|
45
44
|
this.setupRules(compiler);
|
|
46
|
-
|
|
45
|
+
this.applyBrowser(compiler);
|
|
47
46
|
}
|
|
48
47
|
serverApply(compiler) {
|
|
49
48
|
this.serverCompiler = compiler;
|
|
50
|
-
this.applyServer(compiler);
|
|
51
49
|
this.setupRules(compiler);
|
|
50
|
+
this.applyServer(compiler);
|
|
52
51
|
compiler.options.entry = this.getEntryPoints(compiler);
|
|
53
52
|
}
|
|
54
53
|
applyDependencies(multiCompiler, isWatch) {
|
|
55
|
-
if (!this.needsManifestSync) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
54
|
if (isWatch) {
|
|
59
55
|
this.entriesReady = this.createDeferredPromise();
|
|
60
56
|
return;
|
|
@@ -71,6 +67,14 @@ var MarkoRspackPlugin = class {
|
|
|
71
67
|
get entriesReadyPromise() {
|
|
72
68
|
return this.entriesReady;
|
|
73
69
|
}
|
|
70
|
+
/** Page entry modules discovered on the server compiler (id → resource with ?browser-entry). */
|
|
71
|
+
get discoveredClientEntries() {
|
|
72
|
+
return this.clientEntries;
|
|
73
|
+
}
|
|
74
|
+
/** Browser compilation output files per entry (compiler name → entry id → files by extension). */
|
|
75
|
+
get collectedClientAssets() {
|
|
76
|
+
return this.clientAssets;
|
|
77
|
+
}
|
|
74
78
|
setup(api) {
|
|
75
79
|
this._api = api;
|
|
76
80
|
}
|
|
@@ -155,7 +159,7 @@ var MarkoRspackPlugin = class {
|
|
|
155
159
|
}
|
|
156
160
|
this.needsManifestSync = true;
|
|
157
161
|
const filename = resource.replace(/\?server-entry$/, "");
|
|
158
|
-
const entryTemplateId = module_name_default(filename);
|
|
162
|
+
const entryTemplateId = module_name_default(filename).replace(/^\.+/, "");
|
|
159
163
|
if (!removedEntryIds.delete(entryTemplateId)) {
|
|
160
164
|
hasChangedEntries = true;
|
|
161
165
|
this.clientEntries[entryTemplateId] = `${filename}?browser-entry`;
|
|
@@ -176,68 +180,6 @@ var MarkoRspackPlugin = class {
|
|
|
176
180
|
this.entriesReady.resolve();
|
|
177
181
|
}
|
|
178
182
|
);
|
|
179
|
-
compilation.hooks.processAssets.tapPromise(
|
|
180
|
-
{
|
|
181
|
-
name: "MarkoRspackServer:processAssets",
|
|
182
|
-
stage: -100
|
|
183
|
-
},
|
|
184
|
-
async () => {
|
|
185
|
-
if (!this.needsManifestSync || !Object.keys(this.clientEntries).length) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
await Promise.all(
|
|
189
|
-
this.browserCompilers.map(
|
|
190
|
-
(browserCompiler) => browserCompiler.markoAssetsPending
|
|
191
|
-
)
|
|
192
|
-
);
|
|
193
|
-
const clientAssets = this.sortKeys(this.clientAssets);
|
|
194
|
-
let placeholderFound = false;
|
|
195
|
-
for (const chunk of compilation.chunks) {
|
|
196
|
-
if (!chunk.canBeInitial()) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
for (const file of chunk.files) {
|
|
200
|
-
compilation.updateAsset(file, (old) => {
|
|
201
|
-
const placeholder = "MARKO_MANIFEST_PLACEHOLDER";
|
|
202
|
-
const placeholderPosition = old.source().toString().indexOf(placeholder);
|
|
203
|
-
if (placeholderPosition < 0) {
|
|
204
|
-
return old;
|
|
205
|
-
}
|
|
206
|
-
placeholderFound = true;
|
|
207
|
-
const hasMultipleBuilds = this.browserCompilers.length > 1;
|
|
208
|
-
const defaultBuild = this.browserCompilers.length > 0 && this.browserCompilers[0].name ? clientAssets[this.browserCompilers[0].name] || {} : {};
|
|
209
|
-
const content = hasMultipleBuilds ? `{
|
|
210
|
-
getAssets(entry, buildName) {
|
|
211
|
-
const buildAssets = this.builds[buildName];
|
|
212
|
-
if (!buildAssets) {
|
|
213
|
-
throw new Error("Unable to load assets for build with a '$global.buildName' of '" + buildName + "'.");
|
|
214
|
-
}
|
|
215
|
-
return buildAssets[entry] || {};
|
|
216
|
-
},
|
|
217
|
-
builds: ${JSON.stringify(clientAssets)}
|
|
218
|
-
}` : `{
|
|
219
|
-
getAssets(entry) {
|
|
220
|
-
return this.build[entry] || {};
|
|
221
|
-
},
|
|
222
|
-
build: ${JSON.stringify(defaultBuild)}
|
|
223
|
-
}`;
|
|
224
|
-
const newSource = new sources.ReplaceSource(old);
|
|
225
|
-
newSource.replace(
|
|
226
|
-
placeholderPosition,
|
|
227
|
-
placeholderPosition + placeholder.length - 1,
|
|
228
|
-
content
|
|
229
|
-
);
|
|
230
|
-
return newSource;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (Object.keys(this.clientEntries).length > 0 && !placeholderFound) {
|
|
235
|
-
throw new Error(
|
|
236
|
-
"Unable to inject the Marko manifest because the server bundle did not contain MARKO_MANIFEST_PLACEHOLDER."
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
);
|
|
241
183
|
}
|
|
242
184
|
);
|
|
243
185
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/link-assets-runtime.ts
|
|
21
|
+
var link_assets_runtime_exports = {};
|
|
22
|
+
__export(link_assets_runtime_exports, {
|
|
23
|
+
flush: () => flush
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(link_assets_runtime_exports);
|
|
26
|
+
var manifest = globalThis.__MARKO_MANIFEST__ ??= JSON.parse("MARKO_MANIFEST_PLACEHOLDER");
|
|
27
|
+
function flush(_global, type, assetId) {
|
|
28
|
+
const entry = manifest[assetId];
|
|
29
|
+
if (!entry) return "";
|
|
30
|
+
return type === "block" ? entry.block ?? "" : entry.defer ?? "";
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
flush
|
|
35
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime module referenced by `linkAssets`-compiled Marko templates.
|
|
3
|
+
*
|
|
4
|
+
* When markopack compiles a page entry with the `linkAssets` compiler option,
|
|
5
|
+
* the generated code imports `flush` from this module and the html runtime's
|
|
6
|
+
* `withPageAssets` wrapper calls it while rendering:
|
|
7
|
+
*
|
|
8
|
+
* - `type === "block"` → html written at the start of `<head>` (stylesheets)
|
|
9
|
+
* - `type === "defer"` → html written before the hydration bootstrap (scripts)
|
|
10
|
+
*
|
|
11
|
+
* The asset → html mapping lives in a manifest that is injected after the
|
|
12
|
+
* build completes (packages/rspack) by replacing the placeholder string
|
|
13
|
+
* below — the JSON.parse call keeps the literal from being constant-folded
|
|
14
|
+
* away by minification. Dev mode instead populates
|
|
15
|
+
* `globalThis.__MARKO_MANIFEST__` before rendering.
|
|
16
|
+
*/
|
|
17
|
+
declare function flush(_global: unknown, type: "block" | "defer", assetId: string): string;
|
|
18
|
+
|
|
19
|
+
export { flush };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime module referenced by `linkAssets`-compiled Marko templates.
|
|
3
|
+
*
|
|
4
|
+
* When markopack compiles a page entry with the `linkAssets` compiler option,
|
|
5
|
+
* the generated code imports `flush` from this module and the html runtime's
|
|
6
|
+
* `withPageAssets` wrapper calls it while rendering:
|
|
7
|
+
*
|
|
8
|
+
* - `type === "block"` → html written at the start of `<head>` (stylesheets)
|
|
9
|
+
* - `type === "defer"` → html written before the hydration bootstrap (scripts)
|
|
10
|
+
*
|
|
11
|
+
* The asset → html mapping lives in a manifest that is injected after the
|
|
12
|
+
* build completes (packages/rspack) by replacing the placeholder string
|
|
13
|
+
* below — the JSON.parse call keeps the literal from being constant-folded
|
|
14
|
+
* away by minification. Dev mode instead populates
|
|
15
|
+
* `globalThis.__MARKO_MANIFEST__` before rendering.
|
|
16
|
+
*/
|
|
17
|
+
declare function flush(_global: unknown, type: "block" | "defer", assetId: string): string;
|
|
18
|
+
|
|
19
|
+
export { flush };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/link-assets-runtime.ts
|
|
2
|
+
var manifest = globalThis.__MARKO_MANIFEST__ ??= JSON.parse("MARKO_MANIFEST_PLACEHOLDER");
|
|
3
|
+
function flush(_global, type, assetId) {
|
|
4
|
+
const entry = manifest[assetId];
|
|
5
|
+
if (!entry) return "";
|
|
6
|
+
return type === "block" ? entry.block ?? "" : entry.defer ?? "";
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
flush
|
|
10
|
+
};
|
package/dist/marko-loader.cjs
CHANGED
|
@@ -33,16 +33,53 @@ __export(marko_loader_exports, {
|
|
|
33
33
|
default: () => markoLoader
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(marko_loader_exports);
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
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
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
41
|
+
// src/marko-loader.ts
|
|
36
42
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
37
43
|
var import_node_path = __toESM(require("path"), 1);
|
|
38
44
|
var import_node_url = require("url");
|
|
39
45
|
var bundledMarkoCompiler = __toESM(require("@marko/compiler"), 1);
|
|
40
46
|
var import_translator = __toESM(require("@marko/runtime-tags/translator"), 1);
|
|
47
|
+
var linkAssetsRuntimePath = (0, import_node_url.fileURLToPath)(
|
|
48
|
+
new URL("./link-assets-runtime.js", importMetaUrl)
|
|
49
|
+
);
|
|
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);
|
|
53
|
+
}
|
|
54
|
+
function makeResolveVirtualDependency(root) {
|
|
55
|
+
const virtualDir = import_node_path.default.join(
|
|
56
|
+
root,
|
|
57
|
+
"node_modules",
|
|
58
|
+
".cache",
|
|
59
|
+
"markopack",
|
|
60
|
+
"virtual"
|
|
61
|
+
);
|
|
62
|
+
return (from, dep) => {
|
|
63
|
+
const fromId = import_node_path.default.relative(root, from).replace(/[^a-z0-9_.-]+/gi, "_").replace(/^_+|_+$/g, "");
|
|
64
|
+
const name = `${fromId}__${dep.virtualPath.replace(
|
|
65
|
+
/[^a-z0-9_.-]+/gi,
|
|
66
|
+
"_"
|
|
67
|
+
)}.js`;
|
|
68
|
+
const file = import_node_path.default.join(virtualDir, name);
|
|
69
|
+
import_node_fs.default.mkdirSync(virtualDir, { recursive: true });
|
|
70
|
+
import_node_fs.default.writeFileSync(file, dep.code);
|
|
71
|
+
return file;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
41
74
|
function markoLoader(_source) {
|
|
42
75
|
const callback = this.async();
|
|
43
76
|
const options = this.getOptions() || {};
|
|
44
77
|
const filename = this.resourcePath;
|
|
45
|
-
const
|
|
78
|
+
const query = this.resourceQuery || "";
|
|
79
|
+
const isServerEntry = /^\?server-entry/.test(query);
|
|
80
|
+
const isBrowserEntry = /^\?browser-entry/.test(query);
|
|
81
|
+
const isServer = !isBrowserEntry;
|
|
82
|
+
const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : options.output || "dom";
|
|
46
83
|
const compilerPath = options.compiler;
|
|
47
84
|
const translator = options.translator || import_translator.default;
|
|
48
85
|
Promise.resolve().then(async () => {
|
|
@@ -58,6 +95,15 @@ function markoLoader(_source) {
|
|
|
58
95
|
translator,
|
|
59
96
|
modules: options.modules || "esm",
|
|
60
97
|
output: outputFormat,
|
|
98
|
+
...isServer || isBrowserEntry ? { linkAssets: { runtime: linkAssetsRuntimePath, onAsset } } : {},
|
|
99
|
+
...isServerEntry || isBrowserEntry ? { entry: "page" } : {},
|
|
100
|
+
...outputFormat === "hydrate" ? {
|
|
101
|
+
// `root` exists at runtime but is missing from rspack's
|
|
102
|
+
// LoaderContext typings.
|
|
103
|
+
resolveVirtualDependency: makeResolveVirtualDependency(
|
|
104
|
+
this.root || process.cwd()
|
|
105
|
+
)
|
|
106
|
+
} : {},
|
|
61
107
|
...options.babelConfig ? { babelConfig: options.babelConfig } : {},
|
|
62
108
|
sourceMaps: options.sourceMaps ?? false,
|
|
63
109
|
writeVersionComment: false,
|
package/dist/marko-loader.js
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
1
|
// src/marko-loader.ts
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { pathToFileURL } from "url";
|
|
4
|
+
import { pathToFileURL, fileURLToPath } from "url";
|
|
5
5
|
import * as bundledMarkoCompiler from "@marko/compiler";
|
|
6
6
|
import bundledTranslator from "@marko/runtime-tags/translator";
|
|
7
|
+
var linkAssetsRuntimePath = fileURLToPath(
|
|
8
|
+
new URL("./link-assets-runtime.js", import.meta.url)
|
|
9
|
+
);
|
|
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);
|
|
13
|
+
}
|
|
14
|
+
function makeResolveVirtualDependency(root) {
|
|
15
|
+
const virtualDir = path.join(
|
|
16
|
+
root,
|
|
17
|
+
"node_modules",
|
|
18
|
+
".cache",
|
|
19
|
+
"markopack",
|
|
20
|
+
"virtual"
|
|
21
|
+
);
|
|
22
|
+
return (from, dep) => {
|
|
23
|
+
const fromId = path.relative(root, from).replace(/[^a-z0-9_.-]+/gi, "_").replace(/^_+|_+$/g, "");
|
|
24
|
+
const name = `${fromId}__${dep.virtualPath.replace(
|
|
25
|
+
/[^a-z0-9_.-]+/gi,
|
|
26
|
+
"_"
|
|
27
|
+
)}.js`;
|
|
28
|
+
const file = path.join(virtualDir, name);
|
|
29
|
+
fs.mkdirSync(virtualDir, { recursive: true });
|
|
30
|
+
fs.writeFileSync(file, dep.code);
|
|
31
|
+
return file;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
7
34
|
function markoLoader(_source) {
|
|
8
35
|
const callback = this.async();
|
|
9
36
|
const options = this.getOptions() || {};
|
|
10
37
|
const filename = this.resourcePath;
|
|
11
|
-
const
|
|
38
|
+
const query = this.resourceQuery || "";
|
|
39
|
+
const isServerEntry = /^\?server-entry/.test(query);
|
|
40
|
+
const isBrowserEntry = /^\?browser-entry/.test(query);
|
|
41
|
+
const isServer = !isBrowserEntry;
|
|
42
|
+
const outputFormat = isBrowserEntry ? "hydrate" : isServerEntry ? "html" : options.output || "dom";
|
|
12
43
|
const compilerPath = options.compiler;
|
|
13
44
|
const translator = options.translator || bundledTranslator;
|
|
14
45
|
Promise.resolve().then(async () => {
|
|
@@ -24,6 +55,15 @@ function markoLoader(_source) {
|
|
|
24
55
|
translator,
|
|
25
56
|
modules: options.modules || "esm",
|
|
26
57
|
output: outputFormat,
|
|
58
|
+
...isServer || isBrowserEntry ? { linkAssets: { runtime: linkAssetsRuntimePath, onAsset } } : {},
|
|
59
|
+
...isServerEntry || isBrowserEntry ? { entry: "page" } : {},
|
|
60
|
+
...outputFormat === "hydrate" ? {
|
|
61
|
+
// `root` exists at runtime but is missing from rspack's
|
|
62
|
+
// LoaderContext typings.
|
|
63
|
+
resolveVirtualDependency: makeResolveVirtualDependency(
|
|
64
|
+
this.root || process.cwd()
|
|
65
|
+
)
|
|
66
|
+
} : {},
|
|
27
67
|
...options.babelConfig ? { babelConfig: options.babelConfig } : {},
|
|
28
68
|
sourceMaps: options.sourceMaps ?? false,
|
|
29
69
|
writeVersionComment: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markopack/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Marko compiler plugin for rspack (used by @markopack/rspack)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"build": "tsup"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@marko/compiler": "^5.
|
|
45
|
-
"@marko/runtime-tags": "^6.
|
|
44
|
+
"@marko/compiler": "^5.42.11",
|
|
45
|
+
"@marko/runtime-tags": "^6.4.5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@rspack/core": "^2.0.1",
|