From 1b32d52d4d57363bed8af9105dd41a0635075721 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 22 Dec 2024 22:28:24 +0100 Subject: [PATCH] Updated deps --- .../piral-base/src/aggregate.test.ts | 5 +- src/plugins/piral-axios/src/create.test.ts | 6 +- src/plugins/piral-fetch/src/create.test.ts | 6 +- src/tooling/piral-cli/package.json | 2 +- src/tooling/piral-cli/src/common/browser.ts | 3 +- src/tooling/piral-cli/src/common/http.test.ts | 112 +++++++++--------- .../piral-cli/src/external/index.test.ts | 7 +- src/tooling/piral-cli/src/external/index.ts | 6 +- .../publish-microfrontend/package.json | 6 +- .../publish-microfrontend/src/browser.ts | 3 +- 10 files changed, 77 insertions(+), 79 deletions(-) diff --git a/src/framework/piral-base/src/aggregate.test.ts b/src/framework/piral-base/src/aggregate.test.ts index 76ea5802e..17fc5afef 100644 --- a/src/framework/piral-base/src/aggregate.test.ts +++ b/src/framework/piral-base/src/aggregate.test.ts @@ -6,7 +6,10 @@ import { runPilet } from './aggregate'; describe('Piral-Base aggregate module', () => { it('createPilet calls the setup method of the pilet', async () => { - const create: any = vitest.fn(() => ({})); + const create: any = vitest.fn(() => ({ + on: vitest.fn(), + off: vitest.fn(), + })); const setup = vitest.fn(); await runPilet( create, diff --git a/src/plugins/piral-axios/src/create.test.ts b/src/plugins/piral-axios/src/create.test.ts index 6236a28d7..3e6728baf 100644 --- a/src/plugins/piral-axios/src/create.test.ts +++ b/src/plugins/piral-axios/src/create.test.ts @@ -2,6 +2,9 @@ * @vitest-environment jsdom */ import create from 'zustand'; +import getPort from 'get-port'; +import cors from 'cors'; +import express from 'express'; import { describe, it, expect, vitest, beforeAll, afterAll } from 'vitest'; import { createAxiosApi } from './create'; @@ -27,9 +30,6 @@ describe('Piral-Axios create module', () => { let port; beforeAll(async () => { - const express = require('express'); - const cors = require('cors'); - const getPort = require('get-port'); const app = express(); port = await getPort(); diff --git a/src/plugins/piral-fetch/src/create.test.ts b/src/plugins/piral-fetch/src/create.test.ts index bd289ad17..3fe0757c6 100644 --- a/src/plugins/piral-fetch/src/create.test.ts +++ b/src/plugins/piral-fetch/src/create.test.ts @@ -3,6 +3,9 @@ */ import 'whatwg-fetch'; import { describe, it, expect, vitest, beforeAll, afterAll } from 'vitest'; +import getPort from 'get-port'; +import cors from 'cors'; +import express from 'express'; import { createFetchApi } from './create'; describe('Create fetch API Module', () => { @@ -10,9 +13,6 @@ describe('Create fetch API Module', () => { let port; beforeAll(async () => { - const express = require('express'); - const cors = require('cors'); - const getPort = require('get-port'); const app = express(); port = await getPort(); diff --git a/src/tooling/piral-cli/package.json b/src/tooling/piral-cli/package.json index e5fbb6859..8c8e58532 100644 --- a/src/tooling/piral-cli/package.json +++ b/src/tooling/piral-cli/package.json @@ -65,7 +65,6 @@ "is-interactive": "^2", "jju": "^1", "mime": "^4", - "open": "^10", "ora": "^8", "rimraf": "^6", "rc": "^1", @@ -75,6 +74,7 @@ "css-conflict-inspector": "^0.2", "dets": "^0.16", "kras": "^1", + "open": "^10", "typescript": "^5", "yargs": "^17" } diff --git a/src/tooling/piral-cli/src/common/browser.ts b/src/tooling/piral-cli/src/common/browser.ts index cdb665eb8..6fe5c23f3 100644 --- a/src/tooling/piral-cli/src/common/browser.ts +++ b/src/tooling/piral-cli/src/common/browser.ts @@ -1,9 +1,10 @@ import { log } from './log'; import { config } from './config'; -import { open } from '../external'; export async function openBrowserAt(address: string) { try { + const name = 'open'; + const open = await import(name).then((c) => c.default); await open(address, undefined); } catch (err) { log('failedToOpenBrowser_0170', err); diff --git a/src/tooling/piral-cli/src/common/http.test.ts b/src/tooling/piral-cli/src/common/http.test.ts index 0e8cdac30..f2ba3d25e 100644 --- a/src/tooling/piral-cli/src/common/http.test.ts +++ b/src/tooling/piral-cli/src/common/http.test.ts @@ -20,64 +20,62 @@ vitest.mock('../external', async () => { }; }, axios: { - default: { - post(url, _, options) { - const found = url === apiUrl; - const auth = options.headers.authorization === 'Basic 123'; + post(url, _, options) { + const found = url === apiUrl; + const auth = options.headers.authorization === 'Basic 123'; - if (errorRequest) { - return Promise.reject({ - request: {}, - }); - } else if (errorOther) { - return Promise.reject({ - message: 'error', - }); - } else if (errorResponse) { - return Promise.reject({ - response: { - status: 410, - statusText: 'Not Gone', - data: '{ "message": "This component is not available anymore." }', - }, - }); - } else if (errorResponse2) { - return Promise.reject({ - response: { - status: 410, - statusText: 'Not Gone', - data: { message: 'This component is not available anymore.' }, - }, - }); - } else if (!found) { - return Promise.reject({ - response: { - status: 404, - statusText: 'Not found', - }, - }); - } else if (!auth) { - return Promise.reject({ - response: { - status: 401, - statusText: 'Not authorized', - }, - }); - } else { - return Promise.resolve({ - status: 200, - statusText: 'OK', - }); - } - }, - get(url, options) { - if (errorOther) { - return Promise.reject({ - message: 'error', - }); - } - return Promise.resolve({ data: 'test' }); - }, + if (errorRequest) { + return Promise.reject({ + request: {}, + }); + } else if (errorOther) { + return Promise.reject({ + message: 'error', + }); + } else if (errorResponse) { + return Promise.reject({ + response: { + status: 410, + statusText: 'Not Gone', + data: '{ "message": "This component is not available anymore." }', + }, + }); + } else if (errorResponse2) { + return Promise.reject({ + response: { + status: 410, + statusText: 'Not Gone', + data: { message: 'This component is not available anymore.' }, + }, + }); + } else if (!found) { + return Promise.reject({ + response: { + status: 404, + statusText: 'Not found', + }, + }); + } else if (!auth) { + return Promise.reject({ + response: { + status: 401, + statusText: 'Not authorized', + }, + }); + } else { + return Promise.resolve({ + status: 200, + statusText: 'OK', + }); + } + }, + get(url, options) { + if (errorOther) { + return Promise.reject({ + message: 'error', + }); + } + return Promise.resolve({ data: 'test' }); }, }, FormData: ((await vitest.importActual('form-data')) as any).default, diff --git a/src/tooling/piral-cli/src/external/index.test.ts b/src/tooling/piral-cli/src/external/index.test.ts index c04f7a3f5..c95115720 100644 --- a/src/tooling/piral-cli/src/external/index.test.ts +++ b/src/tooling/piral-cli/src/external/index.test.ts @@ -8,7 +8,7 @@ describe('Externals module', () => { }); it('exports axios as a function', () => { - const axios = externals.axios.default; + const axios = externals.axios; expect(typeof axios).toBe('function'); }); @@ -46,9 +46,4 @@ describe('Externals module', () => { const tar = externals.tar; expect(tar).not.toBeUndefined(); }); - - it('exports the open module', () => { - const open = externals.open; - expect(open).not.toBeUndefined(); - }); }); diff --git a/src/tooling/piral-cli/src/external/index.ts b/src/tooling/piral-cli/src/external/index.ts index bec784864..70a5fc0f1 100644 --- a/src/tooling/piral-cli/src/external/index.ts +++ b/src/tooling/piral-cli/src/external/index.ts @@ -1,16 +1,15 @@ +import * as jju from 'jju'; +import * as tar from 'tar'; import glob from 'glob'; import FormData from 'form-data'; -import * as jju from 'jju'; import rc = require('rc'); import mime from 'mime'; import axios from 'axios'; import inquirer from 'inquirer'; import isInteractive from 'is-interactive'; -import open from 'open'; import getPort from 'get-port'; import ora from 'ora'; import chalk from 'chalk'; -import tar from 'tar'; import { rimraf } from 'rimraf'; import { getModulePath } from './resolve'; @@ -27,7 +26,6 @@ export { axios, mime, getPort, - open, jju, getModulePath, }; diff --git a/src/tooling/publish-microfrontend/package.json b/src/tooling/publish-microfrontend/package.json index 46b923e49..869c2abd1 100644 --- a/src/tooling/publish-microfrontend/package.json +++ b/src/tooling/publish-microfrontend/package.json @@ -37,9 +37,12 @@ }, "scripts": { "cleanup": "rimraf lib", - "build": "esbuild src/index.ts --bundle --outfile=lib/index.js --format=cjs --platform=node", + "build": "esbuild src/index.ts --bundle --outfile=lib/index.js --format=cjs --external:open --platform=node", "test": "echo \"Error: run tests from root\" && exit 1" }, + "dependencies": { + "open": "^10" + }, "devDependencies": { "@types/express": "^4", "@types/glob": "^8", @@ -58,7 +61,6 @@ "is-interactive": "^2", "jju": "^1", "mime": "^4", - "open": "^10", "ora": "^8", "rc": "^1", "rimraf": "^6", diff --git a/src/tooling/publish-microfrontend/src/browser.ts b/src/tooling/publish-microfrontend/src/browser.ts index 670551045..b96258700 100644 --- a/src/tooling/publish-microfrontend/src/browser.ts +++ b/src/tooling/publish-microfrontend/src/browser.ts @@ -1,8 +1,9 @@ -import open from 'open'; import { logFail } from './log'; export async function openBrowserAt(address: string) { try { + const name = 'open'; + const open = await import(name).then((c) => c.default); await open(address, undefined); } catch (err) { logFail('Failed to open the browser: %s', err);