From ee590edaa27e53bb3f8aa9d9c7f12370762bc463 Mon Sep 17 00:00:00 2001 From: Nick Fytros Date: Sun, 8 Oct 2017 21:28:17 +0200 Subject: [PATCH 1/3] trying windows path fix --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 1 + tests/example/app.js | 3 ++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 187bc04..8510b15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "express-vue-renderer", - "version": "0.7.0", + "version": "0.7.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4060,15 +4060,6 @@ } } }, - "string_decoder": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.1.tgz", - "integrity": "sha1-YuIA8DmVWmgQ2N8KM//A8BNmLZg=", - "dev": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", @@ -4080,6 +4071,15 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.1.tgz", + "integrity": "sha1-YuIA8DmVWmgQ2N8KM//A8BNmLZg=", + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -9398,15 +9398,6 @@ "duplexer": "0.1.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-hash": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/string-hash/-/string-hash-1.1.3.tgz", @@ -9439,6 +9430,15 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", diff --git a/package.json b/package.json index c84617e..1b46161 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "no-case": "^2.3.2", "pug": "^2.0.0-rc.4", "require-from-string": "^2.0.1", + "slash": "^1.0.0", "string-hash": "^1.1.3", "vue": "^2.4.4", "vue-server-renderer": "^2.4.4", diff --git a/tests/example/app.js b/tests/example/app.js index 0348843..5d4ec2f 100644 --- a/tests/example/app.js +++ b/tests/example/app.js @@ -2,6 +2,7 @@ const path = require('path'); const express = require('express'); const uuidv4 = require('uuid/v4'); +const slash = require('slash'); const expressVueRenderer = require('../../lib'); const expressVue = require('./expressVue'); @@ -15,7 +16,7 @@ var exampleMixin = { }; const options = { - rootPath: path.join(__dirname, 'vueFiles'), + rootPath: slash(path.join(__dirname, 'vueFiles')), vue: { head: { meta: [{ From fd7e9bc26b50edd3150a21d97616d900786aeb67 Mon Sep 17 00:00:00 2001 From: Nick Fytros Date: Sun, 8 Oct 2017 22:07:51 +0200 Subject: [PATCH 2/3] fixed the windows require file problems --- src/utils/require.js | 11 ++++++----- tests/example/app.js | 4 +--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utils/require.js b/src/utils/require.js index 6e1c5d5..4f8ff1c 100644 --- a/src/utils/require.js +++ b/src/utils/require.js @@ -1,6 +1,7 @@ // @flow const Module = require('module'); const path = require('path'); +const slash = require('slash'); const Utils = require('./index'); const Renderer = require('../renderer'); const Models = require('../models'); @@ -59,25 +60,24 @@ function replaceRelativePaths(code: string, rootPath: string): string { const currentMatchesDouble = code.match(/(require\("\.\/)/gm); if (parentMatchesSingle) { for (const match of parentMatchesSingle) { - code = code.replace(match, `require('${rootPath}/../`); + code = code.replace(match, slash(`require('${rootPath}/../`)); } } if (parentMatchesDouble) { for (const match of parentMatchesDouble) { - code = code.replace(match, `require("${rootPath}/../`); + code = code.replace(match, slash(`require("${rootPath}/../`)); } } if (currentMatchesSingle) { for (const match of currentMatchesSingle) { - code = code.replace(match, `require('${rootPath}/./`); + code = code.replace(match, slash(`require('${rootPath}/./`)); } } if (currentMatchesDouble) { for (const match of currentMatchesDouble) { - code = code.replace(match, `require("${rootPath}/./`); + code = code.replace(match, slash(`require("${rootPath}/./`)); } } - return code; } @@ -131,6 +131,7 @@ function requireFromString(code: string, filename: string = '', optsObj: Object reject(error); }); } else { + console.log(code) m._compile(code, filename); resolve(m.exports.default); } diff --git a/tests/example/app.js b/tests/example/app.js index 5d4ec2f..0d30e25 100644 --- a/tests/example/app.js +++ b/tests/example/app.js @@ -2,7 +2,6 @@ const path = require('path'); const express = require('express'); const uuidv4 = require('uuid/v4'); -const slash = require('slash'); const expressVueRenderer = require('../../lib'); const expressVue = require('./expressVue'); @@ -16,7 +15,7 @@ var exampleMixin = { }; const options = { - rootPath: slash(path.join(__dirname, 'vueFiles')), + rootPath: path.join(__dirname, 'vueFiles'), vue: { head: { meta: [{ @@ -41,7 +40,6 @@ const options = { } }; - renderer = expressVue.init(options); const app = express(); From adf5445db6c9081526607456ce16bae17bddf1c8 Mon Sep 17 00:00:00 2001 From: Nick Fytros Date: Thu, 26 Oct 2017 22:39:40 +0200 Subject: [PATCH 3/3] fixed the windows bug with requireFromString --- src/utils/require.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/require.js b/src/utils/require.js index 4f8ff1c..2539675 100644 --- a/src/utils/require.js +++ b/src/utils/require.js @@ -15,7 +15,7 @@ class Options { defaults: Models.Defaults; constructor(optsObj: Object) { this.vueFileRegex = /([\w/.\-@_\d]*\.vue)/igm; - this.requireRegex = /(require\(['"])([\w/.\-@_\d]*\.vue)(['"]\))/igm; + this.requireRegex = /(require\(['"])([\w:/.\-@_\d]*\.vue)(['"]\))/igm; this.appendPaths = optsObj.appendPaths || []; this.prependPaths = optsObj.prependPaths || []; this.rootPath = optsObj.rootPath || ''; @@ -131,7 +131,6 @@ function requireFromString(code: string, filename: string = '', optsObj: Object reject(error); }); } else { - console.log(code) m._compile(code, filename); resolve(m.exports.default); }