From 5cd319fdab238e2b3c245dee2789d0dda9235fac Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 10 Apr 2019 15:53:25 +0300 Subject: [PATCH 1/2] fix: avoid losing the source map in some loader --- android-app-components-loader.js | 4 ++-- apply-css-loader.js | 4 ++-- bundle-config-loader.js | 4 ++-- css2json-loader.js | 6 +++--- markup-hot-loader.js | 5 +++-- script-hot-loader.js | 4 ++-- style-hot-loader.js | 5 +++-- xml-namespace-loader.js | 10 +++++----- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/android-app-components-loader.js b/android-app-components-loader.js index 57760e1e..7f0218b7 100644 --- a/android-app-components-loader.js +++ b/android-app-components-loader.js @@ -1,6 +1,6 @@ const { convertSlashesInPath } = require("./projectHelpers"); -module.exports = function (source) { +module.exports = function (source, map) { this.cacheable(); const { modules } = this.query; const imports = modules.map(convertSlashesInPath) @@ -14,5 +14,5 @@ module.exports = function (source) { ${source} `; - this.callback(null, augmentedSource); + this.callback(null, augmentedSource, map); }; diff --git a/apply-css-loader.js b/apply-css-loader.js index 36e92c13..a543e525 100644 --- a/apply-css-loader.js +++ b/apply-css-loader.js @@ -1,4 +1,4 @@ -module.exports = function(content) { +module.exports = function (content, map) { if (this.request.match(/\/app\.(css|scss|less|sass)$/)) { return content; } @@ -14,5 +14,5 @@ module.exports = function(content) { }); `; - return content; + this.callback(null, content, map); } \ No newline at end of file diff --git a/bundle-config-loader.js b/bundle-config-loader.js index cf403453..4daa915b 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.js @@ -1,6 +1,6 @@ const unitTestingConfigLoader = require("./unit-testing-config-loader"); -module.exports = function (source) { +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; @@ -66,5 +66,5 @@ module.exports = function (source) { `; } - this.callback(null, source); + this.callback(null, source, map); }; diff --git a/css2json-loader.js b/css2json-loader.js index 3f7820bc..022d645b 100644 --- a/css2json-loader.js +++ b/css2json-loader.js @@ -1,15 +1,15 @@ const parse = require("tns-core-modules/css").parse; const nl = "\n"; -module.exports = function(content) { +module.exports = function (content, map) { const ast = parse(content); const dependencies = getImportsFrom(ast) .map(mapURI) - .reduce((dependencies, {uri, requireURI}) => + .reduce((dependencies, { uri, requireURI }) => dependencies + `global.registerModule(${uri}, () => require(${requireURI}));${nl}`, ""); const str = JSON.stringify(ast, (k, v) => k === "position" ? undefined : v); - return `${dependencies}module.exports = ${str};`; + this.callback(null, `${dependencies}module.exports = ${str};`, map); } function getImportsFrom(ast) { diff --git a/markup-hot-loader.js b/markup-hot-loader.js index e811dd5d..50b0654e 100644 --- a/markup-hot-loader.js +++ b/markup-hot-loader.js @@ -1,9 +1,10 @@ const { reload } = require("./hot-loader-helper"); const { convertToUnixPath } = require("./lib/utils"); -module.exports = function (source) { +module.exports = function (source, map) { const typeMarkup = "markup"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); const modulePath = convertToUnixPath(moduleRelativePath); - return `${source};${reload({ type: typeMarkup, path: modulePath })}`; + + this.callback(null, `${source};${reload({ type: typeMarkup, path: modulePath })}`, map); }; diff --git a/script-hot-loader.js b/script-hot-loader.js index b9d07416..1b1d243d 100644 --- a/script-hot-loader.js +++ b/script-hot-loader.js @@ -1,9 +1,9 @@ const { reload } = require("./hot-loader-helper"); const { convertToUnixPath } = require("./lib/utils"); -module.exports = function (source) { +module.exports = function (source, map) { const typeScript = "script"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); const modulePath = convertToUnixPath(moduleRelativePath); - return `${source};${reload({ type: typeScript, path: modulePath })}`; + this.callback(null, `${source};${reload({ type: typeScript, path: modulePath })}`, map); }; diff --git a/style-hot-loader.js b/style-hot-loader.js index c4c3822a..79f13852 100644 --- a/style-hot-loader.js +++ b/style-hot-loader.js @@ -1,9 +1,10 @@ const { reload } = require("./hot-loader-helper"); const { convertToUnixPath } = require("./lib/utils"); -module.exports = function (source) { +module.exports = function (source, map) { const typeStyle = "style"; const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); const modulePath = convertToUnixPath(moduleRelativePath); - return `${source};${reload({ type: typeStyle, path: modulePath })}`; + + this.callback(null, `${source};${reload({ type: typeStyle, path: modulePath })}`, map); }; diff --git a/xml-namespace-loader.js b/xml-namespace-loader.js index 729d8417..e5359f3d 100644 --- a/xml-namespace-loader.js +++ b/xml-namespace-loader.js @@ -2,7 +2,7 @@ const { parse, relative, join, basename, extname } = require("path"); const { promisify } = require('util'); const { convertSlashesInPath } = require("./projectHelpers"); -module.exports = function (source) { +module.exports = function (source, map) { this.value = source; const { ignore } = this.query; const callback = this.async(); @@ -41,14 +41,14 @@ module.exports = function (source) { this.addDependency(xml); namespaces.push({ name: `${moduleName}.xml`, path: xml }); }) - .catch((err) => {}), + .catch((err) => { }), resolvePromise(this.context, `${noExtFilename}.css`) .then((css) => { this.addDependency(css); namespaces.push({ name: `${moduleName}.css`, path: css }); }) - .catch((err) => {}) + .catch((err) => { }) ]); }; @@ -75,7 +75,7 @@ module.exports = function (source) { namespaces.push({ name: `${moduleName}.css`, path: css }); this.addDependency(css); }) - .catch(() => {}) + .catch(() => { }) ]); }); @@ -102,7 +102,7 @@ module.exports = function (source) { const wrapped = `${moduleRegisters}\nmodule.exports = ${json}`; - callback(null, wrapped); + callback(null, wrapped, map); }).catch((err) => { callback(err); }) From 8f881cd12dae85444a76691d96ffe763232258c1 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 10 Apr 2019 17:21:27 +0300 Subject: [PATCH 2/2] fix: generate TypeScript source maps --- templates/webpack.typescript.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 730c38ee..579ce396 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -8,7 +8,7 @@ const CopyWebpackPlugin = require("copy-webpack-plugin"); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const hashSalt = Date.now().toString(); +const hashSalt = Date.now().toString(); module.exports = env => { // Add your custom Activities, Services and other Android app components here. @@ -115,7 +115,7 @@ module.exports = env => { test: (module, chunks) => { const moduleName = module.nameForCondition ? module.nameForCondition() : ''; return /[\\/]node_modules[\\/]/.test(moduleName) || - appComponents.some(comp => comp === moduleName); + appComponents.some(comp => comp === moduleName); }, enforce: true, @@ -179,7 +179,7 @@ module.exports = env => { use: "nativescript-dev-webpack/markup-hot-loader" }, - { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"}, + { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, { test: /\.css$/, @@ -201,6 +201,9 @@ module.exports = env => { options: { configFile: "tsconfig.tns.json", allowTsInNodeModules: true, + compilerOptions: { + sourceMap + } }, } }, @@ -213,7 +216,7 @@ module.exports = env => { "process": undefined, }), // Remove all files from the out dir. - new CleanWebpackPlugin([ `${dist}/**/*` ]), + new CleanWebpackPlugin([`${dist}/**/*`]), // Copy assets to out dir. Add your own globs as needed. new CopyWebpackPlugin([ { from: { glob: "fonts/**" } }, @@ -226,10 +229,10 @@ module.exports = env => { // configures the WebPack runtime to be generated inside the snapshot // module and no `runtime.js` module exist. (snapshot ? [] : ["./runtime"]) - .concat([ - "./vendor", - "./bundle", - ]) + .concat([ + "./vendor", + "./bundle", + ]) ), // For instructions on how to set up workers with webpack // check out https://github.com/nativescript/worker-loader