From 1c2746aaeca8b9b3269a603426430864d7316741 Mon Sep 17 00:00:00 2001 From: thiscantbeserious Date: Thu, 1 Aug 2019 17:30:50 +0200 Subject: [PATCH 01/18] Add RegExp support and strict order of entries (+unit-tests) --- src/index.js | 36 +++++++++++++-------- test/index.js | 86 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 33 deletions(-) diff --git a/src/index.js b/src/index.js index 00b1321..e64e9cc 100644 --- a/src/index.js +++ b/src/index.js @@ -9,13 +9,20 @@ const IS_WINDOWS = platform() === 'win32'; // Helper functions const noop = () => null; -const matches = (key, importee) => { +const matches = (key, importee, isRegEx) => { if (importee.length < key.length) { return false; } if (importee === key) { return true; } + + if (isRegEx) { + if (key.test(importee) === true) { + return true; + } + } + const importeeStartsWithKey = (importee.indexOf(key) === 0); const importeeHasSlashAfterKey = (importee.substring(key.length)[0] === '/'); return importeeStartsWithKey && importeeHasSlashAfterKey; @@ -39,13 +46,11 @@ const normalizeId = (id) => { }; export default function alias(options = {}) { - const hasResolve = Array.isArray(options.resolve); - const resolve = hasResolve ? options.resolve : ['.js']; - const aliasKeys = hasResolve - ? Object.keys(options).filter(k => k !== 'resolve') : Object.keys(options); + const resolve = Array.isArray(options.resolve) ? options.resolve : ['.js']; + const entries = options.entries?options.entries:[]; // No aliases? - if (!aliasKeys.length) { + if (!entries || entries.length <= 0) { return { resolveId: noop, }; @@ -57,17 +62,23 @@ export default function alias(options = {}) { const importerId = normalizeId(importer); // First match is supposed to be the correct one - const toReplace = aliasKeys.find(key => matches(key, importeeId)); - - if (!toReplace || !importerId) { + const matchedEntry = entries.find(entry => matches(entry.find, importeeId, entry.isRegEx)); + if (!matchedEntry || !importerId) { return null; } - const entry = options[toReplace]; + const toReplace = matchedEntry.find; + const isDir = matchedEntry.isRegEx && toReplace.source + && (toReplace.source.substr(-1) === '/' + || toReplace.source.substr(-1) === '\\') ? + true:false; - let updatedId = normalizeId(importeeId.replace(toReplace, entry)); + const replacement = isDir?matchedEntry.replacement+path.sep:matchedEntry.replacement; + + let updatedId = normalizeId(importeeId.replace(toReplace, replacement)); if (isFilePath(updatedId)) { + const directory = posix.dirname(importerId); // Resolve file names @@ -89,10 +100,9 @@ export default function alias(options = {}) { // if alias is windows absoulate path return resolved path or // rollup on windows will throw: // [TypeError: Cannot read property 'specifier' of undefined] - if (VOLUME.test(entry)) { + if (VOLUME.test(replacement)) { return path.resolve(updatedId); } - return updatedId; }, }; diff --git a/test/index.js b/test/index.js index 44d84d3..a3f75c9 100644 --- a/test/index.js +++ b/test/index.js @@ -25,9 +25,11 @@ test('defaults', (t) => { test('Simple aliasing', (t) => { const result = alias({ - foo: 'bar', - pony: 'paradise', - './local': 'global', + entries: [ + {find:'foo', replacement:'bar'}, + {find:'pony', replacement:'paradise'}, + {find:'./local',replacement:'global'} + ] }); const resolved = result.resolveId('foo', '/src/importer.js'); @@ -39,10 +41,34 @@ test('Simple aliasing', (t) => { t.is(resolved3, 'global'); }); +test('RegExp aliasing', (t) => { + const result = alias({ + entries: [ + {find:new RegExp('fo.*'), replacement:'foobar2019', isRegEx:true}, + {find:new RegExp('.*pony.*'), replacement:'i/am/a/barbie/girl', isRegEx:true}, + {find:new RegExp('^test/$'), replacement:'this/is/strict', isRegEx:true} + ] + }); + + const resolved = result.resolveId('foobar', '/src/importer.js'); + const resolved2 = result.resolveId('im/a/little/pony/yes', '/src/importer.js'); + const resolved3 = result.resolveId('./test', '/src/importer.js'); + const resolved4 = result.resolveId('test', '/src/importer.js'); + const resolved5 = result.resolveId('test/', '/src/importer.js'); + + t.is(resolved, 'foobar2019'); + t.is(resolved2, 'i/am/a/barbie/girl'); + t.is(resolved3, null); + t.is(resolved4, null); + t.is(resolved5, 'this/is/strict'); +}); + test('Will not confuse modules with similar names', (t) => { const result = alias({ - foo: 'bar', - './foo': 'bar', + entries:[ + {find:'foo', replacement:'bar'}, + {find:'./foo', replacement:'bar'}, + ] }); const resolved = result.resolveId('foo2', '/src/importer.js'); @@ -56,8 +82,10 @@ test('Will not confuse modules with similar names', (t) => { test('Local aliasing', (t) => { const result = alias({ - foo: './bar', - pony: './par/a/di/se', + entries:[ + {find:'foo', replacement:'./bar'}, + {find:'pony', replacement:'./par/a/di/se'} + ] }); const resolved = result.resolveId('foo', '/src/importer.js'); @@ -73,8 +101,10 @@ test('Local aliasing', (t) => { test('Absolute local aliasing', (t) => { const result = alias({ - foo: '/bar', - pony: '/par/a/di/se.js', + entries:[ + {find:'foo', replacement:'/bar'}, + {find:'pony', replacement:'/par/a/di/se.js'} + ] }); const resolved = result.resolveId('foo', '/src/importer.js'); @@ -90,7 +120,9 @@ test('Absolute local aliasing', (t) => { test('Leaves entry file untouched if matches alias', (t) => { const result = alias({ - abacaxi: './abacaxi', + entries:[ + {find:'abacaxi', replacement:'./abacaxi'} + ] }); const resolved = result.resolveId('abacaxi/entry.js', undefined); @@ -100,8 +132,10 @@ test('Leaves entry file untouched if matches alias', (t) => { test('Test for the resolve property', (t) => { const result = alias({ - ember: './folder/hipster', resolve: ['.js', '.jsx'], + entries:[ + {find:'ember', replacement: './folder/hipster'}, + ] }); const resolved = result.resolveId('ember', posix.resolve(DIRNAME, './files/index.js')); @@ -111,7 +145,9 @@ test('Test for the resolve property', (t) => { test('i/am/a/file', (t) => { const result = alias({ - resolve: 'i/am/a/file', + entries:[ + {find:'resolve', replacement: 'i/am/a/file'} + ] }); const resolved = result.resolveId('resolve', '/src/import.js'); @@ -121,7 +157,9 @@ test('i/am/a/file', (t) => { test('i/am/a/local/file', (t) => { const result = alias({ - resolve: './i/am/a/local/file', + entries:[ + {find:'resolve', replacement: './i/am/a/local/file'} + ] }); const resolved = result.resolveId('resolve', posix.resolve(DIRNAME, './files/index.js')); @@ -132,7 +170,9 @@ test('i/am/a/local/file', (t) => { test('Platform path.resolve(\'file-without-extension\') aliasing', (t) => { // this what used in React and Vue const result = alias({ - test: path.resolve('./test/files/aliasMe'), + entries:[ + {find:'test', replacement:path.resolve('./test/files/aliasMe')} + ] }); const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js')); @@ -142,7 +182,9 @@ test('Platform path.resolve(\'file-without-extension\') aliasing', (t) => { test('Windows absolute path aliasing', (t) => { const result = alias({ - resolve: 'E:\\react\\node_modules\\fbjs\\lib\\warning', + entries:[ + {find:'resolve', replacement:'E:\\react\\node_modules\\fbjs\\lib\\warning'} + ] }); const resolved = result.resolveId('resolve', posix.resolve(DIRNAME, './files/index.js')); @@ -155,7 +197,9 @@ test('Windows absolute path aliasing', (t) => { test('Platform path.resolve(\'file-with.ext\') aliasing', (t) => { const result = alias({ - test: path.resolve('./test/files/folder/hipster.jsx'), + entries:[ + {find:'test', replacement:path.resolve('./test/files/folder/hipster.jsx')}, + ], resolve: ['.js', '.jsx'], }); @@ -181,10 +225,12 @@ const getModuleIdsFromBundle = (bundle) => { test('Works in rollup', t => rollup({ input: './test/files/index.js', plugins: [alias({ - fancyNumber: './aliasMe', - './anotherFancyNumber': './localAliasMe', - numberFolder: './folder', - './numberFolder': './folder', + entries:[ + {find:'fancyNumber', replacement:'./aliasMe'}, + {find:'./anotherFancyNumber', replacement: './localAliasMe'}, + {find:'numberFolder', replacement:'./folder'}, + {find:'./numberFolder', replacement: './folder'} + ] })], }).then(getModuleIdsFromBundle) .then((moduleIds) => { From 8c8a9f9b4933876f5ffd759d775a16c3a4cb33bd Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Thu, 1 Aug 2019 17:45:53 +0200 Subject: [PATCH 02/18] Updated README.md to reflect change in options --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7ca254..5d7a366 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ import alias from 'rollup-plugin-alias'; export default { input: './src/index.js', plugins: [alias({ - somelibrary: './mylocallibrary' + entries:[ + {find:'somelibrary', replacement: './mylocallibrary'} + ] })], }; ``` @@ -52,7 +54,9 @@ export default { input: './src/index.js', plugins: [alias({ resolve: ['.jsx', '.js'], - foo: './bar' // Will check for ./bar.jsx and ./bar.js + entries:[ + {find:'foo', replacement: './bar'} // Will check for ./bar.jsx and ./bar.js + ] })], }; ``` From 44a6bb8aeec4b693809108c3a53bf3fae8e7e05a Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Thu, 1 Aug 2019 17:49:46 +0200 Subject: [PATCH 03/18] Updated README.me to reflect changes to options --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 5d7a366..af22066 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,27 @@ export default { })], }; ``` +The order of the entries are important, in that are the first rules are applied first (obviously). :) + +You can now also include Regular Expressions to search in a way more distinct and complex manner: + +An optional `resolve` array with file extensions can be provided. +If present local aliases beginning with `./` will be resolved to existing files: + +```javascript +// rollup.config.js +import alias from 'rollup-plugin-alias'; + +export default { + input: './src/index.js', + plugins: [alias({ + resolve: ['.jsx', '.js'], + entries:[ + {find:^./foobar\/path.*/i, replacement: './bar'} + ] + })], +}; +``` An optional `resolve` array with file extensions can be provided. If present local aliases beginning with `./` will be resolved to existing files: From 58407694c20830e952828689b7cd1fa02f36685b Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Thu, 1 Aug 2019 17:57:10 +0200 Subject: [PATCH 04/18] Updated README.me to reflect changes to options --- README.md | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index af22066..a150c8c 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,10 @@ import alias from 'rollup-plugin-alias'; export default { input: './src/index.js', plugins: [alias({ + resolve: ['.jsx', '.js'], entries:[ - {find:'somelibrary', replacement: './mylocallibrary'} + {find:'somelibrary', replacement: './mylocallibrary'}, + {find:^./foobar\/path.*/i, replacement: './bar', isRegEx:true} ] })], }; @@ -53,24 +55,6 @@ If present local aliases beginning with `./` will be resolved to existing files: // rollup.config.js import alias from 'rollup-plugin-alias'; -export default { - input: './src/index.js', - plugins: [alias({ - resolve: ['.jsx', '.js'], - entries:[ - {find:^./foobar\/path.*/i, replacement: './bar'} - ] - })], -}; -``` - -An optional `resolve` array with file extensions can be provided. -If present local aliases beginning with `./` will be resolved to existing files: - -```javascript -// rollup.config.js -import alias from 'rollup-plugin-alias'; - export default { input: './src/index.js', plugins: [alias({ From b36a448092364a3796f1d0abc684bc33deb3bfc1 Mon Sep 17 00:00:00 2001 From: thiscantbeserious Date: Wed, 21 Aug 2019 11:29:09 +0200 Subject: [PATCH 05/18] Switched to instanceof instead of isRegEx option in entries to keep configuration easier --- src/index.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index e64e9cc..cd376c7 100644 --- a/src/index.js +++ b/src/index.js @@ -9,20 +9,18 @@ const IS_WINDOWS = platform() === 'win32'; // Helper functions const noop = () => null; -const matches = (key, importee, isRegEx) => { +const matches = (key, importee) => { if (importee.length < key.length) { return false; } if (importee === key) { return true; } - - if (isRegEx) { + if (key instanceof RegExp) { if (key.test(importee) === true) { return true; } } - const importeeStartsWithKey = (importee.indexOf(key) === 0); const importeeHasSlashAfterKey = (importee.substring(key.length)[0] === '/'); return importeeStartsWithKey && importeeHasSlashAfterKey; @@ -41,7 +39,6 @@ const normalizeId = (id) => { if ((IS_WINDOWS && typeof id === 'string') || VOLUME.test(id)) { return slash(id.replace(VOLUME, '')); } - return id; }; @@ -62,23 +59,21 @@ export default function alias(options = {}) { const importerId = normalizeId(importer); // First match is supposed to be the correct one - const matchedEntry = entries.find(entry => matches(entry.find, importeeId, entry.isRegEx)); + const matchedEntry = entries.find(entry => matches(entry.find, importeeId)); if (!matchedEntry || !importerId) { return null; } const toReplace = matchedEntry.find; - const isDir = matchedEntry.isRegEx && toReplace.source - && (toReplace.source.substr(-1) === '/' - || toReplace.source.substr(-1) === '\\') ? - true:false; + const isRegEx = toReplace instanceof RegExp; + const isDir = (!isRegEx && (toReplace.substr(-1) === '/' || toReplace.substr(-1) === '\\') + || isRegEx && (toReplace.source.substr(-1) === '/' || toReplace.source.substr(-1) === '\\')); const replacement = isDir?matchedEntry.replacement+path.sep:matchedEntry.replacement; let updatedId = normalizeId(importeeId.replace(toReplace, replacement)); if (isFilePath(updatedId)) { - const directory = posix.dirname(importerId); // Resolve file names From f8aa9976fbf661a8ce627b608df64e5ad70fcc87 Mon Sep 17 00:00:00 2001 From: thiscantbeserious Date: Wed, 21 Aug 2019 12:17:27 +0200 Subject: [PATCH 06/18] Fixes after Code-Review --- README.md | 6 +++--- src/index.js | 31 +++++++++++-------------------- test/index.js | 10 +++++----- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a150c8c..63069a8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ For Webpack users: This is a plugin to mimic the `resolve.alias` functionality i ``` $ npm install rollup-plugin-alias ``` - +# ## Usage ```javascript // rollup.config.js @@ -39,12 +39,12 @@ export default { resolve: ['.jsx', '.js'], entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, - {find:^./foobar\/path.*/i, replacement: './bar', isRegEx:true} + {find:/^./foobar\/path.*/i, replacement: './bar', isRegEx:true} ] })], }; ``` -The order of the entries are important, in that are the first rules are applied first (obviously). :) +The order of the entries is important, in that the first rules are applied first. You can now also include Regular Expressions to search in a way more distinct and complex manner: diff --git a/src/index.js b/src/index.js index cd376c7..9be8429 100644 --- a/src/index.js +++ b/src/index.js @@ -9,20 +9,18 @@ const IS_WINDOWS = platform() === 'win32'; // Helper functions const noop = () => null; -const matches = (key, importee) => { - if (importee.length < key.length) { +const matches = (pattern, importee) => { + if (pattern instanceof RegExp) { + return pattern.test(importee); + } + if (importee.length < pattern.length) { return false; } - if (importee === key) { + if (importee === pattern) { return true; } - if (key instanceof RegExp) { - if (key.test(importee) === true) { - return true; - } - } - const importeeStartsWithKey = (importee.indexOf(key) === 0); - const importeeHasSlashAfterKey = (importee.substring(key.length)[0] === '/'); + const importeeStartsWithKey = (importee.indexOf(pattern) === 0); + const importeeHasSlashAfterKey = (importee.substring(pattern.length)[0] === '/'); return importeeStartsWithKey && importeeHasSlashAfterKey; }; const endsWith = (needle, haystack) => haystack.slice(-needle.length) === needle; @@ -47,7 +45,7 @@ export default function alias(options = {}) { const entries = options.entries?options.entries:[]; // No aliases? - if (!entries || entries.length <= 0) { + if (!entries || entries.length === 0) { return { resolveId: noop, }; @@ -64,14 +62,7 @@ export default function alias(options = {}) { return null; } - const toReplace = matchedEntry.find; - const isRegEx = toReplace instanceof RegExp; - const isDir = (!isRegEx && (toReplace.substr(-1) === '/' || toReplace.substr(-1) === '\\') - || isRegEx && (toReplace.source.substr(-1) === '/' || toReplace.source.substr(-1) === '\\')); - - const replacement = isDir?matchedEntry.replacement+path.sep:matchedEntry.replacement; - - let updatedId = normalizeId(importeeId.replace(toReplace, replacement)); + let updatedId = normalizeId(importeeId.replace(matchedEntry.find, matchedEntry.replacement)); if (isFilePath(updatedId)) { const directory = posix.dirname(importerId); @@ -95,7 +86,7 @@ export default function alias(options = {}) { // if alias is windows absoulate path return resolved path or // rollup on windows will throw: // [TypeError: Cannot read property 'specifier' of undefined] - if (VOLUME.test(replacement)) { + if (VOLUME.test(matchedEntry.replacement)) { return path.resolve(updatedId); } return updatedId; diff --git a/test/index.js b/test/index.js index a3f75c9..23be12a 100644 --- a/test/index.js +++ b/test/index.js @@ -44,19 +44,19 @@ test('Simple aliasing', (t) => { test('RegExp aliasing', (t) => { const result = alias({ entries: [ - {find:new RegExp('fo.*'), replacement:'foobar2019', isRegEx:true}, - {find:new RegExp('.*pony.*'), replacement:'i/am/a/barbie/girl', isRegEx:true}, - {find:new RegExp('^test/$'), replacement:'this/is/strict', isRegEx:true} + {find:/f(o+)bar/, replacement:'f$1bar2019'}, + {find:new RegExp('.*pony.*'), replacement:'i/am/a/barbie/girl'}, + {find:/^test\/$/, replacement:'this/is/strict'} ] }); - const resolved = result.resolveId('foobar', '/src/importer.js'); + const resolved = result.resolveId('fooooooooobar', '/src/importer.js'); const resolved2 = result.resolveId('im/a/little/pony/yes', '/src/importer.js'); const resolved3 = result.resolveId('./test', '/src/importer.js'); const resolved4 = result.resolveId('test', '/src/importer.js'); const resolved5 = result.resolveId('test/', '/src/importer.js'); - t.is(resolved, 'foobar2019'); + t.is(resolved, 'fooooooooobar2019'); t.is(resolved2, 'i/am/a/barbie/girl'); t.is(resolved3, null); t.is(resolved4, null); From 8b3897c427b161d6ec37de6c27cca220a3d27e06 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:25:33 +0200 Subject: [PATCH 07/18] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63069a8..d2aad94 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,15 @@ export default { resolve: ['.jsx', '.js'], entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, - {find:/^./foobar\/path.*/i, replacement: './bar', isRegEx:true} + {find:/^./foobar\/path.*/i, replacement: './bar'}, + {find:/^./test/(.*)/i, replacement: './anotherfolder/$1' ] })], }; ``` The order of the entries is important, in that the first rules are applied first. -You can now also include Regular Expressions to search in a way more distinct and complex manner: +You can now also include Regular Expressions to search in a way more distinct and complex manner. An optional `resolve` array with file extensions can be provided. If present local aliases beginning with `./` will be resolved to existing files: From f88970ac05342813789c5d2bd749c3fe41fcd013 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:26:34 +0200 Subject: [PATCH 08/18] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2aad94..5f35729 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,8 @@ export default { resolve: ['.jsx', '.js'], entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, - {find:/^./foobar\/path.*/i, replacement: './bar'}, - {find:/^./test/(.*)/i, replacement: './anotherfolder/$1' + {find:/^.\/foobar\/path.*/i, replacement: './bar'}, + {find:/^.\/test\/(.*)/i, replacement: './anotherfolder/$1' ] })], }; From fd11e6d0c96411a78708297fa45f535758f5c09f Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:27:26 +0200 Subject: [PATCH 09/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f35729..c75f38b 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ import alias from 'rollup-plugin-alias'; export default { input: './src/index.js', plugins: [alias({ - resolve: ['.jsx', '.js'], + resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files entries:[ {find:'foo', replacement: './bar'} // Will check for ./bar.jsx and ./bar.js ] From 4445ccf8b3e8427a5c7fb97c2478b37e28dda769 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:29:05 +0200 Subject: [PATCH 10/18] Update README.md --- README.md | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c75f38b..db2afb6 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ import alias from 'rollup-plugin-alias'; export default { input: './src/index.js', plugins: [alias({ - resolve: ['.jsx', '.js'], + resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, {find:/^.\/foobar\/path.*/i, replacement: './bar'}, @@ -47,26 +47,7 @@ export default { ``` The order of the entries is important, in that the first rules are applied first. -You can now also include Regular Expressions to search in a way more distinct and complex manner. - -An optional `resolve` array with file extensions can be provided. -If present local aliases beginning with `./` will be resolved to existing files: - -```javascript -// rollup.config.js -import alias from 'rollup-plugin-alias'; - -export default { - input: './src/index.js', - plugins: [alias({ - resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files - entries:[ - {find:'foo', replacement: './bar'} // Will check for ./bar.jsx and ./bar.js - ] - })], -}; -``` -If not given local aliases will be resolved with a `.js` extension. +You use Regular Expressions to search in a way more distinct and complex manner. ## License MIT, see `LICENSE` for more information From a5acc4bab3aeb0f0ab05ed6d931dec9631be67ac Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:30:10 +0200 Subject: [PATCH 11/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db2afb6..195908e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ export default { ``` The order of the entries is important, in that the first rules are applied first. -You use Regular Expressions to search in a way more distinct and complex manner. +You can use either simple Strings or Regular Expressions to search in a more distinct and complex manner (e.g. to do partial replacements via subpattern-matching, see aboves example). ## License MIT, see `LICENSE` for more information From 1dbb8c0f9b796b8e2a6c41345300e1cc8ea00d25 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:31:37 +0200 Subject: [PATCH 12/18] Update README.md --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 195908e..447dbdb 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,16 @@ import alias from 'rollup-plugin-alias'; export default { input: './src/index.js', - plugins: [alias({ - resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders - entries:[ - {find:'somelibrary', replacement: './mylocallibrary'}, - {find:/^.\/foobar\/path.*/i, replacement: './bar'}, - {find:/^.\/test\/(.*)/i, replacement: './anotherfolder/$1' - ] - })], + plugins: [ + alias({ + resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders + entries:[ + {find:'somelibrary', replacement: './mylocallibrary'}, + {find:/^.\/foobar\/path.*/i, replacement: './bar'}, + {find:/^.\/test\/(.*)/i, replacement: './anotherfolder/$1' + ] + }) + ], }; ``` The order of the entries is important, in that the first rules are applied first. From 8e0cf29605fc6fd0bd088fa19a399c77def6ae8e Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:33:06 +0200 Subject: [PATCH 13/18] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 447dbdb..9e0ce76 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ export default { resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, - {find:/^.\/foobar\/path.*/i, replacement: './bar'}, - {find:/^.\/test\/(.*)/i, replacement: './anotherfolder/$1' + {find:/^foobar\/path.*/i, replacement: './bar'}, + {find:/^test\/(.*)/i, replacement: './anotherfolder/$1' ] }) ], From a1d975ea06abe521ad7a5478a0cc85fa931d71b0 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:35:12 +0200 Subject: [PATCH 14/18] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e0ce76..b98b145 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ export default { entries:[ {find:'somelibrary', replacement: './mylocallibrary'}, {find:/^foobar\/path.*/i, replacement: './bar'}, - {find:/^test\/(.*)/i, replacement: './anotherfolder/$1' + {find:/^test\/(.*)/i, replacement: './anotherfolder/$1'}, + {find:/^test$/i, replacement: 'super-secret-sausage-library'} ] }) ], From 9c9d6c70d75e70c769ded523d2ffcedc527634ec Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:46:09 +0200 Subject: [PATCH 15/18] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b98b145..2592c05 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,9 @@ export default { alias({ resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders entries:[ - {find:'somelibrary', replacement: './mylocallibrary'}, - {find:/^foobar\/path.*/i, replacement: './bar'}, - {find:/^test\/(.*)/i, replacement: './anotherfolder/$1'}, - {find:/^test$/i, replacement: 'super-secret-sausage-library'} + {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version + {find:/^i18n\!(.*)/, replacement: '$1'}, //remove some loaders (e.g. when they're transpiled via the AMD module) + {find:/^(.*)\.js$/, replacement: '$1.wasm'} //for whatever reason, replace all .js extensions with .wasm ] }) ], From 7287338eea6797fed9131ba37f5845f838e1a469 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:55:04 +0200 Subject: [PATCH 16/18] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2592c05..90d26b7 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,11 @@ export default { alias({ resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders entries:[ + {find:'something", replacement: '../../../something'}, //the initial example {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version - {find:/^i18n\!(.*)/, replacement: '$1'}, //remove some loaders (e.g. when they're transpiled via the AMD module) - {find:/^(.*)\.js$/, replacement: '$1.wasm'} //for whatever reason, replace all .js extensions with .wasm + {find:/^i18n\!(.*)/, replacement: '$1'}, //remove something in front of the import (e.g. loaders, that were previously transpiled via the AMD module) + //for whatever reason, replace all .js extensions with .wasm + {find:/^(.*)\.js$/, replacement: '$1.wasm'} ] }) ], From c13f8d11dbe88daf559648cefb6f21305bd20f4d Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:55:25 +0200 Subject: [PATCH 17/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90d26b7..a504b23 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ export default { alias({ resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders entries:[ - {find:'something", replacement: '../../../something'}, //the initial example + {find:'something', replacement: '../../../something'}, //the initial example {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version {find:/^i18n\!(.*)/, replacement: '$1'}, //remove something in front of the import (e.g. loaders, that were previously transpiled via the AMD module) //for whatever reason, replace all .js extensions with .wasm From 036186c38f15caac35dc6139b06ee90453a0bf55 Mon Sep 17 00:00:00 2001 From: thiscantbeserious <34506214+thiscantbeserious@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:57:09 +0200 Subject: [PATCH 18/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a504b23..1c9c161 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ export default { entries:[ {find:'something', replacement: '../../../something'}, //the initial example {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version - {find:/^i18n\!(.*)/, replacement: '$1'}, //remove something in front of the import (e.g. loaders, that were previously transpiled via the AMD module) + {find:/^i18n\!(.*)/, replacement: '$1.js'}, //remove something in front of the import and append an extension (e.g. loaders, for files that were previously transpiled via the AMD module, to properly handle them in rollup as internals now) //for whatever reason, replace all .js extensions with .wasm {find:/^(.*)\.js$/, replacement: '$1.wasm'} ]