@danielx/civet 0.6.50 → 0.6.52

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/unplugin.js CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- default: () => src_default
33
+ default: () => src_default,
34
+ slash: () => slash
34
35
  });
35
36
  module.exports = __toCommonJS(src_exports);
36
37
  var import_unplugin = require("unplugin");
@@ -40,14 +41,46 @@ var fs = __toESM(require("fs"));
40
41
  var import_path = __toESM(require("path"));
41
42
  var import_typescript = __toESM(require("typescript"));
42
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
+ var import_os = __toESM(require("os"));
43
45
  var formatHost = {
44
46
  getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
45
47
  getNewLine: () => import_typescript.default.sys.newLine,
46
48
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
47
49
  };
48
50
  var isCivet = (id) => /\.civet$/.test(id);
49
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
50
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
51
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
52
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
53
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
54
+ var isWindows = import_os.default.platform() === "win32";
55
+ var windowsSlashRE = /\\/g;
56
+ function cleanCivetId(id) {
57
+ return id.replace(postfixRE, "");
58
+ }
59
+ function tryStatSync(file) {
60
+ try {
61
+ return fs.statSync(file, { throwIfNoEntry: false });
62
+ } catch {
63
+ return void 0;
64
+ }
65
+ }
66
+ function slash(p) {
67
+ return p.replace(windowsSlashRE, "/");
68
+ }
69
+ function normalizePath(id) {
70
+ return import_path.default.posix.normalize(isWindows ? slash(id) : id);
71
+ }
72
+ function tryFsResolve(file) {
73
+ const fileStat = tryStatSync(file);
74
+ if (fileStat?.isFile())
75
+ return normalizePath(file);
76
+ return void 0;
77
+ }
78
+ function resolveAbsolutePath(rootDir, id) {
79
+ const resolved = tryFsResolve(import_path.default.join(rootDir, id));
80
+ if (!resolved)
81
+ return tryFsResolve(id);
82
+ return resolved;
83
+ }
51
84
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
52
85
  if (options.dts && options.js) {
53
86
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -60,7 +93,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
60
93
  let fsMap = /* @__PURE__ */ new Map();
61
94
  const sourceMaps = /* @__PURE__ */ new Map();
62
95
  let compilerOptions;
63
- let rootDir;
96
+ let rootDir = process.cwd();
64
97
  return {
65
98
  name: "unplugin-civet",
66
99
  enforce: "pre",
@@ -160,10 +193,11 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
160
193
  return null;
161
194
  if (!isCivet(id) && !isCivetTranspiled(id))
162
195
  return null;
163
- const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
196
+ id = cleanCivetId(id);
197
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
198
+ if (!absolutePath)
199
+ return null;
164
200
  const relativeId = import_path.default.relative(process.cwd(), absolutePath);
165
- if (isCivetTranspiled(id))
166
- return relativeId.replace(/\?transform$/, "");
167
201
  const relativePath = relativeId + outExt;
168
202
  return relativePath;
169
203
  },
@@ -204,9 +238,9 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
204
238
  if (options.dts || options.typecheck) {
205
239
  const resolved = import_path.default.resolve(process.cwd(), id);
206
240
  fsMap.set(resolved, code);
207
- const slash = resolved.replace(/\\/g, "/");
208
- if (resolved !== slash)
209
- fsMap.set(slash, code);
241
+ const slashed = slash(resolved);
242
+ if (resolved !== slashed)
243
+ fsMap.set(slashed, code);
210
244
  }
211
245
  return null;
212
246
  },
@@ -245,3 +279,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
245
279
  };
246
280
  });
247
281
  var src_default = civetUnplugin;
282
+ // Annotate the CommonJS export names for ESM import in node:
283
+ 0 && (module.exports = {
284
+ slash
285
+ });
package/dist/unplugin.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import {
2
+ slash,
2
3
  src_default
3
4
  } from "./unplugin-shared.mjs";
4
5
  export {
5
- src_default as default
6
+ src_default as default,
7
+ slash
6
8
  };
package/dist/vite.js CHANGED
@@ -42,14 +42,46 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var import_typescript = __toESM(require("typescript"));
44
44
  var tsvfs = __toESM(require("@typescript/vfs"));
45
+ var import_os = __toESM(require("os"));
45
46
  var formatHost = {
46
47
  getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
47
48
  getNewLine: () => import_typescript.default.sys.newLine,
48
49
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
50
  };
50
51
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
52
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
53
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
54
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
55
+ var isWindows = import_os.default.platform() === "win32";
56
+ var windowsSlashRE = /\\/g;
57
+ function cleanCivetId(id) {
58
+ return id.replace(postfixRE, "");
59
+ }
60
+ function tryStatSync(file) {
61
+ try {
62
+ return fs.statSync(file, { throwIfNoEntry: false });
63
+ } catch {
64
+ return void 0;
65
+ }
66
+ }
67
+ function slash(p) {
68
+ return p.replace(windowsSlashRE, "/");
69
+ }
70
+ function normalizePath(id) {
71
+ return import_path.default.posix.normalize(isWindows ? slash(id) : id);
72
+ }
73
+ function tryFsResolve(file) {
74
+ const fileStat = tryStatSync(file);
75
+ if (fileStat?.isFile())
76
+ return normalizePath(file);
77
+ return void 0;
78
+ }
79
+ function resolveAbsolutePath(rootDir, id) {
80
+ const resolved = tryFsResolve(import_path.default.join(rootDir, id));
81
+ if (!resolved)
82
+ return tryFsResolve(id);
83
+ return resolved;
84
+ }
53
85
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
86
  if (options.dts && options.js) {
55
87
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -62,7 +94,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
94
  let fsMap = /* @__PURE__ */ new Map();
63
95
  const sourceMaps = /* @__PURE__ */ new Map();
64
96
  let compilerOptions;
65
- let rootDir;
97
+ let rootDir = process.cwd();
66
98
  return {
67
99
  name: "unplugin-civet",
68
100
  enforce: "pre",
@@ -162,10 +194,11 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
162
194
  return null;
163
195
  if (!isCivet(id) && !isCivetTranspiled(id))
164
196
  return null;
165
- const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
197
+ id = cleanCivetId(id);
198
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
199
+ if (!absolutePath)
200
+ return null;
166
201
  const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
- if (isCivetTranspiled(id))
168
- return relativeId.replace(/\?transform$/, "");
169
202
  const relativePath = relativeId + outExt;
170
203
  return relativePath;
171
204
  },
@@ -206,9 +239,9 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
206
239
  if (options.dts || options.typecheck) {
207
240
  const resolved = import_path.default.resolve(process.cwd(), id);
208
241
  fsMap.set(resolved, code);
209
- const slash = resolved.replace(/\\/g, "/");
210
- if (resolved !== slash)
211
- fsMap.set(slash, code);
242
+ const slashed = slash(resolved);
243
+ if (resolved !== slashed)
244
+ fsMap.set(slashed, code);
212
245
  }
213
246
  return null;
214
247
  },
package/dist/webpack.js CHANGED
@@ -42,14 +42,46 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var import_typescript = __toESM(require("typescript"));
44
44
  var tsvfs = __toESM(require("@typescript/vfs"));
45
+ var import_os = __toESM(require("os"));
45
46
  var formatHost = {
46
47
  getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
47
48
  getNewLine: () => import_typescript.default.sys.newLine,
48
49
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
50
  };
50
51
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
52
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
53
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
54
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
55
+ var isWindows = import_os.default.platform() === "win32";
56
+ var windowsSlashRE = /\\/g;
57
+ function cleanCivetId(id) {
58
+ return id.replace(postfixRE, "");
59
+ }
60
+ function tryStatSync(file) {
61
+ try {
62
+ return fs.statSync(file, { throwIfNoEntry: false });
63
+ } catch {
64
+ return void 0;
65
+ }
66
+ }
67
+ function slash(p) {
68
+ return p.replace(windowsSlashRE, "/");
69
+ }
70
+ function normalizePath(id) {
71
+ return import_path.default.posix.normalize(isWindows ? slash(id) : id);
72
+ }
73
+ function tryFsResolve(file) {
74
+ const fileStat = tryStatSync(file);
75
+ if (fileStat?.isFile())
76
+ return normalizePath(file);
77
+ return void 0;
78
+ }
79
+ function resolveAbsolutePath(rootDir, id) {
80
+ const resolved = tryFsResolve(import_path.default.join(rootDir, id));
81
+ if (!resolved)
82
+ return tryFsResolve(id);
83
+ return resolved;
84
+ }
53
85
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
86
  if (options.dts && options.js) {
55
87
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -62,7 +94,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
94
  let fsMap = /* @__PURE__ */ new Map();
63
95
  const sourceMaps = /* @__PURE__ */ new Map();
64
96
  let compilerOptions;
65
- let rootDir;
97
+ let rootDir = process.cwd();
66
98
  return {
67
99
  name: "unplugin-civet",
68
100
  enforce: "pre",
@@ -162,10 +194,11 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
162
194
  return null;
163
195
  if (!isCivet(id) && !isCivetTranspiled(id))
164
196
  return null;
165
- const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
197
+ id = cleanCivetId(id);
198
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
199
+ if (!absolutePath)
200
+ return null;
166
201
  const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
- if (isCivetTranspiled(id))
168
- return relativeId.replace(/\?transform$/, "");
169
202
  const relativePath = relativeId + outExt;
170
203
  return relativePath;
171
204
  },
@@ -206,9 +239,9 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
206
239
  if (options.dts || options.typecheck) {
207
240
  const resolved = import_path.default.resolve(process.cwd(), id);
208
241
  fsMap.set(resolved, code);
209
- const slash = resolved.replace(/\\/g, "/");
210
- if (resolved !== slash)
211
- fsMap.set(slash, code);
242
+ const slashed = slash(resolved);
243
+ if (resolved !== slashed)
244
+ fsMap.set(slashed, code);
212
245
  }
213
246
  return null;
214
247
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.50",
4
+ "version": "0.6.52",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",