@rws-framework/client 2.9.23 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_tools.js +30 -9
- package/cfg/build_steps/webpack/_rws_externals.js +10 -7
- package/package.json +1 -1
- package/rws.webpack.config.js +20 -34
- package/src/client/components.ts +29 -25
- package/src/components/_component.ts +15 -7
- package/src/components/_definitions.ts +2 -0
- package/src/components/_event_handling.ts +7 -0
- package/src/services/ConfigService.ts +3 -4
package/_tools.js
CHANGED
|
@@ -337,16 +337,37 @@ function getAllFilesInFolder(folderPath, ignoreFilenames = [], recursive = false
|
|
|
337
337
|
return files;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
function
|
|
340
|
+
function getRndInteger(min, max) {
|
|
341
|
+
return Math.floor(Math.random() * (max - min + 1) ) + min;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function printAddJs(scriptFileName, partedDirUrlPrefix, partedPrefix, onload = ''){
|
|
345
|
+
const sriptVarName = 'script' + getRndInteger(0, 1000);
|
|
346
|
+
return `
|
|
347
|
+
const ${sriptVarName} = document.createElement('script');
|
|
348
|
+
${sriptVarName}.src = '${partedDirUrlPrefix}/${partedPrefix}.${scriptFileName}.js';
|
|
349
|
+
${sriptVarName}.type = 'text/javascript';
|
|
350
|
+
|
|
351
|
+
document.body.appendChild(${sriptVarName});
|
|
352
|
+
|
|
353
|
+
${onload}
|
|
354
|
+
`
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev = true) {
|
|
358
|
+
let code = `if(!window.RWS_PARTS_LOADED){
|
|
359
|
+
${printAddJs('vendors', partedDirUrlPrefix, partedPrefix, `
|
|
360
|
+
window.RWS_PARTS_LOADED = true;
|
|
361
|
+
console.log('\x1b[1m[RWS]\x1b[0m', 'vendors injected for parted mode');
|
|
362
|
+
`)}
|
|
363
|
+
}`;
|
|
364
|
+
|
|
365
|
+
if(!isDev){
|
|
366
|
+
code = code.replace(/\n\s+/g, '');
|
|
367
|
+
}
|
|
368
|
+
|
|
341
369
|
return {
|
|
342
|
-
banner:
|
|
343
|
-
const script = document.createElement('script');
|
|
344
|
-
script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
|
|
345
|
-
script.type = 'text/javascript';
|
|
346
|
-
document.body.appendChild(script);
|
|
347
|
-
window.RWS_PARTS_LOADED = true;
|
|
348
|
-
console.log('\x1b[1m[RWS]\x1b[0m', 'vendors injected for parted mode');
|
|
349
|
-
}`.replace('\n', ''),
|
|
370
|
+
banner: code,
|
|
350
371
|
raw: true,
|
|
351
372
|
entryOnly: true,
|
|
352
373
|
include: `${partedPrefix}.client.js`
|
|
@@ -12,7 +12,7 @@ const _defaultOpts = {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts) => ({context, request}, callback) => {
|
|
15
|
+
const externals = (declaredCodeBase, nodeModules, automatedChunks, externalOptions = _defaultOpts) => ({context, request}, callback) => {
|
|
16
16
|
let theOptions = _defaultOpts;
|
|
17
17
|
|
|
18
18
|
if(externalOptions !== null){
|
|
@@ -36,11 +36,13 @@ const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts
|
|
|
36
36
|
|
|
37
37
|
const frontendDirs = [
|
|
38
38
|
codeBase,
|
|
39
|
-
__dirname
|
|
40
|
-
];
|
|
39
|
+
path.resolve(__dirname,'..','..','..')
|
|
40
|
+
];
|
|
41
41
|
|
|
42
42
|
const inFrontendContext = frontendDirs.some(dir => context.startsWith(dir)) ||
|
|
43
|
-
externalOptions._vars.frontendRequestContextCache.some(package => context.indexOf(package.request) > -1)
|
|
43
|
+
externalOptions._vars.frontendRequestContextCache.some(package => context.indexOf(package.request) > -1)
|
|
44
|
+
|
|
45
|
+
;
|
|
44
46
|
|
|
45
47
|
const patternInContextOrRequest = pattern => pattern.test(request) || pattern.test(context);
|
|
46
48
|
|
|
@@ -53,13 +55,14 @@ const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
externalOptions._vars.frontendRequestContextCache.push({request, context});
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
+
|
|
59
|
+
//handled as RWS async dependency
|
|
58
60
|
return callback();
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
externalOptions._vars.ignored.push({request, context});
|
|
62
|
-
|
|
64
|
+
|
|
65
|
+
//using require from vendors
|
|
63
66
|
callback(null, false);
|
|
64
67
|
}
|
|
65
68
|
|
package/package.json
CHANGED
package/rws.webpack.config.js
CHANGED
|
@@ -138,7 +138,18 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
138
138
|
|
|
139
139
|
const rwsInfoJson = outputDir + '/rws_info.json'
|
|
140
140
|
const automatedEntries = {};
|
|
141
|
-
|
|
141
|
+
let automatedChunks = {
|
|
142
|
+
client: config.entry,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// if(isParted){
|
|
146
|
+
// automatedChunks = {
|
|
147
|
+
// index: config.entry,
|
|
148
|
+
// client: __dirname + '/src/client.ts',
|
|
149
|
+
// };
|
|
150
|
+
|
|
151
|
+
// console.log({index: automatedChunks.client})
|
|
152
|
+
// }
|
|
142
153
|
|
|
143
154
|
const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', '@rws-framework/client']);
|
|
144
155
|
const foundRWSClientClasses = tools.findComponentFilesWithText(__dirname, '@RWSView', ['dist', 'node_modules']);
|
|
@@ -166,39 +177,13 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
166
177
|
});
|
|
167
178
|
|
|
168
179
|
if (isParted) {
|
|
169
|
-
WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix)));
|
|
180
|
+
// WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev)));
|
|
170
181
|
|
|
171
182
|
for (const pluginKey of Object.keys(rwsPlugins)){
|
|
172
183
|
const plugin = rwsPlugins[pluginKey];
|
|
173
184
|
partedComponentsLocations = await plugin.onComponentsLocated(partedComponentsLocations);
|
|
174
185
|
}
|
|
175
186
|
|
|
176
|
-
optimConfig = { splitChunks: {
|
|
177
|
-
cacheGroups: {
|
|
178
|
-
vendor: {
|
|
179
|
-
test: (module) => {
|
|
180
|
-
let importString = module.identifier();
|
|
181
|
-
|
|
182
|
-
if (importString.split('!').length > 2) {
|
|
183
|
-
importString = importString.split('!')[2];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const inNodeModules = importString.indexOf('node_modules') > -1;
|
|
187
|
-
const inVendorPackage = importString.indexOf(__dirname) > -1;
|
|
188
|
-
|
|
189
|
-
const inExecDir = importString.indexOf(executionDir) > -1;
|
|
190
|
-
const isNoPartedComponent = !Object.keys(automatedEntries).find(key => importString.indexOf(path.resolve(path.dirname(automatedEntries[key]))) > -1);
|
|
191
|
-
|
|
192
|
-
let isAvailableForVendors = (inNodeModules || inVendorPackage) && isNoPartedComponent;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return isAvailableForVendors;
|
|
196
|
-
},
|
|
197
|
-
name: 'vendors',
|
|
198
|
-
chunks: 'all',
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
} };
|
|
202
187
|
}
|
|
203
188
|
|
|
204
189
|
fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
|
|
@@ -237,11 +222,11 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
237
222
|
WEBPACK_AFTER_ACTIONS.push({
|
|
238
223
|
type: 'custom',
|
|
239
224
|
actionHandler: () => {
|
|
240
|
-
fs.writeFileSync(path.join(debugDir, '
|
|
241
|
-
fs.writeFileSync(path.join(debugDir, '
|
|
225
|
+
fs.writeFileSync(path.join(debugDir, 'in_vendors.json'), JSON.stringify(devExternalsVars.ignored, null, 2));
|
|
226
|
+
fs.writeFileSync(path.join(debugDir, 'rws_processed.json'), JSON.stringify(devExternalsVars.packed, null, 2));
|
|
242
227
|
fs.writeFileSync(path.join(debugDir, 'requestcache.json'), JSON.stringify(devExternalsVars.frontendRequestContextCache, null, 2));
|
|
243
228
|
|
|
244
|
-
console.log(chalk.yellow('[RWS BUILD] (after)'), `saved in: ${debugDir}
|
|
229
|
+
console.log(chalk.yellow('[RWS BUILD] (after)'), `packaging debug saved in: ${debugDir}`);
|
|
245
230
|
}
|
|
246
231
|
});
|
|
247
232
|
}
|
|
@@ -250,11 +235,12 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
250
235
|
WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS, dev: isDev }));
|
|
251
236
|
}
|
|
252
237
|
|
|
238
|
+
console.log('Webpack building with entrypoints:', Object.keys(automatedChunks));
|
|
239
|
+
|
|
253
240
|
|
|
254
241
|
let cfgExport = {
|
|
255
242
|
context: executionDir,
|
|
256
|
-
entry: {
|
|
257
|
-
client: config.entry,
|
|
243
|
+
entry: {
|
|
258
244
|
...automatedChunks
|
|
259
245
|
},
|
|
260
246
|
mode: isDev ? 'development' : 'production',
|
|
@@ -276,7 +262,7 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
276
262
|
rules: getRWSLoaders(__dirname, path.resolve(config.packageDir, 'node_modules'), tsConfigPath),
|
|
277
263
|
},
|
|
278
264
|
plugins: WEBPACK_PLUGINS,
|
|
279
|
-
externals: rwsExternals(executionDir, modules_setup, {
|
|
265
|
+
externals: rwsExternals(executionDir, modules_setup, automatedChunks, {
|
|
280
266
|
_vars: devExternalsVars
|
|
281
267
|
})
|
|
282
268
|
}
|
package/src/client/components.ts
CHANGED
|
@@ -5,37 +5,41 @@ import { RWSPlugin } from "../plugins/_plugin";
|
|
|
5
5
|
type RWSInfoType = { components: string[] };
|
|
6
6
|
|
|
7
7
|
async function loadPartedComponents(this: RWSClientInstance): Promise<RWSInfoType> {
|
|
8
|
-
this.assignClientToBrowser();
|
|
8
|
+
this.assignClientToBrowser();
|
|
9
|
+
|
|
10
|
+
return new Promise(async (resolve: (res: RWSInfoType) => void, reject: (res: Error | unknown) => void) => {
|
|
11
|
+
|
|
12
|
+
const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
|
|
13
|
+
const loadedComponents = [];
|
|
14
|
+
|
|
15
|
+
document.addEventListener(RWSViewComponent._EVENTS.component_define, (event: Event) => {
|
|
16
|
+
const customEvent = event as CustomEvent<string>;
|
|
17
|
+
|
|
18
|
+
console.log('defined', customEvent.detail);
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
loadedComponents.push(customEvent.detail);
|
|
11
21
|
|
|
12
|
-
|
|
22
|
+
console.log(loadedComponents.length, componentParts.components.length);
|
|
23
|
+
});
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
let compList = '';
|
|
26
|
+
|
|
27
|
+
componentParts.components.forEach((componentName: string, key: number) => {
|
|
28
|
+
const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
|
|
15
29
|
|
|
16
|
-
|
|
17
|
-
const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
|
|
18
|
-
componentsPromises.push(this.apiService.pureGet(partUrl, {
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'script'
|
|
21
|
-
} as any
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
compList += ` - \x1b[1m${componentParts.components[key]}:\x1b[0m component (${partUrl}) \n`;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
console.info(`\x1b[1m[RWS]\x1b[0m" \x1b[1mPARTED\x1b[0m" mode asynchronously added components: \n${compList}`);
|
|
30
|
+
compList += ` - \x1b[1m${componentParts.components[key]}:\x1b[0m component (${partUrl}) \n`;
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const script: HTMLScriptElement = document.createElement('script');
|
|
33
|
+
script.async = true;
|
|
34
|
+
script.src = partUrl;
|
|
35
|
+
script.type = 'text/javascript';
|
|
36
|
+
document.body.appendChild(script);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.info(`\x1b[1m[RWS]\x1b[0m" \x1b[1mPARTED\x1b[0m" mode asynchronously added components: \n${compList}`);
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
resolve(componentParts);
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
function defineAllComponents() {
|
|
@@ -11,7 +11,7 @@ import { applyConstructor, RWSInject } from './_decorator';
|
|
|
11
11
|
import TheRWSService from '../services/_service';
|
|
12
12
|
import { handleExternalChange } from './_attrs/_external_handler';
|
|
13
13
|
import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
|
|
14
|
-
import { on, $emitDown, observe } from './_event_handling';
|
|
14
|
+
import { on, $emitDown, observe, sendEventToOutside } from './_event_handling';
|
|
15
15
|
|
|
16
16
|
type ComposeMethodType<
|
|
17
17
|
T extends FoundationElementDefinition,
|
|
@@ -31,6 +31,11 @@ export interface IWithCompose<T extends RWSViewComponent> {
|
|
|
31
31
|
_depKeys: {[key: string]: string[]};
|
|
32
32
|
_externalAttrs: { [key:string]: string[] };
|
|
33
33
|
setExternalAttr: (componentName: string, key: string) => void
|
|
34
|
+
sendEventToOutside: <T>(eventName: string, data: T) => void
|
|
35
|
+
_EVENTS: {
|
|
36
|
+
component_define: string,
|
|
37
|
+
component_parted_load: string,
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
abstract class RWSViewComponent extends FoundationElement implements IRWSViewComponent {
|
|
@@ -48,6 +53,11 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
48
53
|
static _externalAttrs: { [key: string]: string[] } = {};
|
|
49
54
|
static _verbose: boolean = false;
|
|
50
55
|
|
|
56
|
+
static _EVENTS = {
|
|
57
|
+
component_define: 'rws:lifecycle:defineComponent',
|
|
58
|
+
component_parted_load: 'rws:lifecycle:loadPartedComponents',
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
@RWSInject(ConfigService, true) protected config: ConfigServiceInstance;
|
|
52
62
|
@RWSInject(DOMService, true) protected domService: DOMServiceInstance;
|
|
53
63
|
@RWSInject(UtilsService, true) protected utilsService: UtilsServiceInstance;
|
|
@@ -170,13 +180,11 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
sendEventToOutside<T>(eventName: string, data: T) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
bubbles: true,
|
|
176
|
-
composed: true
|
|
177
|
-
});
|
|
183
|
+
sendEventToOutside(eventName, data);
|
|
184
|
+
}
|
|
178
185
|
|
|
179
|
-
|
|
186
|
+
static sendEventToOutside<T>(eventName: string, data: T) {
|
|
187
|
+
sendEventToOutside(eventName, data);
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
private applyFileList(): void
|
|
@@ -43,6 +43,8 @@ export function defineComponent<T extends RWSViewComponent>(element: IWithCompos
|
|
|
43
43
|
throw new Error('RWS client not initialized');
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
element.sendEventToOutside<string>(element._EVENTS.component_define, element.definition.name);
|
|
47
|
+
|
|
46
48
|
richWindow.RWS.components[element.definition.name] = {
|
|
47
49
|
interface: composedComp,
|
|
48
50
|
component: element
|
|
@@ -31,4 +31,11 @@ export function observe(this: RWSViewComponent, callback: (component: RWSViewCom
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
observer.observe(this.getShadowRoot(), { childList: true, subtree: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function sendEventToOutside<T>(eventName: string, data: T): void
|
|
37
|
+
{
|
|
38
|
+
document.dispatchEvent(new CustomEvent<T>(eventName, {
|
|
39
|
+
detail: data,
|
|
40
|
+
}));
|
|
34
41
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import TheService from './_service';
|
|
2
2
|
import IRWSConfig from '../types/IRWSConfig';
|
|
3
3
|
import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
|
|
4
|
+
import { sendEventToOutside } from '../components/_event_handling';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
@@ -85,11 +86,9 @@ class ConfigService extends TheService {
|
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
__SENT_TO_COMPONENTS.push(tagName);
|
|
89
|
+
__SENT_TO_COMPONENTS.push(tagName);
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
detail: {tagName},
|
|
92
|
-
}));
|
|
91
|
+
sendEventToOutside<{tagName: string}>('rws_cfg_call', {tagName})
|
|
93
92
|
|
|
94
93
|
return new Promise((resolve) => {
|
|
95
94
|
const tick = () => {
|