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

chore: refactor @lwc/shared to improve module-graph [EXPERIMENT] #5162

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"@swc/helpers": "~0.5.15",
"@types/babel__core": "^7.20.5",
"@types/node": "^22.10.7",
"@vitest/coverage-v8": "^3.0.3",
"@vitest/coverage-v8": "^3.0.4",
"@vitest/eslint-plugin": "^1.1.25",
"@vitest/ui": "^3.0.3",
"@vitest/ui": "^3.0.4",
"bytes": "^3.1.2",
"es-module-lexer": "^1.6.0",
"eslint": "9.18.0",
Expand All @@ -71,7 +71,7 @@
"tslib": "^2.8.1",
"typescript": "5.4.5",
"typescript-eslint": "8.20.0",
"vitest": "^3.0.3"
"vitest": "^3.0.4"
},
"lint-staged": {
"*.{js,mjs,ts}": "eslint --cache",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import path from 'node:path';
import { describe } from 'vitest';
import { transformSync } from '@babel/core';
import { LWC_VERSION, HIGHEST_API_VERSION } from '@lwc/shared';
import { HIGHEST_API_VERSION } from '@lwc/shared/api-version';
import { LWC_VERSION } from '@lwc/shared/meta';
import { testFixtureDir } from '@lwc/test-utils-lwc-internals';
import plugin from '../index';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LWC_VERSION_COMMENT } from '@lwc/shared';
import { LWC_VERSION_COMMENT } from '@lwc/shared/meta';
import type { types, Visitor } from '@babel/core';
import type { BabelAPI, LwcBabelPluginPass } from './types';

Expand Down
3 changes: 2 additions & 1 deletion packages/@lwc/babel-plugin-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
import { basename, extname } from 'path';
import { addDefault, addNamed } from '@babel/helper-module-imports';
import { generateCustomElementTagName, getAPIVersionFromNumber } from '@lwc/shared';
import { getAPIVersionFromNumber } from '@lwc/shared/api-version';
import { generateCustomElementTagName } from '@lwc/shared/custom-element';
import {
COMPONENT_NAME_KEY,
LWC_PACKAGE_ALIAS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { addNamed } from '@babel/helper-module-imports';
import { DecoratorErrors } from '@lwc/errors';
import { APIFeature, getAPIVersionFromNumber, isAPIFeatureEnabled } from '@lwc/shared';
import { APIFeature, getAPIVersionFromNumber, isAPIFeatureEnabled } from '@lwc/shared/api-version';
import { DECORATOR_TYPES, LWC_PACKAGE_ALIAS, REGISTER_DECORATORS_ID } from '../constants';
import { generateError, isClassMethod, isGetterClassMethod, isSetterClassMethod } from '../utils';
import api from './api';
Expand Down
10 changes: 3 additions & 7 deletions packages/@lwc/compiler/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { CompilerValidationErrors, invariant } from '@lwc/errors';
import {
isUndefined,
isBoolean,
getAPIVersionFromNumber,
DEFAULT_SSR_MODE,
type CompilationMode,
} from '@lwc/shared';
import { DEFAULT_SSR_MODE, type CompilationMode } from '@lwc/shared/ssr';
import { isBoolean, isUndefined } from '@lwc/shared/language';
import { getAPIVersionFromNumber } from '@lwc/shared/api-version';
import type { InstrumentationObject } from '@lwc/errors';
import type { CustomRendererConfig } from '@lwc/template-compiler';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { vi, describe, it, expect } from 'vitest';
import { APIVersion, noop } from '@lwc/shared';
import { noop } from '@lwc/shared/language';
import { APIVersion } from '@lwc/shared/api-version';
import { transformSync } from '../transformer';
import type { TransformOptions } from '../../options';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { vi, describe, it, expect } from 'vitest';
import { noop } from '@lwc/shared';
import { noop } from '@lwc/shared/language';
import { transform, transformSync } from '../transformer';
import type { TransformOptions } from '../../options';

Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/transformers/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import babelObjectRestSpreadPlugin from '@babel/plugin-transform-object-rest-spr
import lockerBabelPluginTransformUnforgeables from '@locker/babel-plugin-transform-unforgeables';
import lwcClassTransformPlugin, { type LwcBabelPluginOptions } from '@lwc/babel-plugin-component';
import { normalizeToCompilerError, TransformerErrors } from '@lwc/errors';
import { isAPIFeatureEnabled, APIFeature } from '@lwc/shared';
import { isAPIFeatureEnabled, APIFeature } from '@lwc/shared/api-version';

import type { NormalizedTransformOptions } from '../options';
import type { TransformResult } from './shared';
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/transformers/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as path from 'path';

import { isString } from '@lwc/shared';
import { isString } from '@lwc/shared/language';
import { TransformerErrors, generateCompilerError, invariant } from '@lwc/errors';
import { compileComponentForSSR, compileTemplateForSSR } from '@lwc/ssr-compiler';

Expand Down
11 changes: 5 additions & 6 deletions packages/@lwc/engine-core/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import {
APIFeature,
ArrayPush,
assert,
create as ObjectCreate,
forEach,
freeze as ObjectFreeze,
isAPIFeatureEnabled,
isArray,
isFalse,
isFunction,
Expand All @@ -23,10 +20,12 @@ import {
isUndefined,
StringReplace,
toString,
sanitizeHtmlContent,
normalizeClass,
} from '@lwc/shared';
} from '@lwc/shared/language';

import * as assert from '@lwc/shared/assert';
import { sanitizeHtmlContent } from '@lwc/shared/overridable-hooks';
import { normalizeClass } from '@lwc/shared/normalize-class';
import { isAPIFeatureEnabled, APIFeature } from '@lwc/shared/api-version';
import { logError } from '../shared/logger';

import { invokeEventListener } from './invoker';
Expand Down
13 changes: 7 additions & 6 deletions packages/@lwc/engine-core/src/framework/base-bridge-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
* This module is responsible for creating the base bridge class BaseBridgeElement
* that represents the HTMLElement extension used for any LWC inserted in the DOM.
*/

import {
ArraySlice,
ArrayIndexOf,
ArraySlice,
create,
defineProperties,
defineProperty,
freeze,
getOwnPropertyNames,
getOwnPropertyDescriptors,
getOwnPropertyNames,
isNull,
isUndefined,
seal,
keys,
htmlPropertyToAttribute,
isNull,
} from '@lwc/shared';
seal,
} from '@lwc/shared/language';
import { htmlPropertyToAttribute } from '@lwc/shared/html-attributes';
import { ariaReflectionPolyfillDescriptors } from '../libs/reflection';
import { logWarn } from '../shared/logger';
import { getAssociatedVM } from './vm';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ import {
defineProperty,
entries,
freeze,
isAPIFeatureEnabled,
isFunction,
isNull,
isObject,
isUndefined,
KEY__SYNTHETIC_MODE,
keys,
setPrototypeOf,
APIFeature,
assert,
} from '@lwc/shared';
} from '@lwc/shared/language';

import { KEY__SYNTHETIC_MODE } from '@lwc/shared/keys';
import { APIFeature, isAPIFeatureEnabled } from '@lwc/shared/api-version';
import * as assert from '@lwc/shared/assert';
import { logError, logWarnOnce } from '../shared/logger';
import { getComponentTag } from '../shared/format';
import {
Expand All @@ -54,7 +53,8 @@ import { applyShadowMigrateMode } from './shadow-migration-mode';
import type { HTMLElementConstructor } from './base-bridge-element';
import type { Template } from './template';
import type { RefVNodes, ShadowSupportMode, VM } from './vm';
import type { Stylesheets, AccessibleElementProperties } from '@lwc/shared';
import type { Stylesheets } from '@lwc/shared/style';
import type { AccessibleElementProperties } from '@lwc/shared/aria';

/**
* This operation is called with a descriptor of an standard html property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { isNull, LWC_VERSION, LWC_VERSION_COMMENT_REGEX } from '@lwc/shared';
import { isNull } from '@lwc/shared/language';
import { LWC_VERSION, LWC_VERSION_COMMENT_REGEX } from '@lwc/shared/meta';

import { logError } from '../shared/logger';

import { report, ReportingEventId } from './reporting';
import type { Template } from './template';
import type { LightningElementConstructor } from './base-lightning-element';
import type { Stylesheet } from '@lwc/shared';
import type { Stylesheet } from '@lwc/shared/style';

let warned = false;

Expand Down
6 changes: 4 additions & 2 deletions packages/@lwc/engine-core/src/framework/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { assert, isFalse, isFunction, isUndefined, LOWEST_API_VERSION } from '@lwc/shared';
import { isFalse, isFunction, isUndefined } from '@lwc/shared/language';
import { LOWEST_API_VERSION } from '@lwc/shared/api-version';
import * as assert from '@lwc/shared/assert';

import { createReactiveObserver, unsubscribeFromSignals } from './mutation-tracker';

Expand All @@ -18,7 +20,7 @@ import type { LightningElementConstructor } from './base-lightning-element';
import type { Template } from './template';
import type { VNodes } from './vnodes';
import type { ReactiveObserver } from './mutation-tracker';
import type { APIVersion } from '@lwc/shared';
import type { APIVersion } from '@lwc/shared/api-version';

type ComponentConstructorMetadata = {
tmpl: Template;
Expand Down
3 changes: 2 additions & 1 deletion packages/@lwc/engine-core/src/framework/decorators/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { assert, isFunction, isNull, toString } from '@lwc/shared';
import { isFunction, isNull, toString } from '@lwc/shared/language';
import * as assert from '@lwc/shared/assert';
import { logError } from '../../shared/logger';
import { isInvokingRender, isBeingConstructed } from '../invoker';
import { componentValueObserved, componentValueMutated } from '../mutation-tracker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
defineProperty,
getOwnPropertyDescriptor,
isFalse,
} from '@lwc/shared';
} from '@lwc/shared/language';

import { assertNotProd, EmptyObject } from '../utils';
import { logError } from '../../shared/logger';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { assert, toString } from '@lwc/shared';
import { toString } from '@lwc/shared/language';
import * as assert from '@lwc/shared/assert';
import { trackTargetForMutationLogging } from '../mutation-logger';
import { componentValueObserved } from '../mutation-tracker';
import { isInvokingRender } from '../invoker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { assert } from '@lwc/shared';
import * as assert from '@lwc/shared/assert';
import { componentValueObserved } from '../mutation-tracker';
import { getAssociatedVM } from '../vm';
import { updateComponentValue } from '../update-component-value';
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/engine-core/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import {
defineProperties,
freeze,
getPrototypeOf,
htmlPropertyToAttribute,
isFunction,
isNull,
isUndefined,
keys,
} from '@lwc/shared';
} from '@lwc/shared/language';

import { RenderMode } from '../framework/vm';
import {
Expand All @@ -49,6 +48,7 @@ import type { PropType } from './decorators/register';
import type { LightningElementConstructor } from './base-lightning-element';
import type { Template } from './template';
import type { ShadowSupportMode } from '../framework/vm';
import { htmlPropertyToAttribute } from '@lwc/shared/html-attributes';

export interface ComponentDef {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { ArrayFrom } from '@lwc/shared';
import { ArrayFrom } from '@lwc/shared/language';

export const enum FragmentCacheKey {
HAS_SCOPED_STYLE = 1,
Expand Down
7 changes: 3 additions & 4 deletions packages/@lwc/engine-core/src/framework/freeze-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ import {
getOwnPropertyDescriptor,
isArray,
isUndefined,
KEY__SCOPED_CSS,
KEY__NATIVE_ONLY_CSS,
} from '@lwc/shared';
} from '@lwc/shared/language';
import { KEY__NATIVE_ONLY_CSS, KEY__SCOPED_CSS } from '@lwc/shared/keys';
import { logWarnOnce } from '../shared/logger';
import { onReportingEnabled, report, ReportingEventId } from './reporting';
import type { Template } from './template';
import type { Stylesheet, Stylesheets } from '@lwc/shared';
import type { Stylesheet, Stylesheets } from '@lwc/shared/style';

// See @lwc/engine-core/src/framework/template.ts
const TEMPLATE_PROPS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { isUndefined } from '@lwc/shared';
import { isUndefined } from '@lwc/shared/language';
import { getAssociatedVMIfPresent } from './vm';
import type { LightningElement } from './base-lightning-element';

Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/engine-core/src/framework/hot-swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { isFalse, isNull, isUndefined, flattenStylesheets } from '@lwc/shared';
import { isFalse, isNull, isUndefined } from '@lwc/shared/language';
import { flattenStylesheets, type Stylesheet, type Stylesheets } from '@lwc/shared/style';
import { scheduleRehydration, forceRehydration } from './vm';
import { isComponentConstructor } from './def';
import { markComponentAsDirty } from './component';
Expand All @@ -16,7 +17,6 @@ import { WeakMultiMap } from './weak-multimap';
import type { Template } from './template';
import type { LightningElementConstructor } from './base-lightning-element';
import type { VM } from './vm';
import type { Stylesheet, Stylesheets } from '@lwc/shared';

let swappedTemplateMap: WeakMap<Template, Template> = /*@__PURE__@*/ new WeakMap();
let swappedComponentMap: WeakMap<LightningElementConstructor, LightningElementConstructor> =
Expand Down
12 changes: 3 additions & 9 deletions packages/@lwc/engine-core/src/framework/html-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import {
AriaPropNameToAttrNameMap,
create,
forEach,
getPropertyDescriptor,
isUndefined,
keys,
REFLECTIVE_GLOBAL_PROPERTY_SET,
} from '@lwc/shared';
import { create, forEach, getPropertyDescriptor, isUndefined, keys } from '@lwc/shared/language';

import { AriaPropNameToAttrNameMap } from '@lwc/shared/aria';
import { REFLECTIVE_GLOBAL_PROPERTY_SET } from '@lwc/shared/html-attributes';
import { HTMLElementPrototype } from './html-element';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { ArrayPush, ArrayJoin, ArraySort, ArrayFrom, isNull, isUndefined } from '@lwc/shared';
import {
ArrayPush,
ArrayJoin,
ArraySort,
ArrayFrom,
isNull,
isUndefined,
} from '@lwc/shared/language';

import { assertNotProd } from './utils';

Expand Down
Loading