-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from MohamedLamineAllal/fix-issue-68
Fix issue 68
- Loading branch information
Showing
14 changed files
with
2,345 additions
and
2,174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
node: | ||
- 14 | ||
- 16 | ||
- 18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "testing-mix-issue68" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function anotherTask() { | ||
console.log('Another task running ...'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
const mix = require('laravel-mix'); | ||
const path = require('path'); | ||
const { glb } = require('../../../dist/index'); | ||
|
||
/** | ||
* ////////////////////////////////////////////////////////////////// | ||
* Testing empty | ||
* ////////////////////////////////////////////////////////////////// | ||
*/ | ||
|
||
/** | ||
* ////////// args /////////// | ||
*/ | ||
|
||
/** | ||
* ::: using glb.replaceExtension() and glb.removeSpecifier() and path.resolve(), path.relative() | ||
*/ | ||
|
||
/** | ||
* With specifier | ||
*/ | ||
// relative path | ||
mix.js( | ||
glb.args('./src/empty/**/*.c.js', (src) => { | ||
let out = path.resolve( | ||
path.resolve(__dirname, './dist'), | ||
path.relative(path.resolve(__dirname, './src'), src), | ||
); | ||
out = glb.replaceExtension(out, '.js'); | ||
out = glb.removeSpecifier(out, 'c'); | ||
return [src, out]; | ||
}), | ||
); | ||
/** | ||
* Without specifier | ||
*/ | ||
mix.js( | ||
glb.args('./src/empty/**/*.js', (src) => { | ||
let out = path.resolve( | ||
path.resolve(__dirname, './dist'), | ||
path.relative(path.resolve(__dirname, './src'), src), | ||
); | ||
out = glb.replaceExtension(out, '.js'); | ||
return [src, out]; | ||
}), | ||
); | ||
|
||
/** | ||
* ::: using glb.mapOutput() | ||
*/ | ||
|
||
/** | ||
* With specifier | ||
*/ | ||
mix.js( | ||
glb.args('./src/empty/**/*.c.js', (src) => { | ||
const out = glb.mapOutput({ | ||
src, | ||
outConfig: glb.out({ | ||
baseMap: './src', | ||
outMap: './dist', | ||
extensionMap: '.js', | ||
specifier: 'c', | ||
}), | ||
}); | ||
return [src, out]; | ||
}), | ||
); | ||
|
||
/** | ||
* without specifier | ||
*/ | ||
mix.js( | ||
glb.args('./src/empty/**/*.js', (src) => { | ||
const out = glb.mapOutput({ | ||
src, | ||
outConfig: glb.out({ | ||
baseMap: './src', | ||
outMap: './dist', | ||
extensionMap: '.js', | ||
}), | ||
}); | ||
return [src, out]; | ||
}), | ||
); | ||
|
||
/** | ||
* ////////// src out arg /////////// | ||
*/ | ||
|
||
/** | ||
* src out | ||
* ---------- | ||
*/ | ||
|
||
/** | ||
* with specifier | ||
*/ | ||
mix.js( | ||
glb.src('./src/empty/**/*.c.js'), | ||
glb.out({ | ||
outMap: './dist', | ||
baseMap: './src', | ||
specifier: 'c', | ||
}), | ||
); | ||
|
||
/** | ||
* without specifier | ||
*/ | ||
mix.js( | ||
glb.src('./src/empty/**/*.js'), | ||
glb.out({ | ||
outMap: './dist', | ||
baseMap: './src', | ||
}), | ||
); | ||
|
||
/** | ||
* ////////// react (No args call) //////////////// | ||
*/ | ||
|
||
// with specifier | ||
mix | ||
.js( | ||
glb.src('./src/empty/**/*.c.jsx'), | ||
glb.out({ | ||
outMap: './dist', | ||
baseMap: './src', | ||
specifier: 'c', | ||
}), | ||
) | ||
.react(); | ||
|
||
// without specifier | ||
mix.js( | ||
glb.src('./src/empty/**/*.jsx'), | ||
glb.out({ | ||
outMap: './dist', | ||
baseMap: './src', | ||
}), | ||
); | ||
// NOTE: in PURPOSE i didn't add a .react(). | ||
// NOTE: Because that's something that you would do only one time. | ||
// NOTE: Multiple times would just override the old call options. | ||
// NOTE: Any such kind type of element would just add a general not file specific entry | ||
// NOTE: to webpackConfig. | ||
|
||
/** | ||
* //////////// arg ///////////////// | ||
*/ | ||
|
||
mix.js(glb.arg('./src/empty/**/*.js'), 'dist/empty'); | ||
|
||
/** | ||
* ////////////////////////////////////////////////////////////////// | ||
* Another task (not empty folder) | ||
* ////////////////////////////////////////////////////////////////// | ||
*/ | ||
mix.js( | ||
glb.src('./src/anotherTask/**/*.c.js'), | ||
glb.out({ | ||
outMap: './dist', | ||
baseMap: './src', | ||
specifier: 'c', | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* eslint-disable no-empty */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable indent */ | ||
/* eslint-disable no-async-promise-executor */ | ||
/* eslint-disable prefer-promise-reject-errors */ | ||
/* eslint-disable consistent-return */ | ||
|
||
/** | ||
* Issue 68 (https://github.com/MohamedLamineAllal/laravel-mix-glob/issues/68) | ||
* Empty folders throwing errors and blocking. Instead of not blocking. | ||
* | ||
* Correct behavior: | ||
* - No errors should be thrown when globs don't match anything. A warning only should go in place | ||
*/ | ||
|
||
const fs = require('node:fs'); | ||
const path = require('path'); | ||
const { runMixCommand } = require('../utils'); | ||
|
||
jest.setTimeout(30e3); | ||
|
||
let execOutput; | ||
|
||
beforeAll(async () => { | ||
try { | ||
console.log('Gonna run the command'); | ||
const rootDir = path.resolve(__dirname, './__fixtures__'); | ||
const successOut = await runMixCommand({ | ||
rootDir, | ||
outDir: './dist', | ||
}); | ||
execOutput = { | ||
state: 'success', | ||
data: successOut, | ||
}; | ||
console.log('command run with success', successOut); | ||
} catch (err) { | ||
execOutput = { | ||
state: 'error', | ||
data: err, | ||
}; | ||
console.log('Command run failed'); | ||
console.log(execOutput.data.cause); | ||
} | ||
}); | ||
|
||
const outDist = path.resolve(`${__dirname}/__fixtures__/dist/`); | ||
|
||
test('mix command run correctly', () => { | ||
expect(execOutput && execOutput.state).toBeTruthy(); | ||
}); | ||
|
||
test('mix command run successfully with no error', () => { | ||
expect(execOutput.state).toBe('success'); | ||
}); | ||
|
||
test('No `No matched files error`', () => { | ||
expect(execOutput.data.cause).toBeUndefined(); | ||
expect(JSON.stringify(execOutput.data).toLowerCase()).not.toContain( | ||
'Error: No matched files'.toLowerCase(), | ||
); | ||
}); | ||
|
||
test('Args: `No matched files for the args Glob` message', () => { | ||
expect(JSON.stringify(execOutput.data.stdout).toLowerCase()).toContain( | ||
'No matched files for the args Glob'.toLowerCase(), | ||
); | ||
}); | ||
|
||
test('src, out, arg: `No matched files for the Glob of arg of index` message', () => { | ||
expect(JSON.stringify(execOutput.data.stdout).toLowerCase()).toContain( | ||
'No matched files for the Glob of arg of index'.toLowerCase(), | ||
); | ||
}); | ||
|
||
test('another task core.js compiled correctly', async () => { | ||
const outPath = path.resolve(outDist, './anotherTask/core.js'); | ||
try { | ||
const fileContent = await fs.promises.readFile(outPath, { | ||
encoding: 'utf8', | ||
}); | ||
expect(fileContent.length > 0).toBeTruthy(); | ||
expect(fileContent).toContain('webpackBootstrap'); | ||
} catch (err) { | ||
console.log(err); | ||
if (err.code === 'ENOENT') { | ||
return fail( | ||
`Task blocked by globs no matching (output not found)!\n${JSON.stringify( | ||
err, | ||
null, | ||
4, | ||
)}`, | ||
); | ||
} | ||
fail( | ||
`Task blocked by globs no matching (File reading failed)!\n${JSON.stringify( | ||
err, | ||
null, | ||
4, | ||
)}`, | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.