@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
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- child_process: function(module) {
4
- module.exports = require("child_process");
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__.d = (exports1, definition)=>{
19
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
20
- enumerable: true,
21
- get: definition[key]
22
- });
23
- };
24
- })();
25
- (()=>{
26
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
27
- })();
28
- (()=>{
29
- __webpack_require__.r = (exports1)=>{
30
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
31
- value: 'Module'
32
- });
33
- Object.defineProperty(exports1, '__esModule', {
34
- value: true
35
- });
36
- };
37
- })();
38
- var __webpack_exports__ = {};
39
- (()=>{
40
- __webpack_require__.r(__webpack_exports__);
41
- __webpack_require__.d(__webpack_exports__, {
42
- pluginCompiler: ()=>pluginCompiler
43
- });
44
- const external_tapable_namespaceObject = require("tapable");
45
- const external_compiler_cjs_namespaceObject = require("./compiler.cjs");
46
- const external_util_cjs_namespaceObject = require("../../util.cjs");
47
- function pluginCompiler(options) {
48
- const plugin = {
49
- name: pluginCompiler.name,
50
- apply: (runner)=>{
51
- const { hook, logger, z, fs } = runner;
52
- const log = logger.withTag(pluginCompiler.name);
53
- const validation = z.object({
54
- tsx: z.object({
55
- type: z.enum([
56
- 'tsc',
57
- 'swc'
58
- ]).default('swc'),
59
- rootDir: z.string().trim().min(1).default('.'),
60
- outDir: z.string().trim().min(1).default('./dist/'),
61
- clean: z.boolean().default(true),
62
- main: z.string().trim().optional(),
63
- options: z.object({}).passthrough().optional()
64
- }).default({})
65
- }).optional().default({}).safeParse(options);
66
- if (!validation.success) {
67
- log.error("\u914D\u7F6E\u9519\u8BEF\n", validation.error.message);
68
- process.exit(1);
69
- }
70
- runner.compiler = {
71
- fail: false,
72
- process: null,
73
- hook: {
74
- checkAndEmitType: new external_tapable_namespaceObject.AsyncSeriesHook(),
75
- execMain: new external_tapable_namespaceObject.AsyncSeriesHook()
76
- },
77
- tsx: validation.data.tsx
78
- };
79
- hook.dev.tapPromise(pluginCompiler.name, async ()=>{
80
- const tsxConfig = validation.data.tsx;
81
- (0, external_compiler_cjs_namespaceObject.compileTs)(runner, tsxConfig, {
82
- dev: true
83
- });
84
- });
85
- hook.build.tapPromise(pluginCompiler.name, async ()=>{
86
- const perfStart = performance.now();
87
- const tsxConfig = validation.data.tsx;
88
- await (0, external_compiler_cjs_namespaceObject.compileTs)(runner, tsxConfig, {
89
- build: true
90
- });
91
- if (runner.compiler.fail) {
92
- log.fail(`\u{6784}\u{5EFA}\u{5931}\u{8D25}\u{FF0C}${(0, external_util_cjs_namespaceObject.getDuration)(perfStart)}`);
93
- process.exit(1);
94
- } else log.success(`\u{6784}\u{5EFA}\u{6210}\u{529F}\u{FF0C}${(0, external_util_cjs_namespaceObject.getDuration)(perfStart)}`);
95
- });
96
- runner.compiler.hook.checkAndEmitType.tapPromise(pluginCompiler.name, async ()=>{
97
- const { diagnostics, duration } = (0, external_compiler_cjs_namespaceObject.checkAndEmitType)();
98
- if (diagnostics.length) {
99
- 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`, (0, external_compiler_cjs_namespaceObject.formatDiagnostic)(diagnostics));
100
- runner.compiler.fail = true;
101
- } else log.success(`\u{7C7B}\u{578B}\u{68C0}\u{67E5}\u{6210}\u{529F}\u{FF0C}\u{8017}\u{65F6} ${duration} s`);
102
- });
103
- runner.compiler.hook.execMain.tapPromise(pluginCompiler.name, async ()=>{
104
- const compiler = runner.compiler;
105
- const { main } = compiler.tsx;
106
- if (!main) return void log.debug("\u6CA1\u6709\u6307\u5B9A main");
107
- 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);
108
- log.info(`\u{542F}\u{52A8}\u{6587}\u{4EF6} node %s`, main);
109
- const { fork } = __webpack_require__("child_process");
110
- compiler.process?.kill();
111
- compiler.process = fork(main, {
112
- stdio: 'inherit'
113
- });
114
- });
115
- }
116
- };
117
- return plugin;
118
- }
119
- })();
120
- exports.pluginCompiler = __webpack_exports__.pluginCompiler;
121
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
122
- "pluginCompiler"
123
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
124
- Object.defineProperty(exports, '__esModule', {
125
- value: true
126
- });
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- "@swc/cli": function(module) {
4
- module.exports = require("@swc/cli");
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__.d = (exports1, definition)=>{
19
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
20
- enumerable: true,
21
- get: definition[key]
22
- });
23
- };
24
- })();
25
- (()=>{
26
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
27
- })();
28
- (()=>{
29
- __webpack_require__.r = (exports1)=>{
30
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
31
- value: 'Module'
32
- });
33
- Object.defineProperty(exports1, '__esModule', {
34
- value: true
35
- });
36
- };
37
- })();
38
- var __webpack_exports__ = {};
39
- (()=>{
40
- __webpack_require__.r(__webpack_exports__);
41
- __webpack_require__.d(__webpack_exports__, {
42
- swc: ()=>swc
43
- });
44
- async function swc(options) {
45
- const { watch = false, outDir } = options;
46
- const { swcDir } = __webpack_require__("@swc/cli");
47
- const swcOptions = {
48
- jsc: {
49
- parser: {
50
- syntax: "typescript"
51
- },
52
- target: 'esnext',
53
- externalHelpers: true
54
- },
55
- module: {
56
- type: 'commonjs',
57
- ignoreDynamic: true
58
- },
59
- sourceMaps: true
60
- };
61
- let first = true;
62
- await swcDir({
63
- cliOptions: {
64
- outDir,
65
- watch,
66
- filenames: [
67
- './src'
68
- ],
69
- extensions: [
70
- '.ts',
71
- '.tsx',
72
- '.js',
73
- '.jsx'
74
- ],
75
- stripLeadingPaths: true,
76
- copyFiles: true
77
- },
78
- swcOptions,
79
- callbacks: {
80
- onSuccess: ({ duration })=>{
81
- options?.onSuccess?.({
82
- watch,
83
- first,
84
- duration
85
- });
86
- first = false;
87
- },
88
- onFail: (e)=>{
89
- options?.onFail?.({
90
- ...e,
91
- watch,
92
- first
93
- });
94
- first = false;
95
- },
96
- onWatchReady: ()=>{}
97
- }
98
- });
99
- }
100
- })();
101
- exports.swc = __webpack_exports__.swc;
102
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
103
- "swc"
104
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
105
- Object.defineProperty(exports, '__esModule', {
106
- value: true
107
- });
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- typescript: function(module) {
4
- module.exports = require("typescript");
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
- tsc: ()=>tsc
52
- });
53
- const external_path_namespaceObject = require("path");
54
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
55
- function tsc(config) {
56
- const ts = __webpack_require__("typescript");
57
- const rootDir = config.rootDir || '.';
58
- const formatHost = {
59
- getCanonicalFileName: (path)=>path,
60
- getCurrentDirectory: ts.sys.getCurrentDirectory,
61
- getNewLine: ()=>ts.sys.newLine
62
- };
63
- function reportDiagnostic(diagnostic) {
64
- config.onReportDiagnostic?.({
65
- diagnostic
66
- });
67
- }
68
- function reportWatchStatusChanged(diagnostic) {
69
- const message = `${ts.formatDiagnostic(diagnostic, formatHost)}`.trimEnd();
70
- let status = '';
71
- if (message.includes('message TS6031: Starting compilation in watch mode')) status = 'startWatch';
72
- else if (message.includes('message TS6032: File change detected')) status = 'reCompile';
73
- else if (message.includes('Found 0 errors')) status = 'success';
74
- else if (/Found \d+ error/.test(message)) status = 'error';
75
- config.onWatchStatusChanged?.({
76
- status,
77
- message
78
- });
79
- }
80
- const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.json');
81
- if (!configPath) throw new Error("\u627E\u4E0D\u5230tsconfig.json");
82
- const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
83
- if (config.watch) {
84
- const host = ts.createWatchCompilerHost(configPath, {
85
- ...config.options,
86
- outDir: config.outDir,
87
- noEmit: false,
88
- incremental: true
89
- }, ts.sys, createProgram, reportDiagnostic, reportWatchStatusChanged);
90
- ts.createWatchProgram(host);
91
- } else {
92
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
93
- const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, external_path_default().dirname(configPath), {
94
- ...config.options,
95
- outDir: config.outDir,
96
- noEmit: false,
97
- incremental: false
98
- });
99
- const host = ts.createCompilerHost(compilerOptions.options);
100
- const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
101
- const emitResult = program.emit();
102
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
103
- config.onEmitDiagnostics?.({
104
- diagnostics
105
- });
106
- }
107
- }
108
- })();
109
- exports.tsc = __webpack_exports__.tsc;
110
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
111
- "tsc"
112
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
113
- Object.defineProperty(exports, '__esModule', {
114
- value: true
115
- });
@@ -1,160 +0,0 @@
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 };
@@ -1,94 +0,0 @@
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 };
@@ -1,75 +0,0 @@
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 };