@danielx/civet 0.7.13 → 0.7.15
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/astro.js +61 -6
- package/dist/browser.js +178 -71
- package/dist/civet +16 -18
- package/dist/config.js +74 -42
- package/dist/esbuild.js +61 -6
- package/dist/main.js +178 -71
- package/dist/main.mjs +178 -71
- package/dist/rollup.js +61 -6
- package/dist/unplugin-shared.mjs +61 -6
- package/dist/unplugin.js +61 -6
- package/dist/vite.js +61 -6
- package/dist/webpack.js +61 -6
- package/package.json +10 -3
package/dist/astro.js
CHANGED
|
@@ -100,6 +100,8 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
100
100
|
let compilerOptions, compilerOptionsWithSourceMap;
|
|
101
101
|
let rootDir = process.cwd();
|
|
102
102
|
let esbuildOptions;
|
|
103
|
+
let configErrors;
|
|
104
|
+
let configFileNames;
|
|
103
105
|
const tsPromise = transformTS || options.ts === "tsc" ? import("typescript").then((m) => m.default) : null;
|
|
104
106
|
const getFormatHost = (sys) => {
|
|
105
107
|
return {
|
|
@@ -114,6 +116,16 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
114
116
|
enforce: "pre",
|
|
115
117
|
async buildStart() {
|
|
116
118
|
if (transformTS || options.ts === "tsc") {
|
|
119
|
+
let mogrify2 = function(key) {
|
|
120
|
+
if (key in config && Array.isArray(config[key])) {
|
|
121
|
+
config[key] = config[key].map((item) => {
|
|
122
|
+
if (typeof item !== "string")
|
|
123
|
+
return item;
|
|
124
|
+
return item.replace(/\.civet\b(?!\.)/g, ".civet.tsx");
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var mogrify = mogrify2;
|
|
117
129
|
const ts = await tsPromise;
|
|
118
130
|
const civetConfigPath = "config" in options ? options.config : await (0, import_config.findInDir)(process.cwd());
|
|
119
131
|
if (civetConfigPath) {
|
|
@@ -135,17 +147,26 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
135
147
|
console.error(ts.formatDiagnostic(error, getFormatHost(ts.sys)));
|
|
136
148
|
throw error;
|
|
137
149
|
}
|
|
150
|
+
mogrify2("files");
|
|
151
|
+
const system = { ...ts.sys };
|
|
152
|
+
const { readDirectory: systemReadDirectory } = system;
|
|
153
|
+
system.readDirectory = (path2, extensions, excludes, includes, depth) => {
|
|
154
|
+
extensions = [...extensions ?? [], ".civet"];
|
|
155
|
+
return systemReadDirectory(path2, extensions, excludes, includes, depth).map((name) => name.endsWith(".civet") ? name + ".tsx" : name);
|
|
156
|
+
};
|
|
138
157
|
const configContents = ts.parseJsonConfigFileContent(
|
|
139
158
|
config,
|
|
140
|
-
|
|
159
|
+
system,
|
|
141
160
|
process.cwd()
|
|
142
161
|
);
|
|
162
|
+
configErrors = configContents.errors;
|
|
163
|
+
configFileNames = configContents.fileNames;
|
|
143
164
|
compilerOptions = {
|
|
144
165
|
...configContents.options,
|
|
145
166
|
target: ts.ScriptTarget.ESNext,
|
|
146
167
|
composite: false
|
|
147
168
|
};
|
|
148
|
-
compilerOptions.jsx ?? (compilerOptions.jsx =
|
|
169
|
+
compilerOptions.jsx ?? (compilerOptions.jsx = ts.JsxEmit.Preserve);
|
|
149
170
|
compilerOptionsWithSourceMap = {
|
|
150
171
|
...compilerOptions,
|
|
151
172
|
sourceMap: true
|
|
@@ -153,11 +174,15 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
153
174
|
fsMap = /* @__PURE__ */ new Map();
|
|
154
175
|
}
|
|
155
176
|
},
|
|
156
|
-
async buildEnd() {
|
|
177
|
+
async buildEnd(useConfigFileNames = false) {
|
|
157
178
|
if (transformTS) {
|
|
158
179
|
const ts = await tsPromise;
|
|
159
180
|
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
|
|
160
|
-
const {
|
|
181
|
+
const {
|
|
182
|
+
fileExists: systemFileExists,
|
|
183
|
+
readFile: systemReadFile,
|
|
184
|
+
readDirectory: systemReadDirectory
|
|
185
|
+
} = system;
|
|
161
186
|
system.fileExists = (filename) => {
|
|
162
187
|
if (!filename.endsWith(".civet.tsx"))
|
|
163
188
|
return systemFileExists(filename);
|
|
@@ -165,9 +190,35 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
165
190
|
return true;
|
|
166
191
|
return systemFileExists(filename.slice(0, -4));
|
|
167
192
|
};
|
|
193
|
+
system.readDirectory = (path2) => systemReadDirectory(path2).map((name) => name.endsWith(".civet") ? name + ".tsx" : name);
|
|
168
194
|
system.readFile = (filename, encoding = "utf-8") => {
|
|
195
|
+
if (import_path.default.basename(filename) === "package.json") {
|
|
196
|
+
let recurse2 = function(node) {
|
|
197
|
+
if (node && typeof node === "object") {
|
|
198
|
+
for (const key in node) {
|
|
199
|
+
const value = node[key];
|
|
200
|
+
if (typeof value === "string") {
|
|
201
|
+
if (value.endsWith(".civet")) {
|
|
202
|
+
node[key] = value + ".tsx";
|
|
203
|
+
modified = true;
|
|
204
|
+
}
|
|
205
|
+
} else if (value) {
|
|
206
|
+
recurse2(value);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var recurse = recurse2;
|
|
212
|
+
const json = systemReadFile(filename, encoding);
|
|
213
|
+
if (!json)
|
|
214
|
+
return json;
|
|
215
|
+
const parsed = JSON.parse(json);
|
|
216
|
+
let modified = false;
|
|
217
|
+
recurse2(parsed.imports);
|
|
218
|
+
return modified ? JSON.stringify(parsed) : json;
|
|
219
|
+
}
|
|
169
220
|
if (!filename.endsWith(".civet.tsx"))
|
|
170
|
-
return systemReadFile(filename);
|
|
221
|
+
return systemReadFile(filename, encoding);
|
|
171
222
|
if (fsMap.has(filename))
|
|
172
223
|
return fsMap.get(filename);
|
|
173
224
|
const civetFilename = filename.slice(0, -4);
|
|
@@ -189,8 +240,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
189
240
|
compilerOptions,
|
|
190
241
|
ts
|
|
191
242
|
);
|
|
243
|
+
host.compilerHost.getDirectories = system.getDirectories;
|
|
192
244
|
const program = ts.createProgram({
|
|
193
|
-
rootNames: [...fsMap.keys()],
|
|
245
|
+
rootNames: useConfigFileNames ? configFileNames : [...fsMap.keys()],
|
|
194
246
|
options: compilerOptions,
|
|
195
247
|
host: host.compilerHost
|
|
196
248
|
});
|
|
@@ -216,6 +268,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
216
268
|
start: range.start
|
|
217
269
|
};
|
|
218
270
|
});
|
|
271
|
+
if (configErrors?.length) {
|
|
272
|
+
diagnostics.unshift(...configErrors);
|
|
273
|
+
}
|
|
219
274
|
if (diagnostics.length > 0) {
|
|
220
275
|
console.error(
|
|
221
276
|
ts.formatDiagnosticsWithColorAndContext(
|