@tego/devkit 1.6.11 → 1.6.13-alpha.2
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.
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/__tests__/test-command.test.ts
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import registerTestCommand from "../commands/test.mjs";
|
|
6
|
+
vi.mock("execa", () => ({
|
|
7
|
+
execa: vi.fn()
|
|
8
|
+
}));
|
|
9
|
+
var mockedExeca = vi.mocked(execa);
|
|
10
|
+
function createCli() {
|
|
11
|
+
const cli = new Command();
|
|
12
|
+
registerTestCommand(cli);
|
|
13
|
+
return cli;
|
|
14
|
+
}
|
|
15
|
+
async function runCli(args) {
|
|
16
|
+
const cli = createCli();
|
|
17
|
+
await cli.parseAsync(["node", "cli", ...args], { from: "node" });
|
|
18
|
+
}
|
|
19
|
+
describe("devkit test commands", () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mockedExeca.mockReset();
|
|
22
|
+
});
|
|
23
|
+
it("registers test, test:server, and test:client commands", () => {
|
|
24
|
+
const cli = createCli();
|
|
25
|
+
expect(cli.commands.map((command) => command.name())).toEqual(
|
|
26
|
+
expect.arrayContaining(["test", "test:server", "test:client"])
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
it("runs vitest with forwarded test arguments", async () => {
|
|
30
|
+
await runCli(["test", "--project", "server", "packages/foo.test.ts"]);
|
|
31
|
+
expect(mockedExeca).toHaveBeenCalledWith(
|
|
32
|
+
"pnpm",
|
|
33
|
+
["exec", "vitest", "--project", "server", "packages/foo.test.ts"],
|
|
34
|
+
{ stdio: "inherit" }
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
it("runs server tests with server project and forwarded arguments", async () => {
|
|
38
|
+
await runCli(["test:server", "--project", "custom", "packages/server.test.ts"]);
|
|
39
|
+
expect(mockedExeca).toHaveBeenCalledWith(
|
|
40
|
+
"pnpm",
|
|
41
|
+
["exec", "vitest", "--project", "server", "--project", "custom", "packages/server.test.ts"],
|
|
42
|
+
{ stdio: "inherit" }
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
it("runs client tests with client project and forwarded arguments", async () => {
|
|
46
|
+
await runCli(["test:client", "--project", "custom", "packages/client.test.ts"]);
|
|
47
|
+
expect(mockedExeca).toHaveBeenCalledWith(
|
|
48
|
+
"pnpm",
|
|
49
|
+
["exec", "vitest", "--project", "client", "--project", "custom", "packages/client.test.ts"],
|
|
50
|
+
{ stdio: "inherit" }
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -19,9 +19,11 @@ async function buildEsm(cwd, userConfig, sourcemap = false, log) {
|
|
|
19
19
|
const e2eEntry = path.join(cwd, "src/e2e/index.ts").replaceAll(/\\/g, "/");
|
|
20
20
|
const e2eOutDir = path.resolve(cwd, "es/e2e");
|
|
21
21
|
await build(cwd, e2eEntry, e2eOutDir, userConfig, sourcemap, log);
|
|
22
|
+
const vitestEntry = path.join(cwd, "src/vitest.ts").replaceAll(/\\/g, "/");
|
|
23
|
+
await build(cwd, vitestEntry, outDir, userConfig, sourcemap, log, "vitest", false);
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
function build(cwd, entry, outDir, userConfig, sourcemap = false, log) {
|
|
26
|
+
function build(cwd, entry, outDir, userConfig, sourcemap = false, log, fileName = "index", emptyOutDir = true) {
|
|
25
27
|
const cwdWin = cwd.replaceAll(/\\/g, "/");
|
|
26
28
|
const cwdUnix = cwd.replaceAll(/\//g, "\\");
|
|
27
29
|
const external = function(id) {
|
|
@@ -42,12 +44,12 @@ function build(cwd, entry, outDir, userConfig, sourcemap = false, log) {
|
|
|
42
44
|
minify: false,
|
|
43
45
|
outDir,
|
|
44
46
|
cssCodeSplit: true,
|
|
45
|
-
emptyOutDir
|
|
47
|
+
emptyOutDir,
|
|
46
48
|
sourcemap,
|
|
47
49
|
lib: {
|
|
48
50
|
entry,
|
|
49
51
|
formats: ["es"],
|
|
50
|
-
fileName
|
|
52
|
+
fileName
|
|
51
53
|
},
|
|
52
54
|
target: ["node16"],
|
|
53
55
|
rollupOptions: {
|
package/lib/commands/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import global from "./global.mjs";
|
|
|
10
10
|
import install from "./install.mjs";
|
|
11
11
|
import postinstall from "./postinstall.mjs";
|
|
12
12
|
import tar from "./tar.mjs";
|
|
13
|
+
import test from "./test.mjs";
|
|
13
14
|
import ui from "./ui.mjs";
|
|
14
15
|
import upgrade from "./upgrade.mjs";
|
|
15
16
|
var commands_default = async (cli) => {
|
|
@@ -21,6 +22,7 @@ var commands_default = async (cli) => {
|
|
|
21
22
|
dev(cli);
|
|
22
23
|
ui(cli);
|
|
23
24
|
e2e(cli);
|
|
25
|
+
test(cli);
|
|
24
26
|
clean(cli);
|
|
25
27
|
upgrade(cli);
|
|
26
28
|
install(cli);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/commands/test.ts
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
function runVitest(args) {
|
|
4
|
+
return execa("pnpm", ["exec", "vitest", ...args], {
|
|
5
|
+
stdio: "inherit"
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function test(cli) {
|
|
9
|
+
cli.command("test").allowUnknownOption(true).allowExcessArguments(true).description("Run Vitest tests").action(async (_, command) => {
|
|
10
|
+
await runVitest(command.args);
|
|
11
|
+
});
|
|
12
|
+
cli.command("test:server").allowUnknownOption(true).allowExcessArguments(true).description("Run server Vitest tests").action(async (_, command) => {
|
|
13
|
+
await runVitest(["--project", "server", ...command.args]);
|
|
14
|
+
});
|
|
15
|
+
cli.command("test:client").allowUnknownOption(true).allowExcessArguments(true).description("Run client Vitest tests").action(async (_, command) => {
|
|
16
|
+
await runVitest(["--project", "client", ...command.args]);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
test as default
|
|
21
|
+
};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src/package-map-generator.ts
|
|
9
2
|
import { existsSync as _existsSync, existsSync, mkdirSync, readFileSync, rmSync, watch, writeFileSync } from "fs";
|
|
3
|
+
import { createRequire } from "module";
|
|
10
4
|
import { dirname as _dirname, sep as _sep, join, relative, resolve, sep } from "path";
|
|
11
|
-
import
|
|
12
|
-
|
|
5
|
+
import fastGlob from "fast-glob";
|
|
6
|
+
var require2 = createRequire(import.meta.url);
|
|
7
|
+
var { version } = require2("../package.json");
|
|
13
8
|
var ProjectRoot = process.cwd();
|
|
14
9
|
function getUmiConfig() {
|
|
15
10
|
const { APP_PORT, API_BASE_URL, APP_PUBLIC_PATH } = process.env;
|
|
@@ -77,7 +72,7 @@ function getPackagePaths() {
|
|
|
77
72
|
if (Object.hasOwnProperty.call(paths, key)) {
|
|
78
73
|
for (let dir of paths[key]) {
|
|
79
74
|
if (dir.includes("*")) {
|
|
80
|
-
const files = sync(dir, { cwd: ProjectRoot, onlyDirectories: true });
|
|
75
|
+
const files = fastGlob.sync(dir, { cwd: ProjectRoot, onlyDirectories: true });
|
|
81
76
|
for (const file of files) {
|
|
82
77
|
const dirname = resolve(ProjectRoot, file);
|
|
83
78
|
if (existsSync(dirname)) {
|
|
@@ -179,7 +174,7 @@ export default function devDynamicImport(packageName: string): Promise<any> {
|
|
|
179
174
|
});
|
|
180
175
|
}
|
|
181
176
|
getContent(pluginsPath) {
|
|
182
|
-
const pluginFolders = sync(["plugin-*/package.json", "module-*/package.json"], {
|
|
177
|
+
const pluginFolders = fastGlob.sync(["plugin-*/package.json", "module-*/package.json"], {
|
|
183
178
|
cwd: pluginsPath,
|
|
184
179
|
onlyFiles: true,
|
|
185
180
|
absolute: true
|
|
@@ -189,7 +184,7 @@ export default function devDynamicImport(packageName: string): Promise<any> {
|
|
|
189
184
|
const clientJs = join(dirname, "client.js");
|
|
190
185
|
return _existsSync(clientJs);
|
|
191
186
|
}).map((pluginPackageJsonPath) => {
|
|
192
|
-
const pluginPackageJson =
|
|
187
|
+
const pluginPackageJson = require2(pluginPackageJsonPath);
|
|
193
188
|
const pluginPathArr = pluginPackageJsonPath.replaceAll(_sep, "/").split("/");
|
|
194
189
|
const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith("@");
|
|
195
190
|
const pluginFileName = (hasNamespace ? `${pluginPathArr[pluginPathArr.length - 3].replace("@", "")}_${pluginPathArr[pluginPathArr.length - 2]}` : pluginPathArr[pluginPathArr.length - 2]).replaceAll("-", "_");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tego/devkit",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.13-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/tegojs/tego#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"update-notifier": "^7.3.1",
|
|
66
66
|
"vite": "^7.1.10",
|
|
67
67
|
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
68
|
-
"@tachybase/test": "1.6.
|
|
68
|
+
"@tachybase/test": "1.6.13-alpha.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/fs-extra": "^11.0.4",
|