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

chore: merge release into master #1011

Merged
merged 27 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
571c7f2
fix: escape the regex for the path to the entry module of application
Fatme Jul 12, 2019
82063e2
chore: add unit tests
Fatme Jul 12, 2019
2380a6f
refactor: remove the postinstall helper info
sis0k0 Jul 13, 2019
786bd6c
fix: don't include partial scss files in bundle (#988)
Jul 16, 2019
a3df142
fix(js): try to resolve node_modules from the project root before res…
Jul 16, 2019
a5c6c48
Merge pull request #984 from NativeScript/sis0k0/remove-helper-message
SvetoslavTsenov Jul 16, 2019
a466730
chore: bump version
Jul 16, 2019
318c77d
Merge pull request #991 from NativeScript/tachev/bump-version
SvetoslavTsenov Jul 16, 2019
b9f0e38
release: cut the 1.0.1 release
SvetoslavTsenov Jul 16, 2019
782acd3
docs: update changelog
SvetoslavTsenov Jul 16, 2019
d2bf15b
Merge pull request #992 from NativeScript/release-1.0.1
SvetoslavTsenov Jul 16, 2019
4bb6124
fix: do not require `.js.map` files in the entry points when someone…
DimitarTachev Jul 10, 2019
24aff45
chore: bump version to 1.0.2
Fatme Jul 17, 2019
48da2a1
Merge pull request #976 from NativeScript/tachev/source-map-files
Fatme Jul 18, 2019
5cadf73
Merge pull request #982 from NativeScript/fatme/fix-entry-module-regex
Fatme Jul 18, 2019
c3ed607
fix: vue template crashes on start (#997)
KristianDD Jul 22, 2019
a6c215a
fix: restore getEntryPathRegExp for backward compatibility with older…
KristianDD Jul 23, 2019
4799271
fix: avoid getting invalid require calls when building from Windows
DimitarTachev Jul 24, 2019
642a8f6
Merge pull request #1002 from NativeScript/tachev/fix-entry-point-mod…
Jul 24, 2019
219509f
release: cut the 1.0.2 release
miroslavaivanova Jul 26, 2019
fe2096f
Merge pull request #1007 from NativeScript/release-1.0.2
miroslavaivanova Jul 26, 2019
0ac0682
chore: bump version
DimitarTachev Jul 29, 2019
ff07d6c
fix: require dependencies only in sourceFiles (avoid getting invalid …
DimitarTachev Jul 29, 2019
2b1bbf4
Merge pull request #1008 from NativeScript/tachev/fix-source-map-files
Aug 1, 2019
2ed9850
fix(update-ns-webpack): skip the update of tsconfig.tns.json in… (#1001)
sis0k0 Jul 24, 2019
7933f6e
Merge pull request #1010 from NativeScript/tachev/pick-patch-fix
Aug 1, 2019
2372e75
chore: merge release into master
DimitarTachev Aug 1, 2019
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
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
"args": [
"--config=jasmine-config/jasmine.json"
]
],
"preLaunchTask": "npm:tsc"
},
{
"type": "node",
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<a name="1.0.2"></a>
## [1.0.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.1...1.0.2) (2019-07-26)


### Bug Fixes

* 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))
* 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))
* 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))


<a name="1.0.1"></a>
## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.0...1.0.1) (2019-07-16)


### Bug Fixes

* 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))
* **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))


<a name="1.0.0"></a>
# [1.0.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.0) (2019-07-10)

Expand Down
114 changes: 114 additions & 0 deletions bundle-config-loader.spec.ts
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___");
})
});
2 changes: 1 addition & 1 deletion bundle-config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getOptions } from "loader-utils";
import * as escapeRegExp from "escape-string-regexp";

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

const loader: loader.Loader = function (source, map) {
let {
Expand Down
2 changes: 1 addition & 1 deletion demo/AngularApp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
2 changes: 1 addition & 1 deletion demo/JavaScriptApp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
2 changes: 1 addition & 1 deletion demo/TypeScriptApp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
13 changes: 0 additions & 13 deletions dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ Some dependencies have already been added. \
If you want to force update them, please run "node_modules/.bin/update-ns-webpack".
`;

const USAGE_MESSAGE = `
NativeScript Webpack plugin was successfully added.
You can now bundle your project by passing --bundle flag to NativeScript CLI commands:
- tns build android --bundle
- tns build ios --bundle
- tns run android --bundle
- tns run ios --bundle
You can also pass the "--env.uglify" flag to use Terser for minification.
For more information check out https://docs.nativescript.org/tooling/bundling-with-webpack#bundling.
`;

function addProjectDeps(packageJson, force = false) {
packageJson.devDependencies = packageJson.devDependencies || {};
const postinstallOptions = {
Expand Down Expand Up @@ -105,8 +94,6 @@ function dependsOn(packageJson, package) {
}

function showHelperMessages({ newDepsAdded, hasOldDeps }) {
console.info(USAGE_MESSAGE);

if (hasOldDeps) {
console.info(ALREADY_ADDED_MESSAGE);
}
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ exports.getAppPath = (platform, projectDir) => {
}
};

/**
* For backward compatibility. This method is deprecated. Do not use it anymore.
* This method also has a bug of not escaping valid regex symbols in entry path.
* For module rules use: "include" instead of "test".
*/
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
Expand Down
26 changes: 1 addition & 25 deletions index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getConvertedExternals, getEntryPathRegExp } from './index';
const path = require("path");
import { getConvertedExternals } from './index';

describe('index', () => {
describe('getConvertedExternals', () => {
Expand Down Expand Up @@ -52,27 +51,4 @@ 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);
});
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"preuninstall": "node preuninstall.js",
"postpack": "rm -rf node_modules",
"prepare": "npm run tsc && npm run jasmine",
"test": "npm run prepare && npm run jasmine",
"test": "npm run prepare",
"jasmine": "jasmine --config=jasmine-config/jasmine.json",
"version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
},
Expand Down Expand Up @@ -91,4 +91,4 @@
"tns-core-modules": "next",
"typescript": "~3.4.0"
}
}
}
12 changes: 9 additions & 3 deletions plugins/GenerateNativeScriptEntryPointsPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { convertToUnixPath } = require("../lib/utils");
const { RawSource } = require("webpack-sources");
const { getPackageJson } = require("../projectHelpers");
const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
Expand Down Expand Up @@ -55,7 +56,7 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
entryChunk = chunk;
} else {
chunk.files.forEach(fileName => {
if (!this.isHMRFile(fileName)) {
if (!this.isHMRFile(fileName) && this.isSourceFile(fileName)) {
requiredFiles.push(fileName);
}
});
Expand All @@ -71,14 +72,15 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
throw new Error(`${GenerationFailedError} File "${filePath}" not found for entry "${entryPointName}".`);
}

if (!this.isHMRFile(filePath)) {
if (!this.isHMRFile(filePath) && this.isSourceFile(filePath)) {
const currFileDirRelativePath = path.dirname(filePath);
const pathToRootFromCurrFile = path.relative(currFileDirRelativePath, ".");

const requireDeps = requiredFiles.map(depPath => {
const depRelativePath = path.join(pathToRootFromCurrFile, depPath);
const depRelativePathUnix = convertToUnixPath(depRelativePath);

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

GenerateNativeScriptEntryPointsPlugin.prototype.isSourceFile = function (fileName) {
return fileName.endsWith(".js");
}

return GenerateNativeScriptEntryPointsPlugin;
})();
2 changes: 1 addition & 1 deletion templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(appFullPath, entryPath),
use: [
// Require all Android app components
platform === "android" && {
Expand Down
1 change: 0 additions & 1 deletion templates/webpack.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const nativeScriptDevWebpack = {
getAppPath: () => 'app',
getEntryModule: () => 'EntryModule',
getResolver: () => null,
getEntryPathRegExp: () => null,
getConvertedExternals: nsWebpackIndex.getConvertedExternals,
getSourceMapFilename: nsWebpackIndex.getSourceMapFilename
};
Expand Down
6 changes: 4 additions & 2 deletions templates/webpack.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ module.exports = env => {
extensions: [".js", ".scss", ".css"],
// Resolve {N} system modules from tns-core-modules
modules: [
resolve(__dirname, "node_modules/tns-core-modules"),
resolve(__dirname, "node_modules"),
"node_modules/tns-core-modules",
"node_modules",
],
alias: {
'~': appFullPath
},
// don't resolve symlinks to symlinked modules
// resolve symlinks to symlinked modules
symlinks: true
},
resolveLoader: {
Expand Down Expand Up @@ -159,7 +161,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(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 @@ -164,7 +164,7 @@ module.exports = env => {
module: {
rules: [
{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath),
include: join(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 @@ -170,7 +170,7 @@ module.exports = env => {
},
module: {
rules: [{
test: nsWebpack.getEntryPathRegExp(appFullPath, entryPath + ".(js|ts)"),
include: [join(appFullPath, entryPath + ".js"), join(appFullPath, entryPath + ".ts")],
use: [
// Require all Android app components
platform === "android" && {
Expand Down