@@ -13,6 +13,12 @@ const DEFAULT_EMBED_OPTIONS = {
1313const DEFAULT_GET_IFRAME = url =>
1414 `<iframe src="${ url } " class="embedded-codesandbox" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>` ;
1515
16+ const DEFAULT_IGNORED_FILES = [
17+ 'node_modules' ,
18+ 'package-lock.json' ,
19+ 'yarn.lock'
20+ ]
21+
1622// Matches compression used in Babel and CodeSandbox REPLs
1723// https://github.com/babel/website/blob/master/js/repl/UriUtils.js
1824const compress = string =>
@@ -21,14 +27,7 @@ const compress = string =>
2127 . replace ( / \/ / g, `_` ) // Convert '/' to '_'
2228 . replace ( / = + $ / , `` ) ; // Remove ending '='
2329
24- const getAllFiles = dirPath =>
25- fs . readdirSync ( dirPath ) . reduce ( ( acc , file ) => {
26- if ( file === 'node_modules' ) return acc ;
27- const relativePath = dirPath + '/' + file ;
28- const isDirectory = fs . statSync ( relativePath ) . isDirectory ( ) ;
29- const additions = isDirectory ? getAllFiles ( relativePath ) : [ relativePath ] ;
30- return [ ...acc , ...additions ] ;
31- } , [ ] ) ;
30+
3231
3332module . exports = (
3433 { markdownAST } ,
@@ -37,6 +36,7 @@ module.exports = (
3736 protocol = DEFAULT_PROTOCOL ,
3837 embedOptions = DEFAULT_EMBED_OPTIONS ,
3938 getIframe = DEFAULT_GET_IFRAME ,
39+ ignoredFiles = DEFAULT_IGNORED_FILES ,
4040 }
4141) => {
4242 if ( ! rootDirectory ) {
@@ -47,12 +47,23 @@ module.exports = (
4747 rootDirectory += '/' ;
4848 }
4949
50+ const ignoredFilesSet = new Set ( ignoredFiles )
51+
5052 const getDirectoryPath = url => {
5153 let directoryPath = url . replace ( protocol , '' ) ;
5254 const fullPath = path . join ( rootDirectory , directoryPath ) ;
5355 return normalizePath ( fullPath ) ;
5456 } ;
5557
58+ const getAllFiles = ( dirPath ) =>
59+ fs . readdirSync ( dirPath ) . reduce ( ( acc , file ) => {
60+ if ( ignoredFilesSet . has ( file ) ) return acc ;
61+ const relativePath = dirPath + '/' + file ;
62+ const isDirectory = fs . statSync ( relativePath ) . isDirectory ( ) ;
63+ const additions = isDirectory ? getAllFiles ( relativePath ) : [ relativePath ] ;
64+ return [ ...acc , ...additions ] ;
65+ } , [ ] ) ;
66+
5667 const getFilesList = directory => {
5768 let packageJsonFound = false ;
5869 const folderFiles = getAllFiles ( directory ) ;
0 commit comments