Skip to content

Commit 3494c0d

Browse files
committed
chore: clean up package.json
1 parent c646d2f commit 3494c0d

35 files changed

+419
-327
lines changed

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"commandCenter.border": "#e7e7e799"
2323
},
2424
"peacock.color": "#832561",
25-
"eslint.validate": [
26-
"json"
27-
],
25+
"eslint.validate": ["json"],
2826
"files.exclude": {
2927
"**/.git": true,
3028
"**/.svn": true,

libs/mf-runtime/src/lib/loader/dynamic-federation.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ export type LoadRemoteModuleManifestOptions = {
164164
};
165165

166166
// eslint-disable-next-line @typescript-eslint/no-explicit-any
167-
export async function loadRemoteModule<T = any>(remoteName: string, exposedModule: string): Promise<T>;
168-
export async function loadRemoteModule<T = any>(options: LoadRemoteModuleOptions): Promise<T>
167+
export async function loadRemoteModule<T = any>(
168+
remoteName: string,
169+
exposedModule: string
170+
): Promise<T>;
171+
export async function loadRemoteModule<T = any>(
172+
options: LoadRemoteModuleOptions
173+
): Promise<T>;
169174
export async function loadRemoteModule<T = any>(
170175
optionsOrRemoteName: LoadRemoteModuleOptions | string,
171176
exposedModule?: string
@@ -179,10 +184,9 @@ export async function loadRemoteModule<T = any>(
179184
options = {
180185
type: 'manifest',
181186
remoteName: optionsOrRemoteName,
182-
exposedModule: exposedModule
183-
}
184-
}
185-
else {
187+
exposedModule: exposedModule,
188+
};
189+
} else {
186190
options = optionsOrRemoteName;
187191
}
188192

@@ -246,11 +250,13 @@ export function getManifest<T extends Manifest>(): T {
246250
return config as T;
247251
}
248252

249-
export async function initFederation(manifest: string | ManifestFile, skipRemoteEntries = false): Promise<void> {
253+
export async function initFederation(
254+
manifest: string | ManifestFile,
255+
skipRemoteEntries = false
256+
): Promise<void> {
250257
if (typeof manifest === 'string') {
251258
return loadManifest(manifest, skipRemoteEntries);
252-
}
253-
else {
259+
} else {
254260
return setManifest(manifest, skipRemoteEntries);
255261
}
256262
}

libs/mf-tools/src/lib/web-components/router-utils.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ export function endsWith(prefix: string): UrlMatcher {
2121
}
2222

2323
export function connectRouter(router: Router, useHash = false): void {
24-
25-
let url: string;
26-
if (!useHash) {
27-
url = `${location.pathname.substring(1)}${location.search}`;
28-
router.navigateByUrl(url);
29-
window.addEventListener('popstate', () => {
30-
router.navigateByUrl(url);
31-
});
32-
}
33-
else {
34-
url = `${location.hash.substring(1)}${location.search}`;
35-
router.navigateByUrl(url);
36-
window.addEventListener('hashchange', () => {
37-
router.navigateByUrl(url);
38-
});
39-
}
24+
let url: string;
25+
if (!useHash) {
26+
url = `${location.pathname.substring(1)}${location.search}`;
27+
router.navigateByUrl(url);
28+
window.addEventListener('popstate', () => {
29+
router.navigateByUrl(url);
30+
});
31+
} else {
32+
url = `${location.hash.substring(1)}${location.search}`;
33+
router.navigateByUrl(url);
34+
window.addEventListener('hashchange', () => {
35+
router.navigateByUrl(url);
36+
});
37+
}
4038
}

libs/mf/src/server/colors.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import crypt = require("crypto");
2-
import chalk = require("chalk");
3-
import wordWrap = require("word-wrap");
1+
import crypt = require('crypto');
2+
import chalk = require('chalk');
3+
import wordWrap = require('word-wrap');
44

55
function correctColor(color: string): string {
66
let result = '';
@@ -23,19 +23,21 @@ function correctColor(color: string): string {
2323
return result;
2424
}
2525

26-
export function print(prefix: string, prefixSize: number, message: string, error = false): void {
27-
28-
const hash = crypt.createHash("sha256")
29-
.update(prefix)
30-
.digest("hex");
31-
32-
const color = '#' + correctColor(hash.substring(6,12));
33-
34-
prefix = prefix.padEnd(prefixSize);
35-
36-
if (message.endsWith('\n')) {
37-
message = message.substring(0, message.length-1);
38-
}
26+
export function print(
27+
prefix: string,
28+
prefixSize: number,
29+
message: string,
30+
error = false
31+
): void {
32+
const hash = crypt.createHash('sha256').update(prefix).digest('hex');
33+
34+
const color = '#' + correctColor(hash.substring(6, 12));
35+
36+
prefix = prefix.padEnd(prefixSize);
37+
38+
if (message.endsWith('\n')) {
39+
message = message.substring(0, message.length - 1);
40+
}
3941

4042
const coloredPrefix = chalk.hex(color)(prefix) + ' | ';
4143
const lines = message.split('\n');

libs/mf/src/server/workspace.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@ export function readWorkspaceDef(): WorkspaceDef {
6363

6464
function toCliWorkspaceDef(def: NxOrCliWorkspaceDef): WorkspaceDef {
6565
const result: WorkspaceDef = { projects: {} };
66-
for(const key in def.projects) {
66+
for (const key in def.projects) {
6767
const project = def.projects[key];
6868

6969
if (typeof project === 'string') {
7070
const def = path.join(project, 'project.json');
7171
result.projects[key] = loadProjectDef(def);
72-
}
73-
else {
72+
} else {
7473
result.projects[key] = project;
7574
}
7675
}
77-
return result;
76+
return result;
7877
}
7978

8079
export function readProjectInfos(): ProjectInfo[] {
@@ -100,9 +99,9 @@ function loadProjectDef(projectDef: string): Project {
10099
def.architect = def.targets;
101100
}
102101
return def;
103-
}
104-
catch {
105-
throw new Error(`File ${projectDef} not found. Please start this command from your workspace root.`);
102+
} catch {
103+
throw new Error(
104+
`File ${projectDef} not found. Please start this command from your workspace root.`
105+
);
106106
}
107107
}
108-

libs/mf/src/utils/share-utils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ function getSecondaries(
133133
packagePath: string,
134134
key: string,
135135
shareObject: SharedConfig,
136-
exclude = [...DEFAULT_SECONARIES_SKIP_LIST],
136+
exclude = [...DEFAULT_SECONARIES_SKIP_LIST]
137137
): Record<string, SharedConfig> {
138-
139138
if (typeof includeSecondaries === 'object') {
140139
if (Array.isArray(includeSecondaries.skip)) {
141140
exclude = includeSecondaries.skip;
@@ -244,10 +243,10 @@ export function setInferVersion(infer: boolean): void {
244243
}
245244

246245
export function share(
247-
shareObjects: Config,
246+
shareObjects: Config,
248247
packageJsonPath = '',
249-
skip: string[] = DEFAULT_SECONARIES_SKIP_LIST): Config {
250-
248+
skip: string[] = DEFAULT_SECONARIES_SKIP_LIST
249+
): Config {
251250
if (!packageJsonPath) {
252251
packageJsonPath = cwd();
253252
}
@@ -288,7 +287,7 @@ export function share(
288287
packagePath,
289288
key,
290289
shareObject,
291-
skip,
290+
skip
292291
);
293292
addSecondaries(secondaries, result);
294293
}

libs/mf/src/utils/with-mf-plugin.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { DEFAULT_SECONARIES_SKIP_LIST, DEFAULT_SKIP_LIST, findRootTsConfigJson, shareAll } from './share-utils';
1+
import {
2+
DEFAULT_SECONARIES_SKIP_LIST,
3+
DEFAULT_SKIP_LIST,
4+
findRootTsConfigJson,
5+
shareAll,
6+
} from './share-utils';
27
import { SharedMappings } from './shared-mappings';
38
import { ModifyEntryPlugin } from './modify-entry-plugin';
49

@@ -9,15 +14,15 @@ export function withModuleFederationPlugin(config: unknown) {
914
delete config['sharedMappings'];
1015

1116
const skip = [
12-
...DEFAULT_SKIP_LIST,
17+
...DEFAULT_SKIP_LIST,
1318
...DEFAULT_SECONARIES_SKIP_LIST,
14-
...(config['skip'] || [])
19+
...(config['skip'] || []),
1520
];
1621

1722
delete config['skip'];
1823

1924
if (sharedMappings) {
20-
sharedMappings.filter(m => !skip.includes(m));
25+
sharedMappings.filter((m) => !skip.includes(m));
2126
}
2227

2328
const mappings = new SharedMappings();
@@ -57,7 +62,11 @@ export function withModuleFederationPlugin(config: unknown) {
5762
};
5863
}
5964

60-
function setDefaults(config: unknown, mappings: SharedMappings, skip: string[]) {
65+
function setDefaults(
66+
config: unknown,
67+
mappings: SharedMappings,
68+
skip: string[]
69+
) {
6170
if (!config['library']) {
6271
config['library'] = {
6372
type: 'module',
@@ -69,11 +78,14 @@ function setDefaults(config: unknown, mappings: SharedMappings, skip: string[])
6978
}
7079

7180
if (!config['shared']) {
72-
config['shared'] = shareAll({
73-
singleton: true,
74-
strictVersion: true,
75-
requiredVersion: 'auto',
76-
}, skip);
81+
config['shared'] = shareAll(
82+
{
83+
singleton: true,
84+
strictVersion: true,
85+
requiredVersion: 'auto',
86+
},
87+
skip
88+
);
7789
}
7890

7991
if (typeof config['shared'] === 'object') {

libs/native-federation-core/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,35 +326,35 @@ To make the polyfill to load your EcmaScript modules (bundles) in shim mode, ass
326326
327327
## React and Other CommonJS Libs
328328
329-
Native Federation uses Web Standards like EcmaScript Modules. Most libs and frameworks support them meanwhile. Unfortunately, React still uses CommonJS (und UMD). We do our best to convert these libs to EcmaScript Modules. In the case of React there are some challenges due to the dynamic way the React bundles use the ``exports`` object.
329+
Native Federation uses Web Standards like EcmaScript Modules. Most libs and frameworks support them meanwhile. Unfortunately, React still uses CommonJS (und UMD). We do our best to convert these libs to EcmaScript Modules. In the case of React there are some challenges due to the dynamic way the React bundles use the `exports` object.
330330
331-
As the community is moving to EcmaScrpt Modules, we expect that these issues will vanish over time. In between, we provide some solutions for dealing with CommonJS-based libraries using ``exports`` in a dynamic way.
331+
As the community is moving to EcmaScrpt Modules, we expect that these issues will vanish over time. In between, we provide some solutions for dealing with CommonJS-based libraries using `exports` in a dynamic way.
332332
333-
One of them is ``fileReplacemnts``:
333+
One of them is `fileReplacemnts`:
334334
335335
```javascript
336336
import { reactReplacements } from '@softarc/native-federation-esbuild/src/lib/react-replacements';
337337
import { createEsBuildAdapter } from '@softarc/native-federation-esbuild';
338338

339339
[...]
340340

341-
createEsBuildAdapter({
341+
createEsBuildAdapter({
342342
plugins: [],
343343
fileReplacements: reactReplacements.prod
344344
})
345345
```
346346
347-
Please note that the adapter comes with ``fileReplacements`` settings for React for both, ``dev`` mode and ``prod`` mode. For similar libraries you can add your own replacements. Also, using the ``compensateExports`` property, you can activate some additional logic for such libraries to make sure the exports are not lost
347+
Please note that the adapter comes with `fileReplacements` settings for React for both, `dev` mode and `prod` mode. For similar libraries you can add your own replacements. Also, using the `compensateExports` property, you can activate some additional logic for such libraries to make sure the exports are not lost
348348
349349
```javascript
350-
createEsBuildAdapter({
350+
createEsBuildAdapter({
351351
plugins: [],
352352
fileReplacements: reactReplacements.prod,
353-
compensateExports: [new RegExp('/my-lib/')]
354-
})
353+
compensateExports: [new RegExp('/my-lib/')],
354+
});
355355
```
356356
357-
The default value for ``compensateExports`` is ``[new RegExp('/react/')]``.
357+
The default value for `compensateExports` is `[new RegExp('/react/')]`.
358358
359359
## More: Blog Articles
360360

libs/native-federation-core/src/lib/config/configuration-context.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ export interface ConfigurationContext {
66
let _context: ConfigurationContext = {};
77

88
export function useWorkspace(workspaceRoot: string): void {
9-
_context = {..._context, workspaceRoot};
9+
_context = { ..._context, workspaceRoot };
1010
}
1111

1212
export function usePackageJson(packageJson?: string): void {
13-
_context = {..._context, packageJson};
13+
_context = { ..._context, packageJson };
1414
}
1515

16-
1716
export function getConfigContext(): ConfigurationContext {
1817
return _context;
1918
}

0 commit comments

Comments
 (0)