Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.7.3 #730

Merged
merged 14 commits into from
Dec 11, 2024
Merged
6 changes: 6 additions & 0 deletions .github/workflows/twitter-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ jobs:
consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
- uses: smapiot/send-bluesky-post-action@v2
name: Bluesky post new release
with:
status: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}! ${{ github.event.release.html_url }} #microfrontends #piral #react #release"
bluesky-email: ${{ secrets.BLUESKY_EMAIL }}
bluesky-password: ${{ secrets.BLUESKY_PASSWORD }}
6 changes: 6 additions & 0 deletions .github/workflows/twitter-tip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ jobs:
consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
- uses: smapiot/send-bluesky-post-action@v2
name: Bluesky post daily tip
with:
status: "${{ steps.tweet.outputs.TIP }} #piral #dailytips #microfrontends"
bluesky-email: ${{ secrets.BLUESKY_EMAIL }}
bluesky-password: ${{ secrets.BLUESKY_PASSWORD }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Piral Changelog

## 1.7.3 (tbd)

- Fixed `pilet upgrade` command with `npm` client not changing *package.json*
- Fixed shared dependency list from website emulator to exclude legacy dependencies
- Fixed issue with relative app path in emulator package generated on Windows
- Added `--allow-self-signed` flag to `piral-cli` commands using HTTP requests
- Added support for `react-router` v7

## 1.7.2 (November 8, 2024)

- Fixed removal of `MutationEvent` in recent Chrome in `piral-blazor` (#724) by @dheid
Expand Down
20 changes: 20 additions & 0 deletions src/framework/piral-core/src/defaults/DefaultRouteSwitch_v7.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
//@ts-ignore
import { Routes, Route } from 'react-router';
import { RouteSwitchProps } from '../types';

export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
return (
<Routes {...props}>
{paths.map(({ path, Component }) => (
//@ts-ignore
<Route key={path} path={path} element={<Component />} />
))}
{
//@ts-ignore
<Route path="*" element={<NotFound />} />
}
</Routes>
);
};
DefaultRouteSwitch.displayName = 'DefaultRouteSwitch';
9 changes: 9 additions & 0 deletions src/framework/piral-core/src/defaults/DefaultRouter_v7.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react';
//@ts-ignore
import { BrowserRouter } from 'react-router';
import { RouterProps } from '../types';

export const DefaultRouter: React.FC<RouterProps> = ({ children, publicPath }) => {
return <BrowserRouter basename={publicPath}>{children}</BrowserRouter>;
};
DefaultRouter.displayName = 'DefaultRouter';
97 changes: 97 additions & 0 deletions src/framework/piral-core/src/defaults/navigator_v7.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
//@ts-ignore
import { UNSAFE_NavigationContext as RouterContext, Navigate, useLocation } from 'react-router';
import { NavigationApi } from '../types';

let _nav: any;
const _noop = () => {};

export function useRouterContext() {
return React.useContext(RouterContext);
}

export function useCurrentNavigation() {
const ctx: any = useRouterContext();
const location = useLocation();

React.useEffect(() => {
if (_nav) {
window.dispatchEvent(
new CustomEvent('piral-navigate', {
detail: {
location,
},
}),
);
}
}, [location]);

React.useEffect(() => {
_nav = ctx.navigator;

return () => {
_nav = undefined;
};
}, []);
}

export function createRedirect(to: string) {
return () => <Navigate to={to} />;
}

export function createNavigation(publicPath: string): NavigationApi {
const enhance = (info) => ({
...info,
location: {
get href() {
return _nav.createHref(info.location);
},
...info.location,
},
});

return {
get path() {
const loc = _nav ? _nav.location : location;
return loc.pathname;
},
get url() {
const loc = _nav ? _nav.location : location;
return `${loc.pathname}${loc.search}${loc.hash}`;
},
push(target, state) {
if (_nav) {
_nav.push(target, state);
}
},
replace(target, state) {
if (_nav) {
_nav.replace(target, state);
}
},
go(n) {
if (_nav) {
_nav.go(n);
}
},
block(blocker) {
if (!_nav) {
return _noop;
}
return _nav.block((transition) => blocker(enhance(transition)));
},
listen(listener) {
const handler = (e: CustomEvent) => listener(enhance(e.detail));

window.addEventListener('piral-navigate', handler);

return () => {
window.removeEventListener('piral-navigate', handler);
};
},
get router() {
return _nav;
},
publicPath,
};
}
11 changes: 10 additions & 1 deletion src/framework/piral-core/src/tools/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,26 @@ export function createDefaultState(imports: Array<string>, exports: Array<string
);

if (routerVersion < 6) {
// React Router v5
imports.push(
`import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v5.js';`,
`import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v5.js';`,
`import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v5.js'`,
);
} else {
} else if (routerVersion === 6) {
// React Router v6
imports.push(
`import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v6.js';`,
`import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v6.js';`,
`import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v6.js'`,
);
} else {
// React Router v7
imports.push(
`import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v7.js';`,
`import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v7.js';`,
`import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v7.js'`,
);
}

exports.push(`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"@pidoc/core": "^0.18.3"
"@pidoc/core": "^0.18.4"
}
}
21 changes: 20 additions & 1 deletion src/tooling/piral-cli/src/apps/add-piral-instance-pilet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
checkAppShellPackage,
ForceOverwrite,
copyPiralFiles,
config,
getCertificate,
getAgent,
} from '../common';

export interface AddPiralInstancePiletOptions {
Expand All @@ -39,6 +42,16 @@ export interface AddPiralInstancePiletOptions {
*/
selected?: boolean;

/**
* Defines a custom certificate for the website emulator.
*/
cert?: string;

/**
* Allow self-signed certificates.
*/
allowSelfSigned?: boolean;

/**
* The npm client to be used when scaffolding.
* @example 'yarn'
Expand All @@ -52,6 +65,8 @@ export const addPiralInstancePiletDefaults: AddPiralInstancePiletOptions = {
source: '.',
selected: false,
npmClient: undefined,
cert: undefined,
allowSelfSigned: config.allowSelfSigned,
};

export async function addPiralInstancePilet(baseDir = process.cwd(), options: AddPiralInstancePiletOptions = {}) {
Expand All @@ -61,6 +76,8 @@ export async function addPiralInstancePilet(baseDir = process.cwd(), options: Ad
source = addPiralInstancePiletDefaults.source,
selected = addPiralInstancePiletDefaults.selected,
app = addPiralInstancePiletDefaults.app,
cert = addPiralInstancePiletDefaults.cert,
allowSelfSigned = addPiralInstancePiletDefaults.allowSelfSigned,
} = options;

ensure('baseDir', baseDir, 'string');
Expand All @@ -72,6 +89,8 @@ export async function addPiralInstancePilet(baseDir = process.cwd(), options: Ad

const npmClient = await determineNpmClient(fullBase, defaultNpmClient);
const allEntries = await matchAnyPilet(fullBase, [source]);
const ca = await getCertificate(cert);
const agent = getAgent({ ca, allowSelfSigned });

const tasks = allEntries.map(async (entryModule) => {
const targetDir = dirname(entryModule);
Expand All @@ -80,7 +99,7 @@ export async function addPiralInstancePilet(baseDir = process.cwd(), options: Ad
if (piletJsonPath) {
const piletJsonDir = dirname(piletJsonPath);
const root = await findPiletRoot(piletJsonDir);
const packageName = await installPiralInstance(app, fullBase, root, npmClient, selected);
const packageName = await installPiralInstance(app, fullBase, root, npmClient, agent, selected);
const piralInfo = await readPiralPackage(root, packageName);
const isEmulator = checkAppShellPackage(piralInfo);

Expand Down
20 changes: 19 additions & 1 deletion src/tooling/piral-cli/src/apps/new-pilet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
defaultSchemaVersion,
piletJsonSchemaUrl,
ensure,
getCertificate,
getAgent,
} from '../common';

export interface NewPiletOptions {
Expand All @@ -47,6 +49,16 @@ export interface NewPiletOptions {
*/
source?: string;

/**
* Defines a custom certificate for the website emulator.
*/
cert?: string;

/**
* Allow self-signed certificates.
*/
allowSelfSigned?: boolean;

/**
* Determines if files should be overwritten by the scaffolding.
*/
Expand Down Expand Up @@ -110,6 +122,8 @@ export const newPiletDefaults: NewPiletOptions = {
bundlerName: 'none',
variables: {},
name: undefined,
cert: undefined,
allowSelfSigned: config.allowSelfSigned,
};

export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions = {}) {
Expand All @@ -126,6 +140,8 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions
variables = newPiletDefaults.variables,
npmClient: defaultNpmClient = newPiletDefaults.npmClient,
name = newPiletDefaults.name,
cert = newPiletDefaults.cert,
allowSelfSigned = newPiletDefaults.allowSelfSigned,
} = options;

ensure('baseDir', baseDir, 'string');
Expand All @@ -142,6 +158,8 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions

if (success) {
const npmClient = await determineNpmClient(root, defaultNpmClient);
const ca = await getCertificate(cert);
const agent = getAgent({ ca, allowSelfSigned });
const projectName = name || basename(root);

progress(`Scaffolding new pilet in %s ...`, root);
Expand Down Expand Up @@ -196,7 +214,7 @@ always-auth=true`,
);

const sourceName = source || `empty-piral@${cliVersion}`;
const packageName = await installPiralInstance(sourceName, fullBase, root, npmClient, true);
const packageName = await installPiralInstance(sourceName, fullBase, root, npmClient, agent, true);
const piralInfo = await readPiralPackage(root, packageName);
const isEmulator = checkAppShellPackage(piralInfo);
const { preScaffold, postScaffold, files, template: preSelectedTemplate } = getPiletsInfo(piralInfo);
Expand Down
Loading
Loading