Skip to content

Commit

Permalink
chore(NA): fix logic behind cleaning x-pack node modules on build (#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Oct 3, 2019
1 parent e74a0b8 commit 8d2bc28
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
"expiry-js": "0.1.7",
"file-loader": "4.2.0",
"font-awesome": "4.7.0",
"fp-ts": "^2.0.5",
"getos": "^3.1.0",
"glob": "^7.1.2",
"glob-all": "^3.1.0",
Expand All @@ -176,7 +175,6 @@
"https-proxy-agent": "^2.2.2",
"inert": "^5.1.0",
"inline-style": "^2.0.0",
"io-ts": "^2.0.1",
"joi": "^13.5.2",
"jquery": "^3.4.1",
"js-yaml": "3.13.1",
Expand Down
12 changes: 6 additions & 6 deletions packages/kbn-babel-code-parser/src/can_require.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
* under the License.
*/

export function canRequire(cwd, entry) {
export function canRequire(entry, cwd = require.resolve.paths(entry) || []) {
try {
// We will try to test if we can resolve
// this entry through the require.resolve
// setting as the start looking path the
// given cwd. Require.resolve will keep
// given cwd. That cwd variable could be
// a path or an array of paths
// from where Require.resolve will keep
// looking recursively as normal starting
// from that location.
// from those locations.
return require.resolve(entry, {
paths: [
cwd
]
paths: [].concat(cwd)
});
} catch (e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-babel-code-parser/src/code_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function parseEntries(cwd, entries, strategy, results, wasParsed =
const sanitizedCwd = cwd || process.cwd();

// Test each entry against canRequire function
const entriesQueue = entries.map(entry => canRequire(sanitizedCwd, entry));
const entriesQueue = entries.map(entry => canRequire(entry));

while(entriesQueue.length) {
// Get the first element in the queue as
Expand Down
8 changes: 6 additions & 2 deletions packages/kbn-babel-code-parser/src/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ export async function dependenciesParseStrategy(cwd, parseSingleFile, mainEntry,
// new dependencies
return dependencies.reduce((filteredEntries, entry) => {
const absEntryPath = resolve(cwd, dirname(mainEntry), entry);
const requiredPath = canRequire(cwd, absEntryPath);
const requiredRelativePath = canRequire(cwd, entry);

// NOTE: cwd for following canRequires is absEntryPath
// because we should start looking from there
const requiredPath = canRequire(absEntryPath, absEntryPath);
const requiredRelativePath = canRequire(entry, absEntryPath);

const isRelativeFile = !isAbsolute(entry);
const isNodeModuleDep = isRelativeFile && !requiredPath && requiredRelativePath;
const isNewEntry = isRelativeFile && requiredPath;
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-babel-code-parser/src/strategies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ describe('Code Parser Strategies', () => {
cb(null, `require('dep_from_node_modules')`);
});

canRequire.mockImplementation((mockCwd, entry) => {
if (entry === `${mockCwd}dep1/dep_from_node_modules`) {
canRequire.mockImplementation((entry, cwd) => {
if (entry === `${cwd}dep1/dep_from_node_modules`) {
return false;
}

Expand All @@ -78,7 +78,7 @@ describe('Code Parser Strategies', () => {
cb(null, `require('./relative_dep')`);
});

canRequire.mockImplementation((mockCwd, entry) => {
canRequire.mockImplementation((entry) => {
if (entry === `${mockCwd}dep1/relative_dep`) {
return `${entry}/index.js`;
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"file-type": "^10.9.0",
"font-awesome": "4.7.0",
"formsy-react": "^1.1.5",
"fp-ts": "^2.0.5",
"geojson-rewind": "^0.3.1",
"get-port": "4.2.0",
"getos": "^3.1.0",
Expand All @@ -261,6 +262,7 @@
"immer": "^1.5.0",
"inline-style": "^2.0.0",
"intl": "^1.2.5",
"io-ts": "^2.0.1",
"isbinaryfile": "4.0.2",
"isomorphic-git": "0.55.5",
"joi": "^13.5.2",
Expand Down

0 comments on commit 8d2bc28

Please sign in to comment.