@skip-go/widget 2.1.2-alpha.0.8 → 2.1.2-alpha.0.9

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/preinstall.cjs +62 -9
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@skip-go/widget",
3
3
  "description": "Swap widget",
4
- "version": "2.1.2-alpha.0.8",
4
+ "version": "2.1.2-alpha.0.9",
5
5
  "repository": "https://github.com/skip-mev/widget",
6
6
  "type": "module",
7
7
  "exports": {
@@ -91,6 +91,6 @@
91
91
  "@buf:registry": "https://buf.build/gen/npm/v1/"
92
92
  },
93
93
  "scripts": {
94
- "preinstall": "node preinstall.cjs"
94
+ "preinstall": "node preinstall.cjs & yarn add @skip-go/widget@2.1.2-alpha.0.9"
95
95
  }
96
96
  }
package/preinstall.cjs CHANGED
@@ -1,16 +1,69 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
+ const yarnLockPath = path.resolve(__dirname, '../../../yarn.lock');
5
+ const packageLockPath = path.resolve(__dirname, '../../../package-lock.json');
6
+ const yarnrcPath = path.resolve(__dirname, '../../../.yarnrc.yml');
4
7
  const npmrcPath = path.resolve(__dirname, '../../../.npmrc');
5
- const registryConfig = '@buf:registry=https://buf.build/gen/npm/v1/';
6
-
7
- if (!fs.existsSync(npmrcPath)) {
8
- fs.writeFileSync(npmrcPath, registryConfig);
9
- } else {
10
- const npmrcContent = fs.readFileSync(npmrcPath, 'utf-8');
11
- if (!npmrcContent.includes(registryConfig)) {
12
- fs.appendFileSync(npmrcPath, `\n${registryConfig}`);
8
+
9
+ const yarnRegistryConfig = `
10
+ npmScopes:
11
+ buf:
12
+ npmRegistryServer: 'https://buf.build/gen/npm/v1'
13
+ `;
14
+
15
+ const npmRegistryConfig = '@buf:registry=https://buf.build/gen/npm/v1/';
16
+
17
+ function configureYarnrc() {
18
+ console.log(`Checking for .yarnrc.yml at ${yarnrcPath}`);
19
+ if (!fs.existsSync(yarnrcPath)) {
20
+ console.log('.yarnrc.yml not found, creating it.');
21
+ fs.writeFileSync(yarnrcPath, yarnRegistryConfig.trim());
22
+ } else {
23
+ const yarnrcContent = fs.readFileSync(yarnrcPath, 'utf-8');
24
+ if (!yarnrcContent.includes(yarnRegistryConfig.trim())) {
25
+ console.log('Appending registry config to .yarnrc.yml');
26
+ fs.appendFileSync(yarnrcPath, `\n${yarnRegistryConfig.trim()}`);
27
+ } else {
28
+ console.log('Registry config already present in .yarnrc.yml');
29
+ }
30
+ }
31
+ console.log('.yarnrc.yml configured for @buf registry');
32
+ }
33
+
34
+ function configureNpmrc() {
35
+ console.log(`Checking for .npmrc at ${npmrcPath}`);
36
+ if (!fs.existsSync(npmrcPath)) {
37
+ console.log('.npmrc not found, creating it.');
38
+ fs.writeFileSync(npmrcPath, npmRegistryConfig);
39
+ } else {
40
+ const npmrcContent = fs.readFileSync(npmrcPath, 'utf-8');
41
+ if (!npmrcContent.includes(npmRegistryConfig)) {
42
+ console.log('Appending registry config to .npmrc');
43
+ fs.appendFileSync(npmrcPath, `\n${npmRegistryConfig}`);
44
+ } else {
45
+ console.log('Registry config already present in .npmrc');
46
+ }
13
47
  }
48
+ console.log('.npmrc configured for @buf registry');
14
49
  }
15
50
 
16
- console.log('.npmrc configured for @buf registry');
51
+ function main() {
52
+ if (fs.existsSync(yarnLockPath)) {
53
+ console.log('Detected yarn.lock, configuring Yarn registry.');
54
+ configureYarnrc();
55
+ } else if (fs.existsSync(packageLockPath)) {
56
+ console.log('Detected package-lock.json, configuring npm registry.');
57
+ configureNpmrc();
58
+ } else {
59
+ console.log(
60
+ 'No lock file detected. Please use either Yarn or npm to manage dependencies.'
61
+ );
62
+ }
63
+ }
64
+
65
+ console.log('Running configuration script');
66
+
67
+ main();
68
+
69
+ console.log('Configuration complete.');