@rife/cli 0.0.6-beta.11 → 0.0.6-beta.13
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/cli.cjs +25 -0
- package/dist/cjs/index.cjs +78 -0
- package/dist/cjs/logger.cjs +46 -0
- package/dist/cjs/plugin/commander.cjs +66 -0
- package/dist/cjs/plugin/compiler/compiler.cjs +207 -0
- package/dist/cjs/plugin/compiler/index.cjs +126 -0
- package/dist/cjs/plugin/compiler/swc.cjs +107 -0
- package/dist/cjs/plugin/compiler/tsc.cjs +115 -0
- package/dist/cjs/plugin/config.cjs +107 -0
- package/dist/cjs/plugin/index.cjs +96 -0
- package/dist/cjs/plugin/package.cjs +71 -0
- package/dist/cjs/plugin/release.cjs +129 -0
- package/dist/cjs/runner.cjs +137 -0
- package/dist/{sync.js → cjs/sync.cjs} +12 -23
- package/dist/cjs/util.cjs +57 -0
- package/dist/{1.mjs → esm/cli.mjs} +4 -3
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/logger.mjs +14 -0
- package/dist/esm/plugin/commander.mjs +34 -0
- package/dist/esm/plugin/compiler/compiler.mjs +160 -0
- package/dist/esm/plugin/compiler/index.mjs +94 -0
- package/dist/esm/plugin/compiler/swc.mjs +75 -0
- package/dist/esm/plugin/compiler/tsc.mjs +73 -0
- package/dist/esm/plugin/config.mjs +65 -0
- package/dist/esm/plugin/index.mjs +7 -0
- package/dist/{plugin/package.js → esm/plugin/package.mjs} +11 -14
- package/dist/{plugin/release.js → esm/plugin/release.mjs} +33 -38
- package/dist/esm/runner.mjs +92 -0
- package/dist/esm/sync.mjs +46 -0
- package/dist/esm/util.mjs +9 -0
- package/package.json +12 -6
- package/src/index.ts +0 -6
- package/dist/1.js +0 -24
- package/dist/cjs/1.js +0 -24
- package/dist/cli.js +0 -22
- package/dist/cli.js.map +0 -1
- package/dist/esm/1.mjs +0 -20
- package/dist/index.js +0 -11
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -18
- package/dist/logger.js.map +0 -1
- package/dist/plugin/commander.js +0 -47
- package/dist/plugin/commander.js.map +0 -1
- package/dist/plugin/compiler/compiler.js +0 -166
- package/dist/plugin/compiler/compiler.js.map +0 -1
- package/dist/plugin/compiler/index.js +0 -88
- package/dist/plugin/compiler/index.js.map +0 -1
- package/dist/plugin/compiler/swc.js +0 -48
- package/dist/plugin/compiler/swc.js.map +0 -1
- package/dist/plugin/compiler/swc2.js +0 -65
- package/dist/plugin/compiler/swc2.js.map +0 -1
- package/dist/plugin/compiler/tsc.js +0 -75
- package/dist/plugin/compiler/tsc.js.map +0 -1
- package/dist/plugin/config.js +0 -77
- package/dist/plugin/config.js.map +0 -1
- package/dist/plugin/index.js +0 -9
- package/dist/plugin/index.js.map +0 -1
- package/dist/plugin/package copy.js +0 -32
- package/dist/plugin/package copy.js.map +0 -1
- package/dist/plugin/package.js.map +0 -1
- package/dist/plugin/release.js.map +0 -1
- package/dist/runner.js +0 -81
- package/dist/runner.js.map +0 -1
- package/dist/sync.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/util.js +0 -14
- package/dist/util.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
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,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 };
|
|
@@ -0,0 +1,73 @@
|
|
|
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 };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import __rslib_shim_module__ from 'module';
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
+
import external_path_default from "path";
|
|
4
|
+
function pluginConfig() {
|
|
5
|
+
const plugin = {
|
|
6
|
+
name: pluginConfig.name,
|
|
7
|
+
apply: (runner)=>{
|
|
8
|
+
const { logger, hook, config, command, fs, z } = runner;
|
|
9
|
+
const log = logger.withTag(pluginConfig.name);
|
|
10
|
+
hook.loadConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
11
|
+
let filePath = '';
|
|
12
|
+
const mjs = 'app.mjs';
|
|
13
|
+
const fileNames = [
|
|
14
|
+
'app.js',
|
|
15
|
+
'app.cjs',
|
|
16
|
+
mjs
|
|
17
|
+
];
|
|
18
|
+
let isEsm = false;
|
|
19
|
+
for (const fileName of fileNames)if (await fs.exists(fileName)) {
|
|
20
|
+
filePath = external_path_default.posix.resolve(fileName);
|
|
21
|
+
isEsm = fileName === mjs;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
log.debug("filePath %s", filePath);
|
|
25
|
+
if (!filePath) {
|
|
26
|
+
log.error(`\u{627E}\u{4E0D}\u{5230}\u{914D}\u{7F6E}\u{6587}\u{4EF6} app.(c|m)?js`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
let all = [];
|
|
30
|
+
all = isEsm ? (await import(filePath)).default : require(filePath);
|
|
31
|
+
runner.config.all = all;
|
|
32
|
+
});
|
|
33
|
+
hook.validateConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
34
|
+
const validation = z.array(z.object({
|
|
35
|
+
name: z.string().trim().min(1)
|
|
36
|
+
})).min(1).safeParse(config.all);
|
|
37
|
+
if (!validation.success) {
|
|
38
|
+
log.error(validation.error.message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
hook.applyConfig.tapPromise(pluginConfig.name, async ()=>{
|
|
43
|
+
const result = z.object({
|
|
44
|
+
name: z.string().trim().default('')
|
|
45
|
+
}).default({}).safeParse(command.opts());
|
|
46
|
+
const name = result.data?.name;
|
|
47
|
+
if (name) {
|
|
48
|
+
log.debug(`\u{6307}\u{5B9A} --name ${name}`);
|
|
49
|
+
const find = config.all.find((t)=>t.name === name);
|
|
50
|
+
if (!find) {
|
|
51
|
+
log.error(`\u{672A}\u{627E}\u{5230} name '%s'`, name);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
config.current = find;
|
|
55
|
+
} else {
|
|
56
|
+
log.debug("\u6CA1\u6709\u6307\u5B9A --name\uFF0C\u9ED8\u8BA4\u4F7F\u7528\u5217\u8868\u7B2C\u4E00\u4E2A");
|
|
57
|
+
config.current = config.all[0];
|
|
58
|
+
}
|
|
59
|
+
config.current.plugins.forEach((plugin)=>plugin.apply(runner));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return plugin;
|
|
64
|
+
}
|
|
65
|
+
export { pluginConfig };
|