@jayxuz/verdaccio-offline-storage 3.0.0 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayxuz/verdaccio-offline-storage",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Verdaccio storage plugin that treats local package cache as first class citizen for offline environments",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "node": ">=18.0.0"
40
40
  },
41
41
  "license": "MIT",
42
- "repository": "https://github.com/g3ngar/verdaccio-offline-storage",
43
- "author": "g3ngar <gengar@nauta.cu>",
44
- "homepage": "https://github.com/g3ngar/verdaccio-offline-storage"
42
+ "repository": "https://github.com/jayxuz/verdaccio-offline-sync/packages/verdaccio-offline-storage",
43
+ "author": "jayxuz",
44
+ "homepage": "https://github.com/jayxuz/verdaccio-offline-sync/packages/verdaccio-offline-storage"
45
45
  }
@@ -1,122 +0,0 @@
1
- import { readdir } from 'fs';
2
- import { basename } from 'path';
3
- import cmp from 'semver-compare';
4
- import LocalFS from '@verdaccio/local-storage/lib/local-fs';
5
-
6
- /**
7
- * `IPackageStorage` used internally for packages I/O operations.
8
- *
9
- * This works just like the `IPackageStorage` used by the local-storage plugin but modifying
10
- * the packages definition files (the local-storage `package.json` files) so only the locally
11
- * available versions appears in the definition. This does **NOT** modifies the original
12
- * `package.json` file stored in the local-storage cache, meaning that all the modifications are
13
- * done on the fly, on demand and in memory.
14
- *
15
- * @see https://verdaccio.org/docs/en/plugin-storage#api
16
- * @see https://github.com/verdaccio/monorepo/tree/master/plugins/local-storage
17
- */
18
- export default class OfflinePackageStorage extends LocalFS {
19
- constructor(path, logger, config) {
20
- super(path, logger);
21
- this.config = config;
22
- }
23
- /**
24
- * Computes a package's definition that only lists the locally available versions.
25
- *
26
- * @param {string} name Package name.
27
- * @param cb Callback to invoke with the computed definition.
28
- */
29
- readPackage(name, cb) {
30
- const packageAccess = this.config.getMatchedPackagesSpec(name);
31
- // It's offline if set explicitly in the config or if no proxy is defined for the package
32
- const offline = this.config.offline || !packageAccess.proxy || !packageAccess.proxy.length;
33
- if (!offline) {
34
- this.logger.trace(
35
- {
36
- packageName: name,
37
- },
38
- '[verdaccio-offline-storage/readPackage] Resolving package @{packageName} in online mode'
39
- );
40
- super.readPackage(name, cb);
41
- return;
42
- }
43
- this.logger.trace(
44
- {
45
- packageName: name,
46
- },
47
- '[verdaccio-offline-storage/readPackage] Resolving package @{packageName} in offline mode'
48
- );
49
- super.readPackage(name, (err, data) => {
50
- if (err) {
51
- cb(err);
52
- } else {
53
- this.logger.trace(
54
- {
55
- packageName: name,
56
- },
57
- '[verdaccio-offline-storage/readPackage] Discovering local versions for package: @{packageName}'
58
- );
59
- readdir(this.path, (err, items) => {
60
- if (err) {
61
- this.logger.trace(
62
- {
63
- err,
64
- packageName: name,
65
- },
66
- '[verdaccio-offline-storage/readPackage/readdir] Error discovering package "@{packageName}" files: @{err}'
67
- );
68
- cb(err);
69
- } else {
70
- const localVersions = items
71
- .filter(item => item.endsWith('.tgz'))
72
- .map(item => item.substring(basename(name).length + 1, item.length - 4));
73
- this.logger.trace(
74
- {
75
- packageName: name,
76
- count: localVersions.length,
77
- },
78
- '[verdaccio-offline-storage/readPackage/readdir] Discovered @{count} items for package: @{packageName}'
79
- );
80
- const allVersions = Object.keys(data.versions);
81
- const originalVersionCount = allVersions.length;
82
- this.logger.trace(
83
- {
84
- packageName: name,
85
- count: originalVersionCount,
86
- },
87
- '[verdaccio-offline-storage/readPackage/readdir] Analyzing @{count} declared versions for package: @{packageName}'
88
- );
89
- for (const version of allVersions) {
90
- if (!localVersions.includes(version)) {
91
- delete data.versions[version];
92
- this.logger.trace(
93
- {
94
- packageName: name,
95
- version,
96
- },
97
- '[verdaccio-offline-storage/readPackage/readdir] Removed @{packageName}@@{version}'
98
- );
99
- }
100
- }
101
- this.logger.trace(
102
- {
103
- packageName: name,
104
- count: originalVersionCount - Object.keys(data.versions).length,
105
- },
106
- '[verdaccio-offline-storage/readPackage/readdir] Removed @{count} versions for package: @{packageName}'
107
- );
108
- data['dist-tags'].latest = Object.keys(data.versions).sort((a, b) => cmp(b, a))[0];
109
- this.logger.trace(
110
- {
111
- packageName: name,
112
- latest: data['dist-tags'].latest,
113
- },
114
- '[verdaccio-offline-storage/readPackage/readdir] Set latest version to @{latest} for package: @{packageName}'
115
- );
116
- cb(null, data);
117
- }
118
- });
119
- }
120
- });
121
- }
122
- }
@@ -1,102 +0,0 @@
1
- import { join } from 'path';
2
- import { readdir } from 'fs';
3
- import LocalDatabase from '@verdaccio/local-storage';
4
- import OfflinePackageStorage from './OfflinePackageStorage';
5
-
6
- /**
7
- * Verdaccio storage plugin (`IPluginStorage`) that provides only the locally available versions of
8
- * packages cached in a local-storage storage.
9
- *
10
- * Basically, this is just like local-storage but modifying on the fly the available packages list
11
- * and the packages definitions without altering the original files in the local-storage storage.
12
- *
13
- * @see https://verdaccio.org/docs/en/plugin-storage
14
- * @see https://github.com/verdaccio/monorepo/tree/master/plugins/local-storage
15
- */
16
- export default class OfflineStoragePlugin extends LocalDatabase {
17
- constructor(config, options) {
18
- super(config, options.logger);
19
- // eslint-disable-next-line no-console
20
- if (config.offline) {
21
- options.logger.warn({}, 'Offline mode set explicitly in config. All packages will be resolved in offline mode.');
22
- } else {
23
- options.logger.warn(
24
- {},
25
- 'Offline mode NOT set explicitly in config. Only packages with no `proxy` will be resolved in offline mode.'
26
- );
27
- }
28
- }
29
-
30
- /**
31
- * Retrieves all the locally available packages names. Packages with no cached versions (only
32
- * `package.json` file in the directory) are ignored.
33
- *
34
- * @param callback: The callback to invoke with the found packages names.
35
- * @see https://verdaccio.org/docs/en/plugin-storage#api
36
- */
37
- get(callback) {
38
- const packages = [];
39
- this.search(
40
- (item, cb) => {
41
- this.logger.debug(
42
- {
43
- packageName: item.name,
44
- },
45
- '[verdaccio-offline-storage/get/search] discovering local versions for package: @{packageName}'
46
- );
47
- readdir(item.path, (err, items) => {
48
- if (err) {
49
- this.logger.trace(
50
- {
51
- err,
52
- packageName: item.name,
53
- },
54
- '[verdaccio-offline-storage/get/search/readdir] error discovering package "@{packageName}" files: @{err}'
55
- );
56
- cb(err);
57
- } else {
58
- if (items.find(item => item.endsWith('.tgz'))) {
59
- packages.push(item.name);
60
- this.logger.trace(
61
- {
62
- packageName: item.name,
63
- },
64
- '[verdaccio-offline-storage/get/search/readdir] found locally available package: "@{packageName}"'
65
- );
66
- } else {
67
- this.logger.trace(
68
- {
69
- packageName: item.name,
70
- },
71
- '[verdaccio-offline-storage/get/search/readdir] no locally available version found for package: "@{packageName}"'
72
- );
73
- }
74
- cb();
75
- }
76
- });
77
- },
78
- () => {
79
- this.data.list = packages;
80
- callback(null, packages);
81
- this.logger.trace(
82
- {
83
- totalItems: packages.length,
84
- },
85
- 'verdaccio-offline-storage: [get] full list of packages (@{totalItems}) has been fetched'
86
- );
87
- },
88
- name => !name.startsWith('.') // so `.{sinopia|verdaccio}-db.json` gets ignored
89
- );
90
- }
91
-
92
- /**
93
- * Returns the `IPackageStorage` used internally for packages I/O operations.
94
- *
95
- * @param {string} packageName Package name.
96
- * @return {OfflinePackageStorage}
97
- * @see https://verdaccio.org/docs/en/plugin-storage#api
98
- */
99
- getPackageStorage(packageName) {
100
- return new OfflinePackageStorage(join(this.config.storage, packageName), this.logger, this.config);
101
- }
102
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * The verdaccio-offline-storage plugin entry point.
3
- */
4
- export { default } from './OfflineStoragePlugin';