From 7ff023b6b3c982e9ab3e0067208d7783019f842e Mon Sep 17 00:00:00 2001 From: Stanimira Vlaeva Date: Thu, 13 Dec 2018 11:39:30 +0200 Subject: [PATCH 1/3] refactor: remove unused `extract-text-webpack-plugin` (#737) The plugin is not used in the webpack configurations anymore and can be removed. --- dependencyManager.js | 1 - package.json | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dependencyManager.js b/dependencyManager.js index 6fe1549a..84dac859 100644 --- a/dependencyManager.js +++ b/dependencyManager.js @@ -54,7 +54,6 @@ function removeObsoleteDeps(packageJson) { "raw-loader", "css-loader", "nativescript-worker-loader", - "extract-text-webpack-plugin", "uglifyjs-webpack-plugin", "@angular-devkit/core", "resolve-url-loader", diff --git a/package.json b/package.json index 3c04976b..fef26908 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,11 @@ "generate-android-snapshot": "./bin/generate-android-snapshot" }, "dependencies": { + "@angular-devkit/core": "~7.1.0", + "awesome-typescript-loader": "~5.2.1", + "clean-webpack-plugin": "~1.0.0", + "copy-webpack-plugin": "~4.6.0", + "css-loader": "~1.0.0", "global-modules-path": "2.0.0", "minimatch": "3.0.4", "nativescript-hook": "0.2.4", From 9f1efff86b1cc92d6e69889fd9aeb02fc719fa28 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 13 Dec 2018 12:49:21 +0100 Subject: [PATCH 2/3] fix(JS/TS): use webpack resolver instead of Node.js resolver (#681) --- xml-namespace-loader.js | 147 ++++++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 67 deletions(-) diff --git a/xml-namespace-loader.js b/xml-namespace-loader.js index 2cb83c3a..48f5c83c 100644 --- a/xml-namespace-loader.js +++ b/xml-namespace-loader.js @@ -1,13 +1,18 @@ const { parse, relative, join, basename, extname } = require("path"); +const { promisify } = require('util'); const { convertSlashesInPath } = require("./projectHelpers"); module.exports = function (source) { this.value = source; const { ignore } = this.query; + const callback = this.async(); const { XmlParser } = require("tns-core-modules/xml"); - let namespaces = []; + const resolvePromise = promisify(this.resolve); + const promises = []; + + const namespaces = []; const parser = new XmlParser((event) => { const { namespace, elementName } = event; const moduleName = `${namespace}/${elementName}`; @@ -20,83 +25,91 @@ module.exports = function (source) { ) { const localNamespacePath = join(this.rootContext, namespace); const localModulePath = join(localNamespacePath, elementName); - const resolvedPath = tryResolve(localNamespacePath) || - tryResolve(localModulePath); - - if (!resolvedPath) { - const xml = tryResolve(`${localModulePath}.xml`); - if (!xml) { - namespaces.push({ name: namespace, path: namespace }); - namespaces.push({ name: moduleName, path: namespace }); - - return; - } else { - namespaces.push({ name: `${moduleName}.xml`, path: xml }); - namespaces.push({ name: moduleName, path: xml }); - this.addDependency(xml); - } - - const css = tryResolve(`${localModulePath}.css`); - if (css) { - namespaces.push({ name: `${moduleName}.css`, path: css }); - this.addDependency(css); - } - - return; - } - - this.addDependency(resolvedPath); - - namespaces.push({ name: namespace, path: resolvedPath }); - namespaces.push({ name: moduleName, path: resolvedPath }); - - const { dir, name } = parse(resolvedPath); - const noExtFilename = join(dir, name); - - const xml = tryResolve(`${noExtFilename}.xml`); - if (xml) { - this.addDependency(xml); - namespaces.push({ name: `${moduleName}.xml`, path: xml }); - } - - const css = tryResolve(`${noExtFilename}.css`); - if (css) { - this.addDependency(css); - namespaces.push({ name: `${moduleName}.css`, path: css }); - } + + const pathResolved = (resolvedPath) => { + this.addDependency(resolvedPath); + + namespaces.push({ name: namespace, path: resolvedPath }); + namespaces.push({ name: moduleName, path: resolvedPath }); + + const { dir, name } = parse(resolvedPath); + const noExtFilename = join(dir, name); + + return Promise.all([ + resolvePromise(this.context, `${noExtFilename}.xml`) + .then((xml) => { + this.addDependency(xml); + namespaces.push({ name: `${moduleName}.xml`, path: xml }); + }) + .catch((err) => {}), + + resolvePromise(this.context, `${noExtFilename}.css`) + .then((xml) => { + this.addDependency(xml); + namespaces.push({ name: `${moduleName}.css`, path: css }); + }) + .catch((err) => {}) + ]); + }; + + promises.push(resolvePromise(this.context, localNamespacePath) + .then(path => pathResolved(path)) + .catch(() => { + return promise = resolvePromise(this.context, localModulePath) + .then(path => pathResolved(path)) + .catch(() => { + return Promise.all([ + resolvePromise(this.context, `${localModulePath}.xml`) + .then((xml) => { + namespaces.push({ name: `${moduleName}.xml`, path: xml }); + namespaces.push({ name: moduleName, path: xml }); + this.addDependency(xml); + }) + .catch(() => { + namespaces.push({ name: namespace, path: namespace }); + namespaces.push({ name: moduleName, path: namespace }); + }), + + resolvePromise(this.context, `${localModulePath}.css`) + .then((css) => { + namespaces.push({ name: `${moduleName}.css`, path: css }); + this.addDependency(css); + }) + .catch(() => {}) + ]); + + }); + }) + ); } }, undefined, true); parser.parse(source); - const moduleRegisters = namespaces - .map(convertPath) - .map(n => - `global.registerModule("${n.name}", function() { return require("${n.path}"); });` - ) - .join(""); + Promise.all(promises).then(() => { + const moduleRegisters = namespaces + .map(convertPath) + .map(n => + `global.registerModule("${n.name}", function() { return require("${n.path}"); });` + ) + .join(""); + + // escape special whitespace characters + // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Issue_with_plain_JSON.stringify_for_use_as_JavaScript + const json = JSON.stringify(source) + .replace(/\u2028/g, '\\u2028') + .replace(/\u2029/g, '\\u2029'); - // escape special whitespace characters - // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Issue_with_plain_JSON.stringify_for_use_as_JavaScript - const json = JSON.stringify(source) - .replace(/\u2028/g, '\\u2028') - .replace(/\u2029/g, '\\u2029'); + const wrapped = `${moduleRegisters}\nmodule.exports = ${json}`; - const wrapped = `${moduleRegisters}\nmodule.exports = ${json};`; + callback(null, wrapped); + }).catch((err) => { + callback(err); + }) - this.callback(null, wrapped); } function convertPath(obj) { obj.path = convertSlashesInPath(obj.path); return obj; } - -function tryResolve(path) { - try { - return require.resolve(path); - } catch (e) { - // The path couldn't be resolved - return; - } -} From ab2b63881f93e5bc3b149a2f1c85f05bde62b657 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Fri, 14 Dec 2018 17:03:48 +0200 Subject: [PATCH 3/3] release: cut the 0.18.4 release --- CHANGELOG.md | 10 ++++++++++ package.json | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f98095..dd227bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [0.18.4](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.3...0.18.4) (2018-12-14) + + +### Bug Fixes + +* **JS/TS:** use webpack resolver instead of Node.js resolver ([#681](https://github.com/NativeScript/nativescript-dev-webpack/issues/681)) ([9f1efff](https://github.com/NativeScript/nativescript-dev-webpack/commit/9f1efff)) + + + ## [0.18.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.2...0.18.3) (2018-12-10) diff --git a/package.json b/package.json index fef26908..7e149bb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "0.18.3", + "version": "0.18.4", "main": "index", "description": "", "homepage": "http://www.telerik.com", @@ -92,16 +92,11 @@ "webpack-cli": "~3.1.1", "webpack-bundle-analyzer": "~3.0.2", "webpack-sources": "~1.3.0", - "clean-webpack-plugin": "~1.0.0", - "copy-webpack-plugin": "~4.6.0", "raw-loader": "~0.5.1", - "css-loader": "~1.0.0", "nativescript-worker-loader": "~0.9.0", "extract-text-webpack-plugin": "~3.0.2", "uglifyjs-webpack-plugin": "~1.2.5", - "@angular-devkit/core": "~7.1.0", "resolve-url-loader": "~3.0.0", - "awesome-typescript-loader": "~5.2.1", "sass-loader": "~7.1.0" }, "devDependencies": {