@rife/cli 0.0.6-beta.14 → 0.0.6-beta.16

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 (71) hide show
  1. package/dist/cjs/logger.cjs +2 -0
  2. package/dist/cjs/plugin/commander.cjs +5 -5
  3. package/dist/cjs/plugin/config.cjs +4 -4
  4. package/dist/cjs/plugin/index.cjs +3 -12
  5. package/dist/cjs/plugin/package.cjs +2 -2
  6. package/dist/cjs/plugin/release.cjs +16 -16
  7. package/dist/cjs/runner.cjs +9 -6
  8. package/dist/cjs/sync.cjs +1 -1
  9. package/dist/cjs/util.cjs +2 -2
  10. package/dist/cli.js +22 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/esm/cli.mjs +1 -1
  13. package/dist/esm/index.mjs +1 -1
  14. package/dist/esm/logger.mjs +3 -1
  15. package/dist/esm/plugin/commander.mjs +6 -6
  16. package/dist/esm/plugin/config.mjs +6 -6
  17. package/dist/esm/plugin/index.mjs +1 -2
  18. package/dist/esm/plugin/package.mjs +4 -4
  19. package/dist/esm/plugin/release.mjs +17 -17
  20. package/dist/esm/runner.mjs +14 -11
  21. package/dist/esm/sync.mjs +2 -2
  22. package/dist/esm/util.mjs +4 -4
  23. package/dist/index.js +10 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/logger.js +18 -0
  26. package/dist/logger.js.map +1 -0
  27. package/dist/plugin/commander.js +47 -0
  28. package/dist/plugin/commander.js.map +1 -0
  29. package/{src/plugin/compiler/compiler.ts → dist/plugin/compiler/compiler.js} +39 -71
  30. package/dist/plugin/compiler/compiler.js.map +1 -0
  31. package/dist/plugin/compiler/index.js +87 -0
  32. package/dist/plugin/compiler/index.js.map +1 -0
  33. package/{src/plugin/compiler/swc.ts → dist/plugin/compiler/swc.js} +48 -56
  34. package/dist/plugin/compiler/swc.js.map +1 -0
  35. package/{src/plugin/compiler/tsc.ts → dist/plugin/compiler/tsc.js} +75 -101
  36. package/dist/plugin/compiler/tsc.js.map +1 -0
  37. package/dist/plugin/config.js +77 -0
  38. package/dist/plugin/config.js.map +1 -0
  39. package/dist/plugin/index.js +9 -0
  40. package/dist/plugin/index.js.map +1 -0
  41. package/dist/plugin/package.js +32 -0
  42. package/dist/plugin/package.js.map +1 -0
  43. package/dist/plugin/release.js +102 -0
  44. package/dist/plugin/release.js.map +1 -0
  45. package/dist/runner.js +82 -0
  46. package/dist/runner.js.map +1 -0
  47. package/dist/sync.js +60 -0
  48. package/dist/sync.js.map +1 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -0
  50. package/dist/util.js +14 -0
  51. package/dist/util.js.map +1 -0
  52. package/package.json +8 -18
  53. package/src/cli.ts +23 -23
  54. package/src/index.ts +3 -9
  55. package/src/logger.ts +17 -16
  56. package/src/plugin/commander.ts +49 -49
  57. package/src/plugin/config.ts +78 -78
  58. package/src/plugin/index.ts +0 -1
  59. package/src/plugin/release.ts +113 -113
  60. package/src/runner.ts +132 -128
  61. package/src/sync.ts +63 -63
  62. package/src/util.ts +9 -9
  63. package/dist/cjs/plugin/compiler/compiler.cjs +0 -207
  64. package/dist/cjs/plugin/compiler/index.cjs +0 -126
  65. package/dist/cjs/plugin/compiler/swc.cjs +0 -107
  66. package/dist/cjs/plugin/compiler/tsc.cjs +0 -115
  67. package/dist/esm/plugin/compiler/compiler.mjs +0 -160
  68. package/dist/esm/plugin/compiler/index.mjs +0 -94
  69. package/dist/esm/plugin/compiler/swc.mjs +0 -75
  70. package/dist/esm/plugin/compiler/tsc.mjs +0 -73
  71. package/src/plugin/compiler/index.ts +0 -115
package/src/runner.ts CHANGED
@@ -1,128 +1,132 @@
1
- import type { ConsolaInstance } from 'consola';
2
- import { colors } from 'consola/utils';
3
- import { AsyncSeriesHook } from 'tapable';
4
- import zod from 'zod';
5
-
6
- import { createLogger } from './logger';
7
- import { fs, glob } from './util';
8
-
9
- export interface Config {
10
- name: string;
11
- plugins: Plugin[];
12
- }
13
-
14
- export interface Runner {
15
- env: 'prod' | 'dev';
16
- hook: {
17
- loadPackage: AsyncSeriesHook<[]>;
18
- loadConfig: AsyncSeriesHook<[]>;
19
- validateConfig: AsyncSeriesHook<[]>;
20
- applyConfig: AsyncSeriesHook<[]>;
21
- validatePlugin: AsyncSeriesHook<[]>;
22
- registerCommand: AsyncSeriesHook<[]>;
23
- startCommand: AsyncSeriesHook<[]>;
24
- finishCommand: AsyncSeriesHook<[]>;
25
- dev: AsyncSeriesHook<[]>;
26
- build: AsyncSeriesHook<[]>;
27
- test: AsyncSeriesHook<[]>;
28
- release: AsyncSeriesHook<[]>;
29
- deploy: AsyncSeriesHook<[]>;
30
- lint: AsyncSeriesHook<[]>;
31
- };
32
- logger: ConsolaInstance;
33
- config: {
34
- all: Config[];
35
- current: Config;
36
- };
37
- command: import('commander').Command;
38
- package: any;
39
- z: typeof zod;
40
- fs: typeof import('fs-extra');
41
- glob: typeof import('glob')['glob'];
42
- duration: string;
43
- tempDir: string;
44
- clear: () => void;
45
- }
46
-
47
- export interface Plugin {
48
- name: string;
49
- apply: (runner: Runner) => any;
50
- }
51
-
52
- if (typeof Promise.withResolvers === 'undefined') {
53
- Promise.withResolvers = <T>() => {
54
- let resolve: (value: T | PromiseLike<T>) => void;
55
- let reject: (reason?: unknown) => void;
56
- const promise = new Promise<T>((res, rej) => {
57
- resolve = res;
58
- reject = rej;
59
- });
60
- return { promise, resolve: resolve!, reject: reject! };
61
- };
62
- }
63
-
64
- export function createRunner() {
65
- const perfStart = performance.now();
66
-
67
- const { Command } = require('commander') as typeof import('commander');
68
- const command = new Command();
69
-
70
- command.option('--debug', '打开调试日志');
71
- command.option('-n, --name <string>', '执行指定配置');
72
- command.option('-h, --help', '帮助');
73
- command.parse();
74
-
75
- const args = zod
76
- .object({
77
- debug: zod.boolean().default(false),
78
- })
79
- .default({})
80
- .safeParse(command.opts());
81
-
82
- const runner: Runner = {
83
- env: 'prod',
84
- hook: {
85
- loadPackage: new AsyncSeriesHook([]),
86
- loadConfig: new AsyncSeriesHook([]),
87
- validateConfig: new AsyncSeriesHook([]),
88
- applyConfig: new AsyncSeriesHook([]),
89
- validatePlugin: new AsyncSeriesHook([]),
90
- registerCommand: new AsyncSeriesHook([]),
91
- startCommand: new AsyncSeriesHook([]),
92
- finishCommand: new AsyncSeriesHook([]),
93
- dev: new AsyncSeriesHook([]),
94
- build: new AsyncSeriesHook([]),
95
- test: new AsyncSeriesHook([]),
96
- release: new AsyncSeriesHook([]),
97
- deploy: new AsyncSeriesHook([]),
98
- lint: new AsyncSeriesHook([]),
99
- },
100
- logger: createLogger(args.data),
101
- command,
102
- config: {
103
- all: [],
104
- // @ts-expect-error
105
- current: undefined,
106
- },
107
- package: {},
108
- z: zod,
109
- fs,
110
- glob: glob.glob,
111
- get duration() {
112
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
113
- return `耗时 ${duration} s`;
114
- },
115
- tempDir: './node_modules/.temp/',
116
- clear: () => {
117
- console.clear();
118
- process.stdout.write('\x1b[3J');
119
- console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
120
- },
121
- };
122
-
123
- return runner;
124
- }
125
-
126
- export function defineConfig(all: Config[]) {
127
- return all;
128
- }
1
+ import type { ConsolaInstance } from 'consola';
2
+ import { colors } from 'consola/utils';
3
+ import { AsyncSeriesHook } from 'tapable';
4
+ import zod from 'zod';
5
+
6
+ import { createLogger } from './logger';
7
+ import { fs, glob } from './util';
8
+
9
+ export interface Config {
10
+ name: string;
11
+ plugins: Plugin[];
12
+ }
13
+
14
+ export interface Runner {
15
+ env: 'prod' | 'dev';
16
+ hook: {
17
+ loadPackage: AsyncSeriesHook<[]>;
18
+ loadConfig: AsyncSeriesHook<[]>;
19
+ validateConfig: AsyncSeriesHook<[]>;
20
+ applyConfig: AsyncSeriesHook<[]>;
21
+ validatePlugin: AsyncSeriesHook<[]>;
22
+ registerCommand: AsyncSeriesHook<[]>;
23
+ startCommand: AsyncSeriesHook<[]>;
24
+ finishCommand: AsyncSeriesHook<[]>;
25
+ dev: AsyncSeriesHook<[]>;
26
+ build: AsyncSeriesHook<[]>;
27
+ test: AsyncSeriesHook<[]>;
28
+ release: AsyncSeriesHook<[]>;
29
+ deploy: AsyncSeriesHook<[]>;
30
+ lint: AsyncSeriesHook<[]>;
31
+ };
32
+ logger: ConsolaInstance;
33
+ config: {
34
+ all: Config[];
35
+ current: Config;
36
+ };
37
+ command: import('commander').Command;
38
+ package: any;
39
+ z: typeof zod;
40
+ fs: typeof import('fs-extra');
41
+ glob: typeof import('glob')['glob'];
42
+ duration: string;
43
+ tempDir: string;
44
+ clear: () => void;
45
+ throwError: (message?: string, options?: ErrorOptions) => never;
46
+ }
47
+
48
+ export interface Plugin {
49
+ name: string;
50
+ apply: (runner: Runner) => any;
51
+ }
52
+
53
+ if (typeof Promise.withResolvers === 'undefined') {
54
+ Promise.withResolvers = <T>() => {
55
+ let resolve: (value: T | PromiseLike<T>) => void;
56
+ let reject: (reason?: unknown) => void;
57
+ const promise = new Promise<T>((res, rej) => {
58
+ resolve = res;
59
+ reject = rej;
60
+ });
61
+ return { promise, resolve: resolve!, reject: reject! };
62
+ };
63
+ }
64
+
65
+ export function createRunner() {
66
+ const perfStart = performance.now();
67
+
68
+ const { Command } = require('commander') as typeof import('commander');
69
+ const command = new Command();
70
+
71
+ command.option('--debug', '打开调试日志');
72
+ command.option('-n, --name <string>', '执行指定配置');
73
+ command.option('-h, --help', '帮助');
74
+ command.parse();
75
+
76
+ const args = zod
77
+ .object({
78
+ debug: zod.boolean().default(false),
79
+ })
80
+ .default({})
81
+ .safeParse(command.opts());
82
+
83
+ const runner: Runner = {
84
+ env: 'prod',
85
+ hook: {
86
+ loadPackage: new AsyncSeriesHook([]),
87
+ loadConfig: new AsyncSeriesHook([]),
88
+ validateConfig: new AsyncSeriesHook([]),
89
+ applyConfig: new AsyncSeriesHook([]),
90
+ validatePlugin: new AsyncSeriesHook([]),
91
+ registerCommand: new AsyncSeriesHook([]),
92
+ startCommand: new AsyncSeriesHook([]),
93
+ finishCommand: new AsyncSeriesHook([]),
94
+ dev: new AsyncSeriesHook([]),
95
+ build: new AsyncSeriesHook([]),
96
+ test: new AsyncSeriesHook([]),
97
+ release: new AsyncSeriesHook([]),
98
+ deploy: new AsyncSeriesHook([]),
99
+ lint: new AsyncSeriesHook([]),
100
+ },
101
+ logger: createLogger(args.data),
102
+ command,
103
+ config: {
104
+ all: [],
105
+ // @ts-expect-error
106
+ current: undefined,
107
+ },
108
+ package: {},
109
+ z: zod,
110
+ fs,
111
+ glob: glob.glob,
112
+ get duration() {
113
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
114
+ return `耗时 ${duration} s`;
115
+ },
116
+ tempDir: './node_modules/.rife/',
117
+ clear: () => {
118
+ console.clear();
119
+ process.stdout.write('\x1b[3J');
120
+ console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
121
+ },
122
+ throwError: (message?: string, options?: ErrorOptions) => {
123
+ throw new Error(message, options);
124
+ },
125
+ };
126
+
127
+ return runner;
128
+ }
129
+
130
+ export function defineConfig(all: Config[]) {
131
+ return all;
132
+ }
package/src/sync.ts CHANGED
@@ -1,63 +1,63 @@
1
- async function sync(name: string) {
2
- const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
3
- headers: {
4
- accept: '*/*',
5
- 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
6
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
7
- 'sec-ch-ua-mobile': '?0',
8
- 'sec-ch-ua-platform': '"Windows"',
9
- 'sec-fetch-dest': 'empty',
10
- 'sec-fetch-mode': 'cors',
11
- 'sec-fetch-site': 'same-site',
12
- Referer: 'https://npmmirror.com/',
13
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
14
- },
15
- body: null,
16
- method: 'PUT',
17
- });
18
- const body = await res.json();
19
- if (body.ok === true) {
20
- console.log(`同步 ${name} 成功`);
21
- }
22
- return body;
23
- }
24
-
25
- const list = [
26
- '@rife/config', //
27
- '@rife/cli', //
28
- // '@rife/infra',
29
- // '@rife/logger',
30
- // '@rife/react',
31
- // '@rife/next',
32
- // '@rife/nest',
33
- // '@rife/plugin-deploy',
34
- // '@rife/fast',
35
- ];
36
-
37
- 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
- }
42
-
43
- poll();
44
- }
45
-
46
- main();
47
-
48
- async function get(name: string) {
49
- try {
50
- const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
51
- const data = await res.json();
52
- return `${name} ${data?.['dist-tags']?.['latest']}`;
53
- } catch (e) {
54
- return `${name} error`;
55
- }
56
- }
57
-
58
- async function poll() {
59
- const res = await Promise.all(list.map(get));
60
- console.log(`${res.join('\n')}\n`);
61
-
62
- setTimeout(poll, 1000);
63
- }
1
+ async function sync(name: string) {
2
+ const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
3
+ headers: {
4
+ accept: '*/*',
5
+ 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
6
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
7
+ 'sec-ch-ua-mobile': '?0',
8
+ 'sec-ch-ua-platform': '"Windows"',
9
+ 'sec-fetch-dest': 'empty',
10
+ 'sec-fetch-mode': 'cors',
11
+ 'sec-fetch-site': 'same-site',
12
+ Referer: 'https://npmmirror.com/',
13
+ 'Referrer-Policy': 'strict-origin-when-cross-origin',
14
+ },
15
+ body: null,
16
+ method: 'PUT',
17
+ });
18
+ const body = await res.json();
19
+ if (body.ok === true) {
20
+ console.log(`同步 ${name} 成功`);
21
+ }
22
+ return body;
23
+ }
24
+
25
+ const list = [
26
+ '@rife/config', //
27
+ '@rife/cli', //
28
+ // '@rife/infra',
29
+ // '@rife/logger',
30
+ // '@rife/react',
31
+ // '@rife/next',
32
+ // '@rife/nest',
33
+ // '@rife/plugin-deploy',
34
+ // '@rife/fast',
35
+ ];
36
+
37
+ 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
+ }
42
+
43
+ poll();
44
+ }
45
+
46
+ main();
47
+
48
+ async function get(name: string) {
49
+ try {
50
+ const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
51
+ const data = await res.json();
52
+ return `${name} ${data?.['dist-tags']?.['latest']}`;
53
+ } catch (e) {
54
+ return `${name} error`;
55
+ }
56
+ }
57
+
58
+ async function poll() {
59
+ const res = await Promise.all(list.map(get));
60
+ console.log(`${res.join('\n')}\n`);
61
+
62
+ setTimeout(poll, 1000);
63
+ }
package/src/util.ts CHANGED
@@ -1,9 +1,9 @@
1
- import fs from 'fs-extra';
2
- import * as glob from 'glob';
3
-
4
- export { fs, glob };
5
-
6
- export const getDuration = (perfStart: number) => {
7
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
8
- return `耗时 ${duration} s`;
9
- };
1
+ import fs from 'fs-extra';
2
+ import * as glob from 'glob';
3
+
4
+ export { fs, glob };
5
+
6
+ export const getDuration = (perfStart: number) => {
7
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
8
+ return `耗时 ${duration} s`;
9
+ };
@@ -1,207 +0,0 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- "consola/utils": function(module) {
4
- module.exports = require("consola/utils");
5
- },
6
- typescript: function(module) {
7
- module.exports = require("typescript");
8
- }
9
- };
10
- var __webpack_module_cache__ = {};
11
- function __webpack_require__(moduleId) {
12
- var cachedModule = __webpack_module_cache__[moduleId];
13
- if (void 0 !== cachedModule) return cachedModule.exports;
14
- var module = __webpack_module_cache__[moduleId] = {
15
- exports: {}
16
- };
17
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
18
- return module.exports;
19
- }
20
- (()=>{
21
- __webpack_require__.n = (module)=>{
22
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
23
- __webpack_require__.d(getter, {
24
- a: getter
25
- });
26
- return getter;
27
- };
28
- })();
29
- (()=>{
30
- __webpack_require__.d = (exports1, definition)=>{
31
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
32
- enumerable: true,
33
- get: definition[key]
34
- });
35
- };
36
- })();
37
- (()=>{
38
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
39
- })();
40
- (()=>{
41
- __webpack_require__.r = (exports1)=>{
42
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
43
- value: 'Module'
44
- });
45
- Object.defineProperty(exports1, '__esModule', {
46
- value: true
47
- });
48
- };
49
- })();
50
- var __webpack_exports__ = {};
51
- (()=>{
52
- __webpack_require__.r(__webpack_exports__);
53
- __webpack_require__.d(__webpack_exports__, {
54
- checkAndEmitType: ()=>checkAndEmitType,
55
- compileTs: ()=>compileTs,
56
- formatDiagnostic: ()=>formatDiagnostic
57
- });
58
- const external_path_namespaceObject = require("path");
59
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
60
- var utils_ = __webpack_require__("consola/utils");
61
- const external_swc_cjs_namespaceObject = require("./swc.cjs");
62
- const external_tsc_cjs_namespaceObject = require("./tsc.cjs");
63
- const clear = ()=>{
64
- console.clear();
65
- process.stdout.write('\x1b[3J');
66
- };
67
- async function compileTs(runner, tsxConfig, { dev, build } = {
68
- dev: false,
69
- build: true
70
- }) {
71
- const { logger, fs } = runner;
72
- const log = logger.withTag(compileTs.name);
73
- log.debug('tsxConfig %j', tsxConfig);
74
- if (tsxConfig.clean) {
75
- log.info("\u6E05\u7A7A\u76EE\u5F55 %s", tsxConfig.outDir);
76
- await fs.emptyDir(tsxConfig.outDir);
77
- }
78
- const showProjectName = ()=>{
79
- clear();
80
- console.log(`${utils_.colors.bgBlue(" \u9879\u76EE\u540D\u79F0 ")} ${runner.package.name} \n`);
81
- };
82
- if ('tsc' === tsxConfig.type) {
83
- const diagnostics = [];
84
- let perfStart = performance.now();
85
- (0, external_tsc_cjs_namespaceObject.tsc)({
86
- ...tsxConfig,
87
- watch: dev,
88
- onWatchStatusChanged: (data)=>{
89
- switch(data.status){
90
- case 'startWatch':
91
- diagnostics.length = 0;
92
- perfStart = performance.now();
93
- break;
94
- case 'reCompile':
95
- diagnostics.length = 0;
96
- perfStart = performance.now();
97
- if (dev) showProjectName();
98
- break;
99
- case 'error':
100
- {
101
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
102
- 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));
103
- break;
104
- }
105
- case 'success':
106
- {
107
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
108
- log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
109
- break;
110
- }
111
- default:
112
- console.log(data);
113
- process.exit(1);
114
- }
115
- },
116
- onReportDiagnostic: ({ diagnostic })=>{
117
- diagnostics.push(diagnostic);
118
- },
119
- onEmitDiagnostics: ({ diagnostics })=>{
120
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
121
- if (diagnostics.length) {
122
- log.error(`\u{7F16}\u{8BD1}\u{5931}\u{8D25}\u{FF0C}\u{8017}\u{65F6} ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
123
- runner.compiler.fail = true;
124
- } else log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
125
- }
126
- });
127
- return;
128
- }
129
- if ('swc' === tsxConfig.type) {
130
- const { promise, resolve } = Promise.withResolvers();
131
- (0, external_swc_cjs_namespaceObject.swc)({
132
- ...tsxConfig,
133
- watch: dev,
134
- onSuccess: async ({ watch, first, duration })=>{
135
- if (watch && !first) showProjectName();
136
- log.success(`\u{7F16}\u{8BD1}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${(duration / 1000).toFixed(3)} s`);
137
- if (dev) runner.compiler.hook.execMain.promise();
138
- await runner.compiler.hook.checkAndEmitType.promise();
139
- resolve();
140
- },
141
- onFail: ({ watch, first, duration, reasons })=>{
142
- if (watch && !first) showProjectName();
143
- const message = [
144
- ...reasons.entries()
145
- ].map(([key, value])=>{
146
- const index = value.indexOf(key);
147
- if (index > -1) return value.replace(key, external_path_default().resolve(key));
148
- return `${value}`;
149
- }).join('\n');
150
- 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);
151
- runner.compiler.fail = true;
152
- resolve();
153
- }
154
- });
155
- if (build) return promise;
156
- return;
157
- }
158
- log.error(`compiler type '${tsxConfig.type}' \u{4E0D}\u{5B58}\u{5728}`);
159
- process.exit(1);
160
- }
161
- function checkAndEmitType() {
162
- const perfStart = performance.now();
163
- const ts = __webpack_require__("typescript");
164
- const tsConfigPath = external_path_default().resolve('tsconfig.json');
165
- const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
166
- const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, external_path_default().dirname(tsConfigPath), {
167
- noEmit: true,
168
- incremental: false
169
- });
170
- if (true === compilerOptions.options.declaration) {
171
- compilerOptions.options.noEmit = false;
172
- compilerOptions.options.emitDeclarationOnly = true;
173
- }
174
- const host = ts.createCompilerHost(compilerOptions.options);
175
- const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
176
- const emitResult = program.emit();
177
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
178
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
179
- return {
180
- diagnostics,
181
- duration
182
- };
183
- }
184
- function formatDiagnostic(diagnostics) {
185
- const ts = __webpack_require__("typescript");
186
- const { colors } = __webpack_require__("consola/utils");
187
- return diagnostics.map((diagnostic)=>{
188
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
189
- if (diagnostic.file) {
190
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
191
- return `${colors.gray(diagnostic.file.fileName)} ${colors.yellow(`(${line + 1},${character + 1})`)}: ${colors.white(message)}`;
192
- }
193
- return message;
194
- }).join('\n');
195
- }
196
- })();
197
- exports.checkAndEmitType = __webpack_exports__.checkAndEmitType;
198
- exports.compileTs = __webpack_exports__.compileTs;
199
- exports.formatDiagnostic = __webpack_exports__.formatDiagnostic;
200
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
201
- "checkAndEmitType",
202
- "compileTs",
203
- "formatDiagnostic"
204
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
205
- Object.defineProperty(exports, '__esModule', {
206
- value: true
207
- });