Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions modules/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
apps/google-maps
apps/microblogs

##
## ClayUI
##

#
# Clay CSS and Clay docs site ignores
#
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/.cache
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/public
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/react-docgen
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/static
/apps/frontend-js/frontend-js-clay-web/clay/packages/clay-css/src/js/**/*

##
## Generated Files
##
Expand Down
16 changes: 16 additions & 0 deletions modules/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
tmp/**
types/**/*.d.ts

##
## ClayUI
##

#
# Clay CSS and Clay docs site ignores
#
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/.cache
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/public
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/react-docgen
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/static
/apps/frontend-js/frontend-js-clay-web/clay/packages/clay-css/**/*.md
/apps/frontend-js/frontend-js-clay-web/clay/packages/clay-css/src/js/**/*.js
/apps/frontend-js/frontend-js-clay-web/clay/packages/clay-css/src/scss/bootstrap/**/*.scss


##
## Playwright Tests
##
Expand Down
5 changes: 5 additions & 0 deletions modules/.stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/.cache
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/public
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/react-docgen
/apps/frontend-js/frontend-js-clay-web/clay/packages/clayui.com/static
/apps/frontend-js/frontend-js-clay-web/clay/packages/clay-css/src/scss/bootstrap/**
16 changes: 9 additions & 7 deletions modules/_node-scripts/bundle/amd/writeExportBridges.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function writePackageJsons(projectDescription, projectExports) {
// package.json for those.

const uniquePackageNames = projectExports
.map(splitProjectExport)
.map((projectExport) => splitProjectExport(projectExport.moduleName))
.reduce((uniquePackageNames, {name, scope}) => {
const packageName = `${scope ? `${scope}/` : ''}${name}`;

Expand Down Expand Up @@ -77,23 +77,25 @@ async function writeExportBridge(
projectExport,
projectWebContextPath
) {
const {modulePath, name, scope} = splitProjectExport(projectExport);
const {moduleName} = projectExport;

const {modulePath, name, scope} = splitProjectExport(moduleName);
const {version} = projectScopeRequire(
`${scope ? `${scope}/` : ''}${name}/package.json`
);
const namespacedPackageName = getNamespacedPackageName(
projectExport,
moduleName,
projectDescription.name
);
const namespacedPackageId = `${namespacedPackageName}@${version}`;

// Compose bridge code

const importPath =
getPathToRoot(projectExport, modulePath) +
getPathToRoot(moduleName, modulePath) +
projectWebContextPath +
'/__liferay__/exports/' +
`${getFlatName(projectExport)}.js`;
`${getFlatName(moduleName)}.js`;

const hashedImportPath = hashPathForVariable(importPath);

Expand Down Expand Up @@ -126,7 +128,7 @@ Liferay.Loader.define(
await fs.writeFile(filePath, code, 'utf-8');
}

function getPathToRoot(projectExport, modulePath) {
function getPathToRoot(moduleName, modulePath) {

//
// Compute the relative position of the bridge related to the real ES
Expand All @@ -143,7 +145,7 @@ function getPathToRoot(projectExport, modulePath) {

let pathToRoot = '../..';

if (projectExport.startsWith('@')) {
if (moduleName.startsWith('@')) {
pathToRoot += '/..';
}

Expand Down
4 changes: 2 additions & 2 deletions modules/_node-scripts/bundle/amd/writeManifestJson.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export default async function writeManifestJson(

const groupedProjectExports = projectExports.reduce(
(groupedProjectExports, projectExport) => {
const {name, scope} = splitProjectExport(projectExport);
const {name, scope} = splitProjectExport(projectExport.moduleName);
const packageName = `${scope ? `${scope}/` : ''}${name}`;

if (!groupedProjectExports[packageName]) {
groupedProjectExports[packageName] = [];
}

groupedProjectExports[packageName].push(projectExport);
groupedProjectExports[packageName].push(projectExport.moduleName);

return groupedProjectExports;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default async function writeCSSExportsLoaderModules(

await Promise.all(
projectExports
.filter((moduleName) => moduleName.endsWith('.css'))
.map((moduleName) =>
.filter(({moduleName}) => moduleName.endsWith('.css'))
.map(({moduleName}) =>
writeCSSExportLoaderModule(projectWebContextPath, moduleName)
)
);
Expand Down
10 changes: 5 additions & 5 deletions modules/_node-scripts/bundle/esbuild/bundleCSSExports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default async function bundleCSSExports(projectExports) {

await Promise.all(
projectExports
.filter((moduleName) => moduleName.endsWith('.css'))
.map((moduleName) => bundle(moduleName))
.filter(({moduleName}) => moduleName.endsWith('.css'))
.map((projectExport) => bundle(projectExport))
);
}

async function bundle(moduleName) {
const entryPoint = getEntryPoint(moduleName);
async function bundle(projectExport) {
const entryPoint = getEntryPoint(projectExport);

const esbuildConfig = {
entryPoints: [entryPoint],
Expand Down Expand Up @@ -69,5 +69,5 @@ async function bundle(moduleName) {
);
}

return runEsbuild(esbuildConfig, getFlatName(moduleName));
return runEsbuild(esbuildConfig, getFlatName(projectExport.moduleName));
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export default async function bundleJavaScriptExports(

await Promise.all(
projectExports
.filter((moduleName) => !moduleName.endsWith('.css'))
.map((moduleName) =>
.filter(({moduleName}) => !moduleName.endsWith('.css'))
.map((projectExport) =>
bundle(
globalImports,
overridenPackageSymbols,
projectAlias,
projectWebContextPath,
moduleName
projectExport
)
)
);
Expand All @@ -50,9 +50,9 @@ async function bundle(
overridenPackageSymbols,
projectAlias,
projectWebContextPath,
moduleName
projectExport
) {
const entryPoint = getEntryPoint(moduleName);
const entryPoint = getEntryPoint(projectExport);

const esbuildConfig = {
alias: projectAlias,
Expand All @@ -61,7 +61,9 @@ async function bundle(
format: 'esm',
outdir: BUILD_MAIN_EXPORTS_PATH,
plugins: [
getExactAliasPlugin(globalImports, 'exports', [moduleName]),
getExactAliasPlugin(globalImports, 'exports', [
projectExport.moduleName,
]),
getExternalsPlugin(),
getImportBridgesPlugin(globalImports, overridenPackageSymbols),
],
Expand Down Expand Up @@ -99,9 +101,9 @@ async function bundle(
);
}

await writeExportBridge(overridenPackageSymbols, moduleName);
await writeExportBridge(overridenPackageSymbols, projectExport.moduleName);

const flatModuleName = getFlatName(moduleName);
const flatModuleName = getFlatName(projectExport.moduleName);

await runEsbuild(esbuildConfig, flatModuleName);

Expand Down
6 changes: 4 additions & 2 deletions modules/_node-scripts/bundle/esbuild/getEntryPoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import getFlatName from '../../util/getFlatName.mjs';
import getExportBridgePath from './getExportBridgePath.mjs';

export default function getEntryPoint(moduleName) {
export default function getEntryPoint(projectExport) {
let entryPoint;

const {moduleName, path} = projectExport;

if (moduleName.endsWith('.css')) {
entryPoint = {
in: moduleName,
in: path,
out: `css/${getFlatName(moduleName).replace(/\.css$/, '')}`,
};
}
Expand Down
9 changes: 7 additions & 2 deletions modules/_node-scripts/bundle/esbuild/writeExportBridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ import getExportBridgePath from './getExportBridgePath.mjs';
*/
export default async function writeExportBridge(
overridenPackageSymbols,
moduleName
moduleName,
filePath
) {
const symbols = getExportedSymbols(overridenPackageSymbols, moduleName);
const symbols = getExportedSymbols(
overridenPackageSymbols,
moduleName,
filePath
);

const exportBridgePath = getExportBridgePath(moduleName);

Expand Down
15 changes: 14 additions & 1 deletion modules/_node-scripts/configuration/getProjectExports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import projectScopeRequire from '../util/projectScopeRequire.mjs';
* [
* '@liferay/js-api',
* '@liferay/js-api/data-set',
* {
* moduleName: 'foo',
* path: './src/main/resources/META-INF/resources/foo.js'
* }
* ]
*/
export default function getProjectExports() {
Expand All @@ -21,5 +25,14 @@ export default function getProjectExports() {
return [];
}

return exports;
return exports.map((module) => {
if (typeof module === 'string') {
return {
moduleName: module,
path: module,
};
}

return module;
});
}
2 changes: 1 addition & 1 deletion modules/_node-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node-scripts": "./bin.js"
},
"com.liferay": {
"sha256": "35eb4297f0582256cf4a33a35e7084b37e34233d56fe57b6b49de75e3e23577d"
"sha256": "e28d966fadae2ca27ea72dce120e788c46d9ef05acdacf93e2d95077465ee508"
},
"dependencies": {
"@babel/preset-env": "7.24.7",
Expand Down
13 changes: 11 additions & 2 deletions modules/_node-scripts/test/jest/getJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function getJestConfig({rootDir = '<rootDir>'}) {
resolver: path.join(__dirname, 'resolver.js'),
setupFiles: [path.join(__dirname, 'setup.js')],
setupFilesAfterEnv: [path.join(__dirname, 'setupAfterEnv.js')],
testEnvironment,
testEnvironment: 'jsdom',
testEnvironmentOptions: {
url: 'http://localhost',
},
Expand All @@ -59,7 +59,16 @@ function getJestConfig({rootDir = '<rootDir>'}) {

/* eslint-disable sort-keys */
'\\.scss$': path.join(__dirname, 'transformSass.js'),
'.+': path.join(__dirname, 'transformBabel.js'),
'.+': [
'babel-jest',
{
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript',
],
},
],

/* eslint-enable sort-keys */
},
Expand Down
2 changes: 1 addition & 1 deletion modules/_node-scripts/test/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (!global.createRange) {
});
}

global.fetch = require('jest-fetch-mock');
require('jest-fetch-mock').enableMocks();

global.themeDisplay = global.Liferay.ThemeDisplay;

Expand Down
4 changes: 3 additions & 1 deletion modules/_node-scripts/test/jest/setupAfterEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

/* eslint-env jest */

import '@testing-library/jest-dom/extend-expect';

afterEach(() => {
global.fetch.mockRestore();
global.fetch?.mockRestore?.();
});

beforeEach(() => {
Expand Down
8 changes: 6 additions & 2 deletions modules/_node-scripts/util/createGlobalConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ export async function createGlobalConfig(hashOnly = false) {
projectDir
);

const exportedModuleNames = exports.map((item) =>
typeof item === 'string' ? item : item.moduleName
);

for (const symbolPackage in symbols) {
if (!exports.includes(symbolPackage)) {
if (!exportedModuleNames.includes(symbolPackage)) {
throw Error(
`❌ 'node-scripts.config.js' is invalid. Only declare symbols for packages your module 'exports'. Reading '${symbolPackage}'.`
);
}
}

allDependencies = {...allDependencies, ...dependencies};
allImports[name] = exports;
allImports[name] = exportedModuleNames;

if (submodules) {
allImports[name].push(
Expand Down
9 changes: 5 additions & 4 deletions modules/_node-scripts/util/getExportedSymbols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import projectScopeRequire from './projectScopeRequire.mjs';

export default function getExportedSymbols(
overridenPackageSymbols,
moduleName
moduleName,
filePath
) {
let symbols;

Expand All @@ -28,7 +29,7 @@ export default function getExportedSymbols(
}
}
else {
symbols = loadSymbols(moduleName);
symbols = loadSymbols(moduleName, filePath);
}
}
catch (error) {
Expand All @@ -40,8 +41,8 @@ export default function getExportedSymbols(
return symbols;
}

function loadSymbols(moduleName) {
const module = projectScopeRequire(moduleName);
function loadSymbols(moduleName, filePath) {
const module = projectScopeRequire(filePath ? filePath : moduleName);

const symbols = Object.keys(module).reduce((symbols, key) => {
symbols[key] = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"@clayui/alert": "3.148.0",
"@clayui/button": "3.144.1",
"@clayui/form": "3.148.0",
"@clayui/modal": "3.148.0",
"@clayui/alert": "*",
"@clayui/button": "*",
"@clayui/form": "*",
"@clayui/modal": "*",
"@liferay/accessibility-settings-state-web": "*",
"@liferay/cookies-banner-web": "*",
"@liferay/frontend-js-state-web": "*",
Expand Down
Loading