From 2e2e09ed2b40ff241e85aa85e11ac8a646a10def Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 20 Jan 2020 18:00:38 +0000 Subject: [PATCH 1/4] Fix build to not babel modules inside js/react sdk Adds 'src' to react-sdk & js-sdk babel test path so we don't run node modules inside js & react sdk through babel --- webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index f0dd47f791..01d3833973 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -112,8 +112,8 @@ module.exports = (env, argv) => { include: (f) => { // we use the original source files of react-sdk and js-sdk, so we need to // run them through babel. - if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-js-sdk'))) return true; - if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-react-sdk'))) return true; + if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-js-sdk', 'src'))) return true; + if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-react-sdk', 'src'))) return true; // but we can't run all of our dependencies through babel (many of them still // use module.exports which breaks if babel injects an 'include' for its // polyfills: probably fixable but babeling all our dependencies is probably From c197c2f4fd32ba6755459a5a49164d8583b4992c Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 20 Jan 2020 18:20:41 +0000 Subject: [PATCH 2/4] Third try at fixing build --- webpack.config.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 01d3833973..95087f7df6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -110,21 +110,21 @@ module.exports = (env, argv) => { { test: /\.(ts|js)x?$/, include: (f) => { + // our own source needs babel-ing + if (f.startsWith(path.resolve(__dirname, 'src'))) return true; + // we use the original source files of react-sdk and js-sdk, so we need to - // run them through babel. - if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-js-sdk', 'src'))) return true; - if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-react-sdk', 'src'))) return true; + // run them through babel. Because the path tested is the resolved, absolute + // path, these could be anywhere thanks to yarn link. We must also not + // include node modules inside these modules, so we add 'src'. + if (f.includes(path.join('matrix-js-sdk', 'src'))) return true; + if (f.includes(path.join('matrix-react-sdk', 'src'))) return true; + // but we can't run all of our dependencies through babel (many of them still // use module.exports which breaks if babel injects an 'include' for its // polyfills: probably fixable but babeling all our dependencies is probably - // not necessary anyway). - if (f.startsWith(path.resolve(__dirname, 'node_modules'))) return false; - // anything else gets babeled (our own source files, and also modules that - // are yarn linked from somewhere else because this tests the absolute, - // resolved path, so react-sdk and js-sdk fall under this case in a standard - // dev setup. This will presumably start running any other module through - // babel if yarn linked... caveat emptor. - return true; + // not necessary anyway). So, for anything else, don't babel. + return false; }, loader: 'babel-loader', options: { From 8c103b50af0eed1cf94a6d3536554d4aa4b6a765 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 20 Jan 2020 18:09:48 -0700 Subject: [PATCH 3/4] Fix webpack config (by stealing Dave's config) Without doing something like this it's hard to use `yarn link`ed resources. --- webpack.config.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 95087f7df6..ae92e8154f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -21,6 +21,12 @@ module.exports = (env, argv) => { development['devtool'] = 'eval-source-map'; } + // Resolve the directories for the react-sdk and js-sdk for later use. We resolve these early so we + // don't have to call them over and over. We also resolve to the package.json instead of the src + // directory so we don't have to rely on a index.js or similar file existing. + const reactSdkSrcDir = path.resolve(path.join(require.resolve("matrix-react-sdk/package.json"), '..', 'src')); + const jsSdkSrcDir = path.resolve(path.join(require.resolve("matrix-js-sdk/package.json"), '..', 'src')); + return { ...development, @@ -117,8 +123,8 @@ module.exports = (env, argv) => { // run them through babel. Because the path tested is the resolved, absolute // path, these could be anywhere thanks to yarn link. We must also not // include node modules inside these modules, so we add 'src'. - if (f.includes(path.join('matrix-js-sdk', 'src'))) return true; - if (f.includes(path.join('matrix-react-sdk', 'src'))) return true; + if (f.startsWith(reactSdkSrcDir)) return true; + if (f.startsWith(jsSdkSrcDir)) return true; // but we can't run all of our dependencies through babel (many of them still // use module.exports which breaks if babel injects an 'include' for its From d4e46108c46b74e07babbf1fe247fa80f91f9e34 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 21 Jan 2020 10:16:32 +0000 Subject: [PATCH 4/4] path.resolve does joining too so path.join is redundant --- webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index ae92e8154f..40e902b111 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -24,8 +24,8 @@ module.exports = (env, argv) => { // Resolve the directories for the react-sdk and js-sdk for later use. We resolve these early so we // don't have to call them over and over. We also resolve to the package.json instead of the src // directory so we don't have to rely on a index.js or similar file existing. - const reactSdkSrcDir = path.resolve(path.join(require.resolve("matrix-react-sdk/package.json"), '..', 'src')); - const jsSdkSrcDir = path.resolve(path.join(require.resolve("matrix-js-sdk/package.json"), '..', 'src')); + const reactSdkSrcDir = path.resolve(require.resolve("matrix-react-sdk/package.json"), '..', 'src'); + const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src'); return { ...development,