In stead of manually installing the Javascript library, why not fetch and install it through composer.json on installation? This guarantees that the library is always present, the correct version and in the correct location.

Will try to provide a patch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

b.lammers created an issue. See original summary.

b.lammers’s picture

Created an addition for the README.txt to explain how to install the JavaScript library using Composer. Adding it to the module composer.json did not work (up to this point)

b.lammers’s picture

Assigned: b.lammers » Unassigned
Status: Active » Needs review
kevinquillen’s picture

I don't know if this can work automatically, generally from this point right here:

{
      "extra": {
        "installer-paths": {
          "web/libraries/{$name}": ["type:drupal-library"]
        }
      }
}

Your root is /web, whereas mine is /docroot.

b.lammers’s picture

I understand, put it in as an example, if the user adds lines to their composer.json manually I assumed the knowledge would be there to adapt it to the situation.

New patch added with a bit more obvious example of what needs to be replaced.

cashwilliams’s picture

Status: Needs review » Needs work

One more nitpick - I think it should make it clear it goes in the repositories section, and explain adding a repositories section if one doesn't exist.

KarimB’s picture

Status: Needs work » Needs review
FileSize
1.82 KB

Here is the patch based on #5. (Nice job @b.lammers!)
I added the whole repositories section, so it's more clear where to place the code.
I also deleted the line with ""codesnippet": " in the repositories section because the patch doesn't work with this line.

Best regards.

xmacinfo’s picture

+++ b/README.txt
@@ -10,6 +10,43 @@ This module requires the core CKEditor module and the CodeSnippet plugin from CK
+1. Ensure you have 'composer/installer' as a requirement in your main 'composer.json' file. If you do, skip to 4

The drupal-composer project (https://github.com/drupal-composer/drupal-project/blob/8.x/composer.json) uses :

composer/installers

should we change the instructions to use that one?

The rest of this patch is fine and tested using "composer/installers".

KarimB’s picture

Yes @xmacinfo, you're right. It should be "composer/installers" with a "s".

Here is the patch with the correction.

Best regards.

hugronaphor’s picture

The patch worked well for me as a guide to quickly set up the library but
do we really need to specify the version in:
5. Run 'composer require ckeditor/codesnippet:4.8.0' add the library itself to your composer required list.

I think this is not needed as the version is defined strictly above as part of the repository.

xmacinfo’s picture

Please have a look at :

https://ckeditor.com/cke4/addon/codesnippet

Codesnippet versions relate to CKEditor version. I believe 4.8.0 is the safest version for Drupal 8 CKEditor. But I did not test newer versions.

hugronaphor’s picture

No, I mean: we define the repository with "version": "4.8.0",
And if I do composer require ckeditor/codesnippet there is no way I can get anything other than the version defined above. Am I right?

xmacinfo’s picture

If you do composer require ckeditor/codesnippet the composer.json file will be rewritten and it won't, probably, use 4.8.0.

The problem here as that we use an external package. In the composer file we look specifically for the 4.8.0 ZIP file.

Loading external files not supported by Packagist can be tricky.

xmacinfo’s picture

Look for :

"url": "https://download.ckeditor.com/codesnippet/releases/codesnippet_4.8.0.zip",

…And replace the version number.

KarimB’s picture

You're absolutely right @hugronaphor !
Here is the patch without indicating the version in the composer require command.

Thx !

KarimB’s picture

Sorry, in the last the patch wasn't with the correct message number.
Now the correct one.

;)

KarimB’s picture

Here is the output code without specifying the version in the composer command composer require ckeditor/codesnippet and it looks that it's downloading the 4.8 version of the library as expected.

vagrant@test01 /v/w/d/drupal> composer require ckeditor/codesnippet
    1/2:	https://packages.drupal.org/8/drupal/provider-2018-4$455e123c7ebb607a782d678dcff4acf68e207446d3168299c7be637000529e53.json
    2/2:	https://packages.drupal.org/8/drupal/provider-2018-2$aecc0bc82404e56c5868652445d55396d743787a72381e89590fc02b973bb112.json
    Finished: success: 2, skipped: 0, failure: 0, total: 2
    1/3:	http://repo.packagist.org/p/provider-latest$038b582e963fca6d9df399cff74744bf66e8c75e690a14c4b5a001da12561105.json
    2/3:	http://repo.packagist.org/p/provider-2018-10$f62f8b08160564f40a8e14d78d81058429713c27e901e498faea2a7714082450.json
    3/3:	http://repo.packagist.org/p/provider-2016$e6d1ca276351f53a94691b33e09119c80d9e9b53c4f62232e2b73936b9f544d7.json
    Finished: success: 3, skipped: 0, failure: 0, total: 3
Using version ^4.8 for ckeditor/codesnippet
./composer.json has been updated
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
    1/1:	https://download.ckeditor.com/codesnippet/releases/codesnippet_4.8.0.zip
    Finished: success: 1, skipped: 0, failure: 0, total: 1
Package operations: 1 install, 0 updates, 0 removals
  - Installing ckeditor/codesnippet (4.8.0): Loading from cache
Writing lock file
Generating autoload files
PHP CodeSniffer Config installed_paths set to ../../drupal/coder/coder_sniffer/
> DrupalProject\composer\ScriptHandler::createRequiredFiles
kiwimind’s picture

+++ b/README.txt
@@ -10,6 +10,43 @@ This module requires the core CKEditor module and the CodeSnippet plugin from CK
+2. Run 'composer require composer/installer' to add this package to your installation. It will make sure modules and libraries end up in their correct location.

Should be `composer require composer/installers`.

Otherwise this seems fine, am currently using patch (with incorrect text).

kiwimind’s picture

Status: Needs review » Needs work
hugronaphor’s picture

kiwimind’s picture

Status: Needs review » Reviewed & tested by the community

Patch applied and instructions tested. Looks good to me.

Seems like an important addition too, as this module could be deemed unusable with some deployment processes.

Thank you.

kevinquillen’s picture

Instructions look good, just tried it and worked well. Sorry for the delay on this.

Anyone want to help out with maintaining?

anavarre’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.99 KB

Patch in #20 didn't apply for me.

$ patch -p1 < codesnippet-library-inclusion-2931474-20.patch
patching file README.txt
patch unexpectedly ends in middle of line

And

$ git apply -v codesnippet-library-inclusion-2931474-20.patch
error: corrupt patch at line 58

Here's a new patch that applies correctly, but there's no interdiff.

P.S.: too bad there's no Bower or NPM Code Snippet package available. This would be way more easier to require the library.

Waliur’s picture

#23 worked for me. Thanks anavarre!!!

AkashKumar07’s picture

Status: Needs review » Reviewed & tested by the community

#23 worked for me too. Moving to RTBC.

Thanks @anavarre

sinasalek’s picture

Here is the more maintainable way of doing this :
https://www.drupal.org/docs/8/modules/webform/webform-frequently-asked-q...

sinasalek’s picture

I created a patch for a more uptodate way and easier way
I'm using Drupal recommend composer template and the following patch just works
composer require drupal/codesnippet and that's it

sinasalek’s picture

here is the patch

voleger’s picture

Linking similar discussions.
Here the patch with the dependency on drupal-ckeditor-libraries-group/codesnippet package.
So from the developer side there no needs to provide additional instructions for install via Composer.
You can try how the approach works on the simplytest.me with module ckeditor_font https://simplytest.me/project/ckeditor_font/8.x-1.x

Webbeh’s picture

Status: Reviewed & tested by the community » Needs review

Given the comment in #23:

> P.S.: too bad there's no Bower or NPM Code Snippet package available. This would be way more easier to require the library.

Coupled with the work in #29, marking this as Needs Review for this proposed direction.

jigarius’s picture

I tried the patch in #29. It involved 2 steps.

First, apply the patch to the module using the "patches" section of the composer.json file.
Second, require the libraries using composer: "composer require drupal-ckeditor-libraries-group/codesnippet:4.14.0"

If this is the expected workflow, then it works. I was thinking that the libraries would be installed with the module itself.

voleger’s picture

The patch wouldn't make any effect on the module in the drupal project. Composer working with the metapackage information before applying the patches. So no-action-required approach would be available when the changes would be done in the codesnippet module repository. In that way drupal.org's packagist will tell for your project composer also to download required module dependency.

Check it out the ckeditor_font module which already uses that approach. Composer resolves library dependency.

jigarius’s picture

Status: Needs review » Reviewed & tested by the community

Cool. So, it works. After the patch has been committed, the library should automatically be installed.

solideogloria’s picture

Yeah, the patch has to be committed in order for it to be installed automatically.

jcnventura’s picture

Thanks for the patch, @voleger!

  • voleger authored 7dc6b6e on 8.x-1.x
    Issue #2931474 by KarimB, b.lammers, hugronaphor, sinasalek, voleger,...
jcnventura’s picture

Status: Reviewed & tested by the community » Fixed

Changed the patch a bit to cope with evolving library versions, and also to state the documented minimum (4.5.11). On my tests, it nevertheless installed 4.14.0.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.