Skip to content

Commit

Permalink
Merge pull request #70 from MohamedLamineAllal/fix-issue-68
Browse files Browse the repository at this point in the history
Fix issue 68
  • Loading branch information
MohamedLamineAllal authored Jun 5, 2023
2 parents e201381 + 78196ad commit ce08480
Show file tree
Hide file tree
Showing 14 changed files with 2,345 additions and 2,174 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
fail-fast: false
matrix:
node:
- 14
- 16
- 18

Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/issue-68/__fixtures__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "testing-mix-issue68"
}
3 changes: 3 additions & 0 deletions e2e-tests/issue-68/__fixtures__/src/anotherTask/core.c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function anotherTask() {
console.log('Another task running ...');
}
167 changes: 167 additions & 0 deletions e2e-tests/issue-68/__fixtures__/webpack.mix.js
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',
}),
);
103 changes: 103 additions & 0 deletions e2e-tests/issue-68/issue68.test.js
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,
)}`,
);
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laravel-mix-glob",
"version": "2.0.1",
"version": "2.0.2",
"description": "Laravel mix extension that add support for globs usage with an extensive concise api. For a more natural boosted productivity and dynamic. Configure once and forget about adding the files each time.",
"keywords": [
"laravel",
Expand Down
Loading

0 comments on commit ce08480

Please sign in to comment.