From dbf6bdc414e84c319193e58cf2176070e30d6d42 Mon Sep 17 00:00:00 2001 From: mudlabs Date: Fri, 24 May 2019 08:11:53 +1000 Subject: [PATCH 01/20] Update webpack-bundle-analyzer to patch 3.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15212580..c93e5f39 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "terser-webpack-plugin": "1.2.3", "ts-loader": "^5.3.1", "webpack": "~4.27.0", - "webpack-bundle-analyzer": "~3.0.2", + "webpack-bundle-analyzer": "^3.3.2", "webpack-cli": "~3.1.1", "webpack-sources": "~1.3.0" }, From 76314ee3ec04dc9a223a122f58af87bc5b569bf1 Mon Sep 17 00:00:00 2001 From: Sam <32623552+mudlabs@users.noreply.github.com> Date: Thu, 6 Jun 2019 09:00:05 +1000 Subject: [PATCH 02/20] Update package.json Co-Authored-By: Kristian Dimitrov --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c93e5f39..ee408e4e 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "terser-webpack-plugin": "1.2.3", "ts-loader": "^5.3.1", "webpack": "~4.27.0", - "webpack-bundle-analyzer": "^3.3.2", + "webpack-bundle-analyzer": "~3.3.2", "webpack-cli": "~3.1.1", "webpack-sources": "~1.3.0" }, From 121c3b27cff08d98d7f74e8b4aea262203add5e8 Mon Sep 17 00:00:00 2001 From: fatme Date: Sun, 30 Jun 2019 23:48:46 +0300 Subject: [PATCH 03/20] fix: don't restart application when lazy loaded code is changed in angular app with uglify option Currently there is a logic that gets all runtime files and entry point files from webpack compilation. These files are needed to CLI in order to decides if the application should be restarted or refreshed on device(when there is at least one file that is not hot update file, CLI restarts the application). However, this logic doesn't work for lazy loaded modules in angular application as they are reported neither entry point files nor runtime files. Lazy loaded modules are directly injected into webpack compilation using the hooks of ContextModuleFactory - https://github.com/angular/ngtools-webpack-builds/blob/39ccb0b487e92a7ac4330ff9db821337b7aa5c45/src/angular_compiler_plugin.js#L516. This PR fixes the behavior with lazy loaded files as it gets all chunks produced from webpack compilation and omits hot-update.js files from them. Chunk files are all files except hot update files. Chunk files are: `runtime.js`, `tns_modules/inspector-modules.js`, `bundle.js`, `vendor.js` and all lazy loaded modules. When a files is changed in hmr mode, .hot-update.js file is included into chunk files. This way we don't need to separate the files to entry point, runtime, lazy loaded and others. We just need to omit .hot-update.js file from chunk files from webpack compilation. --- plugins/WatchStateLoggerPlugin.ts | 47 ++++++++----------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/plugins/WatchStateLoggerPlugin.ts b/plugins/WatchStateLoggerPlugin.ts index e10bca88..7e5302d7 100644 --- a/plugins/WatchStateLoggerPlugin.ts +++ b/plugins/WatchStateLoggerPlugin.ts @@ -33,51 +33,28 @@ export class WatchStateLoggerPlugin { .keys(compilation.assets) .filter(assetKey => compilation.assets[assetKey].emitted); - const webpackRuntimeFiles = getWebpackRuntimeOnlyFiles(compilation); - const entryPointFiles = getEntryPointFiles(compilation); + const chunkFiles = getChunkFiles(compilation); process.send && process.send(messages.compilationComplete, error => null); // Send emitted files so they can be LiveSynced if need be - process.send && process.send({ emittedFiles, webpackRuntimeFiles, entryPointFiles }, error => null); + process.send && process.send({ emittedFiles, chunkFiles }, error => null); }); } } -function getWebpackRuntimeOnlyFiles(compilation) { - let runtimeOnlyFiles = []; +function getChunkFiles(compilation) { + const chunkFiles = []; try { - runtimeOnlyFiles = [].concat(...Array.from(compilation.entrypoints.values()) - .map(entrypoint => entrypoint.runtimeChunk) - // filter embedded runtime chunks (e.g. part of bundle.js or inspector-modules.js) - .filter(runtimeChunk => !!runtimeChunk && runtimeChunk.preventIntegration) - .map(runtimeChunk => runtimeChunk.files)) - // get only the unique files in case of "single" runtime (e.g. runtime.js) - .filter((value, index, self) => self.indexOf(value) === index); - } catch (e) { - // breaking change in the Webpack API - console.log("Warning: Unable to find Webpack runtime files."); - } - - return runtimeOnlyFiles; -} - -function getEntryPointFiles(compilation) { - const entryPointFiles = []; - try { - Array.from(compilation.entrypoints.values()) - .forEach((entrypoint: any) => { - for (const entryChunk of entrypoint.chunks) { - entryChunk.files.forEach(fileName => { - if (fileName.indexOf("hot-update") === -1) { - entryPointFiles.push(fileName); - } - }); + compilation.chunks.forEach(chunk => { + chunk.files.forEach(file => { + if (file.indexOf("hot-update") === -1) { + chunkFiles.push(file); } }); + }); } catch (e) { - console.log("Warning: Unable to find Webpack entry point files."); + console.log("Warning: Unable to find chunk files."); } - return entryPointFiles - .filter((value, index, self) => self.indexOf(value) === index); // get only the unique files -} \ No newline at end of file + return chunkFiles; +} From a70fb3b937968b294aacdd437fcd6d21a86345b3 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 1 Jul 2019 15:36:05 +0300 Subject: [PATCH 04/20] fix: 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) --- transformers/ns-replace-lazy-loader.spec.ts | 37 +++++++++++++++++++++ transformers/ns-replace-lazy-loader.ts | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/transformers/ns-replace-lazy-loader.spec.ts b/transformers/ns-replace-lazy-loader.spec.ts index b3628dfc..cdf49df6 100644 --- a/transformers/ns-replace-lazy-loader.spec.ts +++ b/transformers/ns-replace-lazy-loader.spec.ts @@ -43,6 +43,43 @@ describe("@ngtools/webpack transformers", () => { AppModule); export { AppModule };` }, + { + name: "should add providers and NgModuleFactoryLoader when providers is missing and decomposition is used", + rawAppModule: ` + import { NgModule } from "@angular/core"; + import { NativeScriptModule } from "nativescript-angular/nativescript.module"; + import { AppComponent } from "./app.component"; + + const declarationsArray = [AppComponent]; + @NgModule({ + bootstrap: [ + AppComponent + ], + imports: [ + NativeScriptModule + ], + declarations: [ + ...declarationsArray + ] + }) + export class AppModule { } + `, + transformedAppModule: ` + import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core"; + import { NativeScriptModule } from "nativescript-angular/nativescript.module"; + import { AppComponent } from "./app.component"; + ${NgLazyLoaderCode} + const declarationsArray = [AppComponent]; + let AppModule = class AppModule { }; + AppModule = tslib_1.__decorate([ NgModule({ + bootstrap: [ AppComponent ], + imports: [ NativeScriptModule ], + declarations: [ ...declarationsArray ], + providers: [{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] }) + ], + AppModule); + export { AppModule };` + }, { name: "should add NgModuleFactoryLoader when the providers array is empty", rawAppModule: ` diff --git a/transformers/ns-replace-lazy-loader.ts b/transformers/ns-replace-lazy-loader.ts index 9823e801..99f9774f 100644 --- a/transformers/ns-replace-lazy-loader.ts +++ b/transformers/ns-replace-lazy-loader.ts @@ -93,7 +93,8 @@ export function addArrayPropertyValueToNgModule( // the target field is missing, we will insert it @NgModule({ otherProps }) const lastConfigObjPropertyNode = ngModuleConfigObjectNode.properties[ngModuleConfigObjectNode.properties.length - 1]; - const newTargetPropertyNode = ts.createIdentifier(`${targetPropertyName}: [${newPropertyValue}]`); + + const newTargetPropertyNode = ts.createPropertyAssignment(targetPropertyName, ts.createIdentifier(`[${newPropertyValue}]`)); return [ new AddNodeOperation(sourceFile, lastConfigObjPropertyNode, undefined, newTargetPropertyNode), From 7d18cc19b25d6eae547acba25f15db88a29ad46c Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Tue, 2 Jul 2019 11:17:02 +0300 Subject: [PATCH 05/20] fix: unify the TypeScript version with the Angular App (trying to fix the CI) --- demo/TypeScriptApp/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/TypeScriptApp/package.json b/demo/TypeScriptApp/package.json index f98d9675..aabe8c7e 100644 --- a/demo/TypeScriptApp/package.json +++ b/demo/TypeScriptApp/package.json @@ -28,7 +28,7 @@ "mochawesome": "~3.1.2", "nativescript-dev-appium": "next", "nativescript-dev-webpack": "next", - "typescript": "~3.2.2", + "typescript": "~3.4.1", "node-sass": "^4.12.0" }, "scripts": { From f558607d95ed2b7bed962c3de06d2b94524e2184 Mon Sep 17 00:00:00 2001 From: Rosen Vladimirov Date: Tue, 2 Jul 2019 13:34:08 +0300 Subject: [PATCH 06/20] feat(hooks): improve hooks handling (#961) * fix(preuninstall): add preuninstall script to remove old hooks During migration from one version to another or when the plugin is removed from application we need to remove its hooks. This is usually done in preuninstall script, however, it was missing until now. This causes several issues when the version is updated as old hooks remain, but they may not be valid anymore. * fix(postinstall): remove old hooks As in 1.0.0 and CLI 6.0 we've changed the way nativescript-dev-webpack interacts with CLI, we need to remove hooks from previous nativescript-dev-webpack versions and use new ones. Usually this should happen with preuninstall script of the old version that removes the hooks. However, our current live version does not have such logic, so implement this in the postinstall of the current version. This way we try to ensure the current plugin will work correctly. * feat(hooks): add before-checkForChanges hook Add before-checkForChanges hook to prevent users from using the current version of the plugin with CLI 5.x.x or older. These two versions are incompatible, so add an error in case older CLI is used. --- lib/before-checkForChanges.js | 16 ++++++++++++++ package.json | 6 ++++++ postinstall.js | 39 +++++++++++++++++++++++++++++++++-- preuninstall.js | 11 ++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 lib/before-checkForChanges.js create mode 100644 preuninstall.js diff --git a/lib/before-checkForChanges.js b/lib/before-checkForChanges.js new file mode 100644 index 00000000..d456a1d3 --- /dev/null +++ b/lib/before-checkForChanges.js @@ -0,0 +1,16 @@ +module.exports = function ($staticConfig, hookArgs) { + const majorVersionMatch = ($staticConfig.version || '').match(/^(\d+)\./); + const majorVersion = majorVersionMatch && majorVersionMatch[1] && +majorVersionMatch[1]; + if (majorVersion && majorVersion < 6) { + // check if we are using the bundle workflow or the legacy one. + const isUsingBundleWorkflow = hookArgs && + hookArgs.checkForChangesOpts && + hookArgs.checkForChangesOpts.projectChangesOptions && + hookArgs.checkForChangesOpts.projectChangesOptions.bundle; + + if (isUsingBundleWorkflow) { + const packageJsonData = require("../package.json") + throw new Error(`The current version of ${packageJsonData.name} (${packageJsonData.version}) is not compatible with the used CLI: ${$staticConfig.version}. Please upgrade your NativeScript CLI version (npm i -g nativescript).`); + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 24e125e1..de7ef1b9 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,11 @@ "type": "after-prepare", "script": "lib/after-prepare.js", "inject": true + }, + { + "type": "before-checkForChanges", + "script": "lib/before-checkForChanges.js", + "inject": true } ] }, @@ -24,6 +29,7 @@ }, "scripts": { "postinstall": "node postinstall.js", + "preuninstall": "node preuninstall.js", "postpack": "rm -rf node_modules", "prepare": "tsc && npm run jasmine", "test": "npm run prepare && npm run jasmine", diff --git a/postinstall.js b/postinstall.js index 54d6b163..1956dcf5 100644 --- a/postinstall.js +++ b/postinstall.js @@ -1,16 +1,50 @@ "use strict"; -const { dirname } = require("path"); const hook = require("nativescript-hook")(__dirname); const { compareProjectFiles } = require("./projectFilesManager"); const { getProjectDir } = require("./projectHelpers"); +const path = require("path"); +const fs = require("fs"); const projectDir = getProjectDir(); +// This method is introduced as in version 1.0.0 of nativescript-dev-webpack (compatible and required for NativeScript 6.0.0) +// we have changed a lot of hooks and old ones are incompatible. This should be automatically handled with preuninstall script of the old version. +// However, old versions of nativescript-dev-webpack do not have such logic, so remove them manually on postinstall of the current version. +// This logic can be removed later, once most of the projects are migrated to 1.0.0 of the package or later. +// These new versions have preuninstall script that will automatically handle this case. +function removeOldHooks() { + const oldHooks = [ + "before-prepareJSApp", + "before-cleanApp", + "before-watch", + "after-watch", + "before-watchPatterns", + "before-shouldPrepare", + "after-prepare", + "before-preview-sync" + ]; + + const hooksDir = path.join(projectDir, "hooks"); + const pkgName = require("./package.json").name; + const filename = `${pkgName}.js`; + oldHooks.forEach(hookName => { + const hookPath = path.join(hooksDir, hookName, filename); + + try { + if (fs.existsSync(hookPath)) { + fs.unlinkSync(hookPath); + } + } catch (err) { + console.warn(`${pkgName} postinstall task: unable to delete hook ${hookPath}. Error is: ${err}`); + } + }); +} + if (projectDir) { compareProjectFiles(projectDir); - + removeOldHooks(); hook.postinstall(); const installer = require("./installer"); installer.install(); @@ -18,3 +52,4 @@ if (projectDir) { // We are installing dev dependencies for the nativescript-dev-webpack plugin. console.log("Skipping postinstall artifacts! We assumed the nativescript-dev-webpack is installing devDependencies"); } + diff --git a/preuninstall.js b/preuninstall.js new file mode 100644 index 00000000..8632200f --- /dev/null +++ b/preuninstall.js @@ -0,0 +1,11 @@ +"use strict"; + +const hook = require("nativescript-hook")(__dirname); + +const { getProjectDir } = require("./projectHelpers"); + +const projectDir = getProjectDir(); + +if (projectDir) { + hook.preuninstall(); +} From 8c4292e09add87b28b08d4439999413ed3d314d0 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 3 Jul 2019 09:47:59 +0300 Subject: [PATCH 07/20] fix: allow overriding the `global.process` object from both the app and the plugins By default it will be undefined but the plugins and the app developers will be able to polyfill it. We had the same behavior with the Legacy Workflow. --- templates/webpack.angular.js | 2 +- templates/webpack.javascript.js | 2 +- templates/webpack.typescript.js | 2 +- templates/webpack.vue.js | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index e94ffc0d..22b0b558 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -262,7 +262,7 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", - "process": undefined, + "process": "global.process", }), // Remove all files from the out dir. new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }), diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index c910a055..b976e827 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -213,7 +213,7 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", - "process": undefined, + "process": "global.process", }), // Remove all files from the out dir. new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }), diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index daf5a94b..b04e72e2 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -237,7 +237,7 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", - "process": undefined, + "process": "global.process", }), // Remove all files from the out dir. new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }), diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 1d451d4c..600c399c 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -75,7 +75,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "src", "main", "assets", "snapshots")}`); itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } - + const config = { mode: mode, context: appFullPath, @@ -238,7 +238,8 @@ module.exports = env => { // Define useful constants like TNS_WEBPACK new webpack.DefinePlugin({ "global.TNS_WEBPACK": "true", - "TNS_ENV": JSON.stringify(mode) + "TNS_ENV": JSON.stringify(mode), + "process": "global.process" }), // Remove all files from the out dir. new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }), From 7586d4c9ae2e7809c87035302578d09aa515d9d8 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 4 Jul 2019 11:42:47 +0300 Subject: [PATCH 08/20] fix: avoid generating invalid JavaScript when merging IIFE files --- snapshot/android/snapshot-generator.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/snapshot/android/snapshot-generator.js b/snapshot/android/snapshot-generator.js index 2bb1a7eb..c16e40f7 100644 --- a/snapshot/android/snapshot-generator.js +++ b/snapshot/android/snapshot-generator.js @@ -48,7 +48,19 @@ SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFi const bundlePreambleContent = fs.readFileSync(BUNDLE_PREAMBLE_PATH, "utf8"); const bundleEndingContent = fs.readFileSync(BUNDLE_ENDING_PATH, "utf8"); - const inputFilesContent = inputFiles.map(file => fs.readFileSync(file, "utf8")).join("\n"); + // IMPORTANT: join by "\n;" as we are joining IIFE functions and if the snapshot tool is used + // along with Uglify configuration for replacing `;` with `/n`, we will generate invalid JavaScript + // Example: + // (function() { + // some code here + // })() + // // sourceMapUrl...... + // ** when we join without `;` here, the next IIFE is assumed as a function call to the result of the first IIFE + // (function() { + // some code here + // })() + // // sourceMapUrl...... + const inputFilesContent = inputFiles.map(file => fs.readFileSync(file, "utf8")).join("\n;"); const snapshotFileContent = bundlePreambleContent + "\n" + inputFilesContent + "\n" + bundleEndingContent; fs.writeFileSync(outputFile, snapshotFileContent, { encoding: "utf8" }); } From 1a9c4b2193338ac522236153c4f72b4e635ebe57 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 4 Jul 2019 11:46:32 +0300 Subject: [PATCH 09/20] fix: log the real snapshot tool error by trying to evaluate the input file script --- snapshot/android/snapshot-generator.js | 34 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/snapshot/android/snapshot-generator.js b/snapshot/android/snapshot-generator.js index c16e40f7..8c177809 100644 --- a/snapshot/android/snapshot-generator.js +++ b/snapshot/android/snapshot-generator.js @@ -43,7 +43,7 @@ module.exports = SnapshotGenerator; SnapshotGenerator.SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot"; -SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFile) { +SnapshotGenerator.prototype.preprocessInputFiles = function (inputFiles, outputFile) { // Make some modifcations on the original bundle and save it on the specified path const bundlePreambleContent = fs.readFileSync(BUNDLE_PREAMBLE_PATH, "utf8"); const bundleEndingContent = fs.readFileSync(BUNDLE_ENDING_PATH, "utf8"); @@ -67,7 +67,7 @@ SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFi const snapshotToolsDownloads = {}; -SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath, v8Version, targetArch) { +SnapshotGenerator.prototype.downloadMksnapshotTool = function (snapshotToolsPath, v8Version, targetArch) { const hostOS = getHostOS(); const mksnapshotToolRelativePath = join("mksnapshot-tools", "v8-v" + v8Version, hostOS + "-" + os.arch(), "mksnapshot-" + targetArch); const mksnapshotToolPath = join(snapshotToolsPath, mksnapshotToolRelativePath); @@ -96,7 +96,7 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath, return snapshotToolsDownloads[mksnapshotToolPath]; } -SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) { +SnapshotGenerator.prototype.convertToAndroidArchName = function (archName) { switch (archName) { case "arm": return "armeabi-v7a"; case "arm64": return "arm64-v8a"; @@ -106,7 +106,7 @@ SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) { } } -SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams) { +SnapshotGenerator.prototype.runMksnapshotTool = function (snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams) { // Cleans the snapshot build folder shelljs.rm("-rf", join(this.buildPath, "snapshots")); @@ -132,14 +132,22 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu const command = `${currentArchMksnapshotToolPath} ${inputFile} --startup_blob ${join(currentArchBlobOutputPath, `${SNAPSHOT_BLOB_NAME}.blob`)} ${params}`; return new Promise((resolve, reject) => { - const child = child_process.exec(command, {encoding: "utf8"}, (error, stdout, stderr) => { + const child = child_process.exec(command, { encoding: "utf8" }, (error, stdout, stderr) => { const errorHeader = `Target architecture: ${androidArch}\n`; + let errorFooter = ``; + if (stderr.length || error) { + try { + require(inputFile); + } catch (e) { + errorFooter = `\nJavaScript execution error: ${e.stack}$`; + } + } if (stderr.length) { - const message = `${errorHeader}${stderr}`; + const message = `${errorHeader}${stderr}${errorFooter}`; reject(new Error(message)); } else if (error) { - error.message = `${errorHeader}${error.message}`; + error.message = `${errorHeader}${error.message}${errorFooter}`; reject(error); } else { console.log(stdout); @@ -151,7 +159,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu if (buildCSource) { const currentArchSrcOutputPath = join(this.buildPath, "snapshots/src", androidArch); shelljs.mkdir("-p", currentArchSrcOutputPath); - shellJsExecuteInDir(currentArchBlobOutputPath, function() { + shellJsExecuteInDir(currentArchBlobOutputPath, function () { shelljs.exec(`xxd -i ${SNAPSHOT_BLOB_NAME}.blob > ${join(currentArchSrcOutputPath, `${SNAPSHOT_BLOB_NAME}.c`)}`); }); } @@ -162,7 +170,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu }); } -SnapshotGenerator.prototype.buildSnapshotLibs = function(androidNdkBuildPath, targetArchs) { +SnapshotGenerator.prototype.buildSnapshotLibs = function (androidNdkBuildPath, targetArchs) { // Compile *.c files to produce *.so libraries with ndk-build tool const ndkBuildPath = join(this.buildPath, "ndk-build"); const androidArchs = targetArchs.map(arch => this.convertToAndroidArchName(arch)); @@ -171,22 +179,22 @@ SnapshotGenerator.prototype.buildSnapshotLibs = function(androidNdkBuildPath, ta shelljs.cp("-r", NDK_BUILD_SEED_PATH, ndkBuildPath); fs.writeFileSync(join(ndkBuildPath, "jni/Application.mk"), "APP_ABI := " + androidArchs.join(" ")); // create Application.mk file shelljs.mv(join(this.buildPath, "snapshots/src/*"), join(ndkBuildPath, "jni")); - shellJsExecuteInDir(ndkBuildPath, function(){ + shellJsExecuteInDir(ndkBuildPath, function () { shelljs.exec(androidNdkBuildPath); }); return join(ndkBuildPath, "libs"); } -SnapshotGenerator.prototype.buildIncludeGradle = function() { +SnapshotGenerator.prototype.buildIncludeGradle = function () { shelljs.cp(INCLUDE_GRADLE_PATH, join(this.buildPath, "include.gradle")); } -SnapshotGenerator.prototype.generate = function(options) { +SnapshotGenerator.prototype.generate = function (options) { // Arguments validation options = options || {}; if (!options.v8Version) { throw new Error("No v8 version specified."); } if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); } - const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed"); + const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed"); console.log("***** Starting snapshot generation using V8 version: ", options.v8Version); From d3b5cab8a6e7434d830c0cc5c342246355412cd7 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Mon, 8 Jul 2019 11:13:22 +0300 Subject: [PATCH 10/20] test: update tests to ns-dev-appium v6 (#969) --- demo/.gitignore | 3 +- demo/AngularApp/.vscode/launch.json | 7 +- demo/AngularApp/e2e/tests.e2e-spec.ts | 25 +--- demo/AngularApp/e2e/tsconfig.json | 1 + .../e2e/config/appium.capabilities.json | 122 ------------------ demo/JavaScriptApp/e2e/tests.e2e-spec.js | 18 +-- demo/TypeScriptApp/.vscode/launch.json | 5 +- .../e2e/config/appium.capabilities.json | 106 --------------- demo/TypeScriptApp/e2e/config/mocha.opts | 5 - demo/TypeScriptApp/e2e/tests.e2e-spec.ts | 17 +-- demo/config/mocha.opts | 2 +- 11 files changed, 18 insertions(+), 293 deletions(-) delete mode 100644 demo/JavaScriptApp/e2e/config/appium.capabilities.json delete mode 100644 demo/TypeScriptApp/e2e/config/appium.capabilities.json delete mode 100644 demo/TypeScriptApp/e2e/config/mocha.opts diff --git a/demo/.gitignore b/demo/.gitignore index dcdcde1a..ee19ca4e 100644 --- a/demo/.gitignore +++ b/demo/.gitignore @@ -16,4 +16,5 @@ tsconfig.aot.json vendor.js vendor.ts -tsconfig.esm.json \ No newline at end of file +tsconfig.esm.json +mochawesome-report \ No newline at end of file diff --git a/demo/AngularApp/.vscode/launch.json b/demo/AngularApp/.vscode/launch.json index c8276a2a..4c86d32e 100644 --- a/demo/AngularApp/.vscode/launch.json +++ b/demo/AngularApp/.vscode/launch.json @@ -16,11 +16,8 @@ "999999", "--colors", "--opts", - "./e2e/config/mocha.opts", - "--runType", - "android23", - "--reuseDevice" - // "${workspaceFolder}/test" + "../config/mocha.opts", + "android" ], "internalConsoleOptions": "openOnSessionStart" }, diff --git a/demo/AngularApp/e2e/tests.e2e-spec.ts b/demo/AngularApp/e2e/tests.e2e-spec.ts index 47e67d10..aa8c75be 100644 --- a/demo/AngularApp/e2e/tests.e2e-spec.ts +++ b/demo/AngularApp/e2e/tests.e2e-spec.ts @@ -1,29 +1,14 @@ -import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium"; +import { AppiumDriver, createDriver, nsCapabilities } from "nativescript-dev-appium"; import { assert } from "chai"; describe("sample scenario", async function () { let driver: AppiumDriver; before(async function () { + nsCapabilities.testReporter.context = this; driver = await createDriver(); }); - beforeEach(async function () { - try { - const items = await getItems(); - } catch (err) { - try { - const lblNinjas = await driver.findElementByText("Ninjas!"); - } - catch (err) { - console.log("Navigating to ninjas page ..."); - await driver.navBack(); - } - console.log("Navigating to main page ..."); - await driver.navBack(); - } - }); - afterEach(async function () { if (this.currentTest.state === "failed") { await driver.logTestArtifacts(this.currentTest.title); @@ -36,7 +21,7 @@ describe("sample scenario", async function () { }); it("should navigate to a ninja", async function () { - const btnNinjas = await driver.findElementByText("Ninjas"); + const btnNinjas = await driver.waitForElement("Ninjas"); await btnNinjas.click(); const itemMichaelangelo = await driver.findElementByText("Michaelangelo"); @@ -61,10 +46,10 @@ describe("sample scenario", async function () { for (let styleType in styleTypes) { it(`should find an element with ${styleType} style applied`, async function () { const element = await driver.findElementByText(styleTypes[styleType]); + driver.imageHelper.options.keepOriginalImageSize = false; + driver.imageHelper.options.isDeviceSpecific = false; const result = await driver.compareElement(element, "style"); assert.isTrue(result); }); } - - const getItems = async function () { return driver.isAndroid ? await driver.findElementsByText("(Android)") : await driver.findElementsByText("(ios)"); } }); diff --git a/demo/AngularApp/e2e/tsconfig.json b/demo/AngularApp/e2e/tsconfig.json index abb4a3a7..74d502ac 100644 --- a/demo/AngularApp/e2e/tsconfig.json +++ b/demo/AngularApp/e2e/tsconfig.json @@ -5,6 +5,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "importHelpers": false, + "sourceMap": true, "types": [ "mocha", "chai", diff --git a/demo/JavaScriptApp/e2e/config/appium.capabilities.json b/demo/JavaScriptApp/e2e/config/appium.capabilities.json deleted file mode 100644 index b4c9be76..00000000 --- a/demo/JavaScriptApp/e2e/config/appium.capabilities.json +++ /dev/null @@ -1,122 +0,0 @@ -{ - "android19": { - "platformName": "Android", - "platformVersion": "4.4", - "deviceName": "Emulator-Api19-Default", - "avd": "Emulator-Api19-Default", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android21": { - "platformName": "Android", - "platformVersion": "5.0", - "deviceName": "Emulator-Api21-Default", - "avd": "Emulator-Api21-Default", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android23": { - "platformName": "Android", - "platformVersion": "6.0", - "deviceName": "Emulator-Api23-Default", - "avd": "Emulator-Api23-Default", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android24": { - "platformName": "Android", - "platformVersion": "7.0", - "deviceName": "Emulator-Api24-Default", - "avd": "Emulator-Api24-Default", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android25": { - "platformName": "Android", - "platformVersion": "7.1", - "deviceName": "Emulator-Api25-Google", - "avd": "Emulator-Api25-Google", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android26": { - "platformName": "Android", - "platformVersion": "8.0", - "deviceName": "Emulator-Api26-Google", - "avd": "Emulator-Api26-Google", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android27": { - "platformName": "Android", - "platformVersion": "27", - "deviceName": "Emulator-Api27-Google", - "avd": "Emulator-Api27-Google", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "android28": { - "platformName": "Android", - "platformVersion": "28", - "deviceName": "Emulator-Api28-Google", - "avd": "Emulator-Api28-Google", - "lt": 60000, - "newCommandTimeout": 720, - "noReset": false, - "fullReset": false, - "app": "" - }, - "sim.iPhone7": { - "platformName": "iOS", - "platformVersion": "/12.*/", - "deviceName": "iPhone 7", - "noReset": false, - "fullReset": false, - "app": "" - }, - "sim.iPhone8": { - "platformName": "iOS", - "platformVersion": "/12*/", - "deviceName": "iPhone 8", - "noReset": false, - "fullReset": false, - "app": "" - }, - "sim.iPhoneX": { - "platformName": "iOS", - "platformVersion": "/12*/", - "deviceName": "iPhone X", - "noReset": false, - "fullReset": false, - "app": "" - }, - "sim.iPhoneXS": { - "platformName": "ios", - "platformVersion": "/12*/", - "deviceName": "iPhone XS", - "noReset": false, - "fullReset": false, - "app": "" - } -} \ No newline at end of file diff --git a/demo/JavaScriptApp/e2e/tests.e2e-spec.js b/demo/JavaScriptApp/e2e/tests.e2e-spec.js index bd889360..43ea4512 100644 --- a/demo/JavaScriptApp/e2e/tests.e2e-spec.js +++ b/demo/JavaScriptApp/e2e/tests.e2e-spec.js @@ -9,16 +9,6 @@ describe("sample scenario", function () { driver = await nsAppium.createDriver(); })); - beforeEach(async function () { - try { - const lblPlatform = await getPlatformLabel(); - } - catch (err) { - console.log("Navigating to main page ..."); - await driver.navBack(); - } - }); - afterEach(async function () { if (this.currentTest.state === "failed") { await driver.logTestArtifacts(this.currentTest.title); @@ -53,12 +43,10 @@ describe("sample scenario", function () { it(`should find an element with ${styleType} style applied`, async function () { const element = await driver.findElementByText(styleTypes[styleType]); + driver.imageHelper.options.keepOriginalImageSize = false; + driver.imageHelper.options.isDeviceSpecific = false; const result = await driver.compareElement(element, "style"); - chai.assert.isTrue(result); + assert.isTrue(result); }); } - - const getPlatformLabel = async function() { - return driver.isAndroid ? await driver.findElementByText("android") : await driver.findElementByText("ios"); - } }); \ No newline at end of file diff --git a/demo/TypeScriptApp/.vscode/launch.json b/demo/TypeScriptApp/.vscode/launch.json index f0519850..60b22ed9 100644 --- a/demo/TypeScriptApp/.vscode/launch.json +++ b/demo/TypeScriptApp/.vscode/launch.json @@ -17,10 +17,7 @@ "--colors", "--opts", "./e2e/config/mocha.opts", - "--runType", - "android23", - "--reuseDevice" - // "${workspaceFolder}/test" + "-a" ], "internalConsoleOptions": "openOnSessionStart" }, diff --git a/demo/TypeScriptApp/e2e/config/appium.capabilities.json b/demo/TypeScriptApp/e2e/config/appium.capabilities.json deleted file mode 100644 index 3cd2bab2..00000000 --- a/demo/TypeScriptApp/e2e/config/appium.capabilities.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "android19": { - "platformName": "Android", - "platformVersion": "4.4", - "deviceName": "Emulator-Api19-Default", - "avd": "Emulator-Api19-Default", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "android21": { - "platformName": "Android", - "platformVersion": "5.0", - "deviceName": "Emulator-Api21-Default", - "avd": "Emulator-Api21-Default", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "android23": { - "platformName": "Android", - "platformVersion": "6.0", - "deviceName": "Emulator-Api23-Default", - "avd": "Emulator-Api23-Default", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "android24": { - "platformName": "Android", - "platformVersion": "7.0", - "deviceName": "Emulator-Api24-Default", - "avd": "Emulator-Api24-Default", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "android25": { - "platformName": "Android", - "platformVersion": "7.1", - "deviceName": "Emulator-Api25-Google", - "avd": "Emulator-Api25-Google", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "android26": { - "platformName": "Android", - "platformVersion": "8.0", - "deviceName": "Emulator-Api26-Google", - "avd": "Emulator-Api26-Google", - "lt": 60000, - "appActivity": "com.tns.NativeScriptActivity", - "newCommandTimeout": 720, - "noReset": true, - "fullReset": false, - "app": "" - }, - "sim.iPhone7.iOS100": { - "platformName": "iOS", - "platformVersion": "10.0", - "deviceName": "iPhone 7 100", - "noReset": true, - "fullReset": false, - "app": "" - }, - "sim.iPhone8.iOS110": { - "platformName": "iOS", - "platformVersion": "11.2", - "deviceName": "iPhone 8 110", - "noReset": true, - "fullReset": false, - "app": "" - }, - "sim.iPhoneX.iOS110": { - "platformName": "iOS", - "platformVersion": "11.2", - "deviceName": "iPhone X", - "noReset": true, - "fullReset": false, - "app": "" - }, - "sim.iPhoneX.iOS111": { - "platformName": "iOS", - "platformVersion": "11.1", - "deviceName": "iPhone X", - "noReset": true, - "fullReset": false, - "app": "" - } -} diff --git a/demo/TypeScriptApp/e2e/config/mocha.opts b/demo/TypeScriptApp/e2e/config/mocha.opts deleted file mode 100644 index c21dcca6..00000000 --- a/demo/TypeScriptApp/e2e/config/mocha.opts +++ /dev/null @@ -1,5 +0,0 @@ ---timeout 999999 ---recursive e2e ---reporter mochawesome ---reporter-options quiet=true,html=true,inline=true,autoOpen=true ---exit \ No newline at end of file diff --git a/demo/TypeScriptApp/e2e/tests.e2e-spec.ts b/demo/TypeScriptApp/e2e/tests.e2e-spec.ts index 37920f3c..3f549eff 100644 --- a/demo/TypeScriptApp/e2e/tests.e2e-spec.ts +++ b/demo/TypeScriptApp/e2e/tests.e2e-spec.ts @@ -9,19 +9,9 @@ describe("sample scenario", () => { driver = await createDriver(); }); - beforeEach(async function () { - try { - const lblPlatform = await getPlatformLabel(); - } catch (err) { - console.log("Navigating to main page ..."); - await driver.navBack(); - } - }); - afterEach(async function () { if (this.currentTest.state === "failed") { - await driver.logPageSource(this.currentTest.title); - await driver.logScreenshot(this.currentTest.title); + await driver.logTestArtifacts(this.currentTest.title); } }); @@ -33,7 +23,6 @@ describe("sample scenario", () => { it("should the button on second page work", async function () { const btnNav = await driver.findElementByText("btnNav"); await btnNav.tap(); - const secondPage = await driver.findElementByText("Second Page"); const btnZero = await driver.findElementByText("0"); await btnZero.tap(); @@ -64,10 +53,10 @@ describe("sample scenario", () => { for (let styleType in styleTypes) { it(`should find an element with ${styleType} style applied`, async function () { const element = await driver.findElementByText(styleTypes[styleType]); + driver.imageHelper.options.keepOriginalImageSize = false; + driver.imageHelper.options.isDeviceSpecific = false; const result = await driver.compareElement(element, "style"); assert.isTrue(result); }); } - - const getPlatformLabel = async function () { return driver.isAndroid ? await driver.findElementByText("android") : await driver.findElementByText("ios"); } }); \ No newline at end of file diff --git a/demo/config/mocha.opts b/demo/config/mocha.opts index 8e77e681..c21dcca6 100644 --- a/demo/config/mocha.opts +++ b/demo/config/mocha.opts @@ -1,4 +1,4 @@ ---timeout 80000 +--timeout 999999 --recursive e2e --reporter mochawesome --reporter-options quiet=true,html=true,inline=true,autoOpen=true From d4a8dec803acf39b7cdeb4f3bc8c23284046fe67 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Mon, 8 Jul 2019 11:44:39 +0300 Subject: [PATCH 11/20] refactor: HMR and webpack improvements (#966) * feat: support for file qualifiers * refactor: convert bundle-config-loader to TS * chore: vs code tasks * chore: convert hmr folder to TS * feat: universal hmr loader * feat: no need of "page" suffix for HMR to work * chore: add tns-core-modules as dev dep * fix: filter d.ts files * refactor: don't include native app/activity in bundle * refactor: review changes --- .gitignore | 14 +++--- .vscode/launch.json | 10 +++++ .vscode/tasks.json | 13 ++++++ ...onfig-loader.js => bundle-config-loader.ts | 22 ++++++++-- demo/AngularApp/webpack.config.js | 1 - demo/JavaScriptApp/webpack.config.js | 20 +++------ demo/TypeScriptApp/webpack.config.js | 18 ++------ hmr/hmr-update.js | 7 --- hmr/hmr-update.ts | 10 +++++ hmr/hot-loader.ts | 44 +++++++++++++++++++ hmr/index.js | 1 - hmr/index.ts | 1 + jasmine-config/jasmine.json | 3 +- package.json | 9 +++- templates/webpack.angular.js | 1 - templates/webpack.javascript.js | 15 +------ templates/webpack.typescript.js | 17 ++----- templates/webpack.vue.js | 1 - 18 files changed, 126 insertions(+), 81 deletions(-) create mode 100644 .vscode/tasks.json rename bundle-config-loader.js => bundle-config-loader.ts (74%) delete mode 100644 hmr/hmr-update.js create mode 100644 hmr/hmr-update.ts create mode 100644 hmr/hot-loader.ts delete mode 100644 hmr/index.js create mode 100644 hmr/index.ts diff --git a/.gitignore b/.gitignore index cee7d177..8f8de90d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,34 +2,34 @@ node_modules *.tgz package-lock.json +*.js.map plugins/NativeScriptAngularCompilerPlugin.d.ts plugins/NativeScriptAngularCompilerPlugin.js -plugins/NativeScriptAngularCompilerPlugin.js.map transformers/*.d.ts transformers/*.js -transformers/*.js.map utils/*.d.ts utils/*.js -utils/*.js.map + +hmr/*.d.ts +hmr/*.js plugins/PlatformFSPlugin.d.ts plugins/PlatformFSPlugin.js -plugins/PlatformFSPlugin.js.map plugins/WatchStateLoggerPlugin.d.ts plugins/WatchStateLoggerPlugin.js -plugins/WatchStateLoggerPlugin.js.map host/resolver.d.ts host/resolver.js -host/resolver.js.map jasmine-config/reporter.d.ts jasmine-config/reporter.js -jasmine-config/reporter.js.map + +bundle-config-loader.d.ts +bundle-config-loader.js **/*.spec.js* **/*.spec.d.ts* diff --git a/.vscode/launch.json b/.vscode/launch.json index d77d2b08..3cd1efa9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,16 @@ "args": [ "--env.android", "--env.aot" ], "runtimeArgs": [ "--preserve-symlinks" ], "stopOnEntry": true, + }, + { + "type": "node", + "request": "launch", + "name": "TypeScriptApp Webpack", + "cwd": "${workspaceFolder}/demo/TypeScriptApp", + "program": "${workspaceFolder}/demo/TypeScriptApp/node_modules/.bin/webpack", + "args": [ "--env.android" ], + "stopOnEntry": true, + "preLaunchTask": "npm:tsc" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..79199e22 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label":"npm:tsc", + "type": "npm", + "script": "tsc", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/bundle-config-loader.js b/bundle-config-loader.ts similarity index 74% rename from bundle-config-loader.js rename to bundle-config-loader.ts index 4daa915b..da7d4196 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.ts @@ -1,8 +1,19 @@ -const unitTestingConfigLoader = require("./unit-testing-config-loader"); +import unitTestingConfigLoader from "./unit-testing-config-loader"; +import { loader } from "webpack"; +import { getOptions } from "loader-utils"; -module.exports = function (source, map) { - this.cacheable(); - const { angular = false, loadCss = true, unitTesting, projectRoot, appFullPath, registerModules = /(root|page)\.(xml|css|js|ts|scss)$/ } = this.query; +// Matches all source, markup and style files that are not in App_Resources +const defaultMatch = /(? { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index e285ce31..27bfc2db 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -28,7 +28,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -103,7 +102,7 @@ module.exports = env => { '~': appFullPath }, // don't resolve symlinks to symlinked modules - symlinks: false + symlinks: true }, resolveLoader: { // don't resolve symlinks to symlinked loaders @@ -174,24 +173,15 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + registerModules: /(? !!loader) }, { - test: /-page\.js$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(js|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, @@ -234,7 +224,7 @@ module.exports = env => { platforms, }), // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), + new nsWebpack.WatchStateLoggerPlugin() ], }; diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 74dfb0dd..88f3585f 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -29,7 +29,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -180,24 +179,15 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + registerModules: /(? !!loader) }, { - test: /-page\.ts$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(ts|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, @@ -265,7 +255,7 @@ module.exports = env => { async: false, useTypescriptIncrementalApi: true, memoryLimit: 4096 - }), + }) ], }; diff --git a/hmr/hmr-update.js b/hmr/hmr-update.js deleted file mode 100644 index 9536d4fe..00000000 --- a/hmr/hmr-update.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = () => { - const update = require("../hot"); - const fileSystemModule = require("tns-core-modules/file-system"); - const applicationFiles = fileSystemModule.knownFolders.currentApp(); - const latestHash = __webpack_require__["h"](); - return update(latestHash, filename => applicationFiles.getFile(filename)); -} \ No newline at end of file diff --git a/hmr/hmr-update.ts b/hmr/hmr-update.ts new file mode 100644 index 00000000..5f29792d --- /dev/null +++ b/hmr/hmr-update.ts @@ -0,0 +1,10 @@ +import update from "../hot"; +import { knownFolders } from "tns-core-modules/file-system"; + +declare const __webpack_require__: any; + +export function hmrUpdate() { + const applicationFiles = knownFolders.currentApp(); + const latestHash = __webpack_require__["h"](); + return update(latestHash, filename => applicationFiles.getFile(filename)); +} \ No newline at end of file diff --git a/hmr/hot-loader.ts b/hmr/hot-loader.ts new file mode 100644 index 00000000..2a0fca71 --- /dev/null +++ b/hmr/hot-loader.ts @@ -0,0 +1,44 @@ +import { loader } from "webpack"; +import { convertToUnixPath } from "../lib/utils"; +import { extname } from "path"; +import { getOptions } from "loader-utils"; + +const extMap = { + ".css": "style", + ".scss": "style", + ".less": "style", + ".js": "script", + ".ts": "script", + ".xml": "markup", + ".html": "markup", +} + +const loader: loader.Loader = function (source, map) { + const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); + const modulePath = convertToUnixPath(moduleRelativePath); + const ext = extname(modulePath).toLowerCase(); + const moduleType = extMap[ext] || "unknown"; + + const options = getOptions(this) || {}; + const alwaysSelfAccept = options.alwaysSelfAccept; + const trace = options.trace; + + const shouldAutoAcceptCheck = `&& global._isModuleLoadedForUI && global._isModuleLoadedForUI("${modulePath}")`; + const traceCode = `console.log("[hot-loader]: Self-accept module: ${modulePath}");`; + + const hotCode = ` +if (module.hot ${alwaysSelfAccept ? "" : shouldAutoAcceptCheck} ) { + ${trace ? traceCode : ""} + module.hot.accept(); + module.hot.dispose(() => { + global.hmrRefresh({ type: "${moduleType}", path: "${modulePath}" }); + }); +}`; + + this.callback(null, `${source}; ${hotCode} `, map); +}; + +export default loader; + + + diff --git a/hmr/index.js b/hmr/index.js deleted file mode 100644 index bdda024f..00000000 --- a/hmr/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.hmrUpdate = require("./hmr-update"); \ No newline at end of file diff --git a/hmr/index.ts b/hmr/index.ts new file mode 100644 index 00000000..24abe3c0 --- /dev/null +++ b/hmr/index.ts @@ -0,0 +1 @@ +export { hmrUpdate } from "./hmr-update"; \ No newline at end of file diff --git a/jasmine-config/jasmine.json b/jasmine-config/jasmine.json index 84db3eb2..8d3ecdc5 100644 --- a/jasmine-config/jasmine.json +++ b/jasmine-config/jasmine.json @@ -1,7 +1,8 @@ { "spec_dir": ".", "spec_files": [ - "./!(node_modules)/**/*.spec.js", + "!node_modules/**/*.spec.js", + "!demo/**/*.spec.js", "./*.spec.js" ], "helpers": [ diff --git a/package.json b/package.json index f5bce176..8004580e 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,11 @@ "url": "https://github.com/NativeScript/nativescript-dev-webpack.git" }, "scripts": { + "tsc": "tsc", "postinstall": "node postinstall.js", "preuninstall": "node preuninstall.js", "postpack": "rm -rf node_modules", - "prepare": "tsc && npm run jasmine", + "prepare": "npm run tsc && npm run jasmine", "test": "npm run prepare && npm run jasmine", "jasmine": "jasmine --config=jasmine-config/jasmine.json", "version": "rm package-lock.json && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md" @@ -49,8 +50,8 @@ "clean-webpack-plugin": "~1.0.0", "copy-webpack-plugin": "~4.6.0", "css-loader": "~2.1.1", - "fork-ts-checker-webpack-plugin": "1.3.0", "extra-watch-webpack-plugin": "1.0.3", + "fork-ts-checker-webpack-plugin": "1.3.0", "global-modules-path": "2.0.0", "minimatch": "3.0.4", "nativescript-hook": "0.2.4", @@ -77,13 +78,17 @@ "@angular/compiler-cli": "8.0.0", "@ngtools/webpack": "8.0.0", "@types/jasmine": "^3.3.7", + "@types/loader-utils": "^1.1.3", "@types/node": "^10.12.12", "@types/proxyquire": "1.3.28", "@types/semver": "^6.0.0", + "@types/webpack": "^4.4.34", "conventional-changelog-cli": "^1.3.22", "jasmine": "^3.2.0", "jasmine-spec-reporter": "^4.2.1", + "loader-utils": "^1.2.3", "proxyquire": "2.1.0", + "tns-core-modules": "next", "typescript": "~3.4.0" } } diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 22b0b558..f2933c5f 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -32,7 +32,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index b976e827..e6515456 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -27,7 +27,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -179,18 +178,8 @@ module.exports = env => { }, { - test: /-page\.js$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - - { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(js|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index b04e72e2..8c7627bf 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -28,7 +28,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from @@ -183,20 +182,10 @@ module.exports = env => { }, ].filter(loader => !!loader) }, - - { - test: /-page\.ts$/, - use: "nativescript-dev-webpack/script-hot-loader" - }, - - { - test: /\.(css|scss)$/, - use: "nativescript-dev-webpack/style-hot-loader" - }, - + { - test: /\.(html|xml)$/, - use: "nativescript-dev-webpack/markup-hot-loader" + test: /\.(ts|css|scss|html|xml)$/, + use: "nativescript-dev-webpack/hmr/hot-loader" }, { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 600c399c..df96d8e1 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -31,7 +31,6 @@ module.exports = env => { // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; const { // The 'appPath' and 'appResourcesPath' values are fetched from From f1e808190fa50831b66db369fba9eb153fdcce40 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Mon, 8 Jul 2019 13:54:41 +0300 Subject: [PATCH 12/20] fix: hmr export default crash (#970) --- hmr/hmr-update.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hmr/hmr-update.ts b/hmr/hmr-update.ts index 5f29792d..6ad9b3d1 100644 --- a/hmr/hmr-update.ts +++ b/hmr/hmr-update.ts @@ -1,4 +1,4 @@ -import update from "../hot"; +import * as hot from "../hot"; import { knownFolders } from "tns-core-modules/file-system"; declare const __webpack_require__: any; @@ -6,5 +6,5 @@ declare const __webpack_require__: any; export function hmrUpdate() { const applicationFiles = knownFolders.currentApp(); const latestHash = __webpack_require__["h"](); - return update(latestHash, filename => applicationFiles.getFile(filename)); + return hot(latestHash, filename => applicationFiles.getFile(filename)); } \ No newline at end of file From 35d73852b3a903abfa710c5ce15f8c71de753365 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Mon, 8 Jul 2019 18:24:18 +0300 Subject: [PATCH 13/20] fix: default export crash (#971) --- bundle-config-loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index da7d4196..cd4c981b 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -1,4 +1,4 @@ -import unitTestingConfigLoader from "./unit-testing-config-loader"; +import * as unitTestingConfigLoader from "./unit-testing-config-loader"; import { loader } from "webpack"; import { getOptions } from "loader-utils"; From f48bd8c75fe37701faf2fd7852b541b850e96344 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Wed, 10 Jul 2019 00:22:42 +0300 Subject: [PATCH 14/20] fix: handle the `bundle-config-loader` require.context change without breaking-changes for the end-users (#973) --- bundle-config-loader.ts | 16 ++++++++++--- demo/AngularApp/webpack.config.js | 2 ++ demo/JavaScriptApp/webpack.config.js | 3 ++- demo/TypeScriptApp/webpack.config.js | 3 ++- index.js | 35 ++++++++++++++++++++++++++++ templates/webpack.angular.js | 2 ++ templates/webpack.javascript.js | 3 +++ templates/webpack.typescript.js | 2 ++ templates/webpack.vue.js | 2 ++ 9 files changed, 63 insertions(+), 5 deletions(-) diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index cd4c981b..7557874c 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -1,20 +1,30 @@ import * as unitTestingConfigLoader from "./unit-testing-config-loader"; import { loader } from "webpack"; 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 = /(? { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -213,6 +214,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) } }, ].filter(loader => !!loader) diff --git a/demo/JavaScriptApp/webpack.config.js b/demo/JavaScriptApp/webpack.config.js index 27bfc2db..ddcf17ea 100644 --- a/demo/JavaScriptApp/webpack.config.js +++ b/demo/JavaScriptApp/webpack.config.js @@ -69,6 +69,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -173,7 +174,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, - registerModules: /(? !!loader) diff --git a/demo/TypeScriptApp/webpack.config.js b/demo/TypeScriptApp/webpack.config.js index 88f3585f..9bc21ca6 100644 --- a/demo/TypeScriptApp/webpack.config.js +++ b/demo/TypeScriptApp/webpack.config.js @@ -73,6 +73,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -179,7 +180,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, - registerModules: /(? !!loader) diff --git a/index.js b/index.js index e76ce2cb..2ed399dc 100644 --- a/index.js +++ b/index.js @@ -98,6 +98,41 @@ exports.getConvertedExternals = (externals) => { return modifiedExternals; }; + +/** + * The `require.context` call in `bundle-config-loader` will ask the FS for files and + * the PlatformFSPlugin will return files without `.${platform}`. The SplitChunksPlugin will + * compare the `appComponents` with the files returned from the `PlatformFSPlugin` and when they + * do not match because of the platform extension, it will duplicate the custom components + * in `bundle` (activity.js - included by the `require.context` call in `bundle-config-loader`) + * and `vendor` (activity.android.js - included by `android-app-components-loader` and `SplitChunksPlugin`). + * We are post-processing the `appComponents` in order to unify the file names and avoid getting + * a build-time SBG exception for duplicate native class definition. + */ +exports.processAppComponents = (appComponents, platform) => { + for (const key in appComponents) { + appComponents[key] = appComponents[key].replace(`.${platform}`, ""); + } +}; + +/** + * The `bundle-config-loader` needs this in order to skip the custom entries in its `require.context` call. + * If we don't skip them, custom entries like custom Android application will be included in both `application.js` + * (because its defined as an entry) and `bundle.js` (included by the `require.context` call in `bundle-config-loader`) + * causing a build-time SBG exception for duplicate native class definition. + * We are removing the extension in order to unify the file names with the `PlatformFSPlugin`. + */ +exports.getUserDefinedEntries = (entries, platform) => { + const userDefinedEntries = []; + for (const entry in entries) { + if (entry !== "bundle" && entry !== "tns_modules/tns-core-modules/inspector_modules") { + userDefinedEntries.push(entries[entry].replace(`.${platform}`, "")); + } + } + + return userDefinedEntries; +}; + const sanitize = name => name .split("") .filter(char => /[a-zA-Z0-9]/.test(char)) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index f2933c5f..d7cd1e78 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -108,6 +108,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -212,6 +213,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) } }, ].filter(loader => !!loader) diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index e6515456..2d004846 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -68,6 +68,8 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -172,6 +174,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) } }, ].filter(loader => !!loader) diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 8c7627bf..a6bda652 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -72,6 +72,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", context: appFullPath, @@ -178,6 +179,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) } }, ].filter(loader => !!loader) diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index df96d8e1..b0539c0e 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -75,6 +75,7 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: mode, context: appFullPath, @@ -185,6 +186,7 @@ module.exports = env => { unitTesting, appFullPath, projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) }, }, ].filter(loader => Boolean(loader)), From bd893ce6cfbda0d49ed9f4ffbf69d8769ba6dbe1 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Wed, 10 Jul 2019 10:49:09 +0300 Subject: [PATCH 15/20] fix: auto accept new or deleted files (#972) --- bundle-config-loader.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bundle-config-loader.ts b/bundle-config-loader.ts index 7557874c..f1f0458a 100644 --- a/bundle-config-loader.ts +++ b/bundle-config-loader.ts @@ -72,6 +72,11 @@ const loader: loader.Loader = function (source, map) { ${hmr} const context = require.context("~/", true, ${registerModules}); global.registerWebpackModules(context); + if (module.hot) { + module.hot.accept(context.id, () => { + console.log("HMR: Accept module '" + context.id + "' from '" + module.id + "'"); + }); + } ${source} `; } From aa4442a4b14c719d125196771a44118cb9214cb6 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 10 Jul 2019 13:51:08 +0300 Subject: [PATCH 16/20] fix: require automatically only files from app folder of unit-test-runner --- unit-testing-config-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit-testing-config-loader.js b/unit-testing-config-loader.js index b92fa3a6..981c3a4f 100644 --- a/unit-testing-config-loader.js +++ b/unit-testing-config-loader.js @@ -4,7 +4,7 @@ const { convertSlashesInPath } = require("./projectHelpers"); module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) { // TODO: Consider to use the files property from karma.conf.js const testFilesRegExp = /tests\/.*\.(ts|js)/; - const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner"); + const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner", "app"); const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath)); const appCssFilePath = convertSlashesInPath(join(runnerRelativePath, "app.css")); let source = ` From f5b21e602f3fd8624a60acdc256c3365eb671cb4 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Wed, 10 Jul 2019 16:15:03 +0300 Subject: [PATCH 17/20] fix: add loader-utils as dep instead of dev-dep (#975) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8004580e..44b3793b 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "extra-watch-webpack-plugin": "1.0.3", "fork-ts-checker-webpack-plugin": "1.3.0", "global-modules-path": "2.0.0", + "loader-utils": "^1.2.3", "minimatch": "3.0.4", "nativescript-hook": "0.2.4", "nativescript-worker-loader": "~0.9.0", @@ -86,7 +87,6 @@ "conventional-changelog-cli": "^1.3.22", "jasmine": "^3.2.0", "jasmine-spec-reporter": "^4.2.1", - "loader-utils": "^1.2.3", "proxyquire": "2.1.0", "tns-core-modules": "next", "typescript": "~3.4.0" From 5423504cdcaf0f865fc48e48719990aabec67e94 Mon Sep 17 00:00:00 2001 From: Fatme Date: Wed, 10 Jul 2019 21:47:07 +0300 Subject: [PATCH 18/20] fix: fix the execution of unit tests with latest unit-test-runner and nativescript-dev-webpack@rc (#978) With the latest rc of nativescript-dev-webpack it is not possible to run unit tests as the nativescript-dev-webpack searches for app folder inside runner root folder. As such folder doesn't exist in live version of nativescript-unit-test-runner, test command throws an error. --- unit-testing-config-loader.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/unit-testing-config-loader.js b/unit-testing-config-loader.js index 981c3a4f..e3d4a2ff 100644 --- a/unit-testing-config-loader.js +++ b/unit-testing-config-loader.js @@ -1,10 +1,19 @@ const { join, relative } = require("path"); +const { existsSync } = require("fs"); const { convertSlashesInPath } = require("./projectHelpers"); +function getRunnerFullPath(projectRoot) { + const runnerRootPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner"); + const runnerAppPath = join(runnerRootPath, "app"); + const result = existsSync(runnerAppPath) ? runnerAppPath : runnerRootPath; + + return result; +} + module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) { // TODO: Consider to use the files property from karma.conf.js const testFilesRegExp = /tests\/.*\.(ts|js)/; - const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner", "app"); + const runnerFullPath = getRunnerFullPath(projectRoot); const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath)); const appCssFilePath = convertSlashesInPath(join(runnerRelativePath, "app.css")); let source = ` From cf746316606a8d1dbe799fe71b6736914508da77 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Wed, 10 Jul 2019 21:56:10 +0300 Subject: [PATCH 19/20] release: cut the 1.0.0 release (#977) --- CHANGELOG.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c06f845e..3336338e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,43 @@ + +# [1.0.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.0) (2019-07-10) + + +### Bug Fixes + +* 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 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)) +* 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 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 restart application when lazy loaded code is changed in angular app with uglify option ([121c3b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/121c3b2)) +* 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)) +* 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)) +* 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)) +* **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)) +* 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)) +* unify the entry points handling and enable custom applications in android ([de10041](https://github.com/NativeScript/nativescript-dev-webpack/commit/de10041)) +* **hooks:** improve hooks handling ([#961](https://github.com/NativeScript/nativescript-dev-webpack/issues/961)) ([f558607](https://github.com/NativeScript/nativescript-dev-webpack/commit/f558607)) + +### 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)) +* no need of "page" suffix ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) +* support for file qualifiers ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) +* universal hmr loader ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) + +### BREAKING CHANGES: + +* the file names of the NativeScript pages are not required to end with `-page` or `-root`. All `xml`, `css`, `js`, `ts` and `scss` files are not included in the bundle. + +* the plugin is not working with NativeScript CLI older than 6.0.0 (`nativescript@6.0.0`). + +* the Webpack mode it set to `production` based on the `--release` flag of the NativeScript CLI, instead of the `--env.uglify` one. + ## [0.24.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.0...0.24.1) (2019-06-06) From 0585a91bfe7ef926f19dd54a0482397d1256c7c7 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 15 Jul 2019 18:08:17 +0300 Subject: [PATCH 20/20] chore: bump version to 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 44b3793b..90a97bf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "1.0.0", + "version": "1.1.0", "main": "index", "description": "", "homepage": "http://www.telerik.com",