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

Feature/declarative services #112

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ dist
!examples/*/dist
.idea
packages/**/coverage
packages/@pandino/*/dist
packages/@pandino/*/types
**/.DS_Store
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120
"printWidth": 160
}
26 changes: 21 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# Contributing to Pandino

## Environment

If you don't have it already, we recommend installing [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating).

Once installed, you can issue the following command to set up the appropriate NodeJS version:

```bash
nvm use
```

For package management we use [PNPM](https://pnpm.io/) instead of NPM. If you don't have it already, you can install it via:

```bash
npm i - g pnpm
```

## CMDs

```
# Install deps:
npm i
pnpm i

# Format code:
npm run format
pnpm run format

# Build all packages (excluding example project):
npm run build
pnpm run build

# Build single package, e.g.:
npm run build --workspace @pandino/pandino
# Run tests
pnpm run test
```

## Key Architectural Decisions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.9",
"@types/node": "^20.17.0",
"@types/node": "^20.17.1",
"prettier": "^3.3.3",
"rimraf": "^5.0.10"
},
Expand Down
13 changes: 3 additions & 10 deletions packages/@pandino/bundle-installer-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,13 @@ export default class PandinoBundleInstallerDomActivator implements BundleActivat

const callback = async () => {
if (documentDefinedManifest.hasAttribute('src')) {
locations = await this.fetcher!.fetch(
this.context!.getProperty(DEPLOYMENT_ROOT_PROP),
documentDefinedManifest.getAttribute('src') as string,
);
locations = await this.fetcher!.fetch(this.context!.getProperty(DEPLOYMENT_ROOT_PROP), documentDefinedManifest.getAttribute('src') as string);
} else {
locations = documentDefinedManifest ? JSON.parse(documentDefinedManifest.textContent!) : [];
}

const installList = locations.filter(
(manifestLocation) => !this.installedManifestList.includes(manifestLocation),
);
const uninstallList = this.installedManifestList.filter(
(manifestLocation) => !locations.includes(manifestLocation),
);
const installList = locations.filter((manifestLocation) => !this.installedManifestList.includes(manifestLocation));
const uninstallList = this.installedManifestList.filter((manifestLocation) => !locations.includes(manifestLocation));

await Promise.all(uninstallList.map((manifestLocation) => this.uninstall(manifestLocation)));
await Promise.all(installList.map((manifestLocation) => this.install(manifestLocation)));
Expand Down
6 changes: 1 addition & 5 deletions packages/@pandino/bundle-installer-nodejs/src/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export class Activator implements BundleActivator {
this.logger = context.getService<Logger>(this.loggerReference)!;
this.fetcherReference = context.getServiceReference<ManifestFetcher>(FRAMEWORK_MANIFEST_FETCHER)!;
this.fetcher = context.getService<ManifestFetcher>(this.fetcherReference)!;
this.installerService = new InstallerService(
this.context.getProperty(DEPLOYMENT_ROOT_PROP),
this.context,
this.logger,
);
this.installerService = new InstallerService(this.context.getProperty(DEPLOYMENT_ROOT_PROP), this.context, this.logger);
this.installerService.watch();
}

Expand Down
1 change: 1 addition & 0 deletions packages/@pandino/configuration-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@pandino/filters": "workspace:^",
"@pandino/pandino": "workspace:^",
"@pandino/pandino-api": "workspace:^",
"@pandino/persistence-manager-memory": "workspace:^",
"@pandino/persistence-manager-api": "workspace:^",
"@pandino/rollup-plugin-generate-manifest": "workspace:^",
"dts-bundle-generator": "^9.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export class MockBundleContext implements BundleContext {
private properties: Record<any, any> = {};
private serviceListeners: ServiceListener[] = [];
private readonly registrations: ServiceRegistration<any>[] = [];
private readonly refMap: Map<string[] | string, ServiceReference<any>> = new Map<
string[] | string,
ServiceReference<any>
>();
private readonly refMap: Map<string[] | string, ServiceReference<any>> = new Map<string[] | string, ServiceReference<any>>();
private readonly serviceMap: Map<ServiceReference<any>, any> = new Map<ServiceReference<any>, any>();
private bundle?: Bundle;

Expand Down Expand Up @@ -82,11 +79,7 @@ export class MockBundleContext implements BundleContext {
return Promise.resolve(undefined);
}

registerService<S>(
identifiers: string[] | string,
service: S,
properties: ServiceProperties = {},
): ServiceRegistration<S> {
registerService<S>(identifiers: string[] | string, service: S, properties: ServiceProperties = {}): ServiceRegistration<S> {
const ref: ServiceReference<any> = {
getBundle: () => this.getBundle(),
getProperties: () => properties,
Expand Down Expand Up @@ -143,10 +136,7 @@ export class MockBundleContext implements BundleContext {
return undefined as any;
}

trackService<S, T>(
identifierOrFilter: string,
customizer: Partial<ServiceTrackerCustomizer<S, T>>,
): ServiceTracker<S, T> {
trackService<S, T>(identifierOrFilter: string, customizer: Partial<ServiceTrackerCustomizer<S, T>>): ServiceTracker<S, T> {
return undefined as any;
}
}
19 changes: 3 additions & 16 deletions packages/@pandino/configuration-management/src/activator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { FRAMEWORK_EVALUATE_FILTER, FRAMEWORK_LOGGER, OBJECTCLASS } from '@pandino/pandino-api';
import type {
BundleActivator,
BundleContext,
Logger,
ServiceEvent,
ServiceListener,
ServiceReference,
ServiceRegistration,
} from '@pandino/pandino-api';
import type { BundleActivator, BundleContext, Logger, ServiceEvent, ServiceListener, ServiceReference, ServiceRegistration } from '@pandino/pandino-api';
import type { FilterEvaluator } from '@pandino/filters';
import type { ConfigurationAdmin } from '@pandino/configuration-management-api';
import { CONFIG_ADMIN_INTERFACE_KEY } from '@pandino/configuration-management-api';
Expand Down Expand Up @@ -42,9 +34,7 @@ export class Activator implements BundleActivator {

if (this.persistenceManagerReference) {
this.logger.info(
`Activating Configuration Management with immediate Persistence Manager Reference: ${this.persistenceManagerReference.getProperty(
OBJECTCLASS,
)}`,
`Activating Configuration Management with immediate Persistence Manager Reference: ${this.persistenceManagerReference.getProperty(OBJECTCLASS)}`,
);
this.persistenceManager = context.getService(this.persistenceManagerReference);
if (this.persistenceManager) {
Expand Down Expand Up @@ -107,10 +97,7 @@ export class Activator implements BundleActivator {
if (!this.pmUsed && this.context) {
this.configManager = new ConfigurationManager(this.context, this.logger!, this.evaluateFilter!, pm);
this.configAdmin = new ConfigurationAdminImpl(this.configManager, this.context.getBundle(), this.logger!);
this.configAdminRegistration = this.context.registerService<ConfigurationAdmin>(
CONFIG_ADMIN_INTERFACE_KEY,
this.configAdmin,
);
this.configAdminRegistration = this.context.registerService<ConfigurationAdmin>(CONFIG_ADMIN_INTERFACE_KEY, this.configAdmin);
this.configManager.initReferencesAddedBeforeManagerActivation();
this.context.addServiceListener(this.configManager);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ export class ConfigurationCache {
this.cm = cm;

this.persistenceManager.getProperties().forEach((props: ServiceProperties) => {
const configuration = new ConfigurationImpl(
this.cm,
props[SERVICE_PID],
this.context.getBundle().getLocation(),
props,
);
const configuration = new ConfigurationImpl(this.cm, props[SERVICE_PID], this.context.getBundle().getLocation(), props);
this.cache.set(props[SERVICE_PID], configuration);
});
}
Expand Down
Loading
Loading