@batijs/build 0.0.12 → 0.0.14

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.
Files changed (2) hide show
  1. package/dist/exec.js +15 -7
  2. package/package.json +3 -3
package/dist/exec.js CHANGED
@@ -36,6 +36,8 @@ function transformFileAfterExec(filepath, fileContent) {
36
36
  switch (parsed.ext) {
37
37
  case ".ts":
38
38
  case ".js":
39
+ case ".tsx":
40
+ case ".jsx":
39
41
  return fileContent;
40
42
  case ".json":
41
43
  return JSON.stringify(fileContent, null, 2);
@@ -43,6 +45,10 @@ function transformFileAfterExec(filepath, fileContent) {
43
45
  throw new Error(`Unsupported extension ${parsed.ext} (${filepath})`);
44
46
  }
45
47
  }
48
+ async function fileContainsVikeMeta(filepath) {
49
+ const code = await readFile(filepath, { encoding: "utf-8" });
50
+ return code.includes("import.meta.VIKE_");
51
+ }
46
52
  async function main(options, meta) {
47
53
  const sources = Array.isArray(options.source) ? options.source : [options.source];
48
54
  const targets = /* @__PURE__ */ new Map();
@@ -52,13 +58,6 @@ async function main(options, meta) {
52
58
  const parsed = path.parse(p);
53
59
  if (parsed.name.match(reIgnoreFile)) {
54
60
  continue;
55
- } else if (parsed.name.startsWith("$$") && parsed.ext.match(/\.[tj]sx?$/)) {
56
- const mod = await loadFile(p);
57
- const fileContent = await transformAndGenerate(mod.$ast, meta);
58
- if (fileContent) {
59
- await safeWriteFile(target, fileContent);
60
- }
61
- targets.set(target, () => fileContent);
62
61
  } else if (parsed.name.startsWith("$") && parsed.ext.match(/\.tsx?$/)) {
63
62
  throw new Error(`Typescript file needs to be compiled before it can be executed: '${p}'`);
64
63
  } else if (parsed.name.startsWith("$") && parsed.ext.match(/\.jsx?$/)) {
@@ -68,6 +67,15 @@ async function main(options, meta) {
68
67
  await safeWriteFile(target, fileContent);
69
68
  }
70
69
  targets.set(target, () => fileContent);
70
+ } else if (parsed.ext.match(/\.[tj]sx?$/) && await fileContainsVikeMeta(p)) {
71
+ const mod = await loadFile(p);
72
+ const fileContent = await transformAndGenerate(mod.$ast, meta, {
73
+ filepath: p
74
+ });
75
+ if (fileContent) {
76
+ await safeWriteFile(target, fileContent);
77
+ }
78
+ targets.set(target, () => fileContent);
71
79
  } else {
72
80
  await safeCopyFile(p, target);
73
81
  targets.set(target, () => readFile(p, { encoding: "utf-8" }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/build",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -8,10 +8,10 @@
8
8
  "license": "MIT",
9
9
  "devDependencies": {
10
10
  "@types/node": "^16.18.27",
11
- "@batijs/tsup": "0.0.12"
11
+ "@batijs/tsup": "0.0.14"
12
12
  },
13
13
  "dependencies": {
14
- "@batijs/core": "0.0.12"
14
+ "@batijs/core": "0.0.14"
15
15
  },
16
16
  "main": "./dist/exec.js",
17
17
  "module": "./dist/exec.js",