Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audit problems by removing lodash #153

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _tests/plugins/common/alias.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('aliases', () => {
'my-absolute-test-lib': join(process.cwd(), '/_tests/lib/a'),
'same-folder-lib': join(process.cwd(), '/_tests/lib/b')
},
extensionsConf: null
extensionsConf: ['', '.js']
};
expect(aliases).to.deep.equal(targetConfig);
});
Expand Down
3 changes: 2 additions & 1 deletion _tests/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
alias: {
'my-absolute-test-lib': path.join(__dirname, 'lib/a'),
'same-folder-lib': path.resolve(__dirname, 'lib/b'),
}
},
extensions: ['', '.js']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my best effort to ensure the extensionsConf code path is tested. However, it's possible I broke some other relevant testing.

}
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
"dependencies": {
"babel-runtime": "^6.26.0",
"compare-module-exports": "^2.1.0",
"lodash.some": "^4.6.0",
"lodash.template": "^4.4.0",
"node-libs-browser": "^2.1.0",
"path-parse": "^1.0.5",
"wipe-node-cache": "^2.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = (args) => {
mocks: []
}
},
exit({node}, {file}) {
exit({node}) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was left from #143

const {imports, mocks} = node[REGISTRATIONS];
if (mocks.length) {

Expand Down
32 changes: 10 additions & 22 deletions src/plugins/common/aliases.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {join, resolve, isAbsolute, dirname, basename, sep} from 'path';
import template from 'lodash.template';
import some from 'lodash.some';
import {requireModule} from '../../executor';
import {fileExists} from "./utils";

Expand All @@ -10,26 +8,19 @@ const DEFAULT_CONFIG_NAMES = ['webpack.config.js', 'webpack.config.babel.js'];
// just cos we emulate its behavior

function getConfigPath(configPaths) {
let conf = null;

// Try all config paths and return for the first found one
some(configPaths, configPath => {
if (!configPath) return;

// Compile config using environment variables
const compiledConfigPath = template(configPath)(process.env);
for (let configPath of configPaths) {
if (!configPath) continue;

let resolvedConfigPath = resolve(process.cwd(), compiledConfigPath);
let resolvedConfigPath = resolve(process.cwd(), configPath);
const resolvedName = fileExists(resolvedConfigPath);

if (resolvedConfigPath && resolvedName) {
conf = resolvedName;
return resolvedName;
}
}

return conf;
});

return conf;
return null;
}

function readAliases(configPath) {
Expand Down Expand Up @@ -171,16 +162,13 @@ function processFile(filePath, {aliasConf, extensionsConf}) {
// Get an absolute path to the file
const absoluteRequire = join(aliasTo, basename(filePath));

let extension = null;
some(extensionsConf, ext => {
if (!ext) return;
let extension = extensionsConf.find(ext => {
if (!ext) return false;

// If the file with this extension exists set it
if (fileExists(absoluteRequire + ext)) {
extension = ext;
return true;
}

return extension;
});

// Set the extension to the file path, or keep the original one
Expand All @@ -196,4 +184,4 @@ function processFile(filePath, {aliasConf, extensionsConf}) {
export {
readAliases,
processFile
}
}
Loading