@rife/cli 0.0.6-beta.1 → 0.0.6-beta.3
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/pnpmfile.js +11 -2
- package/dist/sync.js +1 -0
- package/dist/sync.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -15
- package/src/cli.ts +19 -19
- package/src/index.ts +3 -3
- package/src/logger.ts +34 -34
- package/src/plugin/commander.ts +44 -44
- package/src/plugin/compiler/swc.ts +55 -55
- package/src/plugin/compiler/tsc.ts +101 -101
- package/src/plugin/release.ts +32 -32
- package/src/pnpmfile.ts +147 -121
- package/src/runner.ts +88 -88
- package/src/sync.ts +63 -62
- package/src/test/pnpmfile.test.ts +223 -223
- package/dist/compiler.js +0 -82
- package/dist/compiler.js.map +0 -1
- package/dist/plugin/package copy.js +0 -32
- package/dist/plugin/package copy.js.map +0 -1
- package/dist/plugin.js +0 -161
- package/dist/plugin.js.map +0 -1
- package/dist/swc.js +0 -78
- package/dist/swc.js.map +0 -1
- package/dist/tsc.js +0 -94
- package/dist/tsc.js.map +0 -1
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import type { TsxConfig } from './compiler';
|
|
2
|
-
|
|
3
|
-
export interface SwcConfig extends TsxConfig {
|
|
4
|
-
watch?: boolean;
|
|
5
|
-
options?: any;
|
|
6
|
-
onSuccess?: (data: { watch: boolean; first: boolean; duration: number }) => any;
|
|
7
|
-
onFail?: (data: { watch: boolean; first: boolean; duration: number; reasons: Map<string, string> }) => any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function swc(options: SwcConfig) {
|
|
11
|
-
const { watch = false, outDir } = options;
|
|
12
|
-
const { swcDir } = require('@swc/cli');
|
|
13
|
-
|
|
14
|
-
// https://swc.rs/docs/configuration/swcrc
|
|
15
|
-
const swcOptions = {
|
|
16
|
-
jsc: {
|
|
17
|
-
parser: {
|
|
18
|
-
syntax: 'typescript',
|
|
19
|
-
},
|
|
20
|
-
target: 'esnext',
|
|
21
|
-
externalHelpers: true,
|
|
22
|
-
},
|
|
23
|
-
module: {
|
|
24
|
-
type: 'commonjs',
|
|
25
|
-
// type: 'es6',
|
|
26
|
-
ignoreDynamic: true,
|
|
27
|
-
},
|
|
28
|
-
sourceMaps: true,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
let first = true;
|
|
32
|
-
|
|
33
|
-
await swcDir({
|
|
34
|
-
cliOptions: {
|
|
35
|
-
outDir,
|
|
36
|
-
watch,
|
|
37
|
-
filenames: ['./src'],
|
|
38
|
-
extensions: ['.ts', '.tsx'],
|
|
39
|
-
stripLeadingPaths: true,
|
|
40
|
-
},
|
|
41
|
-
swcOptions,
|
|
42
|
-
callbacks: {
|
|
43
|
-
onSuccess: ({ duration }: any) => {
|
|
44
|
-
options?.onSuccess?.({ watch, first, duration });
|
|
45
|
-
first = false;
|
|
46
|
-
},
|
|
47
|
-
onFail: (e: any) => {
|
|
48
|
-
options?.onFail?.({ ...e, watch, first });
|
|
49
|
-
// 不退出,下次修复报错后清空屏幕
|
|
50
|
-
first = false;
|
|
51
|
-
},
|
|
52
|
-
onWatchReady: () => {},
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
1
|
+
import type { TsxConfig } from './compiler';
|
|
2
|
+
|
|
3
|
+
export interface SwcConfig extends TsxConfig {
|
|
4
|
+
watch?: boolean;
|
|
5
|
+
options?: any;
|
|
6
|
+
onSuccess?: (data: { watch: boolean; first: boolean; duration: number }) => any;
|
|
7
|
+
onFail?: (data: { watch: boolean; first: boolean; duration: number; reasons: Map<string, string> }) => any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function swc(options: SwcConfig) {
|
|
11
|
+
const { watch = false, outDir } = options;
|
|
12
|
+
const { swcDir } = require('@swc/cli');
|
|
13
|
+
|
|
14
|
+
// https://swc.rs/docs/configuration/swcrc
|
|
15
|
+
const swcOptions = {
|
|
16
|
+
jsc: {
|
|
17
|
+
parser: {
|
|
18
|
+
syntax: 'typescript',
|
|
19
|
+
},
|
|
20
|
+
target: 'esnext',
|
|
21
|
+
externalHelpers: true,
|
|
22
|
+
},
|
|
23
|
+
module: {
|
|
24
|
+
type: 'commonjs',
|
|
25
|
+
// type: 'es6',
|
|
26
|
+
ignoreDynamic: true,
|
|
27
|
+
},
|
|
28
|
+
sourceMaps: true,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let first = true;
|
|
32
|
+
|
|
33
|
+
await swcDir({
|
|
34
|
+
cliOptions: {
|
|
35
|
+
outDir,
|
|
36
|
+
watch,
|
|
37
|
+
filenames: ['./src'],
|
|
38
|
+
extensions: ['.ts', '.tsx'],
|
|
39
|
+
stripLeadingPaths: true,
|
|
40
|
+
},
|
|
41
|
+
swcOptions,
|
|
42
|
+
callbacks: {
|
|
43
|
+
onSuccess: ({ duration }: any) => {
|
|
44
|
+
options?.onSuccess?.({ watch, first, duration });
|
|
45
|
+
first = false;
|
|
46
|
+
},
|
|
47
|
+
onFail: (e: any) => {
|
|
48
|
+
options?.onFail?.({ ...e, watch, first });
|
|
49
|
+
// 不退出,下次修复报错后清空屏幕
|
|
50
|
+
first = false;
|
|
51
|
+
},
|
|
52
|
+
onWatchReady: () => {},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import type { ChildProcess } from 'child_process';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import type * as ts from 'typescript';
|
|
5
|
-
|
|
6
|
-
import type { TsxConfig } from './compiler';
|
|
7
|
-
|
|
8
|
-
type Status = 'startWatch' | 'reCompile' | 'error' | 'success' | '';
|
|
9
|
-
export interface TscConfig extends TsxConfig {
|
|
10
|
-
watch?: boolean;
|
|
11
|
-
options?: ts.CompilerOptions;
|
|
12
|
-
onWatchStatusChanged?: (data: { status: Status; message: string }) => any;
|
|
13
|
-
onReportDiagnostic?: (data: { diagnostic: ts.Diagnostic }) => any;
|
|
14
|
-
onEmitDiagnostics?: (data: { diagnostics: ts.Diagnostic[] }) => any;
|
|
15
|
-
}
|
|
16
|
-
export function tsc(config: TscConfig) {
|
|
17
|
-
const logger = console;
|
|
18
|
-
const ts: typeof import('typescript') = require('typescript');
|
|
19
|
-
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#writing-an-incremental-program-watcher
|
|
20
|
-
|
|
21
|
-
const rootDir = config.rootDir || '.';
|
|
22
|
-
|
|
23
|
-
const formatHost: ts.FormatDiagnosticsHost = {
|
|
24
|
-
getCanonicalFileName: path => path,
|
|
25
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
26
|
-
getNewLine: () => ts.sys.newLine,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function reportDiagnostic(diagnostic: ts.Diagnostic) {
|
|
30
|
-
config.onReportDiagnostic?.({ diagnostic });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Prints a diagnostic every time the watch status changes.
|
|
35
|
-
* This is mainly for messages like "Starting compilation" or "Compilation completed".
|
|
36
|
-
*/
|
|
37
|
-
let a: ChildProcess | any;
|
|
38
|
-
function reportWatchStatusChanged(diagnostic: ts.Diagnostic) {
|
|
39
|
-
const message = `${ts.formatDiagnostic(diagnostic, formatHost)}`.trimEnd();
|
|
40
|
-
let status: Status = '';
|
|
41
|
-
if (message.includes('message TS6031: Starting compilation in watch mode')) {
|
|
42
|
-
status = 'startWatch';
|
|
43
|
-
} else if (message.includes('message TS6032: File change detected')) {
|
|
44
|
-
status = 'reCompile';
|
|
45
|
-
} else if (message.includes('Found 0 errors')) {
|
|
46
|
-
status = 'success';
|
|
47
|
-
} else if (/Found \d+ error/.test(message)) {
|
|
48
|
-
status = 'error';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
config.onWatchStatusChanged?.({ status, message });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.json');
|
|
55
|
-
if (!configPath) {
|
|
56
|
-
throw new Error('找不到tsconfig.json');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
|
|
60
|
-
|
|
61
|
-
if (config.watch) {
|
|
62
|
-
const host = ts.createWatchCompilerHost(
|
|
63
|
-
configPath,
|
|
64
|
-
{
|
|
65
|
-
...config.options,
|
|
66
|
-
outDir: config.outDir,
|
|
67
|
-
noEmit: false,
|
|
68
|
-
incremental: true,
|
|
69
|
-
},
|
|
70
|
-
ts.sys,
|
|
71
|
-
createProgram,
|
|
72
|
-
reportDiagnostic,
|
|
73
|
-
reportWatchStatusChanged,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
ts.createWatchProgram(host);
|
|
77
|
-
} else {
|
|
78
|
-
// 读取 tsconfig.json 文件
|
|
79
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
80
|
-
|
|
81
|
-
// 解析 tsconfig.json 文件
|
|
82
|
-
const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath), {
|
|
83
|
-
...config.options,
|
|
84
|
-
outDir: config.outDir,
|
|
85
|
-
noEmit: false,
|
|
86
|
-
incremental: false,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// 获取编译器实例
|
|
90
|
-
const host = ts.createCompilerHost(compilerOptions.options);
|
|
91
|
-
const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
|
|
92
|
-
|
|
93
|
-
// 执行编译
|
|
94
|
-
const emitResult = program.emit();
|
|
95
|
-
|
|
96
|
-
// 处理编译结果
|
|
97
|
-
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
98
|
-
|
|
99
|
-
config.onEmitDiagnostics?.({ diagnostics });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
import type { ChildProcess } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import type * as ts from 'typescript';
|
|
5
|
+
|
|
6
|
+
import type { TsxConfig } from './compiler';
|
|
7
|
+
|
|
8
|
+
type Status = 'startWatch' | 'reCompile' | 'error' | 'success' | '';
|
|
9
|
+
export interface TscConfig extends TsxConfig {
|
|
10
|
+
watch?: boolean;
|
|
11
|
+
options?: ts.CompilerOptions;
|
|
12
|
+
onWatchStatusChanged?: (data: { status: Status; message: string }) => any;
|
|
13
|
+
onReportDiagnostic?: (data: { diagnostic: ts.Diagnostic }) => any;
|
|
14
|
+
onEmitDiagnostics?: (data: { diagnostics: ts.Diagnostic[] }) => any;
|
|
15
|
+
}
|
|
16
|
+
export function tsc(config: TscConfig) {
|
|
17
|
+
const logger = console;
|
|
18
|
+
const ts: typeof import('typescript') = require('typescript');
|
|
19
|
+
// https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#writing-an-incremental-program-watcher
|
|
20
|
+
|
|
21
|
+
const rootDir = config.rootDir || '.';
|
|
22
|
+
|
|
23
|
+
const formatHost: ts.FormatDiagnosticsHost = {
|
|
24
|
+
getCanonicalFileName: path => path,
|
|
25
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
26
|
+
getNewLine: () => ts.sys.newLine,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function reportDiagnostic(diagnostic: ts.Diagnostic) {
|
|
30
|
+
config.onReportDiagnostic?.({ diagnostic });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Prints a diagnostic every time the watch status changes.
|
|
35
|
+
* This is mainly for messages like "Starting compilation" or "Compilation completed".
|
|
36
|
+
*/
|
|
37
|
+
let a: ChildProcess | any;
|
|
38
|
+
function reportWatchStatusChanged(diagnostic: ts.Diagnostic) {
|
|
39
|
+
const message = `${ts.formatDiagnostic(diagnostic, formatHost)}`.trimEnd();
|
|
40
|
+
let status: Status = '';
|
|
41
|
+
if (message.includes('message TS6031: Starting compilation in watch mode')) {
|
|
42
|
+
status = 'startWatch';
|
|
43
|
+
} else if (message.includes('message TS6032: File change detected')) {
|
|
44
|
+
status = 'reCompile';
|
|
45
|
+
} else if (message.includes('Found 0 errors')) {
|
|
46
|
+
status = 'success';
|
|
47
|
+
} else if (/Found \d+ error/.test(message)) {
|
|
48
|
+
status = 'error';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
config.onWatchStatusChanged?.({ status, message });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.json');
|
|
55
|
+
if (!configPath) {
|
|
56
|
+
throw new Error('找不到tsconfig.json');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
|
|
60
|
+
|
|
61
|
+
if (config.watch) {
|
|
62
|
+
const host = ts.createWatchCompilerHost(
|
|
63
|
+
configPath,
|
|
64
|
+
{
|
|
65
|
+
...config.options,
|
|
66
|
+
outDir: config.outDir,
|
|
67
|
+
noEmit: false,
|
|
68
|
+
incremental: true,
|
|
69
|
+
},
|
|
70
|
+
ts.sys,
|
|
71
|
+
createProgram,
|
|
72
|
+
reportDiagnostic,
|
|
73
|
+
reportWatchStatusChanged,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
ts.createWatchProgram(host);
|
|
77
|
+
} else {
|
|
78
|
+
// 读取 tsconfig.json 文件
|
|
79
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
80
|
+
|
|
81
|
+
// 解析 tsconfig.json 文件
|
|
82
|
+
const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath), {
|
|
83
|
+
...config.options,
|
|
84
|
+
outDir: config.outDir,
|
|
85
|
+
noEmit: false,
|
|
86
|
+
incremental: false,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 获取编译器实例
|
|
90
|
+
const host = ts.createCompilerHost(compilerOptions.options);
|
|
91
|
+
const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
|
|
92
|
+
|
|
93
|
+
// 执行编译
|
|
94
|
+
const emitResult = program.emit();
|
|
95
|
+
|
|
96
|
+
// 处理编译结果
|
|
97
|
+
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
98
|
+
|
|
99
|
+
config.onEmitDiagnostics?.({ diagnostics });
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/plugin/release.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type { ChildProcess } from 'child_process';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import { AsyncSeriesHook } from 'tapable';
|
|
5
|
-
|
|
6
|
-
import type { Plugin } from '../runner';
|
|
7
|
-
|
|
8
|
-
export function pluginRelease() {
|
|
9
|
-
const plugin: Plugin = {
|
|
10
|
-
name: pluginRelease.name,
|
|
11
|
-
apply: runner => {
|
|
12
|
-
const { logger, hook, fs } = runner;
|
|
13
|
-
const log = logger.withTag(pluginRelease.name);
|
|
14
|
-
hook.loadPackage.tapPromise(pluginRelease.name, async () => {
|
|
15
|
-
const fileName = 'package.json';
|
|
16
|
-
const filePath = path.resolve(fileName);
|
|
17
|
-
if (!fs.existsSync(filePath)) {
|
|
18
|
-
log.error(`找不到文件 ${fileName}`);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const data = require(filePath);
|
|
23
|
-
runner.package = data;
|
|
24
|
-
} catch (e) {
|
|
25
|
-
log.error(`读取文件失败`, e.message);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
return plugin;
|
|
32
|
-
}
|
|
1
|
+
import type { ChildProcess } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { AsyncSeriesHook } from 'tapable';
|
|
5
|
+
|
|
6
|
+
import type { Plugin } from '../runner';
|
|
7
|
+
|
|
8
|
+
export function pluginRelease() {
|
|
9
|
+
const plugin: Plugin = {
|
|
10
|
+
name: pluginRelease.name,
|
|
11
|
+
apply: runner => {
|
|
12
|
+
const { logger, hook, fs } = runner;
|
|
13
|
+
const log = logger.withTag(pluginRelease.name);
|
|
14
|
+
hook.loadPackage.tapPromise(pluginRelease.name, async () => {
|
|
15
|
+
const fileName = 'package.json';
|
|
16
|
+
const filePath = path.resolve(fileName);
|
|
17
|
+
if (!fs.existsSync(filePath)) {
|
|
18
|
+
log.error(`找不到文件 ${fileName}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const data = require(filePath);
|
|
23
|
+
runner.package = data;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
log.error(`读取文件失败`, e.message);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
return plugin;
|
|
32
|
+
}
|
package/src/pnpmfile.ts
CHANGED
|
@@ -1,121 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
const h = require('https');
|
|
5
|
+
|
|
6
|
+
const request = h.request;
|
|
7
|
+
h.request = function (...args: any[]) {
|
|
8
|
+
const path = args[0].path || '';
|
|
9
|
+
if (path.startsWith('/@rife') && !path.endsWith('.tgz')) {
|
|
10
|
+
console.log(path);
|
|
11
|
+
args[0].headers['accept'] = 'application/json';
|
|
12
|
+
}
|
|
13
|
+
return request(...args);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let root: any;
|
|
17
|
+
let exit: (message: string) => any;
|
|
18
|
+
const origin: any = {};
|
|
19
|
+
|
|
20
|
+
export function parseVersion(version: string) {
|
|
21
|
+
const [_, a = '', b = '', c = '', d = ''] = /(\d+?)\.(\d+?)\.(\d+?)\D*(\d+)?/.exec(version) || [];
|
|
22
|
+
if (!a || !b || !c) {
|
|
23
|
+
exit(`version ${version}`);
|
|
24
|
+
}
|
|
25
|
+
return [a, b, c, d].map(t => t.padStart(3, '0')).join('.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function compareVersion(v1: string, v2: string) {
|
|
29
|
+
const v = [v1, v2].filter(t => Boolean(t));
|
|
30
|
+
if (v.length === 0) {
|
|
31
|
+
exit('version empty');
|
|
32
|
+
}
|
|
33
|
+
if (v.length === 1) {
|
|
34
|
+
return v[0];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return parseVersion(v1) > parseVersion(v2) ? v1 : v2;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const host: any = {};
|
|
41
|
+
function updateRoot(type: 'dependencies' | 'devDependencies', name: string, version: string, from: string) {
|
|
42
|
+
if (origin[type][name]) return;
|
|
43
|
+
if (!host[type]) {
|
|
44
|
+
host[type] = {};
|
|
45
|
+
}
|
|
46
|
+
const dependencies = host[type];
|
|
47
|
+
dependencies[name] = {
|
|
48
|
+
version: compareVersion(version, dependencies[name]?.version),
|
|
49
|
+
from,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const readPackage = (pkg: any, context: any) => {
|
|
54
|
+
if (!exit) {
|
|
55
|
+
exit = (message: string) => {
|
|
56
|
+
context.log(message);
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
process.exit(1);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!root) {
|
|
62
|
+
root = pkg;
|
|
63
|
+
origin.dependencies = { ...root.dependencies };
|
|
64
|
+
origin.devDependencies = { ...root.devDependencies };
|
|
65
|
+
}
|
|
66
|
+
const dependencies = pkg.dependencies || {};
|
|
67
|
+
const devDependencies = pkg.devDependencies || {};
|
|
68
|
+
const { hostDependencies = {} } = pkg.rife || {};
|
|
69
|
+
const from = {
|
|
70
|
+
name: pkg.name,
|
|
71
|
+
version: pkg.version,
|
|
72
|
+
};
|
|
73
|
+
Object.keys(hostDependencies).forEach(name => {
|
|
74
|
+
const version = dependencies[name] || devDependencies[name];
|
|
75
|
+
if (!version) {
|
|
76
|
+
exit('cannot not found version');
|
|
77
|
+
}
|
|
78
|
+
const isDev = Boolean(devDependencies[name]);
|
|
79
|
+
if (isDev) {
|
|
80
|
+
dependencies[name] = version;
|
|
81
|
+
updateRoot('devDependencies', name, version, from);
|
|
82
|
+
} else {
|
|
83
|
+
updateRoot('dependencies', name, version, from);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return pkg;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const deps = ['devDependencies', 'dependencies'];
|
|
90
|
+
const need: any[] = [];
|
|
91
|
+
|
|
92
|
+
let aaaa = [];
|
|
93
|
+
|
|
94
|
+
export const afterAllResolved = (lockfile, context) => {
|
|
95
|
+
fs.writeFileSync('./temp/1.json', JSON.stringify(host, undefined, 4));
|
|
96
|
+
debugger;
|
|
97
|
+
|
|
98
|
+
deps.map(dep => {
|
|
99
|
+
Object.entries(host[dep as any]).forEach(([name, data]: any) => {
|
|
100
|
+
need.push({
|
|
101
|
+
key: `${name}@${data.version}`,
|
|
102
|
+
name,
|
|
103
|
+
dep,
|
|
104
|
+
version: data.version,
|
|
105
|
+
from: data.from,
|
|
106
|
+
source: `${data.from.name}@${data.from.version}`,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// debugger;
|
|
112
|
+
const current = lockfile.importers['.'];
|
|
113
|
+
const { packages } = lockfile;
|
|
114
|
+
|
|
115
|
+
const list = Object.keys(packages).map(key => {
|
|
116
|
+
const pack = {
|
|
117
|
+
key,
|
|
118
|
+
value: packages[key],
|
|
119
|
+
};
|
|
120
|
+
return pack;
|
|
121
|
+
});
|
|
122
|
+
const t = Object.keys(packages).filter(t => t.startsWith('@rife/cli'));
|
|
123
|
+
aaaa = need.map(n => {
|
|
124
|
+
const f = list.find(t => t.key.startsWith(n.key));
|
|
125
|
+
if (f) {
|
|
126
|
+
return f;
|
|
127
|
+
}
|
|
128
|
+
const s = list.find(t2 => t2.key.startsWith(n.source));
|
|
129
|
+
const v = s?.value?.dependencies[n.name];
|
|
130
|
+
if (v) {
|
|
131
|
+
const newKey = `${n.name}@${v}`;
|
|
132
|
+
const ff = list.find(t => t.key.startsWith(newKey));
|
|
133
|
+
if (ff) {
|
|
134
|
+
return ff;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
debugger;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
debugger;
|
|
141
|
+
return lockfile;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
process.on('exit', () => {
|
|
145
|
+
// const exits = aaaa.map(a => fs.exitsSync(`./node_modules/.pnpm/${a.replace('/', '_')}`));
|
|
146
|
+
// debugger;
|
|
147
|
+
});
|