@vnejs/build 0.0.41 → 0.0.43
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/package.json +1 -1
- package/src/client/utils.js +28 -7
- package/src/client/vite.config.js +5 -7
package/package.json
CHANGED
package/src/client/utils.js
CHANGED
|
@@ -3,6 +3,22 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
const entryDir = "entry";
|
|
5
5
|
|
|
6
|
+
const resolveIndexedFile = (dir) => {
|
|
7
|
+
const candidates = ["index.ts", "index.js"].map((name) => path.join(dir, name));
|
|
8
|
+
|
|
9
|
+
return candidates.find((file) => fs.existsSync(file));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const resolveEntryFile = (entryRoot) => {
|
|
13
|
+
const entryFile = resolveIndexedFile(entryRoot);
|
|
14
|
+
|
|
15
|
+
if (!entryFile) {
|
|
16
|
+
throw new Error(`entry file not found: expected ${["index.ts", "index.js"].map((name) => path.join(entryRoot, name)).join(" or ")}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return entryFile;
|
|
20
|
+
};
|
|
21
|
+
|
|
6
22
|
const getVnejsScopedPackageNames = (rootPath, scopePrefix) => {
|
|
7
23
|
let dir = rootPath;
|
|
8
24
|
|
|
@@ -16,8 +32,10 @@ const getVnejsScopedPackageNames = (rootPath, scopePrefix) => {
|
|
|
16
32
|
.map((name) => `@vnejs/${name}`)
|
|
17
33
|
.filter((packageName) => {
|
|
18
34
|
try {
|
|
19
|
-
require.resolve(`${packageName}/package.json`, { paths: [rootPath] });
|
|
20
|
-
|
|
35
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`, { paths: [rootPath] });
|
|
36
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
37
|
+
|
|
38
|
+
return !pkg.private;
|
|
21
39
|
} catch {
|
|
22
40
|
return false;
|
|
23
41
|
}
|
|
@@ -63,20 +81,22 @@ const getGameModScripts = (rootPath) => {
|
|
|
63
81
|
|
|
64
82
|
return fs
|
|
65
83
|
.readdirSync(gamePath)
|
|
66
|
-
.
|
|
67
|
-
.
|
|
84
|
+
.map((modDir) => resolveIndexedFile(path.join(gamePath, modDir, "scripts")))
|
|
85
|
+
.filter(Boolean)
|
|
86
|
+
.sort((modScriptA, modScriptB) => {
|
|
87
|
+
const modA = path.basename(path.dirname(path.dirname(modScriptA)));
|
|
88
|
+
const modB = path.basename(path.dirname(path.dirname(modScriptB)));
|
|
68
89
|
const orderDiff = getModOrder(modB, gamePath) - getModOrder(modA, gamePath);
|
|
69
90
|
|
|
70
91
|
return orderDiff !== 0 ? orderDiff : modA.localeCompare(modB);
|
|
71
|
-
})
|
|
72
|
-
.map((modDir) => path.join(gamePath, modDir, "scripts", "index.js"));
|
|
92
|
+
});
|
|
73
93
|
};
|
|
74
94
|
|
|
75
95
|
const importStatementPattern = /^[ \t]*import\s[\s\S]*?;[ \t]*(?:\n|$)/gm;
|
|
76
96
|
|
|
77
97
|
const toImportStatements = (targets) => targets.map((target) => `import ${JSON.stringify(target)};`);
|
|
78
98
|
|
|
79
|
-
// Порядок side-effect импортов важен: uis → bundle → entry/index.js → game/*/scripts → тело модуля.
|
|
99
|
+
// Порядок side-effect импортов важен: uis → bundle → entry/index.(ts|js) → game/*/scripts/index.(ts|js) → тело модуля.
|
|
80
100
|
const orderEntryImports = (code, { leadingImports = [], trailingImports = [] } = {}) => {
|
|
81
101
|
const leading = toImportStatements(leadingImports);
|
|
82
102
|
const trailing = toImportStatements(trailingImports);
|
|
@@ -106,6 +126,7 @@ const cleanClientOutput = (distPath, isClientOutput) => {
|
|
|
106
126
|
|
|
107
127
|
module.exports = {
|
|
108
128
|
entryDir,
|
|
129
|
+
resolveEntryFile,
|
|
109
130
|
getVnejsScopedPackageNames,
|
|
110
131
|
getGameModIndexJsonFiles,
|
|
111
132
|
getGameModScripts,
|
|
@@ -4,6 +4,7 @@ const react = require("@vitejs/plugin-react").default;
|
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
entryDir,
|
|
7
|
+
resolveEntryFile,
|
|
7
8
|
getVnejsScopedPackageNames,
|
|
8
9
|
getGameModIndexJsonFiles,
|
|
9
10
|
getGameModScripts,
|
|
@@ -29,13 +30,10 @@ module.exports = (rootPath, options = {}) => {
|
|
|
29
30
|
const isDev = mode === "development";
|
|
30
31
|
const entryRoot = path.join(rootPath, entryDir);
|
|
31
32
|
const distPath = path.join(rootPath, "dist");
|
|
32
|
-
const entryFile =
|
|
33
|
+
const entryFile = resolveEntryFile(entryRoot);
|
|
34
|
+
const entryScript = `./${path.basename(entryFile)}`;
|
|
33
35
|
const htmlFile = path.join(entryRoot, "index.html");
|
|
34
36
|
|
|
35
|
-
if (!fs.existsSync(entryFile)) {
|
|
36
|
-
throw new Error(`entry file not found: ${entryFile}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
37
|
if (!fs.existsSync(htmlFile)) {
|
|
40
38
|
throw new Error(`html template not found: ${htmlFile}`);
|
|
41
39
|
}
|
|
@@ -77,9 +75,9 @@ module.exports = (rootPath, options = {}) => {
|
|
|
77
75
|
transformIndexHtml: {
|
|
78
76
|
order: "pre",
|
|
79
77
|
handler(html) {
|
|
80
|
-
if (html.includes(
|
|
78
|
+
if (html.includes(entryScript)) return html;
|
|
81
79
|
|
|
82
|
-
return html.replace("</body>",
|
|
80
|
+
return html.replace("</body>", ` <script type="module" src="${entryScript}"></script>\n </body>`);
|
|
83
81
|
},
|
|
84
82
|
},
|
|
85
83
|
},
|