Skip to content

Commit

Permalink
fix: context with symbols (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored Apr 8, 2021
1 parent 04fc3ca commit 6fc6874
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { join } from 'path';
import { statSync } from 'fs';

// @ts-ignore
import arrify from 'arrify';

const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;

/**
* @param {string|string[]} files
* @param {string} context
* @returns {string[]}
*/
export function parseFiles(files, context) {
return arrify(files).map(
(/** @type {string} */ file) =>
`${replaceBackslashes(context).replace(
UNESCAPED_GLOB_SYMBOLS_RE,
'\\$2'
)}/${replaceBackslashes(file)}`
return arrify(files).map((/** @type {string} */ file) =>
replaceBackslashes(join(context, file))
);
}

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/[symbols]/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = stuff
1 change: 1 addition & 0 deletions test/fixtures/[symbols]/symbols-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./error');
24 changes: 24 additions & 0 deletions test/symbols.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { join } from 'path';

import pack from './utils/pack';

describe('symbols', () => {
afterEach(() => {
jest.restoreAllMocks();
});

it('should return error', (done) => {
const compiler = pack(
'symbols',
{},
{ context: join(__dirname, 'fixtures/[symbols]') }
);

compiler.run((err, stats) => {
expect(err).toBeNull();
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(true);
done();
});
});
});

0 comments on commit 6fc6874

Please sign in to comment.