@verdaccio/web 6.0.0-6-next.45 → 6.0.0-6-next.47
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 +36 -0
- package/build/api/index.js +10 -1
- package/build/api/index.js.map +1 -1
- package/build/api/package.js +1 -1
- package/build/api/package.js.map +1 -1
- package/build/api/readme.d.ts +1 -1
- package/build/api/readme.js +1 -1
- package/build/api/readme.js.map +1 -1
- package/build/api/sidebar.d.ts +1 -1
- package/build/api/sidebar.js +1 -1
- package/build/api/sidebar.js.map +1 -1
- package/build/api/user.js +3 -2
- package/build/api/user.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/{web-middleware.d.ts → middleware.d.ts} +1 -0
- package/build/middleware.js +45 -0
- package/build/middleware.js.map +1 -0
- package/build/{utils/web-utils.d.ts → web-utils.d.ts} +3 -4
- package/build/{utils/web-utils.js → web-utils.js} +11 -23
- package/build/web-utils.js.map +1 -0
- package/jest.config.js +1 -1
- package/package.json +16 -18
- package/src/api/index.ts +11 -1
- package/src/api/package.ts +1 -1
- package/src/api/readme.ts +1 -1
- package/src/api/sidebar.ts +1 -1
- package/src/api/user.ts +28 -22
- package/src/index.ts +1 -1
- package/src/middleware.ts +46 -0
- package/src/{utils/web-utils.ts → web-utils.ts} +12 -27
- package/test/helper.ts +1 -1
- package/test/web-utils.spec.ts +1 -1
- package/build/middleware/render-web.d.ts +0 -2
- package/build/middleware/render-web.js +0 -92
- package/build/middleware/render-web.js.map +0 -1
- package/build/middleware/security.d.ts +0 -2
- package/build/middleware/security.js +0 -19
- package/build/middleware/security.js.map +0 -1
- package/build/middleware/web-api.d.ts +0 -5
- package/build/middleware/web-api.js +0 -29
- package/build/middleware/web-api.js.map +0 -1
- package/build/renderHTML.d.ts +0 -1
- package/build/renderHTML.js +0 -108
- package/build/renderHTML.js.map +0 -1
- package/build/template.d.ts +0 -13
- package/build/template.js +0 -38
- package/build/template.js.map +0 -1
- package/build/utils/manifest.d.ts +0 -6
- package/build/utils/manifest.js +0 -18
- package/build/utils/manifest.js.map +0 -1
- package/build/utils/web-utils.js.map +0 -1
- package/build/web-middleware.js +0 -21
- package/build/web-middleware.js.map +0 -1
- package/src/middleware/render-web.ts +0 -91
- package/src/middleware/security.ts +0 -18
- package/src/middleware/web-api.ts +0 -25
- package/src/renderHTML.ts +0 -112
- package/src/template.ts +0 -50
- package/src/utils/manifest.ts +0 -23
- package/src/web-middleware.ts +0 -14
- package/test/__snapshots__/template.test.ts.snap +0 -151
- package/test/manifest.test.ts +0 -11
- package/test/render.test.ts +0 -108
- package/test/template.test.ts +0 -74
- package/test/utils.spec.ts +0 -13
package/build/web-middleware.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _express = _interopRequireDefault(require("express"));
|
|
8
|
-
var _renderWeb = require("./middleware/render-web");
|
|
9
|
-
var _webApi = require("./middleware/web-api");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
var _default = async (config, auth, storage) => {
|
|
12
|
-
// eslint-disable-next-line new-cap
|
|
13
|
-
const app = _express.default.Router();
|
|
14
|
-
// load application
|
|
15
|
-
app.use('/', await (0, _renderWeb.renderWebMiddleware)(config, auth));
|
|
16
|
-
// web endpoints, search, packages, etc
|
|
17
|
-
app.use('/-/verdaccio/', (0, _webApi.webAPI)(config, auth, storage));
|
|
18
|
-
return app;
|
|
19
|
-
};
|
|
20
|
-
exports.default = _default;
|
|
21
|
-
//# sourceMappingURL=web-middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web-middleware.js","names":["config","auth","storage","app","express","Router","use","renderWebMiddleware","webAPI"],"sources":["../src/web-middleware.ts"],"sourcesContent":["import express from 'express';\n\nimport { renderWebMiddleware } from './middleware/render-web';\nimport { webAPI } from './middleware/web-api';\n\nexport default async (config, auth, storage) => {\n // eslint-disable-next-line new-cap\n const app = express.Router();\n // load application\n app.use('/', await renderWebMiddleware(config, auth));\n // web endpoints, search, packages, etc\n app.use('/-/verdaccio/', webAPI(config, auth, storage));\n return app;\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AAA8C;AAAA,eAE/B,OAAOA,MAAM,EAAEC,IAAI,EAAEC,OAAO,KAAK;EAC9C;EACA,MAAMC,GAAG,GAAGC,gBAAO,CAACC,MAAM,EAAE;EAC5B;EACAF,GAAG,CAACG,GAAG,CAAC,GAAG,EAAE,MAAM,IAAAC,8BAAmB,EAACP,MAAM,EAAEC,IAAI,CAAC,CAAC;EACrD;EACAE,GAAG,CAACG,GAAG,CAAC,eAAe,EAAE,IAAAE,cAAM,EAACR,MAAM,EAAEC,IAAI,EAAEC,OAAO,CAAC,CAAC;EACvD,OAAOC,GAAG;AACZ,CAAC;AAAA"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import buildDebug from 'debug';
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
import { HTTP_STATUS } from '@verdaccio/core';
|
|
7
|
-
import { asyncLoadPlugin } from '@verdaccio/loaders';
|
|
8
|
-
import { logger } from '@verdaccio/logger';
|
|
9
|
-
import { isURLhasValidProtocol } from '@verdaccio/url';
|
|
10
|
-
|
|
11
|
-
import renderHTML from '../renderHTML';
|
|
12
|
-
import { setSecurityWebHeaders } from './security';
|
|
13
|
-
|
|
14
|
-
const debug = buildDebug('verdaccio:web:render');
|
|
15
|
-
|
|
16
|
-
export async function loadTheme(config: any) {
|
|
17
|
-
if (_.isNil(config.theme) === false) {
|
|
18
|
-
const plugin = await asyncLoadPlugin(
|
|
19
|
-
config.theme,
|
|
20
|
-
{ config, logger },
|
|
21
|
-
// TODO: add types { staticPath: string; manifest: unknown; manifestFiles: unknown }
|
|
22
|
-
function (plugin: any) {
|
|
23
|
-
return plugin.staticPath && plugin.manifest && plugin.manifestFiles;
|
|
24
|
-
},
|
|
25
|
-
config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme'
|
|
26
|
-
);
|
|
27
|
-
if (plugin.length > 1) {
|
|
28
|
-
logger.warn(
|
|
29
|
-
'multiple ui themes has been detected and is not supported, only the first one will be used'
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return _.head(plugin);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const sendFileCallback = (next) => (err) => {
|
|
38
|
-
if (!err) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (err.status === HTTP_STATUS.NOT_FOUND) {
|
|
42
|
-
next();
|
|
43
|
-
} else {
|
|
44
|
-
next(err);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export async function renderWebMiddleware(config, auth): Promise<any> {
|
|
49
|
-
const { staticPath, manifest, manifestFiles } =
|
|
50
|
-
(await loadTheme(config)) || require('@verdaccio/ui-theme')();
|
|
51
|
-
debug('static path %o', staticPath);
|
|
52
|
-
|
|
53
|
-
/* eslint new-cap:off */
|
|
54
|
-
const router = express.Router();
|
|
55
|
-
router.use(auth.webUIJWTmiddleware());
|
|
56
|
-
router.use(setSecurityWebHeaders);
|
|
57
|
-
|
|
58
|
-
// Logo
|
|
59
|
-
let logoURI = config?.web?.logo ?? '';
|
|
60
|
-
if (logoURI && !isURLhasValidProtocol(logoURI)) {
|
|
61
|
-
// URI related to a local file
|
|
62
|
-
|
|
63
|
-
// Note: `path.join` will break on Windows, because it transforms `/` to `\`
|
|
64
|
-
// Use POSIX version `path.posix.join` instead.
|
|
65
|
-
logoURI = path.posix.join('/-/static/', path.basename(logoURI));
|
|
66
|
-
router.get(logoURI, function (req, res, next) {
|
|
67
|
-
res.sendFile(path.resolve(config.web.logo), sendFileCallback(next));
|
|
68
|
-
debug('render static');
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Static
|
|
73
|
-
router.get('/-/static/*', function (req, res, next) {
|
|
74
|
-
const filename = req.params[0];
|
|
75
|
-
const file = `${staticPath}/${filename}`;
|
|
76
|
-
debug('render static file %o', file);
|
|
77
|
-
res.sendFile(file, sendFileCallback(next));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
router.get('/-/web/:section/*', function (req, res) {
|
|
81
|
-
renderHTML(config, manifest, manifestFiles, req, res);
|
|
82
|
-
debug('render html section');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
router.get('/', function (req, res) {
|
|
86
|
-
renderHTML(config, manifest, manifestFiles, req, res);
|
|
87
|
-
debug('render root');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return router;
|
|
91
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { HEADERS } from '@verdaccio/core';
|
|
2
|
-
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
|
|
3
|
-
|
|
4
|
-
export function setSecurityWebHeaders(
|
|
5
|
-
req: $RequestExtend,
|
|
6
|
-
res: $ResponseExtend,
|
|
7
|
-
next: $NextFunctionVer
|
|
8
|
-
): void {
|
|
9
|
-
// disable loading in frames (clickjacking, etc.)
|
|
10
|
-
res.header(HEADERS.FRAMES_OPTIONS, 'deny');
|
|
11
|
-
// avoid stablish connections outside of domain
|
|
12
|
-
res.header(HEADERS.CSP, "connect-src 'self'");
|
|
13
|
-
// https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff
|
|
14
|
-
res.header(HEADERS.CTO, 'nosniff');
|
|
15
|
-
// https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection
|
|
16
|
-
res.header(HEADERS.XSS, '1; mode=block');
|
|
17
|
-
next();
|
|
18
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import bodyParser from 'body-parser';
|
|
2
|
-
import { Router } from 'express';
|
|
3
|
-
|
|
4
|
-
import { Auth } from '@verdaccio/auth';
|
|
5
|
-
import { validateName, validatePackage } from '@verdaccio/middleware';
|
|
6
|
-
import { Storage } from '@verdaccio/store';
|
|
7
|
-
import { Config } from '@verdaccio/types';
|
|
8
|
-
|
|
9
|
-
import webEndpointsApi from '../api';
|
|
10
|
-
import { setSecurityWebHeaders } from './security';
|
|
11
|
-
|
|
12
|
-
export function webAPI(config: Config, auth: Auth, storage: Storage): Router {
|
|
13
|
-
// eslint-disable-next-line new-cap
|
|
14
|
-
const route = Router();
|
|
15
|
-
// validate all of these params as a package name
|
|
16
|
-
// this might be too harsh, so ask if it causes trouble=
|
|
17
|
-
route.param('package', validatePackage);
|
|
18
|
-
route.param('filename', validateName);
|
|
19
|
-
route.param('version', validateName);
|
|
20
|
-
route.use(bodyParser.urlencoded({ extended: false }));
|
|
21
|
-
route.use(auth.webUIJWTmiddleware());
|
|
22
|
-
route.use(setSecurityWebHeaders);
|
|
23
|
-
route.use(webEndpointsApi(auth, storage, config));
|
|
24
|
-
return route;
|
|
25
|
-
}
|
package/src/renderHTML.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import buildDebug from 'debug';
|
|
2
|
-
import LRU from 'lru-cache';
|
|
3
|
-
import { URL } from 'url';
|
|
4
|
-
|
|
5
|
-
import { WEB_TITLE } from '@verdaccio/config';
|
|
6
|
-
import { HEADERS } from '@verdaccio/core';
|
|
7
|
-
import { TemplateUIOptions } from '@verdaccio/types';
|
|
8
|
-
import { getPublicUrl } from '@verdaccio/url';
|
|
9
|
-
|
|
10
|
-
import renderTemplate from './template';
|
|
11
|
-
import { hasLogin, validatePrimaryColor } from './utils/web-utils';
|
|
12
|
-
|
|
13
|
-
const pkgJSON = require('../package.json');
|
|
14
|
-
const DEFAULT_LANGUAGE = 'es-US';
|
|
15
|
-
const cache = new LRU({ max: 500, ttl: 1000 * 60 * 60 });
|
|
16
|
-
|
|
17
|
-
const debug = buildDebug('verdaccio:web:render');
|
|
18
|
-
|
|
19
|
-
const defaultManifestFiles = {
|
|
20
|
-
js: ['runtime.js', 'vendors.js', 'main.js'],
|
|
21
|
-
ico: 'favicon.ico',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default function renderHTML(config, manifest, manifestFiles, req, res) {
|
|
25
|
-
const { url_prefix } = config;
|
|
26
|
-
const base = getPublicUrl(config?.url_prefix, req);
|
|
27
|
-
const basename = new URL(base).pathname;
|
|
28
|
-
const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;
|
|
29
|
-
const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)
|
|
30
|
-
? true
|
|
31
|
-
: config.web.html_cache;
|
|
32
|
-
const darkMode = config?.web?.darkMode ?? false;
|
|
33
|
-
const title = config?.web?.title ?? WEB_TITLE;
|
|
34
|
-
const login = hasLogin(config);
|
|
35
|
-
const scope = config?.web?.scope ?? '';
|
|
36
|
-
const logoURI = config?.web?.logo ?? '';
|
|
37
|
-
const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];
|
|
38
|
-
const version = pkgJSON.version;
|
|
39
|
-
const flags = {
|
|
40
|
-
...config.flags,
|
|
41
|
-
};
|
|
42
|
-
const primaryColor = validatePrimaryColor(config?.web?.primary_color) ?? '#4b5e40';
|
|
43
|
-
const {
|
|
44
|
-
scriptsBodyAfter,
|
|
45
|
-
metaScripts,
|
|
46
|
-
scriptsbodyBefore,
|
|
47
|
-
showInfo,
|
|
48
|
-
showSettings,
|
|
49
|
-
showThemeSwitch,
|
|
50
|
-
showFooter,
|
|
51
|
-
showSearch,
|
|
52
|
-
showDownloadTarball,
|
|
53
|
-
} = Object.assign(
|
|
54
|
-
{},
|
|
55
|
-
{
|
|
56
|
-
scriptsBodyAfter: [],
|
|
57
|
-
bodyBefore: [],
|
|
58
|
-
metaScripts: [],
|
|
59
|
-
},
|
|
60
|
-
config?.web
|
|
61
|
-
);
|
|
62
|
-
const options: TemplateUIOptions = {
|
|
63
|
-
showInfo,
|
|
64
|
-
showSettings,
|
|
65
|
-
showThemeSwitch,
|
|
66
|
-
showFooter,
|
|
67
|
-
showSearch,
|
|
68
|
-
showDownloadTarball,
|
|
69
|
-
darkMode,
|
|
70
|
-
url_prefix,
|
|
71
|
-
basename,
|
|
72
|
-
base,
|
|
73
|
-
primaryColor,
|
|
74
|
-
version,
|
|
75
|
-
logoURI,
|
|
76
|
-
flags,
|
|
77
|
-
login,
|
|
78
|
-
pkgManagers,
|
|
79
|
-
title,
|
|
80
|
-
scope,
|
|
81
|
-
language,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
let webPage;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
webPage = cache.get('template');
|
|
88
|
-
if (!webPage) {
|
|
89
|
-
webPage = renderTemplate(
|
|
90
|
-
{
|
|
91
|
-
manifest: manifestFiles ?? defaultManifestFiles,
|
|
92
|
-
options,
|
|
93
|
-
scriptsBodyAfter,
|
|
94
|
-
metaScripts,
|
|
95
|
-
scriptsbodyBefore,
|
|
96
|
-
},
|
|
97
|
-
manifest
|
|
98
|
-
);
|
|
99
|
-
if (needHtmlCache) {
|
|
100
|
-
cache.set('template', webPage);
|
|
101
|
-
debug('set template cache');
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
debug('reuse template cache');
|
|
105
|
-
}
|
|
106
|
-
} catch (error: any) {
|
|
107
|
-
throw new Error(`theme could not be load, stack ${error.stack}`);
|
|
108
|
-
}
|
|
109
|
-
res.setHeader('Content-Type', HEADERS.TEXT_HTML);
|
|
110
|
-
res.send(webPage);
|
|
111
|
-
debug('web rendered');
|
|
112
|
-
}
|
package/src/template.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import buildDebug from 'debug';
|
|
2
|
-
|
|
3
|
-
import { TemplateUIOptions } from '@verdaccio/types';
|
|
4
|
-
|
|
5
|
-
import { Manifest, getManifestValue } from './utils/manifest';
|
|
6
|
-
|
|
7
|
-
const debug = buildDebug('verdaccio:web:render:template');
|
|
8
|
-
|
|
9
|
-
export type Template = {
|
|
10
|
-
manifest: Manifest;
|
|
11
|
-
options: TemplateUIOptions;
|
|
12
|
-
metaScripts?: string[];
|
|
13
|
-
scriptsBodyAfter?: string[];
|
|
14
|
-
scriptsbodyBefore?: string[];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// the outcome of the Webpack Manifest Plugin
|
|
18
|
-
export interface WebpackManifest {
|
|
19
|
-
[key: string]: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default function renderTemplate(template: Template, manifest: WebpackManifest) {
|
|
23
|
-
debug('template %o', template);
|
|
24
|
-
debug('manifest %o', manifest);
|
|
25
|
-
|
|
26
|
-
return `
|
|
27
|
-
<!DOCTYPE html>
|
|
28
|
-
<html lang="en-us">
|
|
29
|
-
<head>
|
|
30
|
-
<meta charset="utf-8">
|
|
31
|
-
<base href="${template?.options.base}">
|
|
32
|
-
<title>${template?.options?.title ?? ''}</title>
|
|
33
|
-
<link rel="icon" href="${template?.options.base}-/static/favicon.ico"/>
|
|
34
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
35
|
-
<script>
|
|
36
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(template.options)}
|
|
37
|
-
</script>
|
|
38
|
-
${template?.metaScripts ? template.metaScripts.join('') : ''}
|
|
39
|
-
</head>
|
|
40
|
-
<body class="body">
|
|
41
|
-
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
|
|
42
|
-
<div id="root"></div>
|
|
43
|
-
${getManifestValue(template.manifest.js, manifest, template?.options.base)
|
|
44
|
-
.map((item) => `<script defer="defer" src="${item}"></script>`)
|
|
45
|
-
.join('')}
|
|
46
|
-
${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
|
|
47
|
-
</body>
|
|
48
|
-
</html>
|
|
49
|
-
`;
|
|
50
|
-
}
|
package/src/utils/manifest.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import buildDebug from 'debug';
|
|
2
|
-
|
|
3
|
-
export type Manifest = {
|
|
4
|
-
// goes on first place at the header
|
|
5
|
-
ico: string;
|
|
6
|
-
css: string[];
|
|
7
|
-
js: string[];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const debug = buildDebug('verdaccio:web:render:manifest');
|
|
11
|
-
|
|
12
|
-
export function getManifestValue(
|
|
13
|
-
manifestItems: string[],
|
|
14
|
-
manifest,
|
|
15
|
-
basePath: string = ''
|
|
16
|
-
): string[] {
|
|
17
|
-
return manifestItems?.map((item) => {
|
|
18
|
-
debug('resolve item %o', item);
|
|
19
|
-
const resolvedItem = `${basePath}${manifest[item]}`;
|
|
20
|
-
debug('resolved item %o', resolvedItem);
|
|
21
|
-
return resolvedItem;
|
|
22
|
-
});
|
|
23
|
-
}
|
package/src/web-middleware.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
|
|
3
|
-
import { renderWebMiddleware } from './middleware/render-web';
|
|
4
|
-
import { webAPI } from './middleware/web-api';
|
|
5
|
-
|
|
6
|
-
export default async (config, auth, storage) => {
|
|
7
|
-
// eslint-disable-next-line new-cap
|
|
8
|
-
const app = express.Router();
|
|
9
|
-
// load application
|
|
10
|
-
app.use('/', await renderWebMiddleware(config, auth));
|
|
11
|
-
// web endpoints, search, packages, etc
|
|
12
|
-
app.use('/-/verdaccio/', webAPI(config, auth, storage));
|
|
13
|
-
return app;
|
|
14
|
-
};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`template custom body after 1`] = `
|
|
4
|
-
"
|
|
5
|
-
<!DOCTYPE html>
|
|
6
|
-
<html lang="en-us">
|
|
7
|
-
<head>
|
|
8
|
-
<meta charset="utf-8">
|
|
9
|
-
<base href="http://domain.com">
|
|
10
|
-
<title></title>
|
|
11
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
12
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
13
|
-
<script>
|
|
14
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
</head>
|
|
18
|
-
<body class="body">
|
|
19
|
-
|
|
20
|
-
<div id="root"></div>
|
|
21
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
22
|
-
<script src="foo"/>
|
|
23
|
-
</body>
|
|
24
|
-
</html>
|
|
25
|
-
"
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
exports[`template custom body before 1`] = `
|
|
29
|
-
"
|
|
30
|
-
<!DOCTYPE html>
|
|
31
|
-
<html lang="en-us">
|
|
32
|
-
<head>
|
|
33
|
-
<meta charset="utf-8">
|
|
34
|
-
<base href="http://domain.com">
|
|
35
|
-
<title></title>
|
|
36
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
37
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
38
|
-
<script>
|
|
39
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
|
|
40
|
-
</script>
|
|
41
|
-
|
|
42
|
-
</head>
|
|
43
|
-
<body class="body">
|
|
44
|
-
<script src="fooBefore"/><script src="barBefore"/>
|
|
45
|
-
<div id="root"></div>
|
|
46
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
47
|
-
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
50
|
-
"
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
exports[`template custom render 1`] = `
|
|
54
|
-
"
|
|
55
|
-
<!DOCTYPE html>
|
|
56
|
-
<html lang="en-us">
|
|
57
|
-
<head>
|
|
58
|
-
<meta charset="utf-8">
|
|
59
|
-
<base href="http://domain.com">
|
|
60
|
-
<title></title>
|
|
61
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
62
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
63
|
-
<script>
|
|
64
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
|
|
65
|
-
</script>
|
|
66
|
-
|
|
67
|
-
</head>
|
|
68
|
-
<body class="body">
|
|
69
|
-
|
|
70
|
-
<div id="root"></div>
|
|
71
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
72
|
-
|
|
73
|
-
</body>
|
|
74
|
-
</html>
|
|
75
|
-
"
|
|
76
|
-
`;
|
|
77
|
-
|
|
78
|
-
exports[`template custom title 1`] = `
|
|
79
|
-
"
|
|
80
|
-
<!DOCTYPE html>
|
|
81
|
-
<html lang="en-us">
|
|
82
|
-
<head>
|
|
83
|
-
<meta charset="utf-8">
|
|
84
|
-
<base href="http://domain.com">
|
|
85
|
-
<title>foo title</title>
|
|
86
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
87
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
88
|
-
<script>
|
|
89
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com","title":"foo title"}
|
|
90
|
-
</script>
|
|
91
|
-
|
|
92
|
-
</head>
|
|
93
|
-
<body class="body">
|
|
94
|
-
|
|
95
|
-
<div id="root"></div>
|
|
96
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
97
|
-
|
|
98
|
-
</body>
|
|
99
|
-
</html>
|
|
100
|
-
"
|
|
101
|
-
`;
|
|
102
|
-
|
|
103
|
-
exports[`template custom title 2`] = `
|
|
104
|
-
"
|
|
105
|
-
<!DOCTYPE html>
|
|
106
|
-
<html lang="en-us">
|
|
107
|
-
<head>
|
|
108
|
-
<meta charset="utf-8">
|
|
109
|
-
<base href="http://domain.com">
|
|
110
|
-
<title>foo title</title>
|
|
111
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
112
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
113
|
-
<script>
|
|
114
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com","title":"foo title"}
|
|
115
|
-
</script>
|
|
116
|
-
|
|
117
|
-
</head>
|
|
118
|
-
<body class="body">
|
|
119
|
-
|
|
120
|
-
<div id="root"></div>
|
|
121
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
122
|
-
|
|
123
|
-
</body>
|
|
124
|
-
</html>
|
|
125
|
-
"
|
|
126
|
-
`;
|
|
127
|
-
|
|
128
|
-
exports[`template meta scripts 1`] = `
|
|
129
|
-
"
|
|
130
|
-
<!DOCTYPE html>
|
|
131
|
-
<html lang="en-us">
|
|
132
|
-
<head>
|
|
133
|
-
<meta charset="utf-8">
|
|
134
|
-
<base href="http://domain.com">
|
|
135
|
-
<title></title>
|
|
136
|
-
<link rel="icon" href="http://domain.com-/static/favicon.ico"/>
|
|
137
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
138
|
-
<script>
|
|
139
|
-
window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
|
|
140
|
-
</script>
|
|
141
|
-
<style>.someclass{font-size:10px;}</style>
|
|
142
|
-
</head>
|
|
143
|
-
<body class="body">
|
|
144
|
-
|
|
145
|
-
<div id="root"></div>
|
|
146
|
-
<script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
|
|
147
|
-
|
|
148
|
-
</body>
|
|
149
|
-
</html>
|
|
150
|
-
"
|
|
151
|
-
`;
|
package/test/manifest.test.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getManifestValue } from '../src/utils/manifest';
|
|
2
|
-
|
|
3
|
-
const manifest = require('./partials/manifest/manifest.json');
|
|
4
|
-
|
|
5
|
-
describe('manifest', () => {
|
|
6
|
-
test('getManifestValue', () => {
|
|
7
|
-
expect(getManifestValue(['main.js'], manifest)).toEqual([
|
|
8
|
-
'/-/static/main.6126058572f989c948b1.js',
|
|
9
|
-
]);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/test/render.test.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import supertest from 'supertest';
|
|
4
|
-
|
|
5
|
-
import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
|
|
6
|
-
import { setup } from '@verdaccio/logger';
|
|
7
|
-
|
|
8
|
-
import { initializeServer } from './helper';
|
|
9
|
-
|
|
10
|
-
setup([]);
|
|
11
|
-
|
|
12
|
-
const mockManifest = jest.fn();
|
|
13
|
-
jest.mock('@verdaccio/ui-theme', () => mockManifest());
|
|
14
|
-
|
|
15
|
-
describe('test web server', () => {
|
|
16
|
-
beforeAll(() => {
|
|
17
|
-
mockManifest.mockReturnValue(() => ({
|
|
18
|
-
manifestFiles: {
|
|
19
|
-
js: ['runtime.js', 'vendors.js', 'main.js'],
|
|
20
|
-
},
|
|
21
|
-
staticPath: path.join(__dirname, 'static'),
|
|
22
|
-
manifest: require('./partials/manifest/manifest.json'),
|
|
23
|
-
}));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
jest.clearAllMocks();
|
|
28
|
-
mockManifest.mockClear();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('render', () => {
|
|
32
|
-
describe('output', () => {
|
|
33
|
-
const render = async (config = 'default-test.yaml') => {
|
|
34
|
-
const response = await supertest(await initializeServer(config))
|
|
35
|
-
.get('/')
|
|
36
|
-
.set('Accept', HEADERS.TEXT_HTML)
|
|
37
|
-
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
38
|
-
.expect(HTTP_STATUS.OK);
|
|
39
|
-
return new JSDOM(response.text, { runScripts: 'dangerously' });
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
test('should match render set ui properties', async () => {
|
|
43
|
-
const {
|
|
44
|
-
window: { __VERDACCIO_BASENAME_UI_OPTIONS },
|
|
45
|
-
} = await render('web.yaml');
|
|
46
|
-
expect(__VERDACCIO_BASENAME_UI_OPTIONS).toEqual(
|
|
47
|
-
expect.objectContaining({
|
|
48
|
-
showInfo: true,
|
|
49
|
-
showSettings: true,
|
|
50
|
-
showThemeSwitch: true,
|
|
51
|
-
showFooter: true,
|
|
52
|
-
showSearch: true,
|
|
53
|
-
showDownloadTarball: true,
|
|
54
|
-
darkMode: false,
|
|
55
|
-
url_prefix: '/prefix',
|
|
56
|
-
basename: '/prefix/',
|
|
57
|
-
primaryColor: '#ffffff',
|
|
58
|
-
// FIXME: mock these values, avoid random
|
|
59
|
-
// base: 'http://127.0.0.1:60864/prefix/',
|
|
60
|
-
// version: '6.0.0-6-next.28',
|
|
61
|
-
logoURI: '',
|
|
62
|
-
flags: { searchRemote: true },
|
|
63
|
-
login: true,
|
|
64
|
-
pkgManagers: ['pnpm', 'yarn'],
|
|
65
|
-
title: 'verdaccio web',
|
|
66
|
-
scope: '@scope',
|
|
67
|
-
language: 'es-US',
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test.todo('should default title');
|
|
73
|
-
test.todo('should need html cache');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('status', () => {
|
|
77
|
-
test('should return the http status 200 for root', async () => {
|
|
78
|
-
return supertest(await initializeServer('default-test.yaml'))
|
|
79
|
-
.get('/')
|
|
80
|
-
.set('Accept', HEADERS.TEXT_HTML)
|
|
81
|
-
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
82
|
-
.expect(HTTP_STATUS.OK);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('should return the body for a package detail page', async () => {
|
|
86
|
-
return supertest(await initializeServer('default-test.yaml'))
|
|
87
|
-
.get('/-/web/section/some-package')
|
|
88
|
-
.set('Accept', HEADERS.TEXT_HTML)
|
|
89
|
-
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
90
|
-
.expect(HTTP_STATUS.OK);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('should static file not found', async () => {
|
|
94
|
-
return supertest(await initializeServer('default-test.yaml'))
|
|
95
|
-
.get('/-/static/not-found.js')
|
|
96
|
-
.set('Accept', HEADERS.TEXT_HTML)
|
|
97
|
-
.expect(HTTP_STATUS.NOT_FOUND);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('should static file found', async () => {
|
|
101
|
-
return supertest(await initializeServer('default-test.yaml'))
|
|
102
|
-
.get('/-/static/main.js')
|
|
103
|
-
.set('Accept', HEADERS.TEXT_HTML)
|
|
104
|
-
.expect(HTTP_STATUS.OK);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|