wdgdc / wordpress-theme

WDG WordPress Starter Theme
26 stars 9 forks source link

Gulpfile JS path parsing on Windows #7

Open dougaxe1 opened 7 years ago

dougaxe1 commented 7 years ago

gulpfile.babel.js contains JS path parsing logic which assumes *nix style slashes. On Windows 10, node 6.10.3, npm 3.10.10, npm gulp build will break the theme. The build pipeline removes all JS files in the dist directory before encountering this error leaving the dist directory empty.

The faulty logic appears in two locations:

// ...
    const getPaths = (path) => {
        const fileName = path.replace(project.js + '/', '').slice(0, -3);
// ...

and

// ...
    // read js files
    return gulp.src([`${project.js}/**/*.js`, `!_*.js`], { read: false })
        .pipe(vinylPaths((path) => {
            const fileName = path.replace(project.js + '/', '');
// ...

Example error on npm gulp build:

[23:14:38] rollup c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\assets\js\map.js 3.05 kB
{ Error: ENOENT: no such file or directory, mkdir 'c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\assets\dist\c:'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:923:18)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:12:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
    at mkdirpath (c:\Users\Douglas\Workspace\chemonics\wp-content\themes\chemonics\node_modules\rollup\src\utils\fs.js:11:3)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'c:\\Users\\Douglas\\Workspace\\chemonics\\wp-content\\themes\\chemonics\\assets\\dist\\c:' }
dougaxe1 commented 7 years ago

Possible fix is to replace slashes prior to slicing string:

const fileName = path.replace(/\\/g, '/').replace(project.js.replace(/\\/g, '/') + '/', '').slice(0, -3);