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

Load content script as string with esbuild plugin #240

Conversation

hansottowirtz
Copy link
Contributor

@hansottowirtz hansottowirtz commented Jan 1, 2023

This plugin builds on #250 and extracts the injected page content script to a separate ts file, which gets loaded by the custom script-to-file plugin in tsup.config.ts.

This is much cleaner, adds type safety and allows us to bundle other modules into the content script. Can replace #239.

I also added kleur for the terminal colors.

In the built files, the addContentScript call looks as follows:

// script-to-text:<root>/src/page.content-script.ts?script-to-text
var page_content_script_default = '(() => {\n  var __create = Object.create;\n  var __defProp = <the rest of the file...>';

await page.addScriptTag({
  content: `
const __CONTENT_SCRIPT_viewMode = ${JSON.stringify(__CONTENT_SCRIPT_viewMode)};
const __CONTENT_SCRIPT_renderedEvent = ${JSON.stringify(__CONTENT_SCRIPT_renderedEvent)};
const __CONTENT_SCRIPT_testRunnerVersion = ${JSON.stringify(__CONTENT_SCRIPT_testRunnerVersion)};
const __CONTENT_SCRIPT_referenceURL = ${JSON.stringify(__CONTENT_SCRIPT_referenceURL)};
const __CONTENT_SCRIPT_debugPrintLimit = ${JSON.stringify(__CONTENT_SCRIPT_debugPrintLimit)};
const __CONTENT_SCRIPT_targetURL = ${JSON.stringify(null)};
${page_content_script_default}`
});
📦 Published PR as canary version: 0.9.4--canary.240.4cbe11b.0

✨ Test out this PR locally via:

npm install @storybook/test-runner@0.9.4--canary.240.4cbe11b.0
# or 
yarn add @storybook/test-runner@0.9.4--canary.240.4cbe11b.0

@socket-security
Copy link

socket-security bot commented Jan 1, 2023

Socket Security Pull Request Report

👍 No new dependency issues detected in pull request

Pull request report summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script confusion ✅ 0 issues
Bin script shell injection ✅ 0 issues
Shell access ✅ 0 issues
Uses eval ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
GitHub dependency ✅ 0 issues
New author ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues
AI detected malware ✅ 0 issues
Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@2.4.2

Powered by socket.dev

@JReinhold
Copy link
Contributor

This is interesting work, and we're looking at it. @yannbf will redo the PR that this is based on, so we can target that as a base here, to only include the actual changes.

@hansottowirtz hansottowirtz changed the base branch from next to bundle-tsup-swc January 26, 2023 10:33
@hansottowirtz
Copy link
Contributor Author

Great! I changed the base now.

@codecov
Copy link

codecov bot commented Feb 13, 2023

Codecov Report

Base: 76.13% // Head: 76.13% // No change to project coverage 👍

Coverage data is based on head (9a9ffe4) compared to base (a561b1d).
Patch has no changes to coverable lines.

Additional details and impacted files
@@               Coverage Diff                @@
##           bundle-tsup-swc     #240   +/-   ##
================================================
  Coverage            76.13%   76.13%           
================================================
  Files                   11       11           
  Lines                  176      176           
  Branches                36       36           
================================================
  Hits                   134      134           
  Misses                  42       42           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hansottowirtz
Copy link
Contributor Author

I cleaned up some commits, should be good to go now.

@bryanjtc bryanjtc deleted the branch storybookjs:bundle-tsup-swc July 14, 2023 17:43
@bryanjtc bryanjtc closed this Jul 14, 2023
@hansottowirtz hansottowirtz deleted the content-script-plugin branch July 15, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants