Fix SDK asset build failing on Windows (#859)

Fix:

```sh
$ yarn run vite build -c vite.sdk-assets-config.js
yarn run v1.22.18
$ C:\Users\MLM\Documents\GitHub\element\hydrogen-web\node_modules\.bin\vite build -c vite.sdk-assets-config.js
locally linked postcss
cleanUrl(id) C:/Users/MLM/Documents/GitHub/element/hydrogen-web/src/platform/web/ui/css/themes/element/theme.css C:/Users/MLM/Documents/GitHub/element/hydrogen-web/src/platform/web/ui/css/themes/element/theme.css?type=runtime
[build-themes] Could not load C:/Users/MLM/Documents/GitHub/element/hydrogen-web/src/platform/web/ui/css/themes/element/theme.css?variant=light: ENOENT: no such file or directory, open 'C:\Users\MLM\Documents\GitHub\element\C:\Users\MLM\Documents\GitHub\element\hydrogen-web\src\platform\web\ui\css\themes\element\theme.css'
error during build:
Error: Could not load C:/Users/MLM/Documents/GitHub/element/hydrogen-web/src/platform/web/ui/css/themes/element/theme.css?variant=light: ENOENT: no such file or directory, open 'C:\Users\MLM\Documents\GitHub\element\C:\Users\MLM\Documents\GitHub\element\hydrogen-web\src\platform\web\ui\css\themes\element\theme.css'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

Regressed in:
https://github.com/vector-im/hydrogen-web/pull/769/files#diff-5432b565e86d2514c825ed9972c37ea19820bf12b5d8d3203fc9d4ea4654bd34L20 where the `const path = require('path');` was removed but we also started using `path` in more places which needed the same treatment.

When making the fix, we also have to make sure we don't also regress:
https://github.com/vector-im/hydrogen-web/pull/750
This commit is contained in:
Eric Eastwood 2022-09-19 12:20:50 -05:00 committed by GitHub
parent 5f9cfffa3b
commit 0e40258404
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const path = require('path').posix;
// Use the path implementation native to the platform so paths from disk play
// well with resolving against the relative location (think Windows `C:\` and
// backslashes).
const path = require('path');
// Use the posix (forward slash) implementation when working with `import` paths
// to reference resources
const posixPath = require('path').posix;
const {optimize} = require('svgo');
async function readCSSSource(location) {
@ -238,7 +244,7 @@ module.exports = function buildThemes(options) {
switch (file) {
case "index.js": {
const isDark = variants[variant].dark;
return `import "${path.resolve(`${location}/theme.css`)}${isDark? "?dark=true": ""}";` +
return `import "${posixPath.resolve(`${location}/theme.css`)}${isDark? "?dark=true": ""}";` +
`import "@theme/${theme}/${variant}/variables.css"`;
}
case "variables.css": {