@eik/core 1.2.26 → 1.3.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.
- package/CHANGELOG.md +28 -0
- package/lib/classes/alias.js +2 -3
- package/lib/classes/asset.js +4 -5
- package/lib/classes/author.js +2 -3
- package/lib/classes/http-incoming.js +2 -3
- package/lib/classes/http-outgoing.js +2 -4
- package/lib/classes/meta.js +2 -3
- package/lib/classes/package.js +4 -6
- package/lib/classes/versions.js +2 -4
- package/lib/handlers/alias.delete.js +12 -14
- package/lib/handlers/alias.get.js +15 -17
- package/lib/handlers/alias.post.js +19 -21
- package/lib/handlers/alias.put.js +19 -21
- package/lib/handlers/auth.post.js +10 -12
- package/lib/handlers/map.get.js +12 -14
- package/lib/handlers/map.put.js +26 -28
- package/lib/handlers/pkg.get.js +15 -17
- package/lib/handlers/pkg.log.js +12 -14
- package/lib/handlers/pkg.put.js +22 -25
- package/lib/handlers/versions.get.js +11 -13
- package/lib/main.js +25 -22
- package/lib/multipart/form-field.js +1 -3
- package/lib/multipart/form-file.js +1 -3
- package/lib/multipart/parser.js +14 -16
- package/lib/sinks/fs.js +10 -12
- package/lib/sinks/mem-entry.js +3 -4
- package/lib/sinks/mem.js +7 -9
- package/lib/sinks/test.js +9 -10
- package/lib/utils/defaults.js +4 -5
- package/lib/utils/globals.js +1 -3
- package/lib/utils/healthcheck.js +8 -12
- package/lib/utils/path-builders-fs.js +17 -15
- package/lib/utils/path-builders-uri.js +14 -14
- package/lib/utils/utils.js +9 -9
- package/package.json +13 -15
package/lib/handlers/pkg.log.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { validators } from '@eik/common';
|
|
2
|
+
import originalUrl from 'original-url';
|
|
3
|
+
import HttpError from 'http-errors';
|
|
4
|
+
import abslog from 'abslog';
|
|
5
|
+
import Metrics from '@metrics/client';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Metrics = require('@metrics/client');
|
|
8
|
-
|
|
9
|
-
const { createFilePathToPackage } = require('../utils/path-builders-fs');
|
|
10
|
-
const HttpOutgoing = require('../classes/http-outgoing');
|
|
11
|
-
const config = require('../utils/defaults');
|
|
12
|
-
const utils = require('../utils/utils');
|
|
7
|
+
import { createFilePathToPackage } from '../utils/path-builders-fs.js';
|
|
8
|
+
import { decodeUriComponent } from '../utils/utils.js';
|
|
9
|
+
import HttpOutgoing from '../classes/http-outgoing.js';
|
|
10
|
+
import config from '../utils/defaults.js';
|
|
13
11
|
|
|
14
12
|
const PkgLog = class PkgLog {
|
|
15
13
|
constructor({
|
|
@@ -54,8 +52,8 @@ const PkgLog = class PkgLog {
|
|
|
54
52
|
async handler(req, type, name, version) {
|
|
55
53
|
const end = this._histogram.timer();
|
|
56
54
|
|
|
57
|
-
const pVersion =
|
|
58
|
-
const pName =
|
|
55
|
+
const pVersion = decodeUriComponent(version);
|
|
56
|
+
const pName = decodeUriComponent(name);
|
|
59
57
|
|
|
60
58
|
try {
|
|
61
59
|
validators.version(pVersion);
|
|
@@ -114,4 +112,4 @@ const PkgLog = class PkgLog {
|
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
114
|
};
|
|
117
|
-
|
|
115
|
+
export default PkgLog;
|
package/lib/handlers/pkg.put.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { validators } from '@eik/common';
|
|
2
|
+
import originalUrl from 'original-url';
|
|
3
|
+
import HttpError from 'http-errors';
|
|
4
|
+
import Metrics from '@metrics/client';
|
|
5
|
+
import abslog from 'abslog';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const originalUrl = require('original-url');
|
|
5
|
-
const HttpError = require('http-errors');
|
|
6
|
-
const Metrics = require('@metrics/client');
|
|
7
|
-
const abslog = require('abslog');
|
|
8
|
-
|
|
9
|
-
const {
|
|
7
|
+
import {
|
|
10
8
|
createFilePathToPackage,
|
|
11
9
|
createFilePathToVersion,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const MultipartParser = require('../multipart/parser');
|
|
10
|
+
} from '../utils/path-builders-fs.js';
|
|
11
|
+
import { decodeUriComponent, writeJSON, readJSON } from '../utils/utils.js';
|
|
12
|
+
import { createURIPathToPkgLog } from '../utils/path-builders-uri.js';
|
|
13
|
+
import MultipartParser from '../multipart/parser.js';
|
|
14
|
+
import HttpIncoming from '../classes/http-incoming.js';
|
|
15
|
+
import HttpOutgoing from '../classes/http-outgoing.js';
|
|
16
|
+
import Versions from '../classes/versions.js';
|
|
17
|
+
import Package from '../classes/package.js';
|
|
18
|
+
import Author from '../classes/author.js';
|
|
19
|
+
import config from '../utils/defaults.js';
|
|
23
20
|
|
|
24
21
|
const PkgPut = class PkgPut {
|
|
25
22
|
constructor({
|
|
@@ -84,7 +81,7 @@ const PkgPut = class PkgPut {
|
|
|
84
81
|
return pkg;
|
|
85
82
|
}).then(async (pkg) => {
|
|
86
83
|
const path = createFilePathToPackage(pkg);
|
|
87
|
-
await
|
|
84
|
+
await writeJSON(
|
|
88
85
|
this._sink,
|
|
89
86
|
path,
|
|
90
87
|
pkg,
|
|
@@ -106,7 +103,7 @@ const PkgPut = class PkgPut {
|
|
|
106
103
|
const path = createFilePathToVersion(incoming);
|
|
107
104
|
let versions;
|
|
108
105
|
try {
|
|
109
|
-
const obj = await
|
|
106
|
+
const obj = await readJSON(this._sink, path);
|
|
110
107
|
versions = new Versions(obj);
|
|
111
108
|
this._log.info(
|
|
112
109
|
`pkg:put - Successfully read version meta file from sink - Pathname: ${path}`,
|
|
@@ -123,7 +120,7 @@ const PkgPut = class PkgPut {
|
|
|
123
120
|
|
|
124
121
|
async _writeVersions(incoming, versions) {
|
|
125
122
|
const path = createFilePathToVersion(incoming);
|
|
126
|
-
await
|
|
123
|
+
await writeJSON(this._sink, path, versions, 'application/json');
|
|
127
124
|
this._log.info(
|
|
128
125
|
`pkg:put - Successfully wrote version meta file to sink - Pathname: ${path}`,
|
|
129
126
|
);
|
|
@@ -132,8 +129,8 @@ const PkgPut = class PkgPut {
|
|
|
132
129
|
async handler(req, user, type, name, version) {
|
|
133
130
|
const end = this._histogram.timer();
|
|
134
131
|
|
|
135
|
-
const pVersion =
|
|
136
|
-
const pName =
|
|
132
|
+
const pVersion = decodeUriComponent(version);
|
|
133
|
+
const pName = decodeUriComponent(name);
|
|
137
134
|
|
|
138
135
|
try {
|
|
139
136
|
validators.version(pVersion);
|
|
@@ -198,4 +195,4 @@ const PkgPut = class PkgPut {
|
|
|
198
195
|
return outgoing;
|
|
199
196
|
}
|
|
200
197
|
};
|
|
201
|
-
|
|
198
|
+
export default PkgPut;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { validators } from '@eik/common';
|
|
2
|
+
import originalUrl from 'original-url';
|
|
3
|
+
import HttpError from 'http-errors';
|
|
4
|
+
import Metrics from '@metrics/client';
|
|
5
|
+
import abslog from 'abslog';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const abslog = require('abslog');
|
|
8
|
-
|
|
9
|
-
const { createFilePathToVersion } = require('../utils/path-builders-fs');
|
|
10
|
-
const HttpOutgoing = require('../classes/http-outgoing');
|
|
11
|
-
const config = require('../utils/defaults');
|
|
12
|
-
const utils = require('../utils/utils');
|
|
7
|
+
import { createFilePathToVersion } from '../utils/path-builders-fs.js';
|
|
8
|
+
import { decodeUriComponent } from '../utils/utils.js';
|
|
9
|
+
import HttpOutgoing from '../classes/http-outgoing.js';
|
|
10
|
+
import config from '../utils/defaults.js';
|
|
13
11
|
|
|
14
12
|
const VersionsGet = class VersionsGet {
|
|
15
13
|
constructor({
|
|
@@ -55,7 +53,7 @@ const VersionsGet = class VersionsGet {
|
|
|
55
53
|
async handler(req, type, name) {
|
|
56
54
|
const end = this._histogram.timer();
|
|
57
55
|
|
|
58
|
-
const pName =
|
|
56
|
+
const pName = decodeUriComponent(name);
|
|
59
57
|
|
|
60
58
|
try {
|
|
61
59
|
validators.name(pName);
|
|
@@ -118,4 +116,4 @@ const VersionsGet = class VersionsGet {
|
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
};
|
|
121
|
-
|
|
119
|
+
export default VersionsGet;
|
package/lib/main.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import VersionsGet from './handlers/versions.get.js';
|
|
2
|
+
import AliasPost from './handlers/alias.post.js';
|
|
3
|
+
import AliasPut from './handlers/alias.put.js';
|
|
4
|
+
import AliasGet from './handlers/alias.get.js';
|
|
5
|
+
import AliasDel from './handlers/alias.delete.js';
|
|
6
|
+
import AuthPost from './handlers/auth.post.js';
|
|
7
|
+
import PkgLog from './handlers/pkg.log.js';
|
|
8
|
+
import PkgGet from './handlers/pkg.get.js';
|
|
9
|
+
import PkgPut from './handlers/pkg.put.js';
|
|
10
|
+
import MapGet from './handlers/map.get.js';
|
|
11
|
+
import MapPut from './handlers/map.put.js';
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const AliasPut = require('./handlers/alias.put');
|
|
6
|
-
const AliasGet = require('./handlers/alias.get');
|
|
7
|
-
const AliasDel = require('./handlers/alias.delete');
|
|
8
|
-
const AuthPost = require('./handlers/auth.post');
|
|
9
|
-
const PkgLog = require('./handlers/pkg.log');
|
|
10
|
-
const PkgGet = require('./handlers/pkg.get');
|
|
11
|
-
const PkgPut = require('./handlers/pkg.put');
|
|
12
|
-
const MapGet = require('./handlers/map.get');
|
|
13
|
-
const MapPut = require('./handlers/map.put');
|
|
13
|
+
import MEM from './sinks/mem.js';
|
|
14
|
+
import FS from './sinks/fs.js';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
import HealthCheck from './utils/healthcheck.js';
|
|
17
|
+
import globals from './utils/globals.js';
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
const globals = require('./utils/globals');
|
|
20
|
-
|
|
21
|
-
module.exports.HealthCheck = HealthCheck;
|
|
22
|
-
|
|
23
|
-
module.exports.http = {
|
|
19
|
+
const http = {
|
|
24
20
|
VersionsGet,
|
|
25
21
|
AliasPost,
|
|
26
22
|
AliasPut,
|
|
@@ -34,14 +30,21 @@ module.exports.http = {
|
|
|
34
30
|
MapPut,
|
|
35
31
|
};
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
const sink = {
|
|
38
34
|
MEM,
|
|
39
35
|
FS,
|
|
40
36
|
};
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
const prop = {
|
|
43
39
|
base_auth: globals.BASE_AUTHENTICATION,
|
|
44
40
|
base_map: globals.BASE_IMPORT_MAPS,
|
|
45
41
|
base_pkg: globals.BASE_PACKAGES,
|
|
46
42
|
base_npm: globals.BASE_NPM,
|
|
47
43
|
};
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
HealthCheck,
|
|
47
|
+
http,
|
|
48
|
+
sink,
|
|
49
|
+
prop,
|
|
50
|
+
}
|
package/lib/multipart/parser.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const FormFile = require('./form-file');
|
|
13
|
-
const Asset = require('../classes/asset');
|
|
1
|
+
import { pipeline } from 'node:stream';
|
|
2
|
+
import HttpError from 'http-errors';
|
|
3
|
+
import Busboy from 'busboy';
|
|
4
|
+
import abslog from 'abslog';
|
|
5
|
+
import ssri from 'ssri';
|
|
6
|
+
import tar from 'tar';
|
|
7
|
+
|
|
8
|
+
import { createFilePathToAsset } from '../utils/path-builders-fs.js';
|
|
9
|
+
import FormField from './form-field.js';
|
|
10
|
+
import FormFile from './form-file.js';
|
|
11
|
+
import Asset from '../classes/asset.js';
|
|
14
12
|
|
|
15
13
|
const MultipartParser = class MultipartParser {
|
|
16
14
|
constructor({
|
|
@@ -35,7 +33,7 @@ const MultipartParser = class MultipartParser {
|
|
|
35
33
|
return new Promise((resolve, reject) => {
|
|
36
34
|
const queue = [];
|
|
37
35
|
|
|
38
|
-
const busboy =
|
|
36
|
+
const busboy = Busboy({
|
|
39
37
|
headers: incoming.headers,
|
|
40
38
|
limits: {
|
|
41
39
|
fileSize: this._pkgMaxFileSize,
|
|
@@ -82,7 +80,7 @@ const MultipartParser = class MultipartParser {
|
|
|
82
80
|
reject(error);
|
|
83
81
|
});
|
|
84
82
|
|
|
85
|
-
busboy.once('
|
|
83
|
+
busboy.once('close', () => {
|
|
86
84
|
Promise.all(queue).then((items) => {
|
|
87
85
|
resolve(items);
|
|
88
86
|
}).catch((error) => {
|
|
@@ -216,4 +214,4 @@ const MultipartParser = class MultipartParser {
|
|
|
216
214
|
});
|
|
217
215
|
}
|
|
218
216
|
}
|
|
219
|
-
|
|
217
|
+
export default MultipartParser;
|
package/lib/sinks/fs.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { ReadFile } from '@eik/common';
|
|
2
|
+
import Metrics from '@metrics/client';
|
|
3
|
+
import rimraf from 'rimraf';
|
|
4
|
+
import Sink from '@eik/sink';
|
|
5
|
+
import mime from 'mime';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import fs from 'node:fs';
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const rimraf = require('rimraf');
|
|
6
|
-
const Sink = require('@eik/sink');
|
|
7
|
-
const mime = require('mime/lite');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
|
|
11
|
-
const { etagFromFsStat } = require('../utils/utils');
|
|
12
|
-
const conf = require('../utils/defaults');
|
|
9
|
+
import { etagFromFsStat } from '../utils/utils.js';
|
|
10
|
+
import conf from '../utils/defaults.js';
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* A sink for persisting files to local file system
|
|
@@ -263,4 +261,4 @@ const SinkFS = class SinkFS extends Sink {
|
|
|
263
261
|
return 'SinkFS';
|
|
264
262
|
}
|
|
265
263
|
}
|
|
266
|
-
|
|
264
|
+
export default SinkFS;
|
package/lib/sinks/mem-entry.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto');
|
|
1
|
+
import crypto from 'node:crypto';
|
|
4
2
|
|
|
5
3
|
const Entry = class Entry {
|
|
6
4
|
constructor({
|
|
@@ -38,4 +36,5 @@ const Entry = class Entry {
|
|
|
38
36
|
return 'Entry';
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
export default Entry;
|
package/lib/sinks/mem.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Writable, Readable } from 'node:stream';
|
|
2
|
+
import { ReadFile } from '@eik/common';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import Metrics from '@metrics/client';
|
|
5
|
+
import Sink from '@eik/sink';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const { ReadFile } = require('@eik/common');
|
|
5
|
-
const { join } = require('path');
|
|
6
|
-
const Metrics = require('@metrics/client');
|
|
7
|
-
const Sink = require('@eik/sink');
|
|
8
|
-
|
|
9
|
-
const Entry = require('./mem-entry');
|
|
7
|
+
import Entry from './mem-entry.js';
|
|
10
8
|
|
|
11
9
|
const DEFAULT_ROOT_PATH = '/eik';
|
|
12
10
|
|
|
@@ -209,4 +207,4 @@ const SinkMem = class SinkMem extends Sink {
|
|
|
209
207
|
return 'SinkMEM';
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
|
-
|
|
210
|
+
export default SinkMem;
|
package/lib/sinks/test.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { Writable, Readable } from 'node:stream';
|
|
2
|
+
import { ReadFile } from '@eik/common';
|
|
3
|
+
import Metrics from '@metrics/client';
|
|
4
|
+
import Sink from '@eik/sink';
|
|
5
|
+
import mime from 'mime';
|
|
6
|
+
import path from 'node:path';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
const { ReadFile } = require('@eik/common');
|
|
5
|
-
const Metrics = require('@metrics/client');
|
|
6
|
-
const Sink = require('@eik/sink');
|
|
7
|
-
const mime = require('mime/lite');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
const Entry = require('./mem-entry');
|
|
8
|
+
import Entry from './mem-entry.js';
|
|
11
9
|
|
|
12
10
|
const DEFAULT_ROOT_PATH = '/eik';
|
|
13
11
|
|
|
@@ -278,4 +276,5 @@ const SinkTest = class SinkTest extends Sink {
|
|
|
278
276
|
return 'SinkTest';
|
|
279
277
|
}
|
|
280
278
|
}
|
|
281
|
-
|
|
279
|
+
|
|
280
|
+
export default SinkTest;
|
package/lib/utils/defaults.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const os = require('os');
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
5
3
|
|
|
6
4
|
const config = {
|
|
7
5
|
authKey: 'change_me',
|
|
@@ -14,4 +12,5 @@ const config = {
|
|
|
14
12
|
['127.0.0.1', 'local'],
|
|
15
13
|
],
|
|
16
14
|
};
|
|
17
|
-
|
|
15
|
+
|
|
16
|
+
export default config;
|
package/lib/utils/globals.js
CHANGED
package/lib/utils/healthcheck.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Writable, pipeline } from 'node:stream';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
import abslog from 'abslog';
|
|
4
|
+
import slug from 'unique-slug';
|
|
5
|
+
import fs from 'node:fs';
|
|
2
6
|
|
|
3
|
-
const
|
|
4
|
-
const abslog = require('abslog');
|
|
5
|
-
const slug = require('unique-slug');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
|
|
9
|
-
const fileReader = (file = '../../README.md') => {
|
|
10
|
-
const pathname = path.join(__dirname, file);
|
|
11
|
-
return fs.createReadStream(pathname);
|
|
12
|
-
};
|
|
7
|
+
const fileReader = (file = '../../README.md') => fs.createReadStream(new URL(file, import.meta.url));
|
|
13
8
|
|
|
14
9
|
const HealthCheck = class HealthCheck {
|
|
15
10
|
constructor({ sink, logger } = {}) {
|
|
@@ -112,4 +107,5 @@ const HealthCheck = class HealthCheck {
|
|
|
112
107
|
return 'HealthCheck';
|
|
113
108
|
}
|
|
114
109
|
}
|
|
115
|
-
|
|
110
|
+
|
|
111
|
+
export default HealthCheck;
|
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { BASE_IMPORT_MAPS, ROOT } = require("./globals");
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import globals from './globals.js';
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
// Build file system path to a package file
|
|
8
6
|
|
|
9
|
-
const createFilePathToPackage = ({ org = '', type = '', name = '', version = '' } = {}) => path.join(ROOT, org, type, name, `${version}.package.json`)
|
|
10
|
-
module.exports.createFilePathToPackage = createFilePathToPackage;
|
|
7
|
+
const createFilePathToPackage = ({ org = '', type = '', name = '', version = '' } = {}) => path.join(globals.ROOT, org, type, name, `${version}.package.json`)
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
// Build file system path to an asset in a package
|
|
14
11
|
// pkgAsset
|
|
15
|
-
const createFilePathToAsset = ({ org = '', type = '', name = '', version = '', asset = '' } = {}) => path.join(ROOT, org, type, name, version, asset)
|
|
16
|
-
module.exports.createFilePathToAsset = createFilePathToAsset;
|
|
12
|
+
const createFilePathToAsset = ({ org = '', type = '', name = '', version = '', asset = '' } = {}) => path.join(globals.ROOT, org, type, name, version, asset)
|
|
17
13
|
|
|
18
14
|
|
|
19
15
|
// Build file system path to an import map
|
|
20
16
|
|
|
21
|
-
const createFilePathToImportMap = ({ org = '', name = '', version = '' } = {}) => path.join(ROOT, org, BASE_IMPORT_MAPS, name, `${version}.import-map.json`)
|
|
22
|
-
module.exports.createFilePathToImportMap = createFilePathToImportMap;
|
|
17
|
+
const createFilePathToImportMap = ({ org = '', name = '', version = '' } = {}) => path.join(globals.ROOT, org, globals.BASE_IMPORT_MAPS, name, `${version}.import-map.json`)
|
|
23
18
|
|
|
24
19
|
|
|
25
20
|
// Build file system path to an alias file
|
|
26
21
|
|
|
27
|
-
const createFilePathToAlias = ({ org = '', type = '', name = '', alias = '' } = {}) => path.join(ROOT, org, type, name, `${alias}.alias.json`)
|
|
28
|
-
module.exports.createFilePathToAlias = createFilePathToAlias;
|
|
22
|
+
const createFilePathToAlias = ({ org = '', type = '', name = '', alias = '' } = {}) => path.join(globals.ROOT, org, type, name, `${alias}.alias.json`)
|
|
29
23
|
|
|
30
24
|
|
|
31
25
|
// Build file system path to an version file
|
|
32
26
|
|
|
33
|
-
const createFilePathToVersion = ({ org = '', type = '', name = '' } = {}) => path.join(ROOT, org, type, name, 'versions.json')
|
|
34
|
-
module.exports.createFilePathToVersion = createFilePathToVersion;
|
|
27
|
+
const createFilePathToVersion = ({ org = '', type = '', name = '' } = {}) => path.join(globals.ROOT, org, type, name, 'versions.json')
|
|
35
28
|
|
|
36
29
|
const createFilePathToAliasOrigin = ({org = '', type = '', name = '', version = '',} = {}) => {
|
|
37
30
|
if(type === 'map') {
|
|
@@ -39,4 +32,13 @@ const createFilePathToAliasOrigin = ({org = '', type = '', name = '', version =
|
|
|
39
32
|
}
|
|
40
33
|
return createFilePathToPackage({org, type, name, version})
|
|
41
34
|
};
|
|
42
|
-
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
createFilePathToPackage,
|
|
39
|
+
createFilePathToAsset,
|
|
40
|
+
createFilePathToImportMap,
|
|
41
|
+
createFilePathToAlias,
|
|
42
|
+
createFilePathToVersion,
|
|
43
|
+
createFilePathToAliasOrigin,
|
|
44
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { BASE_IMPORT_MAPS, ROOT } = require("./globals");
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import globals from './globals.js';
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
// Build URL pathname to a package log file
|
|
8
6
|
|
|
9
|
-
const createURIPathToPkgLog = ({ type = '', name = '', version = '' } = {}) => path.join(ROOT, type, name, version)
|
|
10
|
-
module.exports.createURIPathToPkgLog = createURIPathToPkgLog;
|
|
7
|
+
const createURIPathToPkgLog = ({ type = '', name = '', version = '' } = {}) => path.join(globals.ROOT, type, name, version)
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
// Build URL pathname to an asset in a package
|
|
14
11
|
|
|
15
|
-
const createURIPathToAsset = ({ type = '', name = '', version = '', asset = '' } = {}) => path.join(ROOT, type, name, version, asset)
|
|
16
|
-
module.exports.createURIPathToAsset = createURIPathToAsset;
|
|
12
|
+
const createURIPathToAsset = ({ type = '', name = '', version = '', asset = '' } = {}) => path.join(globals.ROOT, type, name, version, asset)
|
|
17
13
|
|
|
18
14
|
|
|
19
15
|
// Build URL pathname to an import map
|
|
20
16
|
|
|
21
|
-
const createURIPathToImportMap = ({ name = '', version = '' } = {}) => path.join(ROOT, BASE_IMPORT_MAPS, name, version)
|
|
22
|
-
module.exports.createURIPathToImportMap = createURIPathToImportMap;
|
|
17
|
+
const createURIPathToImportMap = ({ name = '', version = '' } = {}) => path.join(globals.ROOT, globals.BASE_IMPORT_MAPS, name, version)
|
|
23
18
|
|
|
24
19
|
|
|
25
20
|
// Build URL pathname to an alias source
|
|
26
21
|
|
|
27
|
-
const createURIToAlias = ({ type = '', name = '', alias = '' } = {}) => path.join(ROOT, type, name, `v${alias}`)
|
|
28
|
-
module.exports.createURIToAlias = createURIToAlias;
|
|
22
|
+
const createURIToAlias = ({ type = '', name = '', alias = '' } = {}) => path.join(globals.ROOT, type, name, `v${alias}`)
|
|
29
23
|
|
|
30
24
|
|
|
31
25
|
// Build URL pathname to an alias target destination
|
|
32
26
|
|
|
33
|
-
const createURIToTargetOfAlias = ({ type = '', name = '', version = '', extra = '' } = {}) => path.join(ROOT, type, name, version, extra)
|
|
34
|
-
module.exports.createURIToTargetOfAlias = createURIToTargetOfAlias;
|
|
27
|
+
const createURIToTargetOfAlias = ({ type = '', name = '', version = '', extra = '' } = {}) => path.join(globals.ROOT, type, name, version, extra)
|
|
35
28
|
|
|
29
|
+
export {
|
|
30
|
+
createURIPathToPkgLog,
|
|
31
|
+
createURIPathToAsset,
|
|
32
|
+
createURIPathToImportMap,
|
|
33
|
+
createURIToAlias,
|
|
34
|
+
createURIToTargetOfAlias,
|
|
35
|
+
}
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { Writable, Readable, pipeline } = require('stream');
|
|
1
|
+
import { Writable, Readable, pipeline } from 'node:stream';
|
|
4
2
|
|
|
5
3
|
const readJSON = (sink, path) =>
|
|
6
4
|
// eslint-disable-next-line no-async-promise-executor
|
|
@@ -32,7 +30,6 @@ const readJSON = (sink, path) =>
|
|
|
32
30
|
}
|
|
33
31
|
})
|
|
34
32
|
;
|
|
35
|
-
module.exports.readJSON = readJSON;
|
|
36
33
|
|
|
37
34
|
const writeJSON = (sink, path, obj, contentType) =>
|
|
38
35
|
// eslint-disable-next-line no-async-promise-executor
|
|
@@ -59,7 +56,6 @@ const writeJSON = (sink, path, obj, contentType) =>
|
|
|
59
56
|
}
|
|
60
57
|
})
|
|
61
58
|
;
|
|
62
|
-
module.exports.writeJSON = writeJSON;
|
|
63
59
|
|
|
64
60
|
const streamCollector = (from) => new Promise((resolve, reject) => {
|
|
65
61
|
const buffer = [];
|
|
@@ -75,18 +71,22 @@ const streamCollector = (from) => new Promise((resolve, reject) => {
|
|
|
75
71
|
return resolve(buffer.join('').toString());
|
|
76
72
|
});
|
|
77
73
|
});
|
|
78
|
-
module.exports.streamCollector = streamCollector;
|
|
79
74
|
|
|
80
75
|
const etagFromFsStat = (stat) => {
|
|
81
76
|
const mtime = stat.mtime.getTime().toString(16)
|
|
82
77
|
const size = stat.size.toString(16)
|
|
83
78
|
return `W/"${size}-${mtime}"`;
|
|
84
79
|
};
|
|
85
|
-
module.exports.etagFromFsStat = etagFromFsStat;
|
|
86
|
-
|
|
87
80
|
|
|
88
81
|
const decodeUriComponent = (value) => {
|
|
89
82
|
if (value === null || value === undefined) return value;
|
|
90
83
|
return decodeURIComponent(value);
|
|
91
84
|
}
|
|
92
|
-
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
readJSON,
|
|
88
|
+
writeJSON,
|
|
89
|
+
streamCollector,
|
|
90
|
+
etagFromFsStat,
|
|
91
|
+
decodeUriComponent,
|
|
92
|
+
}
|