@vnejs/build 0.0.41 → 0.0.42

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/build",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "description": "Build tools for @vnejs",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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
 
@@ -63,20 +79,22 @@ const getGameModScripts = (rootPath) => {
63
79
 
64
80
  return fs
65
81
  .readdirSync(gamePath)
66
- .filter((modDir) => fs.existsSync(path.join(gamePath, modDir, "scripts", "index.js")))
67
- .sort((modA, modB) => {
82
+ .map((modDir) => resolveIndexedFile(path.join(gamePath, modDir, "scripts")))
83
+ .filter(Boolean)
84
+ .sort((modScriptA, modScriptB) => {
85
+ const modA = path.basename(path.dirname(path.dirname(modScriptA)));
86
+ const modB = path.basename(path.dirname(path.dirname(modScriptB)));
68
87
  const orderDiff = getModOrder(modB, gamePath) - getModOrder(modA, gamePath);
69
88
 
70
89
  return orderDiff !== 0 ? orderDiff : modA.localeCompare(modB);
71
- })
72
- .map((modDir) => path.join(gamePath, modDir, "scripts", "index.js"));
90
+ });
73
91
  };
74
92
 
75
93
  const importStatementPattern = /^[ \t]*import\s[\s\S]*?;[ \t]*(?:\n|$)/gm;
76
94
 
77
95
  const toImportStatements = (targets) => targets.map((target) => `import ${JSON.stringify(target)};`);
78
96
 
79
- // Порядок side-effect импортов важен: uis → bundle → entry/index.js → game/*/scripts → тело модуля.
97
+ // Порядок side-effect импортов важен: uis → bundle → entry/index.(ts|js) → game/*/scripts/index.(ts|js) → тело модуля.
80
98
  const orderEntryImports = (code, { leadingImports = [], trailingImports = [] } = {}) => {
81
99
  const leading = toImportStatements(leadingImports);
82
100
  const trailing = toImportStatements(trailingImports);
@@ -106,6 +124,7 @@ const cleanClientOutput = (distPath, isClientOutput) => {
106
124
 
107
125
  module.exports = {
108
126
  entryDir,
127
+ resolveEntryFile,
109
128
  getVnejsScopedPackageNames,
110
129
  getGameModIndexJsonFiles,
111
130
  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 = path.join(entryRoot, "index.js");
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("./index.js")) return html;
78
+ if (html.includes(entryScript)) return html;
81
79
 
82
- return html.replace("</body>", ' <script type="module" src="./index.js"></script>\n </body>');
80
+ return html.replace("</body>", ` <script type="module" src="${entryScript}"></script>\n </body>`);
83
81
  },
84
82
  },
85
83
  },