Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the SDK friendly to locally link and develop on #693

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cd007b4
Make the SDK friendly to locally link and develop on
MadLittleMods Feb 26, 2022
8fb2b27
Fix typos pointing to wrong files
MadLittleMods Feb 26, 2022
0023ab3
Add a placeholder for upgrading vite to comment on
MadLittleMods Feb 26, 2022
d247bc4
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
MadLittleMods Apr 5, 2022
95d1730
Update Vite which includes fixes to importing `*.js?url` with `exports`
MadLittleMods Apr 5, 2022
dd06d78
Avoid ERR_REQUIRE_ESM errors when requiring SDK
MadLittleMods Apr 5, 2022
2401b7f
Add way to test whether SDK works in ESM and CommonJS
MadLittleMods Apr 6, 2022
12d6447
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
MadLittleMods Apr 19, 2022
f61bf60
Enable extended globs for removing all but some filename !(filename)
MadLittleMods Apr 19, 2022
f56dc58
Fix tests after theme updates
MadLittleMods Apr 20, 2022
e9cee2e
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
MadLittleMods Apr 20, 2022
f1e07b6
Explain what is being deleted by the strange syntax
MadLittleMods Apr 20, 2022
ce289ba
Remove extra space
MadLittleMods Apr 20, 2022
d053d43
Update Vite to avoid flakey errors in our PostCSS plugins
MadLittleMods May 5, 2022
75098b4
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
MadLittleMods May 5, 2022
e54482e
Add some comments
MadLittleMods May 5, 2022
639358b
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
MadLittleMods May 12, 2022
b725269
Clean up index.html in the right spot
MadLittleMods May 18, 2022
1b2a6b5
Merge branch 'master' into madlittlemods/686-682-local-friendly-devel…
bwindels May 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"regenerator-runtime": "^0.13.7",
"text-encoding": "^0.7.0",
"typescript": "^4.3.5",
"vite": "^2.6.14",
"vite": "todo: wait for next Vite release",
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
"xxhashjs": "^0.2.2",
"bs58": "^4.0.1"
},
Expand Down
13 changes: 12 additions & 1 deletion scripts/sdk/base-manifest.json
Expand Up @@ -2,6 +2,17 @@
"name": "hydrogen-view-sdk",
"description": "Embeddable matrix client library, including view components",
"version": "0.0.5",
"main": "./hydrogen.es.js",
"main": "./hydrogen.cjs.js",
"exports": {
".": {
"import": "./lib-build/hydrogen.es.js",
"require": "./lib-build/hydrogen.cjs.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing hydrogen.es.js directly in the build, ./lib-build/hydrogen.es.js, to make it compatible with watching for an local changes and rebuild: yarn run vite build -c vite.sdk-lib-config.js --watch

},
"./paths/vite": "./paths/vite.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This export isn't used but it's part of the ./scripts/sdk/transform-paths.js ./src/platform/web/sdk/paths/vite.js ./target/paths/vite.js stuff in build.sh that's currently commented out.

"./style.css": "./asset-build/assets/index.css",
"./main.js": "./asset-build/assets/main.js",
"./download-sandbox.html": "./asset-build/assets/download-sandbox.html",
"./assets/*": "./asset-build/assets/*"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #682

Make the assets path available to reference and serve separately.

app.use(express.static(path.dirname(require.resolve('hydrogen-view-sdk/assets/main.js'))));

},
"type": "module"
}
12 changes: 3 additions & 9 deletions scripts/sdk/build.sh
@@ -1,5 +1,5 @@
#!/bin/bash
rm -rf target
rm -rf target/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only remove the directory contents instead of the whole directory to maintain the npm link/yarn link symlink

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added as a comment to the script

yarn run vite build -c vite.sdk-assets-config.js
yarn run vite build -c vite.sdk-lib-config.js
yarn tsc -p tsconfig-declaration.json
Expand All @@ -10,13 +10,7 @@ mkdir target/paths
cp doc/SDK.md target/README.md
pushd target
pushd asset-build/assets
mv main.*.js ../../main.js
mv index.*.css ../../style.css
mv download-sandbox.*.html ../../download-sandbox.html
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of needing to move these 3 files and rename them without the hash here, we handle removing the hash in vite.sdk-assets-config.js (rollupOptions.output.assetFileNames) and reference them directly in place in the package.json exports

rm *.js *.wasm
mv ./* ../../
rm !(main).js *.wasm
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
popd
rm -rf asset-build
mv lib-build/* .
rm -rf lib-build
rm index.html
popd
16 changes: 1 addition & 15 deletions scripts/sdk/create-manifest.js
Expand Up @@ -3,21 +3,7 @@ const fs = require("fs");
const appManifest = require("../../package.json");
const baseSDKManifest = require("./base-manifest.json");
/*
need to leave exports out of base-manifest.json because of #vite-bug,
with the downside that we can't support environments that support
both esm and commonjs modules, so we pick just esm.
```
"exports": {
".": {
"import": "./hydrogen.es.js",
"require": "./hydrogen.cjs.js"
},
"./paths/vite": "./paths/vite.js",
"./style.css": "./style.css"
},
```

Also need to leave typescript type definitions out until the
Need to leave typescript type definitions out until the
typescript conversion is complete and all imports in the d.ts files
exists.
```
Expand Down
19 changes: 19 additions & 0 deletions vite.sdk-assets-config.js
Expand Up @@ -2,10 +2,29 @@ const path = require("path");
const mergeOptions = require('merge-options');
const commonOptions = require("./vite.common-config.js");

const pathsToExport = [
"main.js",
"index.css",
"download-sandbox.html"
];

export default mergeOptions(commonOptions, {
root: "src/",
base: "./",
build: {
outDir: "../target/asset-build/",
rollupOptions: {
output: {
assetFileNames: (chunkInfo) => {
// Get rid of the hash so we can consistently reference these
// files in our `package.json` `exports`
if(pathsToExport.includes(path.basename(chunkInfo.name))) {
return "assets/[name].[ext]";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of renaming these files in build.sh, we can just give them the proper name as part of the Vite build.


return "assets/[name]-[hash][extname]";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, docs for the rollupOptions.output.assetFileNames option, https://rollupjs.org/guide/en/#outputassetfilenames

}
}
},
});