Make JS Preprocessing Pluggable

mfer - December 31, 2008 - 16:45
Project:Drupal
Version:8.x-dev
Component:javascript
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Issue tags:JavaScript, Patch Spotlight
Description

Currently drupal_build_js_cache() preforms the JavaScript preprocessing to roll all of the js files into one file. While the method in core works well for most sites there are cases where developers would like to use other methods. For example, see the sf_cache module.

So, let's make JavaScript preprocessing a pluggable system like #259103: make pluggable password hashing framework more generic and use class auto-loading. and #331180: fix pluggable smtp/mail framework. Depending on when this goes in we may want to take advantage of handles in core. See http://www.garfieldtech.com/blog/handlers-rfc-2. I don't know of an actually issue for this, yet.

#1

mfer - December 31, 2008 - 18:20
Status:active» needs review

Here is my first pass at a pluggable JavaScript preprocessor.

AttachmentSizeStatusTest resultOperations
pluggable_js_preprocess-352951-1.patch6.29 KBIdleFailed: Failed to install HEAD.View details | Re-test

#2

mfer - January 7, 2009 - 23:41

Updated the interface name to JSPreprocessingInterface for consistency and fixed some comments.

AttachmentSizeStatusTest resultOperations
pluggable_js_preprocess-352951-2.patch6.31 KBIdleFailed: Failed to install HEAD.View details | Re-test

#3

drewish - January 7, 2009 - 23:55

Looks pretty good to me. Some formatting issues:

+   *
+   * @param $files
+   *  An array of JavaScript files.
+   *
+   * @return
+   *  html for preprocessed JavaScript files.

need to indent two spaces under the @s. That goes for just about all of the PHPDocs.

I know these bits are just getting moved but that's no reason not to improve them:

+    // Create the js/ within the files folder.

I'd say "Ensure there's a js directory with in the files directory that it is writable."

+    file_check_directory($jspath, FILE_CREATE_DIRECTORY);

I think you should also make it writable:
+    file_check_directory($jspath, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

#4

mfer - January 8, 2009 - 00:04

Thanks for the feedback, drewish. Updated.

AttachmentSizeStatusTest resultOperations
pluggable_js_preprocess-352951-4.patch6.38 KBIdleFailed: Failed to install HEAD.View details | Re-test

#5

System Message - January 8, 2009 - 03:25
Status:needs review» needs work

The last submitted patch failed testing.

#6

mfer - January 8, 2009 - 09:19
Status:needs work» needs review

Previous patch still applies with no issues for me.

#7

moshe weitzman - January 8, 2009 - 13:10

Any chance you can name preprocessing to something else? The theme system has kinda taken over that name.

#8

mfer - January 8, 2009 - 15:14

@moshe weitzman - I'm open to a name change. Drupal 6 already uses preprocess when refering to JavaScript so it would be a name change from an existing convention. Though, this topic is out of the scope of this patch which is just to take an existing system (with an existing name) and make it pluggable. It's primarily a re-factoring of code.

#9

Rob Loach - January 9, 2009 - 17:14
Status:needs review» needs work

Stuck up a note about this issue in the JavaScript Aggregator module: #356596: Port to Drupal 7.

Would be nice to have a test case. I'll see what I can do....

#10

Rob Loach - January 9, 2009 - 18:24

Had to make the preprocessor able to lazy load classes from different files. This meant moving JSPreprocessingInterface to common.inc, and changing "preprocess_js_system" to:

<?php
array(
 
'name' => 'DrupalPreprocessJS',
 
'file' => 'includes/preprocess.inc'
)
?>

....When the preprocessor is loaded, it will check "file" and include that file before creating the interface.

As for the tests, I got pretty far, but couldn't get it to work all the time. Help appreciated.

#11

Rob Loach - January 9, 2009 - 18:25

....... Forgot the patch.

AttachmentSizeStatusTest resultOperations
352951.patch9.57 KBIdleFailed: 8504 passes, 2 fails, 0 exceptionsView details | Re-test

#12

moshe weitzman - January 9, 2009 - 18:32

@rob - thats D6 style code. We no longer have to specify files, with the code registry.

#13

mfer - January 9, 2009 - 18:45

Why are we telling it what file to load? The registry takes care of loading files for classes and interfaces. If it's in the includes folder it just finds it. If it's a module you define what module files to scan. See http://drupal.org/node/224333#registry and http://api.drupal.org/api/group/registry/7.

#14

Rob Loach - January 9, 2009 - 18:53

Fixed the tests, but am having troubles with the registry. Assistance would be nice.

AttachmentSizeStatusTest resultOperations
352951.patch9.5 KBIdleFailed: 8485 passes, 0 fails, 1 exceptionView details | Re-test

#15

Rob Loach - January 9, 2009 - 18:58
Status:needs work» needs review

Ahhh, had to add common.test to the registry.

AttachmentSizeStatusTest resultOperations
352951.patch9.95 KBIdleFailed: Failed to apply patch.View details | Re-test

#16

mfer - January 10, 2009 - 16:53

I updated the test to remember the configured class for the JS Preprocessing and restore it after the test.

2 Questions:

  • Is it appropriate for tests/common.test to be listed in simpletest.info?
  • The layout of how we have an interface mixed between functions, is that appropriate? Or, should it be at the start or end of the file? Maybe someplace else?
AttachmentSizeStatusTest resultOperations
pluggable_js_preprocess-352951-16.patch10.52 KBIdleFailed: 9237 passes, 1 fail, 0 exceptionsView details | Re-test

#17

Rob Loach - January 14, 2009 - 21:06

Is it appropriate for tests/common.test to be listed in simpletest.info?

I'd love for it to be referenced somehow else, but can't think of anything since it's running on a different process and the class isn't loaded. Any other ideas would be awesome.

The layout of how we have an interface mixed between functions, is that appropriate? Or, should it be at the start or end of the file? Maybe someplace else?

I don't think it really matters, but we could move it to a different class if that's prefered.

#18

mfer - January 20, 2009 - 00:24

The attached patch moves including common.test to a javascript_test module in the tests folder. The javascript_test.info file includes the module. The javascript_test.module file is a dummy file. If we change core to not require module files this can go away. The setup function for the javascript tests enables this module.

AttachmentSizeStatusTest resultOperations
pluggable_js_preprocess-352951-18.patch12.07 KBIdleFailed: Failed to apply patch.View details | Re-test

#19

Rob Loach - January 25, 2009 - 02:59
Status:needs review» postponed

This is looking pretty much RTBC, but Crell just posted #363787: Plugins: Swappable subsystems for core, so I think we should see how it grows...

#20

Wim Leers - February 7, 2009 - 12:54

Great work! The same should be applied to CSS preprocessing.

Subscribing.

#21

sun - February 17, 2009 - 21:38
Issue tags:+JavaScript

#22

andreiashu - February 25, 2009 - 04:09

nice, subscribing

#23

mfer - July 31, 2009 - 17:28
Status:postponed» needs review

I don't think the plugins/handlers system will make it into D7. So, here is an update to the previous series of patches that store the class in a variable.

This is the overall layout of the functionality but the tests could use some work.

AttachmentSizeStatusTest resultOperations
plug-js-preprocess.patch7.47 KBIdleFailed: 11859 passes, 0 fails, 5 exceptionsView details | Re-test

#24

System Message - July 31, 2009 - 17:40
Status:needs review» needs work

The last submitted patch failed testing.

#25

Wim Leers - August 31, 2009 - 17:14
Status:needs work» needs review

Rerolled the patch. Didn't test it, just a straight re-roll.

AttachmentSizeStatusTest resultOperations
352951-25.patch7.81 KBIdleFailed: 12749 passes, 7 fails, 15 exceptionsView details | Re-test

#26

System Message - August 31, 2009 - 17:40
Status:needs review» needs work

The last submitted patch failed testing.

#27

SeanBannister - September 3, 2009 - 03:49

Sub

#28

sun - September 20, 2009 - 00:46
Version:7.x-dev» 8.x-dev
 
 

Drupal is a registered trademark of Dries Buytaert.