Skip to content

Commit

Permalink
Version the bundled @nimiq/core version to avoid cache issues
Browse files Browse the repository at this point in the history
The @nimiq/core files are not versioned or hashed otherwise.
  • Loading branch information
sisou committed Dec 1, 2024
1 parent 4f613af commit 09edfa6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h2>Result</h2>
crossorigin="anonymous"></script>

<script type="module">
import init, * as Nimiq from '/albatross-client/web/index.js';
import init, * as Nimiq from '/nimiq/v<%= htmlWebpackPlugin.options.coreVersion %>/web/index.js';

/** @type {Promise<Nimiq> | undefined} */
let initPromise;
Expand Down
2 changes: 1 addition & 1 deletion public/cashlink.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<link rel="icon" href="<%= htmlWebpackPlugin.options.domain %>/favicon.ico">

<script type="module">
import init, * as Nimiq from '/albatross-client/web/index.js';
import init, * as Nimiq from '/nimiq/v<%= htmlWebpackPlugin.options.coreVersion %>/web/index.js';

/** @type {Promise<Nimiq> | undefined} */
let initPromise;
Expand Down
2 changes: 1 addition & 1 deletion public/export.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</style>

<script type="module">
import init, * as Nimiq from '/albatross-client/web/index.js';
import init, * as Nimiq from '/nimiq/v<%= htmlWebpackPlugin.options.coreVersion %>/web/index.js';

/** @type {Promise<Nimiq> | undefined} */
let initPromise;
Expand Down
2 changes: 1 addition & 1 deletion public/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="robots" content="noindex">
<title>Nimiq Hub IFrame</title>
<script type="module">
import init, * as Nimiq from '/albatross-client/web/index.js';
import init, * as Nimiq from '/nimiq/v<%= htmlWebpackPlugin.options.coreVersion %>/web/index.js';

/** @type {Promise<Nimiq> | undefined} */
let initPromise;
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<link rel="icon" href="<%= htmlWebpackPlugin.options.domain %>/favicon.ico">

<script type="module">
import init, * as Nimiq from '/albatross-client/web/index.js';
import init, * as Nimiq from '/nimiq/v<%= htmlWebpackPlugin.options.coreVersion %>/web/index.js';

/** @type {Promise<Nimiq> | undefined} */
let initPromise;
Expand Down
25 changes: 18 additions & 7 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ const createHash = require('crypto').createHash;
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const PoLoaderOptimizer = require('webpack-i18n-tools')();

let coreVersion = '';
try {
// Will fail until @nimiq/core export map is updated to also make the package.json file available
coreVersion = require('@nimiq/core/package.json').version;
} catch (e) {
// Fallback to reading the package.json file directly
pkgJson = require('fs').readFileSync(path.join(__dirname, 'node_modules/@nimiq/core/package.json'));
coreVersion = JSON.parse(pkgJson).version;
}

if (!coreVersion) throw new Error('Could not determine @nimiq/core version');

const crypto = require('crypto');

// Fix build for Node version with OpenSSL 3
Expand All @@ -28,8 +40,6 @@ const domain = buildName === 'mainnet'
? process.env.VUE_APP_HUB_URL
: 'http://localhost:8080';

const cdnDomain = 'https://cdn.nimiq-testnet.com';

const browserWarningTemplate = fs.readFileSync(
path.join(__dirname, 'node_modules/@nimiq/browser-warning/dist/browser-warning.html.template'));

Expand Down Expand Up @@ -73,7 +83,7 @@ const configureWebpack = {
},
{
from: 'node_modules/@nimiq/core',
to: './albatross-client/',
to: `./nimiq/v${coreVersion}/`,
},
]}),
new WriteFileWebpackPlugin(),
Expand Down Expand Up @@ -130,7 +140,7 @@ const pages = {
browserWarningTemplate,
browserWarningIntegrityHash,
domain,
cdnDomain,
coreversion,
// output as dist/index.html
filename: 'index.html',
// chunks to include on this page, by default includes
Expand All @@ -142,6 +152,7 @@ const pages = {
entry: 'src/iframe.ts',
// the source template
template: 'public/iframe.html',
coreVersion,
// output as dist/iframe.html
filename: 'iframe.html',
// chunks to include on this page, by default includes
Expand All @@ -157,7 +168,7 @@ const pages = {
browserWarningTemplate,
browserWarningIntegrityHash,
domain,
cdnDomain,
coreversion,
// output as dist/cashlink/index.html
filename: 'cashlink/index.html',
// chunks to include on this page, by default includes
Expand All @@ -169,7 +180,7 @@ const pages = {
entry: 'src/export.ts',
// the source template
template: 'public/export.html',
cdnDomain,
coreversion,
// output as dist/iframe.html
filename: 'export.html',
},
Expand All @@ -181,7 +192,7 @@ if (buildName === 'local' || buildName === 'testnet') {
entry: 'demos/Demo.ts',
// the source template
template: 'demos/index.html',
cdnDomain,
coreversion,
bitcoinJsIntegrityHash,
// output as dist/demos.html
filename: 'demos.html',
Expand Down

0 comments on commit 09edfa6

Please sign in to comment.