@esmx/core 3.0.0-rc.37 → 3.0.0-rc.38
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/cli/cli.mjs +3 -3
- package/dist/utils/resolve-path.d.ts +1 -0
- package/dist/utils/resolve-path.mjs +5 -0
- package/dist/utils/resolve-path.test.mjs +31 -2
- package/package.json +4 -4
- package/src/cli/cli.ts +4 -12
- package/src/utils/resolve-path.test.ts +35 -2
- package/src/utils/resolve-path.ts +6 -0
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import module from "node:module";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import { styleText } from "node:util";
|
|
4
3
|
import pkg from "../../package.json" with { type: "json" };
|
|
5
4
|
import { COMMAND, Esmx } from "../core.mjs";
|
|
5
|
+
import { resolveImportPath } from "../utils/resolve-path.mjs";
|
|
6
6
|
async function getSrcOptions() {
|
|
7
|
-
return import(
|
|
7
|
+
return import(resolveImportPath(process.cwd(), "./src/entry.node.ts")).then(
|
|
8
8
|
(m) => m.default
|
|
9
9
|
);
|
|
10
10
|
}
|
|
@@ -56,7 +56,7 @@ export async function cli(command) {
|
|
|
56
56
|
opts = null;
|
|
57
57
|
break;
|
|
58
58
|
default:
|
|
59
|
-
await import(
|
|
59
|
+
await import(resolveImportPath(process.cwd(), command));
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export type ProjectPath = './' | 'dist' | 'dist/index.mjs' | 'dist/package.json' | 'dist/client' | 'dist/client/manifest.json' | 'dist/client/js' | 'dist/client/css' | 'dist/client/images' | 'dist/client/media' | 'dist/client/fonts' | 'dist/client/workers' | 'dist/client/importmap' | 'dist/client/versions/latest.tgz' | 'dist/server' | 'dist/server/js' | 'dist/server/manifest.json' | 'dist/node' | 'dist/node/js' | 'src' | 'src/entry.node.ts' | 'src/entry.client.ts' | 'src/entry.server.ts' | 'package.json';
|
|
2
2
|
export declare function resolvePath(root: string, projectPath: ProjectPath, ...args: string[]): string;
|
|
3
|
+
export declare function resolveImportPath(...paths: string[]): string;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
2
3
|
export function resolvePath(root, projectPath, ...args) {
|
|
3
4
|
return path.resolve(root, projectPath, ...args);
|
|
4
5
|
}
|
|
6
|
+
export function resolveImportPath(...paths) {
|
|
7
|
+
const absolutePath = path.resolve(...paths);
|
|
8
|
+
return pathToFileURL(absolutePath).href;
|
|
9
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { assert, describe, test } from "vitest";
|
|
4
|
+
import { resolveImportPath, resolvePath } from "./resolve-path.mjs";
|
|
4
5
|
const TEST_ROOT = "/test/root";
|
|
5
6
|
test("basic path resolution", () => {
|
|
6
7
|
const result = resolvePath(TEST_ROOT, "./");
|
|
@@ -50,3 +51,31 @@ test("with additional arguments", () => {
|
|
|
50
51
|
path.resolve(TEST_ROOT, "src", "entry.client.ts")
|
|
51
52
|
);
|
|
52
53
|
});
|
|
54
|
+
describe("resolveImportPath", () => {
|
|
55
|
+
test("should handle multiple path segments", () => {
|
|
56
|
+
const result = resolveImportPath("base", "path", "file.ts");
|
|
57
|
+
assert.typeOf(result, "string");
|
|
58
|
+
const expectedPath = pathToFileURL(
|
|
59
|
+
path.resolve("base", "path", "file.ts")
|
|
60
|
+
).href;
|
|
61
|
+
assert.equal(result, expectedPath);
|
|
62
|
+
});
|
|
63
|
+
test("should resolve from cwd when using relative paths", () => {
|
|
64
|
+
const result = resolveImportPath("./relative/file.ts");
|
|
65
|
+
const expected = pathToFileURL(path.resolve("./relative/file.ts")).href;
|
|
66
|
+
assert.equal(result, expected);
|
|
67
|
+
});
|
|
68
|
+
test("should handle absolute paths", () => {
|
|
69
|
+
const absolutePath = path.resolve("/absolute/path/file.ts");
|
|
70
|
+
const result = resolveImportPath(absolutePath);
|
|
71
|
+
const expected = pathToFileURL(absolutePath).href;
|
|
72
|
+
assert.equal(result, expected);
|
|
73
|
+
});
|
|
74
|
+
test("should work with process.cwd()", () => {
|
|
75
|
+
const result = resolveImportPath(process.cwd(), "src", "file.ts");
|
|
76
|
+
const expected = pathToFileURL(
|
|
77
|
+
path.resolve(process.cwd(), "src", "file.ts")
|
|
78
|
+
).href;
|
|
79
|
+
assert.equal(result, expected);
|
|
80
|
+
});
|
|
81
|
+
});
|
package/package.json
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"build": "unbuild"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@esmx/import": "3.0.0-rc.
|
|
62
|
+
"@esmx/import": "3.0.0-rc.38",
|
|
63
63
|
"@types/serialize-javascript": "^5.0.4",
|
|
64
64
|
"es-module-lexer": "^1.7.0",
|
|
65
65
|
"find": "^0.3.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@biomejs/biome": "1.9.4",
|
|
71
|
-
"@esmx/lint": "3.0.0-rc.
|
|
71
|
+
"@esmx/lint": "3.0.0-rc.38",
|
|
72
72
|
"@types/find": "^0.2.4",
|
|
73
73
|
"@types/node": "^24.0.0",
|
|
74
74
|
"@types/send": "^0.17.4",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"unbuild": "3.5.0",
|
|
80
80
|
"vitest": "3.2.4"
|
|
81
81
|
},
|
|
82
|
-
"version": "3.0.0-rc.
|
|
82
|
+
"version": "3.0.0-rc.38",
|
|
83
83
|
"type": "module",
|
|
84
84
|
"private": false,
|
|
85
85
|
"exports": {
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"template",
|
|
103
103
|
"public"
|
|
104
104
|
],
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "f90b5aae594164a5f62369d4999437ab49993c71"
|
|
106
106
|
}
|
package/src/cli/cli.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import module from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
2
|
import { styleText } from 'node:util';
|
|
5
3
|
import pkg from '../../package.json' with { type: 'json' };
|
|
6
4
|
|
|
7
5
|
import { COMMAND, Esmx, type EsmxOptions } from '../core';
|
|
6
|
+
import { resolveImportPath } from '../utils/resolve-path';
|
|
8
7
|
|
|
9
8
|
async function getSrcOptions(): Promise<EsmxOptions> {
|
|
10
|
-
return import(
|
|
9
|
+
return import(resolveImportPath(process.cwd(), './src/entry.node.ts')).then(
|
|
11
10
|
(m) => m.default
|
|
12
11
|
);
|
|
13
12
|
}
|
|
@@ -26,7 +25,6 @@ export async function cli(command: string) {
|
|
|
26
25
|
esmx = new Esmx(opts);
|
|
27
26
|
exit(await esmx.init(COMMAND.dev));
|
|
28
27
|
|
|
29
|
-
// 释放内存
|
|
30
28
|
esmx = null;
|
|
31
29
|
opts = null;
|
|
32
30
|
break;
|
|
@@ -35,14 +33,12 @@ export async function cli(command: string) {
|
|
|
35
33
|
`Please use 'NODE_ENV=production node dist/index.mjs' to run the built program`
|
|
36
34
|
);
|
|
37
35
|
case COMMAND.build:
|
|
38
|
-
// 编译代码。
|
|
39
36
|
opts = await getSrcOptions();
|
|
40
37
|
esmx = new Esmx(opts);
|
|
41
38
|
exit(await esmx.init(COMMAND.build));
|
|
42
39
|
exit(await esmx.destroy());
|
|
43
40
|
|
|
44
41
|
if (typeof opts.postBuild === 'function') {
|
|
45
|
-
// 生产模式运行
|
|
46
42
|
esmx = new Esmx({
|
|
47
43
|
...opts,
|
|
48
44
|
server: undefined
|
|
@@ -51,28 +47,25 @@ export async function cli(command: string) {
|
|
|
51
47
|
exit(await esmx.postBuild());
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
// 释放内存
|
|
55
50
|
esmx = null;
|
|
56
51
|
opts = null;
|
|
57
52
|
break;
|
|
58
53
|
case COMMAND.preview:
|
|
59
54
|
opts = await getSrcOptions();
|
|
60
|
-
|
|
55
|
+
|
|
61
56
|
esmx = new Esmx(opts);
|
|
62
57
|
exit(await esmx.init(COMMAND.build));
|
|
63
58
|
exit(await esmx.destroy());
|
|
64
59
|
|
|
65
|
-
// 生产模式运行
|
|
66
60
|
esmx = new Esmx(opts);
|
|
67
61
|
exit(await esmx.init(COMMAND.start));
|
|
68
62
|
exit(await esmx.postBuild());
|
|
69
63
|
|
|
70
|
-
// 释放内存
|
|
71
64
|
esmx = null;
|
|
72
65
|
opts = null;
|
|
73
66
|
break;
|
|
74
67
|
default:
|
|
75
|
-
await import(
|
|
68
|
+
await import(resolveImportPath(process.cwd(), command));
|
|
76
69
|
break;
|
|
77
70
|
}
|
|
78
71
|
}
|
|
@@ -83,7 +76,6 @@ function exit(ok: boolean) {
|
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
// Support TS files without .ts suffix.
|
|
87
79
|
module.register(import.meta.url, {
|
|
88
80
|
parentURL: import.meta.url
|
|
89
81
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { assert, describe, test } from 'vitest';
|
|
4
|
+
import { resolveImportPath, resolvePath } from './resolve-path';
|
|
4
5
|
|
|
5
6
|
const TEST_ROOT = '/test/root';
|
|
6
7
|
|
|
@@ -56,3 +57,35 @@ test('with additional arguments', () => {
|
|
|
56
57
|
path.resolve(TEST_ROOT, 'src', 'entry.client.ts')
|
|
57
58
|
);
|
|
58
59
|
});
|
|
60
|
+
|
|
61
|
+
describe('resolveImportPath', () => {
|
|
62
|
+
test('should handle multiple path segments', () => {
|
|
63
|
+
const result = resolveImportPath('base', 'path', 'file.ts');
|
|
64
|
+
assert.typeOf(result, 'string');
|
|
65
|
+
const expectedPath = pathToFileURL(
|
|
66
|
+
path.resolve('base', 'path', 'file.ts')
|
|
67
|
+
).href;
|
|
68
|
+
assert.equal(result, expectedPath);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should resolve from cwd when using relative paths', () => {
|
|
72
|
+
const result = resolveImportPath('./relative/file.ts');
|
|
73
|
+
const expected = pathToFileURL(path.resolve('./relative/file.ts')).href;
|
|
74
|
+
assert.equal(result, expected);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should handle absolute paths', () => {
|
|
78
|
+
const absolutePath = path.resolve('/absolute/path/file.ts');
|
|
79
|
+
const result = resolveImportPath(absolutePath);
|
|
80
|
+
const expected = pathToFileURL(absolutePath).href;
|
|
81
|
+
assert.equal(result, expected);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should work with process.cwd()', () => {
|
|
85
|
+
const result = resolveImportPath(process.cwd(), 'src', 'file.ts');
|
|
86
|
+
const expected = pathToFileURL(
|
|
87
|
+
path.resolve(process.cwd(), 'src', 'file.ts')
|
|
88
|
+
).href;
|
|
89
|
+
assert.equal(result, expected);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
2
3
|
|
|
3
4
|
export type ProjectPath =
|
|
4
5
|
| './'
|
|
@@ -33,3 +34,8 @@ export function resolvePath(
|
|
|
33
34
|
): string {
|
|
34
35
|
return path.resolve(root, projectPath, ...args);
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
export function resolveImportPath(...paths: string[]): string {
|
|
39
|
+
const absolutePath = path.resolve(...paths);
|
|
40
|
+
return pathToFileURL(absolutePath).href;
|
|
41
|
+
}
|