This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
refactor: use webpack context when notifying CLI for changed files #455
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0feb14e
feat: add 'getWebpackConfig' helper function
sis0k0 47bb3e6
feat: add 'getCompilationContext' helper function
sis0k0 644eb43
refactor: simplify getProjectDir helper
sis0k0 223c2b3
style: indent with spaces
sis0k0 e2cc38a
refactor: ignore compilation contexts from CLI watcher
sis0k0 6b9b0ef
refactor: get absolute path for context
sis0k0 aae5baa
refactor: use webpack context when notifying CLI for changed files
sis0k0 e6bffcf
refactor: throw if no 'platforms'
sis0k0 11aed4d
fix: resolve context and ignored files relative to __dirname
sis0k0 875fd3e
fix: use relative path for context
sis0k0 2d61a70
style: replace destructuring with Object assign
sis0k0 04a31cc
style: replace \n with os.EOL
sis0k0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 +1,15 @@ | ||
const { runWebpackCompiler } = require("./compiler"); | ||
|
||
module.exports = function ($mobileHelper, $projectData, $logger, hookArgs) { | ||
const env = hookArgs.config.env || {}; | ||
const platform = hookArgs.config.platform; | ||
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions; | ||
const config = { | ||
env, | ||
platform, | ||
bundle: appFilesUpdaterOptions.bundle, | ||
release: appFilesUpdaterOptions.release, | ||
}; | ||
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, $logger, hookArgs); | ||
return result; | ||
const env = hookArgs.config.env || {}; | ||
const platform = hookArgs.config.platform; | ||
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions; | ||
const config = { | ||
env, | ||
platform, | ||
bundle: appFilesUpdaterOptions.bundle, | ||
release: appFilesUpdaterOptions.release, | ||
}; | ||
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, $logger, hookArgs); | ||
return result; | ||
} |
This file contains hidden or 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,16 +1,33 @@ | ||
const { AppDirectoryLocation } = require("./constants"); | ||
const { basename } = require("path"); | ||
const { buildEnvData, getCompilationContext } = require("./utils"); | ||
|
||
module.exports = function (hookArgs) { | ||
if (hookArgs.liveSyncData && hookArgs.liveSyncData.bundle) { | ||
return (args, originalMethod) => { | ||
return originalMethod(...args).then(originalPatterns => { | ||
const appDirectoryLocationIndex = originalPatterns.indexOf(AppDirectoryLocation); | ||
if (appDirectoryLocationIndex !== -1) { | ||
originalPatterns.splice(appDirectoryLocationIndex, 1); | ||
} | ||
const { liveSyncData } = hookArgs; | ||
if (!liveSyncData || !liveSyncData.bundle) { | ||
return; | ||
} | ||
|
||
return originalPatterns; | ||
}); | ||
}; | ||
} | ||
const { platforms } = hookArgs; | ||
const { env } = liveSyncData; | ||
return (args, originalMethod) => { | ||
return originalMethod(...args).then(originalPatterns => { | ||
if (!platforms || !platforms.length) { | ||
throw new Error("Target platform should be specified!"); | ||
} | ||
|
||
const compilationContexts = platforms.map(platform => | ||
getContext(platform, env)); | ||
|
||
const ignorePatterns = compilationContexts.map( | ||
context => `!${context}` | ||
); | ||
|
||
return [...originalPatterns, ...ignorePatterns]; | ||
}); | ||
}; | ||
} | ||
|
||
function getContext(platform, env) { | ||
const fullEnvData = buildEnvData(platform, env); | ||
return getCompilationContext(fullEnvData); | ||
} |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,9 +1,34 @@ | ||
const os = require("os"); | ||
const path = require("path"); | ||
|
||
const { getProjectDir, getWebpackConfig } = require("../projectHelpers"); | ||
|
||
function buildEnvData(platform, env) { | ||
return Object.assign({}, | ||
env, | ||
{ [platform.toLowerCase()]: true } | ||
); | ||
} | ||
|
||
function getCompilationContext(env) { | ||
const projectDir = getProjectDir(); | ||
const config = getWebpackConfig(projectDir, env); | ||
const { context } = config; | ||
|
||
return context ? | ||
path.relative(projectDir, context) : | ||
"."; | ||
} | ||
|
||
function shouldSnapshot($mobileHelper, config) { | ||
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(config.platform); | ||
const osSupportsSnapshot = os.type() !== "Windows_NT"; | ||
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot; | ||
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(config.platform); | ||
const osSupportsSnapshot = os.type() !== "Windows_NT"; | ||
|
||
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot; | ||
} | ||
|
||
module.exports.shouldSnapshot = shouldSnapshot; | ||
module.exports = { | ||
buildEnvData, | ||
getCompilationContext, | ||
shouldSnapshot, | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old logic
splice
d the unneeded watch pattern, whereas the new logic adds an exclusion and retains theoriginalPatterns
.Whenever we have
["app", "app/App_Resources", "!app"]
in watch patterns - does this work as expected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in person.