@markless/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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/preload.d.ts +79 -0
- package/dist/preload.js +75 -0
- package/dist/rolldown-Czh1duwk.js +1802 -0
- package/dist/rolldown.d.ts +79 -0
- package/dist/rolldown.js +3 -0
- package/dist/source-module-BRb5P7wL.d.ts +6 -0
- package/dist/source-module-CSRzW4Ny.js +876 -0
- package/dist/types-D6KerlYq.d.ts +107 -0
- package/dist/vite.d.ts +12 -0
- package/dist/vite.js +387 -0
- package/package.json +55 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as _$_markless_compiler0 from "@markless/compiler";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type MarklessEnvironment = 'client' | 'server' | 'lib';
|
|
5
|
+
type MarklessClientOutput = 'full' | 'symbols-only';
|
|
6
|
+
type MarklessExecutionLogMode = 'auto' | 'never' | 'always';
|
|
7
|
+
interface MarklessDevServer {
|
|
8
|
+
transformRequest: (url: string, environment: MarklessEnvironment) => Promise<unknown> | unknown;
|
|
9
|
+
}
|
|
10
|
+
interface MarklessRolldownOptions {
|
|
11
|
+
dev?: boolean;
|
|
12
|
+
devInjections?: GlobalInjections[];
|
|
13
|
+
devServer?: MarklessDevServer;
|
|
14
|
+
executionLog?: MarklessExecutionLogMode;
|
|
15
|
+
hmr?: boolean;
|
|
16
|
+
bundleGraphAdders?: Set<BundleGraphAdder>;
|
|
17
|
+
rootDir?: string;
|
|
18
|
+
buildId?: string;
|
|
19
|
+
}
|
|
20
|
+
type MarklessVirtualModuleType = 'payload' | 'resolver' | 'resume' | 'symbol' | 'style';
|
|
21
|
+
interface MarklessVirtualModule {
|
|
22
|
+
id: string;
|
|
23
|
+
type: MarklessVirtualModuleType;
|
|
24
|
+
source: string;
|
|
25
|
+
symbolId?: string;
|
|
26
|
+
exportName?: string;
|
|
27
|
+
}
|
|
28
|
+
interface TransformTsrxModuleInput {
|
|
29
|
+
filename: string;
|
|
30
|
+
source: string;
|
|
31
|
+
devResumeReexport?: boolean;
|
|
32
|
+
buildId?: string;
|
|
33
|
+
environment?: MarklessEnvironment;
|
|
34
|
+
clientOutput?: MarklessClientOutput;
|
|
35
|
+
resumeModuleUrl?: string;
|
|
36
|
+
headInjections?: GlobalInjections[];
|
|
37
|
+
executionLog?: MarklessExecutionLogMode;
|
|
38
|
+
executionLogModuleHooks?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface TransformTsrxModuleResult {
|
|
41
|
+
code: string;
|
|
42
|
+
map: null;
|
|
43
|
+
virtualModules: MarklessVirtualModule[];
|
|
44
|
+
manifest: MarklessTransformManifest;
|
|
45
|
+
}
|
|
46
|
+
interface MarklessTransformManifest {
|
|
47
|
+
source: string;
|
|
48
|
+
payload: MarklessBuildModuleReference;
|
|
49
|
+
resolver: MarklessBuildModuleReference;
|
|
50
|
+
symbols: MarklessSymbolManifestEntry[];
|
|
51
|
+
runtimeDemandMap?: RuntimeDemandMapManifest;
|
|
52
|
+
}
|
|
53
|
+
interface MarklessBuildModuleReference {
|
|
54
|
+
virtualModuleId: string;
|
|
55
|
+
fileName?: string;
|
|
56
|
+
}
|
|
57
|
+
interface MarklessSymbolManifestEntry extends MarklessBuildModuleReference {
|
|
58
|
+
symbolId: string;
|
|
59
|
+
exportName: string;
|
|
60
|
+
kind: string;
|
|
61
|
+
}
|
|
62
|
+
type RuntimeDemandMapManifest = Omit<_$_markless_compiler0.RuntimeDemandMapArtifact, 'passId'>;
|
|
63
|
+
interface MarklessBuildMetadata {
|
|
64
|
+
version: number;
|
|
65
|
+
modules: MarklessTransformManifest[];
|
|
66
|
+
bundles: Record<string, MarklessBundle>;
|
|
67
|
+
assets?: Record<string, MarklessAsset>;
|
|
68
|
+
bundleGraph?: MarklessBundleGraph;
|
|
69
|
+
bundleGraphAsset?: string;
|
|
70
|
+
injections?: GlobalInjections[];
|
|
71
|
+
}
|
|
72
|
+
type MarklessManifest = MarklessBuildMetadata;
|
|
73
|
+
interface MarklessBundle {
|
|
74
|
+
size: number;
|
|
75
|
+
total: number;
|
|
76
|
+
symbols?: string[];
|
|
77
|
+
imports?: string[];
|
|
78
|
+
dynamicImports?: string[];
|
|
79
|
+
origins?: string[];
|
|
80
|
+
}
|
|
81
|
+
type MarklessAsset = {
|
|
82
|
+
name: string | undefined;
|
|
83
|
+
size: number;
|
|
84
|
+
};
|
|
85
|
+
type GlobalInjections = {
|
|
86
|
+
tag: string;
|
|
87
|
+
attributes?: Record<string, string>;
|
|
88
|
+
children?: string;
|
|
89
|
+
location: 'head' | 'body';
|
|
90
|
+
};
|
|
91
|
+
type MarklessBundleGraph = Array<string | number>;
|
|
92
|
+
type PreloadGraphEntries = Record<string, {
|
|
93
|
+
imports?: string[];
|
|
94
|
+
dynamicImports?: string[];
|
|
95
|
+
}>;
|
|
96
|
+
interface PreloadGraphContext {
|
|
97
|
+
readonly manifest: MarklessBuildMetadata;
|
|
98
|
+
readonly hasBundle: (bundleName: string) => boolean;
|
|
99
|
+
readonly bundlesForOrigins: (origins: readonly string[]) => string[];
|
|
100
|
+
}
|
|
101
|
+
type PreloadGraphEntriesAdder = (context: PreloadGraphContext) => PreloadGraphEntries | undefined;
|
|
102
|
+
type BundleGraphAdder = (manifest: MarklessBuildMetadata) => PreloadGraphEntries | undefined;
|
|
103
|
+
type MarklessRolldownPluginApi = {
|
|
104
|
+
invalidateGeneratedModules: (parent: string, environment?: MarklessEnvironment) => string[];
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { TransformTsrxModuleInput as _, MarklessBundle as a, MarklessEnvironment as c, MarklessRolldownPluginApi as d, MarklessTransformManifest as f, PreloadGraphEntriesAdder as g, PreloadGraphEntries as h, MarklessBuildMetadata as i, MarklessManifest as l, PreloadGraphContext as m, GlobalInjections as n, MarklessBundleGraph as o, MarklessVirtualModule as p, MarklessAsset as r, MarklessDevServer as s, BundleGraphAdder as t, MarklessRolldownOptions as u, TransformTsrxModuleResult as v };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { c as MarklessEnvironment, g as PreloadGraphEntriesAdder, h as PreloadGraphEntries, i as MarklessBuildMetadata, l as MarklessManifest, m as PreloadGraphContext, n as GlobalInjections, t as BundleGraphAdder, u as MarklessRolldownOptions } from "./types-D6KerlYq.js";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/vite/index.d.ts
|
|
5
|
+
interface MarklessViteOptions extends MarklessRolldownOptions {
|
|
6
|
+
clientEnvironment?: string;
|
|
7
|
+
serverEnvironment?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function markless(options?: MarklessViteOptions): Plugin[];
|
|
10
|
+
type MarklessVitePlugin = ReturnType<typeof markless>[number];
|
|
11
|
+
//#endregion
|
|
12
|
+
export { type BundleGraphAdder, type GlobalInjections, type MarklessBuildMetadata, type MarklessEnvironment, type MarklessManifest, type MarklessRolldownOptions, MarklessViteOptions, MarklessVitePlugin, type PreloadGraphContext, type PreloadGraphEntries, type PreloadGraphEntriesAdder, markless };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { b as outputDefaults, p as executionLogActivationInjection } from "./source-module-CSRzW4Ny.js";
|
|
2
|
+
import { l as createPreloadGraphAdder, t as createMarklessRolldownPlugin } from "./rolldown-Czh1duwk.js";
|
|
3
|
+
import { joinURL, parsePath } from "ufo";
|
|
4
|
+
//#region src/vite/dev-tags.ts
|
|
5
|
+
function createDevTags() {
|
|
6
|
+
const tags = [];
|
|
7
|
+
let viteTagsAdded = false;
|
|
8
|
+
return {
|
|
9
|
+
tags,
|
|
10
|
+
register(tag) {
|
|
11
|
+
tags.push(tag);
|
|
12
|
+
},
|
|
13
|
+
registerViteTags(base) {
|
|
14
|
+
if (viteTagsAdded) return;
|
|
15
|
+
viteTagsAdded = true;
|
|
16
|
+
tags.unshift(headScript(base, "/@vite/client"));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function headScript(base, src) {
|
|
21
|
+
return {
|
|
22
|
+
tag: "script",
|
|
23
|
+
location: "head",
|
|
24
|
+
attributes: {
|
|
25
|
+
type: "module",
|
|
26
|
+
src: joinURL(base, src)
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/vite/environment.ts
|
|
32
|
+
const UNMANAGED_VITE_ENVIRONMENTS = new Set(["nitro"]);
|
|
33
|
+
function viteEnvironmentName(environment, options = {}) {
|
|
34
|
+
if (environment === "client") return options.clientEnvironment ?? "client";
|
|
35
|
+
if (environment === "server") return options.serverEnvironment ?? "ssr";
|
|
36
|
+
return environment;
|
|
37
|
+
}
|
|
38
|
+
function marklessEnvironment(environment) {
|
|
39
|
+
const config = environment?.config;
|
|
40
|
+
if (isUnmanagedViteEnvironment(environment)) return "lib";
|
|
41
|
+
if (!config) return "client";
|
|
42
|
+
if (config.build?.lib) return "lib";
|
|
43
|
+
if (isServerViteEnvironment(environment)) return "server";
|
|
44
|
+
return "client";
|
|
45
|
+
}
|
|
46
|
+
function isServerViteEnvironment(environment) {
|
|
47
|
+
if (isUnmanagedViteEnvironment(environment)) return false;
|
|
48
|
+
const consumer = environment?.config?.consumer;
|
|
49
|
+
if (consumer) return consumer === "server";
|
|
50
|
+
return environment?.name !== void 0 && environment.name !== "client";
|
|
51
|
+
}
|
|
52
|
+
function isUnmanagedViteEnvironment(environment) {
|
|
53
|
+
return !!environment?.name && UNMANAGED_VITE_ENVIRONMENTS.has(environment.name);
|
|
54
|
+
}
|
|
55
|
+
function transformMarklessRequest(server, url, environment, options) {
|
|
56
|
+
return server.environments[viteEnvironmentName(environment, options)]?.transformRequest(url);
|
|
57
|
+
}
|
|
58
|
+
function fetchableDevEnvironment(environment) {
|
|
59
|
+
if (!environment) return;
|
|
60
|
+
const maybeFetchable = environment;
|
|
61
|
+
if (typeof maybeFetchable.dispatchFetch === "function") return maybeFetchable;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/vite/hmr.ts
|
|
65
|
+
const SOURCE_FILE_EXTENSION = /\.tsrx(?:[?#].*)?$/;
|
|
66
|
+
function createViteHmr(options) {
|
|
67
|
+
let server;
|
|
68
|
+
return {
|
|
69
|
+
configureServer(nextServer) {
|
|
70
|
+
server = nextServer;
|
|
71
|
+
if (options.enabled) installFetchViteClient(nextServer, options);
|
|
72
|
+
},
|
|
73
|
+
transformIndexHtml() {},
|
|
74
|
+
resolveId(_id) {
|
|
75
|
+
return null;
|
|
76
|
+
},
|
|
77
|
+
load(_id) {
|
|
78
|
+
return null;
|
|
79
|
+
},
|
|
80
|
+
hotUpdate(environment, ctx) {
|
|
81
|
+
if (!environment) return;
|
|
82
|
+
const env = marklessEnvironment(environment);
|
|
83
|
+
if (env === "lib") return;
|
|
84
|
+
const hot = env === "server" ? server?.environments?.[options.clientEnvironment]?.hot : environment.hot;
|
|
85
|
+
if (!hot?.send) return;
|
|
86
|
+
if (!options.enabled) {
|
|
87
|
+
hot.send({ type: "full-reload" });
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const files = changedFiles(ctx.modules ?? []);
|
|
91
|
+
const root = server?.config?.root;
|
|
92
|
+
if (ctx.file && SOURCE_FILE_EXTENSION.test(ctx.file)) {
|
|
93
|
+
const prefix = root && `${root}/`;
|
|
94
|
+
files.add(prefix && ctx.file.startsWith(prefix) ? `/${ctx.file.slice(prefix.length)}` : ctx.file);
|
|
95
|
+
}
|
|
96
|
+
if (!files.size) return;
|
|
97
|
+
const invalidationEnvironments = moduleGraphEnvironments(environment, env === "server" ? server?.environments?.[options.clientEnvironment] : void 0);
|
|
98
|
+
for (const file of files) for (const candidate of hmrCandidates(file, ctx.file)) for (const id of options.invalidateGeneratedModules?.(candidate, env) ?? []) for (const targetEnvironment of invalidationEnvironments) {
|
|
99
|
+
const module = targetEnvironment.moduleGraph?.getModuleById?.(id);
|
|
100
|
+
if (!module) continue;
|
|
101
|
+
targetEnvironment.moduleGraph?.invalidateModule?.(module, /* @__PURE__ */ new Set(), ctx.timestamp, true);
|
|
102
|
+
}
|
|
103
|
+
hot.send({
|
|
104
|
+
type: "full-reload",
|
|
105
|
+
path: firstChangedFile(files),
|
|
106
|
+
triggeredBy: ctx.file
|
|
107
|
+
});
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function installFetchViteClient(server, options) {
|
|
113
|
+
for (const environment of Object.values(server.environments)) {
|
|
114
|
+
const fetchEnv = fetchableDevEnvironment(environment);
|
|
115
|
+
if (!fetchEnv) continue;
|
|
116
|
+
const dispatchFetch = fetchEnv.dispatchFetch.bind(fetchEnv);
|
|
117
|
+
fetchEnv.dispatchFetch = async (request) => {
|
|
118
|
+
const response = await dispatchFetch(request);
|
|
119
|
+
if (!response.headers.get("content-type")?.includes("text/html")) return response;
|
|
120
|
+
const html = await response.text();
|
|
121
|
+
const nextHtml = injectViteClient(html, options.base);
|
|
122
|
+
const headers = new Headers(response.headers);
|
|
123
|
+
if (nextHtml !== html) headers.delete("content-length");
|
|
124
|
+
return new Response(nextHtml, {
|
|
125
|
+
headers,
|
|
126
|
+
status: response.status,
|
|
127
|
+
statusText: response.statusText
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function injectViteClient(html, base) {
|
|
133
|
+
if (!html || html.includes("/@vite/client")) return html;
|
|
134
|
+
const tag = `<script type="module" src="${joinURL(base, "/@vite/client")}"><\/script>`;
|
|
135
|
+
if (html.includes("</head>")) return html.replace("</head>", `${tag}</head>`);
|
|
136
|
+
if (html.includes("<head>")) return html.replace("<head>", `<head>${tag}`);
|
|
137
|
+
return `${tag}${html}`;
|
|
138
|
+
}
|
|
139
|
+
function changedFiles(modules) {
|
|
140
|
+
const files = /* @__PURE__ */ new Set();
|
|
141
|
+
for (const module of modules) for (const item of [module, ...module.importers ?? []]) {
|
|
142
|
+
const url = sourceUrl(item);
|
|
143
|
+
if (url) files.add(url);
|
|
144
|
+
}
|
|
145
|
+
return files;
|
|
146
|
+
}
|
|
147
|
+
function sourceUrl(module) {
|
|
148
|
+
const url = parsePath(module.url).pathname;
|
|
149
|
+
if (module.type === "js" && SOURCE_FILE_EXTENSION.test(url)) return url;
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
function hmrCandidates(file, absoluteFile) {
|
|
153
|
+
const candidates = new Set([file]);
|
|
154
|
+
if (absoluteFile) candidates.add(absoluteFile);
|
|
155
|
+
return candidates;
|
|
156
|
+
}
|
|
157
|
+
function moduleGraphEnvironments(environment, clientEnvironment) {
|
|
158
|
+
if (!clientEnvironment || clientEnvironment === environment) return [environment];
|
|
159
|
+
return [environment, clientEnvironment];
|
|
160
|
+
}
|
|
161
|
+
function firstChangedFile(files) {
|
|
162
|
+
for (const file of files) return file;
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/vite/index.ts
|
|
166
|
+
const MARKLESS_SKIP_DUPLICATE_BUILDS = Symbol("markless-skip-duplicate-builds");
|
|
167
|
+
const TSRX_INPUT_FILE = /\.tsrx(?:[?#].*)?$/;
|
|
168
|
+
function markless(options = {}) {
|
|
169
|
+
let command = "build";
|
|
170
|
+
const bundleGraphAdders = /* @__PURE__ */ new Set();
|
|
171
|
+
const transformedTsrxSources = /* @__PURE__ */ new Map();
|
|
172
|
+
const rolldownOptions = { ...options };
|
|
173
|
+
rolldownOptions.bundleGraphAdders = bundleGraphAdders;
|
|
174
|
+
const hmrOptions = {
|
|
175
|
+
base: "/",
|
|
176
|
+
clientEnvironment: viteEnvironmentName("client", options),
|
|
177
|
+
enabled: false,
|
|
178
|
+
invalidateGeneratedModules: (parent, environment) => marklessPlugin.api.invalidateGeneratedModules(parent, environment)
|
|
179
|
+
};
|
|
180
|
+
const devTags = createDevTags();
|
|
181
|
+
rolldownOptions.devInjections = devTags.tags;
|
|
182
|
+
const basePlugin = createMarklessRolldownPlugin({
|
|
183
|
+
environment: getBuildEnvironment,
|
|
184
|
+
options: rolldownOptions
|
|
185
|
+
});
|
|
186
|
+
const hmr = createViteHmr(hmrOptions);
|
|
187
|
+
const marklessPlugin = {
|
|
188
|
+
...basePlugin,
|
|
189
|
+
name: "vite-plugin-markless",
|
|
190
|
+
enforce: "post",
|
|
191
|
+
sharedDuringBuild: true,
|
|
192
|
+
api: {
|
|
193
|
+
...basePlugin.api,
|
|
194
|
+
registerBundleGraphAdder: (adder) => bundleGraphAdders.add(adder),
|
|
195
|
+
registerDevInjection: (injection) => devTags.register(injection),
|
|
196
|
+
registerPreloadGraphEntries: (adder) => bundleGraphAdders.add(createPreloadGraphAdder(adder))
|
|
197
|
+
},
|
|
198
|
+
config(config, env) {
|
|
199
|
+
command = env.command;
|
|
200
|
+
configDefaults(config, options, rolldownOptions);
|
|
201
|
+
},
|
|
202
|
+
configResolved(resolvedConfig) {
|
|
203
|
+
const serve = resolvedConfig.command === "serve";
|
|
204
|
+
hmrOptions.base = resolvedConfig.base;
|
|
205
|
+
hmrOptions.enabled = serve && options.hmr !== false;
|
|
206
|
+
rolldownOptions.dev = serve;
|
|
207
|
+
rolldownOptions.rootDir = resolvedConfig.root;
|
|
208
|
+
rolldownOptions.publicPath = (fileName) => joinURL(resolvedConfig.base, fileName);
|
|
209
|
+
if (serve) devTags.registerViteTags(resolvedConfig.base);
|
|
210
|
+
},
|
|
211
|
+
configEnvironment(name, config) {
|
|
212
|
+
if (command === "serve") return;
|
|
213
|
+
const environment = configEnvironmentKind(name, config, options);
|
|
214
|
+
if (!environment) return;
|
|
215
|
+
const build = config.build ?? {};
|
|
216
|
+
const rolldownOptions = build.rolldownOptions ?? {};
|
|
217
|
+
const outDir = defaultOutDir(environment);
|
|
218
|
+
return { build: {
|
|
219
|
+
...build,
|
|
220
|
+
...environment === "client" ? { modulePreload: build.modulePreload ?? false } : {},
|
|
221
|
+
...build.outDir || !outDir ? {} : { outDir },
|
|
222
|
+
rolldownOptions: {
|
|
223
|
+
...rolldownOptions,
|
|
224
|
+
output: withOutputDefaults(rolldownOptions.output, environment)
|
|
225
|
+
}
|
|
226
|
+
} };
|
|
227
|
+
},
|
|
228
|
+
buildApp: {
|
|
229
|
+
order: "pre",
|
|
230
|
+
handler(builder) {
|
|
231
|
+
return buildMarklessEnvironments(builder, options);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
configureServer(server) {
|
|
235
|
+
rolldownOptions.devServer = { transformRequest: (url, environment) => transformMarklessRequest(server, url, environment, options) };
|
|
236
|
+
hmr.configureServer(server);
|
|
237
|
+
},
|
|
238
|
+
transformIndexHtml() {
|
|
239
|
+
const hmrResult = hmr.transformIndexHtml();
|
|
240
|
+
const injection = executionLogActivationInjection(rolldownOptions.executionLog);
|
|
241
|
+
if (!injection) return hmrResult;
|
|
242
|
+
const tag = {
|
|
243
|
+
tag: injection.tag,
|
|
244
|
+
injectTo: injection.location,
|
|
245
|
+
attrs: injection.attributes,
|
|
246
|
+
children: injection.children
|
|
247
|
+
};
|
|
248
|
+
return Array.isArray(hmrResult) ? [...hmrResult, tag] : [tag];
|
|
249
|
+
},
|
|
250
|
+
resolveId: {
|
|
251
|
+
order: "pre",
|
|
252
|
+
async handler(source, importer, opts) {
|
|
253
|
+
const hmrResolved = hmr.resolveId(source);
|
|
254
|
+
if (hmrResolved) return hmrResolved;
|
|
255
|
+
return runHook(basePlugin.resolveId, this, source, importer, opts);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
load(id, loadOptions) {
|
|
259
|
+
return hmr.load(id) ?? runHook(basePlugin.load, this, id, loadOptions);
|
|
260
|
+
},
|
|
261
|
+
transform: { async handler(code, id, transformOptions) {
|
|
262
|
+
if (rolldownOptions.dev === true && TSRX_INPUT_FILE.test(id)) transformedTsrxSources.set(parsePath(id).pathname, code);
|
|
263
|
+
return runHook(basePlugin.transform, this, code, id, transformOptions);
|
|
264
|
+
} },
|
|
265
|
+
async hotUpdate(ctx) {
|
|
266
|
+
if (await matchesTransformedTsrxSource(ctx, transformedTsrxSources)) return [];
|
|
267
|
+
return hmr.hotUpdate(this.environment, ctx);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
return [marklessPlugin];
|
|
271
|
+
}
|
|
272
|
+
async function buildMarklessEnvironments(builder, options) {
|
|
273
|
+
const environments = buildEnvironments(builder, options);
|
|
274
|
+
skipDuplicateBuilds(builder, environments.map((environment) => environment.name));
|
|
275
|
+
for (const environment of environments) if (!environment.isBuilt) await builder.build(environment);
|
|
276
|
+
}
|
|
277
|
+
function buildEnvironments(builder, options) {
|
|
278
|
+
const environments = /* @__PURE__ */ new Map();
|
|
279
|
+
for (const name of [viteEnvironmentName("client", options), viteEnvironmentName("server", options)]) {
|
|
280
|
+
const environment = builder.environments[name];
|
|
281
|
+
if (environment) environments.set(name, environment);
|
|
282
|
+
}
|
|
283
|
+
for (const environment of Object.values(builder.environments)) if (marklessEnvironment(environment) === "server") environments.set(environment.name, environment);
|
|
284
|
+
return [...environments.values()];
|
|
285
|
+
}
|
|
286
|
+
function skipDuplicateBuilds(builder, names) {
|
|
287
|
+
const guarded = builder;
|
|
288
|
+
const guardedNames = guarded[MARKLESS_SKIP_DUPLICATE_BUILDS] ?? /* @__PURE__ */ new Set();
|
|
289
|
+
for (const name of names) guardedNames.add(name);
|
|
290
|
+
if (guarded[MARKLESS_SKIP_DUPLICATE_BUILDS]) return;
|
|
291
|
+
guarded[MARKLESS_SKIP_DUPLICATE_BUILDS] = guardedNames;
|
|
292
|
+
const build = builder.build.bind(builder);
|
|
293
|
+
builder.build = (environment) => {
|
|
294
|
+
if (guardedNames.has(environment.name) && environment.isBuilt) return Promise.resolve([]);
|
|
295
|
+
return build(environment);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function configDefaults(config, options, internalOptions) {
|
|
299
|
+
const dynamicImportVars = (config.build ??= {}).dynamicImportVarsOptions ??= {};
|
|
300
|
+
dynamicImportVars.exclude = [...Array.isArray(dynamicImportVars.exclude) ? dynamicImportVars.exclude : dynamicImportVars.exclude ? [dynamicImportVars.exclude] : [], /\.tsrx(?:[?#]|$)/];
|
|
301
|
+
if (config.build?.lib || config.build?.ssr) return;
|
|
302
|
+
const build = config.build ??= {};
|
|
303
|
+
const ssrSymbolInput = ssrTsrxInput(config, options);
|
|
304
|
+
if (ssrSymbolInput) {
|
|
305
|
+
internalOptions.emitResumeModules = true;
|
|
306
|
+
const rolldownOptions = build.rolldownOptions ??= {};
|
|
307
|
+
rolldownOptions.input = withSsrSymbolInput(rolldownOptions.input, ssrSymbolInput);
|
|
308
|
+
}
|
|
309
|
+
build.modulePreload ??= false;
|
|
310
|
+
}
|
|
311
|
+
function ssrTsrxInput(config, options) {
|
|
312
|
+
const ssr = config.environments?.[viteEnvironmentName("server", options)];
|
|
313
|
+
return firstTsrxInput(ssr?.build?.rolldownOptions?.input);
|
|
314
|
+
}
|
|
315
|
+
function firstTsrxInput(input) {
|
|
316
|
+
if (typeof input === "string") return TSRX_INPUT_FILE.test(input) ? input : null;
|
|
317
|
+
if (Array.isArray(input)) {
|
|
318
|
+
for (const item of input) {
|
|
319
|
+
const match = firstTsrxInput(item);
|
|
320
|
+
if (match) return match;
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
if (input && typeof input === "object") for (const value of Object.values(input)) {
|
|
325
|
+
const match = firstTsrxInput(value);
|
|
326
|
+
if (match) return match;
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
function withSsrSymbolInput(input, ssrSymbolInput) {
|
|
331
|
+
if (isRolldownInputRecord(input)) {
|
|
332
|
+
if (Object.keys(input).some((name) => /symbol/i.test(name))) return input;
|
|
333
|
+
return {
|
|
334
|
+
...input,
|
|
335
|
+
symbols: ssrSymbolInput
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (typeof input === "string") {
|
|
339
|
+
const name = input.endsWith(".html") ? "index" : "app";
|
|
340
|
+
return input === ssrSymbolInput ? { symbols: ssrSymbolInput } : {
|
|
341
|
+
[name]: input,
|
|
342
|
+
symbols: ssrSymbolInput
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
if (Array.isArray(input)) return Object.fromEntries([...input.map((entry, index) => [`input${index}`, entry]), ["symbols", ssrSymbolInput]]);
|
|
346
|
+
return { symbols: ssrSymbolInput };
|
|
347
|
+
}
|
|
348
|
+
function isRolldownInputRecord(input) {
|
|
349
|
+
return !!input && typeof input === "object" && !Array.isArray(input);
|
|
350
|
+
}
|
|
351
|
+
function withOutputDefaults(output, environment) {
|
|
352
|
+
if (Array.isArray(output)) return output.map((item) => outputDefaults(item, environment));
|
|
353
|
+
if (!output) return outputDefaults({}, environment);
|
|
354
|
+
return outputDefaults(output, environment);
|
|
355
|
+
}
|
|
356
|
+
function defaultOutDir(environment) {
|
|
357
|
+
if (environment === "server") return "dist/server";
|
|
358
|
+
}
|
|
359
|
+
function configEnvironmentKind(name, config, options) {
|
|
360
|
+
if (config.build?.lib) return null;
|
|
361
|
+
if (name === viteEnvironmentName("client", options)) return "client";
|
|
362
|
+
if (name === viteEnvironmentName("server", options)) return "server";
|
|
363
|
+
if (isServerViteEnvironment({
|
|
364
|
+
name,
|
|
365
|
+
config
|
|
366
|
+
})) return "server";
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
async function matchesTransformedTsrxSource(ctx, transformedSources) {
|
|
370
|
+
if (!ctx.file || ctx.type === "delete" || typeof ctx.read !== "function") return false;
|
|
371
|
+
const transformedSource = transformedSources.get(ctx.file);
|
|
372
|
+
if (transformedSource === void 0) return false;
|
|
373
|
+
try {
|
|
374
|
+
return await ctx.read() === transformedSource;
|
|
375
|
+
} catch {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function runHook(hook, context, ...args) {
|
|
380
|
+
if (typeof hook !== "function") return null;
|
|
381
|
+
return hook.call(context, ...args);
|
|
382
|
+
}
|
|
383
|
+
function getBuildEnvironment(context) {
|
|
384
|
+
return marklessEnvironment(context.environment);
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
export { markless };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@markless/bundler",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Markless build plugins for Rolldown and Vite.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/markless-dev/markless.git",
|
|
9
|
+
"directory": "packages/bundler"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
"./preload": {
|
|
18
|
+
"types": "./dist/preload.d.ts",
|
|
19
|
+
"default": "./dist/preload.js"
|
|
20
|
+
},
|
|
21
|
+
"./rolldown": {
|
|
22
|
+
"types": "./dist/rolldown.d.ts",
|
|
23
|
+
"default": "./dist/rolldown.js"
|
|
24
|
+
},
|
|
25
|
+
"./vite": {
|
|
26
|
+
"types": "./dist/vite.d.ts",
|
|
27
|
+
"default": "./dist/vite.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@thi.ng/dgraph": "^2.1.205",
|
|
32
|
+
"pathe": "^2.0.3",
|
|
33
|
+
"ufo": "^1.6.4",
|
|
34
|
+
"@markless/compiler": "0.1.0",
|
|
35
|
+
"@markless/web": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"rolldown": "1.0.3",
|
|
39
|
+
"vite": "8.0.16"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"rolldown": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"vite": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"test:boxes": "witness run"
|
|
54
|
+
}
|
|
55
|
+
}
|