@leverege/build-tools 2.36.2 → 2.37.1

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.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable security/detect-non-literal-fs-filename */
2
3
  "use strict";
3
4
 
4
5
  var _nodeFs = _interopRequireDefault(require("node:fs"));
@@ -7,35 +8,45 @@ var _chalk = _interopRequireDefault(require("chalk"));
7
8
  var _execa = _interopRequireDefault(require("execa"));
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  // we can't use $ until we upgrade to ESM execa
10
- // the standard user npmrc token is stored here
11
- const npmrc = `${_nodeOs.default.homedir()}/.npmrc`;
12
-
13
11
  // max age in seconds of the npmrc file before refresh
14
12
  const refreshThreshold = 3600 * 24; // 1 day
15
13
 
14
+ // eslint-disable-next-line no-console
16
15
  const log = console.log;
17
-
18
- // calculate number of seconds since last update and exit if the file
19
- // was recently updated
20
- let lastUpdated = refreshThreshold * 2; // forces refresh if npmrc file does not exist
21
- let oldToken;
22
- try {
23
- if (_nodeFs.default.existsSync(npmrc)) {
24
- const stat = _nodeFs.default.statSync(npmrc);
25
- lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
26
- // grab the old token for logging a redacted version
27
- const oldNpmrc = _nodeFs.default.readFileSync(npmrc, 'utf8');
28
- const found = oldNpmrc.match(/_authToken=(.*)\n/);
29
- if (found) {
30
- oldToken = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
16
+ const fetchToken = filename => {
17
+ const results = {
18
+ filename,
19
+ exists: false,
20
+ token: 'none',
21
+ lastUpdated: -1
22
+ };
23
+ try {
24
+ if (_nodeFs.default.existsSync(filename)) {
25
+ results.exists = true;
26
+ const stat = _nodeFs.default.statSync(filename);
27
+ results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
28
+ // grab the current token for logging a redacted version
29
+ const currentNpmrc = _nodeFs.default.readFileSync(filename, 'utf8');
30
+ const found = currentNpmrc.match(/_authToken=(.*)\n/);
31
+ if (found) {
32
+ results.token = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
33
+ }
31
34
  }
35
+ } catch (statErr) {
36
+ log({
37
+ statErr
38
+ }, `<==fs.statSync failed on file ${filename}`);
32
39
  }
33
- } catch (statErr) {
34
- log({
35
- statErr
36
- }, `<==fs.statSync failed on file ${npmrc}`);
37
- }
38
- if (lastUpdated < refreshThreshold) {
40
+ return results;
41
+ };
42
+
43
+ // fetch the tokens - note the RO token is deprecated and may not exist
44
+ const npmrc = fetchToken(`${_nodeOs.default.homedir()}/.npmrc`);
45
+ const npmrcRo = fetchToken(`${_nodeOs.default.homedir()}/.npmrc.ro`);
46
+
47
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
48
+
49
+ if (npmrc.exists && npmrc.lastUpdated < refreshThreshold) {
39
50
  process.exit(0);
40
51
  }
41
52
 
@@ -58,7 +69,7 @@ try {
58
69
  _nodeFs.default.copyFileSync(npmrc, `${npmrc}-BAK`); // make a backup for safety
59
70
  }
60
71
 
61
- _nodeFs.default.writeFileSync(`${npmrc}`, npmrcSecret);
72
+ _nodeFs.default.writeFileSync(npmrc.filename, npmrcSecret);
62
73
  } catch (fileErr) {
63
74
  log(fileErr, 'fs failed');
64
75
  process.exit(1);
@@ -66,7 +77,8 @@ try {
66
77
  const now = new Date().toLocaleString();
67
78
  const slackURL = 'https://hooks.slack.com/services/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';
68
79
  const slackData = {
69
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
80
+ // eslint-disable-next-line max-len
81
+ text: `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
70
82
  channel: '#dev-ops-helm'
71
83
  };
72
84
  fetch(slackURL, {
@@ -75,4 +87,8 @@ fetch(slackURL, {
75
87
  headers: {
76
88
  'Content-Type': 'application/json'
77
89
  }
78
- }).catch(err => console.log(err));
90
+ }).catch(err => log(err));
91
+ if (npmrcRo.exists) {
92
+ log(_chalk.default.red('\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove'));
93
+ process.exit(1);
94
+ }
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable security/detect-non-literal-fs-filename */
2
3
  "use strict";
3
4
 
4
5
  var _nodeFs = _interopRequireDefault(require("node:fs"));
@@ -7,35 +8,45 @@ var _chalk = _interopRequireDefault(require("chalk"));
7
8
  var _execa = _interopRequireDefault(require("execa"));
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  // we can't use $ until we upgrade to ESM execa
10
- // the standard user npmrc token is stored here
11
- const npmrc = `${_nodeOs.default.homedir()}/.npmrc`;
12
-
13
11
  // max age in seconds of the npmrc file before refresh
14
12
  const refreshThreshold = 3600 * 24; // 1 day
15
13
 
14
+ // eslint-disable-next-line no-console
16
15
  const log = console.log;
17
-
18
- // calculate number of seconds since last update and exit if the file
19
- // was recently updated
20
- let lastUpdated = refreshThreshold * 2; // forces refresh if npmrc file does not exist
21
- let oldToken;
22
- try {
23
- if (_nodeFs.default.existsSync(npmrc)) {
24
- const stat = _nodeFs.default.statSync(npmrc);
25
- lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
26
- // grab the old token for logging a redacted version
27
- const oldNpmrc = _nodeFs.default.readFileSync(npmrc, 'utf8');
28
- const found = oldNpmrc.match(/_authToken=(.*)\n/);
29
- if (found) {
30
- oldToken = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
16
+ const fetchToken = filename => {
17
+ const results = {
18
+ filename,
19
+ exists: false,
20
+ token: 'none',
21
+ lastUpdated: -1
22
+ };
23
+ try {
24
+ if (_nodeFs.default.existsSync(filename)) {
25
+ results.exists = true;
26
+ const stat = _nodeFs.default.statSync(filename);
27
+ results.lastUpdated = Math.trunc((Date.now() - stat.mtimeMs) / 1000);
28
+ // grab the current token for logging a redacted version
29
+ const currentNpmrc = _nodeFs.default.readFileSync(filename, 'utf8');
30
+ const found = currentNpmrc.match(/_authToken=(.*)\n/);
31
+ if (found) {
32
+ results.token = `${found[1].slice(0, 8)}......${found[1].slice(-4)}`;
33
+ }
31
34
  }
35
+ } catch (statErr) {
36
+ log({
37
+ statErr
38
+ }, `<==fs.statSync failed on file ${filename}`);
32
39
  }
33
- } catch (statErr) {
34
- log({
35
- statErr
36
- }, `<==fs.statSync failed on file ${npmrc}`);
37
- }
38
- if (lastUpdated < refreshThreshold) {
40
+ return results;
41
+ };
42
+
43
+ // fetch the tokens - note the RO token is deprecated and may not exist
44
+ const npmrc = fetchToken(`${_nodeOs.default.homedir()}/.npmrc`);
45
+ const npmrcRo = fetchToken(`${_nodeOs.default.homedir()}/.npmrc.ro`);
46
+
47
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
48
+
49
+ if (npmrc.exists && npmrc.lastUpdated < refreshThreshold) {
39
50
  process.exit(0);
40
51
  }
41
52
 
@@ -58,7 +69,7 @@ try {
58
69
  _nodeFs.default.copyFileSync(npmrc, `${npmrc}-BAK`); // make a backup for safety
59
70
  }
60
71
 
61
- _nodeFs.default.writeFileSync(`${npmrc}`, npmrcSecret);
72
+ _nodeFs.default.writeFileSync(npmrc.filename, npmrcSecret);
62
73
  } catch (fileErr) {
63
74
  log(fileErr, 'fs failed');
64
75
  process.exit(1);
@@ -66,7 +77,8 @@ try {
66
77
  const now = new Date().toLocaleString();
67
78
  const slackURL = 'https://hooks.slack.com/services/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';
68
79
  const slackData = {
69
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
80
+ // eslint-disable-next-line max-len
81
+ text: `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
70
82
  channel: '#dev-ops-helm'
71
83
  };
72
84
  fetch(slackURL, {
@@ -75,4 +87,8 @@ fetch(slackURL, {
75
87
  headers: {
76
88
  'Content-Type': 'application/json'
77
89
  }
78
- }).catch(err => console.log(err));
90
+ }).catch(err => log(err));
91
+ if (npmrcRo.exists) {
92
+ log(_chalk.default.red('\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove'));
93
+ process.exit(1);
94
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.36.2",
3
+ "version": "2.37.1",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -1,37 +1,51 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable security/detect-non-literal-fs-filename */
2
3
  import fs from 'node:fs'
3
4
  import os from 'node:os'
4
5
 
5
6
  import chalk from 'chalk'
6
7
  import execa from 'execa' // we can't use $ until we upgrade to ESM execa
7
8
 
8
- // the standard user npmrc token is stored here
9
- const npmrc = `${os.homedir()}/.npmrc`
10
-
11
9
  // max age in seconds of the npmrc file before refresh
12
- const refreshThreshold = 3600 *24 // 1 day
10
+ const refreshThreshold = 3600 * 24 // 1 day
13
11
 
12
+ // eslint-disable-next-line no-console
14
13
  const log = console.log
15
14
 
16
- // calculate number of seconds since last update and exit if the file
17
- // was recently updated
18
- let lastUpdated = refreshThreshold * 2 // forces refresh if npmrc file does not exist
19
- let oldToken
20
- try {
21
- if ( fs.existsSync( npmrc ) ) {
22
- const stat = fs.statSync( npmrc )
23
- lastUpdated = Math.trunc( ( Date.now() - stat.mtimeMs ) / 1000 )
24
- // grab the old token for logging a redacted version
25
- const oldNpmrc = fs.readFileSync( npmrc, 'utf8' )
26
- const found = oldNpmrc.match( /_authToken=(.*)\n/ )
27
- if( found ) {
28
- oldToken = `${found[1].slice(0,8)}......${found[1].slice(-4)}`
15
+ const fetchToken = ( filename ) => {
16
+ const results = {
17
+ filename,
18
+ exists : false,
19
+ token : 'none',
20
+ lastUpdated : -1
21
+ }
22
+
23
+ try {
24
+ if ( fs.existsSync( filename ) ) {
25
+ results.exists = true
26
+ const stat = fs.statSync( filename )
27
+ results.lastUpdated = Math.trunc( ( Date.now() - stat.mtimeMs ) / 1000 )
28
+ // grab the current token for logging a redacted version
29
+ const currentNpmrc = fs.readFileSync( filename, 'utf8' )
30
+ const found = currentNpmrc.match( /_authToken=(.*)\n/ )
31
+ if ( found ) {
32
+ results.token = `${found[1].slice( 0, 8 )}......${found[1].slice( -4 )}`
33
+ }
29
34
  }
35
+ } catch ( statErr ) {
36
+ log( { statErr }, `<==fs.statSync failed on file ${filename}` )
30
37
  }
31
- } catch ( statErr ) {
32
- log( { statErr }, `<==fs.statSync failed on file ${npmrc}` )
38
+
39
+ return results
33
40
  }
34
- if ( lastUpdated < refreshThreshold ) { process.exit( 0 ) }
41
+
42
+ // fetch the tokens - note the RO token is deprecated and may not exist
43
+ const npmrc = fetchToken( `${os.homedir()}/.npmrc` )
44
+ const npmrcRo = fetchToken( `${os.homedir()}/.npmrc.ro` )
45
+
46
+ // log( { npmrc, npmrcRo }, '<==Your tokens be' )
47
+
48
+ if ( npmrc.exists && npmrc.lastUpdated < refreshThreshold ) { process.exit( 0 ) }
35
49
 
36
50
  // fetch the contents of the npmrc secret stored on leverege-registry
37
51
  let npmrcSecret
@@ -45,7 +59,7 @@ try {
45
59
  '--project=leverege-registry',
46
60
  ] )
47
61
  npmrcSecret = stdout
48
- } catch( err ) {
62
+ } catch ( err ) {
49
63
  log( chalk.yellow( `\nFailed Command => [${err.escapedCommand}]\n\n` ), chalk.red( err.stderr ) )
50
64
  process.exit( 1 )
51
65
  }
@@ -57,8 +71,8 @@ try {
57
71
  if ( fs.existsSync( npmrc ) ) {
58
72
  fs.copyFileSync( npmrc, `${npmrc}-BAK` ) // make a backup for safety
59
73
  }
60
- fs.writeFileSync( `${npmrc}`, npmrcSecret )
61
- } catch( fileErr ) {
74
+ fs.writeFileSync( npmrc.filename, npmrcSecret )
75
+ } catch ( fileErr ) {
62
76
  log( fileErr, 'fs failed' )
63
77
  process.exit( 1 )
64
78
  }
@@ -66,15 +80,21 @@ try {
66
80
  const now = ( new Date() ).toLocaleString()
67
81
  const slackURL = 'https://hooks.slack.com/services/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'
68
82
  const slackData = {
69
- text: `--- npmrc refreshed by \`${process.env['USER']}\` at ${now}\n token [\`${oldToken}\`]`,
70
- channel: '#dev-ops-helm',
83
+ // eslint-disable-next-line max-len
84
+ text : `--- npmrc refreshed by \`${process.env.USER}\` at ${now}\n tokens RW [\`${npmrc.token}\`] RO [\`${npmrcRo.token}\`]`,
85
+ channel : '#dev-ops-helm',
71
86
  }
72
87
 
73
88
  fetch( slackURL, {
74
- method: 'POST',
75
- body: JSON.stringify( slackData ),
76
- headers: {
77
- 'Content-Type': 'application/json',
89
+ method : 'POST',
90
+ body : JSON.stringify( slackData ),
91
+ headers : {
92
+ 'Content-Type' : 'application/json',
78
93
  },
79
94
  } )
80
- .catch( err => console.log( err ) )
95
+ .catch( err => log( err ) )
96
+
97
+ if ( npmrcRo.exists ) {
98
+ log( chalk.red( '\nWARNING - the need for the ~/.npmrc.ro file has been eliminated - please remove' ) )
99
+ process.exit( 1 )
100
+ }