From f5c7fef5d9c661ff488fbc3863104401b8bb2516 Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Tue, 11 Feb 2020 10:04:39 +0900 Subject: [PATCH 1/2] Fix issues with relative paths and double extensions. Fixes #13. --- es6.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/es6.js b/es6.js index 060d7a9..d0aa16d 100644 --- a/es6.js +++ b/es6.js @@ -37,9 +37,12 @@ define([ babel.registerPlugin('module-resolver', moduleResolver); - function resolvePath (sourcePath) { + function resolvePath (sourcePath, currentFile) { if (sourcePath.indexOf('!') < 0) { - return 'es6!' + sourcePath; + // If sourcePath is relative (ex: "./foo"), it's relative to currentFile. + var absSourcePath = /^\.?\.\//.test(sourcePath) ? currentFile.replace(/[^/]*$/, "") + sourcePath : + sourcePath; + return 'es6!' + absSourcePath; } } var excludedOptions = ['extraPlugins', 'resolveModuleSource']; @@ -66,7 +69,7 @@ define([ return { //>>excludeStart('excludeBabel', pragmas.excludeBabel) load: function (name, req, onload, config) { - var sourceFileName = name + fileExtension; + var sourceFileName = /\./.test(name) ? name : name + fileExtension; var url = req.toUrl(sourceFileName); if (url.indexOf('empty:') === 0) { @@ -92,7 +95,7 @@ return { _buildMap[name] = code; } - onload.fromText(code); + onload.fromText(code); }); }, From 25f4760482fb4761aac3e651de5c2006f3ed7f4e Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Tue, 11 Feb 2020 10:11:31 +0900 Subject: [PATCH 2/2] Update demo to test loading lit-html works correctly, and that relative paths within the original example work correctly. You probably don't want to commit this to the repository, or maybe want to commit it as another demo/test. Also, note that I couldn't support a path for lit-html of 'lit-html': '../node_modules/lit-html/lit-html' because then there's no way to specify the path to lit-html's support files (i.e. the other files in the lit-html/ directory). So instead I did: 'lit-html': '../node_modules/lit-html' --- demo/index.html | 1 + demo/src/class.js | 8 +++++--- demo/src/sub/sum.js | 2 ++ demo/src/{sum.js => sub/sum2.js} | 0 package-lock.json | 5 +++++ package.json | 3 +++ 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 demo/src/sub/sum.js rename demo/src/{sum.js => sub/sum2.js} (100%) diff --git a/demo/index.html b/demo/index.html index 0a9f646..38c23e2 100644 --- a/demo/index.html +++ b/demo/index.html @@ -13,6 +13,7 @@ paths: { es6: '../es6', babel: '../node_modules/@babel/standalone/babel.min', + 'lit-html': '../node_modules/lit-html', 'babel-plugin-module-resolver': '../node_modules/babel-plugin-module-resolver-standalone/index' } }); diff --git a/demo/src/class.js b/demo/src/class.js index 22ff7ce..b76007b 100644 --- a/demo/src/class.js +++ b/demo/src/class.js @@ -1,6 +1,5 @@ -import sum from 'src/sum'; - -console.log( sum(1,2) ); +import sum from './sub/sum'; +import {html, render} from 'lit-html/lit-html'; class A { constructor(a) { @@ -9,3 +8,6 @@ class A { } new A('world!'); + +var h = "Hello", w = "world"; +render(html`${h} ${w}, 1 + 2 = ${sum(1,2)}!`, document.body); diff --git a/demo/src/sub/sum.js b/demo/src/sub/sum.js new file mode 100644 index 0000000..3aa83b1 --- /dev/null +++ b/demo/src/sub/sum.js @@ -0,0 +1,2 @@ +import sum from './sum2'; +export default (a, b) => sum(a, b); \ No newline at end of file diff --git a/demo/src/sum.js b/demo/src/sub/sum2.js similarity index 100% rename from demo/src/sum.js rename to demo/src/sub/sum2.js diff --git a/package-lock.json b/package-lock.json index 216f300..a2db110 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1684,6 +1684,11 @@ "dev": true, "optional": true }, + "lit-html": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/lit-html/-/lit-html-1.1.2.tgz", + "integrity": "sha512-FFlUMKHKi+qG1x1iHNZ1hrtc/zHmfYTyrSvs3/wBTvaNtpZjOZGWzU7efGYVpgp6KvWeKF6ql9/KsCq6Z/mEDA==" + }, "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", diff --git a/package.json b/package.json index 3526f7f..cdc9d5e 100644 --- a/package.json +++ b/package.json @@ -26,5 +26,8 @@ "@babel/standalone": "7.4.2", "babel-plugin-module-resolver-standalone": "0.0.1", "requirejs": "^2.3.6" + }, + "dependencies": { + "lit-html": "^1.1.2" } }