@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,73 +0,0 @@
1
- import __rslib_shim_module__ from 'module';
2
- /*#__PURE__*/ import.meta.url;
3
- import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript";
4
- import external_path_default from "path";
5
- var __webpack_modules__ = {
6
- typescript: function(module) {
7
- module.exports = __WEBPACK_EXTERNAL_MODULE_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
- function tsc(config) {
21
- const ts = __webpack_require__("typescript");
22
- const rootDir = config.rootDir || '.';
23
- const formatHost = {
24
- getCanonicalFileName: (path)=>path,
25
- getCurrentDirectory: ts.sys.getCurrentDirectory,
26
- getNewLine: ()=>ts.sys.newLine
27
- };
28
- function reportDiagnostic(diagnostic) {
29
- config.onReportDiagnostic?.({
30
- diagnostic
31
- });
32
- }
33
- function reportWatchStatusChanged(diagnostic) {
34
- const message = `${ts.formatDiagnostic(diagnostic, formatHost)}`.trimEnd();
35
- let status = '';
36
- if (message.includes('message TS6031: Starting compilation in watch mode')) status = 'startWatch';
37
- else if (message.includes('message TS6032: File change detected')) status = 'reCompile';
38
- else if (message.includes('Found 0 errors')) status = 'success';
39
- else if (/Found \d+ error/.test(message)) status = 'error';
40
- config.onWatchStatusChanged?.({
41
- status,
42
- message
43
- });
44
- }
45
- const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.json');
46
- if (!configPath) throw new Error("\u627E\u4E0D\u5230tsconfig.json");
47
- const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
48
- if (config.watch) {
49
- const host = ts.createWatchCompilerHost(configPath, {
50
- ...config.options,
51
- outDir: config.outDir,
52
- noEmit: false,
53
- incremental: true
54
- }, ts.sys, createProgram, reportDiagnostic, reportWatchStatusChanged);
55
- ts.createWatchProgram(host);
56
- } else {
57
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
58
- const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, external_path_default.dirname(configPath), {
59
- ...config.options,
60
- outDir: config.outDir,
61
- noEmit: false,
62
- incremental: false
63
- });
64
- const host = ts.createCompilerHost(compilerOptions.options);
65
- const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
66
- const emitResult = program.emit();
67
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
68
- config.onEmitDiagnostics?.({
69
- diagnostics
70
- });
71
- }
72
- }
73
- export { tsc };
@@ -1,115 +0,0 @@
1
- import type { ChildProcess } from 'child_process';
2
-
3
- import { AsyncSeriesHook } from 'tapable';
4
-
5
- import { TsxConfig, checkAndEmitType, compileTs, formatDiagnostic } from './compiler';
6
- import type { Plugin } from '../../runner';
7
- import { getDuration } from '../../util';
8
-
9
- declare module '../../runner' {
10
- interface Runner {
11
- compiler: {
12
- fail: boolean;
13
- process: ChildProcess | null;
14
- hook: {
15
- checkAndEmitType: AsyncSeriesHook<[]>;
16
- execMain: AsyncSeriesHook<[]>;
17
- };
18
- tsx: TsxConfig;
19
- };
20
- }
21
- }
22
-
23
- export interface pluginCompilerOptions {
24
- tsx?: Partial<TsxConfig>;
25
- less?: {};
26
- }
27
-
28
- export function pluginCompiler(options?: pluginCompilerOptions) {
29
- const plugin: Plugin = {
30
- name: pluginCompiler.name,
31
- apply: runner => {
32
- const { hook, logger, z, fs } = runner;
33
- const log = logger.withTag(pluginCompiler.name);
34
- const validation = z
35
- .object({
36
- tsx: z
37
- .object({
38
- type: z.enum(['tsc', 'swc']).default('swc'),
39
- rootDir: z.string().trim().min(1).default('.'),
40
- outDir: z.string().trim().min(1).default('./dist/'),
41
- clean: z.boolean().default(true),
42
- main: z.string().trim().optional(),
43
- options: z.object({}).passthrough().optional(),
44
- })
45
- .default({}),
46
- })
47
- .optional()
48
- .default({})
49
- .safeParse(options);
50
-
51
- if (!validation.success) {
52
- log.error('配置错误\n', validation.error.message);
53
- process.exit(1);
54
- }
55
-
56
- runner.compiler = {
57
- fail: false,
58
- process: null,
59
- hook: {
60
- checkAndEmitType: new AsyncSeriesHook(),
61
- execMain: new AsyncSeriesHook(),
62
- },
63
- tsx: validation.data.tsx,
64
- };
65
-
66
- hook.dev.tapPromise(pluginCompiler.name, async () => {
67
- const tsxConfig: TsxConfig = validation.data.tsx;
68
- compileTs(runner, tsxConfig, { dev: true });
69
- });
70
-
71
- hook.build.tapPromise(pluginCompiler.name, async () => {
72
- const perfStart = performance.now();
73
- const tsxConfig: TsxConfig = validation.data.tsx;
74
- await compileTs(runner, tsxConfig, { build: true });
75
- if (runner.compiler.fail) {
76
- log.fail(`构建失败,${getDuration(perfStart)}`);
77
- process.exit(1);
78
- } else {
79
- log.success(`构建成功,${getDuration(perfStart)}`);
80
- }
81
- });
82
-
83
- runner.compiler.hook.checkAndEmitType.tapPromise(pluginCompiler.name, async () => {
84
- const { diagnostics, duration } = checkAndEmitType();
85
- if (diagnostics.length) {
86
- log.error(`类型检查失败,耗时 ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
87
- runner.compiler.fail = true;
88
- } else {
89
- log.success(`类型检查成功,耗时 ${duration} s`);
90
- }
91
- });
92
-
93
- runner.compiler.hook.execMain.tapPromise(pluginCompiler.name, async () => {
94
- const compiler = runner.compiler;
95
- const { main } = compiler.tsx;
96
- if (!main) {
97
- log.debug('没有指定 main');
98
- return;
99
- }
100
-
101
- if (!(await fs.exists(main))) {
102
- log.warn(`启动文件不存在 %s`, main);
103
- return;
104
- }
105
-
106
- log.info(`启动文件 node %s`, main);
107
-
108
- const { fork } = require('child_process') as typeof import('child_process');
109
- compiler.process?.kill();
110
- compiler.process = fork(main, { stdio: 'inherit' });
111
- });
112
- },
113
- };
114
- return plugin;
115
- }