Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 9b1e34d

Browse files
author
Dimitar Tachev
authored
Merge pull request #1011 from NativeScript/tachev/merge-release-into-master
chore: merge release into master
2 parents 469c4cb + 2372e75 commit 9b1e34d

17 files changed

+165
-54
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
99
"args": [
1010
"--config=jasmine-config/jasmine.json"
11-
]
11+
],
12+
"preLaunchTask": "npm:tsc"
1213
},
1314
{
1415
"type": "node",

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<a name="1.0.2"></a>
2+
## [1.0.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.1...1.0.2) (2019-07-26)
3+
4+
5+
### Bug Fixes
6+
7+
* do not require `.js.map` files in the entry points when someone is using devtool: "source-map" ([#968](https://github.com/NativeScript/nativescript-dev-webpack/issues/968)) ([4bb6124](https://github.com/NativeScript/nativescript-dev-webpack/commit/4bb6124))
8+
* avoid getting invalid require calls when building from Windows ([#989](https://github.com/NativeScript/nativescript-dev-webpack/issues/989)) ([4799271](https://github.com/NativeScript/nativescript-dev-webpack/commit/4799271))
9+
* escape the regex for the path to the entry module of application ([#998](https://github.com/NativeScript/nativescript-dev-webpack/issues/998)) ([571c7f2](https://github.com/NativeScript/nativescript-dev-webpack/commit/571c7f2))
10+
11+
12+
<a name="1.0.1"></a>
13+
## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.0...1.0.1) (2019-07-16)
14+
15+
16+
### Bug Fixes
17+
18+
* don't include partial scss files in bundle ([#988](https://github.com/NativeScript/nativescript-dev-webpack/issues/988)) ([786bd6c](https://github.com/NativeScript/nativescript-dev-webpack/commit/786bd6c))
19+
* **js:** try to resolve node_modules from the project root before resolving in a linked location ([#987](https://github.com/NativeScript/nativescript-dev-webpack/issues/987)) ([a3df142](https://github.com/NativeScript/nativescript-dev-webpack/commit/a3df142))
20+
21+
122
<a name="1.0.0"></a>
223
# [1.0.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.0) (2019-07-10)
324

bundle-config-loader.spec.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import bundleConfigLoader from "./bundle-config-loader";
2+
3+
const defaultLoaderOptions = {
4+
angular: false,
5+
loadCss: true,
6+
unitTesting: false,
7+
};
8+
9+
const defaultTestFiles = {
10+
"./app-root.xml": true,
11+
"./app-root.land.xml": true,
12+
"./app.ts": true,
13+
"./app.css": true,
14+
"./app.android.scss": true,
15+
"./app.ios.scss": true,
16+
"./app.land.css": true,
17+
"./components/my-component.css": true,
18+
"./components/my-component.land.ts": true,
19+
"./components/my-component.ts": true,
20+
"./components/my-component.land.xml": true,
21+
"./components/my-component.xml": true,
22+
"./components/my-component.land.css": true,
23+
"./main/main-page.land.css": true,
24+
"./main/main-page.css": true,
25+
"./main/main-page.ts": true,
26+
"./main/main-page.land.xml": true,
27+
"./main/main-page.xml": true,
28+
"./main/main-page.land.ts": true,
29+
"./main/main-page-vm.ts": true,
30+
31+
"./app_component.scss": true,
32+
"./App_Resources123/some-file.xml": true,
33+
"./MyApp_Resources/some-file.xml": true,
34+
"./App_Resources_Nobody_Names_Folders_Like_That_Roska/some-file.xml": true,
35+
36+
"./package.json": false, // do not include package.json files
37+
"./app.d.ts": false, // do not include ts definitions
38+
"./_app-common.scss": false, // do not include scss partial files
39+
"./_app-variables.scss": false, // do not include scss partial files
40+
"./App_Resources/Android/src/main/res/values/colors.xml": false, // do not include App_Resources
41+
"./App_Resources/Android/src/main/AndroidManifest.xml": false, // do not include App_Resources
42+
};
43+
44+
const loaderOptionsWithIgnore = {
45+
angular: false,
46+
loadCss: true,
47+
unitTesting: false,
48+
ignoredFiles: ["./application", "./activity"]
49+
};
50+
51+
const ignoredTestFiles = {
52+
"./application.ts": false,
53+
"./activity.ts": false,
54+
}
55+
56+
function getRequireContextRegex(source: string): RegExp {
57+
const requireContextStr = `require.context("~/", true, `;
58+
59+
expect(source).toContain(requireContextStr);
60+
61+
const start = source.indexOf(requireContextStr) + requireContextStr.length;
62+
const end = source.indexOf(");\n", start);
63+
const regexStr = source.substring(start, end);
64+
const regex: RegExp = eval(regexStr);
65+
66+
expect(regex instanceof RegExp).toBeTruthy();
67+
return regex;
68+
}
69+
70+
function assertTestFilesAreMatched(testFiles: { [key: string]: boolean }, regex: RegExp) {
71+
for (let fileName in testFiles) {
72+
if (defaultTestFiles[fileName]) {
73+
expect(fileName).toMatch(regex);
74+
}
75+
else {
76+
expect(fileName).not.toMatch(regex);
77+
}
78+
}
79+
}
80+
81+
describe("BundleConfigLoader should create require.context", () => {
82+
it("default case", (done) => {
83+
84+
const loaderContext = {
85+
callback: (error, source: string, map) => {
86+
const regex = getRequireContextRegex(source);
87+
88+
assertTestFilesAreMatched(defaultTestFiles, regex);
89+
90+
done();
91+
},
92+
query: defaultLoaderOptions
93+
}
94+
95+
bundleConfigLoader.call(loaderContext, " ___CODE___");
96+
})
97+
98+
it("with ignored files", (done) => {
99+
100+
const loaderContext = {
101+
callback: (error, source: string, map) => {
102+
const regex = getRequireContextRegex(source);
103+
const testFiles = { ...defaultTestFiles, ...ignoredTestFiles };
104+
105+
assertTestFilesAreMatched(testFiles, regex);
106+
107+
done();
108+
},
109+
query: loaderOptionsWithIgnore
110+
}
111+
112+
bundleConfigLoader.call(loaderContext, " ___CODE___");
113+
})
114+
});

bundle-config-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getOptions } from "loader-utils";
44
import * as escapeRegExp from "escape-string-regexp";
55

66
// Matches all source, markup and style files that are not in App_Resources
7-
const defaultMatch = "(?<!App_Resources.*)\.(xml|css|js|(?<!d\.)ts|scss)$";
7+
const defaultMatch = "(?<!\\bApp_Resources\\b.*)\\.(xml|css|js|(?<!\\.d\\.)ts|(?<!\\b_[\\w-]*\\.)scss)$";
88

99
const loader: loader.Loader = function (source, map) {
1010
let {

demo/AngularApp/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module.exports = env => {
198198
module: {
199199
rules: [
200200
{
201-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
201+
include: join(appFullPath, entryPath),
202202
use: [
203203
// Require all Android app components
204204
platform === "android" && {

demo/JavaScriptApp/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module.exports = env => {
159159
module: {
160160
rules: [
161161
{
162-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
162+
include: join(appFullPath, entryPath),
163163
use: [
164164
// Require all Android app components
165165
platform === "android" && {

demo/TypeScriptApp/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ module.exports = env => {
165165
module: {
166166
rules: [
167167
{
168-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
168+
include: join(appFullPath, entryPath),
169169
use: [
170170
// Require all Android app components
171171
platform === "android" && {

dependencyManager.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ Some dependencies have already been added. \
1010
If you want to force update them, please run "node_modules/.bin/update-ns-webpack".
1111
`;
1212

13-
const USAGE_MESSAGE = `
14-
NativeScript Webpack plugin was successfully added.
15-
You can now bundle your project by passing --bundle flag to NativeScript CLI commands:
16-
- tns build android --bundle
17-
- tns build ios --bundle
18-
- tns run android --bundle
19-
- tns run ios --bundle
20-
You can also pass the "--env.uglify" flag to use Terser for minification.
21-
For more information check out https://docs.nativescript.org/tooling/bundling-with-webpack#bundling.
22-
`;
23-
2413
function addProjectDeps(packageJson, force = false) {
2514
packageJson.devDependencies = packageJson.devDependencies || {};
2615
const postinstallOptions = {
@@ -105,8 +94,6 @@ function dependsOn(packageJson, package) {
10594
}
10695

10796
function showHelperMessages({ newDepsAdded, hasOldDeps }) {
108-
console.info(USAGE_MESSAGE);
109-
11097
if (hasOldDeps) {
11198
console.info(ALREADY_ADDED_MESSAGE);
11299
}

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ exports.getAppPath = (platform, projectDir) => {
6060
}
6161
};
6262

63+
/**
64+
* For backward compatibility. This method is deprecated. Do not use it anymore.
65+
* This method also has a bug of not escaping valid regex symbols in entry path.
66+
* For module rules use: "include" instead of "test".
67+
*/
6368
exports.getEntryPathRegExp = (appFullPath, entryModule) => {
6469
const entryModuleFullPath = path.join(appFullPath, entryModule);
6570
// Windows paths contain `\`, so we need to convert each of the `\` to `\\`, so it will be correct inside RegExp

index.spec.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getConvertedExternals, getEntryPathRegExp } from './index';
2-
const path = require("path");
1+
import { getConvertedExternals } from './index';
32

43
describe('index', () => {
54
describe('getConvertedExternals', () => {
@@ -52,27 +51,4 @@ describe('index', () => {
5251
});
5352
});
5453
});
55-
56-
describe('getEntryPathRegExp', () => {
57-
const originalPathJoin = path.join;
58-
const entryModule = "index.js";
59-
60-
afterEach(() => {
61-
path.join = originalPathJoin;
62-
});
63-
64-
it('returns RegExp that matches Windows', () => {
65-
const appPath = "D:\\Work\\app1\\app";
66-
path.join = path.win32.join;
67-
const regExp = getEntryPathRegExp(appPath, entryModule);
68-
expect(!!regExp.exec(`${appPath}\\${entryModule}`)).toBe(true);
69-
});
70-
71-
it('returns RegExp that works with POSIX paths', () => {
72-
const appPath = "/usr/local/lib/app1/app";
73-
path.join = path.posix.join;
74-
const regExp = getEntryPathRegExp(appPath, entryModule);
75-
expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true);
76-
});
77-
});
7854
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"preuninstall": "node preuninstall.js",
3434
"postpack": "rm -rf node_modules",
3535
"prepare": "npm run tsc && npm run jasmine",
36-
"test": "npm run prepare && npm run jasmine",
36+
"test": "npm run prepare",
3737
"jasmine": "jasmine --config=jasmine-config/jasmine.json",
3838
"version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
3939
},
@@ -91,4 +91,4 @@
9191
"tns-core-modules": "next",
9292
"typescript": "~3.4.0"
9393
}
94-
}
94+
}

plugins/GenerateNativeScriptEntryPointsPlugin.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { convertToUnixPath } = require("../lib/utils");
12
const { RawSource } = require("webpack-sources");
23
const { getPackageJson } = require("../projectHelpers");
34
const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
@@ -55,7 +56,7 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
5556
entryChunk = chunk;
5657
} else {
5758
chunk.files.forEach(fileName => {
58-
if (!this.isHMRFile(fileName)) {
59+
if (!this.isHMRFile(fileName) && this.isSourceFile(fileName)) {
5960
requiredFiles.push(fileName);
6061
}
6162
});
@@ -71,14 +72,15 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
7172
throw new Error(`${GenerationFailedError} File "${filePath}" not found for entry "${entryPointName}".`);
7273
}
7374

74-
if (!this.isHMRFile(filePath)) {
75+
if (!this.isHMRFile(filePath) && this.isSourceFile(filePath)) {
7576
const currFileDirRelativePath = path.dirname(filePath);
7677
const pathToRootFromCurrFile = path.relative(currFileDirRelativePath, ".");
7778

7879
const requireDeps = requiredFiles.map(depPath => {
7980
const depRelativePath = path.join(pathToRootFromCurrFile, depPath);
81+
const depRelativePathUnix = convertToUnixPath(depRelativePath);
8082

81-
return `require("./${depRelativePath}");`;
83+
return `require("./${depRelativePathUnix}");`;
8284
}).join("");
8385
const currentEntryFileContent = compilation.assets[filePath].source();
8486
compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
@@ -96,5 +98,9 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
9698
return fileName.indexOf("hot-update") > -1;
9799
}
98100

101+
GenerateNativeScriptEntryPointsPlugin.prototype.isSourceFile = function (fileName) {
102+
return fileName.endsWith(".js");
103+
}
104+
99105
return GenerateNativeScriptEntryPointsPlugin;
100106
})();

templates/webpack.angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ module.exports = env => {
197197
module: {
198198
rules: [
199199
{
200-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
200+
include: join(appFullPath, entryPath),
201201
use: [
202202
// Require all Android app components
203203
platform === "android" && {

templates/webpack.config.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const nativeScriptDevWebpack = {
3131
getAppPath: () => 'app',
3232
getEntryModule: () => 'EntryModule',
3333
getResolver: () => null,
34-
getEntryPathRegExp: () => null,
3534
getConvertedExternals: nsWebpackIndex.getConvertedExternals,
3635
getSourceMapFilename: nsWebpackIndex.getSourceMapFilename
3736
};

templates/webpack.javascript.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ module.exports = env => {
9696
extensions: [".js", ".scss", ".css"],
9797
// Resolve {N} system modules from tns-core-modules
9898
modules: [
99+
resolve(__dirname, "node_modules/tns-core-modules"),
100+
resolve(__dirname, "node_modules"),
99101
"node_modules/tns-core-modules",
100102
"node_modules",
101103
],
102104
alias: {
103105
'~': appFullPath
104106
},
105-
// don't resolve symlinks to symlinked modules
107+
// resolve symlinks to symlinked modules
106108
symlinks: true
107109
},
108110
resolveLoader: {
@@ -159,7 +161,7 @@ module.exports = env => {
159161
module: {
160162
rules: [
161163
{
162-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
164+
include: join(appFullPath, entryPath),
163165
use: [
164166
// Require all Android app components
165167
platform === "android" && {

templates/webpack.typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = env => {
164164
module: {
165165
rules: [
166166
{
167-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
167+
include: join(appFullPath, entryPath),
168168
use: [
169169
// Require all Android app components
170170
platform === "android" && {

templates/webpack.vue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = env => {
170170
},
171171
module: {
172172
rules: [{
173-
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath + ".(js|ts)"),
173+
include: [join(appFullPath, entryPath + ".js"), join(appFullPath, entryPath + ".ts")],
174174
use: [
175175
// Require all Android app components
176176
platform === "android" && {

0 commit comments

Comments
 (0)