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

chore(NA): fix logic behind cleaning x-pack node modules on build #47091

Merged
merged 1 commit into from
Oct 3, 2019
Merged
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: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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 @@ -177,7 +176,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 @@ -241,6 +241,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 @@ -262,6 +263,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