1287 library assets url#1479
Conversation
59771c4 to
d1cdca5
Compare
|
Once merged we need to have something like following posted in a slack channel For anyone using editor-ui for local development I’ve just merged some work so that we are now using Scratch editor from our own private registry - it now pulls @RaspberryPiFoundation/scratch-gui from GitHub Packages. You will need to do the following
|
There was a problem hiding this comment.
Pull request overview
Configures Scratch library picker asset URLs to load from the Raspberry Pi Foundation CDN by wiring a build-time URL template through ScratchEditor into the pinned @RaspberryPiFoundation/scratch-gui build, and updates CI/dev tooling to authenticate against GitHub Packages.
Changes:
- Pin
@RaspberryPiFoundation/scratch-guiand update all imports/webpack copy & externals paths accordingly. - Add
REACT_APP_SCRATCH_LIBRARY_ASSET_URL_TEMPLATEsupport (incl. CSP origin derivation) and passlibraryAssetUrlTemplateinto Scratch GUI. - Add GitHub Packages auth configuration for local dev, Docker, and CI/deploy; add unit tests for env-template resolution.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
yarn.lock |
Locks the new @RaspberryPiFoundation/scratch-gui package and updated transitive Scratch deps. |
package.json |
Replaces @scratch/scratch-gui with pinned @RaspberryPiFoundation/scratch-gui. |
webpack.config.js |
Updates scratch-gui dist paths/externals and injects a derived CSP origin for library assets. |
src/utils/scratchLibraryAssetUrl.js |
Adds helper to resolve the library asset URL template from env (or undefined). |
src/utils/scratchLibraryAssetUrl.test.js |
Adds unit tests for URL-template resolution behavior. |
src/scratch.html |
Expands CSP directives to allow the derived library asset origin. |
src/components/ScratchEditor/WrappedScratchGui.jsx |
Switches Scratch GUI import to the RPF-scoped package. |
src/components/ScratchEditor/ScratchIntegrationHOC.jsx |
Switches action imports to the RPF-scoped scratch-gui package. |
src/components/ScratchEditor/ScratchIntegrationHOC.test.jsx |
Updates Jest mock to match the new scratch-gui package name. |
src/components/ScratchEditor/ScratchEditor.jsx |
Resolves env template and passes libraryAssetUrlTemplate to WrappedScratchGui. |
src/components/ScratchEditor/ScratchEditor.test.jsx |
Mocks template resolution and asserts the prop is passed (or unset). |
README.md |
Documents GitHub Packages token setup and local scratch-editor linking workflow. |
.env.example |
Documents REACT_APP_SCRATCH_LIBRARY_ASSET_URL_TEMPLATE and default behavior. |
docker-compose.yml |
Passes NPM_AUTH_TOKEN through to support installs from GitHub Packages in-container. |
.yarnrc.yml |
Configures npm scope registry/auth for GitHub Packages and pre-approves scratch-gui. |
.npmrc |
Adds npm registry + auth token wiring for the @RaspberryPiFoundation scope. |
.github/workflows/deploy.yml |
Plumbs the new env var into deploy builds and configures auth env vars for installs. |
.github/workflows/ci-cd.yml |
Adds packages: read permission and wires auth + template env for tests/Cypress. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
73e3ddf to
6f0287c
Compare
| <code class="language-python">print('hello world')</code> | ||
| ``` | ||
|
|
||
| ### Linking a local scratch-editor (Scratch GUI) |
There was a problem hiding this comment.
Might be nice to add this to a seperate file and reference here since now the readme is getting very long
| # Substitute {assetPath} in the template (e.g. cd21514d0531fdffb22204e0ec5ed84a.svg). | ||
| # MIT default in scratch-gui when unset: | ||
| # https://cdn.assets.scratch.mit.edu/internalapi/asset/{assetPath}/get/ | ||
| REACT_APP_SCRATCH_LIBRARY_ASSET_URL_TEMPLATE='https://editor-assets.raspberrypi.org/internalapi/asset/{assetPath}/get/' |
There was a problem hiding this comment.
I don't feel strongly about this, but it might be simpler to put this in a constant in JS file rather than using an environment variable.
We don't need to vary this per environment, it's not secret, and we don't need to change it independently of deploys.
Having it as a env var just adds a little more setup that we'll have to do when deploying and locally.
zetter-rpf
left a comment
There was a problem hiding this comment.
Great work, and I appreciate the documentation for if we need to make other changes in a couple of months time.
I've added a couple of optional comments.
related to issue: 1287
Summary
Configures Scratch library picker assets to load from the RPF CDN and pins editor-ui to the published
@RaspberryPiFoundation/scratch-guibuild that includeslibraryAssetUrlTemplatesupport (scratch-editorcode-classroom/ #1287).Project save/load assets are unchanged — they still use
editor-apiviaassetHost/projectHost.Changes
REACT_APP_SCRATCH_LIBRARY_ASSET_URL_TEMPLATE(placeholder{assetPath}) wired throughScratchEditor→ scratch-gui; CSPimg-srcderived at webpack build time.@scratch/scratch-gui@^13.0.0with@RaspberryPiFoundation/scratch-gui@13.7.3-code-classroom.20260522151700from GitHub Packages; updated imports, webpack copy paths, and iframe externals..npmrc,.yarnrc.ymlnpmScopes, README “Set a personal access token”, Docker Compose passesNPM_AUTH_TOKENfrom the host shell.REACT_APP_SCRATCH_LIBRARY_ASSET_URL_TEMPLATEset foryarn build(all deploy environments viadeploy.ymldefault) and for Jest/Cypress inci-cd.yml.ScratchEditor.test.jsxmocks env resolution so tests are stable; unit tests forresolveScratchLibraryAssetUrlTemplate..env.example, README local scratch-editor linking updated for@RaspberryPiFoundation/scratch-gui.Default library URL (all deployed envs)
Unset locally → scratch-gui falls back to MIT CDN.
Developer setup
Create a classic personal access token with
repo+read:packages(authorize SSO for RPF if required), set asNPM_AUTH_TOKENin~/.zshrc, then runyarn install. CI usesGITHUB_TOKEN+ existing GPRsetup-nodeconfig.image-assets-loaded.mov