xanix 1.0.3 → 1.0.5
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/bin/bundler/buildServer.js +3 -2
- package/dist/bin/bundler/config/output.d.ts +1 -1
- package/dist/bin/bundler/config/output.js +2 -2
- package/dist/bin/bundler/plugins/XanixTsconfigAlias.js +20 -10
- package/dist/bin/bundler/watchServer.js +7 -3
- package/dist/bin/cli/dev.js +2 -2
- package/package.json +1 -1
|
@@ -42,13 +42,14 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
|
42
42
|
if (id.startsWith(".") ||
|
|
43
43
|
path.isAbsolute(id) ||
|
|
44
44
|
id === "@" ||
|
|
45
|
-
id.startsWith("@/")
|
|
45
|
+
id.startsWith("@/") ||
|
|
46
|
+
id.startsWith("xanix")) {
|
|
46
47
|
return false;
|
|
47
48
|
}
|
|
48
49
|
return true;
|
|
49
50
|
},
|
|
50
51
|
});
|
|
51
|
-
await build.write(bundlerOutput.server());
|
|
52
|
+
await build.write(bundlerOutput.server({ isDev: false }));
|
|
52
53
|
await build.close();
|
|
53
54
|
await onBuildEnd(entries);
|
|
54
55
|
};
|
|
@@ -31,11 +31,11 @@ const client = (entries, { isDev }) => {
|
|
|
31
31
|
}
|
|
32
32
|
return opt;
|
|
33
33
|
};
|
|
34
|
-
const server = () => {
|
|
34
|
+
const server = (opt) => {
|
|
35
35
|
return {
|
|
36
36
|
dir: outDir.server,
|
|
37
37
|
format: "esm",
|
|
38
|
-
sourcemap:
|
|
38
|
+
sourcemap: opt.isDev ?? true,
|
|
39
39
|
entryFileNames: "[name].js",
|
|
40
40
|
chunkFileNames: "chunks/[hash].js",
|
|
41
41
|
assetFileNames: "assets/[hash][extname]",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import ts from "typescript";
|
|
4
3
|
import alias from "@rollup/plugin-alias";
|
|
5
4
|
export default function xanixTsconfigAlias() {
|
|
6
5
|
const root = process.cwd();
|
|
@@ -10,22 +9,23 @@ export default function xanixTsconfigAlias() {
|
|
|
10
9
|
name: "xanix-tsconfig-alias",
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
12
|
+
let config;
|
|
13
|
+
try {
|
|
14
|
+
const content = fs.readFileSync(tsconfigPath, "utf8");
|
|
15
|
+
config = parseJsonc(content);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`[xanix] Failed to read tsconfig.json:\n${error.message}`);
|
|
17
19
|
}
|
|
18
|
-
const config = configFile.config;
|
|
19
20
|
const compilerOptions = config.compilerOptions ?? {};
|
|
20
21
|
const baseUrl = compilerOptions.baseUrl ?? ".";
|
|
21
22
|
const basePath = path.resolve(path.dirname(tsconfigPath), baseUrl);
|
|
22
23
|
const paths = compilerOptions.paths ?? {};
|
|
23
24
|
const entries = Object.entries(paths)
|
|
24
25
|
.map(([find, replacements]) => {
|
|
25
|
-
const replacement = replacements[0];
|
|
26
|
-
if (!replacement)
|
|
26
|
+
const replacement = replacements?.[0];
|
|
27
|
+
if (!replacement)
|
|
27
28
|
return null;
|
|
28
|
-
}
|
|
29
29
|
if (find.includes("*")) {
|
|
30
30
|
const findPrefix = find.replace(/\/?\*$/, "");
|
|
31
31
|
const replacementPrefix = replacement.replace(/\/?\*$/, "");
|
|
@@ -39,7 +39,7 @@ export default function xanixTsconfigAlias() {
|
|
|
39
39
|
replacement: path.resolve(basePath, replacement),
|
|
40
40
|
};
|
|
41
41
|
})
|
|
42
|
-
.filter(
|
|
42
|
+
.filter(Boolean);
|
|
43
43
|
return alias({
|
|
44
44
|
entries,
|
|
45
45
|
});
|
|
@@ -47,3 +47,13 @@ export default function xanixTsconfigAlias() {
|
|
|
47
47
|
function escapeRegExp(value) {
|
|
48
48
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
49
|
}
|
|
50
|
+
function parseJsonc(content) {
|
|
51
|
+
const withoutComments = content
|
|
52
|
+
// Remove /* block comments */
|
|
53
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
54
|
+
// Remove // comments
|
|
55
|
+
.replace(/\/\/.*$/gm, "");
|
|
56
|
+
// Remove trailing commas
|
|
57
|
+
const withoutTrailingCommas = withoutComments.replace(/,\s*([}\]])/g, "$1");
|
|
58
|
+
return JSON.parse(withoutTrailingCommas);
|
|
59
|
+
}
|
|
@@ -31,19 +31,23 @@ const watchServer = async ({ rootEntry, onChange, onBuildEnd, onServerChange, on
|
|
|
31
31
|
target: "server",
|
|
32
32
|
development: true,
|
|
33
33
|
assetExternal: false,
|
|
34
|
-
onChange:
|
|
34
|
+
onChange: (entry) => {
|
|
35
|
+
changedFiles.add(entry);
|
|
36
|
+
return onChange?.(entry);
|
|
37
|
+
},
|
|
35
38
|
}),
|
|
36
39
|
],
|
|
37
40
|
external(id) {
|
|
38
41
|
if (id.startsWith(".") ||
|
|
39
42
|
path.isAbsolute(id) ||
|
|
40
43
|
id === "@" ||
|
|
41
|
-
id.startsWith("@/")
|
|
44
|
+
id.startsWith("@/") ||
|
|
45
|
+
id.startsWith("xanix")) {
|
|
42
46
|
return false;
|
|
43
47
|
}
|
|
44
48
|
return true;
|
|
45
49
|
},
|
|
46
|
-
output: bundlerOutput.server(),
|
|
50
|
+
output: bundlerOutput.server({ isDev: true }),
|
|
47
51
|
watch: {
|
|
48
52
|
clearScreen: false,
|
|
49
53
|
},
|
package/dist/bin/cli/dev.js
CHANGED
|
@@ -11,7 +11,7 @@ const root = process.cwd();
|
|
|
11
11
|
let child;
|
|
12
12
|
function start() {
|
|
13
13
|
child?.kill();
|
|
14
|
-
return new Promise((resolve
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
15
|
const filePath = path.join(outDir.server, "index.js");
|
|
16
16
|
child = spawn(process.execPath, [filePath], {
|
|
17
17
|
stdio: !child ? "inherit" : "pipe",
|
|
@@ -78,7 +78,7 @@ const dev = async (rootEntry) => {
|
|
|
78
78
|
async onClientEntryChange(_entry, entries) {
|
|
79
79
|
await clientWatcher(entries);
|
|
80
80
|
},
|
|
81
|
-
onServerChange: async (
|
|
81
|
+
onServerChange: async (_entry, _entries) => {
|
|
82
82
|
await start();
|
|
83
83
|
},
|
|
84
84
|
onBuildEnd: async () => {
|