Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6699da2
connect require fn to registerComponent fn
Sep 18, 2024
7b0838e
experiment: set event emitter to dynamic-import loader
Sep 19, 2024
704ece4
optimize amount of invokations __webpack_require__ function
Sep 23, 2024
cc5dfb8
fixing syntax errors after build
Sep 25, 2024
66f1e04
fixed breaked imports and syntax errors
Sep 25, 2024
1d28cc1
return empty string if component doesn't have deps
Sep 25, 2024
16d3e36
fixed build errors issued by updated loaders
Sep 26, 2024
f489153
fixed syntax errors
Oct 1, 2024
f05a361
removed ununsed handler
Oct 1, 2024
676b81f
applied layer of the components for emitting registration events
Oct 3, 2024
6361a3f
set layer for registerComponent as arg
Oct 3, 2024
9d13e83
removed debug logs
Oct 3, 2024
5a0e33a
fixed optional chaining if obj is undefined
Oct 3, 2024
c82d4ea
updated set-layer ts-transformer
Oct 4, 2024
60592eb
fixed incorrect reference to variable
Oct 4, 2024
5238f72
fix: pass real filePath as arg
Oct 4, 2024
302fbee
Merge branch 'v4' of github.com:V4Fire/Client into issues/1420
Oct 4, 2024
63f0dcb
removed unused handlers
Oct 7, 2024
d25d62e
updated loader dynamic-component-import
Oct 7, 2024
9f2db30
applied refactor fixes
Oct 8, 2024
d1a0df1
used getLayerName instead getOriginLayerFromPath
Oct 16, 2024
4cd14f1
fixed syntax error
Oct 16, 2024
ac8ee23
removed import by event from dynamic-component-import
Oct 17, 2024
c2fbe0e
limit imports only for page components
Oct 20, 2024
659159a
Merge branch 'v4' of github.com:V4Fire/Client into issues/1420
Oct 21, 2024
113411a
applied fixes of build and undefined layers
Oct 23, 2024
e3d9a39
Merge branch 'v4' of github.com:V4Fire/Client into issues/1420
Oct 24, 2024
597d129
fixed layer=undefined problem
Oct 27, 2024
d01c6a6
fixed regexp for isComponent
Oct 28, 2024
c132014
added async-render to i-static-page
Oct 28, 2024
9cbb09e
remove lazy invocations for interfaces
Oct 29, 2024
64fa0dc
use literal reg exp
Oct 29, 2024
140963f
polish code, fixed tabs and empty lines
Oct 30, 2024
56cfc08
removed unused \n
Oct 30, 2024
b9d919f
jsdoc for get-origin-layer helper
Oct 30, 2024
396622c
removed unused semicolon
Oct 30, 2024
bfd818b
removed empty lines
Oct 30, 2024
b9bba72
fixed lint issues
Oct 30, 2024
aa0fe4f
debug playwright tests
Oct 30, 2024
565d932
removed debug for tests
Oct 30, 2024
c264144
Merge branch 'v4' of github.com:V4Fire/Client into issues/1420
Oct 30, 2024
a0a9c20
debug: try to run tests without waiting for template
Oct 31, 2024
fbeb68e
debug: removed comments
Oct 31, 2024
f51207e
fixed a typo in variable name
Oct 31, 2024
dc86f4f
added comments to ts-transformer updates
Oct 31, 2024
5ba983b
refactor code; debug using config.projectName instead of getLayerName fn
Nov 5, 2024
1532035
removed unused helpers and apply code review suggestions
Nov 5, 2024
087705f
refactor: use @pzlr for getting layerName of component
Nov 5, 2024
107e50f
fixed dynamic loading of components
Nov 5, 2024
c4cde01
fixed incorrect layer calculation and regexp for name of component
Nov 5, 2024
7fbb509
Update src/core/component/functional/test/unit/getters.ts
DmitryYegorov Nov 5, 2024
52d4983
Merge branch 'v4' of https://github.com/V4Fire/Client into issues/1420
Nov 6, 2024
150b947
added registration of DataProvider and Daemons methods
Nov 7, 2024
7228c24
Удалил ненужное
bonkalol Nov 8, 2024
cbf5686
:art: eslint
bonkalol Nov 8, 2024
5a17c1f
Поправил тесты
bonkalol Nov 8, 2024
91b5f10
:wrench: appendChild to DOM proto
bonkalol Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/globals.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const
const
{csp, build, webpack, i18n} = config,
{config: pzlr} = require('@pzlr/build-core'),
{collectI18NKeysets} = include('build/helpers'),
{collectI18NKeysets, getLayerName} = include('build/helpers'),
{getDSComponentMods, getThemes, getDS} = include('build/ds');

const
Expand Down Expand Up @@ -58,7 +58,8 @@ module.exports = {
return $C(components).to({}).reduce((res, el, key) => {
res[key] = {
parent: JSON.stringify(el.parent),
dependencies: JSON.stringify(el.dependencies)
dependencies: JSON.stringify(el.dependencies),
layer: JSON.stringify(getLayerName(el.logic ?? el.index))
};

return res;
Expand Down
19 changes: 16 additions & 3 deletions build/graph/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const {
output,
cacheDir,
isStandalone,
tracer
tracer,
invokeByRegisterEvent,
getLayerName
} = include('build/helpers');

/**
Expand Down Expand Up @@ -244,12 +246,23 @@ async function buildProjectGraph() {
entry = path.resolve(tmpEntries, '../', name);
}

const entryPath = getEntryPath(entry);
let importScript;

const
componentName = component?.name ?? name,
isComponent = /^[bpg]-[\w-]+/.test(componentName);

if (webpack.ssr) {
str += `Object.assign(module.exports, require('${getEntryPath(entry)}'));\n`;
importScript = `Object.assign(module.exports, require('${entryPath}'));\n`;

} else {
str += `require('${getEntryPath(entry)}');\n`;
importScript = `require('${entryPath}');\n`;
}

str += isComponent ?
invokeByRegisterEvent(importScript, getLayerName(entry), componentName) :
importScript;
}

return str;
Expand Down
4 changes: 3 additions & 1 deletion build/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ Object.assign(
include('build/helpers/webpack'),
include('build/helpers/other'),
include('build/helpers/i18n'),
include('build/helpers/tracer')
include('build/helpers/tracer'),
include('build/helpers/invoke-by-register-component'),
include('build/helpers/layer-name')
);
37 changes: 37 additions & 0 deletions build/helpers/invoke-by-register-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*!
* V4Fire Client Core
* https://github.com/V4Fire/Client
*
* Released under the MIT license
* https://github.com/V4Fire/Client/blob/master/LICENSE
*/

'use strict';

/**
* Function incapsulates script to event handler that is being triggered when component with
* name `componentName` from `layerName` renders on the page.
*
* @param {string} script
* @param {string} layerName
* @param {string} componentName
* @returns {string}
*/
function invokeByRegisterEvent(script, layerName, componentName) {
if (script?.trim()?.length === 0) {
return script;
}

return `\n
(function () {
const {initEmitter} = require('core/component/event');

initEmitter.once('registerComponent.${layerName}.${componentName}', () => {
${script}
});
})();
\n
`;
}

exports.invokeByRegisterEvent = invokeByRegisterEvent;
42 changes: 42 additions & 0 deletions build/helpers/layer-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*!
* V4Fire Client Core
* https://github.com/V4Fire/Client
*
* Released under the MIT license
* https://github.com/V4Fire/Client/blob/master/LICENSE
*/

'use strict';

const {
config,
resolve: {rootDependencies}
} = require('@pzlr/build-core');

const
isPathInside = require('is-path-inside'),
fs = require('fs'),
path = require('path');

/**
* The function determines the package in which the module is defined and
* returns the name of this package from the `package.json` file
*
* @param {string} filePath
* @returns {string}
*/
function getLayerName(filePath) {
let layer = config.projectName;

for (let i = 0; i < rootDependencies.length; i++) {
if (isPathInside(fs.realpathSync(filePath), fs.realpathSync(rootDependencies[i]))) {
const pathPackageJson = path.resolve(fs.realpathSync(rootDependencies[i]), '..', 'package.json');
layer = require(pathPackageJson).name;
break;
}
}

return layer;
}

exports.getLayerName = getLayerName;
5 changes: 3 additions & 2 deletions build/monic/attach-component-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const

const
path = require('upath'),
graph = include('build/graph');
graph = include('build/graph'),
{invokeByRegisterEvent, getLayerName} = include('build/helpers');

const
decls = Object.create(null);
Expand Down Expand Up @@ -132,7 +133,7 @@ module.exports = async function attachComponentDependencies(str, filePath) {
expr = `TPLS['${dep}'] = require('${src}')['${dep}'];`;

} else {
expr = `require('${src}');`;
expr = invokeByRegisterEvent(`require('${src}');`, getLayerName(filePath), dep);
}

decl += `try { ${expr} } catch (err) { stderr(err); }`;
Expand Down
58 changes: 38 additions & 20 deletions build/ts-transformers/set-component-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
'use strict';

const ts = require('typescript');
const {validators} = require('@pzlr/build-core');
const {validators, config} = require('@pzlr/build-core');

const {getLayerName} = include('build/helpers');

/**
* @typedef {import('typescript').TransformationContext} Context
Expand All @@ -21,7 +23,6 @@ const {validators} = require('@pzlr/build-core');
*/

const
pathToRootRgxp = /(?<path>.+)[/\\]src[/\\]/,
isComponentPath = new RegExp(`\\/(${validators.blockTypeList.join('|')})-.+?\\/?`);

/**
Expand Down Expand Up @@ -53,12 +54,19 @@ const
* ```
*/
const setComponentLayerTransformer = (context) => (sourceFile) => {
if (!isInsideComponent(sourceFile.path)) {
const
{factory} = context,
isInitAppFile = sourceFile.path.endsWith('core/init/index.ts');

if (!isInsideComponent(sourceFile.path) && !isInitAppFile) {
return sourceFile;
}

const layer = getLayerName(sourceFile.path);
const {factory} = context;
let layer = getLayerName(sourceFile.path);

if (isInitAppFile) {
layer = config.projectName;
}

/**
* A visitor for the AST node
Expand All @@ -67,10 +75,32 @@ const setComponentLayerTransformer = (context) => (sourceFile) => {
* @returns {Node}
*/
const visitor = (node) => {
if (ts.isDecorator(node) && isComponentCallExpression(node)) {
const
expr = node.expression;
const
expr = node?.expression;

// Passing the value of the original layer as an argument to
// the createApp function for initializing the root component.
if (
ts.isCallExpression(node) &&
isInitAppFile &&
expr.escapedText === 'createApp'
) {

const updatedCallExpression = factory.createCallExpression(
factory.createIdentifier(expr.escapedText),
undefined,
[
...node.arguments,
factory.createStringLiteral(layer)
]
);

return updatedCallExpression;
}

// Passing the value of the package layer in which the component
// is defined to the @component decorator.
if (ts.isDecorator(node) && isComponentCallExpression(node)) {
if (!ts.isCallExpression(expr)) {
return node;
}
Expand Down Expand Up @@ -110,18 +140,6 @@ const setComponentLayerTransformer = (context) => (sourceFile) => {
// eslint-disable-next-line @v4fire/require-jsdoc
module.exports = () => setComponentLayerTransformer;

/**
* The function determines the package in which the module is defined and
* returns the name of this package from the `package.json` file
*
* @param {string} filePath
* @returns {string}
*/
function getLayerName(filePath) {
const pathToRootDir = filePath.match(pathToRootRgxp).groups.path;
return require(`${pathToRootDir}/package.json`).name;
}

/**
* Returns true if the specified path is within the context of the component
*
Expand Down
4 changes: 3 additions & 1 deletion components-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hash": "7b16e904c8d6785034161f61a4a4b42111ccf767585d6f643478eec974899aa8",
"hash": "9608b1e90d91053ae7e5f9db2002b150f358069aff02d61e172e1061eed9f959",
"data": {
"%data": "%data:Map",
"%data:Map": [
Expand Down Expand Up @@ -2889,6 +2889,7 @@
"b-textarea",
"b-select",
"b-select-date",
"b-traits-i-observe-dom-dummy",
"p-v4-dynamic-page1",
"p-v4-dynamic-page2",
"p-v4-dynamic-page3"
Expand Down Expand Up @@ -2938,6 +2939,7 @@
"b-textarea",
"b-select",
"b-select-date",
"b-traits-i-observe-dom-dummy",
"p-v4-dynamic-page1",
"p-v4-dynamic-page2",
"p-v4-dynamic-page3"
Expand Down
4 changes: 4 additions & 0 deletions fat-html.components-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
<<<<<<< HEAD
"hash": "848188ca4409395693c58ff85ada48b70cb4709ad07a56f9cbc9f191c8586a10",
=======
"hash": "63486c753ebbba9087e1f56ad93e610addf0677a5298daf4109b9ab9a703a942",
>>>>>>> fdd5344add3f10679f37d4bd0f50907fc8747a5c
"data": {
"%data": "%data:Map",
"%data:Map": [
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare const MODULE: string;
declare const PATH: Dictionary<CanUndef<string>>;
declare const PUBLIC_PATH: CanUndef<string>;

declare const COMPONENTS: Dictionary<{parent: string; dependencies: string[]}>;
declare const COMPONENTS: Dictionary<{parent: string; dependencies: string[]; layer: string}>;
declare const TPLS: Dictionary<Dictionary<Function>>;
declare const BLOCK_NAMES: CanUndef<string[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { AsyncOptions } from 'core/async';
import SyncPromise from 'core/promise/sync';

import type iItems from 'components/traits/i-items/i-items';
import DOM, { watchForIntersection } from 'components/friends/dom';
import DOM, { watchForIntersection, appendChild } from 'components/friends/dom';
import VDOM, { create, render } from 'components/friends/vdom';
import iVirtualScrollProps from 'components/base/b-virtual-scroll-new/props';

Expand Down Expand Up @@ -75,7 +75,7 @@ export * from 'components/super/i-data/i-data';

const $$ = symbolGenerator();

DOM.addToPrototype({watchForIntersection});
DOM.addToPrototype({watchForIntersection, appendChild});
VDOM.addToPrototype({create, render});

interface bVirtualScrollNew extends Trait<typeof iVirtualScrollHandlers> {}
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/p-v4-components-demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ package('p-v4-components-demo')
'b-select',
'b-select-date',

'b-traits-i-observe-dom-dummy',

'p-v4-dynamic-page1',
'p-v4-dynamic-page2',
'p-v4-dynamic-page3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

import iStaticPage, { component, prop, field, system, hook } from 'components/super/i-static-page/i-static-page';
import VDOM, * as VDOMAPI from 'components/friends/vdom';
import DataProvider, * as DataProviderAPI from 'components/friends/data-provider';

export * from 'components/super/i-static-page/i-static-page';

VDOM.addToPrototype(VDOMAPI);
DataProvider.addToPrototype(DataProviderAPI);

/**
* Page with component demos.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

import iInputText, { component } from 'components/super/i-input-text/i-input-text';

import Mask, * as MaskAPI from 'components/super/i-input-text/mask';

export * from 'components/super/i-input-text/i-input-text';

Mask.addToPrototype(MaskAPI);

@component({
functional: {
functional: true,
Expand Down
3 changes: 3 additions & 0 deletions src/components/super/i-static-page/i-static-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type bRouter from 'components/base/b-router/b-router';
import type iBlock from 'components/super/i-block/i-block';

import iPage, { component, field, system, computed, hook, watch } from 'components/super/i-page/i-page';
import AsyncRender, { iterate } from 'components/friends/async-render';

import createProviderDataStore, { ProviderDataStore } from 'components/super/i-static-page/modules/provider-data-store';

Expand All @@ -39,6 +40,8 @@ export * from 'components/super/i-static-page/modules/provider-data-store';

export * from 'components/super/i-static-page/interface';

AsyncRender.addToPrototype({iterate});

const
$$ = symbolGenerator();

Expand Down
1 change: 0 additions & 1 deletion src/core/component/functional/test/unit/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test.describe('functional component getters', () => {

test.beforeEach(async ({demoPage, page}) => {
await demoPage.goto();

await Promise.all([
Component.waitForComponentTemplate(page, 'b-functional-dummy'),
Component.waitForComponentTemplate(page, 'b-functional-button-dummy')
Expand Down
1 change: 1 addition & 0 deletions src/core/component/functional/test/unit/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test.describe('functional component', () => {
]);

target = await Component.createComponent<bFunctionalDummy>(page, 'b-functional-dummy', {stage: 'main'});

text = page.getByText(/Counter/);
button = page.getByRole('button');
});
Expand Down
Loading