AnsweredAssumed Answered

Using NPM in a Share widget; Ignoring node_modules

Question asked by emlync on Apr 12, 2016
I am currently attempting to use npm, the nodeJS package manager, to manage and install various javascript libraries that I'm using for a Share widget. It works by defining a package.json and using the cli program to install various javascript files, can also acts as a build system to bundle a javascript application before putting it in a share widget.

However Maven chokes when you attempt to build and run the project (
mvn clean install -Prun
). The problem is that the
maven-resources-plugin
attempts to move and minify (using the YUI compressor) all of the Javascript code in node_modules, FYI this was discovered by running
mvn -X install
and observing the following:

<blockcode>
[DEBUG] file terminal-notifier has a filtered file extension
[DEBUG] filtering ../node_modules/node-notifier/vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier to ../target/amp/web/js/rubble-workflow/dashlets/widgets/node_modules/node-notifier/vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier
</blockcode>

It is rectified by moving the node_modules folder out of src tree.

It is possible to to get maven to ignore a file by it's file extension by using the
<configuration><configuration/>
block in maven-resources-plugin and setting a
<nonFilteredFileExtension>
. However, this doesn't help for files that don't have a file extension, like the code above.

Another method would be to use the <excludes> element in the <build> section of the Share pom file and I've tried this:

<blockcode>
<resources>
    <resource>
        <directory>src/main/amp/web/js/rubble-workflow/dashlets/widgets/</directory>
        <excludes>
            <exclude>
                node_modules/**
            </exclude>
        </excludes>
    </resource>
</resources>
</blockcode>

However, this leads to:

<blockcode>
[INFO] Installing /Users/emlyn/Documents/Rubble/Repo/rubble-workflow/alfresco-aio/rubble-workflow/rubble-workflow-share/target/rubble-workflow-share-1.0-SNAPSHOT.amp into /Users/emlyn/Documents/Rubble/Repo/rubble-workflow/alfresco-aio/rubble-workflow/share/target/share-1.0-SNAPSHOT
de.schlichtherle.truezip.fs.FsEntryNotFoundException: amp:file:/Users/emlyn/Documents/Rubble/Repo/rubble-workflow/alfresco-aio/rubble-workflow/rubble-workflow-share/target/rubble-workflow-share-1.0-SNAPSHOT.amp!/module.properties (no such entry)
</blockcode>

i.e. a broken amp file because module.properties is missing from the AMP.

Has anyone attempted this before? Any here know how to exclude a whole directory within the src/main/amp and not break the AMP?

Outcomes