@danielx/civet 0.6.89 → 0.6.91
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/README.md +1 -2
- package/dist/astro.d.mts +15 -0
- package/dist/astro.d.ts +15 -0
- package/dist/astro.js +452 -0
- package/dist/astro.mjs +22 -0
- package/dist/browser.js +1263 -1097
- package/dist/main.js +1263 -1097
- package/dist/main.mjs +1263 -1097
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -16,8 +16,7 @@ The modern way to write TypeScript.
|
|
|
16
16
|
- [Civet VSCode Extension](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)
|
|
17
17
|
- [Discord Server](https://discord.gg/xkrW9GebBc)
|
|
18
18
|
- Plugins for
|
|
19
|
-
[Vite, esbuild, Rollup, Webpack, Rspack](integration/unplugin)
|
|
20
|
-
(including metaframeworks such as Astro),
|
|
19
|
+
[Vite, esbuild, Astro, Rollup, Webpack, Rspack](integration/unplugin)
|
|
21
20
|
<!--
|
|
22
21
|
[esbuild](source/esbuild-plugin.civet),
|
|
23
22
|
[Vite](https://github.com/edemaine/vite-plugin-civet),
|
package/dist/astro.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginOptions } from './unplugin.mjs';
|
|
2
|
+
import 'unplugin';
|
|
3
|
+
|
|
4
|
+
interface AstroIntegration {
|
|
5
|
+
name: string;
|
|
6
|
+
hooks: {
|
|
7
|
+
"astro:config:setup": (data: {
|
|
8
|
+
updateConfig: (config: unknown) => void;
|
|
9
|
+
}) => void;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function export_default(opts?: PluginOptions): AstroIntegration;
|
|
14
|
+
|
|
15
|
+
export { export_default as default };
|
package/dist/astro.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginOptions } from './unplugin.js';
|
|
2
|
+
import 'unplugin';
|
|
3
|
+
|
|
4
|
+
interface AstroIntegration {
|
|
5
|
+
name: string;
|
|
6
|
+
hooks: {
|
|
7
|
+
"astro:config:setup": (data: {
|
|
8
|
+
updateConfig: (config: unknown) => void;
|
|
9
|
+
}) => void;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function export_default(opts?: PluginOptions): AstroIntegration;
|
|
14
|
+
|
|
15
|
+
export { export_default as default };
|
package/dist/astro.js
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/astro.ts
|
|
31
|
+
var astro_exports = {};
|
|
32
|
+
__export(astro_exports, {
|
|
33
|
+
default: () => astro_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(astro_exports);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var import_unplugin = require("unplugin");
|
|
39
|
+
var import_civet = __toESM(require("@danielx/civet"));
|
|
40
|
+
var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
|
|
41
|
+
var fs = __toESM(require("fs"));
|
|
42
|
+
var import_path = __toESM(require("path"));
|
|
43
|
+
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
|
+
var import_os = __toESM(require("os"));
|
|
45
|
+
var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
|
|
46
|
+
var postfixRE = /[?#].*$/s;
|
|
47
|
+
var isWindows = import_os.default.platform() === "win32";
|
|
48
|
+
var windowsSlashRE = /\\/g;
|
|
49
|
+
function cleanCivetId(id) {
|
|
50
|
+
return id.replace(postfixRE, "").replace(/\.[jt]sx$/, "");
|
|
51
|
+
}
|
|
52
|
+
function tryStatSync(file) {
|
|
53
|
+
try {
|
|
54
|
+
return fs.statSync(file, { throwIfNoEntry: false });
|
|
55
|
+
} catch {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function slash(p) {
|
|
60
|
+
return p.replace(windowsSlashRE, "/");
|
|
61
|
+
}
|
|
62
|
+
function normalizePath(id) {
|
|
63
|
+
return import_path.default.posix.normalize(isWindows ? slash(id) : id);
|
|
64
|
+
}
|
|
65
|
+
function tryFsResolve(file) {
|
|
66
|
+
const fileStat = tryStatSync(file);
|
|
67
|
+
if (fileStat?.isFile())
|
|
68
|
+
return normalizePath(file);
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
72
|
+
const file = import_path.default.join(rootDir, id);
|
|
73
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
74
|
+
}
|
|
75
|
+
function implicitCivet(file) {
|
|
76
|
+
if (tryFsResolve(file))
|
|
77
|
+
return;
|
|
78
|
+
const civet2 = file + ".civet";
|
|
79
|
+
if (tryFsResolve(civet2))
|
|
80
|
+
return civet2;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
var rawPlugin = (options = {}, meta) => {
|
|
84
|
+
if (options.dts)
|
|
85
|
+
options.emitDeclaration = options.dts;
|
|
86
|
+
if (options.js)
|
|
87
|
+
options.ts = "civet";
|
|
88
|
+
const transformTS = options.emitDeclaration || options.typecheck;
|
|
89
|
+
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
90
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
91
|
+
let fsMap = /* @__PURE__ */ new Map();
|
|
92
|
+
const sourceMaps = /* @__PURE__ */ new Map();
|
|
93
|
+
let compilerOptions, compilerOptionsWithSourceMap;
|
|
94
|
+
let rootDir = process.cwd();
|
|
95
|
+
let esbuildOptions;
|
|
96
|
+
const tsPromise = transformTS || options.ts === "tsc" ? import("typescript").then((m) => m.default) : null;
|
|
97
|
+
const getFormatHost = (sys) => {
|
|
98
|
+
return {
|
|
99
|
+
getCurrentDirectory: () => sys.getCurrentDirectory(),
|
|
100
|
+
getNewLine: () => sys.newLine,
|
|
101
|
+
getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
name: "unplugin-civet",
|
|
106
|
+
enforce: "pre",
|
|
107
|
+
async buildStart() {
|
|
108
|
+
if (transformTS || options.ts === "tsc") {
|
|
109
|
+
const ts = await tsPromise;
|
|
110
|
+
const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
|
|
111
|
+
if (!configPath) {
|
|
112
|
+
throw new Error("Could not find 'tsconfig.json'");
|
|
113
|
+
}
|
|
114
|
+
const { config, error } = ts.readConfigFile(
|
|
115
|
+
configPath,
|
|
116
|
+
ts.sys.readFile
|
|
117
|
+
);
|
|
118
|
+
if (error) {
|
|
119
|
+
console.error(ts.formatDiagnostic(error, getFormatHost(ts.sys)));
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
const configContents = ts.parseJsonConfigFileContent(
|
|
123
|
+
config,
|
|
124
|
+
ts.sys,
|
|
125
|
+
process.cwd()
|
|
126
|
+
);
|
|
127
|
+
compilerOptions = {
|
|
128
|
+
...configContents.options,
|
|
129
|
+
target: ts.ScriptTarget.ESNext,
|
|
130
|
+
composite: false
|
|
131
|
+
};
|
|
132
|
+
compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
|
|
133
|
+
compilerOptionsWithSourceMap = {
|
|
134
|
+
...compilerOptions,
|
|
135
|
+
sourceMap: true
|
|
136
|
+
};
|
|
137
|
+
fsMap = /* @__PURE__ */ new Map();
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
async buildEnd() {
|
|
141
|
+
if (transformTS) {
|
|
142
|
+
const ts = await tsPromise;
|
|
143
|
+
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
|
|
144
|
+
const { fileExists: systemFileExists, readFile: systemReadFile } = system;
|
|
145
|
+
system.fileExists = (filename) => {
|
|
146
|
+
if (!filename.endsWith(".civet.tsx"))
|
|
147
|
+
return systemFileExists(filename);
|
|
148
|
+
if (fsMap.has(filename))
|
|
149
|
+
return true;
|
|
150
|
+
return systemFileExists(filename.slice(0, -4));
|
|
151
|
+
};
|
|
152
|
+
system.readFile = (filename, encoding = "utf-8") => {
|
|
153
|
+
if (!filename.endsWith(".civet.tsx"))
|
|
154
|
+
return systemReadFile(filename);
|
|
155
|
+
if (fsMap.has(filename))
|
|
156
|
+
return fsMap.get(filename);
|
|
157
|
+
const civetFilename = filename.slice(0, -4);
|
|
158
|
+
const rawCivetSource = fs.readFileSync(civetFilename, {
|
|
159
|
+
encoding
|
|
160
|
+
});
|
|
161
|
+
const compiledTS = import_civet.default.compile(rawCivetSource, {
|
|
162
|
+
filename,
|
|
163
|
+
js: false
|
|
164
|
+
});
|
|
165
|
+
fsMap.set(filename, compiledTS);
|
|
166
|
+
return compiledTS;
|
|
167
|
+
};
|
|
168
|
+
const host = tsvfs.createVirtualCompilerHost(
|
|
169
|
+
system,
|
|
170
|
+
compilerOptions,
|
|
171
|
+
ts
|
|
172
|
+
);
|
|
173
|
+
const program = ts.createProgram({
|
|
174
|
+
rootNames: [...fsMap.keys()],
|
|
175
|
+
options: compilerOptions,
|
|
176
|
+
host: host.compilerHost
|
|
177
|
+
});
|
|
178
|
+
const diagnostics = ts.getPreEmitDiagnostics(program).map((diagnostic) => {
|
|
179
|
+
const file = diagnostic.file;
|
|
180
|
+
if (!file)
|
|
181
|
+
return diagnostic;
|
|
182
|
+
const sourceMap = sourceMaps.get(file.fileName);
|
|
183
|
+
if (!sourceMap)
|
|
184
|
+
return diagnostic;
|
|
185
|
+
const sourcemapLines = sourceMap.data.lines;
|
|
186
|
+
const range = (0, import_ts_diagnostic.remapRange)(
|
|
187
|
+
{
|
|
188
|
+
start: diagnostic.start || 0,
|
|
189
|
+
end: (diagnostic.start || 0) + (diagnostic.length || 1)
|
|
190
|
+
},
|
|
191
|
+
sourcemapLines
|
|
192
|
+
);
|
|
193
|
+
return {
|
|
194
|
+
...diagnostic,
|
|
195
|
+
messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(diagnostic.messageText),
|
|
196
|
+
length: diagnostic.length,
|
|
197
|
+
start: range.start
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
if (diagnostics.length > 0) {
|
|
201
|
+
console.error(
|
|
202
|
+
ts.formatDiagnosticsWithColorAndContext(
|
|
203
|
+
diagnostics,
|
|
204
|
+
getFormatHost(ts.sys)
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
if (options.typecheck) {
|
|
208
|
+
let failures = [];
|
|
209
|
+
if (typeof options.typecheck === "string") {
|
|
210
|
+
if (options.typecheck.includes("error"))
|
|
211
|
+
failures.push(1 /* Error */);
|
|
212
|
+
if (options.typecheck.includes("warning"))
|
|
213
|
+
failures.push(0 /* Warning */);
|
|
214
|
+
if (options.typecheck.includes("suggestion"))
|
|
215
|
+
failures.push(2 /* Suggestion */);
|
|
216
|
+
if (options.typecheck.includes("message"))
|
|
217
|
+
failures.push(3 /* Message */);
|
|
218
|
+
if (options.typecheck.includes("all")) {
|
|
219
|
+
failures = { includes: () => true };
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
failures.push(1 /* Error */);
|
|
223
|
+
}
|
|
224
|
+
const count = diagnostics.filter((d) => failures.includes(d.category)).length;
|
|
225
|
+
if (count) {
|
|
226
|
+
const reason = count === diagnostics.length ? count : `${count} out of ${diagnostics.length}`;
|
|
227
|
+
throw new Error(`Aborting build because of ${reason} TypeScript diagnostic${diagnostics.length > 1 ? "s" : ""} above`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (options.emitDeclaration) {
|
|
232
|
+
if (meta.framework === "esbuild" && !esbuildOptions.outdir) {
|
|
233
|
+
console.log("WARNING: Civet unplugin's `emitDeclaration` requires esbuild's `outdir` option to be set;");
|
|
234
|
+
}
|
|
235
|
+
for (const file of fsMap.keys()) {
|
|
236
|
+
const slashed = slash(file);
|
|
237
|
+
if (file !== slashed) {
|
|
238
|
+
fsMap.delete(slashed);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (const file of fsMap.keys()) {
|
|
242
|
+
const sourceFile = program.getSourceFile(file);
|
|
243
|
+
program.emit(
|
|
244
|
+
sourceFile,
|
|
245
|
+
(filePath, content) => {
|
|
246
|
+
const pathFromDistDir = import_path.default.relative(
|
|
247
|
+
compilerOptions.outDir ?? process.cwd(),
|
|
248
|
+
filePath
|
|
249
|
+
);
|
|
250
|
+
if (meta.framework === "esbuild") {
|
|
251
|
+
fs.mkdirSync(
|
|
252
|
+
import_path.default.dirname(
|
|
253
|
+
import_path.default.resolve(esbuildOptions.outdir, pathFromDistDir)
|
|
254
|
+
),
|
|
255
|
+
{ recursive: true }
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
this.emitFile({
|
|
259
|
+
source: content,
|
|
260
|
+
fileName: pathFromDistDir,
|
|
261
|
+
type: "asset"
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
void 0,
|
|
265
|
+
true,
|
|
266
|
+
// emitDtsOnly
|
|
267
|
+
void 0,
|
|
268
|
+
// @ts-ignore @internal interface
|
|
269
|
+
true
|
|
270
|
+
// forceDtsEmit
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
resolveId(id, importer, options2) {
|
|
277
|
+
if (/\0/.test(id))
|
|
278
|
+
return null;
|
|
279
|
+
id = cleanCivetId(id);
|
|
280
|
+
let resolvedId = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
281
|
+
if (!resolvedId)
|
|
282
|
+
return null;
|
|
283
|
+
if (!resolvedId.endsWith(".civet")) {
|
|
284
|
+
if (!implicitExtension)
|
|
285
|
+
return null;
|
|
286
|
+
const implicitId = implicitCivet(resolvedId);
|
|
287
|
+
if (!implicitId)
|
|
288
|
+
return null;
|
|
289
|
+
resolvedId = implicitId;
|
|
290
|
+
}
|
|
291
|
+
if (options2.scan && meta.framework === "vite") {
|
|
292
|
+
resolvedId = `\0${resolvedId}`;
|
|
293
|
+
}
|
|
294
|
+
return resolvedId + outExt;
|
|
295
|
+
},
|
|
296
|
+
loadInclude(id) {
|
|
297
|
+
return isCivetTranspiled.test(id);
|
|
298
|
+
},
|
|
299
|
+
async load(id) {
|
|
300
|
+
const match = isCivetTranspiled.exec(id);
|
|
301
|
+
if (!match)
|
|
302
|
+
return null;
|
|
303
|
+
const basename = id.slice(0, match.index + match[1].length);
|
|
304
|
+
const filename = import_path.default.resolve(rootDir, basename);
|
|
305
|
+
const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
|
|
306
|
+
this.addWatchFile(filename);
|
|
307
|
+
let compiled;
|
|
308
|
+
if (options.ts === "civet" && !transformTS) {
|
|
309
|
+
compiled = import_civet.default.compile(rawCivetSource, {
|
|
310
|
+
filename: id,
|
|
311
|
+
js: true,
|
|
312
|
+
sourceMap: true
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
const compiledTS = import_civet.default.compile(rawCivetSource, {
|
|
316
|
+
filename: id,
|
|
317
|
+
js: false,
|
|
318
|
+
sourceMap: true
|
|
319
|
+
});
|
|
320
|
+
const resolved = filename + outExt;
|
|
321
|
+
sourceMaps.set(
|
|
322
|
+
resolved,
|
|
323
|
+
compiledTS.sourceMap
|
|
324
|
+
);
|
|
325
|
+
if (transformTS) {
|
|
326
|
+
const tsx = filename + ".tsx";
|
|
327
|
+
fsMap.set(tsx, compiledTS.code);
|
|
328
|
+
const slashed = slash(tsx);
|
|
329
|
+
if (tsx !== slashed)
|
|
330
|
+
fsMap.set(slashed, compiledTS.code);
|
|
331
|
+
}
|
|
332
|
+
switch (options.ts) {
|
|
333
|
+
case "esbuild": {
|
|
334
|
+
const esbuildTransform = (await import("esbuild")).transform;
|
|
335
|
+
const result = await esbuildTransform(compiledTS.code, {
|
|
336
|
+
jsx: "preserve",
|
|
337
|
+
loader: "tsx",
|
|
338
|
+
sourcefile: id,
|
|
339
|
+
sourcemap: "external"
|
|
340
|
+
});
|
|
341
|
+
compiled = { code: result.code, sourceMap: result.map };
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "tsc": {
|
|
345
|
+
const tsTranspile = (await tsPromise).transpileModule;
|
|
346
|
+
const result = tsTranspile(
|
|
347
|
+
compiledTS.code,
|
|
348
|
+
{ compilerOptions: compilerOptionsWithSourceMap }
|
|
349
|
+
);
|
|
350
|
+
compiled = {
|
|
351
|
+
code: result.outputText,
|
|
352
|
+
sourceMap: result.sourceMapText
|
|
353
|
+
};
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case "preserve": {
|
|
357
|
+
compiled = compiledTS;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case "civet":
|
|
361
|
+
default: {
|
|
362
|
+
compiled = import_civet.default.compile(rawCivetSource, {
|
|
363
|
+
filename: id,
|
|
364
|
+
js: true,
|
|
365
|
+
sourceMap: true
|
|
366
|
+
});
|
|
367
|
+
if (options.ts == void 0) {
|
|
368
|
+
console.log(
|
|
369
|
+
'WARNING: You are using the default mode for `options.ts` which is `"civet"`. This mode does not support all TS features. If this is intentional, you should explicitly set `options.ts` to `"civet"`, or choose a different mode.'
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const jsonSourceMap = compiled.sourceMap && (typeof compiled.sourceMap === "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
|
|
377
|
+
import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
|
|
378
|
+
import_path.default.basename(id)
|
|
379
|
+
));
|
|
380
|
+
let transformed = {
|
|
381
|
+
code: compiled.code,
|
|
382
|
+
map: jsonSourceMap
|
|
383
|
+
};
|
|
384
|
+
if (options.transformOutput)
|
|
385
|
+
transformed = await options.transformOutput(transformed.code, id);
|
|
386
|
+
return transformed;
|
|
387
|
+
},
|
|
388
|
+
esbuild: {
|
|
389
|
+
config(options2) {
|
|
390
|
+
esbuildOptions = options2;
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
vite: {
|
|
394
|
+
config(config) {
|
|
395
|
+
var _a;
|
|
396
|
+
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
397
|
+
if (implicitExtension) {
|
|
398
|
+
config.resolve ?? (config.resolve = {});
|
|
399
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
400
|
+
config.resolve.extensions.push(".civet");
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
async transformIndexHtml(html) {
|
|
404
|
+
return html.replace(
|
|
405
|
+
/<!--[^]*?-->|<[^<>]*>/g,
|
|
406
|
+
(tag) => tag.replace(
|
|
407
|
+
/<\s*script\b[^<>]*>/gi,
|
|
408
|
+
(script) => (
|
|
409
|
+
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
|
|
410
|
+
script.replace(
|
|
411
|
+
/([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
|
|
412
|
+
(attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
|
|
413
|
+
/(\.civet)(['"]?)$/,
|
|
414
|
+
(_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
|
|
415
|
+
) : attr
|
|
416
|
+
)
|
|
417
|
+
)
|
|
418
|
+
)
|
|
419
|
+
);
|
|
420
|
+
},
|
|
421
|
+
handleHotUpdate({ file, server, modules }) {
|
|
422
|
+
if (!file.endsWith(".civet"))
|
|
423
|
+
return;
|
|
424
|
+
const resolvedId = slash(import_path.default.resolve(file) + outExt);
|
|
425
|
+
const module2 = server.moduleGraph.getModuleById(resolvedId);
|
|
426
|
+
if (module2) {
|
|
427
|
+
server.moduleGraph.onFileChange(resolvedId);
|
|
428
|
+
return [...modules, module2];
|
|
429
|
+
}
|
|
430
|
+
return modules;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
};
|
|
435
|
+
var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
|
|
436
|
+
var src_default = unplugin;
|
|
437
|
+
|
|
438
|
+
// src/astro.ts
|
|
439
|
+
function astro_default(opts = {}) {
|
|
440
|
+
return {
|
|
441
|
+
name: "@danielx/civet",
|
|
442
|
+
hooks: {
|
|
443
|
+
"astro:config:setup": ({ updateConfig }) => {
|
|
444
|
+
updateConfig({
|
|
445
|
+
vite: {
|
|
446
|
+
plugins: [src_default.vite(opts)]
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
package/dist/astro.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
src_default
|
|
3
|
+
} from "./unplugin-shared.mjs";
|
|
4
|
+
|
|
5
|
+
// src/astro.ts
|
|
6
|
+
function astro_default(opts = {}) {
|
|
7
|
+
return {
|
|
8
|
+
name: "@danielx/civet",
|
|
9
|
+
hooks: {
|
|
10
|
+
"astro:config:setup": ({ updateConfig }) => {
|
|
11
|
+
updateConfig({
|
|
12
|
+
vite: {
|
|
13
|
+
plugins: [src_default.vite(opts)]
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
astro_default as default
|
|
22
|
+
};
|