@vureact/compiler-core 1.3.0 → 1.4.0

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/lib/cli.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @vureact/compiler-core v1.3.0
3
+ * @vureact/compiler-core v1.4.0
4
4
  * (c) 2025-present Ruihong Zhong (Ryan John)
5
5
  * @license MIT
6
6
  */
@@ -13,74 +13,67 @@ import {
13
13
  getDirname,
14
14
  normalizePath,
15
15
  version
16
- } from "./chunk-CUCUXW56.esm.js";
16
+ } from "./chunk-NF5BSPYE.esm.js";
17
17
 
18
18
  // src/cli/index.ts
19
19
  import { cac } from "cac";
20
20
 
21
- // src/cli/action.ts
22
- import chokidar from "chokidar";
21
+ // src/cli/action/index.ts
22
+ import kleur3 from "kleur";
23
+ import path3 from "path";
24
+
25
+ // src/cli/action/config-loader.ts
23
26
  import { existsSync } from "fs";
24
27
  import kleur from "kleur";
25
- import ora from "ora";
26
28
  import path from "path";
27
29
  import { pathToFileURL } from "url";
28
- async function resolveAction(root, options) {
29
- const projectRoot = root ? path.resolve(process.cwd(), root) : process.cwd();
30
- const userConfig = await loadUserConfig(projectRoot);
31
- const finalConfig = mergeConfig(projectRoot, options, userConfig);
32
- const compiler = new VuReact(finalConfig);
33
- await compiler.execute();
34
- if (finalConfig.watch) {
35
- setupWatcher(compiler, finalConfig);
36
- console.info(
37
- kleur.dim(`
38
- ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
39
- kleur.bold(kleur.magenta("[hrm]")),
40
- kleur.gray(`Watching for file changes...
41
- `)
42
- );
30
+ async function loadUserConfig(root) {
31
+ const tsConfigPath = path.resolve(root, "vureact.config.ts");
32
+ const jsConfigPath = path.resolve(root, "vureact.config.js");
33
+ if (existsSync(tsConfigPath)) {
34
+ return await resolveConfig("TypeScript", tsConfigPath);
43
35
  }
36
+ if (existsSync(jsConfigPath)) {
37
+ return await resolveConfig("JavaScript", jsConfigPath);
38
+ }
39
+ return {};
44
40
  }
45
- async function loadUserConfig(root) {
46
- const configPath = path.resolve(root, "vureact.config.js");
47
- if (!existsSync(configPath)) return {};
41
+ async function resolveConfig(type, configPath) {
48
42
  try {
43
+ if (type === "TypeScript") {
44
+ const { register } = await import("tsx/esm/api");
45
+ register();
46
+ }
49
47
  const configUrl = pathToFileURL(configPath).href;
50
48
  const module = await import(configUrl);
51
49
  return module.default || module;
52
50
  } catch (err) {
53
- console.warn(
54
- kleur.yellow("\n\u26A0"),
55
- `Load config failed at ${configPath}, using default options`,
56
- err
57
- );
51
+ console.warn(kleur.yellow(`\u26A0\uFE0F Load ${type} config failed, using default options.`));
52
+ console.error(err);
58
53
  return {};
59
54
  }
60
55
  }
56
+
57
+ // src/cli/action/config-merger.ts
61
58
  function mergeConfig(projectRoot, options, userConfig) {
62
59
  const merged = {
63
60
  ...userConfig,
64
61
  ...options,
65
62
  root: projectRoot
66
63
  };
67
- if (options.exclude) {
68
- merged.exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude];
69
- } else if (userConfig.exclude) {
70
- merged.exclude = userConfig.exclude;
71
- }
72
64
  merged.output = {
73
65
  ...userConfig.output,
74
66
  workspace: options.workspace ?? userConfig.output?.workspace,
75
- outDir: options.outDir ?? userConfig.output?.outDir,
76
- bootstrapVite: options.bootstrapVite ?? userConfig.output?.bootstrapVite
77
- };
78
- merged.format = {
79
- enabled: options.format ?? userConfig.format?.enabled,
80
- formatter: options.formatter ?? userConfig.format?.formatter
67
+ outDir: options.outDir ?? userConfig.output?.outDir
81
68
  };
82
69
  return merged;
83
70
  }
71
+
72
+ // src/cli/action/file-watcher.ts
73
+ import chokidar from "chokidar";
74
+ import kleur2 from "kleur";
75
+ import ora from "ora";
76
+ import path2 from "path";
84
77
  function setupWatcher(compiler, config) {
85
78
  const spinner = ora();
86
79
  const cmpHelper = new Helper(config);
@@ -111,7 +104,7 @@ function setupWatcher(compiler, config) {
111
104
  ".scss": (p) => compiler.processStyle(p)
112
105
  };
113
106
  const onRecompile = async (event, filePath) => {
114
- const ext = path.extname(filePath);
107
+ const ext = path2.extname(filePath);
115
108
  if (ext in processors) {
116
109
  spinner.start("Recompiling...");
117
110
  const startTime = performance.now();
@@ -126,21 +119,21 @@ function setupWatcher(compiler, config) {
126
119
  spinner.start("Updating assets...");
127
120
  await compiler.processAsset(filePath);
128
121
  cmpHelper.print(
129
- kleur.blue("Copied Asset"),
130
- kleur.dim(normalizePath(cmpHelper.relativePath(filePath)))
122
+ kleur2.blue("Copied Asset"),
123
+ kleur2.dim(normalizePath(cmpHelper.relativePath(filePath)))
131
124
  );
132
125
  }
133
126
  spinner.stop();
134
127
  };
135
128
  const onRemoveFile = async (type, filePath) => {
136
- const ext = path.extname(filePath);
129
+ const ext = path2.extname(filePath);
137
130
  const scriptExtRegex = /\.(js|ts)$/i;
138
- const styleExtRegex = /\.(less|sass|scss)$/i;
131
+ const styleExtRegex = /\.(css|less|sass|scss)$/i;
139
132
  const removeFile = async (type2) => {
140
133
  await compiler.removeOutputPath(filePath, type2);
141
134
  cmpHelper.print(
142
- kleur.yellow("Removed"),
143
- kleur.dim(normalizePath(cmpHelper.relativePath(filePath)))
135
+ kleur2.yellow("Removed"),
136
+ kleur2.dim(normalizePath(cmpHelper.relativePath(filePath)))
144
137
  );
145
138
  };
146
139
  if (type === "unlink") {
@@ -168,9 +161,28 @@ function setupWatcher(compiler, config) {
168
161
  };
169
162
  }
170
163
 
164
+ // src/cli/action/index.ts
165
+ async function resolveAction(root, options) {
166
+ const projectRoot = root ? path3.resolve(process.cwd(), root) : process.cwd();
167
+ const userConfig = await loadUserConfig(projectRoot);
168
+ const finalConfig = mergeConfig(projectRoot, options, userConfig);
169
+ const compiler = new VuReact(finalConfig);
170
+ await compiler.execute();
171
+ if (finalConfig.watch) {
172
+ setupWatcher(compiler, finalConfig);
173
+ console.info(
174
+ kleur3.dim(`
175
+ ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
176
+ kleur3.bold(kleur3.magenta("[hrm]")),
177
+ kleur3.gray(`Watching for file changes...
178
+ `)
179
+ );
180
+ }
181
+ }
182
+
171
183
  // src/cli/option.ts
172
184
  function resolveOptions(command) {
173
- return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output").option("--bootstrapVite", "Enable Vite to initialize a standard React project environment.").option("--exclude <pattern>", "Exclude files/directories (glob pattern)").option("--no-recursive", "Disable recursive search in subdirectories").option("--no-cache", "Disable cache", { default: void 0 }).option("--format", "Enable code formatting", { default: void 0 }).option("--formatter <type>", 'Choose formatter: "prettier" or "builtin"');
185
+ return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output");
174
186
  }
175
187
 
176
188
  // src/cli/update-check.ts
package/lib/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
3
- * @vureact/compiler-core v1.3.0
3
+ * @vureact/compiler-core v1.4.0
4
4
  * (c) 2025-present Ruihong Zhong (Ryan John)
5
5
  * @license MIT
6
6
  */
@@ -13,77 +13,70 @@
13
13
 
14
14
 
15
15
 
16
- var _chunk7LBUUA24js = require('./chunk-7LBUUA24.js');
16
+ var _chunkIVRFEV6Hjs = require('./chunk-IVRFEV6H.js');
17
17
 
18
18
  // src/cli/index.ts
19
19
  var _cac = require('cac');
20
20
 
21
- // src/cli/action.ts
22
- var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
23
- var _fs = require('fs');
21
+ // src/cli/action/index.ts
24
22
  var _kleur = require('kleur'); var _kleur2 = _interopRequireDefault(_kleur);
25
- var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
26
23
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
24
+
25
+ // src/cli/action/config-loader.ts
26
+ var _fs = require('fs');
27
+
28
+
27
29
  var _url = require('url');
28
- async function resolveAction(root, options) {
29
- const projectRoot = root ? _path2.default.resolve(process.cwd(), root) : process.cwd();
30
- const userConfig = await loadUserConfig(projectRoot);
31
- const finalConfig = mergeConfig(projectRoot, options, userConfig);
32
- const compiler = new (0, _chunk7LBUUA24js.VuReact)(finalConfig);
33
- await compiler.execute();
34
- if (finalConfig.watch) {
35
- setupWatcher(compiler, finalConfig);
36
- console.info(
37
- _kleur2.default.dim(`
38
- ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
39
- _kleur2.default.bold(_kleur2.default.magenta("[hrm]")),
40
- _kleur2.default.gray(`Watching for file changes...
41
- `)
42
- );
30
+ async function loadUserConfig(root) {
31
+ const tsConfigPath = _path2.default.resolve(root, "vureact.config.ts");
32
+ const jsConfigPath = _path2.default.resolve(root, "vureact.config.js");
33
+ if (_fs.existsSync.call(void 0, tsConfigPath)) {
34
+ return await resolveConfig("TypeScript", tsConfigPath);
35
+ }
36
+ if (_fs.existsSync.call(void 0, jsConfigPath)) {
37
+ return await resolveConfig("JavaScript", jsConfigPath);
43
38
  }
39
+ return {};
44
40
  }
45
- async function loadUserConfig(root) {
46
- const configPath = _path2.default.resolve(root, "vureact.config.js");
47
- if (!_fs.existsSync.call(void 0, configPath)) return {};
41
+ async function resolveConfig(type, configPath) {
48
42
  try {
43
+ if (type === "TypeScript") {
44
+ const { register } = await Promise.resolve().then(() => _interopRequireWildcard(require("tsx/esm/api")));
45
+ register();
46
+ }
49
47
  const configUrl = _url.pathToFileURL.call(void 0, configPath).href;
50
48
  const module = await Promise.resolve().then(() => _interopRequireWildcard(require(configUrl)));
51
49
  return module.default || module;
52
50
  } catch (err) {
53
- console.warn(
54
- _kleur2.default.yellow("\n\u26A0"),
55
- `Load config failed at ${configPath}, using default options`,
56
- err
57
- );
51
+ console.warn(_kleur2.default.yellow(`\u26A0\uFE0F Load ${type} config failed, using default options.`));
52
+ console.error(err);
58
53
  return {};
59
54
  }
60
55
  }
56
+
57
+ // src/cli/action/config-merger.ts
61
58
  function mergeConfig(projectRoot, options, userConfig) {
62
59
  const merged = {
63
60
  ...userConfig,
64
61
  ...options,
65
62
  root: projectRoot
66
63
  };
67
- if (options.exclude) {
68
- merged.exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude];
69
- } else if (userConfig.exclude) {
70
- merged.exclude = userConfig.exclude;
71
- }
72
64
  merged.output = {
73
65
  ...userConfig.output,
74
66
  workspace: _nullishCoalesce(options.workspace, () => ( _optionalChain([userConfig, 'access', _ => _.output, 'optionalAccess', _2 => _2.workspace]))),
75
- outDir: _nullishCoalesce(options.outDir, () => ( _optionalChain([userConfig, 'access', _3 => _3.output, 'optionalAccess', _4 => _4.outDir]))),
76
- bootstrapVite: _nullishCoalesce(options.bootstrapVite, () => ( _optionalChain([userConfig, 'access', _5 => _5.output, 'optionalAccess', _6 => _6.bootstrapVite])))
77
- };
78
- merged.format = {
79
- enabled: _nullishCoalesce(options.format, () => ( _optionalChain([userConfig, 'access', _7 => _7.format, 'optionalAccess', _8 => _8.enabled]))),
80
- formatter: _nullishCoalesce(options.formatter, () => ( _optionalChain([userConfig, 'access', _9 => _9.format, 'optionalAccess', _10 => _10.formatter])))
67
+ outDir: _nullishCoalesce(options.outDir, () => ( _optionalChain([userConfig, 'access', _3 => _3.output, 'optionalAccess', _4 => _4.outDir])))
81
68
  };
82
69
  return merged;
83
70
  }
71
+
72
+ // src/cli/action/file-watcher.ts
73
+ var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
74
+
75
+ var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
76
+
84
77
  function setupWatcher(compiler, config) {
85
78
  const spinner = _ora2.default.call(void 0, );
86
- const cmpHelper = new (0, _chunk7LBUUA24js.Helper)(config);
79
+ const cmpHelper = new (0, _chunkIVRFEV6Hjs.Helper)(config);
87
80
  const watcher = _chokidar2.default.watch(cmpHelper.getInputPath(), {
88
81
  ignored: cmpHelper.getExcludes(),
89
82
  persistent: true,
@@ -118,16 +111,16 @@ function setupWatcher(compiler, config) {
118
111
  const fn = processors[ext];
119
112
  const unit = await fn(filePath);
120
113
  cmpHelper.printCoreLogs();
121
- cmpHelper.printCompileInfo(filePath, _chunk7LBUUA24js.calcElapsedTime.call(void 0, startTime));
114
+ cmpHelper.printCompileInfo(filePath, _chunkIVRFEV6Hjs.calcElapsedTime.call(void 0, startTime));
122
115
  if (unit) {
123
- await _optionalChain([config, 'access', _11 => _11.onChange, 'optionalCall', _12 => _12(event, unit)]);
116
+ await _optionalChain([config, 'access', _5 => _5.onChange, 'optionalCall', _6 => _6(event, unit)]);
124
117
  }
125
118
  } else {
126
119
  spinner.start("Updating assets...");
127
120
  await compiler.processAsset(filePath);
128
121
  cmpHelper.print(
129
122
  _kleur2.default.blue("Copied Asset"),
130
- _kleur2.default.dim(_chunk7LBUUA24js.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
123
+ _kleur2.default.dim(_chunkIVRFEV6Hjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
131
124
  );
132
125
  }
133
126
  spinner.stop();
@@ -135,12 +128,12 @@ function setupWatcher(compiler, config) {
135
128
  const onRemoveFile = async (type, filePath) => {
136
129
  const ext = _path2.default.extname(filePath);
137
130
  const scriptExtRegex = /\.(js|ts)$/i;
138
- const styleExtRegex = /\.(less|sass|scss)$/i;
131
+ const styleExtRegex = /\.(css|less|sass|scss)$/i;
139
132
  const removeFile = async (type2) => {
140
133
  await compiler.removeOutputPath(filePath, type2);
141
134
  cmpHelper.print(
142
135
  _kleur2.default.yellow("Removed"),
143
- _kleur2.default.dim(_chunk7LBUUA24js.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
136
+ _kleur2.default.dim(_chunkIVRFEV6Hjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
144
137
  );
145
138
  };
146
139
  if (type === "unlink") {
@@ -168,16 +161,35 @@ function setupWatcher(compiler, config) {
168
161
  };
169
162
  }
170
163
 
164
+ // src/cli/action/index.ts
165
+ async function resolveAction(root, options) {
166
+ const projectRoot = root ? _path2.default.resolve(process.cwd(), root) : process.cwd();
167
+ const userConfig = await loadUserConfig(projectRoot);
168
+ const finalConfig = mergeConfig(projectRoot, options, userConfig);
169
+ const compiler = new (0, _chunkIVRFEV6Hjs.VuReact)(finalConfig);
170
+ await compiler.execute();
171
+ if (finalConfig.watch) {
172
+ setupWatcher(compiler, finalConfig);
173
+ console.info(
174
+ _kleur2.default.dim(`
175
+ ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
176
+ _kleur2.default.bold(_kleur2.default.magenta("[hrm]")),
177
+ _kleur2.default.gray(`Watching for file changes...
178
+ `)
179
+ );
180
+ }
181
+ }
182
+
171
183
  // src/cli/option.ts
172
184
  function resolveOptions(command) {
173
- return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output").option("--bootstrapVite", "Enable Vite to initialize a standard React project environment.").option("--exclude <pattern>", "Exclude files/directories (glob pattern)").option("--no-recursive", "Disable recursive search in subdirectories").option("--no-cache", "Disable cache", { default: void 0 }).option("--format", "Enable code formatting", { default: void 0 }).option("--formatter <type>", 'Choose formatter: "prettier" or "builtin"');
185
+ return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output");
174
186
  }
175
187
 
176
188
  // src/cli/update-check.ts
177
189
 
178
190
 
179
191
  var _updatenotifier = require('update-notifier'); var _updatenotifier2 = _interopRequireDefault(_updatenotifier);
180
- var __dirname = _chunk7LBUUA24js.getDirname.call(void 0, import.meta.url);
192
+ var __dirname = _chunkIVRFEV6Hjs.getDirname.call(void 0, import.meta.url);
181
193
  function checkForUpdates() {
182
194
  try {
183
195
  const possiblePaths = [
@@ -217,7 +229,7 @@ function checkForUpdates() {
217
229
  }
218
230
 
219
231
  // src/cli/index.ts
220
- var [programName] = Object.keys(_chunk7LBUUA24js.bin);
232
+ var [programName] = Object.keys(_chunkIVRFEV6Hjs.bin);
221
233
  var cli = _cac.cac.call(void 0, programName);
222
234
  checkForUpdates();
223
235
  var buildCommand = cli.command("build [root]", "Compile Vue3 to React (one-time)");
@@ -228,4 +240,4 @@ var watchCommand = cli.command("watch [root]", "Compile Vue3 to React and watch
228
240
  resolveOptions(watchCommand).action((root, options) => {
229
241
  resolveAction(root, { ...options, watch: true });
230
242
  });
231
- cli.help().version(_chunk7LBUUA24js.version).parse();
243
+ cli.help().version(_chunkIVRFEV6Hjs.version).parse();