Description
I am using Pattern Lab Node v2.7.2
on Linux
, with Node v4.7.0
, using the Grunt
Edition.
See also pattern-lab/edition-node-grunt#12
Expected Behavior
Starter Kits are always loaded completely when running starterkit_manager.loadstarterkit()
via
core/scripts/postinstall.js
gulp patternlab:loadstarterkit --kit=yourkit
grunt patternlab:loadstarterkit --kit=yourkit
The output is
====[ Pattern Lab / Node - v2.7.2 ]====
Running "patternlab:loadstarterkit" (patternlab) task
Attempting to load starterkit from /home/tobi/tmp/edition-node-grunt/node_modules/starterkit-thymol-demo/dist
Deleting contents of ./source/ prior to starterkit load.
starterkit starterkit-thymol-demo loaded successfully.
Done.
Actual Behavior
The command line shows a success message, but only in case 1. and 2. the StarterKit files are actually copied.
The reason is that starterkit_manager
uses the ansynchnous variant of fs.copy(src, dest, callback)
. Typically a starterkit is < ~1MB of files, while modern SSD's have speeds of 300+ GB/s. Thus copying the whole starterkit takes only a few milliseconds at most.
In postinstall.js
(Method 1) there is a plugin discovery with synchronous file system access, which just takes enough time to complete copying the StarterKit.
With gulp
(method 2), the behaviour seems to be similar. Additionally there is some async handling in gulp
via done()
. Presumably similar to Method 1 shutting down the gulp process also takes enough time.
Lastly when using grunt, the process finishes before the callback is even executed (i.e. copying the files takes longer than processing the remaining code, which only consists of method returns).
The output is
====[ Pattern Lab / Node - v2.7.2 ]====
Running "patternlab:loadstarterkit" (patternlab) task
Attempting to load starterkit from /home/tobi/tmp/edition-node-grunt/node_modules/starterkit-thymol-demo/dist
Deleting contents of ./source/ prior to starterkit load.
Done.
As you can see the starterkit starterkit-thymol-demo loaded successfully.
is missing.
Steps to Reproduce
Try to install a starterkit via edition-node-grunt
. By default the source
folder will stay empty.
Now, after the line grunt.registerTask('patternlab')
insert const done = this.async();
into the callback function. Likewise, add
setTimeout(function () {
done();
}, 10000);
at the very end of the callback function.
Now the source files are copied from the StarterKit successfully.