@danielx/civet 0.6.21 → 0.6.23
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/browser.js +629 -433
- package/dist/chunk-UZRN3RFA.mjs +141 -0
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.js +176 -0
- package/dist/esbuild.mjs +9 -0
- package/dist/main.js +629 -433
- package/dist/main.mjs +629 -433
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.d.ts +7 -0
- package/dist/rollup.js +176 -0
- package/dist/rollup.mjs +9 -0
- package/dist/unplugin.d.mts +16 -0
- package/dist/unplugin.d.ts +16 -0
- package/dist/unplugin.js +171 -0
- package/dist/unplugin.mjs +6 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.js +176 -0
- package/dist/vite.mjs +9 -0
- package/dist/webpack.d.mts +6 -0
- package/dist/webpack.d.ts +6 -0
- package/dist/webpack.js +176 -0
- package/dist/webpack.mjs +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
3
|
+
import civet from "@danielx/civet";
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import * as tsvfs from "@typescript/vfs";
|
|
8
|
+
var formatHost = {
|
|
9
|
+
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
10
|
+
getNewLine: () => ts.sys.newLine,
|
|
11
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
12
|
+
};
|
|
13
|
+
var isCivet = (id) => /\.civet$/.test(id);
|
|
14
|
+
var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
|
|
15
|
+
var civetUnplugin = createUnplugin((options = {}) => {
|
|
16
|
+
if (options.dts && options.js) {
|
|
17
|
+
throw new Error("Can't have both `dts` and `js` be set to `true`.");
|
|
18
|
+
}
|
|
19
|
+
const transpileToJS = options.js ?? !options.dts;
|
|
20
|
+
const outExt = options.outputExtension ?? (transpileToJS ? ".jsx" : ".tsx");
|
|
21
|
+
let fsMap = /* @__PURE__ */ new Map();
|
|
22
|
+
let compilerOptions;
|
|
23
|
+
return {
|
|
24
|
+
name: "unplugin-civet",
|
|
25
|
+
enforce: "pre",
|
|
26
|
+
async buildStart() {
|
|
27
|
+
if (options.dts) {
|
|
28
|
+
const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
|
|
29
|
+
if (!configPath) {
|
|
30
|
+
throw new Error("Could not find 'tsconfig.json'");
|
|
31
|
+
}
|
|
32
|
+
const { config, error } = ts.readConfigFile(
|
|
33
|
+
configPath,
|
|
34
|
+
ts.sys.readFile
|
|
35
|
+
);
|
|
36
|
+
if (error) {
|
|
37
|
+
console.error(ts.formatDiagnostic(error, formatHost));
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
const configContents = ts.parseJsonConfigFileContent(
|
|
41
|
+
config,
|
|
42
|
+
ts.sys,
|
|
43
|
+
process.cwd()
|
|
44
|
+
);
|
|
45
|
+
compilerOptions = {
|
|
46
|
+
...configContents.options,
|
|
47
|
+
target: ts.ScriptTarget.ESNext
|
|
48
|
+
};
|
|
49
|
+
fsMap = /* @__PURE__ */ new Map();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
buildEnd() {
|
|
53
|
+
if (options.dts) {
|
|
54
|
+
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
|
|
55
|
+
const host = tsvfs.createVirtualCompilerHost(
|
|
56
|
+
system,
|
|
57
|
+
compilerOptions,
|
|
58
|
+
ts
|
|
59
|
+
);
|
|
60
|
+
const program = ts.createProgram({
|
|
61
|
+
rootNames: [...fsMap.keys()],
|
|
62
|
+
options: compilerOptions,
|
|
63
|
+
host: host.compilerHost
|
|
64
|
+
});
|
|
65
|
+
for (const file of fsMap.keys()) {
|
|
66
|
+
const sourceFile = program.getSourceFile(file);
|
|
67
|
+
program.emit(
|
|
68
|
+
sourceFile,
|
|
69
|
+
(filePath, content) => {
|
|
70
|
+
this.emitFile({
|
|
71
|
+
source: content,
|
|
72
|
+
fileName: path.relative(process.cwd(), filePath),
|
|
73
|
+
type: "asset"
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
void 0,
|
|
77
|
+
true
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
resolveId(id, importer) {
|
|
83
|
+
if (/\0/.test(id))
|
|
84
|
+
return null;
|
|
85
|
+
if (!isCivet(id))
|
|
86
|
+
return null;
|
|
87
|
+
const relativeId = path.relative(
|
|
88
|
+
process.cwd(),
|
|
89
|
+
path.resolve(path.dirname(importer ?? ""), id)
|
|
90
|
+
);
|
|
91
|
+
const relativePath = relativeId + outExt;
|
|
92
|
+
return relativePath;
|
|
93
|
+
},
|
|
94
|
+
loadInclude(id) {
|
|
95
|
+
return isCivetTranspiled(id);
|
|
96
|
+
},
|
|
97
|
+
async load(id) {
|
|
98
|
+
if (!isCivetTranspiled(id))
|
|
99
|
+
return null;
|
|
100
|
+
const filename = path.resolve(process.cwd(), id.slice(0, -outExt.length));
|
|
101
|
+
const code = await fs.promises.readFile(filename, "utf-8");
|
|
102
|
+
let transformed = {
|
|
103
|
+
code: civet.compile(code, {
|
|
104
|
+
inlineMap: true,
|
|
105
|
+
filename: id,
|
|
106
|
+
js: transpileToJS
|
|
107
|
+
}),
|
|
108
|
+
map: null
|
|
109
|
+
};
|
|
110
|
+
if (options.transformOutput)
|
|
111
|
+
transformed = await options.transformOutput(transformed.code, id);
|
|
112
|
+
return transformed;
|
|
113
|
+
},
|
|
114
|
+
transform(code, id) {
|
|
115
|
+
if (!/\.civet\.tsx?$/.test(id))
|
|
116
|
+
return null;
|
|
117
|
+
if (options.dts) {
|
|
118
|
+
fsMap.set(path.resolve(process.cwd(), id), code);
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
},
|
|
122
|
+
vite: {
|
|
123
|
+
config(_config, { command }) {
|
|
124
|
+
if (command === "build") {
|
|
125
|
+
return {
|
|
126
|
+
esbuild: {
|
|
127
|
+
include: [/\.civet$/],
|
|
128
|
+
loader: "tsx"
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
var src_default = civetUnplugin;
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
src_default
|
|
141
|
+
};
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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/esbuild.ts
|
|
31
|
+
var esbuild_exports = {};
|
|
32
|
+
__export(esbuild_exports, {
|
|
33
|
+
default: () => esbuild_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(esbuild_exports);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var import_unplugin = require("unplugin");
|
|
39
|
+
var import_civet = __toESM(require("@danielx/civet"));
|
|
40
|
+
var fs = __toESM(require("fs"));
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
var import_typescript = __toESM(require("typescript"));
|
|
43
|
+
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
|
+
var formatHost = {
|
|
45
|
+
getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
|
|
46
|
+
getNewLine: () => import_typescript.default.sys.newLine,
|
|
47
|
+
getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
48
|
+
};
|
|
49
|
+
var isCivet = (id) => /\.civet$/.test(id);
|
|
50
|
+
var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
|
|
51
|
+
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
52
|
+
if (options.dts && options.js) {
|
|
53
|
+
throw new Error("Can't have both `dts` and `js` be set to `true`.");
|
|
54
|
+
}
|
|
55
|
+
const transpileToJS = options.js ?? !options.dts;
|
|
56
|
+
const outExt = options.outputExtension ?? (transpileToJS ? ".jsx" : ".tsx");
|
|
57
|
+
let fsMap = /* @__PURE__ */ new Map();
|
|
58
|
+
let compilerOptions;
|
|
59
|
+
return {
|
|
60
|
+
name: "unplugin-civet",
|
|
61
|
+
enforce: "pre",
|
|
62
|
+
async buildStart() {
|
|
63
|
+
if (options.dts) {
|
|
64
|
+
const configPath = import_typescript.default.findConfigFile(process.cwd(), import_typescript.default.sys.fileExists);
|
|
65
|
+
if (!configPath) {
|
|
66
|
+
throw new Error("Could not find 'tsconfig.json'");
|
|
67
|
+
}
|
|
68
|
+
const { config, error } = import_typescript.default.readConfigFile(
|
|
69
|
+
configPath,
|
|
70
|
+
import_typescript.default.sys.readFile
|
|
71
|
+
);
|
|
72
|
+
if (error) {
|
|
73
|
+
console.error(import_typescript.default.formatDiagnostic(error, formatHost));
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
const configContents = import_typescript.default.parseJsonConfigFileContent(
|
|
77
|
+
config,
|
|
78
|
+
import_typescript.default.sys,
|
|
79
|
+
process.cwd()
|
|
80
|
+
);
|
|
81
|
+
compilerOptions = {
|
|
82
|
+
...configContents.options,
|
|
83
|
+
target: import_typescript.default.ScriptTarget.ESNext
|
|
84
|
+
};
|
|
85
|
+
fsMap = /* @__PURE__ */ new Map();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
buildEnd() {
|
|
89
|
+
if (options.dts) {
|
|
90
|
+
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), import_typescript.default);
|
|
91
|
+
const host = tsvfs.createVirtualCompilerHost(
|
|
92
|
+
system,
|
|
93
|
+
compilerOptions,
|
|
94
|
+
import_typescript.default
|
|
95
|
+
);
|
|
96
|
+
const program = import_typescript.default.createProgram({
|
|
97
|
+
rootNames: [...fsMap.keys()],
|
|
98
|
+
options: compilerOptions,
|
|
99
|
+
host: host.compilerHost
|
|
100
|
+
});
|
|
101
|
+
for (const file of fsMap.keys()) {
|
|
102
|
+
const sourceFile = program.getSourceFile(file);
|
|
103
|
+
program.emit(
|
|
104
|
+
sourceFile,
|
|
105
|
+
(filePath, content) => {
|
|
106
|
+
this.emitFile({
|
|
107
|
+
source: content,
|
|
108
|
+
fileName: import_path.default.relative(process.cwd(), filePath),
|
|
109
|
+
type: "asset"
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
void 0,
|
|
113
|
+
true
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
resolveId(id, importer) {
|
|
119
|
+
if (/\0/.test(id))
|
|
120
|
+
return null;
|
|
121
|
+
if (!isCivet(id))
|
|
122
|
+
return null;
|
|
123
|
+
const relativeId = import_path.default.relative(
|
|
124
|
+
process.cwd(),
|
|
125
|
+
import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
|
|
126
|
+
);
|
|
127
|
+
const relativePath = relativeId + outExt;
|
|
128
|
+
return relativePath;
|
|
129
|
+
},
|
|
130
|
+
loadInclude(id) {
|
|
131
|
+
return isCivetTranspiled(id);
|
|
132
|
+
},
|
|
133
|
+
async load(id) {
|
|
134
|
+
if (!isCivetTranspiled(id))
|
|
135
|
+
return null;
|
|
136
|
+
const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
|
|
137
|
+
const code = await fs.promises.readFile(filename, "utf-8");
|
|
138
|
+
let transformed = {
|
|
139
|
+
code: import_civet.default.compile(code, {
|
|
140
|
+
inlineMap: true,
|
|
141
|
+
filename: id,
|
|
142
|
+
js: transpileToJS
|
|
143
|
+
}),
|
|
144
|
+
map: null
|
|
145
|
+
};
|
|
146
|
+
if (options.transformOutput)
|
|
147
|
+
transformed = await options.transformOutput(transformed.code, id);
|
|
148
|
+
return transformed;
|
|
149
|
+
},
|
|
150
|
+
transform(code, id) {
|
|
151
|
+
if (!/\.civet\.tsx?$/.test(id))
|
|
152
|
+
return null;
|
|
153
|
+
if (options.dts) {
|
|
154
|
+
fsMap.set(import_path.default.resolve(process.cwd(), id), code);
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
},
|
|
158
|
+
vite: {
|
|
159
|
+
config(_config, { command }) {
|
|
160
|
+
if (command === "build") {
|
|
161
|
+
return {
|
|
162
|
+
esbuild: {
|
|
163
|
+
include: [/\.civet$/],
|
|
164
|
+
loader: "tsx"
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
var src_default = civetUnplugin;
|
|
174
|
+
|
|
175
|
+
// src/esbuild.ts
|
|
176
|
+
var esbuild_default = src_default.esbuild;
|