Skip to content

Commit

Permalink
cleanup verdaccio typings override, fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jan 10, 2023
1 parent 663e023 commit aef3d60
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
3 changes: 1 addition & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@types/escodegen": "^0.0.6",
"@types/express": "^4.17.11",
"@types/fs-extra": "^9.0.6",
"@types/js-yaml": "^3.12.6",
"@types/node": "^16.0.0",
"@types/node-fetch": "^2.5.7",
"@types/prompts": "2.0.11",
Expand Down Expand Up @@ -106,7 +105,6 @@
"jest-os-detection": "^1.3.1",
"jest-serializer-html": "^7.1.0",
"jest-watch-typeahead": "^2.2.1",
"js-yaml": "^3.14.1",
"junit-xml": "^1.2.0",
"lint-staged": "^10.5.4",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -148,6 +146,7 @@
"@types/lodash": "^4"
},
"optionalDependencies": {
"@verdaccio/types": "^10.2.0",
"ts-loader": "^9.4.2",
"verdaccio": "^5.19.1",
"verdaccio-auth-memory": "^10.2.0"
Expand Down
42 changes: 15 additions & 27 deletions scripts/run-registry.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
import { exec } from 'child_process';
import { remove, pathExists } from 'fs-extra';
import { remove, pathExists, readJSON } from 'fs-extra';
import chalk from 'chalk';
import path from 'path';
import program from 'commander';
import detectFreePort from 'detect-port';
import fs from 'fs';
import yaml from 'js-yaml';

import startVerdaccioServer from 'verdaccio';
import { runServer, parseConfigFile } from 'verdaccio';
import pLimit from 'p-limit';
import type { Server } from 'http';
// @ts-expect-error (Converted from ts-ignore)
import { maxConcurrentTasks } from './utils/concurrency';
import { listOfPackages } from './utils/list-packages';

program
.option('-O, --open', 'keep process open')
.option('-P, --publish', 'should publish packages')
.option('-p, --port <port>', 'port to run https server on');
.option('-P, --publish', 'should publish packages');

program.parse(process.argv);

const logger = console;

const freePort = (port?: number) => port || detectFreePort(port);

const startVerdaccio = (port: number): Promise<any> => {
const startVerdaccio = async () => {
let resolved = false;
return Promise.race([
new Promise((resolve) => {
const cache = path.join(__dirname, '..', '.verdaccio-cache');
const config = {
...(yaml.safeLoad(
fs.readFileSync(path.join(__dirname, 'verdaccio.yaml'), 'utf8')
) as Record<string, any>),
...parseConfigFile(path.join(__dirname, 'verdaccio.yaml')),
self_path: cache,
};

const onReady = (webServer: any) => {
webServer.listen(port, () => {
runServer(config).then((app: Server) => {
app.listen(6001, () => {
resolved = true;
resolve(webServer);
resolve(app);
});
};

startVerdaccioServer(config, 6001, cache, '1.0.0', 'verdaccio', onReady);
});
}),
new Promise((_, rej) => {
setTimeout(() => {
Expand All @@ -53,11 +44,11 @@ const startVerdaccio = (port: number): Promise<any> => {
}
}, 10000);
}),
]);
]) as Promise<Server>;
};

const currentVersion = async () => {
const { version } = (await import('../code/lerna.json')).default;
const { version } = await readJSON(path.join(__dirname, '..', 'code', 'package.json'));
return version;
};

Expand Down Expand Up @@ -95,7 +86,7 @@ const publish = (packages: { name: string; location: string }[], url: string) =>
};

const addUser = (url: string) =>
new Promise((res, rej) => {
new Promise<void>((res, rej) => {
logger.log(`👤 add temp user to verdaccio`);

exec(`npx npm-cli-adduser -r "${url}" -a -u user -p password -e [email protected]`, (e) => {
Expand All @@ -108,10 +99,7 @@ const addUser = (url: string) =>
});

const run = async () => {
const port = await freePort(program.port);
logger.log(`🌏 found a open port: ${port}`);

const verdaccioUrl = `http://localhost:${port}`;
const verdaccioUrl = `http://localhost:6001`;

logger.log(`📐 reading version of storybook`);
logger.log(`🚛 listing storybook packages`);
Expand All @@ -128,7 +116,7 @@ const run = async () => {
logger.log(`🎬 starting verdaccio (this takes ±5 seconds, so be patient)`);

const [verdaccioServer, packages, version] = await Promise.all([
startVerdaccio(port),
startVerdaccio(),
listOfPackages(),
currentVersion(),
]);
Expand Down
5 changes: 0 additions & 5 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"paths": {
"verdaccio": [
"./typings.d.ts"
]
},
},
"exclude": [
"dist",
Expand Down
1 change: 0 additions & 1 deletion scripts/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module 'verdaccio';
declare module 'pretty-hrtime';
21 changes: 11 additions & 10 deletions scripts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2751,7 +2751,6 @@ __metadata:
"@types/escodegen": ^0.0.6
"@types/express": ^4.17.11
"@types/fs-extra": ^9.0.6
"@types/js-yaml": ^3.12.6
"@types/lodash": ^4
"@types/node": ^16.0.0
"@types/node-fetch": ^2.5.7
Expand All @@ -2764,6 +2763,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^5.45.0
"@typescript-eslint/experimental-utils": ^5.45.0
"@typescript-eslint/parser": ^5.45.0
"@verdaccio/types": ^10.2.0
babel-eslint: ^10.1.0
babel-loader: ^8.3.0
boxen: ^5.1.2
Expand Down Expand Up @@ -2798,7 +2798,6 @@ __metadata:
jest-os-detection: ^1.3.1
jest-serializer-html: ^7.1.0
jest-watch-typeahead: ^2.2.1
js-yaml: ^3.14.1
junit-xml: ^1.2.0
lint-staged: ^10.5.4
lodash: ^4.17.21
Expand Down Expand Up @@ -2839,6 +2838,8 @@ __metadata:
window-size: ^1.1.1
zx: ^7.0.3
dependenciesMeta:
"@verdaccio/types":
optional: true
ts-loader:
optional: true
verdaccio:
Expand Down Expand Up @@ -3287,13 +3288,6 @@ __metadata:
languageName: node
linkType: hard

"@types/js-yaml@npm:^3.12.6":
version: 3.12.7
resolution: "@types/js-yaml@npm:3.12.7"
checksum: 7df8078fb1783e04f6b24b97378ec396359d81bda4fe9cf352ec35bb055b3d4034854582f9b337d5d7a946c622265f422aca7f61bf872e2acaed07f317bedb06
languageName: node
linkType: hard

"@types/jsdom@npm:^20.0.0":
version: 20.0.1
resolution: "@types/jsdom@npm:20.0.1"
Expand Down Expand Up @@ -3736,6 +3730,13 @@ __metadata:
languageName: node
linkType: hard

"@verdaccio/types@npm:^10.2.0":
version: 10.7.0
resolution: "@verdaccio/types@npm:10.7.0"
checksum: 3930ebe912221d58f300d17e50b1a874e72c9b0b3518cb5abfd30419b241afd7a36c6c751c60c24c1ba1de5c396b486bfb90b6891ff3d5ad22416fc832191280
languageName: node
linkType: hard

"@verdaccio/ui-theme@npm:6.0.0-6-next.52":
version: 6.0.0-6-next.52
resolution: "@verdaccio/ui-theme@npm:6.0.0-6-next.52"
Expand Down Expand Up @@ -9615,7 +9616,7 @@ __metadata:
languageName: node
linkType: hard

"js-yaml@npm:3.14.1, js-yaml@npm:^3.10.0, js-yaml@npm:^3.13.1, js-yaml@npm:^3.14.1, js-yaml@npm:^3.6.1":
"js-yaml@npm:3.14.1, js-yaml@npm:^3.10.0, js-yaml@npm:^3.13.1, js-yaml@npm:^3.6.1":
version: 3.14.1
resolution: "js-yaml@npm:3.14.1"
dependencies:
Expand Down

0 comments on commit aef3d60

Please sign in to comment.