Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import fs from 'fs/promises';
import path from 'path';

import {BUILD_NPM_EXPORTS_PATH} from '../../util/constants.mjs';
import {
BUILD_CSS_EXPORTS_PATH,
BUILD_NPM_EXPORTS_PATH,
} from '../../util/constants.mjs';
import getFlatName from '../../util/getFlatName.mjs';
import calculateFileHash from '../util/calculateFileHash.mjs';
import extractFileHash from '../util/extractFileHash.mjs';

export default async function writeCSSExportsLoaderModules(
projectExports,
Expand All @@ -29,23 +34,38 @@ export default async function writeCSSExportsLoaderModules(
async function writeCSSExportLoaderModule(webContextPath, moduleName) {
const flatModuleName = getFlatName(moduleName);

const cssLoaderPath = path.join(
BUILD_NPM_EXPORTS_PATH,
`${flatModuleName}.js`
const baseFlatModuleName = flatModuleName.substring(
0,
flatModuleName.length - 4
);

const cssFiles = await fs.readdir(path.join(BUILD_CSS_EXPORTS_PATH));

const cssFile = cssFiles.find((cssFile) =>
cssFile.startsWith(`${baseFlatModuleName}.(`)
);

const cssFileHash = extractFileHash(cssFile);

const source = `
const link = document.createElement('link');
link.setAttribute('rel','stylesheet');
link.setAttribute('type','text/css');
link.setAttribute('href', Liferay.ThemeDisplay.getPathContext() + '/o${webContextPath}/__liferay__/css/${flatModuleName}');
link.setAttribute('href', Liferay.ThemeDisplay.getPathContext() + '/o${webContextPath}/__liferay__/css/${baseFlatModuleName}.(${cssFileHash}).css');
if (Liferay.CSP) {
link.setAttribute('nonce', Liferay.CSP.nonce);
}

document.querySelector('head').appendChild(link);
`;

const hash = await calculateFileHash(source);

const cssLoaderPath = path.join(
BUILD_NPM_EXPORTS_PATH,
`${flatModuleName}.(${hash}).js`
);

await fs.mkdir(path.dirname(cssLoaderPath), {recursive: true});
await fs.writeFile(cssLoaderPath, source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function bundle(moduleName) {
const entryPoint = getEntryPoint(moduleName);

const esbuildConfig = {
entryNames: '[dir]/[name].([hash])',
entryPoints: [entryPoint],
loader: {
'.png': 'empty',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function bundle(
const esbuildConfig = {
alias: projectAlias,
bundle: true,
entryNames: '[dir]/[name].([hash])',
entryPoints: [entryPoint],
format: 'esm',
outdir: BUILD_MAIN_EXPORTS_PATH,
Expand Down Expand Up @@ -103,14 +104,17 @@ async function bundle(

const flatModuleName = getFlatName(moduleName);

await runEsbuild(esbuildConfig, flatModuleName);
const {metafile} = await runEsbuild(esbuildConfig, flatModuleName);
const {outputs} = metafile;

await relocateSourcemap(
path.join(
BUILD_MAIN_EXPORTS_PATH,
'exports',
`${flatModuleName}.js.map`
),
projectWebContextPath
);
await Promise.all([
...Object.keys(outputs).map(async (output) => {
if (output.endsWith('.map')) {
return relocateSourcemap(
path.join(output),
projectWebContextPath
);
}
}),
]);
}
22 changes: 11 additions & 11 deletions modules/_node-scripts/bundle/esbuild/bundleJavaScriptMain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default async function bundleJavaScriptMain(
const esbuildConfig = {
alias: projectAlias,
bundle: true,
entryNames: '[dir]/[name].([hash])',
entryPoints: [
...Object.keys(submodules).map((submoduleName) => ({
in: path.resolve(submodules[submoduleName]),
Expand Down Expand Up @@ -96,19 +97,18 @@ export default async function bundleJavaScriptMain(
);
}

await runEsbuild(esbuildConfig, 'main');
const {metafile} = await runEsbuild(esbuildConfig, 'main');
const {outputs} = metafile;

await Promise.all([
relocateSourcemap(
path.join(BUILD_MAIN_EXPORTS_PATH, 'index.js.map'),
projectWebContextPath
),
...Object.keys(submodules).map((submodule) =>
relocateSourcemap(
path.join(BUILD_MAIN_EXPORTS_PATH, `${submodule}.js.map`),
projectWebContextPath
)
),
...Object.keys(outputs).map(async (output) => {
if (output.endsWith('.map')) {
return relocateSourcemap(
path.join(output),
projectWebContextPath
);
}
}),
writeLanguageJSON(languageJSON),
]);
}
Expand Down
11 changes: 9 additions & 2 deletions modules/_node-scripts/bundle/esbuild/runEsbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import fs from 'fs/promises';
import path from 'path';

export default async function runEsbuild(esbuildConfig, configName) {
await Promise.all([
const [result] = await Promise.all([
doRunEsbuild(esbuildConfig, configName),
writeDebugEsbuildConfig(esbuildConfig, configName),
]);

return result;
}

async function doRunEsbuild(esbuildesbuildConfig, configName) {
let result;

const start = performance.now();

try {
await esbuild.build({
result = await esbuild.build({
define: {

// Flag to use React 16 instead of React 18. See render.tsx in frontend-js-react-web.
Expand All @@ -27,6 +31,7 @@ async function doRunEsbuild(esbuildesbuildConfig, configName) {
? 'true'
: 'false',
},
metafile: true,
minify: process.env.NODE_ENV === 'production',
...esbuildesbuildConfig,
});
Expand All @@ -40,6 +45,8 @@ async function doRunEsbuild(esbuildesbuildConfig, configName) {
console.log(
`⌛ Esbuild for ${configName} took: ${(lapse / 1000).toFixed(3)} s`
);

return result;
}

async function writeDebugEsbuildConfig(esbuildConfig, configName) {
Expand Down
3 changes: 2 additions & 1 deletion modules/_node-scripts/bundle/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default async function main() {
// CSS exports bundling

bundleCSSExports(projectExports),
writeCSSExportsLoaderModules(projectExports, projectWebContextPath),

// AMD bridging

Expand All @@ -100,5 +99,7 @@ export default async function main() {
),
]);

await writeCSSExportsLoaderModules(projectExports, projectWebContextPath);

await writeTimings(start, endConfig);
}
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": "7e554174eba462bfa15bd5385c4d0d373656ec6180b8419abcfbc8ad59176ed5"
},
"dependencies": {
"@babel/preset-env": "7.24.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<%@ include file="/init.jsp" %>

<%
String alloyEditorServletContextName = PortalWebResourcesUtil.getServletContext(
PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_ALLOYEDITOR
).getServletContextName();
String ckEditorServletContextName = PortalWebResourcesUtil.getServletContext(
PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR
).getServletContextName();
String editorName = (String)request.getAttribute(AlloyEditorConstants.ATTRIBUTE_NAMESPACE + ":editorName");
%>

Expand All @@ -16,18 +22,14 @@ String editorName = (String)request.getAttribute(AlloyEditorConstants.ATTRIBUTE_
>
<aui:link href='<%= PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + PortalWebResourcesUtil.getContextPath(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_ALLOYEDITOR) + "/alloyeditor/assets/alloy-editor-atlas.css") %>' rel="stylesheet" senna="temporary" type="text/css" />

<%
long javaScriptLastModified = PortalWebResourcesUtil.getLastModified(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_ALLOYEDITOR);
%>

<aui:script senna="temporary" type="text/javascript">
window.ALLOYEDITOR_BASEPATH =
'<%= PortalUtil.getPathProxy() + application.getContextPath() %>/alloyeditor/';
</aui:script>

<aui:script id='<%= namespace + "ckEditorScript" %>' senna="temporary" src='<%= HtmlUtil.escapeAttribute(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + PortalWebResourcesUtil.getContextPath(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR) + "/ckeditor/ckeditor.js", javaScriptLastModified)) %>' type="text/javascript"></aui:script>
<aui:script hashedFile="<%= true %>" id='<%= namespace + "ckEditorScript" %>' senna="temporary" src='<%= ckEditorServletContextName + "/ckeditor/ckeditor.js" %>' type="text/javascript"></aui:script>

<aui:script id='<%= namespace + "alloyEditorScript" %>' senna="temporary" src='<%= HtmlUtil.escapeAttribute(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + PortalWebResourcesUtil.getContextPath(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_ALLOYEDITOR) + "/alloyeditor/alloy-editor-no-ckeditor-min.js", javaScriptLastModified)) %>' type="text/javascript"></aui:script>
<aui:script hashedFile="<%= true %>" id='<%= namespace + "alloyEditorScript" %>' senna="temporary" src='<%= alloyEditorServletContextName + "/alloyeditor/alloy-editor-no-ckeditor-min.js" %>' type="text/javascript"></aui:script>

<liferay-util:dynamic-include key='<%= "com.liferay.frontend.editor.alloyeditor.web#" + editorName + "#additionalResources" %>' />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ page import="com.liferay.portal.kernel.util.GetterUtil" %><%@
page import="com.liferay.portal.kernel.util.HashMapBuilder" %><%@
page import="com.liferay.portal.kernel.util.HtmlUtil" %><%@
page import="com.liferay.portal.kernel.util.JavaConstants" %><%@
page import="com.liferay.portal.kernel.util.PortalUtil" %><%@
page import="com.liferay.portal.kernel.util.SessionClicks" %><%@
page import="com.liferay.portal.kernel.util.TextFormatter" %><%@
page import="com.liferay.portal.kernel.util.URLCodec" %><%@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<%@ include file="/init.jsp" %>

<%
String ckEditorServletContextName = PortalWebResourcesUtil.getServletContext(
PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR
).getServletContextName();
String editorName = (String)request.getAttribute(CKEditorConstants.ATTRIBUTE_NAMESPACE + ":editorName");
boolean inlineEdit = GetterUtil.getBoolean((String)request.getAttribute(CKEditorConstants.ATTRIBUTE_NAMESPACE + ":inlineEdit"));
String inlineEditSaveURL = GetterUtil.getString((String)request.getAttribute(CKEditorConstants.ATTRIBUTE_NAMESPACE + ":inlineEditSaveURL"));
Expand All @@ -22,14 +25,10 @@ String inlineEditSaveURL = GetterUtil.getString((String)request.getAttribute(CKE
}
</aui:style>

<%
long javaScriptLastModified = PortalWebResourcesUtil.getLastModified(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR);
%>

<aui:script senna="temporary" src='<%= HtmlUtil.escapeAttribute(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + PortalWebResourcesUtil.getContextPath(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR) + "/ckeditor/ckeditor.js", javaScriptLastModified)) %>' type="text/javascript"></aui:script>
<aui:script hashedFile="<%= true %>" senna="temporary" src='<%= ckEditorServletContextName + "/ckeditor/ckeditor.js" %>' type="text/javascript"></aui:script>

<c:if test="<%= inlineEdit && Validator.isNotNull(inlineEditSaveURL) %>">
<aui:script senna="temporary" src='<%= HtmlUtil.escapeAttribute(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + PortalWebResourcesUtil.getContextPath(PortalWebResourceConstants.RESOURCE_TYPE_EDITOR_CKEDITOR) + "/js/legacy/main.js", javaScriptLastModified)) %>' type="text/javascript"></aui:script>
<aui:script hashedFile="<%= true %>" senna="temporary" src='<%= ckEditorServletContextName + "/js/legacy/main.js" %>' type="text/javascript"></aui:script>
</c:if>

<liferay-util:dynamic-include key='<%= "com.liferay.frontend.editor.ckeditor.web#" + editorName + "#additionalResources" %>' />
Expand Down

This file was deleted.

Loading