@juit/check-updates 2.0.6 → 3.0.0

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.
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // versions.ts
31
+ var versions_exports = {};
32
+ __export(versions_exports, {
33
+ VersionsCache: () => VersionsCache
34
+ });
35
+ module.exports = __toCommonJS(versions_exports);
36
+ var import_npm_registry_fetch = __toESM(require("npm-registry-fetch"), 1);
37
+ var import_semver = __toESM(require("semver"), 1);
38
+ var import_debug = require("./debug.cjs");
39
+ var VersionsCache = class {
40
+ _cache;
41
+ _debug;
42
+ constructor(debug = false) {
43
+ this._debug = (0, import_debug.makeDebug)(debug);
44
+ this._cache = {};
45
+ }
46
+ /** Return the available versions for a package, sorted */
47
+ getVersions(name, npmrc) {
48
+ if (this._cache[name]) {
49
+ this._debug(`Returning cached versions for ${import_debug.Y}${name}${import_debug.X}`);
50
+ return this._cache[name];
51
+ }
52
+ this._debug(`Retrieving versions for package ${import_debug.Y}${name}${import_debug.X}`);
53
+ const range = new import_semver.default.Range(">=0.0.0", { includePrerelease: false });
54
+ const promise = import_npm_registry_fetch.default.json(name, Object.assign({}, npmrc, { spec: name })).then((data) => {
55
+ return Object.entries(data.versions).filter(([, info]) => !info.deprecated).map(([version]) => version).filter((version) => range.test(version)).sort(import_semver.default.rcompare);
56
+ });
57
+ this._cache[name] = promise;
58
+ return promise;
59
+ }
60
+ };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ VersionsCache
64
+ });
65
+ //# sourceMappingURL=versions.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/versions.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAkB;AAClB,oBAAmB;AAEnB,mBAAgC;AAGzB,IAAM,gBAAN,MAAoB;AAAA,EACjB;AAAA,EACA;AAAA,EAER,YAAY,QAAiB,OAAO;AAClC,SAAK,aAAS,wBAAU,KAAK;AAC7B,SAAK,SAAS,CAAC;AAAA,EACjB;AAAA;AAAA,EAGA,YACI,MACA,OACiB;AACnB,QAAI,KAAK,OAAO,IAAI,GAAG;AACrB,WAAK,OAAO,iCAAiC,cAAC,GAAG,IAAI,GAAG,cAAC,EAAE;AAC3D,aAAO,KAAK,OAAO,IAAI;AAAA,IACzB;AAEA,SAAK,OAAO,mCAAmC,cAAC,GAAG,IAAI,GAAG,cAAC,EAAE;AAE7D,UAAM,QAAQ,IAAI,cAAAA,QAAO,MAAM,WAAW,EAAE,mBAAmB,MAAM,CAAC;AAItE,UAAM,UAAU,0BAAAC,QAAM,KAAK,MAAM,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,MAAM,KAAK,CAAC,CAAC,EACpE,KAAK,CAAC,SAAc;AACnB,aAAO,OAAO,QAAQ,KAAK,QAA+C,EACrE,OAAO,CAAC,CAAE,EAAE,IAAK,MAAM,CAAE,KAAK,UAAU,EACxC,IAAI,CAAC,CAAE,OAAQ,MAAM,OAAO,EAC5B,OAAO,CAAC,YAAY,MAAM,KAAK,OAAO,CAAC,EACvC,KAAK,cAAAD,QAAO,QAAQ;AAAA,IAC3B,CAAC;AACL,SAAK,OAAO,IAAI,IAAI;AACpB,WAAO;AAAA,EACT;AACF;",
5
+ "names": ["semver", "fetch"]
6
+ }
@@ -0,0 +1,8 @@
1
+ /** Cache of versions */
2
+ export declare class VersionsCache {
3
+ private _cache;
4
+ private _debug;
5
+ constructor(debug?: boolean);
6
+ /** Return the available versions for a package, sorted */
7
+ getVersions(name: string, npmrc: Record<string, any>): Promise<string[]>;
8
+ }
@@ -0,0 +1,30 @@
1
+ // versions.ts
2
+ import fetch from "npm-registry-fetch";
3
+ import semver from "semver";
4
+ import { X, Y, makeDebug } from "./debug.mjs";
5
+ var VersionsCache = class {
6
+ _cache;
7
+ _debug;
8
+ constructor(debug = false) {
9
+ this._debug = makeDebug(debug);
10
+ this._cache = {};
11
+ }
12
+ /** Return the available versions for a package, sorted */
13
+ getVersions(name, npmrc) {
14
+ if (this._cache[name]) {
15
+ this._debug(`Returning cached versions for ${Y}${name}${X}`);
16
+ return this._cache[name];
17
+ }
18
+ this._debug(`Retrieving versions for package ${Y}${name}${X}`);
19
+ const range = new semver.Range(">=0.0.0", { includePrerelease: false });
20
+ const promise = fetch.json(name, Object.assign({}, npmrc, { spec: name })).then((data) => {
21
+ return Object.entries(data.versions).filter(([, info]) => !info.deprecated).map(([version]) => version).filter((version) => range.test(version)).sort(semver.rcompare);
22
+ });
23
+ this._cache[name] = promise;
24
+ return promise;
25
+ }
26
+ };
27
+ export {
28
+ VersionsCache
29
+ };
30
+ //# sourceMappingURL=versions.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/versions.ts"],
4
+ "mappings": ";AAAA,OAAO,WAAW;AAClB,OAAO,YAAY;AAEnB,SAAS,GAAG,GAAG,iBAAiB;AAGzB,IAAM,gBAAN,MAAoB;AAAA,EACjB;AAAA,EACA;AAAA,EAER,YAAY,QAAiB,OAAO;AAClC,SAAK,SAAS,UAAU,KAAK;AAC7B,SAAK,SAAS,CAAC;AAAA,EACjB;AAAA;AAAA,EAGA,YACI,MACA,OACiB;AACnB,QAAI,KAAK,OAAO,IAAI,GAAG;AACrB,WAAK,OAAO,iCAAiC,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE;AAC3D,aAAO,KAAK,OAAO,IAAI;AAAA,IACzB;AAEA,SAAK,OAAO,mCAAmC,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE;AAE7D,UAAM,QAAQ,IAAI,OAAO,MAAM,WAAW,EAAE,mBAAmB,MAAM,CAAC;AAItE,UAAM,UAAU,MAAM,KAAK,MAAM,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,MAAM,KAAK,CAAC,CAAC,EACpE,KAAK,CAAC,SAAc;AACnB,aAAO,OAAO,QAAQ,KAAK,QAA+C,EACrE,OAAO,CAAC,CAAE,EAAE,IAAK,MAAM,CAAE,KAAK,UAAU,EACxC,IAAI,CAAC,CAAE,OAAQ,MAAM,OAAO,EAC5B,OAAO,CAAC,YAAY,MAAM,KAAK,OAAO,CAAC,EACvC,KAAK,OAAO,QAAQ;AAAA,IAC3B,CAAC;AACL,SAAK,OAAO,IAAI,IAAI;AACpB,WAAO;AAAA,EACT;AACF;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,12 +1,27 @@
1
1
  {
2
2
  "name": "@juit/check-updates",
3
- "version": "2.0.6",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "description": "Small and fast utility to update package dependencies",
6
6
  "author": "Team Juit <developers@juit.com>",
7
7
  "license": "Apache-2.0",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "require": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.cjs"
16
+ },
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.mjs"
20
+ }
21
+ }
22
+ },
8
23
  "bin": {
9
- "check-updates": "check-updates.js"
24
+ "check-updates": "./dist/main.mjs"
10
25
  },
11
26
  "scripts": {
12
27
  "build": "plug",
@@ -17,19 +32,17 @@
17
32
  "transpile": "plug transpile"
18
33
  },
19
34
  "dependencies": {
20
- "glob": "^10.3.4",
21
35
  "ini": "^4.1.1",
22
36
  "npm-registry-fetch": "^16.0.0",
23
37
  "semver": "^7.5.4",
24
- "yargs": "^17.7.2"
38
+ "yargs-parser": "^21.1.1"
25
39
  },
26
40
  "devDependencies": {
27
- "@plugjs/build": "^0.4.34",
28
- "@types/glob": "^8.1.0",
41
+ "@plugjs/build": "^0.5.4",
29
42
  "@types/ini": "^1.3.31",
30
- "@types/npm-registry-fetch": "^8.0.4",
31
- "@types/semver": "^7.5.1",
32
- "@types/yargs": "^17.0.24"
43
+ "@types/npm-registry-fetch": "^8.0.5",
44
+ "@types/semver": "^7.5.2",
45
+ "@types/yargs-parser": "^21.0.1"
33
46
  },
34
47
  "repository": {
35
48
  "type": "git",
@@ -41,7 +54,7 @@
41
54
  "homepage": "https://github.com/juitnow/juit-check-updates#readme",
42
55
  "files": [
43
56
  "*.md",
44
- "check-updates.js",
57
+ "dist/",
45
58
  "src/"
46
59
  ],
47
60
  "directories": {
package/src/debug.ts ADDED
@@ -0,0 +1,14 @@
1
+ /** Our colors */
2
+ export const X = '\u001b[0m'
3
+ export const R = '\u001b[38;5;203m'
4
+ export const G = '\u001b[38;5;76m'
5
+ export const Y = '\u001b[38;5;220m'
6
+ export const B = '\u001b[38;5;69m'
7
+ export const K = '\u001b[38;5;240m'
8
+
9
+ /* Create our debug function */
10
+ export function makeDebug(debug?: boolean): (...args: any[]) => void {
11
+ return debug ?
12
+ (...args: any[]) => void (args.length && console.log(`${K}[DEBUG]${X}`, ...args)) :
13
+ () => void 0
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type { UpdaterOptions } from './updater'
2
+
3
+ export { readNpmRc } from './npmrc'
4
+ export { Updater } from './updater'
5
+ export { VersionsCache } from './versions'
package/src/main.mts ADDED
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync } from 'node:fs'
4
+ import { resolve } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+
7
+ import yargsParser from 'yargs-parser'
8
+
9
+ import { B, G, K, R, X, Y, makeDebug } from './debug'
10
+ import { Updater } from './updater'
11
+ import { VersionsCache } from './versions'
12
+
13
+ import type { UpdaterOptions } from './updater'
14
+
15
+ type ReleaseType = undefined | 'major' | 'minor' | 'patch'
16
+ function releaseType(releaseType: unknown): ReleaseType {
17
+ if (releaseType === undefined) return
18
+ if (releaseType === '') return 'patch'
19
+ if (releaseType === 'major') return 'major'
20
+ if (releaseType === 'minor') return 'minor'
21
+ if (releaseType === 'patch') return 'patch'
22
+ console.log(`Invalid flag for --bump: "${releaseType}"`)
23
+ process.exit(1)
24
+ }
25
+
26
+ /* ========================================================================== *
27
+ * CALL UP MAIN() AND DEAL WITH THE ASYNC PROMISE IT RETURNS *
28
+ * ========================================================================== */
29
+
30
+ function showVersion(): never {
31
+ const path = fileURLToPath(import.meta.url)
32
+ const file = resolve(path, '..', '..', 'package.json')
33
+ const data = readFileSync(file, 'utf-8')
34
+ const json = JSON.parse(data)
35
+ console.log(`v${json.version}`)
36
+ process.exit(1)
37
+ }
38
+
39
+ function showHelp(): never {
40
+ console.log(`
41
+ ${Y}Usage${X}:
42
+ ${G}check-updates${X} [--options ...] [package.json ...]
43
+
44
+ ${Y}Options${X}:
45
+ ${G}-h${X}, ${G}--help${X} Show this help.
46
+
47
+ ${G}-v${X}, ${G}--version${X} Show the version and exit.
48
+
49
+ ${G}-b${X}, ${G}--bump${X} Bump the version of the package file when changes in the
50
+ dependencies are found. Specifiy either "${B}major${X}", "${B}minor${X}"
51
+ or "${B}patch${X}" ${K}(default)${X} to indicate which version to bump.
52
+
53
+ ${G}-s${X}, ${G}--strict${X} Strictly adhere to semver rules for tilde ${K}(~x.y.z)${X} and
54
+ caret ${K}(^x.y.z)${X} dependency ranges.
55
+
56
+ ${G}-q${X}, ${G}--quick${X} Consider dev/peer/optional dependency updates if and only
57
+ if the main depenencies also had updates.
58
+
59
+ ${G}-d${X}, ${G}--debug${X} Output debugging informations.
60
+
61
+ ${G}-x${X}, ${G}--dry-run${X} Do not write package changes.
62
+
63
+ ${G}--no-errors${X} Exit with ${B}0${X} in case of no updates. Normally the updater
64
+ will exit with ${B}255${X} in this case.
65
+
66
+ ${G}--no-workspaces${X} Do not process workspaces.
67
+
68
+ ${G}--no-align${X} Do not align workspaces versions. By default all versions
69
+ will be set to the highest one amongst all workspaces
70
+ after bumping.
71
+
72
+ ${Y}Remarks${X}:
73
+ Multiple ${B}package.json${X} files can be specified on the command line. In case no
74
+ files are specified, the default is to process the ${B}package.json${X} file in the
75
+ current directory.
76
+ `)
77
+ process.exit(1)
78
+ }
79
+
80
+ /* Parse command line arguments */
81
+ const { _: args, ...opts } = yargsParser(process.argv.slice(2), {
82
+ configuration: {
83
+ 'camel-case-expansion': false,
84
+ 'strip-aliased': true,
85
+ 'strip-dashed': true,
86
+ },
87
+ alias: {
88
+ 'bump': [ 'b' ],
89
+ 'debug': [ 'd' ],
90
+ 'dry-run': [ 'x' ],
91
+ 'help': [ 'h' ],
92
+ 'quick': [ 'q' ],
93
+ 'strict': [ 's' ],
94
+ 'version': [ 'v' ],
95
+ },
96
+ string: [ 'bump' ],
97
+ boolean: [
98
+ 'align',
99
+ 'debug',
100
+ 'dry-run',
101
+ 'help',
102
+ 'errors',
103
+ 'quick',
104
+ 'strict',
105
+ 'version',
106
+ 'workspaces',
107
+ ],
108
+ })
109
+
110
+ /* Preliminiary stuff before checking options */
111
+ makeDebug(opts.debug)('Options:', { args, ...opts })
112
+ if (opts.version) showVersion()
113
+ if (opts.help) showHelp()
114
+
115
+ /* Defaults */
116
+ let align = true
117
+ let dryRun = false
118
+ let errors = true
119
+ const options: UpdaterOptions = {
120
+ bump: undefined,
121
+ debug: false,
122
+ quick: false,
123
+ strict: false,
124
+ workspaces: true,
125
+ }
126
+
127
+ /* Process each option, one by one */
128
+ for (const [ key, value ] of Object.entries(opts)) {
129
+ switch (key) {
130
+ case 'align': align = !! value; break
131
+ case 'bump': options.bump = releaseType(value); break
132
+ case 'debug': options.debug = !! value; break
133
+ case 'dry-run': dryRun = !! value; break
134
+ case 'errors': errors = !! value; break
135
+ case 'quick': options.quick = !! value; break
136
+ case 'strict': options.strict = !! value; break
137
+ case 'workspaces': options.workspaces = !! value; break
138
+ default:
139
+ console.log(`${R}[ERROR]${X} Unsupported / unknown option: --${key}\n`)
140
+ showHelp()
141
+ }
142
+ }
143
+
144
+ /* Normalize arguments and default to package.json in the current directory */
145
+ const files = args.map((arg) => arg.toString())
146
+ if (! files.length) files.push('package.json')
147
+
148
+ /* Process packages, one by one */
149
+ try {
150
+ const cache = new VersionsCache()
151
+
152
+ let changed = false
153
+ for (const file of files) {
154
+ const updater = await new Updater(file, options, cache).init()
155
+ await updater.update()
156
+ if (align) await updater.align()
157
+ if (! dryRun) await updater.write()
158
+ changed ||= updater.changed
159
+ }
160
+
161
+ process.exitCode = changed ? 0 : errors ? -1 : 0
162
+ } catch (error) {
163
+ console.error(error)
164
+ process.exitCode = 1
165
+ }
package/src/npmrc.ts CHANGED
@@ -9,7 +9,7 @@ function replaceEnvironmentVariable(token: string): string {
9
9
  })
10
10
  }
11
11
 
12
- async function readFile(filename: string): Promise<Record<string, any>> {
12
+ async function readIniFile(filename: string): Promise<Record<string, any>> {
13
13
  try {
14
14
  const data = await fs.readFile(filename, 'utf8')
15
15
  const npmrc = parse(data)
@@ -28,12 +28,12 @@ async function readFile(filename: string): Promise<Record<string, any>> {
28
28
  }
29
29
 
30
30
  export async function readNpmRc(packageJsonFile: string): Promise<Record<string, any>> {
31
- const local = readFile(path.resolve(packageJsonFile, '..', '.npmrc'))
32
- const user = readFile(
31
+ const local = readIniFile(path.resolve(packageJsonFile, '..', '.npmrc'))
32
+ const user = readIniFile(
33
33
  process.env.NPM_CONFIG_USERCONFIG ?
34
34
  process.env.NPM_CONFIG_USERCONFIG :
35
35
  process.env.HOME ? path.resolve(process.env.HOME, '.npmrc') : '' )
36
- const global = readFile(
36
+ const global = readIniFile(
37
37
  process.env.NPM_CONFIG_GLOBALCONFIG ?
38
38
  process.env.NPM_CONFIG_GLOBALCONFIG :
39
39
  '/etc/npmrc')