-
-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(repo): remove node 8 in github actions, linting updates
- Loading branch information
1 parent
9faf50b
commit d4286c4
Showing
30 changed files
with
137 additions
and
130 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
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
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 |
---|---|---|
@@ -1,27 +1,29 @@ | ||
import { statSync } from 'fs'; | ||
import glob from 'glob'; | ||
|
||
import { resolve } from 'path'; | ||
|
||
import glob from 'glob'; | ||
|
||
import { normalizePathSlashes } from './transform'; | ||
|
||
export default function getDynamicRequirePaths(patterns) { | ||
const dynamicRequireModuleSet = new Set(); | ||
for (const pattern of (!patterns || Array.isArray(patterns)) ? patterns || [] : [patterns]) { | ||
for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) { | ||
const isNegated = pattern.startsWith('!'); | ||
const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind( | ||
dynamicRequireModuleSet | ||
); | ||
const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind(dynamicRequireModuleSet); | ||
for (const path of glob.sync(isNegated ? pattern.substr(1) : pattern)) { | ||
modifySet(normalizePathSlashes(resolve(path))); | ||
} | ||
} | ||
const dynamicRequireModuleDirPaths = Array.from(dynamicRequireModuleSet.values()).filter(path => { | ||
try { | ||
if (statSync(path).isDirectory()) | ||
return true; | ||
} catch (ignored) { | ||
// Nothing to do here | ||
const dynamicRequireModuleDirPaths = Array.from(dynamicRequireModuleSet.values()).filter( | ||
(path) => { | ||
try { | ||
if (statSync(path).isDirectory()) return true; | ||
} catch (ignored) { | ||
// Nothing to do here | ||
} | ||
return false; | ||
} | ||
return false; | ||
}); | ||
); | ||
return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths }; | ||
} |
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
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
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
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
6 changes: 3 additions & 3 deletions
6
packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/main.js
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
t.deepEqual(require('./sub/submodule'), { | ||
moduleDirect: 'direct', | ||
moduleNested: 'nested', | ||
parentModule: 'parent' | ||
moduleDirect: 'direct', | ||
moduleNested: 'nested', | ||
parentModule: 'parent' | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/dynamic-require-absolute-import/sub/submodule.js
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
3 changes: 2 additions & 1 deletion
3
packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
const Path = require('path'); | ||
let basePath = process.cwd() + '/fixtures/function/dynamic-require-absolute-paths'; | ||
|
||
const basePath = `${process.cwd()}/fixtures/function/dynamic-require-absolute-paths`; | ||
|
||
t.is(require(Path.resolve(`${basePath}/submodule.js`)), 'submodule'); |
4 changes: 2 additions & 2 deletions
4
packages/commonjs/test/fixtures/function/dynamic-require-es-entry/importer.js
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule (withName) { | ||
return require('./' + withName); | ||
function takeModule(withName) { | ||
return require(`./${withName}`); | ||
} | ||
|
||
module.exports = takeModule('submodule.js'); |
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/dynamic-require-extensions/main.js
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
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/dynamic-require-extensions/submodule.js
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = {name: 'submodule', value: null}; | ||
module.exports = { name: 'submodule', value: null }; |
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
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/dynamic-require-instances/main.js
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
6 changes: 3 additions & 3 deletions
6
packages/commonjs/test/fixtures/function/dynamic-require-json/main.js
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(withName) { | ||
return require('./' + withName); | ||
return require(`./${withName}`); | ||
} | ||
|
||
t.deepEqual(takeModule('dynamic.json'), {value: 'present'}); | ||
t.deepEqual(takeModule('dynamic'), {value: 'present'}); | ||
t.deepEqual(takeModule('dynamic.json'), { value: 'present' }); | ||
t.deepEqual(takeModule('dynamic'), { value: 'present' }); |
1 change: 0 additions & 1 deletion
1
packages/commonjs/test/fixtures/function/dynamic-require-package-sub/sub/entry.js
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
|
||
t.is(require('custom-module'), 'custom-module'); |
6 changes: 3 additions & 3 deletions
6
packages/commonjs/test/fixtures/function/dynamic-require-package/sub/sub.js
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(name) { | ||
return require(name); | ||
return require(name); | ||
} | ||
|
||
module.exports = { | ||
parent: takeModule('..'), | ||
customModule: takeModule('custom-module') | ||
parent: takeModule('..'), | ||
customModule: takeModule('custom-module') | ||
}; |
Oops, something went wrong.