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

Commit dc31083

Browse files
chore: entryPath check should work on Windows (#838)
In a previous commit we've changed the check when to execute the `bundle-config-loader` to be based on full path. However, the created RegExp does not match anything on Windows as the paths contain `\`, which are used for escape symbol inside RegExp. Escape the `\` and update all webpack configs with the new RegExp.
1 parent 7944611 commit dc31083

7 files changed

+36
-5
lines changed

Diff for: index.js

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ exports.getAppPath = (platform, projectDir) => {
5353
}
5454
};
5555

56+
exports.getEntryPathRegExp = (appFullPath, entryModule) => {
57+
const entryModuleFullPath = path.join(appFullPath, entryModule);
58+
// Windows paths contain `\`, so we need to convert each of the `\` to `\\`, so it will be correct inside RegExp
59+
const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\");
60+
return new RegExp(escapedPath);
61+
}
5662
/**
5763
* Converts an array of strings externals to an array of regular expressions.
5864
* Input is an array of string, which we need to convert to regular expressions, so all imports for this module will be treated as externals.

Diff for: index.spec.ts

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

34
describe('index', () => {
45
describe('getConvertedExternals', () => {
@@ -51,4 +52,27 @@ describe('index', () => {
5152
});
5253
});
5354
});
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+
});
5478
});

Diff for: templates/webpack.angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports = env => {
180180
module: {
181181
rules: [
182182
{
183-
test: new RegExp(join(appFullPath, entryPath)),
183+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
184184
use: [
185185
// Require all Android app components
186186
platform === "android" && {

Diff for: templates/webpack.config.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const nativeScriptDevWebpack = {
2121
getAppPath: () => 'app',
2222
getEntryModule: () => 'EntryModule',
2323
getResolver: () => null,
24+
getEntryPathRegExp: () => null,
2425
getConvertedExternals: nsWebpackIndex.getConvertedExternals
2526
};
2627

Diff for: templates/webpack.javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module.exports = env => {
142142
module: {
143143
rules: [
144144
{
145-
test: new RegExp(join(appFullPath, entryPath)),
145+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
146146
use: [
147147
// Require all Android app components
148148
platform === "android" && {

Diff for: templates/webpack.typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ module.exports = env => {
144144
module: {
145145
rules: [
146146
{
147-
test: new RegExp(join(appFullPath, entryPath)),
147+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
148148
use: [
149149
// Require all Android app components
150150
platform === "android" && {

Diff for: templates/webpack.vue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = env => {
155155
},
156156
module: {
157157
rules: [{
158-
test: new RegExp(join(appFullPath, entryPath + ".(js|ts)")),
158+
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath + ".(js|ts)"),
159159
use: [
160160
// Require all Android app components
161161
platform === "android" && {

0 commit comments

Comments
 (0)