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

chore: entryPath check should work on Windows #838

Merged
merged 1 commit into from
Mar 20, 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
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ exports.getAppPath = (platform, projectDir) => {
}
};

exports.getEntryPathRegExp = (appFullPath, entryModule) => {
const entryModuleFullPath = path.join(appFullPath, entryModule);
// Windows paths contain `\`, so we need to convert each of the `\` to `\\`, so it will be correct inside RegExp
const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\");
return new RegExp(escapedPath);
}
/**
* Converts an array of strings externals to an array of regular expressions.
* 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.
Expand Down
26 changes: 25 additions & 1 deletion index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getConvertedExternals } from './index';
import { getConvertedExternals, getEntryPathRegExp } from './index';
const path = require("path");

describe('index', () => {
describe('getConvertedExternals', () => {
Expand Down Expand Up @@ -51,4 +52,27 @@ describe('index', () => {
});
});
});

describe('getEntryPathRegExp', () => {
const originalPathJoin = path.join;
const entryModule = "index.js";

afterEach(() => {
path.join = originalPathJoin;
});

it('returns RegExp that matches Windows', () => {
const appPath = "D:\\Work\\app1\\app";
path.join = path.win32.join;
const regExp = getEntryPathRegExp(appPath, entryModule);
expect(!!regExp.exec(`${appPath}\\${entryModule}`)).toBe(true);
});

it('returns RegExp that works with POSIX paths', () => {
const appPath = "/usr/local/lib/app1/app";
path.join = path.posix.join;
const regExp = getEntryPathRegExp(appPath, entryModule);
expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true);
});
});
});
2 changes: 1 addition & 1 deletion templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = env => {
module: {
rules: [
{
test: new RegExp(join(appFullPath, entryPath)),
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
1 change: 1 addition & 0 deletions templates/webpack.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const nativeScriptDevWebpack = {
getAppPath: () => 'app',
getEntryModule: () => 'EntryModule',
getResolver: () => null,
getEntryPathRegExp: () => null,
getConvertedExternals: nsWebpackIndex.getConvertedExternals
};

Expand Down
2 changes: 1 addition & 1 deletion templates/webpack.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module.exports = env => {
module: {
rules: [
{
test: new RegExp(join(appFullPath, entryPath)),
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
2 changes: 1 addition & 1 deletion templates/webpack.typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = env => {
module: {
rules: [
{
test: new RegExp(join(appFullPath, entryPath)),
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
2 changes: 1 addition & 1 deletion templates/webpack.vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = env => {
},
module: {
rules: [{
test: new RegExp(join(appFullPath, entryPath + ".(js|ts)")),
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath + ".(js|ts)"),
use: [
// Require all Android app components
platform === "android" && {
Expand Down