Skip to content

Commit

Permalink
Fix problem with TTW compilation of bundles.
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
thet committed Jan 7, 2020
1 parent 4e4f90e commit 9e7390e
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 13 deletions.
10 changes: 0 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,6 @@ For more information on the Plone resource registry see the documentation at:
- https://docs.plone.org/adapt-and-extend/theming/resourceregistry.html


Warning
-------

If you update ``r.js`` or ``less``, you will need to manually re-apply a patch that gives us cache busting resource downloads so we can build through the web.
See:

- https://github.com/plone/Products.CMFPlone/commit/2d3865805efc6b72dce236eb68e502d8c57717b6
- https://github.com/plone/Products.CMFPlone/commit/bd1f9ba99d1ad40bb7fe1c00eaa32b8884aae5e2


License
-------

Expand Down
1 change: 1 addition & 0 deletions news/58.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix problem with TTW compilation of bundles.
2 changes: 1 addition & 1 deletion src/plone/staticresources/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<metadata>
<version>3</version>
<version>4</version>
<dependencies>
<dependency>profile-plone.resource:default</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<field type="plone.registry.field.ASCII">
<title>URL of r.js</title>
</field>
<value>++plone++static/components/requirejs/bin/r.js</value>
<value>++plone++static/webcompiler/r.js</value>
</record>
<record name="plone.resources.lessc">
<field type="plone.registry.field.ASCII">
<title>URL of less.js</title>
</field>
<value>++plone++static/components/less/dist/less.js</value>
<value>++plone++static/webcompiler/less.js</value>
</record>
<records prefix="plone.resources/less"
interface='Products.CMFPlone.interfaces.IResourceRegistry'>
Expand Down
1 change: 1 addition & 0 deletions src/plone/staticresources/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ def getNonInstallableProfiles(self):
"plone.staticresources:uninstall",
"plone.staticresources.upgrades:2",
"plone.staticresources.upgrades:3",
"plone.staticresources.upgrades:4",
]
17 changes: 17 additions & 0 deletions src/plone/staticresources/static/webcompiler/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Scripts for TTW compilation of resources
========================================

These scripts are used for through-the-web compilation of resources in the ``@@resourceregistry-controlpanel``.

All resources are downloaded to the client browser and compiled there to bundles.
The bundles are then re-uploaded to the server and stored in a plone.resource directory in the ZODB.

If you update ``r.js`` or ``less``, you will need to manually re-apply a patch that gives us cache busting resource downloads so we can build through the web.
See:

- https://github.com/plone/plone.staticresources/commit/a8f7d5e0d9711423d95317ef3e1b9ed6df1609e9
- https://github.com/plone/plone.staticresources/commit/4effd0d5803a794267e6b433fe55e323002508cf


1) Get original resources
-------------------------
::
Expand All @@ -10,4 +22,9 @@ Scripts for TTW compilation of resources
git commit -m'Get original resources of less.js and r.js'


2) Apply patches
----------------
::
git apply less.js.patch
git apply r.js.patch

35 changes: 35 additions & 0 deletions src/plone/staticresources/static/webcompiler/less.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 6f0269fdaed7c12872e709c0a12c81e982f071da Mon Sep 17 00:00:00 2001
From: Johannes Raggam <thetetet@gmail.com>
Date: Sun, 5 Jan 2020 13:04:17 +0100
Subject: [PATCH] less.js for uncached resource downloads Original
commit by @vangheem:
https://github.com/plone/Products.CMFPlone/commit/bd1f9ba99d1ad40bb7fe1c00eaa32b8884aae5e2

---
src/plone/staticresources/static/webcompiler/less.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/plone/staticresources/static/webcompiler/less.js b/src/plone/staticresources/static/webcompiler/less.js
index fbbba14..e476c79 100644
--- a/src/plone/staticresources/static/webcompiler/less.js
+++ b/src/plone/staticresources/static/webcompiler/less.js
@@ -462,7 +462,15 @@ FileManager.prototype.loadFile = function loadFile(filename, currentDirectory, o
return;
}

- this.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
+ /* XXX Plone hack to always re-download resource TTW */
+ var url = href;
+ if(url.indexOf('?') === -1){
+ url += '?';
+ }else{
+ url += '&';
+ }
+ url = url + "bust=" + (new Date()).getTime();
+ this.doXHR(url, options.mime, function doXHRCallback(data, lastModified) {
// per file cache
fileCache[href] = data;

--
2.20.1

36 changes: 36 additions & 0 deletions src/plone/staticresources/static/webcompiler/r.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From c950dbe7c16533e5040cceb22db62db8f244bdd7 Mon Sep 17 00:00:00 2001
From: Johannes Raggam <thetetet@gmail.com>
Date: Sun, 5 Jan 2020 13:04:32 +0100
Subject: [PATCH] r.js for uncached resource downloads Original commit
by @vangheem:
https://github.com/plone/Products.CMFPlone/commit/2d3865805efc6b72dce236eb68e502d8c57717b6

---
src/plone/staticresources/static/webcompiler/r.js | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/plone/staticresources/static/webcompiler/r.js b/src/plone/staticresources/static/webcompiler/r.js
index ed177d8..d5e2573 100644
--- a/src/plone/staticresources/static/webcompiler/r.js
+++ b/src/plone/staticresources/static/webcompiler/r.js
@@ -25821,7 +25821,16 @@ define('build', function (require) {
d.resolve(require._cachedRawText[path]);
return d.promise;
} else {
- return file.readFileAsync(path, encoding).then(function (text) {
+
+ /* XXX Plone hack to always re-download resource TTW */
+ var url = path;
+ if(url.indexOf('?') === -1){
+ url += '?';
+ }else{
+ url += '&';
+ }
+ url = url + "bust=" + (new Date()).getTime();
+ return file.readFileAsync(url, encoding).then(function (text) {
require._cachedRawText[path] = text;
return text;
});
--
2.20.1

21 changes: 21 additions & 0 deletions src/plone/staticresources/upgrades/4.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:gs="http://namespaces.zope.org/genericsetup">

<gs:registerProfile name="4"
title="Change r.js and less.js paths for TTW compilation"
description='Configuration for version 4'
directory="profiles/4"
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION" />

<gs:upgradeSteps source="3"
destination="4"
profile="plone.staticresources:default">

<gs:upgradeDepends
title="Change r.js and less.js paths for TTW compilation"
import_profile="plone.staticresources.upgrades:4" />

</gs:upgradeSteps>

</configure>
1 change: 1 addition & 0 deletions src/plone/staticresources/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

<include file="2.zcml" />
<include file="3.zcml" />
<include file="4.zcml" />

</configure>
9 changes: 9 additions & 0 deletions src/plone/staticresources/upgrades/profiles/4/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<registry>
<record name="plone.resources.rjs">
<value>++plone++static/webcompiler/r.js</value>
</record>
<record name="plone.resources.lessc">
<value>++plone++static/webcompiler/less.js</value>
</record>
</registry>

0 comments on commit 9e7390e

Please sign in to comment.