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
fix: don't include partial scss files in bundle #988
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import bundleConfigLoader from "./bundle-config-loader"; | ||
|
||
const defaultLoaderOptions = { | ||
angular: false, | ||
loadCss: true, | ||
unitTesting: false, | ||
}; | ||
|
||
const defaultTestFiles = { | ||
"./app-root.xml": true, | ||
"./app-root.land.xml": true, | ||
"./app.ts": true, | ||
"./app.css": true, | ||
"./app.android.scss": true, | ||
"./app.ios.scss": true, | ||
"./app.land.css": true, | ||
"./components/my-component.css": true, | ||
"./components/my-component.land.ts": true, | ||
"./components/my-component.ts": true, | ||
"./components/my-component.land.xml": true, | ||
"./components/my-component.xml": true, | ||
"./components/my-component.land.css": true, | ||
"./main/main-page.land.css": true, | ||
"./main/main-page.css": true, | ||
"./main/main-page.ts": true, | ||
"./main/main-page.land.xml": true, | ||
"./main/main-page.xml": true, | ||
"./main/main-page.land.ts": true, | ||
"./main/main-page-vm.ts": true, | ||
|
||
"./app_component.scss": true, | ||
"./App_Resources123/some-file.xml": true, | ||
"./MyApp_Resources/some-file.xml": true, | ||
"./App_Resources_Nobody_Names_Folders_Like_That_Roska/some-file.xml": true, | ||
|
||
"./package.json": false, // do not include package.json files | ||
"./app.d.ts": false, // do not include ts definitions | ||
"./_app-common.scss": false, // do not include scss partial files | ||
"./_app-variables.scss": false, // do not include scss partial files | ||
"./App_Resources/Android/src/main/res/values/colors.xml": false, // do not include App_Resources | ||
"./App_Resources/Android/src/main/AndroidManifest.xml": false, // do not include App_Resources | ||
}; | ||
|
||
const loaderOptionsWithIgnore = { | ||
angular: false, | ||
loadCss: true, | ||
unitTesting: false, | ||
ignoredFiles: ["./application", "./activity"] | ||
}; | ||
|
||
const ignoredTestFiles = { | ||
"./application.ts": false, | ||
"./activity.ts": false, | ||
} | ||
|
||
function getRequireContextRegex(source: string): RegExp { | ||
const requireContextStr = `require.context("~/", true, `; | ||
|
||
expect(source).toContain(requireContextStr); | ||
|
||
const start = source.indexOf(requireContextStr) + requireContextStr.length; | ||
const end = source.indexOf(");\n", start); | ||
const regexStr = source.substring(start, end); | ||
const regex: RegExp = eval(regexStr); | ||
|
||
expect(regex instanceof RegExp).toBeTruthy(); | ||
return regex; | ||
} | ||
|
||
function assertTestFilesAreMatched(testFiles: { [key: string]: boolean }, regex: RegExp) { | ||
for (let fileName in testFiles) { | ||
if (defaultTestFiles[fileName]) { | ||
expect(fileName).toMatch(regex); | ||
} | ||
else { | ||
expect(fileName).not.toMatch(regex); | ||
} | ||
} | ||
} | ||
|
||
describe("BundleConfigLoader should create require.context", () => { | ||
it("default case", (done) => { | ||
|
||
const loaderContext = { | ||
callback: (error, source: string, map) => { | ||
const regex = getRequireContextRegex(source); | ||
|
||
assertTestFilesAreMatched(defaultTestFiles, regex); | ||
|
||
done(); | ||
}, | ||
query: defaultLoaderOptions | ||
} | ||
|
||
bundleConfigLoader.call(loaderContext, " ___CODE___"); | ||
}) | ||
|
||
it("with ignored files", (done) => { | ||
|
||
const loaderContext = { | ||
callback: (error, source: string, map) => { | ||
const regex = getRequireContextRegex(source); | ||
const testFiles = { ...defaultTestFiles, ...ignoredTestFiles }; | ||
|
||
assertTestFilesAreMatched(testFiles, regex); | ||
|
||
done(); | ||
}, | ||
query: loaderOptionsWithIgnore | ||
} | ||
|
||
bundleConfigLoader.call(loaderContext, " ___CODE___"); | ||
}) | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.