From 571c7f28510c2b92285b70993d067ea3ac1c7a3a Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 12 Jul 2019 15:48:34 +0300 Subject: [PATCH 01/17] fix: escape the regex for the path to the entry module of application --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2ed399dc..3d24db39 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const path = require("path"); const { existsSync } = require("fs"); +const escapeRegExp = require("escape-string-regexp"); const { ANDROID_APP_PATH } = require("./androidProjectHelpers"); const { getPackageJson, @@ -62,8 +63,7 @@ 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, "\\\\"); + const escapedPath = escapeRegExp(entryModuleFullPath); return new RegExp(escapedPath); } From 82063e287c6f0574669a5e53b2c5b3c5ba872f98 Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 12 Jul 2019 15:55:17 +0300 Subject: [PATCH 02/17] chore: add unit tests --- index.spec.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.spec.ts b/index.spec.ts index eda14f88..d97dc20d 100644 --- a/index.spec.ts +++ b/index.spec.ts @@ -61,7 +61,7 @@ describe('index', () => { path.join = originalPathJoin; }); - it('returns RegExp that matches Windows', () => { + it('returns RegExp that works with Windows paths', () => { const appPath = "D:\\Work\\app1\\app"; path.join = path.win32.join; const regExp = getEntryPathRegExp(appPath, entryModule); @@ -74,5 +74,19 @@ describe('index', () => { const regExp = getEntryPathRegExp(appPath, entryModule); expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true); }); + + it('returns RegExp that works with Windows paths with special symbol in path', () => { + const appPath = "D:\\Work\\app1\\app (2)"; + 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 with special symbol in path', () => { + const appPath = "/usr/local/lib/app1/app (2)"; + path.join = path.posix.join; + const regExp = getEntryPathRegExp(appPath, entryModule); + expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true); + }); }); }); From 2380a6ff95a75f72a5920210f5d8f9e317ad1820 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Sat, 13 Jul 2019 14:51:34 +0300 Subject: [PATCH 03/17] refactor: remove the postinstall helper info The following helper message is displayed after installation of the plugin: ``` 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 UglifyJS for minification. For more information check out https://docs.nativescript.org/tooling/bundling-with-webpack#bundling. ``` With {N} 6.0, this message is not relevant any more: 1). the `bundle` flag is not needed for webpack builds; 2). the default build/run workflow uses webpack. --- dependencyManager.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/dependencyManager.js b/dependencyManager.js index 3364a779..7ed804de 100644 --- a/dependencyManager.js +++ b/dependencyManager.js @@ -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 = { @@ -105,8 +94,6 @@ function dependsOn(packageJson, package) { } function showHelperMessages({ newDepsAdded, hasOldDeps }) { - console.info(USAGE_MESSAGE); - if (hasOldDeps) { console.info(ALREADY_ADDED_MESSAGE); } From 786bd6c209e61df202b835f30ce9e27c10a72fa8 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Tue, 16 Jul 2019 11:45:33 +0300 Subject: [PATCH 04/17] fix: don't include partial scss files in bundle (#988) * fix: don't include partial scss files in bundle * fix: imporve regex after review --- .vscode/launch.json | 3 +- bundle-config-loader.spec.ts | 114 +++++++++++++++++++++++++++++++++++ bundle-config-loader.ts | 2 +- package.json | 2 +- 4 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 bundle-config-loader.spec.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 3cd1efa9..5c1dca3e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,8 @@ "program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js", "args": [ "--config=jasmine-config/jasmine.json" - ] + ], + "preLaunchTask": "npm:tsc" }, { "type": "node", diff --git a/bundle-config-loader.spec.ts b/bundle-config-loader.spec.ts new file mode 100644 index 00000000..ec8ad99b --- /dev/null +++ b/bundle-config-loader.spec.ts @@ -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___"); + }) +}); diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index f1f0458a..6732058c 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -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 = "(? Date: Tue, 16 Jul 2019 12:01:12 +0300 Subject: [PATCH 05/17] fix(js): try to resolve node_modules from the project root before resolving in a linked location (#987) --- templates/webpack.javascript.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 2d004846..18d28bc7 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -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: { From a466730d40d04fe0b78f195df0978a5ced145913 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Tue, 16 Jul 2019 15:23:18 +0300 Subject: [PATCH 06/17] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3ed6a0c..0cfa3ef0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "1.0.0", + "version": "1.0.1", "main": "index", "description": "", "homepage": "http://www.telerik.com", From b9f0e389be60bd525d59e2978524a495133ed714 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Tue, 16 Jul 2019 18:55:25 +0300 Subject: [PATCH 07/17] release: cut the 1.0.1 release --- CHANGELOG.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3336338e..21770048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,50 @@ + +## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.1) (2019-07-16) + + +### Bug Fixes + +* add loader-utils as dep instead of dev-dep ([#975](https://github.com/NativeScript/nativescript-dev-webpack/issues/975)) ([f5b21e6](https://github.com/NativeScript/nativescript-dev-webpack/commit/f5b21e6)) +* allow overriding the `global.process` object from both the app and the plugins ([8c4292e](https://github.com/NativeScript/nativescript-dev-webpack/commit/8c4292e)) +* auto accept new or deleted files ([#972](https://github.com/NativeScript/nativescript-dev-webpack/issues/972)) ([bd893ce](https://github.com/NativeScript/nativescript-dev-webpack/commit/bd893ce)) +* avoid affecting the source maps by inserting new lines ([23675a4](https://github.com/NativeScript/nativescript-dev-webpack/commit/23675a4)) +* avoid generating invalid JavaScript when merging IIFE files ([7586d4c](https://github.com/NativeScript/nativescript-dev-webpack/commit/7586d4c)) +* create PropertyAssignment instead of string literal (Identifier) when modifying the NgModule - in some cases (e.g. when there is a decomposition in another NgModule property), the TypeScipt program is trying to read `node.name.kind` on each property causing an exception for Identifiers) ([a70fb3b](https://github.com/NativeScript/nativescript-dev-webpack/commit/a70fb3b)) +* default export crash ([#971](https://github.com/NativeScript/nativescript-dev-webpack/issues/971)) ([35d7385](https://github.com/NativeScript/nativescript-dev-webpack/commit/35d7385)) +* do not add inspector_modules entry when core modules are an external module ([e0cd8c1](https://github.com/NativeScript/nativescript-dev-webpack/commit/e0cd8c1)) +* do not include hot updates when generating requires in entry files (they have to be required and processed by the Webpack runtime) ([27360fd](https://github.com/NativeScript/nativescript-dev-webpack/commit/27360fd)) +* do not show warning for format differences in templates ([#947](https://github.com/NativeScript/nativescript-dev-webpack/issues/947)) ([a352064](https://github.com/NativeScript/nativescript-dev-webpack/commit/a352064)) +* 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)) +* don't restart application when lazy loaded code is changed in angular app with uglify option ([121c3b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/121c3b2)) +* don't throw an error from after-prepare hook when running legacy workflow with CLI <= v5.4.2 and nativescript-dev-webpack@next ([#948](https://github.com/NativeScript/nativescript-dev-webpack/issues/948)) ([1e42046](https://github.com/NativeScript/nativescript-dev-webpack/commit/1e42046)) +* emit inspector_modules as a module ([be2a5a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/be2a5a6)) +* fix app.css file path on windows machines ([7d734d8](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d734d8)) +* fix hmr for platform specific files in linked plugins ([#946](https://github.com/NativeScript/nativescript-dev-webpack/issues/946)) ([9e8c921](https://github.com/NativeScript/nativescript-dev-webpack/commit/9e8c921)) +* fix the execution of unit tests with latest unit-test-runner and nativescript-dev-webpack@rc ([#978](https://github.com/NativeScript/nativescript-dev-webpack/issues/978)) ([5423504](https://github.com/NativeScript/nativescript-dev-webpack/commit/5423504)) +* follow the symlinks in JavaScript apps ([#941](https://github.com/NativeScript/nativescript-dev-webpack/issues/941)) ([f0c62fb](https://github.com/NativeScript/nativescript-dev-webpack/commit/f0c62fb)) +* handle entry points with custom output filename like output.filename: "[name].custom.js" ([274ff53](https://github.com/NativeScript/nativescript-dev-webpack/commit/274ff53)) +* handle file dependencies in non root entry modules (e.g. tns_modules/tns_core_modules/inspector_modules) ([bcf0a5c](https://github.com/NativeScript/nativescript-dev-webpack/commit/bcf0a5c)) +* handle the `bundle-config-loader` require.context change without breaking-changes for the end-users ([#973](https://github.com/NativeScript/nativescript-dev-webpack/issues/973)) ([f48bd8c](https://github.com/NativeScript/nativescript-dev-webpack/commit/f48bd8c)) +* hmr export default crash ([#970](https://github.com/NativeScript/nativescript-dev-webpack/issues/970)) ([f1e8081](https://github.com/NativeScript/nativescript-dev-webpack/commit/f1e8081)) +* hmr should work with uglify ([#953](https://github.com/NativeScript/nativescript-dev-webpack/issues/953)) ([874e4f8](https://github.com/NativeScript/nativescript-dev-webpack/commit/874e4f8)) +* inject app.css file from unit-test-runner on test command ([#949](https://github.com/NativeScript/nativescript-dev-webpack/issues/949)) ([a216ed3](https://github.com/NativeScript/nativescript-dev-webpack/commit/a216ed3)) +* log the real snapshot tool error by trying to evaluate the input file script ([1a9c4b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/1a9c4b2)) +* migrate demo apps to android x ([c2d6684](https://github.com/NativeScript/nativescript-dev-webpack/commit/c2d6684)) +* require automatically only files from app folder of unit-test-runner ([aa4442a](https://github.com/NativeScript/nativescript-dev-webpack/commit/aa4442a)) +* throw errors when the compilation state is not valid in order to make the investigation easier ([3aef461](https://github.com/NativeScript/nativescript-dev-webpack/commit/3aef461)) +* unify the entry points handling and enable custom applications in android ([de10041](https://github.com/NativeScript/nativescript-dev-webpack/commit/de10041)) +* **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)) +* unify the TypeScript version with the Angular App (trying to fix the CI) ([7d18cc1](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d18cc1)) +* **xml-ns-loader:** remove wrong register of xml ([#940](https://github.com/NativeScript/nativescript-dev-webpack/issues/940)) ([bc2f6f1](https://github.com/NativeScript/nativescript-dev-webpack/commit/bc2f6f1)) + + +### Features + +* introduce webpack only workflow ([#882](https://github.com/NativeScript/nativescript-dev-webpack/issues/882)) ([2de4c68](https://github.com/NativeScript/nativescript-dev-webpack/commit/2de4c68)) +* **hooks:** improve hooks handling ([#961](https://github.com/NativeScript/nativescript-dev-webpack/issues/961)) ([f558607](https://github.com/NativeScript/nativescript-dev-webpack/commit/f558607)) + + + # [1.0.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.0) (2019-07-10) From 782acd3ade46902fe0d5a6dac9188e6cc2dc68a1 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Tue, 16 Jul 2019 19:09:26 +0300 Subject: [PATCH 08/17] docs: update changelog --- CHANGELOG.md | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21770048..4a0bdc55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,48 +1,11 @@ -## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.1) (2019-07-16) +## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.0...1.0.1) (2019-07-16) ### Bug Fixes -* add loader-utils as dep instead of dev-dep ([#975](https://github.com/NativeScript/nativescript-dev-webpack/issues/975)) ([f5b21e6](https://github.com/NativeScript/nativescript-dev-webpack/commit/f5b21e6)) -* allow overriding the `global.process` object from both the app and the plugins ([8c4292e](https://github.com/NativeScript/nativescript-dev-webpack/commit/8c4292e)) -* auto accept new or deleted files ([#972](https://github.com/NativeScript/nativescript-dev-webpack/issues/972)) ([bd893ce](https://github.com/NativeScript/nativescript-dev-webpack/commit/bd893ce)) -* avoid affecting the source maps by inserting new lines ([23675a4](https://github.com/NativeScript/nativescript-dev-webpack/commit/23675a4)) -* avoid generating invalid JavaScript when merging IIFE files ([7586d4c](https://github.com/NativeScript/nativescript-dev-webpack/commit/7586d4c)) -* create PropertyAssignment instead of string literal (Identifier) when modifying the NgModule - in some cases (e.g. when there is a decomposition in another NgModule property), the TypeScipt program is trying to read `node.name.kind` on each property causing an exception for Identifiers) ([a70fb3b](https://github.com/NativeScript/nativescript-dev-webpack/commit/a70fb3b)) -* default export crash ([#971](https://github.com/NativeScript/nativescript-dev-webpack/issues/971)) ([35d7385](https://github.com/NativeScript/nativescript-dev-webpack/commit/35d7385)) -* do not add inspector_modules entry when core modules are an external module ([e0cd8c1](https://github.com/NativeScript/nativescript-dev-webpack/commit/e0cd8c1)) -* do not include hot updates when generating requires in entry files (they have to be required and processed by the Webpack runtime) ([27360fd](https://github.com/NativeScript/nativescript-dev-webpack/commit/27360fd)) -* do not show warning for format differences in templates ([#947](https://github.com/NativeScript/nativescript-dev-webpack/issues/947)) ([a352064](https://github.com/NativeScript/nativescript-dev-webpack/commit/a352064)) * 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)) -* don't restart application when lazy loaded code is changed in angular app with uglify option ([121c3b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/121c3b2)) -* don't throw an error from after-prepare hook when running legacy workflow with CLI <= v5.4.2 and nativescript-dev-webpack@next ([#948](https://github.com/NativeScript/nativescript-dev-webpack/issues/948)) ([1e42046](https://github.com/NativeScript/nativescript-dev-webpack/commit/1e42046)) -* emit inspector_modules as a module ([be2a5a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/be2a5a6)) -* fix app.css file path on windows machines ([7d734d8](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d734d8)) -* fix hmr for platform specific files in linked plugins ([#946](https://github.com/NativeScript/nativescript-dev-webpack/issues/946)) ([9e8c921](https://github.com/NativeScript/nativescript-dev-webpack/commit/9e8c921)) -* fix the execution of unit tests with latest unit-test-runner and nativescript-dev-webpack@rc ([#978](https://github.com/NativeScript/nativescript-dev-webpack/issues/978)) ([5423504](https://github.com/NativeScript/nativescript-dev-webpack/commit/5423504)) -* follow the symlinks in JavaScript apps ([#941](https://github.com/NativeScript/nativescript-dev-webpack/issues/941)) ([f0c62fb](https://github.com/NativeScript/nativescript-dev-webpack/commit/f0c62fb)) -* handle entry points with custom output filename like output.filename: "[name].custom.js" ([274ff53](https://github.com/NativeScript/nativescript-dev-webpack/commit/274ff53)) -* handle file dependencies in non root entry modules (e.g. tns_modules/tns_core_modules/inspector_modules) ([bcf0a5c](https://github.com/NativeScript/nativescript-dev-webpack/commit/bcf0a5c)) -* handle the `bundle-config-loader` require.context change without breaking-changes for the end-users ([#973](https://github.com/NativeScript/nativescript-dev-webpack/issues/973)) ([f48bd8c](https://github.com/NativeScript/nativescript-dev-webpack/commit/f48bd8c)) -* hmr export default crash ([#970](https://github.com/NativeScript/nativescript-dev-webpack/issues/970)) ([f1e8081](https://github.com/NativeScript/nativescript-dev-webpack/commit/f1e8081)) -* hmr should work with uglify ([#953](https://github.com/NativeScript/nativescript-dev-webpack/issues/953)) ([874e4f8](https://github.com/NativeScript/nativescript-dev-webpack/commit/874e4f8)) -* inject app.css file from unit-test-runner on test command ([#949](https://github.com/NativeScript/nativescript-dev-webpack/issues/949)) ([a216ed3](https://github.com/NativeScript/nativescript-dev-webpack/commit/a216ed3)) -* log the real snapshot tool error by trying to evaluate the input file script ([1a9c4b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/1a9c4b2)) -* migrate demo apps to android x ([c2d6684](https://github.com/NativeScript/nativescript-dev-webpack/commit/c2d6684)) -* require automatically only files from app folder of unit-test-runner ([aa4442a](https://github.com/NativeScript/nativescript-dev-webpack/commit/aa4442a)) -* throw errors when the compilation state is not valid in order to make the investigation easier ([3aef461](https://github.com/NativeScript/nativescript-dev-webpack/commit/3aef461)) -* unify the entry points handling and enable custom applications in android ([de10041](https://github.com/NativeScript/nativescript-dev-webpack/commit/de10041)) * **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)) -* unify the TypeScript version with the Angular App (trying to fix the CI) ([7d18cc1](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d18cc1)) -* **xml-ns-loader:** remove wrong register of xml ([#940](https://github.com/NativeScript/nativescript-dev-webpack/issues/940)) ([bc2f6f1](https://github.com/NativeScript/nativescript-dev-webpack/commit/bc2f6f1)) - - -### Features - -* introduce webpack only workflow ([#882](https://github.com/NativeScript/nativescript-dev-webpack/issues/882)) ([2de4c68](https://github.com/NativeScript/nativescript-dev-webpack/commit/2de4c68)) -* **hooks:** improve hooks handling ([#961](https://github.com/NativeScript/nativescript-dev-webpack/issues/961)) ([f558607](https://github.com/NativeScript/nativescript-dev-webpack/commit/f558607)) - From 4bb61242077311384a950c0eae4bb60d41909ece Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 10 Jul 2019 16:00:27 +0300 Subject: [PATCH 09/17] fix: do not require `.js.map` files in the entry points when someone is using devtool: "source-map" --- plugins/GenerateNativeScriptEntryPointsPlugin.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/GenerateNativeScriptEntryPointsPlugin.js b/plugins/GenerateNativeScriptEntryPointsPlugin.js index 2d640e89..99edef26 100644 --- a/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ b/plugins/GenerateNativeScriptEntryPointsPlugin.js @@ -55,7 +55,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); } }); @@ -96,5 +96,9 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { return fileName.indexOf("hot-update") > -1; } + GenerateNativeScriptEntryPointsPlugin.prototype.isSourceFile = function (fileName) { + return fileName.endsWith(".js"); + } + return GenerateNativeScriptEntryPointsPlugin; })(); From 24aff45f1d3fad91ce382cb5cc7dce25e9a98410 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 17 Jul 2019 23:33:52 +0300 Subject: [PATCH 10/17] chore: bump version to 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0cfa3ef0..aad09b9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "1.0.1", + "version": "1.0.2", "main": "index", "description": "", "homepage": "http://www.telerik.com", From c3ed607c806f49e6bff62c4b16edf93bd9580002 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Mon, 22 Jul 2019 18:28:28 +0300 Subject: [PATCH 11/17] fix: vue template crashes on start (#997) --- demo/AngularApp/webpack.config.js | 2 +- demo/JavaScriptApp/webpack.config.js | 2 +- demo/TypeScriptApp/webpack.config.js | 2 +- index.js | 7 ----- index.spec.ts | 40 +--------------------------- templates/webpack.angular.js | 2 +- templates/webpack.config.spec.ts | 1 - templates/webpack.javascript.js | 2 +- templates/webpack.typescript.js | 2 +- templates/webpack.vue.js | 2 +- 10 files changed, 8 insertions(+), 54 deletions(-) diff --git a/demo/AngularApp/webpack.config.js b/demo/AngularApp/webpack.config.js index 9ad1ba8f..8137073f 100644 --- a/demo/AngularApp/webpack.config.js +++ b/demo/AngularApp/webpack.config.js @@ -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" && { diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index ddcf17ea..ec4ea0b5 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -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" && { diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 9bc21ca6..64ad184c 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -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" && { diff --git a/index.js b/index.js index 3d24db39..74afd066 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ const path = require("path"); const { existsSync } = require("fs"); -const escapeRegExp = require("escape-string-regexp"); const { ANDROID_APP_PATH } = require("./androidProjectHelpers"); const { getPackageJson, @@ -61,12 +60,6 @@ exports.getAppPath = (platform, projectDir) => { } }; -exports.getEntryPathRegExp = (appFullPath, entryModule) => { - const entryModuleFullPath = path.join(appFullPath, entryModule); - const escapedPath = escapeRegExp(entryModuleFullPath); - return new RegExp(escapedPath); -} - exports.getSourceMapFilename = (hiddenSourceMap, appFolderPath, outputPath) => { const appFolderRelativePath = path.join(path.relative(outputPath, appFolderPath)); let sourceMapFilename = "[file].map"; diff --git a/index.spec.ts b/index.spec.ts index d97dc20d..4e5471bb 100644 --- a/index.spec.ts +++ b/index.spec.ts @@ -1,5 +1,4 @@ -import { getConvertedExternals, getEntryPathRegExp } from './index'; -const path = require("path"); +import { getConvertedExternals } from './index'; describe('index', () => { describe('getConvertedExternals', () => { @@ -52,41 +51,4 @@ describe('index', () => { }); }); }); - - describe('getEntryPathRegExp', () => { - const originalPathJoin = path.join; - const entryModule = "index.js"; - - afterEach(() => { - path.join = originalPathJoin; - }); - - it('returns RegExp that works with Windows paths', () => { - 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); - }); - - it('returns RegExp that works with Windows paths with special symbol in path', () => { - const appPath = "D:\\Work\\app1\\app (2)"; - 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 with special symbol in path', () => { - const appPath = "/usr/local/lib/app1/app (2)"; - path.join = path.posix.join; - const regExp = getEntryPathRegExp(appPath, entryModule); - expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true); - }); - }); }); diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index d7cd1e78..fa623eee 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -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" && { diff --git a/templates/webpack.config.spec.ts b/templates/webpack.config.spec.ts index eced35fc..024461bd 100644 --- a/templates/webpack.config.spec.ts +++ b/templates/webpack.config.spec.ts @@ -31,7 +31,6 @@ const nativeScriptDevWebpack = { getAppPath: () => 'app', getEntryModule: () => 'EntryModule', getResolver: () => null, - getEntryPathRegExp: () => null, getConvertedExternals: nsWebpackIndex.getConvertedExternals, getSourceMapFilename: nsWebpackIndex.getSourceMapFilename }; diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 18d28bc7..f9add996 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -161,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" && { diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index a6bda652..9e0a3e84 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -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" && { diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index b0539c0e..61068c7f 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -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" && { From a6c215aa7bd6e1abf0104ed3eb33d522888cdda7 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Tue, 23 Jul 2019 15:41:54 +0300 Subject: [PATCH 12/17] fix: restore getEntryPathRegExp for backward compatibility with older webpack.config.js (#1000) --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index 74afd066..7effb6c3 100644 --- a/index.js +++ b/index.js @@ -60,6 +60,18 @@ 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 + const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\"); + return new RegExp(escapedPath); +} + exports.getSourceMapFilename = (hiddenSourceMap, appFolderPath, outputPath) => { const appFolderRelativePath = path.join(path.relative(outputPath, appFolderPath)); let sourceMapFilename = "[file].map"; From 47992714db490cdabcdd8dc11559360c826f475e Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 24 Jul 2019 09:08:13 +0300 Subject: [PATCH 13/17] fix: avoid getting invalid require calls when building from Windows --- plugins/GenerateNativeScriptEntryPointsPlugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/GenerateNativeScriptEntryPointsPlugin.js b/plugins/GenerateNativeScriptEntryPointsPlugin.js index 99edef26..1f9cd772 100644 --- a/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ b/plugins/GenerateNativeScriptEntryPointsPlugin.js @@ -1,3 +1,4 @@ +const { convertToUnixPath } = require("../lib/utils"); const { RawSource } = require("webpack-sources"); const { getPackageJson } = require("../projectHelpers"); const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin"); @@ -77,8 +78,9 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { 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}`); From 219509fd7d6ec874e3d7e646b54f97581fe90392 Mon Sep 17 00:00:00 2001 From: miroslavaivanova Date: Fri, 26 Jul 2019 13:50:16 +0300 Subject: [PATCH 14/17] release: cut the 1.0.2 release --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0bdc55..56bd54c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ + +## [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)) + + ## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.0...1.0.1) (2019-07-16) From 0ac0682597fbd42ce04898f1370c5bc6944c886d Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 29 Jul 2019 13:59:08 +0300 Subject: [PATCH 15/17] chore: bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aad09b9c..06b4cdb3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "1.0.2", + "version": "1.0.3", "main": "index", "description": "", "homepage": "http://www.telerik.com", @@ -91,4 +91,4 @@ "tns-core-modules": "next", "typescript": "~3.4.0" } -} +} \ No newline at end of file From ff07d6c0576836587c68e38bba93c20ff82f7db2 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 29 Jul 2019 13:59:37 +0300 Subject: [PATCH 16/17] fix: require dependencies only in sourceFiles (avoid getting invalid `.js.map` files) --- plugins/GenerateNativeScriptEntryPointsPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/GenerateNativeScriptEntryPointsPlugin.js b/plugins/GenerateNativeScriptEntryPointsPlugin.js index 1f9cd772..9417be22 100644 --- a/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ b/plugins/GenerateNativeScriptEntryPointsPlugin.js @@ -72,7 +72,7 @@ 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, "."); From 2ed9850a5115f1da5ab63f90c9c9b5466c350f68 Mon Sep 17 00:00:00 2001 From: Stanimira Vlaeva Date: Wed, 24 Jul 2019 10:10:52 +0300 Subject: [PATCH 17/17] =?UTF-8?q?fix(update-ns-webpack):=20skip=20the=20up?= =?UTF-8?q?date=20of=20tsconfig.tns.json=20in=E2=80=A6=20(#1001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NativeScript Angular code-sharing projects, built with the [recommended structure](https://docs.nativescript.org/angular/code-sharing/intro), have a different `tsconfig.tns.json` file compared to the rest of the {N} project flavors. The update script, distributed by the `nativescript-dev-webpack` plugin shouldn't override that file when executed in a code-sharing project. --- projectFilesManager.js | 14 ++++++++++++-- projectHelpers.js | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/projectFilesManager.js b/projectFilesManager.js index c2ccd8e1..d033d492 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -1,7 +1,7 @@ const path = require("path"); const fs = require("fs"); -const { isTypeScript, isAngular, isVue } = require("./projectHelpers"); +const { isTypeScript, isAngular, isVue, isShared } = require("./projectHelpers"); function addProjectFiles(projectDir) { const projectTemplates = getProjectTemplates(projectDir); @@ -62,7 +62,11 @@ function getProjectTemplates(projectDir) { let templates; if (isAngular({ projectDir })) { - templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + if (isShared({ projectDir })) { + templates = getSharedAngularTemplates(WEBPACK_CONFIG_NAME); + } else { + templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME); + } } else if (isVue({ projectDir })) { templates = getVueTemplates(WEBPACK_CONFIG_NAME); } else if (isTypeScript({ projectDir })) { @@ -74,6 +78,12 @@ function getProjectTemplates(projectDir) { return getFullTemplatesPath(projectDir, templates); } +function getSharedAngularTemplates(webpackConfigName) { + return { + "webpack.angular.js": webpackConfigName, + }; +} + function getAngularTemplates(webpackConfigName, tsconfigName) { return { "webpack.angular.js": webpackConfigName, diff --git a/projectHelpers.js b/projectHelpers.js index 792dd8fa..ca3a24b6 100644 --- a/projectHelpers.js +++ b/projectHelpers.js @@ -17,6 +17,11 @@ const isTypeScript = ({ projectDir, packageJson } = {}) => { ) || isAngular({ packageJson }); }; +const isShared = ({ projectDir }) => { + const nsConfig = getNsConfig(projectDir); + return nsConfig && !!nsConfig.shared; +} + const isAngular = ({ projectDir, packageJson } = {}) => { packageJson = packageJson || getPackageJson(projectDir); @@ -39,9 +44,22 @@ const isVue = ({ projectDir, packageJson } = {}) => { const getPackageJson = projectDir => { const packageJsonPath = getPackageJsonPath(projectDir); + const result = readJsonFile(packageJsonPath); + + return result; +}; + +const getNsConfig = projectDir => { + const nsConfigPath = getNsConfigPath(projectDir); + const result = readJsonFile(nsConfigPath); + + return result; +}; + +const readJsonFile = filePath => { let result; try { - result = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); + result = JSON.parse(fs.readFileSync(filePath, "utf8")); } catch (e) { result = {}; } @@ -69,6 +87,7 @@ const getIndentationCharacter = (jsonContent) => { const getProjectDir = hook.findProjectDir; const getPackageJsonPath = projectDir => resolve(projectDir, "package.json"); +const getNsConfigPath = projectDir => resolve(projectDir, "nsconfig.json"); const isAndroid = platform => /android/i.test(platform); const isIos = platform => /ios/i.test(platform); @@ -104,6 +123,7 @@ module.exports = { isAndroid, isIos, isAngular, + isShared, getAngularVersion, isVue, isTypeScript, @@ -111,4 +131,5 @@ module.exports = { convertSlashesInPath, getIndentationCharacter, safeGet, -}; \ No newline at end of file +}; +