@rife/cli 0.0.6-beta.13 → 0.0.6-beta.15
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/dist/cjs/logger.cjs +2 -0
- package/dist/cjs/plugin/index.cjs +3 -12
- package/dist/cjs/runner.cjs +4 -1
- package/dist/esm/cli.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/logger.mjs +3 -1
- package/dist/esm/plugin/commander.mjs +1 -1
- package/dist/esm/plugin/config.mjs +2 -2
- package/dist/esm/plugin/index.mjs +1 -2
- package/dist/esm/plugin/package.mjs +2 -2
- package/dist/esm/plugin/release.mjs +1 -1
- package/dist/esm/runner.mjs +9 -6
- package/dist/esm/sync.mjs +1 -1
- package/dist/esm/util.mjs +3 -3
- package/package.json +7 -17
- package/src/index.ts +0 -6
- package/src/logger.ts +2 -1
- package/src/plugin/index.ts +0 -1
- package/src/runner.ts +5 -1
- package/dist/cjs/plugin/compiler/compiler.cjs +0 -207
- package/dist/cjs/plugin/compiler/index.cjs +0 -126
- package/dist/cjs/plugin/compiler/swc.cjs +0 -107
- package/dist/cjs/plugin/compiler/tsc.cjs +0 -115
- package/dist/esm/plugin/compiler/compiler.mjs +0 -160
- package/dist/esm/plugin/compiler/index.mjs +0 -94
- package/dist/esm/plugin/compiler/swc.mjs +0 -75
- package/dist/esm/plugin/compiler/tsc.mjs +0 -73
- package/src/plugin/compiler/compiler.ts +0 -198
- package/src/plugin/compiler/index.ts +0 -115
- package/src/plugin/compiler/swc.ts +0 -56
- package/src/plugin/compiler/tsc.ts +0 -101
|
@@ -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 };
|
|
@@ -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 };
|