@danielx/civet 0.6.25 → 0.6.27

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/vite.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/vite.ts
31
+ var vite_exports = {};
32
+ __export(vite_exports, {
33
+ default: () => vite_default
34
+ });
35
+ module.exports = __toCommonJS(vite_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/vite.ts
176
+ var vite_default = src_default.vite;
package/dist/vite.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./unplugin-shared.mjs";
4
+
5
+ // src/vite.ts
6
+ var vite_default = src_default.vite;
7
+ export {
8
+ vite_default as default
9
+ };
@@ -0,0 +1,6 @@
1
+ import { PluginOptions } from './unplugin.mjs';
2
+ import 'unplugin';
3
+
4
+ declare const _default: (options?: PluginOptions | undefined) => WebpackPluginInstance;
5
+
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import { PluginOptions } from './unplugin.js';
2
+ import 'unplugin';
3
+
4
+ declare const _default: (options?: PluginOptions | undefined) => WebpackPluginInstance;
5
+
6
+ export { _default as default };
@@ -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/webpack.ts
31
+ var webpack_exports = {};
32
+ __export(webpack_exports, {
33
+ default: () => webpack_default
34
+ });
35
+ module.exports = __toCommonJS(webpack_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/webpack.ts
176
+ var webpack_default = src_default.webpack;
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./unplugin-shared.mjs";
4
+
5
+ // src/webpack.ts
6
+ var webpack_default = src_default.webpack;
7
+ export {
8
+ webpack_default as default
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.6.25",
3
+ "version": "0.6.27",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",
@@ -15,6 +15,26 @@
15
15
  "./esbuild-plugin": "./dist/esbuild-plugin.js",
16
16
  "./register": "./register.js",
17
17
  "./config": "./dist/config.js",
18
+ "./unplugin": {
19
+ "require": "./dist/unplugin.js",
20
+ "import": "./dist/unplugin.mjs"
21
+ },
22
+ "./vite": {
23
+ "require": "./dist/vite.js",
24
+ "import": "./dist/vite.mjs"
25
+ },
26
+ "./webpack": {
27
+ "require": "./dist/webpack.js",
28
+ "import": "./dist/webpack.mjs"
29
+ },
30
+ "./rollup": {
31
+ "require": "./dist/rollup.js",
32
+ "import": "./dist/rollup.mjs"
33
+ },
34
+ "./esbuild": {
35
+ "require": "./dist/esbuild.js",
36
+ "import": "./dist/esbuild.mjs"
37
+ },
18
38
  "./*": "./*",
19
39
  "./dist/*": "./dist/*"
20
40
  },
@@ -35,33 +55,39 @@
35
55
  "docs:build": "yarn build && vitepress build civet.dev",
36
56
  "docs:preview": "yarn build && vitepress preview civet.dev",
37
57
  "prepublishOnly": "yarn build && yarn test",
38
- "test": "c8 mocha"
58
+ "test": "c8 mocha && tsc"
39
59
  },
40
60
  "author": "Daniel X. Moore",
41
61
  "license": "MIT",
42
62
  "dependencies": {
43
- "@cspotcode/source-map-support": "^0.8.1"
63
+ "@cspotcode/source-map-support": "^0.8.1",
64
+ "@typescript/vfs": "^1.5.0",
65
+ "unplugin": "^1.4.0"
44
66
  },
45
67
  "devDependencies": {
46
- "@danielx/hera": "^0.8.8",
68
+ "@danielx/civet": "^0.6.26",
69
+ "@danielx/hera": "^0.8.10",
47
70
  "@types/assert": "^1.5.6",
48
- "@types/coffeescript": "^2.5.2",
49
71
  "@types/mocha": "^9.1.1",
50
- "@types/node": "^18.7.8",
72
+ "@types/node": "^20.5.1",
51
73
  "axios": "^1.2.2",
52
74
  "c8": "^7.12.0",
53
75
  "esbuild": "^0.14.49",
54
- "esbuild-coffeescript": "^2.1.0",
55
76
  "marked": "^4.2.4",
56
77
  "mocha": "^10.0.0",
57
78
  "prettier": "^2.8.1",
58
79
  "terser": "^5.16.1",
59
80
  "ts-node": "^10.9.1",
60
81
  "tslib": "^2.4.0",
82
+ "tsup": "^7.2.0",
61
83
  "typescript": "^4.7.4",
84
+ "vite": "^4.4.9",
62
85
  "vitepress": "^1.0.0-alpha.35",
63
86
  "vue": "^3.2.45"
64
87
  },
88
+ "peerDependencies": {
89
+ "typescript": "^4.5 || ^5.0"
90
+ },
65
91
  "c8": {
66
92
  "all": true,
67
93
  "reporter": [
@@ -71,7 +97,10 @@
71
97
  "extension": [
72
98
  ".civet",
73
99
  ".coffee",
100
+ ".hera",
74
101
  ".js",
102
+ ".mjs",
103
+ ".mts",
75
104
  ".ts"
76
105
  ],
77
106
  "include": [
@@ -85,9 +114,8 @@
85
114
  ],
86
115
  "loader": [
87
116
  "ts-node/esm",
88
- "./build/coffee-esm.mjs",
89
117
  "./build/hera-esm.mjs",
90
- "./dist/esm.mjs"
118
+ "./node_modules/@danielx/civet/dist/esm.mjs"
91
119
  ],
92
120
  "reporter": "dot",
93
121
  "recursive": true,
Binary file