From 2caea65b4dd0da39c3ba98e0c86aa7b07a626060 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Wed, 2 Jan 2019 17:58:57 +0100 Subject: [PATCH 1/9] Added config option to package.json to find imports Scss imports in imports are often broken as the paths there may be absolute to node_modules (at least in the case of @material packages). To fix this, there is now a config option in package.json: vue.css.loaderOptions.sass.includePaths (array of Strings) --- packages/vue-sass/vue-sass.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 22f4a78..5abad09 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -18,15 +18,27 @@ function resolveImport (dependencyManager) { let currentDirectory = path.dirname(prev === 'stdin' ? this.options.outFile : prev) resolvedFilename = path.resolve(currentDirectory, url) } + const importPaths = [ resolvedFilename ] + const pjson = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run - resolvedFilename = discoverImportPath(resolvedFilename) - if (resolvedFilename === null) { + try { + // get the package.json config option and create paths for the requested file. + pjson.vue.css.loaderOptions.sass.includePaths.forEach( (str) => { + importPaths.push(path.resolve(str, url)) + }) + } catch (e) { + // Ignore error. package.json option is not set. + } + + const resolvedNames = importPaths.map( discoverImportPath ).filter((fileName) => fileName !== null && typeof fileName !== "undefined"); + + if (resolvedNames.length < 1) { done(new Error('Unknown import (file not found): ' + url)) } else { - dependencyManager.addDependency(resolvedFilename) + dependencyManager.addDependency(resolvedNames[0]) done({ - file: resolvedFilename, + file: resolvedNames[0], }) } } @@ -44,7 +56,7 @@ function discoverImportPath (importPath) { } for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { - if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { + if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { return potentialPath } } From 78c844ef83d7f18e05345ea06df25baf93af9daf Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Wed, 2 Jan 2019 18:03:43 +0100 Subject: [PATCH 2/9] replaced tab caracter with spaces --- packages/vue-sass/vue-sass.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 5abad09..631dc24 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -56,7 +56,7 @@ function discoverImportPath (importPath) { } for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { - if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { + if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { return potentialPath } } From 7c5b0f25d22f232a90cc86d8e221ba1edb9c0863 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Wed, 2 Jan 2019 18:05:54 +0100 Subject: [PATCH 3/9] fixed indention --- packages/vue-sass/vue-sass.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 631dc24..d1dbcfa 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -56,7 +56,7 @@ function discoverImportPath (importPath) { } for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { - if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { + if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { return potentialPath } } From 748c549d8e1311c6c683d80db3d7fb39fb30f7b2 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Thu, 28 Nov 2019 19:33:34 +0100 Subject: [PATCH 4/9] vue-sass now follows symlinks for imports As vue-sass checked that files exists with fs.lstatSync().isFile(), files with an symlink in their path were not detected as existing. This fix now Checks if the path is an symlink. If so, then the symlink will be resolved and checked if the resolved path is an exising file. --- packages/vue-sass/vue-sass.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index d9550c4..d4f9984 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -57,11 +57,25 @@ function discoverImportPath (importPath) { [].concat(potentialPaths).forEach(potentialPath => potentialPaths.push(`${path.dirname(potentialPath)}/_${path.basename(potentialPath)}`)) } - for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { - if (fs.existsSync(potentialPaths[i]) && fs.lstatSync(potentialPaths[i]).isFile()) { - return potentialPath + potentialPaths.forEach((path) => { + if(fs.existsSync(path)) { + const stat = fs.lstatSync(path); + + // if path is an symlink, check if the symlink points to a file + if(stat.isSymbolicLink()) { + try { + const realPath = fs.realpathSync(path); + if(fs.lstatSync(realPath).isFile()) { + return path; + } + } catch (e) { + // ignore errors + } + } else if(stat.isFile()) { + return path; + } } - } + }); return null } From fd139290a5f98d5c467f9c04cefb6d55a488bd00 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Wed, 27 Mar 2019 19:22:05 +0100 Subject: [PATCH 5/9] Also allowing .scss files to be symlinked --- packages/vue-sass/vue-sass.js | 38 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index d4f9984..46aa24c 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -12,27 +12,25 @@ function resolveImport (dependencyManager) { url = url.replace(/^["']?(.*?)["']?$/, '$1') if (url.indexOf('~') === 0 || url.indexOf('/') === 0) { resolvedFilename = url.substr(1) - /* } else if (url.indexOf('{') === 0) { - resolvedFilename = decodeFilePath(url) */ + /* } else if (url.indexOf('{') === 0) { + resolvedFilename = decodeFilePath(url) */ } else { let currentDirectory = path.dirname(prev === 'stdin' ? this.options.outFile : prev) resolvedFilename = path.resolve(currentDirectory, url) } - const importPaths = [resolvedFilename] - const pkg = require('package.json') // can not be moved outside. Reqired here to get the package.json of the project that is being run + const importPaths = [ resolvedFilename ] + const pjson = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run try { // get the package.json config option and create paths for the requested file. - pkg.vue.css.sass.includePaths.forEach((str) => { + pjson.vue.css.loaderOptions.sass.includePaths.forEach( (str) => { importPaths.push(path.resolve(str, url)) }) } catch (e) { // Ignore error. package.json option is not set. } - const resolvedNames = importPaths.map(discoverImportPath).filter( - fileName => fileName !== null && typeof fileName !== 'undefined' - ) + const resolvedNames = importPaths.map( discoverImportPath ).filter((fileName) => fileName !== null && typeof fileName !== "undefined"); if (resolvedNames.length < 1) { done(new Error('Unknown import (file not found): ' + url)) @@ -57,25 +55,15 @@ function discoverImportPath (importPath) { [].concat(potentialPaths).forEach(potentialPath => potentialPaths.push(`${path.dirname(potentialPath)}/_${path.basename(potentialPath)}`)) } - potentialPaths.forEach((path) => { - if(fs.existsSync(path)) { - const stat = fs.lstatSync(path); - - // if path is an symlink, check if the symlink points to a file - if(stat.isSymbolicLink()) { - try { - const realPath = fs.realpathSync(path); - if(fs.lstatSync(realPath).isFile()) { - return path; - } - } catch (e) { - // ignore errors - } - } else if(stat.isFile()) { - return path; + for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { + if (fs.existsSync(potentialPaths[i])) { + const stats = fs.lstatSync(potentialPaths[i]); + if (stats.isFile() || stats.isSymbolicLink()) { + // TODO: isSymbolicLink will return also true if the symlink points to an directory. + return potentialPath } } - }); + } return null } From 7ad9333d264ada8f573704d4377dc4dd52c7c6c9 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Thu, 9 Jan 2020 18:38:16 +0100 Subject: [PATCH 6/9] Fixed last commit --- packages/vue-sass/vue-sass.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 46aa24c..264743d 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -56,11 +56,21 @@ function discoverImportPath (importPath) { } for (let i = 0, potentialPath = potentialPaths[i]; i < potentialPaths.length; i++, potentialPath = potentialPaths[i]) { - if (fs.existsSync(potentialPaths[i])) { - const stats = fs.lstatSync(potentialPaths[i]); - if (stats.isFile() || stats.isSymbolicLink()) { - // TODO: isSymbolicLink will return also true if the symlink points to an directory. - return potentialPath + if(fs.existsSync(potentialPath)) { + const stat = fs.lstatSync(potentialPath); + + // if path is an symlink, check if the symlink points to a file + if(stat.isSymbolicLink()) { + try { + const realPath = fs.realpathSync(potentialPath); + if(fs.lstatSync(realPath).isFile()) { + return potentialPath; + } + } catch (e) { + // ignore errors + } + } else if(stat.isFile()) { + return potentialPath; } } } From 38d6ba0e16f1e3ce6e59731b9162500cce5ce552 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Thu, 9 Jan 2020 18:39:59 +0100 Subject: [PATCH 7/9] Fixed some unneccesary changes --- packages/vue-sass/vue-sass.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 264743d..835f0b5 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -12,25 +12,27 @@ function resolveImport (dependencyManager) { url = url.replace(/^["']?(.*?)["']?$/, '$1') if (url.indexOf('~') === 0 || url.indexOf('/') === 0) { resolvedFilename = url.substr(1) - /* } else if (url.indexOf('{') === 0) { - resolvedFilename = decodeFilePath(url) */ + /* } else if (url.indexOf('{') === 0) { + resolvedFilename = decodeFilePath(url) */ } else { let currentDirectory = path.dirname(prev === 'stdin' ? this.options.outFile : prev) resolvedFilename = path.resolve(currentDirectory, url) } - const importPaths = [ resolvedFilename ] - const pjson = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run + const importPaths = [resolvedFilename] + const pkg = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run try { // get the package.json config option and create paths for the requested file. - pjson.vue.css.loaderOptions.sass.includePaths.forEach( (str) => { + pkg.vue.css.sass.includePaths.forEach( (str) => { importPaths.push(path.resolve(str, url)) }) } catch (e) { // Ignore error. package.json option is not set. } - const resolvedNames = importPaths.map( discoverImportPath ).filter((fileName) => fileName !== null && typeof fileName !== "undefined"); + const resolvedNames = importPaths.map( discoverImportPath ).filter( + fileName => fileName !== null && typeof fileName !== "undefined" + ); if (resolvedNames.length < 1) { done(new Error('Unknown import (file not found): ' + url)) From bc966d1ccf9b0cd027f16582456c2757f23d8c93 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Thu, 9 Jan 2020 18:41:07 +0100 Subject: [PATCH 8/9] Fixed some unneccesary changes --- packages/vue-sass/vue-sass.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 835f0b5..2219352 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -19,20 +19,20 @@ function resolveImport (dependencyManager) { resolvedFilename = path.resolve(currentDirectory, url) } const importPaths = [resolvedFilename] - const pkg = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run + const pkg = require('package.json') // can not be moved outside. Reqired here to get the package.json of the project that is being run try { // get the package.json config option and create paths for the requested file. - pkg.vue.css.sass.includePaths.forEach( (str) => { + pkg.vue.css.sass.includePaths.forEach( (str) => { importPaths.push(path.resolve(str, url)) }) } catch (e) { // Ignore error. package.json option is not set. } - const resolvedNames = importPaths.map( discoverImportPath ).filter( - fileName => fileName !== null && typeof fileName !== "undefined" - ); + const resolvedNames = importPaths.map(discoverImportPath).filter( + fileName => fileName !== null && typeof fileName !== 'undefined' + ) if (resolvedNames.length < 1) { done(new Error('Unknown import (file not found): ' + url)) From 6e0499456df9db2f66eeecaca4d9c26ab85330d1 Mon Sep 17 00:00:00 2001 From: Marvin Wiesner Date: Thu, 9 Jan 2020 18:42:34 +0100 Subject: [PATCH 9/9] Fixed some unneccesary changes --- packages/vue-sass/vue-sass.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue-sass/vue-sass.js b/packages/vue-sass/vue-sass.js index 2219352..0309376 100644 --- a/packages/vue-sass/vue-sass.js +++ b/packages/vue-sass/vue-sass.js @@ -23,7 +23,7 @@ function resolveImport (dependencyManager) { try { // get the package.json config option and create paths for the requested file. - pkg.vue.css.sass.includePaths.forEach( (str) => { + pkg.vue.css.sass.includePaths.forEach((str) => { importPaths.push(path.resolve(str, url)) }) } catch (e) {