From 06b695c2cb22eb28eaf91250d884d15e7765dd2b Mon Sep 17 00:00:00 2001 From: cvci Date: Wed, 6 Feb 2019 15:54:44 -0700 Subject: [PATCH 1/2] Use pkgUp to build better relative paths --- index.js | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0f961b7..423cfe3 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const path = require("path"); const vm = require("vm"); const { promisify } = require("util"); +const pkgUp = require('pkg-up'); const { getOptions } = require("loader-utils"); @@ -10,7 +11,7 @@ const { ReplaceSource, } = require("webpack-sources"); -module.exports = function(source, map, meta) { +module.exports = function (source, map, meta) { // Using exec() in parallel, so we need separate RegExp instances. // That means don't "optimize" this by moving this to the global scope! const pattern = /\brequire\((?:'bindings'|"bindings")\)\s*\(([^)]*)\)/g; @@ -48,7 +49,10 @@ module.exports = function(source, map, meta) { : bindings.getRoot(this.resourcePath); const addonPath = bindings(arg); - const addonRequest = `./${path.basename(addonPath)}`; + // take addon path and make it relative to the package we're loading it from. + const pkgPath = path.dirname(path.dirname(await pkgUp(addonPath))); + const addonRequest = path.relative(pkgPath, addonPath); + // const addonRequest = `./${path.basename(addonPath)}`; const addonContent = await readFile(addonPath); this.emitFile(addonRequest, addonContent); diff --git a/package.json b/package.json index 380b2c5..eb466a2 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "main": "index.js", "dependencies": { "loader-utils": "^1.1.0", + "pkg-up": "^2.0.0", "webpack-sources": "^1.3.0" }, "devDependencies": { From 417e03415986c28a818385d128025496783f5fed Mon Sep 17 00:00:00 2001 From: cvci Date: Wed, 6 Feb 2019 15:54:48 -0700 Subject: [PATCH 2/2] yarn lock --- yarn.lock | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/yarn.lock b/yarn.lock index 8cd3ef0..e3a229c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,46 +5,77 @@ big.js@^3.1.3: version "3.2.0" resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e" - integrity sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q== emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" - integrity sha1-TapNnbAPmBmIDHn6RXrlsJof04k= + +find-up@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" + dependencies: + locate-path "^2.0.0" json5@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" - integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE= loader-utils@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd" - integrity sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0= dependencies: big.js "^3.1.3" emojis-list "^2.0.0" json5 "^0.5.0" +locate-path@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" + dependencies: + p-locate "^2.0.0" + path-exists "^3.0.0" + +p-limit@^1.1.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" + dependencies: + p-try "^1.0.0" + +p-locate@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" + dependencies: + p-limit "^1.1.0" + +p-try@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" + +path-exists@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" + +pkg-up@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f" + dependencies: + find-up "^2.1.0" + prettier@^1.14.3: version "1.14.3" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.3.tgz#90238dd4c0684b7edce5f83b0fb7328e48bd0895" - integrity sha512-qZDVnCrnpsRJJq5nSsiHCE3BYMED2OtsI+cmzIzF1QIfqm5ALf8tEJcO27zV1gKNKRPdhjO0dNWnrzssDQ1tFg== source-list-map@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085" - integrity sha512-I2UmuJSRr/T8jisiROLU3A3ltr+swpniSmNPI4Ml3ZCX6tVnDsuZzK7F2hl5jTqbZBWCEKlj5HRQiPExXLgE8A== source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" - integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== webpack-sources@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.3.0.tgz#2a28dcb9f1f45fe960d8f1493252b5ee6530fa85" - integrity sha512-OiVgSrbGu7NEnEvQJJgdSFPl2qWKkWq5lHMhgiToIiN9w34EBnjYzSYs+VbL5KoYiLNtFFa7BZIKxRED3I32pA== dependencies: source-list-map "^2.0.0" source-map "~0.6.1"