@rife/cli 0.0.6-beta.10 → 0.0.6-beta.12

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 (69) hide show
  1. package/dist/cjs/cli.cjs +25 -0
  2. package/dist/cjs/index.cjs +110 -0
  3. package/dist/cjs/logger.cjs +46 -0
  4. package/dist/cjs/plugin/commander.cjs +66 -0
  5. package/dist/cjs/plugin/compiler/compiler.cjs +207 -0
  6. package/dist/cjs/plugin/compiler/index.cjs +126 -0
  7. package/dist/cjs/plugin/compiler/swc.cjs +107 -0
  8. package/dist/cjs/plugin/compiler/tsc.cjs +115 -0
  9. package/dist/cjs/plugin/config.cjs +107 -0
  10. package/dist/cjs/plugin/index.cjs +96 -0
  11. package/dist/cjs/plugin/package.cjs +71 -0
  12. package/dist/cjs/plugin/release.cjs +129 -0
  13. package/dist/cjs/runner.cjs +137 -0
  14. package/dist/{sync.js → cjs/sync.cjs} +12 -23
  15. package/dist/cjs/util.cjs +57 -0
  16. package/dist/{1.mjs → esm/cli.mjs} +4 -3
  17. package/dist/esm/index.mjs +8 -0
  18. package/dist/esm/logger.mjs +14 -0
  19. package/dist/esm/plugin/commander.mjs +34 -0
  20. package/dist/esm/plugin/compiler/compiler.mjs +160 -0
  21. package/dist/esm/plugin/compiler/index.mjs +94 -0
  22. package/dist/esm/plugin/compiler/swc.mjs +75 -0
  23. package/dist/esm/plugin/compiler/tsc.mjs +73 -0
  24. package/dist/esm/plugin/config.mjs +65 -0
  25. package/dist/esm/plugin/index.mjs +7 -0
  26. package/dist/{plugin/package.js → esm/plugin/package.mjs} +11 -14
  27. package/dist/{plugin/release.js → esm/plugin/release.mjs} +33 -38
  28. package/dist/esm/runner.mjs +92 -0
  29. package/dist/esm/sync.mjs +46 -0
  30. package/dist/esm/util.mjs +9 -0
  31. package/package.json +12 -5
  32. package/src/index.ts +2 -0
  33. package/src/plugin/compiler/index.ts +3 -3
  34. package/src/runner.ts +0 -2
  35. package/dist/1.js +0 -24
  36. package/dist/cjs/1.js +0 -24
  37. package/dist/cli.js +0 -22
  38. package/dist/cli.js.map +0 -1
  39. package/dist/esm/1.mjs +0 -20
  40. package/dist/index.js +0 -10
  41. package/dist/index.js.map +0 -1
  42. package/dist/logger.js +0 -18
  43. package/dist/logger.js.map +0 -1
  44. package/dist/plugin/commander.js +0 -47
  45. package/dist/plugin/commander.js.map +0 -1
  46. package/dist/plugin/compiler/compiler.js +0 -166
  47. package/dist/plugin/compiler/compiler.js.map +0 -1
  48. package/dist/plugin/compiler/index.js +0 -87
  49. package/dist/plugin/compiler/index.js.map +0 -1
  50. package/dist/plugin/compiler/swc.js +0 -48
  51. package/dist/plugin/compiler/swc.js.map +0 -1
  52. package/dist/plugin/compiler/swc2.js +0 -65
  53. package/dist/plugin/compiler/swc2.js.map +0 -1
  54. package/dist/plugin/compiler/tsc.js +0 -75
  55. package/dist/plugin/compiler/tsc.js.map +0 -1
  56. package/dist/plugin/config.js +0 -77
  57. package/dist/plugin/config.js.map +0 -1
  58. package/dist/plugin/index.js +0 -9
  59. package/dist/plugin/index.js.map +0 -1
  60. package/dist/plugin/package copy.js +0 -32
  61. package/dist/plugin/package copy.js.map +0 -1
  62. package/dist/plugin/package.js.map +0 -1
  63. package/dist/plugin/release.js.map +0 -1
  64. package/dist/runner.js +0 -82
  65. package/dist/runner.js.map +0 -1
  66. package/dist/sync.js.map +0 -1
  67. package/dist/tsconfig.tsbuildinfo +0 -1
  68. package/dist/util.js +0 -14
  69. package/dist/util.js.map +0 -1
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ commander: function(module) {
4
+ module.exports = require("commander");
5
+ }
6
+ };
7
+ var __webpack_module_cache__ = {};
8
+ function __webpack_require__(moduleId) {
9
+ var cachedModule = __webpack_module_cache__[moduleId];
10
+ if (void 0 !== cachedModule) return cachedModule.exports;
11
+ var module = __webpack_module_cache__[moduleId] = {
12
+ exports: {}
13
+ };
14
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
+ return module.exports;
16
+ }
17
+ (()=>{
18
+ __webpack_require__.n = (module)=>{
19
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
20
+ __webpack_require__.d(getter, {
21
+ a: getter
22
+ });
23
+ return getter;
24
+ };
25
+ })();
26
+ (()=>{
27
+ __webpack_require__.d = (exports1, definition)=>{
28
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
29
+ enumerable: true,
30
+ get: definition[key]
31
+ });
32
+ };
33
+ })();
34
+ (()=>{
35
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
36
+ })();
37
+ (()=>{
38
+ __webpack_require__.r = (exports1)=>{
39
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
40
+ value: 'Module'
41
+ });
42
+ Object.defineProperty(exports1, '__esModule', {
43
+ value: true
44
+ });
45
+ };
46
+ })();
47
+ var __webpack_exports__ = {};
48
+ (()=>{
49
+ __webpack_require__.r(__webpack_exports__);
50
+ __webpack_require__.d(__webpack_exports__, {
51
+ defineConfig: ()=>defineConfig,
52
+ createRunner: ()=>createRunner
53
+ });
54
+ const utils_namespaceObject = require("consola/utils");
55
+ const external_tapable_namespaceObject = require("tapable");
56
+ const external_zod_namespaceObject = require("zod");
57
+ var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
58
+ const external_logger_cjs_namespaceObject = require("./logger.cjs");
59
+ const external_util_cjs_namespaceObject = require("./util.cjs");
60
+ if (void 0 === Promise.withResolvers) Promise.withResolvers = ()=>{
61
+ let resolve;
62
+ let reject;
63
+ const promise = new Promise((res, rej)=>{
64
+ resolve = res;
65
+ reject = rej;
66
+ });
67
+ return {
68
+ promise,
69
+ resolve: resolve,
70
+ reject: reject
71
+ };
72
+ };
73
+ function createRunner() {
74
+ const perfStart = performance.now();
75
+ const { Command } = __webpack_require__("commander");
76
+ const command = new Command();
77
+ command.option('--debug', "\u6253\u5F00\u8C03\u8BD5\u65E5\u5FD7");
78
+ command.option('-n, --name <string>', "\u6267\u884C\u6307\u5B9A\u914D\u7F6E");
79
+ command.option('-h, --help', "\u5E2E\u52A9");
80
+ command.parse();
81
+ const args = external_zod_default().object({
82
+ debug: external_zod_default().boolean().default(false)
83
+ }).default({}).safeParse(command.opts());
84
+ const runner = {
85
+ env: 'prod',
86
+ hook: {
87
+ loadPackage: new external_tapable_namespaceObject.AsyncSeriesHook([]),
88
+ loadConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
89
+ validateConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
90
+ applyConfig: new external_tapable_namespaceObject.AsyncSeriesHook([]),
91
+ validatePlugin: new external_tapable_namespaceObject.AsyncSeriesHook([]),
92
+ registerCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
93
+ startCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
94
+ finishCommand: new external_tapable_namespaceObject.AsyncSeriesHook([]),
95
+ dev: new external_tapable_namespaceObject.AsyncSeriesHook([]),
96
+ build: new external_tapable_namespaceObject.AsyncSeriesHook([]),
97
+ test: new external_tapable_namespaceObject.AsyncSeriesHook([]),
98
+ release: new external_tapable_namespaceObject.AsyncSeriesHook([]),
99
+ deploy: new external_tapable_namespaceObject.AsyncSeriesHook([]),
100
+ lint: new external_tapable_namespaceObject.AsyncSeriesHook([])
101
+ },
102
+ logger: (0, external_logger_cjs_namespaceObject.createLogger)(args.data),
103
+ command,
104
+ config: {
105
+ all: [],
106
+ current: void 0
107
+ },
108
+ package: {},
109
+ z: external_zod_default(),
110
+ fs: external_util_cjs_namespaceObject.fs,
111
+ glob: external_util_cjs_namespaceObject.glob.glob,
112
+ get duration () {
113
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
114
+ return `\u{8017}\u{65F6} ${duration} s`;
115
+ },
116
+ tempDir: './node_modules/.temp/',
117
+ clear: ()=>{
118
+ console.clear();
119
+ process.stdout.write('\x1b[3J');
120
+ console.log(`${utils_namespaceObject.colors.bgBlue(" \u9879\u76EE\u540D\u79F0 ")} ${runner.package.name} \n`);
121
+ }
122
+ };
123
+ return runner;
124
+ }
125
+ function defineConfig(all) {
126
+ return all;
127
+ }
128
+ })();
129
+ exports.createRunner = __webpack_exports__.createRunner;
130
+ exports.defineConfig = __webpack_exports__.defineConfig;
131
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
132
+ "createRunner",
133
+ "defineConfig"
134
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
135
+ Object.defineProperty(exports, '__esModule', {
136
+ value: true
137
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ var __webpack_exports__ = {};
3
2
  async function sync(name) {
4
3
  const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
5
4
  headers: {
@@ -12,33 +11,21 @@ async function sync(name) {
12
11
  'sec-fetch-mode': 'cors',
13
12
  'sec-fetch-site': 'same-site',
14
13
  Referer: 'https://npmmirror.com/',
15
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
14
+ 'Referrer-Policy': 'strict-origin-when-cross-origin'
16
15
  },
17
16
  body: null,
18
- method: 'PUT',
17
+ method: 'PUT'
19
18
  });
20
19
  const body = await res.json();
21
- if (body.ok === true) {
22
- console.log(`同步 ${name} 成功`);
23
- }
20
+ if (true === body.ok) console.log(`\u{540C}\u{6B65} ${name} \u{6210}\u{529F}`);
24
21
  return body;
25
22
  }
26
23
  const list = [
27
- '@rife/config', //
28
- '@rife/cli', //
29
- // '@rife/infra',
30
- // '@rife/logger',
31
- // '@rife/react',
32
- // '@rife/next',
33
- // '@rife/nest',
34
- // '@rife/plugin-deploy',
35
- // '@rife/fast',
24
+ '@rife/config',
25
+ '@rife/cli'
36
26
  ];
37
27
  async function main() {
38
- for (const item of list) {
39
- // https://registry.npmmirror.com/-/package/@rife/infra/syncs/65a255a2afa293666acf6655/log
40
- await sync(item);
41
- }
28
+ for (const item of list)await sync(item);
42
29
  poll();
43
30
  }
44
31
  main();
@@ -47,8 +34,7 @@ async function get(name) {
47
34
  const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
48
35
  const data = await res.json();
49
36
  return `${name} ${data?.['dist-tags']?.['latest']}`;
50
- }
51
- catch (e) {
37
+ } catch (e) {
52
38
  return `${name} error`;
53
39
  }
54
40
  }
@@ -57,4 +43,7 @@ async function poll() {
57
43
  console.log(`${res.join('\n')}\n`);
58
44
  setTimeout(poll, 1000);
59
45
  }
60
- //# sourceMappingURL=sync.js.map
46
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ getDuration: ()=>getDuration,
37
+ glob: ()=>external_glob_namespaceObject,
38
+ fs: ()=>external_fs_extra_default()
39
+ });
40
+ const external_fs_extra_namespaceObject = require("fs-extra");
41
+ var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
42
+ const external_glob_namespaceObject = require("glob");
43
+ const getDuration = (perfStart)=>{
44
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
45
+ return `\u{8017}\u{65F6} ${duration} s`;
46
+ };
47
+ exports.fs = __webpack_exports__.fs;
48
+ exports.getDuration = __webpack_exports__.getDuration;
49
+ exports.glob = __webpack_exports__.glob;
50
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
51
+ "fs",
52
+ "getDuration",
53
+ "glob"
54
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -1,6 +1,7 @@
1
- import { pluginCommander, pluginConfig, pluginPackage } from './plugin';
2
- import { pluginRelease } from './plugin/release';
3
- import { createRunner } from './runner';
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { pluginCommander, pluginConfig, pluginPackage, pluginRelease } from "./plugin/index.mjs";
4
+ import { createRunner } from "./runner.mjs";
4
5
  const plugins = [
5
6
  pluginPackage(),
6
7
  pluginConfig(),
@@ -0,0 +1,8 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import external_fs_extra_default from "fs-extra";
4
+ export * from "./runner.mjs";
5
+ export * from "./plugin/index.mjs";
6
+ export * from "./logger.mjs";
7
+ export * from "tapable";
8
+ export { external_fs_extra_default as fs };
@@ -0,0 +1,14 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { createConsola } from "consola";
4
+ function createLogger(options) {
5
+ const instance = createConsola({
6
+ level: options?.debug ? 4 : 3,
7
+ formatOptions: {
8
+ compact: false,
9
+ date: false
10
+ }
11
+ });
12
+ return instance;
13
+ }
14
+ export { createLogger };
@@ -0,0 +1,34 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ function pluginCommander() {
4
+ const plugin = {
5
+ name: pluginCommander.name,
6
+ apply: (runner)=>{
7
+ const { hook, command, config, z, logger } = runner;
8
+ const log = logger.withTag(pluginCommander.name);
9
+ hook.registerCommand.tapPromise(pluginCommander.name, async ()=>{
10
+ command.command('dev').description("\u542F\u52A8\u5F00\u53D1").action(async ()=>{
11
+ process.env.NODE_ENV = 'development';
12
+ await hook.dev.promise();
13
+ });
14
+ command.command('build').description("\u6784\u5EFA\u9879\u76EE").action(async ()=>{
15
+ process.env.NODE_ENV = 'production';
16
+ await hook.build.promise();
17
+ });
18
+ command.command('release').description("\u53D1\u5E03\u5305").action(async ()=>{
19
+ await hook.release.promise();
20
+ });
21
+ command.command('deploy').description("\u90E8\u7F72\u9879\u76EE").action(async ()=>{
22
+ await hook.deploy.promise().catch((e)=>{
23
+ log.fail(`\u{90E8}\u{7F72}\u{5931}\u{8D25}\u{FF0C}${runner.duration}\u{FF0C}${e.message}`);
24
+ });
25
+ });
26
+ });
27
+ hook.startCommand.tapPromise(pluginCommander.name, async ()=>{
28
+ await command.parseAsync(process.argv);
29
+ });
30
+ }
31
+ };
32
+ return plugin;
33
+ }
34
+ export { pluginCommander };
@@ -0,0 +1,160 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import * as __WEBPACK_EXTERNAL_MODULE_consola_utils_6b69f78e__ from "consola/utils";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
5
+ import external_path_default from "path";
6
+ import { swc } from "./swc.mjs";
7
+ import { tsc } from "./tsc.mjs";
8
+ var __webpack_modules__ = {
9
+ "consola/utils": function(module) {
10
+ module.exports = __WEBPACK_EXTERNAL_MODULE_consola_utils_6b69f78e__;
11
+ },
12
+ typescript: function(module) {
13
+ module.exports = __WEBPACK_EXTERNAL_MODULE_typescript__;
14
+ }
15
+ };
16
+ var __webpack_module_cache__ = {};
17
+ function __webpack_require__(moduleId) {
18
+ var cachedModule = __webpack_module_cache__[moduleId];
19
+ if (void 0 !== cachedModule) return cachedModule.exports;
20
+ var module = __webpack_module_cache__[moduleId] = {
21
+ exports: {}
22
+ };
23
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
24
+ return module.exports;
25
+ }
26
+ var utils_ = __webpack_require__("consola/utils");
27
+ const clear = ()=>{
28
+ console.clear();
29
+ process.stdout.write('\x1b[3J');
30
+ };
31
+ async function compileTs(runner, tsxConfig, { dev, build } = {
32
+ dev: false,
33
+ build: true
34
+ }) {
35
+ const { logger, fs } = runner;
36
+ const log = logger.withTag(compileTs.name);
37
+ log.debug('tsxConfig %j', tsxConfig);
38
+ if (tsxConfig.clean) {
39
+ log.info("\u6E05\u7A7A\u76EE\u5F55 %s", tsxConfig.outDir);
40
+ await fs.emptyDir(tsxConfig.outDir);
41
+ }
42
+ const showProjectName = ()=>{
43
+ clear();
44
+ console.log(`${utils_.colors.bgBlue(" \u9879\u76EE\u540D\u79F0 ")} ${runner.package.name} \n`);
45
+ };
46
+ if ('tsc' === tsxConfig.type) {
47
+ const diagnostics = [];
48
+ let perfStart = performance.now();
49
+ tsc({
50
+ ...tsxConfig,
51
+ watch: dev,
52
+ onWatchStatusChanged: (data)=>{
53
+ switch(data.status){
54
+ case 'startWatch':
55
+ diagnostics.length = 0;
56
+ perfStart = performance.now();
57
+ break;
58
+ case 'reCompile':
59
+ diagnostics.length = 0;
60
+ perfStart = performance.now();
61
+ if (dev) showProjectName();
62
+ break;
63
+ case 'error':
64
+ {
65
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
66
+ log.error(`\u{7C7B}\u{578B}\u{68C0}\u{67E5}\u{5931}\u{8D25}\u{FF0C}\u{8017}\u{65F6} ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
67
+ break;
68
+ }
69
+ case 'success':
70
+ {
71
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
72
+ log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
73
+ break;
74
+ }
75
+ default:
76
+ console.log(data);
77
+ process.exit(1);
78
+ }
79
+ },
80
+ onReportDiagnostic: ({ diagnostic })=>{
81
+ diagnostics.push(diagnostic);
82
+ },
83
+ onEmitDiagnostics: ({ diagnostics })=>{
84
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
85
+ if (diagnostics.length) {
86
+ log.error(`\u{7F16}\u{8BD1}\u{5931}\u{8D25}\u{FF0C}\u{8017}\u{65F6} ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
87
+ runner.compiler.fail = true;
88
+ } else log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
89
+ }
90
+ });
91
+ return;
92
+ }
93
+ if ('swc' === tsxConfig.type) {
94
+ const { promise, resolve } = Promise.withResolvers();
95
+ swc({
96
+ ...tsxConfig,
97
+ watch: dev,
98
+ onSuccess: async ({ watch, first, duration })=>{
99
+ if (watch && !first) showProjectName();
100
+ log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${(duration / 1000).toFixed(3)} s`);
101
+ if (dev) runner.compiler.hook.execMain.promise();
102
+ await runner.compiler.hook.checkAndEmitType.promise();
103
+ resolve();
104
+ },
105
+ onFail: ({ watch, first, duration, reasons })=>{
106
+ if (watch && !first) showProjectName();
107
+ const message = [
108
+ ...reasons.entries()
109
+ ].map(([key, value])=>{
110
+ const index = value.indexOf(key);
111
+ if (index > -1) return value.replace(key, external_path_default.resolve(key));
112
+ return `${value}`;
113
+ }).join('\n');
114
+ log.error(`\u{7F16}\u{8BD1}\u{5931}\u{8D25}\u{FF0C}\u{8017}\u{65F6} ${(duration / 1000).toFixed(3)} s\n\n%s`, message);
115
+ runner.compiler.fail = true;
116
+ resolve();
117
+ }
118
+ });
119
+ if (build) return promise;
120
+ return;
121
+ }
122
+ log.error(`compiler type '${tsxConfig.type}' \u{4E0D}\u{5B58}\u{5728}`);
123
+ process.exit(1);
124
+ }
125
+ function checkAndEmitType() {
126
+ const perfStart = performance.now();
127
+ const ts = __webpack_require__("typescript");
128
+ const tsConfigPath = external_path_default.resolve('tsconfig.json');
129
+ const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
130
+ const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, external_path_default.dirname(tsConfigPath), {
131
+ noEmit: true,
132
+ incremental: false
133
+ });
134
+ if (true === compilerOptions.options.declaration) {
135
+ compilerOptions.options.noEmit = false;
136
+ compilerOptions.options.emitDeclarationOnly = true;
137
+ }
138
+ const host = ts.createCompilerHost(compilerOptions.options);
139
+ const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
140
+ const emitResult = program.emit();
141
+ const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
142
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
143
+ return {
144
+ diagnostics,
145
+ duration
146
+ };
147
+ }
148
+ function formatDiagnostic(diagnostics) {
149
+ const ts = __webpack_require__("typescript");
150
+ const { colors } = __webpack_require__("consola/utils");
151
+ return diagnostics.map((diagnostic)=>{
152
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
153
+ if (diagnostic.file) {
154
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
155
+ return `${colors.gray(diagnostic.file.fileName)} ${colors.yellow(`(${line + 1},${character + 1})`)}: ${colors.white(message)}`;
156
+ }
157
+ return message;
158
+ }).join('\n');
159
+ }
160
+ export { checkAndEmitType, compileTs, formatDiagnostic };
@@ -0,0 +1,94 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
4
+ import { AsyncSeriesHook } from "tapable";
5
+ import { checkAndEmitType, compileTs, formatDiagnostic } from "./compiler.mjs";
6
+ import { getDuration } from "../../util.mjs";
7
+ var __webpack_modules__ = {
8
+ child_process: function(module) {
9
+ module.exports = __WEBPACK_EXTERNAL_MODULE_child_process__;
10
+ }
11
+ };
12
+ var __webpack_module_cache__ = {};
13
+ function __webpack_require__(moduleId) {
14
+ var cachedModule = __webpack_module_cache__[moduleId];
15
+ if (void 0 !== cachedModule) return cachedModule.exports;
16
+ var module = __webpack_module_cache__[moduleId] = {
17
+ exports: {}
18
+ };
19
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
20
+ return module.exports;
21
+ }
22
+ function pluginCompiler(options) {
23
+ const plugin = {
24
+ name: pluginCompiler.name,
25
+ apply: (runner)=>{
26
+ const { hook, logger, z, fs } = runner;
27
+ const log = logger.withTag(pluginCompiler.name);
28
+ const validation = z.object({
29
+ tsx: z.object({
30
+ type: z.enum([
31
+ 'tsc',
32
+ 'swc'
33
+ ]).default('swc'),
34
+ rootDir: z.string().trim().min(1).default('.'),
35
+ outDir: z.string().trim().min(1).default('./dist/'),
36
+ clean: z.boolean().default(true),
37
+ main: z.string().trim().optional(),
38
+ options: z.object({}).passthrough().optional()
39
+ }).default({})
40
+ }).optional().default({}).safeParse(options);
41
+ if (!validation.success) {
42
+ log.error("\u914D\u7F6E\u9519\u8BEF\n", validation.error.message);
43
+ process.exit(1);
44
+ }
45
+ runner.compiler = {
46
+ fail: false,
47
+ process: null,
48
+ hook: {
49
+ checkAndEmitType: new AsyncSeriesHook(),
50
+ execMain: new AsyncSeriesHook()
51
+ },
52
+ tsx: validation.data.tsx
53
+ };
54
+ hook.dev.tapPromise(pluginCompiler.name, async ()=>{
55
+ const tsxConfig = validation.data.tsx;
56
+ compileTs(runner, tsxConfig, {
57
+ dev: true
58
+ });
59
+ });
60
+ hook.build.tapPromise(pluginCompiler.name, async ()=>{
61
+ const perfStart = performance.now();
62
+ const tsxConfig = validation.data.tsx;
63
+ await compileTs(runner, tsxConfig, {
64
+ build: true
65
+ });
66
+ if (runner.compiler.fail) {
67
+ log.fail(`\u{6784}\u{5EFA}\u{5931}\u{8D25}\u{FF0C}${getDuration(perfStart)}`);
68
+ process.exit(1);
69
+ } else log.success(`\u{6784}\u{5EFA}\u{6210}\u{529F}\u{FF0C}${getDuration(perfStart)}`);
70
+ });
71
+ runner.compiler.hook.checkAndEmitType.tapPromise(pluginCompiler.name, async ()=>{
72
+ const { diagnostics, duration } = checkAndEmitType();
73
+ if (diagnostics.length) {
74
+ log.error(`\u{7C7B}\u{578B}\u{68C0}\u{67E5}\u{5931}\u{8D25}\u{FF0C}\u{8017}\u{65F6} ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
75
+ runner.compiler.fail = true;
76
+ } else log.success(`\u{7C7B}\u{578B}\u{68C0}\u{67E5}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
77
+ });
78
+ runner.compiler.hook.execMain.tapPromise(pluginCompiler.name, async ()=>{
79
+ const compiler = runner.compiler;
80
+ const { main } = compiler.tsx;
81
+ if (!main) return void log.debug("\u6CA1\u6709\u6307\u5B9A main");
82
+ if (!await fs.exists(main)) return void log.warn(`\u{542F}\u{52A8}\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728} %s`, main);
83
+ log.info(`\u{542F}\u{52A8}\u{6587}\u{4EF6} node %s`, main);
84
+ const { fork } = __webpack_require__("child_process");
85
+ compiler.process?.kill();
86
+ compiler.process = fork(main, {
87
+ stdio: 'inherit'
88
+ });
89
+ });
90
+ }
91
+ };
92
+ return plugin;
93
+ }
94
+ export { pluginCompiler };
@@ -0,0 +1,75 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import * as __WEBPACK_EXTERNAL_MODULE__swc_cli_524a95a0__ from "@swc/cli";
4
+ var __webpack_modules__ = {
5
+ "@swc/cli": function(module) {
6
+ module.exports = __WEBPACK_EXTERNAL_MODULE__swc_cli_524a95a0__;
7
+ }
8
+ };
9
+ var __webpack_module_cache__ = {};
10
+ function __webpack_require__(moduleId) {
11
+ var cachedModule = __webpack_module_cache__[moduleId];
12
+ if (void 0 !== cachedModule) return cachedModule.exports;
13
+ var module = __webpack_module_cache__[moduleId] = {
14
+ exports: {}
15
+ };
16
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
17
+ return module.exports;
18
+ }
19
+ async function swc(options) {
20
+ const { watch = false, outDir } = options;
21
+ const { swcDir } = __webpack_require__("@swc/cli");
22
+ const swcOptions = {
23
+ jsc: {
24
+ parser: {
25
+ syntax: "typescript"
26
+ },
27
+ target: 'esnext',
28
+ externalHelpers: true
29
+ },
30
+ module: {
31
+ type: 'commonjs',
32
+ ignoreDynamic: true
33
+ },
34
+ sourceMaps: true
35
+ };
36
+ let first = true;
37
+ await swcDir({
38
+ cliOptions: {
39
+ outDir,
40
+ watch,
41
+ filenames: [
42
+ './src'
43
+ ],
44
+ extensions: [
45
+ '.ts',
46
+ '.tsx',
47
+ '.js',
48
+ '.jsx'
49
+ ],
50
+ stripLeadingPaths: true,
51
+ copyFiles: true
52
+ },
53
+ swcOptions,
54
+ callbacks: {
55
+ onSuccess: ({ duration })=>{
56
+ options?.onSuccess?.({
57
+ watch,
58
+ first,
59
+ duration
60
+ });
61
+ first = false;
62
+ },
63
+ onFail: (e)=>{
64
+ options?.onFail?.({
65
+ ...e,
66
+ watch,
67
+ first
68
+ });
69
+ first = false;
70
+ },
71
+ onWatchReady: ()=>{}
72
+ }
73
+ });
74
+ }
75
+ export { swc };