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

feat(spotlight): Stabilize embedded JS filename for external use #553

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-insects-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/spotlight': minor
---

Stabilize embedded JS file name for local includes
15 changes: 9 additions & 6 deletions packages/overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export {
DEFAULT_ANCHOR,
DEFAULT_EXPERIMENTS,
DEFAULT_SIDECAR_URL,
React,
ReactDOM,
off,
on,
React,
ReactDOM,
trigger,
};

Expand Down Expand Up @@ -107,19 +107,22 @@ export async function init(options: SpotlightOverlayOptions = {}) {

const {
openOnInit = false,
showTriggerButton = true,
injectImmediately = false,
sidecarUrl = DEFAULT_SIDECAR_URL,
anchor = DEFAULT_ANCHOR,
debug = false,
integrations,
experiments = DEFAULT_EXPERIMENTS,
fullPage = false,
showClearEventsButton = true,
initialEvents = undefined,
startFrom = undefined,
} = options;

const isLoadedFromSidecar = new URL(sidecarUrl).origin === document.location.origin;
Copy link
Collaborator

Choose a reason for hiding this comment

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

[NOT RELATED TO THIS PR]

Looking at these, I think we can give the support of query params to users for changing config of spotlight when running overlay via sidecar url.
Something like 'localhost:8969?integrations=sentry,console&fullScreen=true'

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha, pretty good idea! I wonder if we can do something similar with the Electron app too. For that we may have to fall back to config files :(


const fullPage = options.fullPage ?? isLoadedFromSidecar;
const showTriggerButton = options.showTriggerButton ?? !fullPage;
const injectImmediately = options.injectImmediately ?? (isLoadedFromSidecar || fullPage);
const debug = options.debug ?? document.location.hash.endsWith('debug');

if (debug) {
activateLogger();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/spotlight/bin/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
const { setupSidecar } = await import('../dist/sidecar.js');
const port = process.argv.length >= 3 ? Number(process.argv[2]) : undefined;
import { join } from 'path';
import { fileURLToPath } from 'url';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
setupSidecar({ port, basePath: join(fileURLToPath(import.meta.url), '../../dist/overlay/') });
7 changes: 1 addition & 6 deletions packages/spotlight/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
<body>
<script type="module">
import * as Spotlight from '@spotlightjs/overlay';
Spotlight.init({
fullPage: true,
injectImmediately: true,
debug: document.URL.toLowerCase().endsWith('#debug'),
showTriggerButton: false,
});
Spotlight.init();
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/spotlight/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { builtinModules } from 'node:module';
import { resolve } from 'path';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';

import packageJson from './package.json';
Expand Down
8 changes: 8 additions & 0 deletions packages/spotlight/vite.overlay.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export default defineConfig({
input: {
main: resolve(__dirname, 'src', 'index.html'),
},
// We disable versioned filenames here explicitly
// so we can include the script when sidecar is running
// for server-side frameworks
output: {
entryFileNames: 'assets/[name].js',
chunkFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]',
},
},
},
});
Loading