@infly/libs 2.0.43 → 2.0.44
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/README.md +92 -67
- package/adapters/vue2/build/webpack5/inline-runtime-plugin.js +35 -0
- package/adapters/vue2/build/webpack5/remove-legacy-assets-plugin.js +84 -0
- package/adapters/vue2/build/webpack5/webpack.base.js +437 -0
- package/adapters/vue2/module/Permission.js +204 -0
- package/adapters/vue2/postinstall.js +46 -0
- package/adapters/vue2/project-preview.js +148 -0
- package/adapters/vue2/script-config.js +26 -0
- package/adapters/vue2/store/index.js +1 -0
- package/adapters/vue2/store/modules/user.js +268 -0
- package/bin/cli.js +71 -71
- package/build/build-dist/index.js +863 -863
- package/build/build-dist/script-management.js +5 -5
- package/build/docker/compose-command.js +74 -74
- package/build/docker/compose-release.js +91 -91
- package/build/webpack5/inline-runtime-plugin.js +1 -35
- package/build/webpack5/remove-legacy-assets-plugin.js +1 -84
- package/build/webpack5/webpack.base.js +1 -435
- package/compat/init.js +9 -0
- package/index.js +8 -20
- package/module/Permission.js +1 -204
- package/module/REST.js +31 -19
- package/module/TokenService.js +9 -0
- package/module/Uts.js +460 -7252
- package/module/cjs/request-url-rules.cjs +6 -0
- package/module/cjs/rest-error-rules.cjs +33 -0
- package/package.json +121 -92
- package/script/build/deps.js +1 -1
- package/script/build/webhook.js +3 -2
- package/script/git-automation/git-clone.js +3 -4
- package/script/git-automation/index.js +2 -2
- package/script/index.js +1 -26
- package/script/webhook/webhook.js +7 -2
- package/store/index.js +1 -0
- package/store/modules/user.js +1 -268
- package/tools/auto-export.js +1 -2
- package/tools/file-export.js +6 -4
- package/tools/project-command.js +194 -194
- package/tools/project-preview.js +1 -148
- package/tools/select-option.js +60 -60
- package/.prettierrc +0 -5
- package/build/build-dist/script-management.test.js +0 -16
- package/build/docker/compose-command.test.js +0 -148
- package/build/docker/compose-release.test.js +0 -101
- package/build/docker/docker-build-push.test.js +0 -124
- package/build/webpack5/webpack.base.test.js +0 -59
- package/lib/index.js +0 -6
- package/lib/server/connect.js +0 -3011
- package/lib/server/serve-static.js +0 -4848
- package/script/pts/cloud-scenes.mjs +0 -65
- package/script/pts/cloud.js +0 -151
- package/script/pts/generate-cloud-params.mjs +0 -210
- package/script/pts/generate-cloud-params.test.mjs +0 -67
- package/tools/project-command.test.js +0 -267
- package/tools/select-option.test.js +0 -52
- package/webpack.config.js +0 -38
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
const assert = require("node:assert/strict");
|
|
2
|
-
const fs = require("node:fs");
|
|
3
|
-
const os = require("node:os");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const test = require("node:test");
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
loadConfig,
|
|
9
|
-
resolveBuildPlatforms,
|
|
10
|
-
runProjectCommand,
|
|
11
|
-
} = require("./project-command");
|
|
12
|
-
const { EXIT_SELECTION } = require("./select-option");
|
|
13
|
-
|
|
14
|
-
const config = {
|
|
15
|
-
targets: {
|
|
16
|
-
SQ223: { label: "宿迁贰贰叁" },
|
|
17
|
-
QDXY: { label: "青岛信跃" },
|
|
18
|
-
XZYA: { label: "徐州沂埃平台" },
|
|
19
|
-
},
|
|
20
|
-
dev: {
|
|
21
|
-
command: ["pnpm", "exec", "vue-cli-service", "serve"],
|
|
22
|
-
},
|
|
23
|
-
build: {
|
|
24
|
-
before: ["infly-libs", "beforeBuild"],
|
|
25
|
-
command: ["pnpm", "exec", "vue-cli-service", "build"],
|
|
26
|
-
after: ["infly-libs", "afterBuild"],
|
|
27
|
-
environments: {
|
|
28
|
-
prod: { label: "正式环境", mode: "production", args: [] },
|
|
29
|
-
stage: { label: "测试环境", mode: "staging", args: ["--mode", "staging"] },
|
|
30
|
-
},
|
|
31
|
-
presets: {
|
|
32
|
-
all: { label: "批量构建", targets: ["SQ223", "QDXY", "XZYA"] },
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
test("resolveBuildPlatforms derives platforms from shared target keys", () => {
|
|
38
|
-
assert.deepEqual(resolveBuildPlatforms(config.targets, config.build, "SQ223"), ["SQ223"]);
|
|
39
|
-
assert.deepEqual(resolveBuildPlatforms(config.targets, config.build, "all"), [
|
|
40
|
-
"SQ223",
|
|
41
|
-
"QDXY",
|
|
42
|
-
"XZYA",
|
|
43
|
-
]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("runProjectCommand accepts target arrays and string dev commands", async () => {
|
|
47
|
-
const calls = [];
|
|
48
|
-
const compactConfig = {
|
|
49
|
-
targets: ["QDXY"],
|
|
50
|
-
dev: { command: "pnpm exec vue-cli-service serve" },
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
await runProjectCommand(
|
|
54
|
-
{ action: "dev", target: "QDXY", config: compactConfig, configDir: "C:/project" },
|
|
55
|
-
{ runCommand: (command, args, options) => calls.push({ command, args, options }) },
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
assert.equal(calls[0].command, "pnpm");
|
|
59
|
-
assert.deepEqual(calls[0].args, ["exec", "vue-cli-service", "serve"]);
|
|
60
|
-
assert.equal(calls[0].options.env.VUE_APP_PLATFORM, "QDXY");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("runProjectCommand accepts string build lifecycle commands", async () => {
|
|
64
|
-
const calls = [];
|
|
65
|
-
const compactConfig = {
|
|
66
|
-
targets: { SQ223: {} },
|
|
67
|
-
build: {
|
|
68
|
-
before: "infly-libs beforeBuild",
|
|
69
|
-
command: "pnpm exec vue-cli-service build",
|
|
70
|
-
after: "infly-libs afterBuild",
|
|
71
|
-
environments: ["stage:staging"],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
await runProjectCommand(
|
|
76
|
-
{ action: "build", target: "SQ223", env: "stage", config: compactConfig, configDir: "C:/project" },
|
|
77
|
-
{ runCommand: (command, args, options) => calls.push({ command, args, options }) },
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
assert.deepEqual(
|
|
81
|
-
calls.map(({ command, args }) => ({ command, args })),
|
|
82
|
-
[
|
|
83
|
-
{ command: "infly-libs", args: ["beforeBuild", "--mode", "staging"] },
|
|
84
|
-
{ command: "pnpm", args: ["exec", "vue-cli-service", "build", "--mode", "staging"] },
|
|
85
|
-
{ command: "infly-libs", args: ["afterBuild", "--mode", "staging"] },
|
|
86
|
-
],
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("loadConfig reads project commands from package.json infly config", () => {
|
|
91
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "project-config-discovery-"));
|
|
92
|
-
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({
|
|
93
|
-
name: "fixture",
|
|
94
|
-
infly: {
|
|
95
|
-
buildConfigs: { enabled: true },
|
|
96
|
-
targets: { QDXY: { label: "青岛信跃" } },
|
|
97
|
-
dev: { marker: "dev" },
|
|
98
|
-
build: { marker: "build" },
|
|
99
|
-
},
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const loaded = loadConfig(dir);
|
|
104
|
-
assert.deepEqual(loaded.config, {
|
|
105
|
-
targets: { QDXY: { label: "青岛信跃" } },
|
|
106
|
-
dev: { marker: "dev" },
|
|
107
|
-
build: { marker: "build" },
|
|
108
|
-
});
|
|
109
|
-
assert.equal(loaded.configDir, dir);
|
|
110
|
-
} finally {
|
|
111
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("runProjectCommand starts a selected dev target", async () => {
|
|
116
|
-
const calls = [];
|
|
117
|
-
|
|
118
|
-
await runProjectCommand(
|
|
119
|
-
{ action: "dev", target: "QDXY", config, configDir: "C:/project" },
|
|
120
|
-
{ runCommand: (command, args, options) => calls.push({ command, args, options }) },
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
assert.equal(calls.length, 1);
|
|
124
|
-
assert.equal(calls[0].command, "pnpm");
|
|
125
|
-
assert.deepEqual(calls[0].args, ["exec", "vue-cli-service", "serve"]);
|
|
126
|
-
assert.equal(calls[0].options.cwd, "C:/project");
|
|
127
|
-
assert.equal(calls[0].options.env.VUE_APP_PLATFORM, "QDXY");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("runProjectCommand executes lifecycle for every selected build platform", async () => {
|
|
131
|
-
const calls = [];
|
|
132
|
-
|
|
133
|
-
await runProjectCommand(
|
|
134
|
-
{ action: "build", target: "SQ223", env: "stage", config, configDir: "C:/project" },
|
|
135
|
-
{ runCommand: (command, args, options) => calls.push({ command, args, options }) },
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
assert.deepEqual(
|
|
139
|
-
calls.map(({ command, args, options }) => ({
|
|
140
|
-
command,
|
|
141
|
-
args,
|
|
142
|
-
platform: options.env.VUE_APP_PLATFORM,
|
|
143
|
-
})),
|
|
144
|
-
[
|
|
145
|
-
{ command: "infly-libs", args: ["beforeBuild", "--mode", "staging"], platform: "SQ223" },
|
|
146
|
-
{
|
|
147
|
-
command: "pnpm",
|
|
148
|
-
args: ["exec", "vue-cli-service", "build", "--mode", "staging"],
|
|
149
|
-
platform: "SQ223",
|
|
150
|
-
},
|
|
151
|
-
{ command: "infly-libs", args: ["afterBuild", "--mode", "staging"], platform: "SQ223" },
|
|
152
|
-
],
|
|
153
|
-
);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test("runProjectCommand prompts when action, environment, and target are omitted", async () => {
|
|
157
|
-
const answers = ["build", "stage", "QDXY"];
|
|
158
|
-
const prompts = [];
|
|
159
|
-
const calls = [];
|
|
160
|
-
|
|
161
|
-
await runProjectCommand(
|
|
162
|
-
{ config, configDir: "C:/project", dryRun: true },
|
|
163
|
-
{
|
|
164
|
-
selectOption: async (message, choices) => {
|
|
165
|
-
prompts.push({ message, choices });
|
|
166
|
-
return answers.shift();
|
|
167
|
-
},
|
|
168
|
-
runCommand: (...args) => calls.push(args),
|
|
169
|
-
},
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
assert.deepEqual(prompts.map(({ message }) => message), [
|
|
173
|
-
"请选择操作",
|
|
174
|
-
"请选择构建环境",
|
|
175
|
-
"请选择目标平台",
|
|
176
|
-
]);
|
|
177
|
-
assert.equal(calls.length, 0);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("runProjectCommand exits cleanly when the user chooses exit", async () => {
|
|
181
|
-
const logs = [];
|
|
182
|
-
const result = await runProjectCommand(
|
|
183
|
-
{ config, configDir: "C:/project" },
|
|
184
|
-
{
|
|
185
|
-
selectOption: async () => EXIT_SELECTION,
|
|
186
|
-
log: (message) => logs.push(message),
|
|
187
|
-
runCommand: () => assert.fail("no command should run after exit"),
|
|
188
|
-
},
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
assert.deepEqual(result, { cancelled: true });
|
|
192
|
-
assert.deepEqual(logs, ["已退出,未执行任何操作。"]);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
test("postal project scripts keep defaults non-interactive and platform scripts interactive", () => {
|
|
196
|
-
const appDir = path.resolve(__dirname, "../../../apps/postal-benefits-platform");
|
|
197
|
-
const packageJson = require(path.join(appDir, "package.json"));
|
|
198
|
-
const scripts = packageJson.scripts;
|
|
199
|
-
|
|
200
|
-
assert.equal(scripts.dev, "vue-cli-service serve");
|
|
201
|
-
assert.equal(scripts["project"], "infly-libs project");
|
|
202
|
-
assert.equal(scripts["dev:platform"], "infly-libs project dev");
|
|
203
|
-
assert.equal(scripts["build:prod"], "infly-libs beforeBuild && vue-cli-service build && infly-libs afterBuild");
|
|
204
|
-
assert.equal(scripts["build:stage"], "infly-libs beforeBuild && vue-cli-service build --mode staging && infly-libs afterBuild");
|
|
205
|
-
assert.equal(scripts["build:prod:platform"], "infly-libs project build --env prod");
|
|
206
|
-
assert.equal(scripts["build:stage:platform"], "infly-libs project build --env stage");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test("postal package shares one target map across dev and build", () => {
|
|
210
|
-
const appDir = path.resolve(__dirname, "../../../apps/postal-benefits-platform");
|
|
211
|
-
const projectConfig = require(path.join(appDir, "package.json")).infly;
|
|
212
|
-
|
|
213
|
-
assert.equal(projectConfig.dev.targets, undefined);
|
|
214
|
-
assert.equal(projectConfig.build.targets, undefined);
|
|
215
|
-
assert.deepEqual(projectConfig.targets, [
|
|
216
|
-
"DEFAULT",
|
|
217
|
-
"MER",
|
|
218
|
-
"JXEE",
|
|
219
|
-
"JXEELEVEL",
|
|
220
|
-
"SQ223",
|
|
221
|
-
"SQ223LEVEL",
|
|
222
|
-
"QDXY",
|
|
223
|
-
"XZYA",
|
|
224
|
-
]);
|
|
225
|
-
assert.deepEqual(projectConfig.build.environments, ["prod:production", "stage:staging"]);
|
|
226
|
-
assert.deepEqual(projectConfig.build.presets.all.targets, [
|
|
227
|
-
"SQ223",
|
|
228
|
-
"SQ223LEVEL",
|
|
229
|
-
"QDXY",
|
|
230
|
-
"XZYA",
|
|
231
|
-
]);
|
|
232
|
-
assert.doesNotMatch(JSON.stringify(projectConfig), /益爱圈/);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("project build requires an explicit environment outside a TTY", async () => {
|
|
236
|
-
await assert.rejects(
|
|
237
|
-
() => runProjectCommand({
|
|
238
|
-
action: "build",
|
|
239
|
-
target: "QDXY",
|
|
240
|
-
dryRun: true,
|
|
241
|
-
configObject: {
|
|
242
|
-
targets: { QDXY: { label: "青岛信跃" } },
|
|
243
|
-
build: {
|
|
244
|
-
before: ["infly-libs", "beforeBuild"],
|
|
245
|
-
command: ["pnpm", "build"],
|
|
246
|
-
after: ["infly-libs", "afterBuild"],
|
|
247
|
-
environments: { prod: { label: "正式环境", mode: "production", args: [] } },
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
configDir: ".",
|
|
251
|
-
}),
|
|
252
|
-
/interactive selection requires a TTY/,
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
test("runProjectCommand rejects project config file paths", async () => {
|
|
256
|
-
await assert.rejects(
|
|
257
|
-
() => runProjectCommand({ action: "dev", config: "legacy.config.js" }),
|
|
258
|
-
/--config is not supported for project commands/,
|
|
259
|
-
);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
test("runProjectCommand rejects unknown targets before executing commands", async () => {
|
|
263
|
-
await assert.rejects(
|
|
264
|
-
() => runProjectCommand({ action: "dev", target: "missing", config, configDir: "." }),
|
|
265
|
-
/Unknown dev target: missing/,
|
|
266
|
-
);
|
|
267
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const assert = require("node:assert/strict");
|
|
2
|
-
const { EventEmitter } = require("node:events");
|
|
3
|
-
const test = require("node:test");
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
EXIT_SELECTION,
|
|
7
|
-
makePromptCancellationSafe,
|
|
8
|
-
selectOption,
|
|
9
|
-
} = require("./select-option");
|
|
10
|
-
|
|
11
|
-
test("makePromptCancellationSafe ignores readline cleanup after it was closed", () => {
|
|
12
|
-
const prompt = new EventEmitter();
|
|
13
|
-
const unsafeStop = () => {
|
|
14
|
-
const error = new Error("readline was closed");
|
|
15
|
-
error.code = "ERR_USE_AFTER_CLOSE";
|
|
16
|
-
throw error;
|
|
17
|
-
};
|
|
18
|
-
prompt.stop = unsafeStop;
|
|
19
|
-
prompt.once("close", unsafeStop);
|
|
20
|
-
|
|
21
|
-
makePromptCancellationSafe(prompt);
|
|
22
|
-
|
|
23
|
-
assert.doesNotThrow(() => prompt.emit("close"));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("selectOption offers exit and converts cancellation into an exit result", async () => {
|
|
27
|
-
let promptOptions;
|
|
28
|
-
class CancelledSelect extends EventEmitter {
|
|
29
|
-
constructor(options) {
|
|
30
|
-
super();
|
|
31
|
-
promptOptions = options;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
run() {
|
|
35
|
-
const error = new Error("cancelled");
|
|
36
|
-
error.name = "CancelPromptError";
|
|
37
|
-
return Promise.reject(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const result = await selectOption(
|
|
42
|
-
"请选择操作",
|
|
43
|
-
[{ value: "dev", label: "启动开发环境" }],
|
|
44
|
-
{ Select: CancelledSelect, stdin: { isTTY: true }, stdout: { isTTY: true } },
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
assert.equal(result, EXIT_SELECTION);
|
|
48
|
-
assert.deepEqual(promptOptions.choices.at(-1), {
|
|
49
|
-
name: EXIT_SELECTION,
|
|
50
|
-
message: "退出",
|
|
51
|
-
});
|
|
52
|
-
});
|
package/webpack.config.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 用于将一些常用的库打包压缩成模块文件 libs/ 而不依赖node_modules
|
|
3
|
-
*/
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const nodeExternals = require("webpack-node-externals");
|
|
6
|
-
|
|
7
|
-
const libName = "connect";
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
mode: "production",
|
|
11
|
-
target: "node", // 关键配置:生成Node环境兼容代码
|
|
12
|
-
entry: "./lib/index.js",
|
|
13
|
-
output: {
|
|
14
|
-
filename: `${libName}.js`,
|
|
15
|
-
path: path.resolve(__dirname, "lib/server"),
|
|
16
|
-
libraryTarget: "commonjs2" // 符合Node模块规范
|
|
17
|
-
},
|
|
18
|
-
externals: [
|
|
19
|
-
nodeExternals({
|
|
20
|
-
allowlist: [libName], // 强制打包含路径操作的模块
|
|
21
|
-
modulesFromFile: true // 自动读取package.json的dependencies
|
|
22
|
-
})
|
|
23
|
-
],
|
|
24
|
-
module: {
|
|
25
|
-
rules: [
|
|
26
|
-
{
|
|
27
|
-
test: /\.js$/,
|
|
28
|
-
exclude: new RegExp(`/node_modules\\/(?!(${libName})\\/).*`), // 仅编译目标模块
|
|
29
|
-
use: "babel-loader" // 可选:如需语法降级
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
},
|
|
33
|
-
optimization: {
|
|
34
|
-
splitChunks: false, // 关闭代码分割
|
|
35
|
-
runtimeChunk: false, // 禁用runtime文件生成
|
|
36
|
-
minimize: false // 关闭代码压缩
|
|
37
|
-
}
|
|
38
|
-
};
|